@kitbag/router 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/kitbag-router.d.ts +159 -760
- package/dist/kitbag-router.js +850 -794
- package/dist/kitbag-router.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/kitbag-router.d.ts
CHANGED
|
@@ -55,13 +55,6 @@ declare type __VLS_WithTemplateSlots_2<T, S> = T & {
|
|
|
55
55
|
*/
|
|
56
56
|
export declare type AddAfterRouteHook = (hook: AfterRouteHook) => RouteHookRemove;
|
|
57
57
|
|
|
58
|
-
/**
|
|
59
|
-
* Adds a hook that is called after a route change. Returns a function to remove the hook.
|
|
60
|
-
* @param hook - {@link AfterRouteHook} The hook function to add.
|
|
61
|
-
* @returns {RouteHookRemove} A function that removes the added hook.
|
|
62
|
-
*/
|
|
63
|
-
declare type AddAfterRouteHook_2 = (hook: AfterRouteHook_2) => RouteHookRemove_2
|
|
64
|
-
|
|
65
58
|
/**
|
|
66
59
|
* Adds a hook that is called before a route change. Returns a function to remove the hook.
|
|
67
60
|
* @param hook - {@link BeforeRouteHook} The hook function to add.
|
|
@@ -69,13 +62,6 @@ declare type AddAfterRouteHook_2 = (hook: AfterRouteHook_2) => RouteHookRemove_2
|
|
|
69
62
|
*/
|
|
70
63
|
export declare type AddBeforeRouteHook = (hook: BeforeRouteHook) => RouteHookRemove;
|
|
71
64
|
|
|
72
|
-
/**
|
|
73
|
-
* Adds a hook that is called before a route change. Returns a function to remove the hook.
|
|
74
|
-
* @param hook - {@link BeforeRouteHook} The hook function to add.
|
|
75
|
-
* @returns {RouteHookRemove} A function that removes the added hook.
|
|
76
|
-
*/
|
|
77
|
-
declare type AddBeforeRouteHook_2 = (hook: BeforeRouteHook_2) => RouteHookRemove_2
|
|
78
|
-
|
|
79
65
|
/**
|
|
80
66
|
* Represents a function called after a route change has occurred.
|
|
81
67
|
* @param to - {@link ResolvedRoute} The resolved route the router has navigated to.
|
|
@@ -84,24 +70,11 @@ declare type AddBeforeRouteHook_2 = (hook: BeforeRouteHook_2) => RouteHookRemove
|
|
|
84
70
|
*/
|
|
85
71
|
export declare type AfterRouteHook = (to: ResolvedRoute, context: AfterRouteHookContext) => MaybePromise<void>;
|
|
86
72
|
|
|
87
|
-
/**
|
|
88
|
-
* Represents a function called after a route change has occurred.
|
|
89
|
-
* @param to - {@link ResolvedRoute} The resolved route the router has navigated to.
|
|
90
|
-
* @param context - {@link AfterRouteHookContext} The context providing functions and state for the routing operation.
|
|
91
|
-
* @returns Possibly a promise that resolves when the hook's logic has completed.
|
|
92
|
-
*/
|
|
93
|
-
declare type AfterRouteHook_2 = (to: ResolvedRoute_2, context: AfterRouteHookContext_2) => MaybePromise_2<void>
|
|
94
|
-
|
|
95
73
|
/**
|
|
96
74
|
* Context provided to route hooks, containing context of previous route and functions for triggering rejections and push/replace to another route.
|
|
97
75
|
*/
|
|
98
76
|
declare type AfterRouteHookContext = RouteHookContext;
|
|
99
77
|
|
|
100
|
-
/**
|
|
101
|
-
* Context provided to route hooks, containing context of previous route and functions for triggering rejections and push/replace to another route.
|
|
102
|
-
*/
|
|
103
|
-
declare type AfterRouteHookContext_2 = RouteHookContext_2
|
|
104
|
-
|
|
105
78
|
/**
|
|
106
79
|
* Enumerates the lifecycle events for after route hooks.
|
|
107
80
|
*/
|
|
@@ -115,21 +88,6 @@ export declare type AfterRouteHookResponse<TRoutes extends Routes> = RouteHookSu
|
|
|
115
88
|
|
|
116
89
|
declare type AllPropertiesAreOptional<T> = Record<string, unknown> extends T ? true : IsEmptyObject<OnlyRequiredProperties<T>>;
|
|
117
90
|
|
|
118
|
-
declare type AllPropertiesAreOptional_2<T> = Record<string, unknown> extends T
|
|
119
|
-
? true
|
|
120
|
-
: IsEmptyObject_2<OnlyRequiredProperties_2<T>>
|
|
121
|
-
|
|
122
|
-
declare type BaseResolvedRoute = Route & {
|
|
123
|
-
path: {
|
|
124
|
-
params: Record<string, unknown>;
|
|
125
|
-
};
|
|
126
|
-
query: {
|
|
127
|
-
params: Record<string, unknown>;
|
|
128
|
-
};
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
declare type BaseResolvedRoute_2 = Route_2 & { path: { params: Record<string, unknown> }, query: { params: Record<string, unknown> } }
|
|
132
|
-
|
|
133
91
|
declare type BaseRoute = {
|
|
134
92
|
key: string;
|
|
135
93
|
disabled: false;
|
|
@@ -141,8 +99,6 @@ declare type BaseRoute = {
|
|
|
141
99
|
};
|
|
142
100
|
};
|
|
143
101
|
|
|
144
|
-
declare type BaseRoute_2 = { key: string, disabled: false, path: { params: Record<string, unknown> }, query: { params: Record<string, unknown> } }
|
|
145
|
-
|
|
146
102
|
/**
|
|
147
103
|
* Represents a function called before a route change, potentially altering the routing operation.
|
|
148
104
|
* @param to - {@link ResolvedRoute} The resolved route the router is navigating to.
|
|
@@ -151,14 +107,6 @@ declare type BaseRoute_2 = { key: string, disabled: false, path: { params: Recor
|
|
|
151
107
|
*/
|
|
152
108
|
export declare type BeforeRouteHook = (to: ResolvedRoute, context: BeforeRouteHookContext) => MaybePromise<void>;
|
|
153
109
|
|
|
154
|
-
/**
|
|
155
|
-
* Represents a function called before a route change, potentially altering the routing operation.
|
|
156
|
-
* @param to - {@link ResolvedRoute} The resolved route the router is navigating to.
|
|
157
|
-
* @param context - {@link BeforeRouteHookContext} The context providing functions and state for the routing operation.
|
|
158
|
-
* @returns Possibly a promise that resolves when the hook's logic has completed.
|
|
159
|
-
*/
|
|
160
|
-
declare type BeforeRouteHook_2 = (to: ResolvedRoute_2, context: BeforeRouteHookContext_2) => MaybePromise_2<void>
|
|
161
|
-
|
|
162
110
|
/**
|
|
163
111
|
* Context provided to route hooks, containing context of previous route and functions for triggering rejections, push/replace to another route,
|
|
164
112
|
* as well as aborting current route change.
|
|
@@ -167,14 +115,6 @@ declare type BeforeRouteHookContext = RouteHookContext & {
|
|
|
167
115
|
abort: RouteHookAbort;
|
|
168
116
|
};
|
|
169
117
|
|
|
170
|
-
/**
|
|
171
|
-
* Context provided to route hooks, containing context of previous route and functions for triggering rejections, push/replace to another route,
|
|
172
|
-
* as well as aborting current route change.
|
|
173
|
-
*/
|
|
174
|
-
declare type BeforeRouteHookContext_2 = RouteHookContext_2 & {
|
|
175
|
-
abort: RouteHookAbort_2,
|
|
176
|
-
}
|
|
177
|
-
|
|
178
118
|
/**
|
|
179
119
|
* Enumerates the lifecycle events for before route hooks.
|
|
180
120
|
*/
|
|
@@ -188,12 +128,8 @@ export declare type BeforeRouteHookResponse<TRoutes extends Routes> = RouteHookS
|
|
|
188
128
|
|
|
189
129
|
declare const builtInRejections: ['NotFound'];
|
|
190
130
|
|
|
191
|
-
declare const builtInRejections_2: ['NotFound'] = ['NotFound'];
|
|
192
|
-
|
|
193
131
|
declare type BuiltInRejectionType = typeof builtInRejections[number];
|
|
194
132
|
|
|
195
|
-
declare type BuiltInRejectionType_2 = typeof builtInRejections_2[number]
|
|
196
|
-
|
|
197
133
|
/**
|
|
198
134
|
* Represents properties for child routes, including required component, name, and path.
|
|
199
135
|
*/
|
|
@@ -220,32 +156,6 @@ export declare type ChildRouteProps = (WithComponent | WithComponents) & WithHoo
|
|
|
220
156
|
meta?: RouteMeta;
|
|
221
157
|
};
|
|
222
158
|
|
|
223
|
-
/**
|
|
224
|
-
* Represents properties for child routes, including required component, name, and path.
|
|
225
|
-
*/
|
|
226
|
-
declare type ChildRouteProps_2 = (WithComponent_2 | WithComponents_2) & WithHooks_2 & {
|
|
227
|
-
/**
|
|
228
|
-
* Name for route, used to create route keys and in navigation.
|
|
229
|
-
*/
|
|
230
|
-
name: string,
|
|
231
|
-
/**
|
|
232
|
-
* Children routes, expected type comes from `createRoutes()`
|
|
233
|
-
*/
|
|
234
|
-
disabled?: boolean,
|
|
235
|
-
/**
|
|
236
|
-
* Path part of URL.
|
|
237
|
-
*/
|
|
238
|
-
path: string | Path_2,
|
|
239
|
-
/**
|
|
240
|
-
* Query (aka search) part of URL.
|
|
241
|
-
*/
|
|
242
|
-
query?: string | Query_2,
|
|
243
|
-
/**
|
|
244
|
-
* Represents additional metadata associated with a route, customizable via declaration merging.
|
|
245
|
-
*/
|
|
246
|
-
meta?: RouteMeta_2,
|
|
247
|
-
}
|
|
248
|
-
|
|
249
159
|
declare type CombineName<TParentName extends string | undefined, TChildName extends string | undefined> = TParentName extends string ? TChildName extends string ? `${TParentName}.${TChildName}` : TParentName : TChildName extends string ? TChildName : '';
|
|
250
160
|
|
|
251
161
|
declare type CombinePath<TParent extends Path, TChild extends Path> = ToPath<TParent> extends {
|
|
@@ -290,6 +200,8 @@ export declare function component<TComponent extends Component>(component: TComp
|
|
|
290
200
|
|
|
291
201
|
declare type Constructor = new (...args: any) => any;
|
|
292
202
|
|
|
203
|
+
export declare function createExternalRoutes<const TRoutes extends ExternalRouteProps[]>(routes: TRoutes): FlattenRoutes<TRoutes>;
|
|
204
|
+
|
|
293
205
|
export declare function createParam<TParam extends ParamWithDefault>(param: TParam): TParam;
|
|
294
206
|
|
|
295
207
|
export declare function createParam<TParam extends Param>(param: TParam): ParamGetSet<ExtractParamType<TParam>>;
|
|
@@ -321,6 +233,8 @@ export declare function createParam<TParam extends Param>(param: TParam, default
|
|
|
321
233
|
*/
|
|
322
234
|
export declare function createRouter<const T extends Routes>(routes: T, options?: RouterOptions): Router<T>;
|
|
323
235
|
|
|
236
|
+
export declare function createRouter<const T extends Routes>(arrayOfRoutes: T[], options?: RouterOptions): Router<T>;
|
|
237
|
+
|
|
324
238
|
/**
|
|
325
239
|
* Creates an array of routes from a defined set of route properties, handling hierarchical route combinations.
|
|
326
240
|
* This function also validates for duplicate parameter keys across the combined routes.
|
|
@@ -328,7 +242,7 @@ export declare function createRouter<const T extends Routes>(routes: T, options?
|
|
|
328
242
|
* @param routesProps - An array of route properties used to configure and create routes.
|
|
329
243
|
* @returns An array of fully configured Route instances.
|
|
330
244
|
*/
|
|
331
|
-
export declare function createRoutes<const TRoutes extends
|
|
245
|
+
export declare function createRoutes<const TRoutes extends RouteProps[]>(routes: TRoutes): FlattenRoutes<TRoutes>;
|
|
332
246
|
|
|
333
247
|
/**
|
|
334
248
|
* An error thrown when duplicate parameters are detected in a route when creating a router.
|
|
@@ -343,62 +257,82 @@ export declare class DuplicateParamsError extends Error {
|
|
|
343
257
|
constructor(paramName: string);
|
|
344
258
|
}
|
|
345
259
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
260
|
+
declare type ExternalRouteChildProps = {
|
|
261
|
+
/**
|
|
262
|
+
* Represents the host for this route. Used for external routes.
|
|
263
|
+
*/
|
|
264
|
+
host?: string;
|
|
265
|
+
/**
|
|
266
|
+
* Name for route, used to create route keys and in navigation.
|
|
267
|
+
*/
|
|
268
|
+
name: string;
|
|
269
|
+
/**
|
|
270
|
+
* Children routes, expected type comes from `createRoutes()`
|
|
271
|
+
*/
|
|
272
|
+
disabled?: boolean;
|
|
273
|
+
/**
|
|
274
|
+
* Path part of URL.
|
|
275
|
+
*/
|
|
276
|
+
path: string | Path;
|
|
277
|
+
/**
|
|
278
|
+
* Query (aka search) part of URL.
|
|
279
|
+
*/
|
|
280
|
+
query?: string | Query;
|
|
281
|
+
/**
|
|
282
|
+
* Children routes, cannot have a value for a child route.
|
|
283
|
+
*/
|
|
284
|
+
children?: never;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
declare type ExternalRouteParentProps = {
|
|
288
|
+
/**
|
|
289
|
+
* Represents the host for this route. Used for external routes.
|
|
290
|
+
*/
|
|
291
|
+
host?: string;
|
|
292
|
+
/**
|
|
293
|
+
* Name for route, used to create route keys and in navigation.
|
|
294
|
+
*/
|
|
295
|
+
name?: string;
|
|
296
|
+
/**
|
|
297
|
+
* Disabled routes will not ever match but can still provide physical structure, nested children behave normally.
|
|
298
|
+
*/
|
|
299
|
+
disabled?: boolean;
|
|
300
|
+
/**
|
|
301
|
+
* Path part of URL.
|
|
302
|
+
*/
|
|
303
|
+
path: string | Path;
|
|
304
|
+
/**
|
|
305
|
+
* Query (aka search) part of URL.
|
|
306
|
+
*/
|
|
307
|
+
query?: string | Query;
|
|
308
|
+
/**
|
|
309
|
+
* Children routes, expected type comes from `createExternalRoutes()`
|
|
310
|
+
*/
|
|
311
|
+
children: ExternalRoutes;
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
declare type ExternalRouteProps = ExternalRouteParentProps | ExternalRouteChildProps;
|
|
315
|
+
|
|
316
|
+
declare type ExternalRoutes = Route<string, '', Path, Query, boolean>[];
|
|
352
317
|
|
|
353
318
|
/**
|
|
354
319
|
* Extracts the parameter name from a string, handling optional parameters denoted by a leading '?'.
|
|
355
320
|
* @template TParam - The string from which to extract the parameter name.
|
|
356
321
|
* @returns The extracted parameter name, or never if the parameter string is empty.
|
|
357
322
|
*/
|
|
358
|
-
declare type
|
|
359
|
-
TParam extends string
|
|
360
|
-
> = TParam extends `?${infer Param}`
|
|
361
|
-
? Param extends ''
|
|
362
|
-
? never
|
|
363
|
-
: Param
|
|
364
|
-
: TParam extends ''
|
|
365
|
-
? never
|
|
366
|
-
: TParam
|
|
323
|
+
export declare type ExtractParamName<TParam extends PropertyKey> = TParam extends `?${infer Param}` ? Param extends '' ? never : Param : TParam extends '' ? never : TParam;
|
|
367
324
|
|
|
368
325
|
declare type ExtractParamsFromPathString<TPath extends string, TParams extends Record<string, Param | undefined> = Record<never, never>> = TPath extends `${string}${ParamStart}${infer Param}${ParamEnd}${infer Rest}` ? MergeParams<{
|
|
369
|
-
[P in
|
|
326
|
+
[P in Param]: ExtractPathParamType<Param, TParams>;
|
|
370
327
|
}, ExtractParamsFromPathString<Rest, TParams>> : Record<never, never>;
|
|
371
328
|
|
|
372
|
-
declare type ExtractParamsFromPathString_2<
|
|
373
|
-
TPath extends string,
|
|
374
|
-
TParams extends Record<string, Param_2 | undefined> = Record<never, never>
|
|
375
|
-
> = TPath extends `${string}${ParamStart_2}${infer Param}${ParamEnd_2}${infer Rest}`
|
|
376
|
-
? MergeParams_2<{ [P in ExtractParamName_2<Param>]: ExtractPathParamType_2<Param, TParams> }, ExtractParamsFromPathString_2<Rest, TParams>>
|
|
377
|
-
: Record<never, never>
|
|
378
|
-
|
|
379
329
|
/**
|
|
380
330
|
* Extracts the actual type from a parameter type, handling getters, setters, and potential undefined values.
|
|
381
331
|
* This type also is responsible for narrowing possibly undefined values when the param has a default value.
|
|
382
332
|
* @template TParam - The parameter type.
|
|
383
333
|
* @returns The extracted type, or 'string' as a fallback.
|
|
384
334
|
*/
|
|
385
|
-
export declare type ExtractParamType<TParam extends Param> = TParam extends ParamGetSet<infer Type> ?
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* Extracts the actual type from a parameter type, handling getters, setters, and potential undefined values.
|
|
389
|
-
* This type also is responsible for narrowing possibly undefined values when the param has a default value.
|
|
390
|
-
* @template TParam - The parameter type.
|
|
391
|
-
* @returns The extracted type, or 'string' as a fallback.
|
|
392
|
-
*/
|
|
393
|
-
declare type ExtractParamType_2<TParam extends Param_2> = TParam extends ParamGetSet_2<infer Type>
|
|
394
|
-
? TParam extends IsOptionalParam_2
|
|
395
|
-
? TParam extends ParamWithDefault_2
|
|
396
|
-
? Type
|
|
397
|
-
: Type | undefined
|
|
398
|
-
: Type
|
|
399
|
-
: TParam extends ParamGetter_2
|
|
400
|
-
? ReturnType<TParam>
|
|
401
|
-
: string
|
|
335
|
+
export declare type ExtractParamType<TParam extends Param, TParamKey extends PropertyKey = string> = TParam extends ParamGetSet<infer Type> ? TParamKey extends `?${string}` ? TParam extends ParamWithDefault ? Type : Type | undefined : Type : TParam extends ParamGetter ? TParamKey extends `?${string}` ? ReturnType<TParam> | undefined : ReturnType<TParam> : TParamKey extends `?${string}` ? string | undefined : string;
|
|
402
336
|
|
|
403
337
|
/**
|
|
404
338
|
* Transforms a record of parameter types into a type with optional properties where the original type allows undefined.
|
|
@@ -406,43 +340,14 @@ declare type ExtractParamType_2<TParam extends Param_2> = TParam extends ParamGe
|
|
|
406
340
|
* @returns A new type with the appropriate properties marked as optional.
|
|
407
341
|
*/
|
|
408
342
|
export declare type ExtractParamTypes<TParams extends Record<string, Param>> = Identity<MakeOptional<{
|
|
409
|
-
[K in keyof TParams]: ExtractParamType<TParams[K]>;
|
|
343
|
+
[K in keyof TParams as ExtractParamName<K>]: ExtractParamType<TParams[K], K>;
|
|
410
344
|
}>>;
|
|
411
345
|
|
|
412
|
-
/**
|
|
413
|
-
* Transforms a record of parameter types into a type with optional properties where the original type allows undefined.
|
|
414
|
-
* @template TParams - The record of parameter types, possibly including undefined.
|
|
415
|
-
* @returns A new type with the appropriate properties marked as optional.
|
|
416
|
-
*/
|
|
417
|
-
declare type ExtractParamTypes_2<TParams extends Record<string, Param_2>> = Identity_2<MakeOptional_2<{
|
|
418
|
-
[K in keyof TParams]: ExtractParamType_2<TParams[K]>
|
|
419
|
-
}>>
|
|
420
|
-
|
|
421
346
|
declare type ExtractParamTypesWithoutLosingOptional<TParams extends Record<string, Param>> = Identity<MakeOptional<{
|
|
422
|
-
[K in keyof TParams]: ExtractParamTypeWithoutLosingOptional<TParams[K]>;
|
|
347
|
+
[K in keyof TParams as ExtractParamName<K>]: ExtractParamTypeWithoutLosingOptional<TParams[K], K>;
|
|
423
348
|
}>>;
|
|
424
349
|
|
|
425
|
-
declare type
|
|
426
|
-
[K in keyof TParams]: ExtractParamTypeWithoutLosingOptional_2<TParams[K]>
|
|
427
|
-
}>>
|
|
428
|
-
|
|
429
|
-
declare type ExtractParamTypeWithoutLosingOptional<TParam extends Param> = TParam extends ParamGetSet<infer Type> ? TParam extends IsOptionalParam ? Type | undefined : Type : TParam extends ParamGetter ? ReturnType<TParam> : string;
|
|
430
|
-
|
|
431
|
-
declare type ExtractParamTypeWithoutLosingOptional_2<TParam extends Param_2> = TParam extends ParamGetSet_2<infer Type>
|
|
432
|
-
? TParam extends IsOptionalParam_2
|
|
433
|
-
? Type | undefined
|
|
434
|
-
: Type
|
|
435
|
-
: TParam extends ParamGetter_2
|
|
436
|
-
? ReturnType<TParam>
|
|
437
|
-
: string
|
|
438
|
-
|
|
439
|
-
/**
|
|
440
|
-
* Determines the type of a path parameter from a record of parameter types, considering optional parameters.
|
|
441
|
-
* @template TParam - The parameter name string.
|
|
442
|
-
* @template TParams - The record object mapping parameter names to their types.
|
|
443
|
-
* @returns The type associated with the parameter, or StringConstructor if unspecified; may be undefined for optional parameters.
|
|
444
|
-
*/
|
|
445
|
-
export declare type ExtractPathParamType<TParam extends string, TParams extends Record<string, Param | undefined>> = TParam extends `?${infer OptionalParam}` ? OptionalParam extends keyof TParams ? TParams[OptionalParam] extends Param ? OptionalParamGetSet<TParams[OptionalParam]> : OptionalParamGetSet<StringConstructor> : OptionalParamGetSet<StringConstructor> : TParam extends keyof TParams ? TParams[TParam] : StringConstructor;
|
|
350
|
+
declare type ExtractParamTypeWithoutLosingOptional<TParam extends Param, TParamKey extends PropertyKey> = TParam extends ParamGetSet<infer Type> ? TParamKey extends `?${string}` ? Type | undefined : Type : TParam extends ParamGetter ? TParamKey extends `?${string}` ? ReturnType<TParam> | undefined : ReturnType<TParam> : TParamKey extends `?${string}` ? string | undefined : string;
|
|
446
351
|
|
|
447
352
|
/**
|
|
448
353
|
* Determines the type of a path parameter from a record of parameter types, considering optional parameters.
|
|
@@ -450,31 +355,13 @@ export declare type ExtractPathParamType<TParam extends string, TParams extends
|
|
|
450
355
|
* @template TParams - The record object mapping parameter names to their types.
|
|
451
356
|
* @returns The type associated with the parameter, or StringConstructor if unspecified; may be undefined for optional parameters.
|
|
452
357
|
*/
|
|
453
|
-
declare type
|
|
454
|
-
TParam extends string,
|
|
455
|
-
TParams extends Record<string, Param_2 | undefined>
|
|
456
|
-
> = TParam extends `?${infer OptionalParam}`
|
|
457
|
-
? OptionalParam extends keyof TParams
|
|
458
|
-
? TParams[OptionalParam] extends Param_2
|
|
459
|
-
? OptionalParamGetSet_2<TParams[OptionalParam]>
|
|
460
|
-
: OptionalParamGetSet_2<StringConstructor>
|
|
461
|
-
: OptionalParamGetSet_2<StringConstructor>
|
|
462
|
-
: TParam extends keyof TParams
|
|
463
|
-
? TParams[TParam]
|
|
464
|
-
: StringConstructor
|
|
358
|
+
export declare type ExtractPathParamType<TParam extends string, TParams extends Record<string, Param | undefined>> = TParam extends `?${infer OptionalParam}` ? OptionalParam extends keyof TParams ? TParams[OptionalParam] : StringConstructor : TParam extends keyof TParams ? TParams[TParam] : StringConstructor;
|
|
465
359
|
|
|
466
360
|
declare type ExtractQueryParamsFromQueryString<TQuery extends string, TParams extends Record<string, Param | undefined> = Record<never, never>> = TQuery extends `${string}=${ParamStart}${infer Param}${ParamEnd}${infer Rest}` ? MergeParams<{
|
|
467
|
-
[P in
|
|
361
|
+
[P in Param]: ExtractPathParamType<Param, TParams>;
|
|
468
362
|
}, ExtractQueryParamsFromQueryString<Rest, TParams>> : Record<never, never>;
|
|
469
363
|
|
|
470
|
-
declare type
|
|
471
|
-
TQuery extends string,
|
|
472
|
-
TParams extends Record<string, Param_2 | undefined> = Record<never, never>
|
|
473
|
-
> = TQuery extends `${string}=${ParamStart_2}${infer Param}${ParamEnd_2}${infer Rest}`
|
|
474
|
-
? MergeParams_2<{ [P in ExtractParamName_2<Param>]: ExtractPathParamType_2<Param, TParams> }, ExtractQueryParamsFromQueryString_2<Rest, TParams>>
|
|
475
|
-
: Record<never, never>
|
|
476
|
-
|
|
477
|
-
declare type ExtractRouteChildren<TRoute extends RouteProps> = TRoute extends ParentRouteProps ? TRoute['children'] extends Route[] ? TRoute['children'] : [] : [];
|
|
364
|
+
declare type ExtractRouteChildren<TRoute extends RouteProps | ExternalRouteProps> = TRoute extends ParentRouteProps ? TRoute['children'] extends Route[] ? TRoute['children'] : [] : [];
|
|
478
365
|
|
|
479
366
|
/**
|
|
480
367
|
* Extracts combined types of path and query parameters for a given route, creating a unified parameter object.
|
|
@@ -489,20 +376,7 @@ export declare type ExtractRouteParamTypes<TRoute> = TRoute extends {
|
|
|
489
376
|
query: {
|
|
490
377
|
params: infer QueryParams extends Record<string, Param>;
|
|
491
378
|
};
|
|
492
|
-
} ? ExtractParamTypes<MergeParams<PathParams, QueryParams>> :
|
|
493
|
-
|
|
494
|
-
/**
|
|
495
|
-
* Extracts combined types of path and query parameters for a given route, creating a unified parameter object.
|
|
496
|
-
* This parameter object type represents the expected type when accessing params from router.route or useRoute.
|
|
497
|
-
* @template TRoute - The route type from which to extract and merge parameter types.
|
|
498
|
-
* @returns A record of parameter names to their respective types, extracted and merged from both path and query parameters.
|
|
499
|
-
*/
|
|
500
|
-
declare type ExtractRouteParamTypes_2<TRoute> = TRoute extends {
|
|
501
|
-
path: { params: infer PathParams extends Record<string, Param_2> },
|
|
502
|
-
query: { params: infer QueryParams extends Record<string, Param_2> },
|
|
503
|
-
}
|
|
504
|
-
? ExtractParamTypes_2<MergeParams_2<PathParams, QueryParams>>
|
|
505
|
-
: Record<string, unknown>
|
|
379
|
+
} ? ExtractParamTypes<MergeParams<PathParams, QueryParams>> : {};
|
|
506
380
|
|
|
507
381
|
declare type ExtractRouteParamTypesWithoutLosingOptional<TRoute> = TRoute extends {
|
|
508
382
|
path: {
|
|
@@ -513,23 +387,18 @@ declare type ExtractRouteParamTypesWithoutLosingOptional<TRoute> = TRoute extend
|
|
|
513
387
|
};
|
|
514
388
|
} ? ExtractParamTypesWithoutLosingOptional<MergeParams<PathParams, QueryParams>> : Record<string, unknown>;
|
|
515
389
|
|
|
516
|
-
declare type ExtractRouteParamTypesWithoutLosingOptional_2<TRoute> = TRoute extends {
|
|
517
|
-
path: { params: infer PathParams extends Record<string, Param_2> },
|
|
518
|
-
query: { params: infer QueryParams extends Record<string, Param_2> },
|
|
519
|
-
}
|
|
520
|
-
? ExtractParamTypesWithoutLosingOptional_2<MergeParams_2<PathParams, QueryParams>>
|
|
521
|
-
: Record<string, unknown>
|
|
522
|
-
|
|
523
390
|
declare type Flatten<T extends any[]> = T extends [infer First, ...infer Rest] ? First extends unknown[] ? Flatten<[...First, ...Flatten<Rest>]> : [First, ...Flatten<Rest>] : [];
|
|
524
391
|
|
|
525
|
-
declare type FlattenRoute<TRoute extends RouteProps, TKey extends string = string & TRoute['name'],
|
|
526
|
-
|
|
392
|
+
declare type FlattenRoute<TRoute extends RouteProps | ExternalRouteProps, TKey extends string = string & TRoute['name'], THost extends string = TRoute extends {
|
|
393
|
+
host: infer T extends string;
|
|
394
|
+
} ? T : '', TPath extends Path = ToPath<TRoute['path']>, TQuery extends Query = ToQuery<TRoute['query']>, TDisabled extends boolean = TRoute['disabled'] extends boolean ? TRoute['disabled'] : false, TChildren extends Route[] = ExtractRouteChildren<TRoute>> = [
|
|
395
|
+
Route<TKey, THost, TPath, TQuery, TDisabled>,
|
|
527
396
|
...{
|
|
528
|
-
[K in keyof TChildren]: Route<CombineName<TKey, TChildren[K]['key']>, CombinePath<TPath, TChildren[K]['path']>, CombineQuery<TQuery, TChildren[K]['query']>, TChildren[K]['disabled']>;
|
|
397
|
+
[K in keyof TChildren]: Route<CombineName<TKey, TChildren[K]['key']>, THost, CombinePath<TPath, TChildren[K]['path']>, CombineQuery<TQuery, TChildren[K]['query']>, TChildren[K]['disabled']>;
|
|
529
398
|
}
|
|
530
399
|
];
|
|
531
400
|
|
|
532
|
-
declare type FlattenRoutes<TRoutes extends Readonly<RouteProps[]>> = Flatten<[
|
|
401
|
+
declare type FlattenRoutes<TRoutes extends Readonly<RouteProps[] | ExternalRouteProps[]>> = Flatten<[
|
|
533
402
|
...{
|
|
534
403
|
[K in keyof TRoutes]: FlattenRoute<TRoutes[K]>;
|
|
535
404
|
}
|
|
@@ -539,22 +408,8 @@ declare type Identity<T> = T extends object ? {} & {
|
|
|
539
408
|
[P in keyof T as T[P] extends never ? never : P]: T[P];
|
|
540
409
|
} : T;
|
|
541
410
|
|
|
542
|
-
declare type Identity_2<T> = T extends object ? {} & {
|
|
543
|
-
[P in keyof T as T[P] extends never ? never : P]: T[P]
|
|
544
|
-
} : T
|
|
545
|
-
|
|
546
411
|
declare type IsEmptyObject<T> = T extends Record<string, never> ? (keyof T extends never ? true : false) : false;
|
|
547
412
|
|
|
548
|
-
declare type IsEmptyObject_2<T> = T extends Record<string, never> ? (keyof T extends never ? true : false) : false
|
|
549
|
-
|
|
550
|
-
declare type IsOptionalParam = {
|
|
551
|
-
[optionalParamKey]: true;
|
|
552
|
-
};
|
|
553
|
-
|
|
554
|
-
declare type IsOptionalParam_2 = {
|
|
555
|
-
[optionalParamKey_2]: true,
|
|
556
|
-
}
|
|
557
|
-
|
|
558
413
|
/**
|
|
559
414
|
* Type guard to check if a value conforms to the ParamGetSet type.
|
|
560
415
|
* @param value - The value to check.
|
|
@@ -582,7 +437,27 @@ export declare function isParentRouteWithoutComponent(value: RouteProps): value
|
|
|
582
437
|
|
|
583
438
|
export declare function isRoute(route: unknown): route is RouterRoute;
|
|
584
439
|
|
|
585
|
-
export declare function isRoute<TRouteKey extends
|
|
440
|
+
export declare function isRoute<TRoute extends RouterRoute, TRouteKey extends TRoute['key']>(route: TRoute, routeKey: TRouteKey, options: IsRouteOptions & {
|
|
441
|
+
exact: true;
|
|
442
|
+
}): route is TRoute & {
|
|
443
|
+
key: TRouteKey;
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
export declare function isRoute<TRoute extends RouterRoute, TRouteKey extends TRoute['key']>(route: TRoute, routeKey: TRouteKey, options?: IsRouteOptions): route is TRoute & {
|
|
447
|
+
key: `${TRouteKey}${string}`;
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
export declare function isRoute<TRouteKey extends RegisteredRoutesKey>(route: unknown, routeKey: TRouteKey, options: IsRouteOptions & {
|
|
451
|
+
exact: true;
|
|
452
|
+
}): route is RegisteredRouterRoute & {
|
|
453
|
+
key: TRouteKey;
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
export declare function isRoute<TRouteKey extends RegisteredRoutesKey>(route: unknown, routeKey: TRouteKey, options?: IsRouteOptions): route is RegisteredRouterRoute & {
|
|
457
|
+
key: `${TRouteKey}${string}`;
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
export declare function isRoute(route: unknown, routeKey?: string, options?: IsRouteOptions): boolean;
|
|
586
461
|
|
|
587
462
|
declare type IsRouteOptions = {
|
|
588
463
|
exact?: boolean;
|
|
@@ -602,20 +477,10 @@ declare type MakeOptional<T> = {
|
|
|
602
477
|
[P in Exclude<keyof T, WithOptionalProperties<T>>]: T[P];
|
|
603
478
|
};
|
|
604
479
|
|
|
605
|
-
declare type MakeOptional_2<T> = {
|
|
606
|
-
[P in WithOptionalProperties_2<T>]?: T[P];
|
|
607
|
-
} & {
|
|
608
|
-
[P in Exclude<keyof T, WithOptionalProperties_2<T>>]: T[P];
|
|
609
|
-
}
|
|
610
|
-
|
|
611
480
|
declare type MaybeArray<T> = T | T[];
|
|
612
481
|
|
|
613
|
-
declare type MaybeArray_2<T> = T | T[]
|
|
614
|
-
|
|
615
482
|
declare type MaybePromise<T> = T | Promise<T>;
|
|
616
483
|
|
|
617
|
-
declare type MaybePromise_2<T> = T | Promise<T>
|
|
618
|
-
|
|
619
484
|
/**
|
|
620
485
|
* Merges two parameter type records, ensuring no overlap in properties.
|
|
621
486
|
* @template TAlpha - The first record type.
|
|
@@ -626,29 +491,8 @@ export declare type MergeParams<TAlpha extends Record<string, unknown>, TBeta ex
|
|
|
626
491
|
[K in keyof TAlpha | keyof TBeta]: K extends keyof TAlpha & keyof TBeta ? never : K extends keyof TAlpha ? TAlpha[K] : K extends keyof TBeta ? TBeta[K] : never;
|
|
627
492
|
};
|
|
628
493
|
|
|
629
|
-
/**
|
|
630
|
-
* Merges two parameter type records, ensuring no overlap in properties.
|
|
631
|
-
* @template TAlpha - The first record type.
|
|
632
|
-
* @template TBeta - The second record type.
|
|
633
|
-
* @returns A new record type combining properties from both inputs without overlaps.
|
|
634
|
-
*/
|
|
635
|
-
declare type MergeParams_2<
|
|
636
|
-
TAlpha extends Record<string, unknown>,
|
|
637
|
-
TBeta extends Record<string, unknown>
|
|
638
|
-
> = {
|
|
639
|
-
[K in keyof TAlpha | keyof TBeta]: K extends keyof TAlpha & keyof TBeta
|
|
640
|
-
? never
|
|
641
|
-
: K extends keyof TAlpha
|
|
642
|
-
? TAlpha[K]
|
|
643
|
-
: K extends keyof TBeta
|
|
644
|
-
? TBeta[K]
|
|
645
|
-
: never
|
|
646
|
-
}
|
|
647
|
-
|
|
648
494
|
declare type NamedNotDisabled<T> = T extends BaseRoute ? T : never;
|
|
649
495
|
|
|
650
|
-
declare type NamedNotDisabled_2<T> = T extends BaseRoute_2 ? T : never
|
|
651
|
-
|
|
652
496
|
/**
|
|
653
497
|
* Registers a hook that is called after a route has been entered. Must be called during setup.
|
|
654
498
|
* This allows performing actions right after the component becomes active, such as fetching data or setting up event listeners.
|
|
@@ -698,72 +542,32 @@ declare type OnlyRequiredProperties<T> = {
|
|
|
698
542
|
[K in keyof T as Extract<T[K], undefined> extends never ? K : never]: T[K];
|
|
699
543
|
};
|
|
700
544
|
|
|
701
|
-
declare type OnlyRequiredProperties_2<T> = {
|
|
702
|
-
[K in keyof T as Extract<T[K], undefined> extends never ? K : never]: T[K]
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
declare type OptionalParamGetSet<TParam extends Param> = TParam extends ParamGetSet ? TParam & IsOptionalParam : ParamGetSet<ExtractParamType<TParam>> & IsOptionalParam;
|
|
706
|
-
|
|
707
|
-
declare type OptionalParamGetSet_2<TParam extends Param_2> = TParam extends ParamGetSet_2
|
|
708
|
-
? TParam & IsOptionalParam_2
|
|
709
|
-
: ParamGetSet_2<ExtractParamType_2<TParam>> & IsOptionalParam_2
|
|
710
|
-
|
|
711
|
-
declare const optionalParamKey: unique symbol;
|
|
712
|
-
|
|
713
|
-
declare const optionalParamKey_2 = Symbol();
|
|
714
|
-
|
|
715
545
|
export declare type Param = ParamGetter | ParamGetSet | RegExp | BooleanConstructor | NumberConstructor | StringConstructor | DateConstructor | JSON;
|
|
716
546
|
|
|
717
|
-
declare type Param_2 = ParamGetter_2 | ParamGetSet_2 | RegExp | BooleanConstructor | NumberConstructor | StringConstructor | DateConstructor | JSON
|
|
718
|
-
|
|
719
547
|
export declare type ParamEnd = typeof paramEnd;
|
|
720
548
|
|
|
721
549
|
export declare const paramEnd = "]";
|
|
722
550
|
|
|
723
|
-
declare type ParamEnd_2 = typeof paramEnd_2
|
|
724
|
-
|
|
725
|
-
declare const paramEnd_2 = ']';
|
|
726
|
-
|
|
727
551
|
export declare type ParamExtras = {
|
|
728
552
|
invalid: (message?: string) => never;
|
|
729
553
|
};
|
|
730
554
|
|
|
731
|
-
declare type ParamExtras_2 = {
|
|
732
|
-
invalid: (message?: string) => never,
|
|
733
|
-
}
|
|
734
|
-
|
|
735
555
|
export declare type ParamGetSet<T = any> = {
|
|
736
556
|
get: ParamGetter<T>;
|
|
737
557
|
set: ParamSetter<T>;
|
|
738
558
|
defaultValue?: T;
|
|
739
559
|
};
|
|
740
560
|
|
|
741
|
-
declare type ParamGetSet_2<T = any> = {
|
|
742
|
-
get: ParamGetter_2<T>,
|
|
743
|
-
set: ParamSetter_2<T>,
|
|
744
|
-
defaultValue?: T,
|
|
745
|
-
}
|
|
746
|
-
|
|
747
561
|
export declare type ParamGetter<T = any> = (value: string, extras: ParamExtras) => T;
|
|
748
562
|
|
|
749
|
-
declare type ParamGetter_2<T = any> = (value: string, extras: ParamExtras_2) => T
|
|
750
|
-
|
|
751
563
|
export declare type ParamSetter<T = any> = (value: T, extras: ParamExtras) => string;
|
|
752
564
|
|
|
753
|
-
declare type ParamSetter_2<T = any> = (value: T, extras: ParamExtras_2) => string
|
|
754
|
-
|
|
755
565
|
export declare type ParamStart = typeof paramStart;
|
|
756
566
|
|
|
757
567
|
export declare const paramStart = "[";
|
|
758
568
|
|
|
759
|
-
declare type ParamStart_2 = typeof paramStart_2
|
|
760
|
-
|
|
761
|
-
declare const paramStart_2 = '[';
|
|
762
|
-
|
|
763
569
|
export declare type ParamWithDefault<TParam extends Param = Param> = Required<ParamGetSet<ExtractParamType<TParam>>>;
|
|
764
570
|
|
|
765
|
-
declare type ParamWithDefault_2<TParam extends Param_2 = Param_2> = Required<ParamGetSet_2<ExtractParamType_2<TParam>>>
|
|
766
|
-
|
|
767
571
|
/**
|
|
768
572
|
* Represents properties common to parent routes in a route configuration, including hooks, path, and optional query parameters.
|
|
769
573
|
*/
|
|
@@ -794,37 +598,7 @@ export declare type ParentRouteProps = Partial<WithComponent | WithComponents> &
|
|
|
794
598
|
meta?: RouteMeta;
|
|
795
599
|
};
|
|
796
600
|
|
|
797
|
-
|
|
798
|
-
* Represents properties common to parent routes in a route configuration, including hooks, path, and optional query parameters.
|
|
799
|
-
*/
|
|
800
|
-
declare type ParentRouteProps_2 = Partial<WithComponent_2 | WithComponents_2> & WithHooks_2 & {
|
|
801
|
-
/**
|
|
802
|
-
* Name for route, used to create route keys and in navigation.
|
|
803
|
-
*/
|
|
804
|
-
name?: string,
|
|
805
|
-
/**
|
|
806
|
-
* Path part of URL.
|
|
807
|
-
*/
|
|
808
|
-
path: string | Path_2,
|
|
809
|
-
/**
|
|
810
|
-
* Query (aka search) part of URL.
|
|
811
|
-
*/
|
|
812
|
-
query?: string | Query_2,
|
|
813
|
-
/**
|
|
814
|
-
* Disabled routes will not ever match but can still provide physical structure, nested children behave normally.
|
|
815
|
-
*/
|
|
816
|
-
disabled?: boolean,
|
|
817
|
-
/**
|
|
818
|
-
* Children routes, expected type comes from `createRoutes()`
|
|
819
|
-
*/
|
|
820
|
-
children: Routes_2,
|
|
821
|
-
/**
|
|
822
|
-
* Represents additional metadata associated with a route, customizable via declaration merging.
|
|
823
|
-
*/
|
|
824
|
-
meta?: RouteMeta_2,
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
declare type Path<TPath extends string = string, TParams extends PathParams<TPath> = Record<string, Param | undefined>> = {
|
|
601
|
+
declare type Path<TPath extends string = string, TParams extends PathParamsWithParamNameExtracted<TPath> = Record<string, Param | undefined>> = {
|
|
828
602
|
path: TPath;
|
|
829
603
|
params: string extends TPath ? Record<string, Param> : Identity<ExtractParamsFromPathString<TPath, TParams>>;
|
|
830
604
|
toString: () => string;
|
|
@@ -853,30 +627,21 @@ declare type Path<TPath extends string = string, TParams extends PathParams<TPat
|
|
|
853
627
|
* ])
|
|
854
628
|
* ```
|
|
855
629
|
*/
|
|
856
|
-
export declare function path<TPath extends string, TParams extends
|
|
857
|
-
|
|
858
|
-
declare type Path_2<
|
|
859
|
-
TPath extends string = string,
|
|
860
|
-
TParams extends PathParams_2<TPath> = Record<string, Param_2 | undefined>
|
|
861
|
-
> = {
|
|
862
|
-
path: TPath,
|
|
863
|
-
params: string extends TPath ? Record<string, Param_2> : Identity_2<ExtractParamsFromPathString_2<TPath, TParams>>,
|
|
864
|
-
toString: () => string,
|
|
865
|
-
}
|
|
630
|
+
export declare function path<TPath extends string, TParams extends PathParamsWithParamNameExtracted<TPath>>(path: TPath, params: Identity<TParams>): Path<TPath, TParams>;
|
|
866
631
|
|
|
867
632
|
declare type PathParams<TPath extends string> = {
|
|
868
633
|
[K in keyof ExtractParamsFromPathString<TPath>]?: Param;
|
|
869
634
|
};
|
|
870
635
|
|
|
871
|
-
declare type
|
|
872
|
-
[K in keyof
|
|
873
|
-
}
|
|
636
|
+
declare type PathParamsWithParamNameExtracted<TPath extends string> = {
|
|
637
|
+
[K in keyof ExtractParamsFromPathString<TPath> as ExtractParamName<K>]?: Param;
|
|
638
|
+
};
|
|
874
639
|
|
|
875
640
|
declare type Props<TComponent extends Component> = TComponent extends Constructor ? InstanceType<TComponent>['$props'] : TComponent extends AsyncComponentLoader<infer T extends Component> ? Props<T> : TComponent extends FunctionalComponent<infer T> ? T : never;
|
|
876
641
|
|
|
877
642
|
declare type PropsGetter<TComponent extends Component> = () => MaybePromise<Props<TComponent>>;
|
|
878
643
|
|
|
879
|
-
declare type Query<TQuery extends string = string, TQueryParams extends
|
|
644
|
+
declare type Query<TQuery extends string = string, TQueryParams extends QueryParamsWithParamNameExtracted<TQuery> = Record<string, Param | undefined>> = {
|
|
880
645
|
query: TQuery;
|
|
881
646
|
params: string extends TQuery ? Record<string, Param> : Identity<ExtractQueryParamsFromQueryString<TQuery, TQueryParams>>;
|
|
882
647
|
toString: () => string;
|
|
@@ -905,24 +670,15 @@ declare type Query<TQuery extends string = string, TQueryParams extends QueryPar
|
|
|
905
670
|
* ])
|
|
906
671
|
* ```
|
|
907
672
|
*/
|
|
908
|
-
export declare function query<TQuery extends string, TParams extends
|
|
909
|
-
|
|
910
|
-
declare type Query_2<
|
|
911
|
-
TQuery extends string = string,
|
|
912
|
-
TQueryParams extends QueryParams_2<TQuery> = Record<string, Param_2 | undefined>
|
|
913
|
-
> = {
|
|
914
|
-
query: TQuery,
|
|
915
|
-
params: string extends TQuery ? Record<string, Param_2> : Identity_2<ExtractQueryParamsFromQueryString_2<TQuery, TQueryParams>>,
|
|
916
|
-
toString: () => string,
|
|
917
|
-
}
|
|
673
|
+
export declare function query<TQuery extends string, TParams extends QueryParamsWithParamNameExtracted<TQuery>>(query: TQuery, params: Identity<TParams>): Query<TQuery, TParams>;
|
|
918
674
|
|
|
919
675
|
declare type QueryParams<T extends string> = {
|
|
920
676
|
[K in keyof ExtractQueryParamsFromQueryString<T>]?: Param;
|
|
921
677
|
};
|
|
922
678
|
|
|
923
|
-
declare type
|
|
924
|
-
[K in keyof
|
|
925
|
-
}
|
|
679
|
+
declare type QueryParamsWithParamNameExtracted<T extends string> = {
|
|
680
|
+
[K in keyof ExtractQueryParamsFromQueryString<T> as ExtractParamName<K>]?: Param;
|
|
681
|
+
};
|
|
926
682
|
|
|
927
683
|
/**
|
|
928
684
|
* Represents the state of currently registered router, and rejections. Used to provide correct type context for
|
|
@@ -940,21 +696,6 @@ declare type QueryParams_2<T extends string> = {
|
|
|
940
696
|
export declare interface Register {
|
|
941
697
|
}
|
|
942
698
|
|
|
943
|
-
/**
|
|
944
|
-
* Represents the state of currently registered router, and rejections. Used to provide correct type context for
|
|
945
|
-
* components like `RouterLink`, as well as for composables like `useRouter`, `useRoute`, and hooks.
|
|
946
|
-
*
|
|
947
|
-
* @example
|
|
948
|
-
* ```ts
|
|
949
|
-
* declare module '@kitbag/router' {
|
|
950
|
-
* interface Register {
|
|
951
|
-
* router: typeof router
|
|
952
|
-
* }
|
|
953
|
-
* }
|
|
954
|
-
* ```
|
|
955
|
-
*/
|
|
956
|
-
declare interface Register_2 {}
|
|
957
|
-
|
|
958
699
|
/**
|
|
959
700
|
* Represents the possible Rejections registered within {@link Register}
|
|
960
701
|
*/
|
|
@@ -962,13 +703,6 @@ export declare type RegisteredRejectionType = Register extends {
|
|
|
962
703
|
rejections: infer TRejections extends string[];
|
|
963
704
|
} ? TRejections[number] : never;
|
|
964
705
|
|
|
965
|
-
/**
|
|
966
|
-
* Represents the possible Rejections registered within {@link Register}
|
|
967
|
-
*/
|
|
968
|
-
declare type RegisteredRejectionType_2 = Register_2 extends { rejections: infer TRejections extends string[] }
|
|
969
|
-
? TRejections[number]
|
|
970
|
-
: never
|
|
971
|
-
|
|
972
706
|
/**
|
|
973
707
|
* Represents the a map of all possible RouteKeys with corresponding Route registered within {@link Register}
|
|
974
708
|
*/
|
|
@@ -986,20 +720,15 @@ export declare type RegisteredRouter = Register extends {
|
|
|
986
720
|
*/
|
|
987
721
|
export declare type RegisteredRouterPush = RouterPush<RegisteredRoutes>;
|
|
988
722
|
|
|
989
|
-
/**
|
|
990
|
-
* Represents the type for router `push`, with types for routes registered within {@link Register}
|
|
991
|
-
*/
|
|
992
|
-
declare type RegisteredRouterPush_2 = RouterPush_2<RegisteredRoutes_2>
|
|
993
|
-
|
|
994
723
|
/**
|
|
995
724
|
* Represents the type for router `replace`, with types for routes registered within {@link Register}
|
|
996
725
|
*/
|
|
997
726
|
export declare type RegisteredRouterReplace = RouterReplace<RegisteredRoutes>;
|
|
998
727
|
|
|
999
728
|
/**
|
|
1000
|
-
* Represents the
|
|
729
|
+
* Represents the Router property within {@link Register}
|
|
1001
730
|
*/
|
|
1002
|
-
declare type
|
|
731
|
+
export declare type RegisteredRouterRoute = RegisteredRouter['route'];
|
|
1003
732
|
|
|
1004
733
|
/**
|
|
1005
734
|
* Represents the State property registered within {@link Register}
|
|
@@ -1013,14 +742,7 @@ export declare type RegisteredRouterState = Register extends {
|
|
|
1013
742
|
*/
|
|
1014
743
|
export declare type RegisteredRoutes = Register extends {
|
|
1015
744
|
router: Router<infer TRoutes extends Routes>;
|
|
1016
|
-
} ? TRoutes : Route<string, Path<'', {}>, Query<'', {}>, false>[];
|
|
1017
|
-
|
|
1018
|
-
/**
|
|
1019
|
-
* Represents the Router routes property within {@link Register}
|
|
1020
|
-
*/
|
|
1021
|
-
declare type RegisteredRoutes_2 = Register_2 extends { router: Router_2<infer TRoutes extends Routes_2> }
|
|
1022
|
-
? TRoutes
|
|
1023
|
-
: Route_2<string, Path_2<'', {}>, Query_2<'', {}>, false>[]
|
|
745
|
+
} ? TRoutes : Route<string, '', Path<'', {}>, Query<'', {}>, false>[];
|
|
1024
746
|
|
|
1025
747
|
/**
|
|
1026
748
|
* Represents the union of all possible RouteKeys registered within {@link Register}
|
|
@@ -1031,7 +753,7 @@ export declare type RegisteredRoutesKey = RoutesKey<RegisteredRoutes>;
|
|
|
1031
753
|
* Represents a route that the router has matched to current browser location.
|
|
1032
754
|
* @template TRoute - Underlying Route that has been resolved.
|
|
1033
755
|
*/
|
|
1034
|
-
declare type ResolvedRoute<TRoute extends Route =
|
|
756
|
+
declare type ResolvedRoute<TRoute extends Route = Route> = Readonly<{
|
|
1035
757
|
/**
|
|
1036
758
|
* The specific route properties that were matched in the current route.
|
|
1037
759
|
*/
|
|
@@ -1052,47 +774,14 @@ declare type ResolvedRoute<TRoute extends Route = BaseResolvedRoute> = Readonly<
|
|
|
1052
774
|
/**
|
|
1053
775
|
* Key value pair for route params, values will be the user provided value from current browser location.
|
|
1054
776
|
*/
|
|
1055
|
-
params:
|
|
777
|
+
params: ExtractRouteParamTypes<TRoute>;
|
|
1056
778
|
}>;
|
|
1057
779
|
|
|
1058
|
-
/**
|
|
1059
|
-
* Represents a route that the router has matched to current browser location.
|
|
1060
|
-
* @template TRoute - Underlying Route that has been resolved.
|
|
1061
|
-
*/
|
|
1062
|
-
declare type ResolvedRoute_2<TRoute extends Route_2 = BaseResolvedRoute_2> = Readonly<{
|
|
1063
|
-
/**
|
|
1064
|
-
* The specific route properties that were matched in the current route.
|
|
1065
|
-
*/
|
|
1066
|
-
matched: TRoute['matched'],
|
|
1067
|
-
/**
|
|
1068
|
-
* The specific route properties that were matched in the current route, including any ancestors.
|
|
1069
|
-
* Order of routes will be from greatest ancestor to narrowest matched.
|
|
1070
|
-
*/
|
|
1071
|
-
matches: TRoute['matches'],
|
|
1072
|
-
/**
|
|
1073
|
-
* Unique identifier for the route, generated by joining route `name` by period. Key is used for routing and for matching.
|
|
1074
|
-
*/
|
|
1075
|
-
key: TRoute['key'],
|
|
1076
|
-
/**
|
|
1077
|
-
* Accessor for query string values from user in the current browser location.
|
|
1078
|
-
*/
|
|
1079
|
-
query: ResolvedRouteQuery_2,
|
|
1080
|
-
/**
|
|
1081
|
-
* Key value pair for route params, values will be the user provided value from current browser location.
|
|
1082
|
-
*/
|
|
1083
|
-
params: BaseResolvedRoute_2 extends TRoute ? Record<string, unknown> : ExtractRouteParamTypes_2<TRoute>,
|
|
1084
|
-
}>
|
|
1085
|
-
|
|
1086
780
|
declare type ResolvedRouteQuery = {
|
|
1087
781
|
get: (key: string) => string | null;
|
|
1088
782
|
getAll: (key: string) => string[];
|
|
1089
783
|
};
|
|
1090
784
|
|
|
1091
|
-
declare type ResolvedRouteQuery_2 = {
|
|
1092
|
-
get: (key: string) => string | null,
|
|
1093
|
-
getAll: (key: string) => string[],
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
785
|
/**
|
|
1097
786
|
* Represents the structure of a route within the application. Return value of `createRoutes`
|
|
1098
787
|
* @template TKey - Represents the unique key identifying the route, typically a string.
|
|
@@ -1100,7 +789,7 @@ declare type ResolvedRouteQuery_2 = {
|
|
|
1100
789
|
* @template TQuery - The type or structure of the query parameters associated with the route.
|
|
1101
790
|
* @template TDisabled - Indicates whether the route is disabled, which could affect routing logic.
|
|
1102
791
|
*/
|
|
1103
|
-
export declare type Route<TKey extends string = string,
|
|
792
|
+
export declare type Route<TKey extends string = string, THost extends string = string, TPath extends Path = Path, TQuery extends Query = Query, TDisabled extends boolean = boolean> = {
|
|
1104
793
|
/**
|
|
1105
794
|
* The specific route properties that were matched in the current route.
|
|
1106
795
|
*/
|
|
@@ -1115,65 +804,26 @@ export declare type Route<TKey extends string = string, TPath extends string | P
|
|
|
1115
804
|
*/
|
|
1116
805
|
key: TKey;
|
|
1117
806
|
/**
|
|
1118
|
-
* Represents the
|
|
1119
|
-
*/
|
|
1120
|
-
path: ToPath<TPath>;
|
|
1121
|
-
/**
|
|
1122
|
-
* Represents the structured query of the route, including query params.
|
|
1123
|
-
*/
|
|
1124
|
-
query: ToQuery<TQuery>;
|
|
1125
|
-
depth: number;
|
|
1126
|
-
/**
|
|
1127
|
-
* Indicates if the route is disabled.
|
|
807
|
+
* Represents the host for this route. Used for external routes.
|
|
1128
808
|
*/
|
|
1129
|
-
|
|
1130
|
-
};
|
|
1131
|
-
|
|
1132
|
-
/**
|
|
1133
|
-
* Represents the structure of a route within the application. Return value of `createRoutes`
|
|
1134
|
-
* @template TKey - Represents the unique key identifying the route, typically a string.
|
|
1135
|
-
* @template TPath - The type or structure of the route's path.
|
|
1136
|
-
* @template TQuery - The type or structure of the query parameters associated with the route.
|
|
1137
|
-
* @template TDisabled - Indicates whether the route is disabled, which could affect routing logic.
|
|
1138
|
-
*/
|
|
1139
|
-
declare type Route_2<
|
|
1140
|
-
TKey extends string = string,
|
|
1141
|
-
TPath extends string | Path_2 = Path_2,
|
|
1142
|
-
TQuery extends string | Query_2 = Query_2,
|
|
1143
|
-
TDisabled extends boolean = boolean
|
|
1144
|
-
> = {
|
|
1145
|
-
/**
|
|
1146
|
-
* The specific route properties that were matched in the current route.
|
|
1147
|
-
*/
|
|
1148
|
-
matched: RoutePropsWithMeta_2,
|
|
1149
|
-
/**
|
|
1150
|
-
* The specific route properties that were matched in the current route, including any ancestors.
|
|
1151
|
-
* Order of routes will be from greatest ancestor to narrowest matched.
|
|
1152
|
-
*/
|
|
1153
|
-
matches: RoutePropsWithMeta_2[],
|
|
1154
|
-
/**
|
|
1155
|
-
* Unique identifier for the route, generated by joining route `name` by period. Key is used for routing and for matching.
|
|
1156
|
-
*/
|
|
1157
|
-
key: TKey,
|
|
809
|
+
host: THost;
|
|
1158
810
|
/**
|
|
1159
811
|
* Represents the structured path of the route, including path params.
|
|
1160
812
|
*/
|
|
1161
|
-
path:
|
|
813
|
+
path: TPath;
|
|
1162
814
|
/**
|
|
1163
815
|
* Represents the structured query of the route, including query params.
|
|
1164
816
|
*/
|
|
1165
|
-
query:
|
|
1166
|
-
depth: number
|
|
817
|
+
query: TQuery;
|
|
818
|
+
depth: number;
|
|
1167
819
|
/**
|
|
1168
820
|
* Indicates if the route is disabled.
|
|
1169
821
|
*/
|
|
1170
|
-
disabled: TDisabled
|
|
1171
|
-
}
|
|
822
|
+
disabled: TDisabled;
|
|
823
|
+
};
|
|
1172
824
|
|
|
1173
825
|
declare type RouteGetByKey<TRoutes extends Routes, TKey extends RoutesKey<TRoutes>> = RoutesMap<TRoutes>[TKey];
|
|
1174
826
|
|
|
1175
|
-
declare type RouteGetByKey_2<TRoutes extends Routes_2, TKey extends RoutesKey_2<TRoutes>> = RoutesMap_2<TRoutes>[TKey]
|
|
1176
|
-
|
|
1177
827
|
/**
|
|
1178
828
|
* Generic type representing a route hook, which can be either before or after a route change.
|
|
1179
829
|
*/
|
|
@@ -1184,11 +834,6 @@ export declare type RouteHook = BeforeRouteHook | AfterRouteHook;
|
|
|
1184
834
|
*/
|
|
1185
835
|
export declare type RouteHookAbort = () => void;
|
|
1186
836
|
|
|
1187
|
-
/**
|
|
1188
|
-
* A function that can be called to abort a routing operation.
|
|
1189
|
-
*/
|
|
1190
|
-
declare type RouteHookAbort_2 = () => void
|
|
1191
|
-
|
|
1192
837
|
/**
|
|
1193
838
|
* Defines the structure of an aborted route hook response.
|
|
1194
839
|
*/
|
|
@@ -1206,16 +851,6 @@ declare type RouteHookContext = {
|
|
|
1206
851
|
replace: RegisteredRouterReplace;
|
|
1207
852
|
};
|
|
1208
853
|
|
|
1209
|
-
/**
|
|
1210
|
-
* Context provided to route hooks, containing context of previous route and functions for triggering rejections and push/replace to another route.
|
|
1211
|
-
*/
|
|
1212
|
-
declare type RouteHookContext_2 = {
|
|
1213
|
-
from: ResolvedRoute_2 | null,
|
|
1214
|
-
reject: RouterReject_2,
|
|
1215
|
-
push: RegisteredRouterPush_2,
|
|
1216
|
-
replace: RegisteredRouterReplace_2,
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
854
|
/**
|
|
1220
855
|
* Union type for all route hook lifecycle events.
|
|
1221
856
|
*/
|
|
@@ -1243,11 +878,6 @@ declare type RouteHookRejectResponse = {
|
|
|
1243
878
|
*/
|
|
1244
879
|
export declare type RouteHookRemove = () => void;
|
|
1245
880
|
|
|
1246
|
-
/**
|
|
1247
|
-
* A function to remove a previously registered route hook.
|
|
1248
|
-
*/
|
|
1249
|
-
declare type RouteHookRemove_2 = () => void
|
|
1250
|
-
|
|
1251
881
|
/**
|
|
1252
882
|
* Union type for all possible route hook responses, covering both before and after scenarios.
|
|
1253
883
|
* @template TRoutes - The type of the routes configuration.
|
|
@@ -1275,36 +905,13 @@ declare type RouteHookSuccessResponse = {
|
|
|
1275
905
|
export declare interface RouteMeta extends Record<string, unknown> {
|
|
1276
906
|
}
|
|
1277
907
|
|
|
1278
|
-
/**
|
|
1279
|
-
* Represents additional metadata associated with a route, customizable via declaration merging.
|
|
1280
|
-
* @example
|
|
1281
|
-
* ```ts
|
|
1282
|
-
* declare module '@kitbag/router' {
|
|
1283
|
-
* interface RouteMeta {
|
|
1284
|
-
* pageTitle?: string
|
|
1285
|
-
* }
|
|
1286
|
-
* }
|
|
1287
|
-
* ```
|
|
1288
|
-
*/
|
|
1289
|
-
declare interface RouteMeta_2 extends Record<string, unknown> {}
|
|
1290
|
-
|
|
1291
908
|
declare type RouteParamsByKey<TRoutes extends Routes, TKey extends string> = ExtractRouteParamTypesWithoutLosingOptional<RouteGetByKey<TRoutes, TKey>>;
|
|
1292
909
|
|
|
1293
|
-
declare type RouteParamsByKey_2<
|
|
1294
|
-
TRoutes extends Routes_2,
|
|
1295
|
-
TKey extends string
|
|
1296
|
-
> = ExtractRouteParamTypesWithoutLosingOptional_2<RouteGetByKey_2<TRoutes, TKey>>
|
|
1297
|
-
|
|
1298
910
|
/**
|
|
1299
911
|
* Unifies the properties of both parent and child routes, ensuring type safety and consistency across route configurations.
|
|
1300
912
|
*/
|
|
1301
913
|
export declare type RouteProps = Readonly<ParentRouteProps | ChildRouteProps>;
|
|
1302
914
|
|
|
1303
|
-
/**
|
|
1304
|
-
* Unifies the properties of both parent and child routes, ensuring type safety and consistency across route configurations.
|
|
1305
|
-
*/
|
|
1306
|
-
declare type RouteProps_2 = Readonly<ParentRouteProps_2 | ChildRouteProps_2>
|
|
1307
|
-
|
|
1308
915
|
/**
|
|
1309
916
|
* The Route properties originally provided to `createRoutes`. The only change is normalizing meta to always default to an empty object.
|
|
1310
917
|
*/
|
|
@@ -1312,16 +919,11 @@ export declare type RoutePropsWithMeta = RouteProps & {
|
|
|
1312
919
|
meta: RouteMeta;
|
|
1313
920
|
};
|
|
1314
921
|
|
|
1315
|
-
/**
|
|
1316
|
-
* The Route properties originally provided to `createRoutes`. The only change is normalizing meta to always default to an empty object.
|
|
1317
|
-
*/
|
|
1318
|
-
declare type RoutePropsWithMeta_2 = RouteProps_2 & { meta: RouteMeta_2 }
|
|
1319
|
-
|
|
1320
922
|
export declare type Router<TRoutes extends Routes = any> = Plugin_2 & {
|
|
1321
923
|
/**
|
|
1322
924
|
* Manages the current route state.
|
|
1323
925
|
*/
|
|
1324
|
-
route:
|
|
926
|
+
route: RouterRoutes<TRoutes>;
|
|
1325
927
|
/**
|
|
1326
928
|
* Resolves a URL to a route object.
|
|
1327
929
|
*/
|
|
@@ -1386,103 +988,19 @@ export declare type Router<TRoutes extends Routes = any> = Plugin_2 & {
|
|
|
1386
988
|
* A promise that resolves when the router is fully initialized.
|
|
1387
989
|
*/
|
|
1388
990
|
initialized: Promise<void>;
|
|
1389
|
-
};
|
|
1390
|
-
|
|
1391
|
-
declare type Router_2<
|
|
1392
|
-
TRoutes extends Routes_2 = any
|
|
1393
|
-
> = Plugin_2 & {
|
|
1394
|
-
/**
|
|
1395
|
-
* Manages the current route state.
|
|
1396
|
-
*/
|
|
1397
|
-
route: RouterRoute_2,
|
|
1398
|
-
/**
|
|
1399
|
-
* Resolves a URL to a route object.
|
|
1400
|
-
*/
|
|
1401
|
-
resolve: RouterResolve_2<TRoutes>,
|
|
1402
|
-
/**
|
|
1403
|
-
* Navigates to a specified path or route object in the history stack, adding a new entry.
|
|
1404
|
-
*/
|
|
1405
|
-
push: RouterPush_2<TRoutes>,
|
|
1406
|
-
/**
|
|
1407
|
-
* Replaces the current entry in the history stack with a new one.
|
|
1408
|
-
*/
|
|
1409
|
-
replace: RouterReplace_2<TRoutes>,
|
|
1410
|
-
/**
|
|
1411
|
-
* Finds a route object based on the provided lookup parameters.
|
|
1412
|
-
*/
|
|
1413
|
-
find: RouterFind_2<TRoutes>,
|
|
1414
|
-
/**
|
|
1415
|
-
* Handles route rejection based on a specified rejection type.
|
|
1416
|
-
*/
|
|
1417
|
-
reject: RouterReject_2,
|
|
1418
|
-
/**
|
|
1419
|
-
* Forces the router to re-evaluate the current route.
|
|
1420
|
-
*/
|
|
1421
|
-
refresh: () => void,
|
|
1422
|
-
/**
|
|
1423
|
-
* Navigates to the previous entry in the browser's history stack.
|
|
1424
|
-
*/
|
|
1425
|
-
back: () => void,
|
|
1426
|
-
/**
|
|
1427
|
-
* Navigates to the next entry in the browser's history stack.
|
|
1428
|
-
*/
|
|
1429
|
-
forward: () => void,
|
|
1430
|
-
/**
|
|
1431
|
-
* Moves the current history entry to a specific point in the history stack.
|
|
1432
|
-
*/
|
|
1433
|
-
go: (delta: number) => void,
|
|
1434
|
-
/**
|
|
1435
|
-
* Registers a hook to be called before a route is entered.
|
|
1436
|
-
*/
|
|
1437
|
-
onBeforeRouteEnter: AddBeforeRouteHook_2,
|
|
1438
991
|
/**
|
|
1439
|
-
*
|
|
1440
|
-
*/
|
|
1441
|
-
onBeforeRouteLeave: AddBeforeRouteHook_2,
|
|
1442
|
-
/**
|
|
1443
|
-
* Registers a hook to be called before a route is updated.
|
|
1444
|
-
*/
|
|
1445
|
-
onBeforeRouteUpdate: AddBeforeRouteHook_2,
|
|
1446
|
-
/**
|
|
1447
|
-
* Registers a hook to be called after a route is entered.
|
|
992
|
+
* Given a URL, returns true if host does not match host stored on router instance
|
|
1448
993
|
*/
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
* Registers a hook to be called after a route is left.
|
|
1452
|
-
*/
|
|
1453
|
-
onAfterRouteLeave: AddAfterRouteHook_2,
|
|
1454
|
-
/**
|
|
1455
|
-
* Registers a hook to be called after a route is updated.
|
|
1456
|
-
*/
|
|
1457
|
-
onAfterRouteUpdate: AddAfterRouteHook_2,
|
|
1458
|
-
/**
|
|
1459
|
-
* A promise that resolves when the router is fully initialized.
|
|
1460
|
-
*/
|
|
1461
|
-
initialized: Promise<void>,
|
|
1462
|
-
}
|
|
994
|
+
isExternal: (url: string) => boolean;
|
|
995
|
+
};
|
|
1463
996
|
|
|
1464
997
|
declare type RouterFind<TRoutes extends Routes> = {
|
|
1465
998
|
<TSource extends RoutesKey<TRoutes>>(source: TSource, ...args: RouterFindArgs<TRoutes, TSource>): ResolvedRoute | undefined;
|
|
1466
999
|
(source: Url): ResolvedRoute | undefined;
|
|
1467
1000
|
};
|
|
1468
1001
|
|
|
1469
|
-
declare type RouterFind_2<
|
|
1470
|
-
TRoutes extends Routes_2
|
|
1471
|
-
> = {
|
|
1472
|
-
<TSource extends RoutesKey_2<TRoutes>>(source: TSource, ...args: RouterFindArgs_2<TRoutes, TSource>): ResolvedRoute_2 | undefined,
|
|
1473
|
-
(source: Url_2): ResolvedRoute_2 | undefined,
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
1002
|
declare type RouterFindArgs<TRoutes extends Routes, TSource extends RoutesKey<TRoutes>, TParams = RouteParamsByKey<TRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: TParams] : [params: TParams];
|
|
1477
1003
|
|
|
1478
|
-
declare type RouterFindArgs_2<
|
|
1479
|
-
TRoutes extends Routes_2,
|
|
1480
|
-
TSource extends RoutesKey_2<TRoutes>,
|
|
1481
|
-
TParams = RouteParamsByKey_2<TRoutes, TSource>
|
|
1482
|
-
> = AllPropertiesAreOptional_2<TParams> extends true
|
|
1483
|
-
? [params?: TParams]
|
|
1484
|
-
: [params: TParams]
|
|
1485
|
-
|
|
1486
1004
|
declare type RouterHistoryMode = 'auto' | 'browser' | 'memory' | 'hash';
|
|
1487
1005
|
|
|
1488
1006
|
export declare const routerInjectionKey: InjectionKey<RegisteredRouter>;
|
|
@@ -1519,7 +1037,7 @@ export declare class RouterNotInstalledError extends Error {
|
|
|
1519
1037
|
*/
|
|
1520
1038
|
export declare type RouterOptions = {
|
|
1521
1039
|
/**
|
|
1522
|
-
* Initial URL for the router to use. Required if using Node environment.
|
|
1040
|
+
* Initial URL for the router to use. Required if using Node environment. Defaults to window.location when using browser.
|
|
1523
1041
|
*
|
|
1524
1042
|
* @default window.location.toString()
|
|
1525
1043
|
*/
|
|
@@ -1535,37 +1053,15 @@ declare type RouterPush<TRoutes extends Routes = any> = {
|
|
|
1535
1053
|
(source: Url, options?: RouterPushOptions): Promise<void>;
|
|
1536
1054
|
};
|
|
1537
1055
|
|
|
1538
|
-
declare type RouterPush_2<
|
|
1539
|
-
TRoutes extends Routes_2 = any
|
|
1540
|
-
> = {
|
|
1541
|
-
<TSource extends RoutesKey_2<TRoutes>>(source: TSource, ...args: RouterPushArgs_2<TRoutes, TSource>): Promise<void>,
|
|
1542
|
-
(source: Url_2, options?: RouterPushOptions_2): Promise<void>,
|
|
1543
|
-
}
|
|
1544
|
-
|
|
1545
1056
|
declare type RouterPushArgs<TRoutes extends Routes, TSource extends RoutesKey<TRoutes>, TParams = RouteParamsByKey<TRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: TParams, options?: RouterPushOptions] : [params: TParams, options?: RouterPushOptions];
|
|
1546
1057
|
|
|
1547
|
-
declare type RouterPushArgs_2<
|
|
1548
|
-
TRoutes extends Routes_2,
|
|
1549
|
-
TSource extends RoutesKey_2<TRoutes>,
|
|
1550
|
-
TParams = RouteParamsByKey_2<TRoutes, TSource>
|
|
1551
|
-
> = AllPropertiesAreOptional_2<TParams> extends true
|
|
1552
|
-
? [params?: TParams, options?: RouterPushOptions_2]
|
|
1553
|
-
: [params: TParams, options?: RouterPushOptions_2]
|
|
1554
|
-
|
|
1555
1058
|
declare type RouterPushOptions = {
|
|
1556
1059
|
query?: Record<string, string>;
|
|
1557
1060
|
replace?: boolean;
|
|
1558
1061
|
};
|
|
1559
1062
|
|
|
1560
|
-
declare type RouterPushOptions_2 = {
|
|
1561
|
-
query?: Record<string, string>,
|
|
1562
|
-
replace?: boolean,
|
|
1563
|
-
}
|
|
1564
|
-
|
|
1565
1063
|
export declare type RouterReject = (type: RouterRejectionType) => void;
|
|
1566
1064
|
|
|
1567
|
-
declare type RouterReject_2 = (type: RouterRejectionType_2) => void
|
|
1568
|
-
|
|
1569
1065
|
declare type RouterRejection = Ref<null | {
|
|
1570
1066
|
type: RouterRejectionType;
|
|
1571
1067
|
component: Component;
|
|
@@ -1579,64 +1075,26 @@ export declare const routerRejectionKey: InjectionKey<RouterRejection>;
|
|
|
1579
1075
|
|
|
1580
1076
|
declare type RouterRejectionType = BuiltInRejectionType | RegisteredRejectionType;
|
|
1581
1077
|
|
|
1582
|
-
declare type RouterRejectionType_2 = BuiltInRejectionType_2 | RegisteredRejectionType_2
|
|
1583
|
-
|
|
1584
1078
|
declare type RouterReplace<TRoutes extends Routes> = {
|
|
1585
1079
|
<TSource extends RoutesKey<TRoutes>>(source: TSource, ...args: RouterReplaceArgs<TRoutes, TSource>): Promise<void>;
|
|
1586
1080
|
(source: Url, options?: RouterReplaceOptions): Promise<void>;
|
|
1587
1081
|
};
|
|
1588
1082
|
|
|
1589
|
-
declare type RouterReplace_2<
|
|
1590
|
-
TRoutes extends Routes_2
|
|
1591
|
-
> = {
|
|
1592
|
-
<TSource extends RoutesKey_2<TRoutes>>(source: TSource, ...args: RouterReplaceArgs_2<TRoutes, TSource>): Promise<void>,
|
|
1593
|
-
(source: Url_2, options?: RouterReplaceOptions_2): Promise<void>,
|
|
1594
|
-
}
|
|
1595
|
-
|
|
1596
1083
|
declare type RouterReplaceArgs<TRoutes extends Routes, TSource extends RoutesKey<TRoutes>, TParams = RouteParamsByKey<TRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: TParams, options?: RouterReplaceOptions] : [params: TParams, options?: RouterReplaceOptions];
|
|
1597
1084
|
|
|
1598
|
-
declare type RouterReplaceArgs_2<
|
|
1599
|
-
TRoutes extends Routes_2,
|
|
1600
|
-
TSource extends RoutesKey_2<TRoutes>,
|
|
1601
|
-
TParams = RouteParamsByKey_2<TRoutes, TSource>
|
|
1602
|
-
> = AllPropertiesAreOptional_2<TParams> extends true
|
|
1603
|
-
? [params?: TParams, options?: RouterReplaceOptions_2]
|
|
1604
|
-
: [params: TParams, options?: RouterReplaceOptions_2]
|
|
1605
|
-
|
|
1606
1085
|
declare type RouterReplaceOptions = Omit<RouterPushOptions, 'replace'>;
|
|
1607
1086
|
|
|
1608
|
-
declare type RouterReplaceOptions_2 = Omit<RouterPushOptions_2, 'replace'>
|
|
1609
|
-
|
|
1610
1087
|
declare type RouterResolve<TRoutes extends Routes> = {
|
|
1611
1088
|
<TSource extends RoutesKey<TRoutes>>(source: TSource, ...args: RouterResolveArgs<TRoutes, TSource>): string;
|
|
1612
1089
|
(source: Url, options?: RouterResolveOptions): string;
|
|
1613
1090
|
};
|
|
1614
1091
|
|
|
1615
|
-
declare type RouterResolve_2<
|
|
1616
|
-
TRoutes extends Routes_2
|
|
1617
|
-
> = {
|
|
1618
|
-
<TSource extends RoutesKey_2<TRoutes>>(source: TSource, ...args: RouterResolveArgs_2<TRoutes, TSource>): string,
|
|
1619
|
-
(source: Url_2, options?: RouterResolveOptions_2): string,
|
|
1620
|
-
}
|
|
1621
|
-
|
|
1622
1092
|
declare type RouterResolveArgs<TRoutes extends Routes, TSource extends RoutesKey<TRoutes>, TParams = RouteParamsByKey<TRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: TParams, options?: RouterResolveOptions] : [params: TParams, options?: RouterResolveOptions];
|
|
1623
1093
|
|
|
1624
|
-
declare type RouterResolveArgs_2<
|
|
1625
|
-
TRoutes extends Routes_2,
|
|
1626
|
-
TSource extends RoutesKey_2<TRoutes>,
|
|
1627
|
-
TParams = RouteParamsByKey_2<TRoutes, TSource>
|
|
1628
|
-
> = AllPropertiesAreOptional_2<TParams> extends true
|
|
1629
|
-
? [params?: TParams, options?: RouterResolveOptions_2]
|
|
1630
|
-
: [params: TParams, options?: RouterResolveOptions_2]
|
|
1631
|
-
|
|
1632
1094
|
declare type RouterResolveOptions = {
|
|
1633
1095
|
query?: Record<string, string>;
|
|
1634
1096
|
};
|
|
1635
1097
|
|
|
1636
|
-
declare type RouterResolveOptions_2 = {
|
|
1637
|
-
query?: Record<string, string>,
|
|
1638
|
-
}
|
|
1639
|
-
|
|
1640
1098
|
declare type RouterRoute<TRoute extends ResolvedRoute = ResolvedRoute> = Readonly<{
|
|
1641
1099
|
key: TRoute['key'];
|
|
1642
1100
|
matched: TRoute['matched'];
|
|
@@ -1646,14 +1104,12 @@ declare type RouterRoute<TRoute extends ResolvedRoute = ResolvedRoute> = Readonl
|
|
|
1646
1104
|
update: RouteUpdate<TRoute>;
|
|
1647
1105
|
}>;
|
|
1648
1106
|
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
update: RouteUpdate_2<TRoute>,
|
|
1656
|
-
}>
|
|
1107
|
+
/**
|
|
1108
|
+
* This type is the same as `RouterRoute<ResolvedRoute<TRoutes[number]>>` while remaining distributive
|
|
1109
|
+
*/
|
|
1110
|
+
export declare type RouterRoutes<TRoutes extends Routes> = {
|
|
1111
|
+
[K in keyof TRoutes]: RouterRoute<ResolvedRoute<TRoutes[K]>>;
|
|
1112
|
+
}[number];
|
|
1657
1113
|
|
|
1658
1114
|
export declare const RouterView: __VLS_WithTemplateSlots<DefineComponent<__VLS_TypePropsToRuntimeProps<{
|
|
1659
1115
|
name?: string | undefined;
|
|
@@ -1666,14 +1122,11 @@ name?: string | undefined;
|
|
|
1666
1122
|
matched: RoutePropsWithMeta;
|
|
1667
1123
|
matches: RoutePropsWithMeta[];
|
|
1668
1124
|
query: ResolvedRouteQuery;
|
|
1669
|
-
params: Writable<
|
|
1670
|
-
update:
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
query: ResolvedRouteQuery_2;
|
|
1675
|
-
params: Record<string, unknown>;
|
|
1676
|
-
}>>;
|
|
1125
|
+
params: Writable< {}>;
|
|
1126
|
+
update: {
|
|
1127
|
+
(key: string, value: unknown, options?: RouterPushOptions | undefined): Promise<void>;
|
|
1128
|
+
(params: Partial<{}>, options?: RouterPushOptions | undefined): Promise<void>;
|
|
1129
|
+
};
|
|
1677
1130
|
}>;
|
|
1678
1131
|
component: Component;
|
|
1679
1132
|
rejection: {
|
|
@@ -1690,14 +1143,11 @@ name?: string | undefined;
|
|
|
1690
1143
|
matched: RoutePropsWithMeta;
|
|
1691
1144
|
matches: RoutePropsWithMeta[];
|
|
1692
1145
|
query: ResolvedRouteQuery;
|
|
1693
|
-
params: Writable<
|
|
1694
|
-
update:
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
query: ResolvedRouteQuery_2;
|
|
1699
|
-
params: Record<string, unknown>;
|
|
1700
|
-
}>>;
|
|
1146
|
+
params: Writable< {}>;
|
|
1147
|
+
update: {
|
|
1148
|
+
(key: string, value: unknown, options?: RouterPushOptions | undefined): Promise<void>;
|
|
1149
|
+
(params: Partial<{}>, options?: RouterPushOptions | undefined): Promise<void>;
|
|
1150
|
+
};
|
|
1701
1151
|
}>;
|
|
1702
1152
|
component: Component;
|
|
1703
1153
|
rejection: {
|
|
@@ -1714,57 +1164,34 @@ name?: string | undefined;
|
|
|
1714
1164
|
*/
|
|
1715
1165
|
export declare type Routes = Readonly<Route[]>;
|
|
1716
1166
|
|
|
1717
|
-
/**
|
|
1718
|
-
* Represents an immutable array of Route instances. Return value of `createRoutes`, expected param for `createRouter`.
|
|
1719
|
-
*/
|
|
1720
|
-
declare type Routes_2 = Readonly<Route_2[]>
|
|
1721
|
-
|
|
1722
1167
|
declare type RoutesKey<TRoutes extends Routes> = string & keyof RoutesMap<TRoutes>;
|
|
1723
1168
|
|
|
1724
|
-
declare type RoutesKey_2<TRoutes extends Routes_2> = string & keyof RoutesMap_2<TRoutes>
|
|
1725
|
-
|
|
1726
1169
|
declare type RoutesMap<TRoutes extends Routes = []> = {
|
|
1727
1170
|
[K in TRoutes[number] as NamedNotDisabled<K> extends {
|
|
1728
1171
|
key: string;
|
|
1729
1172
|
} ? NamedNotDisabled<K>['key'] : never]: NamedNotDisabled<K>;
|
|
1730
1173
|
};
|
|
1731
1174
|
|
|
1732
|
-
declare type
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
declare type RouteUpdate<TRoute extends ResolvedRoute = ResolvedRoute> = {
|
|
1175
|
+
declare type RouteUpdate<TRoute extends ResolvedRoute = ResolvedRoute> = ResolvedRoute extends TRoute ? {
|
|
1176
|
+
(key: string, value: unknown, options?: RouterPushOptions): Promise<void>;
|
|
1177
|
+
(params: Partial<TRoute['params']>, options?: RouterPushOptions): Promise<void>;
|
|
1178
|
+
} : {
|
|
1737
1179
|
<TKey extends keyof TRoute['params']>(key: TKey, value: TRoute['params'][TKey], options?: RouterPushOptions): Promise<void>;
|
|
1738
1180
|
(params: Partial<TRoute['params']>, options?: RouterPushOptions): Promise<void>;
|
|
1739
1181
|
};
|
|
1740
1182
|
|
|
1741
|
-
declare type RouteUpdate_2<TRoute extends ResolvedRoute_2 = ResolvedRoute_2> = {
|
|
1742
|
-
<TKey extends keyof TRoute['params']>(key: TKey, value: TRoute['params'][TKey], options?: RouterPushOptions_2): Promise<void>,
|
|
1743
|
-
(params: Partial<TRoute['params']>, options?: RouterPushOptions_2): Promise<void>,
|
|
1744
|
-
}
|
|
1745
|
-
|
|
1746
1183
|
declare type StringHasValue<T extends string | undefined> = T extends undefined ? false : '' extends T ? false : true;
|
|
1747
1184
|
|
|
1185
|
+
export declare function throwIfDuplicateParamsAreFound(routes: Route[]): void;
|
|
1186
|
+
|
|
1748
1187
|
declare type ToCallback = (resolve: RegisteredRouter['resolve']) => string;
|
|
1749
1188
|
|
|
1750
1189
|
declare type ToPath<T extends string | Path> = T extends string ? Path<T, {}> : T;
|
|
1751
1190
|
|
|
1752
|
-
declare type ToPath_2<T extends string | Path_2> = T extends string ? Path_2<T, {}> : T
|
|
1753
|
-
|
|
1754
1191
|
declare type ToQuery<T extends string | Query | undefined> = T extends string ? Query<T, {}> : T extends undefined ? Query<'', {}> : unknown extends T ? Query<'', {}> : T;
|
|
1755
1192
|
|
|
1756
|
-
declare type ToQuery_2<T extends string | Query_2 | undefined> = T extends string
|
|
1757
|
-
? Query_2<T, {}>
|
|
1758
|
-
: T extends undefined
|
|
1759
|
-
? Query_2<'', {}>
|
|
1760
|
-
: unknown extends T
|
|
1761
|
-
? Query_2<'', {}>
|
|
1762
|
-
: T
|
|
1763
|
-
|
|
1764
1193
|
declare type Url = `http://${string}` | `https://${string}` | `/${string}` | '/';
|
|
1765
1194
|
|
|
1766
|
-
declare type Url_2 = `http://${string}` | `https://${string}` | `/${string}` | '/'
|
|
1767
|
-
|
|
1768
1195
|
export declare type UseLink = {
|
|
1769
1196
|
/**
|
|
1770
1197
|
* ResolvedRoute if matched. Same value as `router.find`
|
|
@@ -1833,9 +1260,17 @@ export declare function useRejection(): RouterRejection;
|
|
|
1833
1260
|
* The function also sets up a reactive watcher on the route object from the router to continually check the validity of the route key
|
|
1834
1261
|
* if provided, throwing an error if the validation fails at any point during the component's lifecycle.
|
|
1835
1262
|
*/
|
|
1836
|
-
export declare function useRoute
|
|
1263
|
+
export declare function useRoute(): RegisteredRouterRoute;
|
|
1264
|
+
|
|
1265
|
+
export declare function useRoute<TRouteKey extends RegisteredRoutesKey>(routeKey: TRouteKey, options: IsRouteOptions & {
|
|
1266
|
+
exact: true;
|
|
1267
|
+
}): RegisteredRouterRoute & {
|
|
1268
|
+
key: TRouteKey;
|
|
1269
|
+
};
|
|
1837
1270
|
|
|
1838
|
-
export declare function useRoute():
|
|
1271
|
+
export declare function useRoute<TRouteKey extends RegisteredRoutesKey>(routeKey: TRouteKey, options?: IsRouteOptions): RegisteredRouterRoute & {
|
|
1272
|
+
key: `${TRouteKey}${string}`;
|
|
1273
|
+
};
|
|
1839
1274
|
|
|
1840
1275
|
/**
|
|
1841
1276
|
* An error thrown when there is a mismatch between an expected route and the one actually used.
|
|
@@ -1850,10 +1285,6 @@ export declare class UseRouteInvalidError extends Error {
|
|
|
1850
1285
|
constructor(routeName: string, actualRouteName: string);
|
|
1851
1286
|
}
|
|
1852
1287
|
|
|
1853
|
-
export declare type UseRouteOptions = {
|
|
1854
|
-
exact?: boolean;
|
|
1855
|
-
};
|
|
1856
|
-
|
|
1857
1288
|
/**
|
|
1858
1289
|
* A composition to access the registered router instance within a Vue component.
|
|
1859
1290
|
*
|
|
@@ -1870,13 +1301,6 @@ declare type WithComponent = {
|
|
|
1870
1301
|
component: Component;
|
|
1871
1302
|
};
|
|
1872
1303
|
|
|
1873
|
-
declare type WithComponent_2 = {
|
|
1874
|
-
/**
|
|
1875
|
-
* A Vue component, which can be either synchronous or asynchronous components.
|
|
1876
|
-
*/
|
|
1877
|
-
component: Component,
|
|
1878
|
-
}
|
|
1879
|
-
|
|
1880
1304
|
declare type WithComponents = {
|
|
1881
1305
|
/**
|
|
1882
1306
|
* Multiple components for named views, which can be either synchronous or asynchronous components.
|
|
@@ -1884,13 +1308,6 @@ declare type WithComponents = {
|
|
|
1884
1308
|
components: Record<string, Component>;
|
|
1885
1309
|
};
|
|
1886
1310
|
|
|
1887
|
-
declare type WithComponents_2 = {
|
|
1888
|
-
/**
|
|
1889
|
-
* Multiple components for named views, which can be either synchronous or asynchronous components.
|
|
1890
|
-
*/
|
|
1891
|
-
components: Record<string, Component>,
|
|
1892
|
-
}
|
|
1893
|
-
|
|
1894
1311
|
export declare function withDefault<TParam extends Param>(param: TParam, defaultValue: ExtractParamType<TParam>): ParamWithDefault<TParam>;
|
|
1895
1312
|
|
|
1896
1313
|
/**
|
|
@@ -1905,32 +1322,14 @@ declare type WithHooks = {
|
|
|
1905
1322
|
onAfterRouteLeave?: MaybeArray<AfterRouteHook>;
|
|
1906
1323
|
};
|
|
1907
1324
|
|
|
1908
|
-
/**
|
|
1909
|
-
* Defines route hooks that can be applied before entering, updating, or leaving a route, as well as after these events.
|
|
1910
|
-
*/
|
|
1911
|
-
declare type WithHooks_2 = {
|
|
1912
|
-
onBeforeRouteEnter?: MaybeArray_2<BeforeRouteHook_2>,
|
|
1913
|
-
onBeforeRouteUpdate?: MaybeArray_2<BeforeRouteHook_2>,
|
|
1914
|
-
onBeforeRouteLeave?: MaybeArray_2<BeforeRouteHook_2>,
|
|
1915
|
-
onAfterRouteEnter?: MaybeArray_2<AfterRouteHook_2>,
|
|
1916
|
-
onAfterRouteUpdate?: MaybeArray_2<AfterRouteHook_2>,
|
|
1917
|
-
onAfterRouteLeave?: MaybeArray_2<AfterRouteHook_2>,
|
|
1918
|
-
}
|
|
1919
|
-
|
|
1920
1325
|
declare type WithOptionalProperties<T> = {
|
|
1921
1326
|
[P in keyof T]-?: undefined extends T[P] ? P : never;
|
|
1922
1327
|
}[keyof T];
|
|
1923
1328
|
|
|
1924
|
-
declare type WithOptionalProperties_2<T> = {
|
|
1925
|
-
[P in keyof T]-?: undefined extends T[P] ? P : never
|
|
1926
|
-
}[keyof T]
|
|
1927
|
-
|
|
1928
1329
|
declare type Writable<T> = {
|
|
1929
1330
|
-readonly [P in keyof T]: T[P];
|
|
1930
1331
|
};
|
|
1931
1332
|
|
|
1932
|
-
declare type Writable_2<T> = { -readonly [P in keyof T]: T[P] }
|
|
1933
|
-
|
|
1934
1333
|
export { }
|
|
1935
1334
|
|
|
1936
1335
|
|