@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/README.md +77 -13
- package/dist/cyclonedx/bom.json +1 -1
- package/dist/index.d.ts +294 -203
- package/dist/index.js +2 -689
- package/dist/pages/link.js +162 -0
- package/dist/pages/link.props.js +3 -0
- package/dist/pages/pages.json +20 -0
- package/dist/shared-D7o15Y7B.js +813 -0
- package/locales/en/specimen/route-link.json +16 -0
- package/package.json +31 -24
- package/dist/rolldown-runtime-BBjsoOtd.js +0 -27
package/dist/index.d.ts
CHANGED
|
@@ -1,82 +1,117 @@
|
|
|
1
1
|
import { ComponentProps, FunctionComponent, ReactNode } from "react";
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
*
|
|
9
|
+
* Derives the router's base path from the base the bundler was given.
|
|
6
10
|
*
|
|
7
11
|
* @remarks
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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
|
-
|
|
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
|
|
46
|
+
* The parameters and the search, in the type alone.
|
|
14
47
|
*/
|
|
15
|
-
readonly
|
|
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
|
-
*
|
|
59
|
+
* The full id the route was declared under.
|
|
18
60
|
*/
|
|
19
|
-
readonly
|
|
61
|
+
readonly id: string;
|
|
20
62
|
}
|
|
21
63
|
/**
|
|
22
|
-
*
|
|
64
|
+
* Points at a route, either by a reference or by the bare id of one.
|
|
23
65
|
*/
|
|
24
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
*
|
|
78
|
+
* Describes the parameters argument of a function that resolves a link: required where
|
|
79
|
+
* `RequiresParams` is true, and optional otherwise.
|
|
41
80
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
97
|
+
* Imports the module that exports the page.
|
|
58
98
|
*/
|
|
59
|
-
readonly
|
|
99
|
+
readonly load: () => Promise<Readonly<Record<string, FunctionComponent>>>;
|
|
60
100
|
}
|
|
61
101
|
/**
|
|
62
|
-
*
|
|
102
|
+
* Validates a route's search string and types the values its page reads.
|
|
63
103
|
*
|
|
64
104
|
* @remarks
|
|
65
|
-
*
|
|
66
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
146
|
-
* breadcrumb or a telemetry hook
|
|
147
|
-
*
|
|
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
|
|
225
|
+
* The menu entry the declaration stated, passed through untouched.
|
|
156
226
|
*/
|
|
157
227
|
readonly navigation?: unknown;
|
|
158
228
|
}
|
|
159
229
|
/**
|
|
160
|
-
*
|
|
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
|
|
164
|
-
* evaluator
|
|
165
|
-
* the library's own `redirect` instead
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
*
|
|
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>) =>
|
|
260
|
+
readonly errorComponent?: ((declaration: RouteDeclaration<Condition>) => ErrorRouteComponent$1) | undefined;
|
|
179
261
|
/**
|
|
180
|
-
*
|
|
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:
|
|
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
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
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
|
|
206
|
-
* cycle, where one states a condition and no evaluator was given, or where one states an
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
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
|
|
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
|
|
324
|
+
* Reads the id of the deepest named route the page is on.
|
|
275
325
|
*
|
|
276
326
|
* @remarks
|
|
277
|
-
* The
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
* @returns The id and the menu entry, or nothing where no matched route
|
|
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
|
|
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
|
|
290
|
-
* tree the route is not in. The
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
* @param to - A reference to the route the calling component
|
|
296
|
-
* @returns The parameters the route's path
|
|
297
|
-
* @throws {@link Error} Where the page being
|
|
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
|
-
*
|
|
396
|
+
* Maps every id that a link can point at to the route that renders it.
|
|
326
397
|
*/
|
|
327
|
-
type RouteMap = ReadonlyMap<string,
|
|
398
|
+
type RouteMap = ReadonlyMap<string, AnyRoute$1>;
|
|
328
399
|
/**
|
|
329
|
-
*
|
|
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
|
|
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
|
|
342
|
-
*
|
|
343
|
-
*
|
|
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
|
|
421
|
+
* Reads every id of a tree, against the route that renders it.
|
|
350
422
|
*
|
|
351
423
|
* @remarks
|
|
352
|
-
*
|
|
353
|
-
* built from a declaration
|
|
354
|
-
* serve one URL
|
|
355
|
-
*
|
|
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
|
|
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:
|
|
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
|
|
437
|
+
* Resolves a declared id to a path, with the parameters of the path filled in.
|
|
366
438
|
*
|
|
367
439
|
* @remarks
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
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
|
|
374
|
-
* @param params - The parameters the path
|
|
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
|
|
377
|
-
* route was placed in, or where a parameter the path
|
|
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
|
|
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
|
|
385
|
-
* package's own
|
|
386
|
-
*
|
|
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
|
|
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
|
-
*
|
|
399
|
-
* @param
|
|
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
|
|
402
|
-
* a parameter the path
|
|
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
|
|
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
|
|
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
|
|
481
|
+
type LinkProps<Params extends AnyParams, Search> = {
|
|
416
482
|
/**
|
|
417
|
-
* The
|
|
483
|
+
* The search to open the route with, typed by the reference where one was given.
|
|
418
484
|
*/
|
|
419
|
-
readonly
|
|
485
|
+
readonly search?: NoInfer<Search> | undefined;
|
|
420
486
|
/**
|
|
421
|
-
* A reference to the route, or the bare id one
|
|
487
|
+
* A reference to the route, or the bare id of one.
|
|
422
488
|
*/
|
|
423
|
-
readonly to: RouteTarget<Params>;
|
|
424
|
-
} & Omit<ComponentProps<typeof
|
|
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
|
|
431
|
-
* the one place in this package where
|
|
432
|
-
*
|
|
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>(
|
|
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
|
|
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
|
|
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
|
|
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 };
|