@oomfware/stacker 0.2.3 → 0.2.5
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 +16 -16
- package/dist/index.d.mts +73 -95
- package/dist/index.mjs +238 -125
- package/dist/testing.d.mts +5 -7
- package/dist/testing.mjs +19 -20
- package/dist/{types-kax-GwM6.d.mts → types-BUru23Cr.d.mts} +41 -43
- package/dist/{url-DerpiRjh.mjs → url-0EHjozDe.mjs} +6 -7
- package/package.json +69 -68
package/README.md
CHANGED
|
@@ -38,17 +38,17 @@ const routes = defineRoutes({
|
|
|
38
38
|
app: layout({
|
|
39
39
|
component: AppShell,
|
|
40
40
|
children: {
|
|
41
|
-
Home: route({
|
|
41
|
+
Home: route({ path: '/', component: Home }),
|
|
42
42
|
Profile: route({
|
|
43
|
-
component: Profile,
|
|
44
|
-
params: { actor: string() },
|
|
45
43
|
path: '/profile/:actor',
|
|
44
|
+
params: { actor: string() },
|
|
45
|
+
component: Profile,
|
|
46
46
|
}),
|
|
47
47
|
},
|
|
48
48
|
}),
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
-
const router = new Router({ history: new NavigationHistory()
|
|
51
|
+
const router = new Router({ routes, history: new NavigationHistory() });
|
|
52
52
|
|
|
53
53
|
export const App = () => <RouterView router={router} />;
|
|
54
54
|
```
|
|
@@ -65,14 +65,14 @@ const routes = defineRoutes({
|
|
|
65
65
|
app: layout({
|
|
66
66
|
component: AppShell,
|
|
67
67
|
children: {
|
|
68
|
-
Home: route({
|
|
68
|
+
Home: route({ path: '/', component: Home }),
|
|
69
69
|
Profile: route({
|
|
70
|
-
|
|
70
|
+
path: '/profile/:actor',
|
|
71
71
|
params: { actor: string() },
|
|
72
72
|
query: { tab: optional(string()) },
|
|
73
|
-
|
|
73
|
+
component: Profile,
|
|
74
74
|
}),
|
|
75
|
-
Settings: route({
|
|
75
|
+
Settings: route({ path: '/settings', component: Settings }),
|
|
76
76
|
},
|
|
77
77
|
}),
|
|
78
78
|
});
|
|
@@ -85,10 +85,10 @@ configure `type` to control page instance lifetimes:
|
|
|
85
85
|
|
|
86
86
|
```ts
|
|
87
87
|
// page (default): new instance and state per history entry
|
|
88
|
-
route({
|
|
88
|
+
route({ path: '/profile/:actor', type: 'page', component: Profile });
|
|
89
89
|
|
|
90
90
|
// singleton: one instance per distinct parameter set
|
|
91
|
-
route({
|
|
91
|
+
route({ path: '/', type: 'singleton', component: Home });
|
|
92
92
|
```
|
|
93
93
|
|
|
94
94
|
### parameters
|
|
@@ -99,7 +99,6 @@ declare path and query parameters using codecs. types are inferred automatically
|
|
|
99
99
|
import { boolean, enumOf, integer, optional, route, string, withDefault } from '@oomfware/stacker';
|
|
100
100
|
|
|
101
101
|
route({
|
|
102
|
-
component: SearchPage,
|
|
103
102
|
path: '/search/:tag',
|
|
104
103
|
params: { tag: string() },
|
|
105
104
|
query: {
|
|
@@ -107,6 +106,7 @@ route({
|
|
|
107
106
|
sort: withDefault(enumOf(['new', 'top']), 'new'),
|
|
108
107
|
unread: optional(boolean()),
|
|
109
108
|
},
|
|
109
|
+
component: SearchPage,
|
|
110
110
|
});
|
|
111
111
|
```
|
|
112
112
|
|
|
@@ -117,7 +117,7 @@ end a path with `*name` to capture the rest of the URL, separators included. a s
|
|
|
117
117
|
its bare parent path, where the remainder is empty:
|
|
118
118
|
|
|
119
119
|
```ts
|
|
120
|
-
route({
|
|
120
|
+
route({ path: '/docs/*rest', params: { rest: string() }, component: Docs });
|
|
121
121
|
|
|
122
122
|
// /docs/guide/intro -> { rest: 'guide/intro' }
|
|
123
123
|
// /docs -> { rest: '' }
|
|
@@ -231,7 +231,7 @@ generate type-safe hooks bound to your route configuration using `createRouterHo
|
|
|
231
231
|
```tsx
|
|
232
232
|
import { createRouterHooks } from '@oomfware/stacker';
|
|
233
233
|
|
|
234
|
-
const {
|
|
234
|
+
const { useRouter, useParams } = createRouterHooks(routes);
|
|
235
235
|
|
|
236
236
|
const Profile = () => {
|
|
237
237
|
const [{ actor }, replace] = useParams('Profile');
|
|
@@ -303,8 +303,8 @@ use `router.dispose()` to detach the router from history when it is no longer ne
|
|
|
303
303
|
use focus hooks for work that should run when the screen becomes active, rather than when it mounts:
|
|
304
304
|
|
|
305
305
|
```tsx
|
|
306
|
-
import { useCallback } from 'react';
|
|
307
306
|
import { useFocusEffect, useIsFocused } from '@oomfware/stacker';
|
|
307
|
+
import { useCallback } from 'react';
|
|
308
308
|
|
|
309
309
|
const Profile = () => {
|
|
310
310
|
const [{ actor }] = useParams('Profile');
|
|
@@ -373,9 +373,9 @@ parameters:
|
|
|
373
373
|
|
|
374
374
|
```ts
|
|
375
375
|
route({
|
|
376
|
-
component: Beta,
|
|
377
376
|
path: '/feed',
|
|
378
377
|
when: ({ rawSearch }) => rawSearch.has('beta'),
|
|
378
|
+
component: Beta,
|
|
379
379
|
});
|
|
380
380
|
```
|
|
381
381
|
|
|
@@ -387,7 +387,7 @@ use `MemoryHistory` to test routing behavior in environments without a DOM:
|
|
|
387
387
|
import { MemoryHistory } from '@oomfware/stacker/testing';
|
|
388
388
|
|
|
389
389
|
const router = new Router({
|
|
390
|
-
history: new MemoryHistory({ initialEntries: ['/', '/profile/alice'] }),
|
|
391
390
|
routes,
|
|
391
|
+
history: new MemoryHistory({ initialEntries: ['/', '/profile/alice'] }),
|
|
392
392
|
});
|
|
393
393
|
```
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { a as HistoryLocation, c as HistoryUpdate, i as HistoryListener, n as HistoryAction, o as HistoryNavigateOptions, r as HistoryEntry, s as HistoryScrollBehavior, t as History } from "./types-
|
|
1
|
+
import { a as HistoryLocation, c as HistoryUpdate, i as HistoryListener, n as HistoryAction, o as HistoryNavigateOptions, r as HistoryEntry, s as HistoryScrollBehavior, t as History } from "./types-BUru23Cr.mjs";
|
|
2
2
|
import { AnchorHTMLAttributes, ComponentType, EffectCallback, LazyExoticComponent, ReactElement, ReactNode } from "react";
|
|
3
|
-
//#region src/codec.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* a bidirectional codec for a single route parameter.
|
|
6
5
|
*
|
|
@@ -54,26 +53,26 @@ type BuildShape<P extends CodecRecord> = Prettify$1<{ [K in Exclude<keyof P, Def
|
|
|
54
53
|
*
|
|
55
54
|
* @returns the string codec
|
|
56
55
|
*/
|
|
57
|
-
declare const string: () => Codec<string>;
|
|
56
|
+
export declare const string: () => Codec<string>;
|
|
58
57
|
/**
|
|
59
58
|
* creates a codec for a safe integer.
|
|
60
59
|
*
|
|
61
60
|
* @returns the integer codec
|
|
62
61
|
*/
|
|
63
|
-
declare const integer: () => Codec<number>;
|
|
62
|
+
export declare const integer: () => Codec<number>;
|
|
64
63
|
/**
|
|
65
64
|
* creates a codec for a boolean value.
|
|
66
65
|
*
|
|
67
66
|
* @returns the boolean codec
|
|
68
67
|
*/
|
|
69
|
-
declare const boolean: () => Codec<boolean>;
|
|
68
|
+
export declare const boolean: () => Codec<boolean>;
|
|
70
69
|
/**
|
|
71
70
|
* creates a codec for a fixed set of string values.
|
|
72
71
|
*
|
|
73
72
|
* @param values the allowed string values
|
|
74
73
|
* @returns the enum codec
|
|
75
74
|
*/
|
|
76
|
-
declare const enumOf: <const V extends readonly string[]>(values: V) => Codec<V[number]>;
|
|
75
|
+
export declare const enumOf: <const V extends readonly string[]>(values: V) => Codec<V[number]>;
|
|
77
76
|
/**
|
|
78
77
|
* creates a codec for a string that rejects the empty value.
|
|
79
78
|
*
|
|
@@ -83,14 +82,14 @@ declare const enumOf: <const V extends readonly string[]>(values: V) => Codec<V[
|
|
|
83
82
|
*
|
|
84
83
|
* @returns the non-empty string codec
|
|
85
84
|
*/
|
|
86
|
-
declare const nonEmpty: () => Codec<string>;
|
|
85
|
+
export declare const nonEmpty: () => Codec<string>;
|
|
87
86
|
/**
|
|
88
87
|
* wraps a codec to allow its parameter to be absent.
|
|
89
88
|
*
|
|
90
89
|
* @param codec the inner codec
|
|
91
90
|
* @returns the optional codec
|
|
92
91
|
*/
|
|
93
|
-
declare const optional: <T>(codec: Codec<T>) => OptionalCodec<T>;
|
|
92
|
+
export declare const optional: <T>(codec: Codec<T>) => OptionalCodec<T>;
|
|
94
93
|
/**
|
|
95
94
|
* wraps a codec with a default value.
|
|
96
95
|
*
|
|
@@ -98,9 +97,7 @@ declare const optional: <T>(codec: Codec<T>) => OptionalCodec<T>;
|
|
|
98
97
|
* @param fallback the default value
|
|
99
98
|
* @returns the defaulted codec
|
|
100
99
|
*/
|
|
101
|
-
declare const withDefault: <T>(codec: Codec<T>, fallback: T) => DefaultedCodec<T>;
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/routes.d.ts
|
|
100
|
+
export declare const withDefault: <T>(codec: Codec<T>, fallback: T) => DefaultedCodec<T>;
|
|
104
101
|
type Empty = Record<never, never>;
|
|
105
102
|
/**
|
|
106
103
|
* defines how a leaf route instance is keyed.
|
|
@@ -128,28 +125,28 @@ interface RouteMeta {}
|
|
|
128
125
|
type ReadonlyURLSearchParams = Omit<URLSearchParams, 'append' | 'delete' | 'set' | 'sort'>;
|
|
129
126
|
/** context passed to a route `when` predicate. */
|
|
130
127
|
interface WhenContext {
|
|
131
|
-
readonly hash: string;
|
|
132
128
|
readonly pathname: string;
|
|
133
|
-
readonly rawSearch: ReadonlyURLSearchParams;
|
|
134
129
|
readonly search: string;
|
|
130
|
+
readonly hash: string;
|
|
131
|
+
readonly rawSearch: ReadonlyURLSearchParams;
|
|
135
132
|
}
|
|
136
133
|
interface LeafShared<Params extends CodecRecord, Query extends CodecRecord> {
|
|
137
|
-
/** component to render. */
|
|
138
|
-
readonly component: ComponentType;
|
|
139
|
-
/** suspense fallback component. */
|
|
140
|
-
readonly fallback?: ReactNode;
|
|
141
|
-
/** application metadata. */
|
|
142
|
-
readonly meta?: RouteMeta;
|
|
143
|
-
/** path parameter codecs. */
|
|
144
|
-
readonly params?: Params;
|
|
145
134
|
/** absolute URL path pattern. */
|
|
146
135
|
readonly path: string;
|
|
136
|
+
/** path parameter codecs. */
|
|
137
|
+
readonly params?: Params;
|
|
147
138
|
/** query parameter codecs. */
|
|
148
139
|
readonly query?: Query;
|
|
149
|
-
/** instance-keying strategy. */
|
|
150
|
-
readonly type?: LeafType;
|
|
151
140
|
/** dynamic predicate for route matching. */
|
|
152
141
|
readonly when?: (ctx: WhenContext) => boolean;
|
|
142
|
+
/** instance-keying strategy. */
|
|
143
|
+
readonly type?: LeafType;
|
|
144
|
+
/** component to render. */
|
|
145
|
+
readonly component: ComponentType;
|
|
146
|
+
/** suspense fallback component. */
|
|
147
|
+
readonly fallback?: ReactNode;
|
|
148
|
+
/** application metadata. */
|
|
149
|
+
readonly meta?: RouteMeta;
|
|
153
150
|
}
|
|
154
151
|
/** configuration for a navigable leaf route. */
|
|
155
152
|
type RouteConfig<Params extends CodecRecord, Query extends CodecRecord> = LeafShared<Params, Query>;
|
|
@@ -159,19 +156,19 @@ interface RouteLeaf<Params extends CodecRecord = Empty, Query extends CodecRecor
|
|
|
159
156
|
}
|
|
160
157
|
/** configuration for an interior layout node. */
|
|
161
158
|
interface LayoutConfig<Children extends RouteChildren, Params extends CodecRecord> {
|
|
162
|
-
/**
|
|
163
|
-
|
|
159
|
+
/**
|
|
160
|
+
* codecs for layout parameters. parameter names must appear in all descendant leaf paths, allowing layouts
|
|
161
|
+
* to decode their own values.
|
|
162
|
+
*/
|
|
163
|
+
readonly params?: Params;
|
|
164
164
|
/** layout component rendering an outlet. */
|
|
165
165
|
readonly component: ComponentType;
|
|
166
166
|
/** suspense fallback component. */
|
|
167
167
|
readonly fallback?: ReactNode;
|
|
168
168
|
/** application metadata. */
|
|
169
169
|
readonly meta?: RouteMeta;
|
|
170
|
-
/**
|
|
171
|
-
|
|
172
|
-
* to decode their own values.
|
|
173
|
-
*/
|
|
174
|
-
readonly params?: Params;
|
|
170
|
+
/** nested child nodes. */
|
|
171
|
+
readonly children: Children;
|
|
175
172
|
}
|
|
176
173
|
/** an interior layout node. */
|
|
177
174
|
type LayoutNode<Children extends RouteChildren = RouteChildren, Params extends CodecRecord = Empty> = {
|
|
@@ -189,14 +186,14 @@ interface RouteChildren {
|
|
|
189
186
|
* @param config the route configuration
|
|
190
187
|
* @returns the route leaf node
|
|
191
188
|
*/
|
|
192
|
-
declare const route: <const Params extends CodecRecord = Empty, const Query extends CodecRecord = Empty>(config: RouteConfig<Params, Query>) => RouteLeaf<Params, Query>;
|
|
189
|
+
export declare const route: <const Params extends CodecRecord = Empty, const Query extends CodecRecord = Empty>(config: RouteConfig<Params, Query>) => RouteLeaf<Params, Query>;
|
|
193
190
|
/**
|
|
194
191
|
* defines an interior layout node.
|
|
195
192
|
*
|
|
196
193
|
* @param config the layout configuration
|
|
197
194
|
* @returns the layout node
|
|
198
195
|
*/
|
|
199
|
-
declare const layout: <const Children extends RouteChildren, const Params extends CodecRecord = Empty>(config: LayoutConfig<Children, Params>) => LayoutNode<Children, Params>;
|
|
196
|
+
export declare const layout: <const Children extends RouteChildren, const Params extends CodecRecord = Empty>(config: LayoutConfig<Children, Params>) => LayoutNode<Children, Params>;
|
|
200
197
|
/** a node resolved with an id and normalized parameters. */
|
|
201
198
|
interface ResolvedNode {
|
|
202
199
|
readonly kind: 'layout' | 'route';
|
|
@@ -204,25 +201,25 @@ interface ResolvedNode {
|
|
|
204
201
|
readonly id: string;
|
|
205
202
|
/** key name within the parent record. */
|
|
206
203
|
readonly key: string;
|
|
207
|
-
readonly node: RouteNode;
|
|
208
|
-
/** local parameter codecs. */
|
|
209
|
-
readonly params: CodecRecord;
|
|
210
204
|
/** absolute path pattern if a route. */
|
|
211
205
|
readonly path: string | undefined;
|
|
206
|
+
/** local parameter codecs. */
|
|
207
|
+
readonly params: CodecRecord;
|
|
208
|
+
readonly node: RouteNode;
|
|
212
209
|
}
|
|
213
210
|
/** a leaf node resolved with its ancestors and metadata. */
|
|
214
211
|
interface ResolvedLeaf {
|
|
215
|
-
/** ancestors list from root to leaf. */
|
|
216
|
-
readonly chain: readonly ResolvedNode[];
|
|
217
|
-
readonly leaf: RouteLeaf;
|
|
218
212
|
/** unique route name. */
|
|
219
213
|
readonly name: string;
|
|
220
|
-
/** path parameter codecs. */
|
|
221
|
-
readonly params: CodecRecord;
|
|
222
214
|
/** absolute path pattern. */
|
|
223
215
|
readonly path: string;
|
|
216
|
+
/** path parameter codecs. */
|
|
217
|
+
readonly params: CodecRecord;
|
|
224
218
|
/** query parameter codecs. */
|
|
225
219
|
readonly query: CodecRecord;
|
|
220
|
+
readonly leaf: RouteLeaf;
|
|
221
|
+
/** ancestors list from root to leaf. */
|
|
222
|
+
readonly chain: readonly ResolvedNode[];
|
|
226
223
|
}
|
|
227
224
|
/** a compiled registry of routes and nodes. */
|
|
228
225
|
interface RouteRegistry<T> {
|
|
@@ -238,11 +235,11 @@ type ValidRoutes<T> = { readonly [K in keyof T]: T[K] extends RouteNode ? T[K] :
|
|
|
238
235
|
* @returns the compiled registry
|
|
239
236
|
* @throws when route definitions violate nesting, unique names, or codec constraints
|
|
240
237
|
*/
|
|
241
|
-
declare const defineRoutes: <const T>(tree: T & ValidRoutes<T>) => RouteRegistry<T>;
|
|
238
|
+
export declare const defineRoutes: <const T>(tree: T & ValidRoutes<T>) => RouteRegistry<T>;
|
|
242
239
|
type UnionToIntersection<U> = (U extends unknown ? (arg: U) => void : never) extends ((arg: infer I) => void) ? I : never;
|
|
243
240
|
type FlattenChildren<C> = UnionToIntersection<{ [K in keyof C]: C[K] extends {
|
|
244
|
-
readonly children: infer GC;
|
|
245
241
|
readonly kind: 'layout';
|
|
242
|
+
readonly children: infer GC;
|
|
246
243
|
} ? FlattenChildren<GC> : C[K] extends {
|
|
247
244
|
readonly kind: 'route';
|
|
248
245
|
} ? { readonly [P in K]: C[K]; } : never; }[keyof C]>;
|
|
@@ -281,8 +278,6 @@ type BuildParamsOf<R, K extends RouteName<R>> = LeafBuild<LeavesMap<R>[K]>;
|
|
|
281
278
|
* `undefined` to delete the parameter. path parameters are excluded — they are not settable in place.
|
|
282
279
|
*/
|
|
283
280
|
type QueryPatchOf<R, K extends RouteName<R>> = LeafQueryPatch<LeavesMap<R>[K]>;
|
|
284
|
-
//#endregion
|
|
285
|
-
//#region src/match.d.ts
|
|
286
281
|
/** a node on a matched chain paired with its instance parameters. */
|
|
287
282
|
interface MatchedNode {
|
|
288
283
|
readonly node: ResolvedNode;
|
|
@@ -291,11 +286,11 @@ interface MatchedNode {
|
|
|
291
286
|
}
|
|
292
287
|
/** the result of matching a URL, containing the chain, leaf, name, and parameters. */
|
|
293
288
|
interface RouteMatch {
|
|
294
|
-
readonly chain: readonly MatchedNode[];
|
|
295
|
-
readonly leaf: ResolvedLeaf;
|
|
296
289
|
readonly name: string;
|
|
297
290
|
/** leaf parameters, combining path and query. */
|
|
298
291
|
readonly params: Readonly<Record<string, unknown>>;
|
|
292
|
+
readonly leaf: ResolvedLeaf;
|
|
293
|
+
readonly chain: readonly MatchedNode[];
|
|
299
294
|
}
|
|
300
295
|
/**
|
|
301
296
|
* looks up the nearest metadata value for a key on a matched chain, searching leaf-first.
|
|
@@ -304,11 +299,11 @@ interface RouteMatch {
|
|
|
304
299
|
* @param key the metadata key to resolve
|
|
305
300
|
* @returns the nearest metadata value, or undefined if none is found
|
|
306
301
|
*/
|
|
307
|
-
declare const resolveMeta: <K extends keyof RouteMeta>(match: RouteMatch, key: K) => RouteMeta[K] | undefined;
|
|
308
|
-
//#endregion
|
|
309
|
-
//#region src/history/navigation.d.ts
|
|
302
|
+
export declare const resolveMeta: <K extends keyof RouteMeta>(match: RouteMatch, key: K) => RouteMeta[K] | undefined;
|
|
310
303
|
/** options for navigation-api history. */
|
|
311
304
|
interface NavigationHistoryOptions {
|
|
305
|
+
/** window instance to bind to; defaults to global window. */
|
|
306
|
+
readonly window?: Window;
|
|
312
307
|
/**
|
|
313
308
|
* same-origin destinations the server owns, which the browser should load as a real page rather than the
|
|
314
309
|
* router rendering in-app — an OAuth entry point, a server-rendered admin area, a static file. without this
|
|
@@ -328,8 +323,6 @@ interface NavigationHistoryOptions {
|
|
|
328
323
|
* @param error failure reason
|
|
329
324
|
*/
|
|
330
325
|
readonly onError?: (error: unknown) => void;
|
|
331
|
-
/** window instance to bind to; defaults to global window. */
|
|
332
|
-
readonly window?: Window;
|
|
333
326
|
}
|
|
334
327
|
/**
|
|
335
328
|
* history implementation backed by the web navigation API.
|
|
@@ -337,7 +330,7 @@ interface NavigationHistoryOptions {
|
|
|
337
330
|
* intercepting same-document navigations converts standard page loads into in-app renders. per-revision
|
|
338
331
|
* metadata and indices are managed natively by the browser.
|
|
339
332
|
*/
|
|
340
|
-
declare class NavigationHistory implements History {
|
|
333
|
+
export declare class NavigationHistory implements History {
|
|
341
334
|
#private;
|
|
342
335
|
constructor(options?: NavigationHistoryOptions);
|
|
343
336
|
get location(): HistoryLocation;
|
|
@@ -354,24 +347,20 @@ declare class NavigationHistory implements History {
|
|
|
354
347
|
listen(listener: HistoryListener): () => void;
|
|
355
348
|
dispose(): void;
|
|
356
349
|
}
|
|
357
|
-
//#endregion
|
|
358
|
-
//#region src/view-model.d.ts
|
|
359
350
|
/** an instance node within the layout tree structure. */
|
|
360
351
|
interface InstanceNode {
|
|
361
|
-
readonly children: InstanceNode[];
|
|
362
352
|
readonly instanceKey: string;
|
|
363
353
|
readonly node: ResolvedNode;
|
|
364
354
|
readonly params: Readonly<Record<string, unknown>>;
|
|
355
|
+
readonly children: InstanceNode[];
|
|
365
356
|
}
|
|
366
357
|
/** the computed rendering view configuration. */
|
|
367
358
|
interface View {
|
|
368
|
-
/** instance keys along the active chain from root to leaf. */
|
|
369
|
-
readonly activePath: readonly string[];
|
|
370
359
|
/** the top-level pool (instances at the root outlet). */
|
|
371
360
|
readonly roots: readonly InstanceNode[];
|
|
361
|
+
/** instance keys along the active chain from root to leaf. */
|
|
362
|
+
readonly activePath: readonly string[];
|
|
372
363
|
}
|
|
373
|
-
//#endregion
|
|
374
|
-
//#region src/lazy.d.ts
|
|
375
364
|
/** a preloadable lazily-loaded component. */
|
|
376
365
|
type LazyComponent<T extends ComponentType<any>> = LazyExoticComponent<T> & {
|
|
377
366
|
/**
|
|
@@ -387,32 +376,30 @@ type LazyComponent<T extends ComponentType<any>> = LazyExoticComponent<T> & {
|
|
|
387
376
|
* @param init component module loader
|
|
388
377
|
* @returns lazy component
|
|
389
378
|
*/
|
|
390
|
-
declare const lazy: <T extends ComponentType<any>>(init: () => Promise<{
|
|
379
|
+
export declare const lazy: <T extends ComponentType<any>>(init: () => Promise<{
|
|
391
380
|
default: T;
|
|
392
381
|
}>) => LazyComponent<T>;
|
|
393
|
-
//#endregion
|
|
394
|
-
//#region src/router.d.ts
|
|
395
382
|
/** options for a navigation. */
|
|
396
383
|
interface NavigateOptions<R extends RouteRegistry<unknown>> extends HistoryNavigateOptions {
|
|
397
|
-
/** replace the active history entry instead. */
|
|
398
|
-
readonly replace?: boolean;
|
|
399
384
|
/** where to go */
|
|
400
385
|
readonly to: RouteTarget<R> | string;
|
|
386
|
+
/** replace the active history entry instead. */
|
|
387
|
+
readonly replace?: boolean;
|
|
401
388
|
}
|
|
402
389
|
/** options for the router constructor. */
|
|
403
390
|
interface RouterOptions<R extends RouteRegistry<unknown>> {
|
|
404
|
-
/**
|
|
405
|
-
readonly
|
|
391
|
+
/** compiled route registry. */
|
|
392
|
+
readonly routes: R;
|
|
406
393
|
/** backing history instance. */
|
|
407
394
|
readonly history: History;
|
|
408
|
-
/** maximum number of backward entries to keep warm. */
|
|
409
|
-
readonly max?: number;
|
|
410
395
|
/** component rendered when no route matches. */
|
|
411
396
|
readonly notFound?: ComponentType;
|
|
397
|
+
/** default fallback component shown during lazy chunk loading. */
|
|
398
|
+
readonly defaultFallback?: ReactNode;
|
|
399
|
+
/** maximum number of backward entries to keep warm. */
|
|
400
|
+
readonly max?: number;
|
|
412
401
|
/** route names of pathless singleton routes to keep warm for the router's lifetime once first visited. */
|
|
413
402
|
readonly pins?: readonly string[];
|
|
414
|
-
/** compiled route registry. */
|
|
415
|
-
readonly routes: R;
|
|
416
403
|
/** window whose scroll position the router restores, defaulting to the global one where there is one. */
|
|
417
404
|
readonly window?: Window;
|
|
418
405
|
}
|
|
@@ -422,7 +409,7 @@ interface RouterOptions<R extends RouteRegistry<unknown>> {
|
|
|
422
409
|
* this class acts as the store for the React router view, maintaining and caching active matched nodes and
|
|
423
410
|
* coordinates scrolling and focus.
|
|
424
411
|
*/
|
|
425
|
-
declare class Router<R extends RouteRegistry<unknown>> {
|
|
412
|
+
export declare class Router<R extends RouteRegistry<unknown>> {
|
|
426
413
|
#private;
|
|
427
414
|
constructor(options: RouterOptions<R>);
|
|
428
415
|
/** current view structure. */
|
|
@@ -535,8 +522,6 @@ declare class Router<R extends RouteRegistry<unknown>> {
|
|
|
535
522
|
/** detaches history listeners and disposes resources. */
|
|
536
523
|
dispose(): void;
|
|
537
524
|
}
|
|
538
|
-
//#endregion
|
|
539
|
-
//#region src/react/router-view.d.ts
|
|
540
525
|
/**
|
|
541
526
|
* renders the current view tree of the router.
|
|
542
527
|
*
|
|
@@ -547,51 +532,47 @@ declare class Router<R extends RouteRegistry<unknown>> {
|
|
|
547
532
|
* @param props.router router instance
|
|
548
533
|
* @returns rendered component tree
|
|
549
534
|
*/
|
|
550
|
-
declare const RouterView: <R extends RouteRegistry<unknown>>({ router }: {
|
|
535
|
+
export declare const RouterView: <R extends RouteRegistry<unknown>>({ router }: {
|
|
551
536
|
readonly router: Router<R>;
|
|
552
537
|
}) => ReactElement;
|
|
553
|
-
//#endregion
|
|
554
|
-
//#region src/react/outlet.d.ts
|
|
555
538
|
/**
|
|
556
539
|
* renders the child branch pool within a layout component.
|
|
557
540
|
*
|
|
558
541
|
* @returns rendered outlet child pool or null if outside a layout
|
|
559
542
|
*/
|
|
560
|
-
declare const Outlet: () => ReactElement | null;
|
|
561
|
-
//#endregion
|
|
562
|
-
//#region src/react/hooks.d.ts
|
|
543
|
+
export declare const Outlet: () => ReactElement | null;
|
|
563
544
|
/**
|
|
564
545
|
* gets the active router instance.
|
|
565
546
|
*
|
|
566
547
|
* @returns router instance
|
|
567
548
|
* @throws when used outside a router view context
|
|
568
549
|
*/
|
|
569
|
-
declare const useRouter: () => Router<RouteRegistry<unknown>>;
|
|
550
|
+
export declare const useRouter: () => Router<RouteRegistry<unknown>>;
|
|
570
551
|
/**
|
|
571
552
|
* gets the active history location.
|
|
572
553
|
*
|
|
573
554
|
* @returns history location
|
|
574
555
|
*/
|
|
575
|
-
declare const useLocation: () => HistoryLocation;
|
|
556
|
+
export declare const useLocation: () => HistoryLocation;
|
|
576
557
|
/**
|
|
577
558
|
* gets the active route match information.
|
|
578
559
|
*
|
|
579
560
|
* @returns active route match
|
|
580
561
|
*/
|
|
581
|
-
declare const useRoute: () => RouteMatch;
|
|
562
|
+
export declare const useRoute: () => RouteMatch;
|
|
582
563
|
/**
|
|
583
564
|
* gets the untyped parameter map of the nearest enclosing route node.
|
|
584
565
|
*
|
|
585
566
|
* @returns decoded parameters
|
|
586
567
|
* @throws when used outside a route tree context
|
|
587
568
|
*/
|
|
588
|
-
declare const useParams: () => Readonly<Record<string, unknown>>;
|
|
569
|
+
export declare const useParams: () => Readonly<Record<string, unknown>>;
|
|
589
570
|
/**
|
|
590
571
|
* gets whether the enclosing branch is focused (on screen).
|
|
591
572
|
*
|
|
592
573
|
* @returns true if focused
|
|
593
574
|
*/
|
|
594
|
-
declare const useIsFocused: () => boolean;
|
|
575
|
+
export declare const useIsFocused: () => boolean;
|
|
595
576
|
/**
|
|
596
577
|
* runs an effect callback only while the branch is focused.
|
|
597
578
|
*
|
|
@@ -600,15 +581,15 @@ declare const useIsFocused: () => boolean;
|
|
|
600
581
|
*
|
|
601
582
|
* @param effect effect callback
|
|
602
583
|
*/
|
|
603
|
-
declare const useFocusEffect: (effect: EffectCallback) => void;
|
|
584
|
+
export declare const useFocusEffect: (effect: EffectCallback) => void;
|
|
604
585
|
/** typed hooks bound to a specific route registry. */
|
|
605
586
|
interface RouterHooks<R extends RouteRegistry<unknown>> {
|
|
606
|
-
/** gets a route's parameters and a setter that patches its query in place. */
|
|
607
|
-
useParams<K extends RouteName<R>>(name: K): readonly [ParamsOf<R, K>, (patch: QueryPatchOf<R, K>) => void];
|
|
608
587
|
/** gets the typed router instance. */
|
|
609
588
|
useRouter(): Router<R>;
|
|
610
589
|
/** gets the active route's name and parameters. */
|
|
611
590
|
useTarget(): MatchedTarget<R>;
|
|
591
|
+
/** gets a route's parameters and a setter that patches its query in place. */
|
|
592
|
+
useParams<K extends RouteName<R>>(name: K): readonly [ParamsOf<R, K>, (patch: QueryPatchOf<R, K>) => void];
|
|
612
593
|
}
|
|
613
594
|
/**
|
|
614
595
|
* generates typed hooks bound to a specific route registry.
|
|
@@ -620,15 +601,13 @@ interface RouterHooks<R extends RouteRegistry<unknown>> {
|
|
|
620
601
|
* @returns typed hooks record
|
|
621
602
|
* @throws when used with a router built from a different registry
|
|
622
603
|
*/
|
|
623
|
-
declare const createRouterHooks: <R extends RouteRegistry<unknown>>(routes: R) => RouterHooks<R>;
|
|
624
|
-
//#endregion
|
|
625
|
-
//#region src/react/link.d.ts
|
|
604
|
+
export declare const createRouterHooks: <R extends RouteRegistry<unknown>>(routes: R) => RouterHooks<R>;
|
|
626
605
|
/** properties for the link component. */
|
|
627
606
|
interface LinkProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> {
|
|
628
|
-
/** replace the current history entry. */
|
|
629
|
-
readonly replace?: boolean;
|
|
630
607
|
/** target relative URL path. */
|
|
631
608
|
readonly to: string;
|
|
609
|
+
/** replace the current history entry. */
|
|
610
|
+
readonly replace?: boolean;
|
|
632
611
|
}
|
|
633
612
|
/**
|
|
634
613
|
* anchor element that intercepts clicks for in-app navigation.
|
|
@@ -638,6 +617,5 @@ interface LinkProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'
|
|
|
638
617
|
* @param props link properties
|
|
639
618
|
* @returns rendered anchor element
|
|
640
619
|
*/
|
|
641
|
-
declare const Link: ({
|
|
642
|
-
|
|
643
|
-
export { type BuildParamsOf, type Codec, type DefaultedCodec, type History, type HistoryAction, type HistoryEntry, type HistoryListener, type HistoryLocation, type HistoryNavigateOptions, type HistoryScrollBehavior, type HistoryUpdate, type Infer, type InstanceNode, type LayoutConfig, type LayoutNode, type LazyComponent, type LeafType, Link, type LinkProps, type MatchedNode, type MatchedTarget, type NavigateOptions, NavigationHistory, type NavigationHistoryOptions, type OptionalCodec, Outlet, type ParamsOf, type QueryPatchOf, type ReadonlyURLSearchParams, type ResolvedLeaf, type ResolvedNode, type RouteChildren, type RouteConfig, type RouteLeaf, type RouteMatch, type RouteMeta, type RouteName, type RouteNode, type RouteRegistry, type RouteTarget, Router, type RouterHooks, type RouterOptions, RouterView, type View, type WhenContext, boolean, createRouterHooks, defineRoutes, enumOf, integer, layout, lazy, nonEmpty, optional, resolveMeta, route, string, useFocusEffect, useIsFocused, useLocation, useParams, useRoute, useRouter, withDefault };
|
|
620
|
+
export declare const Link: ({ to, replace, children, onClick, ...rest }: LinkProps) => ReactElement;
|
|
621
|
+
export type { BuildParamsOf, Codec, DefaultedCodec, History, HistoryAction, HistoryEntry, HistoryListener, HistoryLocation, HistoryNavigateOptions, HistoryScrollBehavior, HistoryUpdate, Infer, InstanceNode, LayoutConfig, LayoutNode, LazyComponent, LeafType, LinkProps, MatchedNode, MatchedTarget, NavigateOptions, NavigationHistoryOptions, OptionalCodec, ParamsOf, QueryPatchOf, ReadonlyURLSearchParams, ResolvedLeaf, ResolvedNode, RouteChildren, RouteConfig, RouteLeaf, RouteMatch, RouteMeta, RouteName, RouteNode, RouteRegistry, RouteTarget, RouterHooks, RouterOptions, View, WhenContext };
|