@stealthscale/provider-router 0.1.0 → 0.4.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/index.d.ts CHANGED
@@ -1,82 +1,117 @@
1
1
  import { ComponentProps, FunctionComponent, ReactNode } from "react";
2
- export * from "@tanstack/react-router";
3
- //#region src/declaration.d.ts
2
+ import { AnyRoute, AnyRoute as AnyRoute$1, AnyRouter, ErrorComponentProps, ErrorRouteComponent, ErrorRouteComponent as ErrorRouteComponent$1, Link, Navigate, NotFoundRouteComponent, NotFoundRouteProps, Outlet, RouterContextProvider, RouterHistory, RouterProvider, createLink, createMemoryHistory, createRootRoute, createRootRouteWithContext, createRoute, createRouter, isNotFound, isRedirect, notFound, redirect, useChildMatches, useLinkProps, useLocation, useMatches, useNavigate, useRouteContext, useRouter, useRouterState } from "@tanstack/react-router";
3
+ import { StandardSchemaV1 } from "@standard-schema/spec";
4
+ //#region src/basepath.d.ts
5
+ /**
6
+ * Derives the path a router mounts its routes under from where the documents are served.
7
+ */
4
8
  /**
5
- * Loads a page on first navigation, rather than with the bundle that declared it.
9
+ * Derives the router's base path from the base the bundler was given.
6
10
  *
7
11
  * @remarks
8
- * A wrapper rather than a bare function, because a React component is a function too and nothing
9
- * at run time separates one from an importer.
12
+ * The bundler's base locates the assets: a path under the application's origin for an ordinary
13
+ * deployment, an absolute URL for one whose assets are served from another host. The router's
14
+ * base path locates the documents, which is always a path on the application's origin. A
15
+ * path-only base locates both, so its path becomes the router's without the trailing slash the
16
+ * bundler writes. A base naming a host says nothing about the documents, so the router mounts at
17
+ * the root.
18
+ * @param base - Base the bundler was given, which is `import.meta.env.BASE_URL` in a page.
19
+ * @param documents - Path the documents are served under, for a deployment whose assets are served
20
+ * from another host. Omitted, the base decides.
21
+ * @returns The path the router mounts under, with a leading slash and no trailing slash.
22
+ */
23
+ export declare function basepathOf(base: string, documents?: string): string;
24
+ //#endregion
25
+ //#region src/reference.d.ts
26
+ /**
27
+ * Types a reference to a route, which contains no path, no module and no address.
10
28
  */
11
- interface LazyPage {
29
+ /**
30
+ * The parameters of a route whose reference has no parameter type.
31
+ */
32
+ type AnyParams = Readonly<Record<string, string>>;
33
+ /**
34
+ * Points at a route by the id it was declared under, with its parameters and its search in the
35
+ * type alone.
36
+ *
37
+ * @remarks
38
+ * The type is structural, so a plugin SDK's own reference type satisfies it, and this package
39
+ * does not depend on that SDK. A reference contains no path, because whoever composes the
40
+ * application chooses the path, and a link written against a path would break when they placed
41
+ * the route elsewhere. No code reads `~types` at run time. A link that passes `id` to a route
42
+ * whose path has `invoice` fails to compile because of it, and a page reads its search typed.
43
+ */
44
+ interface RouteRef<Params extends AnyParams = AnyParams, Search = unknown> {
12
45
  /**
13
- * The export the page is published under. The module's default export where it states none.
46
+ * The parameters and the search, in the type alone.
14
47
  */
15
- readonly export?: string | undefined;
48
+ readonly "~types"?: {
49
+ /**
50
+ * The parameters of the route's path, which a link fills.
51
+ */
52
+ readonly params: Params;
53
+ /**
54
+ * The search that the route's validator returns, which a page reads and a link writes.
55
+ */
56
+ readonly search: Search;
57
+ };
16
58
  /**
17
- * Imports the module holding the page.
59
+ * The full id the route was declared under.
18
60
  */
19
- readonly load: () => Promise<Readonly<Record<string, FunctionComponent>>>;
61
+ readonly id: string;
20
62
  }
21
63
  /**
22
- * Reports one fault a schema found.
64
+ * Points at a route, either by a reference or by the bare id of one.
23
65
  */
24
- interface SearchIssue {
25
- /**
26
- * The fault, in words a person can read.
27
- */
28
- readonly message: string;
29
- }
66
+ type RouteTarget<Params extends AnyParams = AnyParams, Search = unknown> = RouteRef<Params, Search> | string;
30
67
  /**
31
- * Reports that a value was refused, and why.
68
+ * Reports whether a link to a route must pass parameters: true where the parameters have a
69
+ * required key.
70
+ *
71
+ * @remarks
72
+ * A bare id and an untyped reference take `AnyParams`, whose keys are any string, so a link to
73
+ * either passes parameters at will. A reference to a path without parameters, or with optional
74
+ * ones alone, has no required key.
32
75
  */
33
- interface SearchRefused {
34
- /**
35
- * Each fault the schema found.
36
- */
37
- readonly issues: readonly SearchIssue[];
38
- }
76
+ type RequiresParams<Params extends AnyParams> = string extends keyof Params ? false : Partial<Params> extends Params ? false : true;
39
77
  /**
40
- * Reports that a value was accepted, and what it read as.
78
+ * Describes the parameters argument of a function that resolves a link: required where
79
+ * `RequiresParams` is true, and optional otherwise.
41
80
  */
42
- interface SearchRead {
43
- /**
44
- * Nothing, which is how a reader tells an acceptance from a refusal.
45
- */
46
- readonly issues?: undefined;
47
- /**
48
- * The value, as the schema read it.
49
- */
50
- readonly value: unknown;
51
- }
81
+ type ParamsArgument<Params extends AnyParams> = RequiresParams<Params> extends true ? [params: Params] : [params?: Params | undefined];
82
+ //#endregion
83
+ //#region src/declaration.d.ts
52
84
  /**
53
- * Checks a value against a schema, in the shape Standard Schema settled on.
85
+ * Loads a page on the first navigation to it.
86
+ *
87
+ * @remarks
88
+ * The importer is a member of an object, because a React component is a function too and nothing
89
+ * at run time tells one from an importer.
54
90
  */
55
- interface StandardSurface {
91
+ interface LazyPage {
92
+ /**
93
+ * The export the page is published under. The module's default export where it states none.
94
+ */
95
+ readonly export?: string | undefined;
56
96
  /**
57
- * Checks a value and returns what it read, or why it refused.
97
+ * Imports the module that exports the page.
58
98
  */
59
- readonly validate: (value: unknown) => Promise<SearchRead | SearchRefused> | SearchRead | SearchRefused;
99
+ readonly load: () => Promise<Readonly<Record<string, FunctionComponent>>>;
60
100
  }
61
101
  /**
62
- * Reads a search string into the values a route draws with.
102
+ * Validates a route's search string and types the values its page reads.
63
103
  *
64
104
  * @remarks
65
- * Stated structurally rather than by the library's own name, so a declaration carries a validator
66
- * from any library that implements Standard Schema without this package depending on any of them.
105
+ * Any library that implements Standard Schema provides one. This package depends on the
106
+ * specification's types alone, so a declaration takes a validator from any such library.
67
107
  */
68
- interface SearchValidator {
69
- /**
70
- * The Standard Schema surface, which is the whole of what the library reads.
71
- */
72
- readonly "~standard": StandardSurface;
73
- }
108
+ type SearchValidator<Search = unknown> = StandardSchemaV1<unknown, Search>;
74
109
  /**
75
- * Draws a frame around whatever a route below it draws.
110
+ * Describes the props of a layout, which renders a frame around the route below it.
76
111
  */
77
112
  interface LayoutProps {
78
113
  /**
79
- * The route drawn inside the frame, which React supplies.
114
+ * The route below the layout, which React renders inside the frame.
80
115
  */
81
116
  readonly children?: ReactNode | undefined;
82
117
  /**
@@ -84,6 +119,35 @@ interface LayoutProps {
84
119
  */
85
120
  readonly options?: Readonly<Record<string, unknown>> | undefined;
86
121
  }
122
+ /**
123
+ * Lists what a declared route's loader receives.
124
+ */
125
+ interface RouteLoaderArgs {
126
+ /**
127
+ * The route's context, which contains whatever the application put in the router's context.
128
+ */
129
+ readonly context: unknown;
130
+ /**
131
+ * The parameters the route's path names.
132
+ */
133
+ readonly params: AnyParams;
134
+ /**
135
+ * True where the router loads the route ahead of a navigation.
136
+ */
137
+ readonly preload: boolean;
138
+ /**
139
+ * The route's search, as its validator returned it.
140
+ */
141
+ readonly search: unknown;
142
+ /**
143
+ * Signal that aborts when a later navigation supersedes this one.
144
+ */
145
+ readonly signal: AbortSignal;
146
+ }
147
+ /**
148
+ * Loads a route's data before its page renders.
149
+ */
150
+ type RouteLoader = (args: RouteLoaderArgs) => Promise<void> | void;
87
151
  /**
88
152
  * Describes one route a host declares, in the form the compiler takes.
89
153
  *
@@ -94,7 +158,7 @@ interface LayoutProps {
94
158
  */
95
159
  interface RouteDeclaration<Condition = unknown> {
96
160
  /**
97
- * Draws the page, either directly or loaded on first navigation.
161
+ * The page, as a component or as a module that loads on the first navigation to it.
98
162
  */
99
163
  readonly component: FunctionComponent | LazyPage;
100
164
  /**
@@ -102,19 +166,25 @@ interface RouteDeclaration<Condition = unknown> {
102
166
  */
103
167
  readonly id: string;
104
168
  /**
105
- * The layouts it is drawn in, outermost first. Drawn bare where it names none.
169
+ * The layouts the page renders in, by name, outermost first. The page renders in none where the
170
+ * list is absent.
106
171
  */
107
172
  readonly layout?: readonly string[] | undefined;
108
173
  /**
109
174
  * Passed to each layout untouched, for whatever the layout reads.
110
175
  */
111
176
  readonly layoutOptions?: Readonly<Record<string, unknown>> | undefined;
177
+ /**
178
+ * Loads the route's data before its page renders, and again when its search changes.
179
+ */
180
+ readonly loader?: RouteLoader | undefined;
112
181
  /**
113
182
  * The menu entry a menu reads, which the compiler writes onto the route without reading.
114
183
  */
115
184
  readonly navigation?: unknown;
116
185
  /**
117
- * The pane it is drawn in, which this package refuses because it draws no panes.
186
+ * The pane the page renders in, which the compiler refuses, because a matched route renders the
187
+ * whole screen.
118
188
  */
119
189
  readonly outlet?: string | undefined;
120
190
  /**
@@ -130,7 +200,7 @@ interface RouteDeclaration<Condition = unknown> {
130
200
  */
131
201
  readonly sample?: Readonly<Record<string, string>> | undefined;
132
202
  /**
133
- * Reads the search string this route draws with.
203
+ * Validates the route's search string, and types the values its page reads.
134
204
  */
135
205
  readonly search?: SearchValidator | undefined;
136
206
  /**
@@ -139,12 +209,12 @@ interface RouteDeclaration<Condition = unknown> {
139
209
  readonly when?: Condition | undefined;
140
210
  }
141
211
  /**
142
- * Carries the name a route goes by, and whatever a menu reads off it.
212
+ * Describes the id a compiled route is named by, and the menu entry a menu reads from it.
143
213
  *
144
214
  * @remarks
145
- * Written onto the route's `staticData`, which the library hands back on every match. A menu, a
146
- * breadcrumb or a telemetry hook therefore reads the name off the page it is drawing rather than
147
- * holding a second copy of the list.
215
+ * The compiler writes it into the route's `staticData`, which the library returns with every
216
+ * match. A menu, a breadcrumb or a telemetry hook reads the id from the match of the page on
217
+ * screen, and keeps no second copy of the list.
148
218
  */
149
219
  interface DeclaredRoute {
150
220
  /**
@@ -152,99 +222,79 @@ interface DeclaredRoute {
152
222
  */
153
223
  readonly id: string;
154
224
  /**
155
- * The menu entry the declaration carried, passed through untouched.
225
+ * The menu entry the declaration stated, passed through untouched.
156
226
  */
157
227
  readonly navigation?: unknown;
158
228
  }
159
229
  /**
160
- * Reports whether a route's condition holds for whoever is asking.
230
+ * Describes the address a navigation enters, as an evaluator reads it.
231
+ */
232
+ interface EnteredLocation {
233
+ /**
234
+ * The path, the search and the hash of the address, without its origin.
235
+ */
236
+ readonly href: string;
237
+ }
238
+ /**
239
+ * Returns whether a route's condition is true for the router whose context is given.
161
240
  *
162
241
  * @remarks
163
- * Returning false makes the route a 404, because a route nobody may reach does not exist. An
164
- * evaluator wanting anything else, such as sending an unauthenticated person to sign in, throws
165
- * the library's own `redirect` instead.
166
- */
167
- type Evaluate<Condition = unknown> = (when: Condition) => boolean;
168
- import * as import__tanstack_react_router from "@tanstack/react-router";
242
+ * Returning false makes the route not found, because a route nobody may open does not exist. An
243
+ * evaluator that wants anything else, such as sending an unauthenticated person to sign in,
244
+ * throws the library's own `redirect` instead, and reads the address to return to from
245
+ * `location`. The context is the route's, as `beforeLoad` receives it, so the evaluator reads the
246
+ * state of the router it runs in, and one tree serves every router built from it. A caller that
247
+ * evaluates outside a navigation, such as a menu, passes no location.
248
+ */
249
+ type Evaluate<Condition = unknown, Context = unknown> = (when: Condition, context: Context, location?: EnteredLocation) => boolean;
169
250
  //#endregion
170
251
  //#region src/compile.d.ts
171
252
  /**
172
253
  * Describes what one compilation needs beyond the declarations themselves.
173
254
  */
174
- interface CompileOptions<Condition = unknown> {
255
+ interface CompileOptions<Condition = unknown, Context = unknown> {
175
256
  /**
176
- * Draws a page whose own component threw or failed to load, named per declaration.
257
+ * Builds the error component of each declaration's route, which renders when the page throws or
258
+ * fails to load.
177
259
  */
178
- readonly errorComponent?: ((declaration: RouteDeclaration<Condition>) => tanstack_d_exports.ErrorRouteComponent) | undefined;
260
+ readonly errorComponent?: ((declaration: RouteDeclaration<Condition>) => ErrorRouteComponent$1) | undefined;
179
261
  /**
180
- * Reports whether a route's condition holds. Required where any declaration states one.
262
+ * Returns whether a route's condition is true. Required where any declaration states one.
181
263
  */
182
- readonly evaluate?: Evaluate<Condition> | undefined;
264
+ readonly evaluate?: Evaluate<Condition, Context> | undefined;
183
265
  /**
184
266
  * The layouts a declaration may name.
185
267
  */
186
268
  readonly layouts?: Readonly<Record<string, FunctionComponent<LayoutProps>>> | undefined;
269
+ /**
270
+ * Renders in a compiled route's place where its page, its loader or its condition throws the
271
+ * router's not-found. Where it is absent, the not-found renders at the nearest route above that
272
+ * states one.
273
+ */
274
+ readonly notFoundComponent?: NotFoundRouteComponent | undefined;
187
275
  /**
188
276
  * The route every compiled route hangs under, which this compilation never changes.
189
277
  */
190
- readonly parent: tanstack_d_exports.AnyRoute;
278
+ readonly parent: AnyRoute$1;
191
279
  }
192
280
  /**
193
281
  * Compiles declarations into routes under the parent a caller states.
194
282
  *
195
283
  * @remarks
196
- * Pure with respect to the caller. It creates routes and never mutates the parent, so a second
197
- * call returns a second set of routes sharing no object with the first. That is what keeps two
198
- * routers in one process from reading each other's tree through the library's process-wide cache.
199
- * Compile every contributor's declarations in one call. Two calls under one parent cannot see
200
- * each other's paths, and `routeMap` reports the collision once the tree is assembled.
284
+ * The compiler creates routes and never mutates the parent, so a second call returns a second set
285
+ * of routes that shares no object with the first. Two routers in one process therefore never read
286
+ * each other's tree through the library's process-wide cache. Compile every contributor's
287
+ * declarations in one call: two calls under one parent cannot see each other's paths, and
288
+ * `routeMap` reports the collision once the tree is assembled.
201
289
  * @param declarations - The routes to compile, in any order.
202
290
  * @param options - The parent, and what the declarations may name.
203
291
  * @returns The routes to place in the parent's own `addChildren` call.
204
292
  * @throws {@link Error} Where two declarations share an id, where one names a parent or a layout
205
- * nothing provides, where one names a layout a route above it already draws, where parents form a
206
- * cycle, where one states a condition and no evaluator was given, or where one states an outlet.
207
- */
208
- export declare function compileRoutes<Condition = unknown>(declarations: ReadonlyArray<RouteDeclaration<Condition>>, options: CompileOptions<Condition>): readonly tanstack_d_exports.AnyRoute[];
209
- //#endregion
210
- //#region src/reference.d.ts
211
- /**
212
- * Points at a route without naming a path, a module or an address.
213
- */
214
- /**
215
- * The parameters a route names where its reference states none.
216
- */
217
- type AnyParams = Readonly<Record<string, string>>;
218
- /**
219
- * Points at a route by the id it was declared under, carrying the parameters its path names.
220
- *
221
- * @remarks
222
- * Stated structurally rather than imported, so a plugin SDK's own reference type satisfies it
223
- * without this package depending on that SDK. A reference carries no path, because the path is
224
- * whoever composed the application's to choose and a link written against one would move when
225
- * they re-placed the route.
226
- * The parameters live in the type alone. Nothing reads `~types` at run time, and it is there so
227
- * a link to a route filling `id` is refused where the route names `invoice`.
228
- */
229
- interface RouteRef<Params extends AnyParams = AnyParams> {
230
- /**
231
- * The parameters, in the type alone.
232
- */
233
- readonly "~types"?: {
234
- /**
235
- * The parameters the route's path names, which a link fills.
236
- */
237
- readonly params: Params;
238
- };
239
- /**
240
- * The full id the route was declared under.
241
- */
242
- readonly id: string;
243
- }
244
- /**
245
- * Points at a route, either by a reference or by the bare id one carries.
293
+ * nothing provides, where one names a layout a route above it already renders, where parents form
294
+ * a cycle, where one states a condition and no evaluator was given, or where one states an
295
+ * outlet.
246
296
  */
247
- type RouteTarget<Params extends AnyParams = AnyParams> = RouteRef<Params> | string;
297
+ export declare function compileRoutes<Condition = unknown, Context = unknown>(declarations: ReadonlyArray<RouteDeclaration<Condition>>, options: CompileOptions<Condition, Context>): readonly AnyRoute$1[];
248
298
  //#endregion
249
299
  //#region src/declared.d.ts
250
300
  /**
@@ -252,51 +302,68 @@ type RouteTarget<Params extends AnyParams = AnyParams> = RouteRef<Params> | stri
252
302
  */
253
303
  interface MatchedRoute {
254
304
  /**
255
- * The data the route was given to carry, which the library hands back untouched.
305
+ * The static data the route was created with, which the library returns untouched.
256
306
  */
257
307
  readonly staticData: object;
258
308
  }
259
309
  /**
260
- * Reads the id and the menu entry a matched route carries, or nothing where it carries neither.
310
+ * Reads the id and the menu entry a matched route stores, or nothing where it stores neither.
261
311
  *
262
312
  * @remarks
263
- * A route carries its id in `staticData`, which is where the library keeps whatever a route wants
264
- * to carry. The compiler writes it for a route built from a declaration and `namedRoute` writes
265
- * it for one written in code, so a menu, a breadcrumb or a telemetry hook reads what it needs off
266
- * the match either way. The shape is checked rather than trusted, because `staticData` is untyped
267
- * by design and a route may carry anything under the same name. The checked object itself is
268
- * returned, so every read of one route gives one reference.
313
+ * A route stores its id in `staticData`, the library's place for data a route is created with.
314
+ * The compiler writes it for a route built from a declaration, and `namedRoute` writes it for one
315
+ * written in code, so a menu, a breadcrumb or a telemetry hook reads the id from the match either
316
+ * way. The function checks the shape, because `staticData` is untyped and a route may store
317
+ * anything under the same name. It returns the checked object itself, so every read of one route
318
+ * returns one reference.
269
319
  * @param match - A match, as `useMatches` returns one.
270
- * @returns The id and the menu entry it carries, or nothing.
320
+ * @returns The id and the menu entry, or nothing.
271
321
  */
272
322
  export declare function declaredOf(match: MatchedRoute): DeclaredRoute | undefined;
273
323
  /**
274
- * Reads the name the deepest named route the page is on goes by.
324
+ * Reads the id of the deepest named route the page is on.
275
325
  *
276
326
  * @remarks
277
- * The deepest match rather than the first, because a named route nested under another is the page
278
- * a person is looking at. A page drawn entirely from unnamed routes returns nothing.
279
- * The selector returns the object the route carries rather than a copy of it. A route's static
280
- * data is fixed once the tree is built, so the reference is the same one until a different route
281
- * matches, and a navigation that left the page alone re-renders nothing.
282
- * @returns The id and the menu entry, or nothing where no matched route carries either.
327
+ * The hook reads the deepest match, because a named route nested under another is the page a
328
+ * person is looking at. A page rendered from unnamed routes alone returns nothing. The selector
329
+ * returns the object the route stores, not a copy. A route's static data is fixed once the tree
330
+ * is built, so the reference changes only when a different route matches, and a navigation that
331
+ * keeps the page does not render it again.
332
+ * @returns The id and the menu entry, or nothing where no matched route has an id.
283
333
  */
284
334
  export declare function useDeclaredRoute(): DeclaredRoute | undefined;
285
335
  /**
286
- * Reads the parameters of the page being drawn, typed by the reference the caller holds.
336
+ * Reads the parameters of the page being rendered, typed by the reference the caller passes.
287
337
  *
288
338
  * @remarks
289
- * A compiled route is outside the tree an application registered, so `useParams` types against a
290
- * tree the route is not in. The parameters are read off the match instead, and the reference
291
- * carries their names. This checks at run time that the page really is the route the reference
292
- * names before it makes the claim.
293
- * The selector returns the id and the parameters alone, which are strings. Structural sharing
294
- * compares them, so a navigation that changed neither re-renders nothing.
295
- * @param to - A reference to the route the calling component draws.
296
- * @returns The parameters the route's path named.
297
- * @throws {@link Error} Where the page being drawn is not the route the reference names.
339
+ * A compiled route is outside the tree an application registered, so `useParams` types the
340
+ * parameters against a tree the route is not in. The hook reads them from the match instead, and
341
+ * the reference types them. It checks at run time that the page is the route of the reference,
342
+ * and throws where it is not. The selector returns the id and the parameters alone, which are
343
+ * strings. Structural sharing compares them, so a navigation that changes neither does not render
344
+ * the page again.
345
+ * @param to - A reference to the route the calling component renders.
346
+ * @returns The parameters of the route's path.
347
+ * @throws {@link Error} Where the page being rendered is not the route of the reference.
298
348
  */
299
349
  export declare function useRouteParams<Params extends AnyParams>(to: RouteRef<Params>): Params;
350
+ /**
351
+ * Reads the search of the page being rendered, typed by the reference the caller passes.
352
+ *
353
+ * @remarks
354
+ * A compiled route is outside the tree an application registered, so `useSearch` types the search
355
+ * against a tree the route is not in. The hook reads it from the match instead, and the reference
356
+ * types it. It checks at run time that the page is the route of the reference, and throws where
357
+ * it is not. The value is the match's `_strictSearch`: what the validators of the route and the
358
+ * routes above it returned. The hook leaves out the keys of the address that the validators left
359
+ * out, so the page never receives a value the validator refused under the validator's type.
360
+ * Structural sharing compares the search, so the page does not render again after a navigation
361
+ * that left it equal.
362
+ * @param to - A reference to the route the calling component renders.
363
+ * @returns The search the route's validator returned.
364
+ * @throws {@link Error} Where the page being rendered is not the route of the reference.
365
+ */
366
+ export declare function useRouteSearch<Search>(to: RouteRef<AnyParams, Search>): Search;
300
367
  //#endregion
301
368
  //#region src/defaults.d.ts
302
369
  /**
@@ -313,126 +380,153 @@ export declare function useRouteParams<Params extends AnyParams>(to: RouteRef<Pa
313
380
  * already replaced.
314
381
  * Scroll position is restored on the way back, because a person returning to a list expects to be
315
382
  * where they left it rather than at the top.
383
+ * The window is moved in one step, on the way back and to the top of a new page alike. The
384
+ * library moves it with the page's own scroll behaviour by default, and the foundation sets that
385
+ * to smooth for a link into the page, so a page opened from a scrolled one glided in from above.
316
386
  */
317
387
  export declare const routerDefaults: {
318
388
  readonly defaultPreload: "intent";
319
389
  readonly defaultPreloadStaleTime: 0;
320
390
  readonly scrollRestoration: true;
391
+ readonly scrollRestorationBehavior: "instant";
321
392
  };
322
393
  //#endregion
323
394
  //#region src/map.d.ts
324
395
  /**
325
- * Every id anything links by, against the route that draws it.
396
+ * Maps every id that a link can point at to the route that renders it.
326
397
  */
327
- type RouteMap = ReadonlyMap<string, tanstack_d_exports.AnyRoute>;
398
+ type RouteMap = ReadonlyMap<string, AnyRoute$1>;
328
399
  /**
329
- * Carries a route's name where the library hands it back on every match.
400
+ * Describes the static data that contains a route's name, which the library returns with every
401
+ * match.
330
402
  */
331
403
  interface StaticName {
332
404
  /**
333
- * The static data the route carries, which `declaredOf` reads the name out of.
405
+ * The static data of the route, from which `declaredOf` reads the name.
334
406
  */
335
407
  readonly staticData: Readonly<Record<"declared", DeclaredRoute>>;
336
408
  }
337
409
  /**
338
- * Gives a route written in code the id everything else links to it by.
410
+ * Gives a route written in code the id that everything else links to it by.
339
411
  *
340
412
  * @remarks
341
- * A route carries its id in `staticData`, which is where the compiler writes the id of a route
342
- * built from a declaration. One mechanism names both, so a link does not need to know which of
343
- * the two it is pointing at.
413
+ * A route keeps its id in `staticData`, where the compiler writes the id of a route built from a
414
+ * declaration. The same field identifies both kinds, so a link does not need to know which kind
415
+ * it points at.
344
416
  * @param id - The id to name the route under.
345
417
  * @returns The static data to spread into `createRoute`.
346
418
  */
347
419
  export declare function namedRoute(id: string): StaticName;
348
420
  /**
349
- * Reads every id a tree names, against the route that draws it.
421
+ * Reads every id of a tree, against the route that renders it.
350
422
  *
351
423
  * @remarks
352
- * Derived from the tree rather than collected beside it, so a route written in code and a route
353
- * built from a declaration reach the map the same way. The walk also reports two routes that
354
- * serve one URL, which a development build reports as a duplicate route and a production build
355
- * resolves by keeping the first and dropping the rest in silence.
424
+ * The map derives from the tree and is not collected beside it, so a route written in code and a
425
+ * route built from a declaration enter the map the same way. The walk also reports two routes
426
+ * that serve one URL. A development build reports them as a duplicate route, and a production
427
+ * build keeps the first and drops the rest without a report.
356
428
  * @param tree - The assembled tree, as `createRouter` takes it.
357
429
  * @returns Every id, against its route.
358
- * @throws {@link Error} Where two routes carry one id, or where two serve one path under a shared
430
+ * @throws {@link Error} Where two routes have one id, or where two serve one path under a shared
359
431
  * parent.
360
432
  */
361
- export declare function routeMap(tree: tanstack_d_exports.AnyRoute): RouteMap;
433
+ export declare function routeMap(tree: AnyRoute$1): RouteMap;
362
434
  //#endregion
363
435
  //#region src/href.d.ts
364
436
  /**
365
- * Resolves a declared id to a path, with the parameters the path names filled in.
437
+ * Resolves a declared id to a path, with the parameters of the path filled in.
366
438
  *
367
439
  * @remarks
368
- * Throwing is deliberate in all three cases. Interpolation otherwise returns a path with a
369
- * literal `$id` still in it, and a route the library has not worked a full path out for yet
370
- * returns the site root. A link that navigates somewhere wrong is worse than one that fails where
371
- * somebody wrote it.
440
+ * The parameters are required where a typed reference's path has a required one, so the compiler
441
+ * refuses such a call without them. A bare id takes them at will, and the call throws where one
442
+ * is missing.
372
443
  * @param map - The map every route is named in.
373
- * @param to - A reference to the route, or the bare id one carries.
374
- * @param params - The parameters the path names, typed by the reference where one was given.
444
+ * @param to - A reference to the route, or the bare id of one.
445
+ * @param params - The parameters of the path, typed by the reference where one was given.
375
446
  * @returns The path, ready to navigate to.
376
- * @throws {@link Error} Where the map holds no such id, where no router has processed the tree the
377
- * route was placed in, or where a parameter the path names is missing.
447
+ * @throws {@link Error} Where the map contains no such id, where no router has processed the tree
448
+ * the route was placed in, or where a parameter of the path is missing.
378
449
  */
379
- export declare function routeHref<Params extends AnyParams>(map: RouteMap, to: RouteTarget<Params>, params?: Params): string;
450
+ export declare function routeHref<Params extends AnyParams>(map: RouteMap, to: RouteTarget<Params>, ...params: ParamsArgument<Params>): string;
380
451
  /**
381
452
  * Reads the map every route is named in, from the router's own context.
382
453
  *
383
454
  * @remarks
384
- * The map reaches a component through the router's own context rather than a provider of this
385
- * package's own, so an application mounts nothing extra to make a link by id work.
386
- * Take the map rather than a resolved path where the route is chosen after the render: a hook
387
- * cannot run inside an event handler, and `routeHref` can.
455
+ * The router's own context passes the map to a component, so an application mounts no provider
456
+ * of this package's own to make a link by id work. Where the route is chosen after the render,
457
+ * pass the map to `routeHref` inside the event handler, because a hook cannot run there.
388
458
  * @returns Every id the router knows, against the route that serves it.
389
459
  * @throws {@link Error} Where the router was built without one.
390
460
  */
391
461
  export declare function useRouteMap(): RouteMap;
392
462
  /**
393
- * Resolves a reference to a path, through the map the router context holds.
463
+ * Resolves a reference to a path, through the map in the router context.
394
464
  *
395
465
  * @remarks
396
466
  * A hook, so the route has to be known while the component renders. Use `useRouteMap` where the
397
- * route is chosen later, such as in the handler of a row a person clicked.
398
- * @param to - A reference to the route, or the bare id one carries.
399
- * @param params - The parameters the path names, typed by the reference where one was given.
467
+ * route is chosen later, such as in the handler of a row a person clicked. The parameters are
468
+ * required as `routeHref` requires them.
469
+ * @param to - A reference to the route, or the bare id of one.
470
+ * @param params - The parameters of the path, typed by the reference where one was given.
400
471
  * @returns The path, ready to navigate to.
401
- * @throws {@link Error} Where no map is in the router context, where it holds no such id, or where
402
- * a parameter the path names is missing.
472
+ * @throws {@link Error} Where no map is in the router context, where the map contains no such id,
473
+ * or where a parameter of the path is missing.
403
474
  */
404
- export declare function useRouteHref<Params extends AnyParams>(to: RouteTarget<Params>, params?: Params): string;
475
+ export declare function useRouteHref<Params extends AnyParams>(to: RouteTarget<Params>, ...params: ParamsArgument<Params>): string;
405
476
  //#endregion
406
477
  //#region src/link.d.ts
407
478
  /**
408
- * Describes a link to a declared route.
409
- *
410
- * @remarks
411
- * Everything the library's own `Link` takes passes through, so a declared link is styled,
412
- * labelled and given an active state the way any other link is. Only `to` and `params` are
413
- * restated, because a declared id is not a path the compiler knows.
479
+ * Describes the props of a link other than its parameters.
414
480
  */
415
- type RouteLinkProps<Params extends AnyParams = AnyParams> = {
481
+ type LinkProps<Params extends AnyParams, Search> = {
416
482
  /**
417
- * The parameters the route's path names, typed by the reference where one was given.
483
+ * The search to open the route with, typed by the reference where one was given.
418
484
  */
419
- readonly params?: Params | undefined;
485
+ readonly search?: NoInfer<Search> | undefined;
420
486
  /**
421
- * A reference to the route, or the bare id one carries.
487
+ * A reference to the route, or the bare id of one.
422
488
  */
423
- readonly to: RouteTarget<Params>;
424
- } & Omit<ComponentProps<typeof tanstack_d_exports.Link>, "params" | "to">;
489
+ readonly to: RouteTarget<Params, Search>;
490
+ } & Omit<ComponentProps<typeof Link>, "params" | "search" | "to">;
491
+ /**
492
+ * Describes the `params` prop of a link: required where the reference's path has a required
493
+ * parameter, and optional otherwise.
494
+ */
495
+ type ParamsProp<Params extends AnyParams> = RequiresParams<Params> extends true ? {
496
+ /**
497
+ * The parameters of the route's path, typed by the reference.
498
+ */
499
+ readonly params: Params;
500
+ } : {
501
+ /**
502
+ * The parameters of the route's path, typed by the reference where one was given.
503
+ */
504
+ readonly params?: Params | undefined;
505
+ };
506
+ /**
507
+ * Describes a link to a declared route.
508
+ *
509
+ * @remarks
510
+ * Everything the library's own `Link` takes passes through, so a declared link is styled,
511
+ * labelled and given an active state the way any other link is. Only `to`, `params` and `search`
512
+ * are restated, because a declared id is not a path the compiler knows. The reference types the
513
+ * parameters and the search, so a link without a required parameter, and a search that the
514
+ * route's validator does not return, fail to compile.
515
+ */
516
+ type RouteLinkProps<Params extends AnyParams = AnyParams, Search = unknown> = LinkProps<Params, Search> & ParamsProp<Params>;
425
517
  /**
426
518
  * Links to a route by the id a manifest declared it under.
427
519
  *
428
520
  * @remarks
429
521
  * A declared route is outside the tree an application registered, so `Link` refuses its path at
430
- * compile time. This resolves the id at run time and hands the library a plain string, which is
431
- * the one place in this package where a path is not checked by the compiler.
432
- * @param props - The declared id, its parameters, and whatever else the library's `Link` takes.
522
+ * compile time. This resolves the id at run time and passes the library a plain string, which is
523
+ * the one place in this package where the compiler does not check a path. The search passes to
524
+ * the library's `Link` beside the path.
525
+ * @param props - The declared id, its parameters, its search, and whatever else the library's
526
+ * `Link` takes.
433
527
  * @returns An anchor to the resolved path.
434
528
  */
435
- export declare function RouteLink<Params extends AnyParams>({ params, to, ...rest }: RouteLinkProps<Params>): ReactNode;
529
+ export declare function RouteLink<Params extends AnyParams, Search>(props: RouteLinkProps<Params, Search>): ReactNode;
436
530
  //#endregion
437
531
  //#region src/options.d.ts
438
532
  /**
@@ -473,7 +567,7 @@ export declare function routerOptions<Context extends object>(context: Context):
473
567
  //#endregion
474
568
  //#region src/root.d.ts
475
569
  /**
476
- * Builds a root route whose context holds whatever the application states and the route map.
570
+ * Builds a root route whose context contains whatever the application states and the route map.
477
571
  *
478
572
  * @remarks
479
573
  * Calling the library's `createRootRoute` instead leaves the context typed as empty, and the
@@ -481,9 +575,6 @@ export declare function routerOptions<Context extends object>(context: Context):
481
575
  * then names the router rather than the root, which is the file that has to change.
482
576
  * @returns The root route factory, to call with the route's own options.
483
577
  */
484
- export declare function createAppRootRoute<Context extends object = RoutesContext>(): ReturnType<typeof tanstack_d_exports.createRootRouteWithContext<Context>>;
485
- declare namespace index_d_exports {
486
- export { AnyParams, AppRouterOptions, CompileOptions, DeclaredRoute, Evaluate, LayoutProps, LazyPage, MatchedRoute, RouteDeclaration, RouteLink, RouteLinkProps, RouteMap, RouteRef, RouteTarget, RoutesContext, SearchValidator, StaticName, compileRoutes, createAppRootRoute, declaredOf, namedRoute, routeHref, routeMap, routerDefaults, routerOptions, useDeclaredRoute, useRouteHref, useRouteMap, useRouteParams };
487
- }
578
+ export declare function createAppRootRoute<Context extends object = RoutesContext>(): ReturnType<typeof createRootRouteWithContext<Context>>;
488
579
  //#endregion
489
- export type { AnyParams, AppRouterOptions, CompileOptions, DeclaredRoute, Evaluate, LayoutProps, LazyPage, MatchedRoute, RouteDeclaration, RouteLinkProps, RouteMap, RouteRef, RouteTarget, RoutesContext, SearchValidator, StaticName };
580
+ export { type AnyParams, type AnyRoute, type AnyRouter, type AppRouterOptions, type CompileOptions, type DeclaredRoute, type EnteredLocation, type ErrorComponentProps, type ErrorRouteComponent, type Evaluate, type LayoutProps, type LazyPage, type MatchedRoute, Navigate, type NotFoundRouteProps, Outlet, type RouteDeclaration, type RouteLinkProps, type RouteLoader, type RouteLoaderArgs, type RouteMap, type RouteRef, type RouteTarget, RouterContextProvider, type RouterHistory, RouterProvider, type RoutesContext, type SearchValidator, type StaticName, createLink, createMemoryHistory, createRootRoute, createRoute, createRouter, isNotFound, isRedirect, notFound, redirect, useChildMatches, useLinkProps, useLocation, useMatches, useNavigate, useRouteContext, useRouter, useRouterState };