@kitbag/router 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/kitbag-router.d.ts +793 -41
- package/dist/kitbag-router.js +770 -728
- package/dist/kitbag-router.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/kitbag-router.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AsyncComponentLoader } from 'vue';
|
|
2
2
|
import { Component } from 'vue';
|
|
3
3
|
import { ComponentOptionsMixin } from 'vue';
|
|
4
|
-
import { DeepReadonly } from 'vue';
|
|
5
4
|
import { DefineComponent } from 'vue';
|
|
6
5
|
import { ExtractPropTypes } from 'vue';
|
|
7
6
|
import { FunctionalComponent } from 'vue';
|
|
@@ -56,6 +55,13 @@ declare type __VLS_WithTemplateSlots_2<T, S> = T & {
|
|
|
56
55
|
*/
|
|
57
56
|
export declare type AddAfterRouteHook = (hook: AfterRouteHook) => RouteHookRemove;
|
|
58
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
|
+
|
|
59
65
|
/**
|
|
60
66
|
* Adds a hook that is called before a route change. Returns a function to remove the hook.
|
|
61
67
|
* @param hook - {@link BeforeRouteHook} The hook function to add.
|
|
@@ -63,6 +69,13 @@ export declare type AddAfterRouteHook = (hook: AfterRouteHook) => RouteHookRemov
|
|
|
63
69
|
*/
|
|
64
70
|
export declare type AddBeforeRouteHook = (hook: BeforeRouteHook) => RouteHookRemove;
|
|
65
71
|
|
|
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
|
+
|
|
66
79
|
/**
|
|
67
80
|
* Represents a function called after a route change has occurred.
|
|
68
81
|
* @param to - {@link ResolvedRoute} The resolved route the router has navigated to.
|
|
@@ -71,11 +84,24 @@ export declare type AddBeforeRouteHook = (hook: BeforeRouteHook) => RouteHookRem
|
|
|
71
84
|
*/
|
|
72
85
|
export declare type AfterRouteHook = (to: ResolvedRoute, context: AfterRouteHookContext) => MaybePromise<void>;
|
|
73
86
|
|
|
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
|
+
|
|
74
95
|
/**
|
|
75
96
|
* Context provided to route hooks, containing context of previous route and functions for triggering rejections and push/replace to another route.
|
|
76
97
|
*/
|
|
77
98
|
declare type AfterRouteHookContext = RouteHookContext;
|
|
78
99
|
|
|
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
|
+
|
|
79
105
|
/**
|
|
80
106
|
* Enumerates the lifecycle events for after route hooks.
|
|
81
107
|
*/
|
|
@@ -89,6 +115,10 @@ export declare type AfterRouteHookResponse<TRoutes extends Routes> = RouteHookSu
|
|
|
89
115
|
|
|
90
116
|
declare type AllPropertiesAreOptional<T> = Record<string, unknown> extends T ? true : IsEmptyObject<OnlyRequiredProperties<T>>;
|
|
91
117
|
|
|
118
|
+
declare type AllPropertiesAreOptional_2<T> = Record<string, unknown> extends T
|
|
119
|
+
? true
|
|
120
|
+
: IsEmptyObject_2<OnlyRequiredProperties_2<T>>
|
|
121
|
+
|
|
92
122
|
declare type BaseResolvedRoute = Route & {
|
|
93
123
|
path: {
|
|
94
124
|
params: Record<string, unknown>;
|
|
@@ -98,6 +128,8 @@ declare type BaseResolvedRoute = Route & {
|
|
|
98
128
|
};
|
|
99
129
|
};
|
|
100
130
|
|
|
131
|
+
declare type BaseResolvedRoute_2 = Route_2 & { path: { params: Record<string, unknown> }, query: { params: Record<string, unknown> } }
|
|
132
|
+
|
|
101
133
|
declare type BaseRoute = {
|
|
102
134
|
key: string;
|
|
103
135
|
disabled: false;
|
|
@@ -109,6 +141,8 @@ declare type BaseRoute = {
|
|
|
109
141
|
};
|
|
110
142
|
};
|
|
111
143
|
|
|
144
|
+
declare type BaseRoute_2 = { key: string, disabled: false, path: { params: Record<string, unknown> }, query: { params: Record<string, unknown> } }
|
|
145
|
+
|
|
112
146
|
/**
|
|
113
147
|
* Represents a function called before a route change, potentially altering the routing operation.
|
|
114
148
|
* @param to - {@link ResolvedRoute} The resolved route the router is navigating to.
|
|
@@ -117,6 +151,14 @@ declare type BaseRoute = {
|
|
|
117
151
|
*/
|
|
118
152
|
export declare type BeforeRouteHook = (to: ResolvedRoute, context: BeforeRouteHookContext) => MaybePromise<void>;
|
|
119
153
|
|
|
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
|
+
|
|
120
162
|
/**
|
|
121
163
|
* Context provided to route hooks, containing context of previous route and functions for triggering rejections, push/replace to another route,
|
|
122
164
|
* as well as aborting current route change.
|
|
@@ -125,6 +167,14 @@ declare type BeforeRouteHookContext = RouteHookContext & {
|
|
|
125
167
|
abort: RouteHookAbort;
|
|
126
168
|
};
|
|
127
169
|
|
|
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
|
+
|
|
128
178
|
/**
|
|
129
179
|
* Enumerates the lifecycle events for before route hooks.
|
|
130
180
|
*/
|
|
@@ -136,10 +186,14 @@ export declare type BeforeRouteHookLifecycle = 'onBeforeRouteEnter' | 'onBeforeR
|
|
|
136
186
|
*/
|
|
137
187
|
export declare type BeforeRouteHookResponse<TRoutes extends Routes> = RouteHookSuccessResponse | RouteHookPushResponse<TRoutes> | RouteHookRejectResponse | RouteHookAbortResponse;
|
|
138
188
|
|
|
139
|
-
declare const builtInRejections:
|
|
189
|
+
declare const builtInRejections: ['NotFound'];
|
|
190
|
+
|
|
191
|
+
declare const builtInRejections_2: ['NotFound'] = ['NotFound'];
|
|
140
192
|
|
|
141
193
|
declare type BuiltInRejectionType = typeof builtInRejections[number];
|
|
142
194
|
|
|
195
|
+
declare type BuiltInRejectionType_2 = typeof builtInRejections_2[number]
|
|
196
|
+
|
|
143
197
|
/**
|
|
144
198
|
* Represents properties for child routes, including required component, name, and path.
|
|
145
199
|
*/
|
|
@@ -166,6 +220,32 @@ export declare type ChildRouteProps = (WithComponent | WithComponents) & WithHoo
|
|
|
166
220
|
meta?: RouteMeta;
|
|
167
221
|
};
|
|
168
222
|
|
|
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
|
+
|
|
169
249
|
declare type CombineName<TParentName extends string | undefined, TChildName extends string | undefined> = TParentName extends string ? TChildName extends string ? `${TParentName}.${TChildName}` : TParentName : TChildName extends string ? TChildName : '';
|
|
170
250
|
|
|
171
251
|
declare type CombinePath<TParent extends Path, TChild extends Path> = ToPath<TParent> extends {
|
|
@@ -210,6 +290,12 @@ export declare function component<TComponent extends Component>(component: TComp
|
|
|
210
290
|
|
|
211
291
|
declare type Constructor = new (...args: any) => any;
|
|
212
292
|
|
|
293
|
+
export declare function createParam<TParam extends ParamWithDefault>(param: TParam): TParam;
|
|
294
|
+
|
|
295
|
+
export declare function createParam<TParam extends Param>(param: TParam): ParamGetSet<ExtractParamType<TParam>>;
|
|
296
|
+
|
|
297
|
+
export declare function createParam<TParam extends Param>(param: TParam, defaultValue: ExtractParamType<TParam>): ParamWithDefault<TParam>;
|
|
298
|
+
|
|
213
299
|
/**
|
|
214
300
|
* Creates a router instance for a Vue application, equipped with methods for route handling, lifecycle hooks, and state management.
|
|
215
301
|
*
|
|
@@ -264,64 +350,179 @@ export declare class DuplicateParamsError extends Error {
|
|
|
264
350
|
*/
|
|
265
351
|
export declare type ExtractParamName<TParam extends string> = TParam extends `?${infer Param}` ? Param extends '' ? never : Param : TParam extends '' ? never : TParam;
|
|
266
352
|
|
|
353
|
+
/**
|
|
354
|
+
* Extracts the parameter name from a string, handling optional parameters denoted by a leading '?'.
|
|
355
|
+
* @template TParam - The string from which to extract the parameter name.
|
|
356
|
+
* @returns The extracted parameter name, or never if the parameter string is empty.
|
|
357
|
+
*/
|
|
358
|
+
declare type ExtractParamName_2<
|
|
359
|
+
TParam extends string
|
|
360
|
+
> = TParam extends `?${infer Param}`
|
|
361
|
+
? Param extends ''
|
|
362
|
+
? never
|
|
363
|
+
: Param
|
|
364
|
+
: TParam extends ''
|
|
365
|
+
? never
|
|
366
|
+
: TParam
|
|
367
|
+
|
|
267
368
|
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<{
|
|
268
369
|
[P in ExtractParamName<Param>]: ExtractPathParamType<Param, TParams>;
|
|
269
370
|
}, ExtractParamsFromPathString<Rest, TParams>> : Record<never, never>;
|
|
270
371
|
|
|
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
|
+
/**
|
|
380
|
+
* Extracts the actual type from a parameter type, handling getters, setters, and potential undefined values.
|
|
381
|
+
* This type also is responsible for narrowing possibly undefined values when the param has a default value.
|
|
382
|
+
* @template TParam - The parameter type.
|
|
383
|
+
* @returns The extracted type, or 'string' as a fallback.
|
|
384
|
+
*/
|
|
385
|
+
export declare type ExtractParamType<TParam extends Param> = TParam extends ParamGetSet<infer Type> ? TParam extends IsOptionalParam ? TParam extends ParamWithDefault ? Type : Type | undefined : Type : TParam extends ParamGetter ? ReturnType<TParam> : string;
|
|
386
|
+
|
|
271
387
|
/**
|
|
272
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.
|
|
273
390
|
* @template TParam - The parameter type.
|
|
274
391
|
* @returns The extracted type, or 'string' as a fallback.
|
|
275
392
|
*/
|
|
276
|
-
|
|
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
|
|
277
402
|
|
|
278
403
|
/**
|
|
279
404
|
* Transforms a record of parameter types into a type with optional properties where the original type allows undefined.
|
|
280
405
|
* @template TParams - The record of parameter types, possibly including undefined.
|
|
281
406
|
* @returns A new type with the appropriate properties marked as optional.
|
|
282
407
|
*/
|
|
283
|
-
export declare type ExtractParamTypes<TParams extends Record<string, Param
|
|
408
|
+
export declare type ExtractParamTypes<TParams extends Record<string, Param>> = Identity<MakeOptional<{
|
|
284
409
|
[K in keyof TParams]: ExtractParamType<TParams[K]>;
|
|
285
410
|
}>>;
|
|
286
411
|
|
|
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
|
+
declare type ExtractParamTypesWithoutLosingOptional<TParams extends Record<string, Param>> = Identity<MakeOptional<{
|
|
422
|
+
[K in keyof TParams]: ExtractParamTypeWithoutLosingOptional<TParams[K]>;
|
|
423
|
+
}>>;
|
|
424
|
+
|
|
425
|
+
declare type ExtractParamTypesWithoutLosingOptional_2<TParams extends Record<string, Param_2>> = Identity_2<MakeOptional_2<{
|
|
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
|
+
|
|
287
439
|
/**
|
|
288
440
|
* Determines the type of a path parameter from a record of parameter types, considering optional parameters.
|
|
289
441
|
* @template TParam - The parameter name string.
|
|
290
442
|
* @template TParams - The record object mapping parameter names to their types.
|
|
291
443
|
* @returns The type associated with the parameter, or StringConstructor if unspecified; may be undefined for optional parameters.
|
|
292
444
|
*/
|
|
293
|
-
export declare type ExtractPathParamType<TParam extends string, TParams extends Record<string, Param | undefined>> = TParam extends `?${infer OptionalParam}` ? OptionalParam extends keyof TParams ? TParams[OptionalParam]
|
|
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;
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Determines the type of a path parameter from a record of parameter types, considering optional parameters.
|
|
449
|
+
* @template TParam - The parameter name string.
|
|
450
|
+
* @template TParams - The record object mapping parameter names to their types.
|
|
451
|
+
* @returns The type associated with the parameter, or StringConstructor if unspecified; may be undefined for optional parameters.
|
|
452
|
+
*/
|
|
453
|
+
declare type ExtractPathParamType_2<
|
|
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
|
|
294
465
|
|
|
295
466
|
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<{
|
|
296
467
|
[P in ExtractParamName<Param>]: ExtractPathParamType<Param, TParams>;
|
|
297
468
|
}, ExtractQueryParamsFromQueryString<Rest, TParams>> : Record<never, never>;
|
|
298
469
|
|
|
470
|
+
declare type ExtractQueryParamsFromQueryString_2<
|
|
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
|
+
|
|
299
477
|
declare type ExtractRouteChildren<TRoute extends RouteProps> = TRoute extends ParentRouteProps ? TRoute['children'] extends Route[] ? TRoute['children'] : [] : [];
|
|
300
478
|
|
|
301
479
|
/**
|
|
302
480
|
* Extracts combined types of path and query parameters for a given route, creating a unified parameter object.
|
|
481
|
+
* This parameter object type represents the expected type when accessing params from router.route or useRoute.
|
|
303
482
|
* @template TRoute - The route type from which to extract and merge parameter types.
|
|
304
483
|
* @returns A record of parameter names to their respective types, extracted and merged from both path and query parameters.
|
|
305
484
|
*/
|
|
306
|
-
export declare type ExtractRouteParamTypes<TRoute extends {
|
|
485
|
+
export declare type ExtractRouteParamTypes<TRoute> = TRoute extends {
|
|
307
486
|
path: {
|
|
308
|
-
params: Record<string,
|
|
487
|
+
params: infer PathParams extends Record<string, Param>;
|
|
309
488
|
};
|
|
310
489
|
query: {
|
|
311
|
-
params: Record<string,
|
|
490
|
+
params: infer QueryParams extends Record<string, Param>;
|
|
312
491
|
};
|
|
313
|
-
}
|
|
492
|
+
} ? ExtractParamTypes<MergeParams<PathParams, QueryParams>> : Record<string, unknown>;
|
|
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>
|
|
506
|
+
|
|
507
|
+
declare type ExtractRouteParamTypesWithoutLosingOptional<TRoute> = TRoute extends {
|
|
314
508
|
path: {
|
|
315
|
-
params: infer PathParams extends Record<string, Param
|
|
509
|
+
params: infer PathParams extends Record<string, Param>;
|
|
316
510
|
};
|
|
317
511
|
query: {
|
|
318
|
-
params: infer QueryParams extends Record<string, Param
|
|
512
|
+
params: infer QueryParams extends Record<string, Param>;
|
|
319
513
|
};
|
|
320
|
-
} ?
|
|
514
|
+
} ? ExtractParamTypesWithoutLosingOptional<MergeParams<PathParams, QueryParams>> : Record<string, unknown>;
|
|
515
|
+
|
|
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>
|
|
321
522
|
|
|
322
523
|
declare type Flatten<T extends any[]> = T extends [infer First, ...infer Rest] ? First extends unknown[] ? Flatten<[...First, ...Flatten<Rest>]> : [First, ...Flatten<Rest>] : [];
|
|
323
524
|
|
|
324
|
-
declare type FlattenRoute<TRoute extends RouteProps, TKey extends string
|
|
525
|
+
declare type FlattenRoute<TRoute extends RouteProps, TKey extends string = string & TRoute['name'], 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>> = [
|
|
325
526
|
Route<TKey, TPath, TQuery, TDisabled>,
|
|
326
527
|
...{
|
|
327
528
|
[K in keyof TChildren]: Route<CombineName<TKey, TChildren[K]['key']>, CombinePath<TPath, TChildren[K]['path']>, CombineQuery<TQuery, TChildren[K]['query']>, TChildren[K]['disabled']>;
|
|
@@ -338,8 +539,22 @@ declare type Identity<T> = T extends object ? {} & {
|
|
|
338
539
|
[P in keyof T as T[P] extends never ? never : P]: T[P];
|
|
339
540
|
} : T;
|
|
340
541
|
|
|
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
|
+
|
|
341
546
|
declare type IsEmptyObject<T> = T extends Record<string, never> ? (keyof T extends never ? true : false) : false;
|
|
342
547
|
|
|
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
|
+
|
|
343
558
|
/**
|
|
344
559
|
* Type guard to check if a value conforms to the ParamGetSet type.
|
|
345
560
|
* @param value - The value to check.
|
|
@@ -354,6 +569,8 @@ export declare function isParamGetSet(value: Param): value is ParamGetSet;
|
|
|
354
569
|
*/
|
|
355
570
|
export declare function isParamGetter(value: Param): value is ParamGetter;
|
|
356
571
|
|
|
572
|
+
export declare function isParamWithDefault(param: Param): param is ParamWithDefault;
|
|
573
|
+
|
|
357
574
|
/**
|
|
358
575
|
* Type guard function to determine if a given route configuration is a parent route, based on the presence of children.
|
|
359
576
|
* @param value - The route configuration to check.
|
|
@@ -365,36 +582,40 @@ export declare function isParentRouteWithoutComponent(value: RouteProps): value
|
|
|
365
582
|
|
|
366
583
|
export declare function isRoute(route: unknown): route is RouterRoute;
|
|
367
584
|
|
|
368
|
-
export declare function isRoute<TRouteKey extends RegisteredRoutesKey>(route: unknown, routeKey: TRouteKey, options
|
|
585
|
+
export declare function isRoute<TRouteKey extends RegisteredRoutesKey>(route: unknown, routeKey: TRouteKey, options?: IsRouteOptions): route is RouterRoute<ResolvedRoute<RegisteredRouteMap[TRouteKey]>>;
|
|
369
586
|
|
|
370
587
|
declare type IsRouteOptions = {
|
|
371
588
|
exact?: boolean;
|
|
372
589
|
};
|
|
373
590
|
|
|
374
|
-
declare const isRouterRouteSymbol: unique symbol;
|
|
375
|
-
|
|
376
591
|
export declare function isRouteWithComponent(value: RouteProps): value is RouteProps & WithComponent;
|
|
377
592
|
|
|
378
593
|
export declare function isRouteWithComponent(value: Readonly<RouteProps>): value is Readonly<RouteProps & WithComponent>;
|
|
379
594
|
|
|
380
|
-
export declare function isRouteWithComponent(value: DeepReadonly<RouteProps>): value is DeepReadonly<RouteProps & WithComponent>;
|
|
381
|
-
|
|
382
595
|
export declare function isRouteWithComponents(value: RouteProps): value is RouteProps & WithComponents;
|
|
383
596
|
|
|
384
597
|
export declare function isRouteWithComponents(value: Readonly<RouteProps>): value is Readonly<RouteProps & WithComponents>;
|
|
385
598
|
|
|
386
|
-
export declare function isRouteWithComponents(value: DeepReadonly<RouteProps>): value is DeepReadonly<RouteProps & WithComponents>;
|
|
387
|
-
|
|
388
599
|
declare type MakeOptional<T> = {
|
|
389
600
|
[P in WithOptionalProperties<T>]?: T[P];
|
|
390
601
|
} & {
|
|
391
602
|
[P in Exclude<keyof T, WithOptionalProperties<T>>]: T[P];
|
|
392
603
|
};
|
|
393
604
|
|
|
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
|
+
|
|
394
611
|
declare type MaybeArray<T> = T | T[];
|
|
395
612
|
|
|
613
|
+
declare type MaybeArray_2<T> = T | T[]
|
|
614
|
+
|
|
396
615
|
declare type MaybePromise<T> = T | Promise<T>;
|
|
397
616
|
|
|
617
|
+
declare type MaybePromise_2<T> = T | Promise<T>
|
|
618
|
+
|
|
398
619
|
/**
|
|
399
620
|
* Merges two parameter type records, ensuring no overlap in properties.
|
|
400
621
|
* @template TAlpha - The first record type.
|
|
@@ -405,8 +626,29 @@ export declare type MergeParams<TAlpha extends Record<string, unknown>, TBeta ex
|
|
|
405
626
|
[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;
|
|
406
627
|
};
|
|
407
628
|
|
|
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
|
+
|
|
408
648
|
declare type NamedNotDisabled<T> = T extends BaseRoute ? T : never;
|
|
409
649
|
|
|
650
|
+
declare type NamedNotDisabled_2<T> = T extends BaseRoute_2 ? T : never
|
|
651
|
+
|
|
410
652
|
/**
|
|
411
653
|
* Registers a hook that is called after a route has been entered. Must be called during setup.
|
|
412
654
|
* This allows performing actions right after the component becomes active, such as fetching data or setting up event listeners.
|
|
@@ -456,29 +698,72 @@ declare type OnlyRequiredProperties<T> = {
|
|
|
456
698
|
[K in keyof T as Extract<T[K], undefined> extends never ? K : never]: T[K];
|
|
457
699
|
};
|
|
458
700
|
|
|
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
|
+
|
|
459
715
|
export declare type Param = ParamGetter | ParamGetSet | RegExp | BooleanConstructor | NumberConstructor | StringConstructor | DateConstructor | JSON;
|
|
460
716
|
|
|
717
|
+
declare type Param_2 = ParamGetter_2 | ParamGetSet_2 | RegExp | BooleanConstructor | NumberConstructor | StringConstructor | DateConstructor | JSON
|
|
718
|
+
|
|
461
719
|
export declare type ParamEnd = typeof paramEnd;
|
|
462
720
|
|
|
463
721
|
export declare const paramEnd = "]";
|
|
464
722
|
|
|
723
|
+
declare type ParamEnd_2 = typeof paramEnd_2
|
|
724
|
+
|
|
725
|
+
declare const paramEnd_2 = ']';
|
|
726
|
+
|
|
465
727
|
export declare type ParamExtras = {
|
|
466
728
|
invalid: (message?: string) => never;
|
|
467
729
|
};
|
|
468
730
|
|
|
731
|
+
declare type ParamExtras_2 = {
|
|
732
|
+
invalid: (message?: string) => never,
|
|
733
|
+
}
|
|
734
|
+
|
|
469
735
|
export declare type ParamGetSet<T = any> = {
|
|
470
736
|
get: ParamGetter<T>;
|
|
471
737
|
set: ParamSetter<T>;
|
|
738
|
+
defaultValue?: T;
|
|
472
739
|
};
|
|
473
740
|
|
|
741
|
+
declare type ParamGetSet_2<T = any> = {
|
|
742
|
+
get: ParamGetter_2<T>,
|
|
743
|
+
set: ParamSetter_2<T>,
|
|
744
|
+
defaultValue?: T,
|
|
745
|
+
}
|
|
746
|
+
|
|
474
747
|
export declare type ParamGetter<T = any> = (value: string, extras: ParamExtras) => T;
|
|
475
748
|
|
|
749
|
+
declare type ParamGetter_2<T = any> = (value: string, extras: ParamExtras_2) => T
|
|
750
|
+
|
|
476
751
|
export declare type ParamSetter<T = any> = (value: T, extras: ParamExtras) => string;
|
|
477
752
|
|
|
753
|
+
declare type ParamSetter_2<T = any> = (value: T, extras: ParamExtras_2) => string
|
|
754
|
+
|
|
478
755
|
export declare type ParamStart = typeof paramStart;
|
|
479
756
|
|
|
480
757
|
export declare const paramStart = "[";
|
|
481
758
|
|
|
759
|
+
declare type ParamStart_2 = typeof paramStart_2
|
|
760
|
+
|
|
761
|
+
declare const paramStart_2 = '[';
|
|
762
|
+
|
|
763
|
+
export declare type ParamWithDefault<TParam extends Param = Param> = Required<ParamGetSet<ExtractParamType<TParam>>>;
|
|
764
|
+
|
|
765
|
+
declare type ParamWithDefault_2<TParam extends Param_2 = Param_2> = Required<ParamGetSet_2<ExtractParamType_2<TParam>>>
|
|
766
|
+
|
|
482
767
|
/**
|
|
483
768
|
* Represents properties common to parent routes in a route configuration, including hooks, path, and optional query parameters.
|
|
484
769
|
*/
|
|
@@ -509,9 +794,39 @@ export declare type ParentRouteProps = Partial<WithComponent | WithComponents> &
|
|
|
509
794
|
meta?: RouteMeta;
|
|
510
795
|
};
|
|
511
796
|
|
|
512
|
-
|
|
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>> = {
|
|
513
828
|
path: TPath;
|
|
514
|
-
params: Identity<ExtractParamsFromPathString<TPath, TParams>>;
|
|
829
|
+
params: string extends TPath ? Record<string, Param> : Identity<ExtractParamsFromPathString<TPath, TParams>>;
|
|
515
830
|
toString: () => string;
|
|
516
831
|
};
|
|
517
832
|
|
|
@@ -540,17 +855,30 @@ declare type Path<TPath extends string = any, TParams extends PathParams<TPath>
|
|
|
540
855
|
*/
|
|
541
856
|
export declare function path<TPath extends string, TParams extends PathParams<TPath>>(path: TPath, params: Identity<TParams>): Path<TPath, TParams>;
|
|
542
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
|
+
}
|
|
866
|
+
|
|
543
867
|
declare type PathParams<TPath extends string> = {
|
|
544
868
|
[K in keyof ExtractParamsFromPathString<TPath>]?: Param;
|
|
545
869
|
};
|
|
546
870
|
|
|
871
|
+
declare type PathParams_2<TPath extends string> = {
|
|
872
|
+
[K in keyof ExtractParamsFromPathString_2<TPath>]?: Param_2
|
|
873
|
+
}
|
|
874
|
+
|
|
547
875
|
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;
|
|
548
876
|
|
|
549
877
|
declare type PropsGetter<TComponent extends Component> = () => MaybePromise<Props<TComponent>>;
|
|
550
878
|
|
|
551
|
-
declare type Query<
|
|
552
|
-
query:
|
|
553
|
-
params: Identity<ExtractQueryParamsFromQueryString<
|
|
879
|
+
declare type Query<TQuery extends string = string, TQueryParams extends QueryParams<TQuery> = Record<string, Param | undefined>> = {
|
|
880
|
+
query: TQuery;
|
|
881
|
+
params: string extends TQuery ? Record<string, Param> : Identity<ExtractQueryParamsFromQueryString<TQuery, TQueryParams>>;
|
|
554
882
|
toString: () => string;
|
|
555
883
|
};
|
|
556
884
|
|
|
@@ -579,10 +907,23 @@ declare type Query<T extends string = any, P extends QueryParams<T> = any> = {
|
|
|
579
907
|
*/
|
|
580
908
|
export declare function query<TQuery extends string, TParams extends QueryParams<TQuery>>(query: TQuery, params: Identity<TParams>): Query<TQuery, TParams>;
|
|
581
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
|
+
}
|
|
918
|
+
|
|
582
919
|
declare type QueryParams<T extends string> = {
|
|
583
920
|
[K in keyof ExtractQueryParamsFromQueryString<T>]?: Param;
|
|
584
921
|
};
|
|
585
922
|
|
|
923
|
+
declare type QueryParams_2<T extends string> = {
|
|
924
|
+
[K in keyof ExtractQueryParamsFromQueryString_2<T>]?: Param_2
|
|
925
|
+
}
|
|
926
|
+
|
|
586
927
|
/**
|
|
587
928
|
* Represents the state of currently registered router, and rejections. Used to provide correct type context for
|
|
588
929
|
* components like `RouterLink`, as well as for composables like `useRouter`, `useRoute`, and hooks.
|
|
@@ -599,6 +940,21 @@ declare type QueryParams<T extends string> = {
|
|
|
599
940
|
export declare interface Register {
|
|
600
941
|
}
|
|
601
942
|
|
|
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
|
+
|
|
602
958
|
/**
|
|
603
959
|
* Represents the possible Rejections registered within {@link Register}
|
|
604
960
|
*/
|
|
@@ -606,6 +962,13 @@ export declare type RegisteredRejectionType = Register extends {
|
|
|
606
962
|
rejections: infer TRejections extends string[];
|
|
607
963
|
} ? TRejections[number] : never;
|
|
608
964
|
|
|
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
|
+
|
|
609
972
|
/**
|
|
610
973
|
* Represents the a map of all possible RouteKeys with corresponding Route registered within {@link Register}
|
|
611
974
|
*/
|
|
@@ -623,11 +986,21 @@ export declare type RegisteredRouter = Register extends {
|
|
|
623
986
|
*/
|
|
624
987
|
export declare type RegisteredRouterPush = RouterPush<RegisteredRoutes>;
|
|
625
988
|
|
|
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
|
+
|
|
626
994
|
/**
|
|
627
995
|
* Represents the type for router `replace`, with types for routes registered within {@link Register}
|
|
628
996
|
*/
|
|
629
997
|
export declare type RegisteredRouterReplace = RouterReplace<RegisteredRoutes>;
|
|
630
998
|
|
|
999
|
+
/**
|
|
1000
|
+
* Represents the type for router `replace`, with types for routes registered within {@link Register}
|
|
1001
|
+
*/
|
|
1002
|
+
declare type RegisteredRouterReplace_2 = RouterReplace_2<RegisteredRoutes_2>
|
|
1003
|
+
|
|
631
1004
|
/**
|
|
632
1005
|
* Represents the State property registered within {@link Register}
|
|
633
1006
|
*/
|
|
@@ -642,6 +1015,13 @@ export declare type RegisteredRoutes = Register extends {
|
|
|
642
1015
|
router: Router<infer TRoutes extends Routes>;
|
|
643
1016
|
} ? TRoutes : Route<string, Path<'', {}>, Query<'', {}>, false>[];
|
|
644
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>[]
|
|
1024
|
+
|
|
645
1025
|
/**
|
|
646
1026
|
* Represents the union of all possible RouteKeys registered within {@link Register}
|
|
647
1027
|
*/
|
|
@@ -651,7 +1031,7 @@ export declare type RegisteredRoutesKey = RoutesKey<RegisteredRoutes>;
|
|
|
651
1031
|
* Represents a route that the router has matched to current browser location.
|
|
652
1032
|
* @template TRoute - Underlying Route that has been resolved.
|
|
653
1033
|
*/
|
|
654
|
-
declare type ResolvedRoute<TRoute extends Route = BaseResolvedRoute> =
|
|
1034
|
+
declare type ResolvedRoute<TRoute extends Route = BaseResolvedRoute> = Readonly<{
|
|
655
1035
|
/**
|
|
656
1036
|
* The specific route properties that were matched in the current route.
|
|
657
1037
|
*/
|
|
@@ -660,7 +1040,7 @@ declare type ResolvedRoute<TRoute extends Route = BaseResolvedRoute> = DeepReado
|
|
|
660
1040
|
* The specific route properties that were matched in the current route, including any ancestors.
|
|
661
1041
|
* Order of routes will be from greatest ancestor to narrowest matched.
|
|
662
1042
|
*/
|
|
663
|
-
matches:
|
|
1043
|
+
matches: TRoute['matches'];
|
|
664
1044
|
/**
|
|
665
1045
|
* Unique identifier for the route, generated by joining route `name` by period. Key is used for routing and for matching.
|
|
666
1046
|
*/
|
|
@@ -672,14 +1052,47 @@ declare type ResolvedRoute<TRoute extends Route = BaseResolvedRoute> = DeepReado
|
|
|
672
1052
|
/**
|
|
673
1053
|
* Key value pair for route params, values will be the user provided value from current browser location.
|
|
674
1054
|
*/
|
|
675
|
-
params: ExtractRouteParamTypes<TRoute>;
|
|
1055
|
+
params: BaseResolvedRoute extends TRoute ? Record<string, unknown> : ExtractRouteParamTypes<TRoute>;
|
|
676
1056
|
}>;
|
|
677
1057
|
|
|
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
|
+
|
|
678
1086
|
declare type ResolvedRouteQuery = {
|
|
679
1087
|
get: (key: string) => string | null;
|
|
680
1088
|
getAll: (key: string) => string[];
|
|
681
1089
|
};
|
|
682
1090
|
|
|
1091
|
+
declare type ResolvedRouteQuery_2 = {
|
|
1092
|
+
get: (key: string) => string | null,
|
|
1093
|
+
getAll: (key: string) => string[],
|
|
1094
|
+
}
|
|
1095
|
+
|
|
683
1096
|
/**
|
|
684
1097
|
* Represents the structure of a route within the application. Return value of `createRoutes`
|
|
685
1098
|
* @template TKey - Represents the unique key identifying the route, typically a string.
|
|
@@ -687,7 +1100,7 @@ declare type ResolvedRouteQuery = {
|
|
|
687
1100
|
* @template TQuery - The type or structure of the query parameters associated with the route.
|
|
688
1101
|
* @template TDisabled - Indicates whether the route is disabled, which could affect routing logic.
|
|
689
1102
|
*/
|
|
690
|
-
export declare type Route<TKey extends string
|
|
1103
|
+
export declare type Route<TKey extends string = string, TPath extends string | Path = Path, TQuery extends string | Query = Query, TDisabled extends boolean = boolean> = {
|
|
691
1104
|
/**
|
|
692
1105
|
* The specific route properties that were matched in the current route.
|
|
693
1106
|
*/
|
|
@@ -716,8 +1129,51 @@ export declare type Route<TKey extends string | undefined = any, TPath extends s
|
|
|
716
1129
|
disabled: TDisabled extends boolean ? TDisabled : false;
|
|
717
1130
|
};
|
|
718
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,
|
|
1158
|
+
/**
|
|
1159
|
+
* Represents the structured path of the route, including path params.
|
|
1160
|
+
*/
|
|
1161
|
+
path: ToPath_2<TPath>,
|
|
1162
|
+
/**
|
|
1163
|
+
* Represents the structured query of the route, including query params.
|
|
1164
|
+
*/
|
|
1165
|
+
query: ToQuery_2<TQuery>,
|
|
1166
|
+
depth: number,
|
|
1167
|
+
/**
|
|
1168
|
+
* Indicates if the route is disabled.
|
|
1169
|
+
*/
|
|
1170
|
+
disabled: TDisabled extends boolean ? TDisabled : false,
|
|
1171
|
+
}
|
|
1172
|
+
|
|
719
1173
|
declare type RouteGetByKey<TRoutes extends Routes, TKey extends RoutesKey<TRoutes>> = RoutesMap<TRoutes>[TKey];
|
|
720
1174
|
|
|
1175
|
+
declare type RouteGetByKey_2<TRoutes extends Routes_2, TKey extends RoutesKey_2<TRoutes>> = RoutesMap_2<TRoutes>[TKey]
|
|
1176
|
+
|
|
721
1177
|
/**
|
|
722
1178
|
* Generic type representing a route hook, which can be either before or after a route change.
|
|
723
1179
|
*/
|
|
@@ -728,6 +1184,11 @@ export declare type RouteHook = BeforeRouteHook | AfterRouteHook;
|
|
|
728
1184
|
*/
|
|
729
1185
|
export declare type RouteHookAbort = () => void;
|
|
730
1186
|
|
|
1187
|
+
/**
|
|
1188
|
+
* A function that can be called to abort a routing operation.
|
|
1189
|
+
*/
|
|
1190
|
+
declare type RouteHookAbort_2 = () => void
|
|
1191
|
+
|
|
731
1192
|
/**
|
|
732
1193
|
* Defines the structure of an aborted route hook response.
|
|
733
1194
|
*/
|
|
@@ -745,6 +1206,16 @@ declare type RouteHookContext = {
|
|
|
745
1206
|
replace: RegisteredRouterReplace;
|
|
746
1207
|
};
|
|
747
1208
|
|
|
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
|
+
|
|
748
1219
|
/**
|
|
749
1220
|
* Union type for all route hook lifecycle events.
|
|
750
1221
|
*/
|
|
@@ -772,6 +1243,11 @@ declare type RouteHookRejectResponse = {
|
|
|
772
1243
|
*/
|
|
773
1244
|
export declare type RouteHookRemove = () => void;
|
|
774
1245
|
|
|
1246
|
+
/**
|
|
1247
|
+
* A function to remove a previously registered route hook.
|
|
1248
|
+
*/
|
|
1249
|
+
declare type RouteHookRemove_2 = () => void
|
|
1250
|
+
|
|
775
1251
|
/**
|
|
776
1252
|
* Union type for all possible route hook responses, covering both before and after scenarios.
|
|
777
1253
|
* @template TRoutes - The type of the routes configuration.
|
|
@@ -799,20 +1275,48 @@ declare type RouteHookSuccessResponse = {
|
|
|
799
1275
|
export declare interface RouteMeta extends Record<string, unknown> {
|
|
800
1276
|
}
|
|
801
1277
|
|
|
802
|
-
|
|
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
|
+
declare type RouteParamsByKey<TRoutes extends Routes, TKey extends string> = ExtractRouteParamTypesWithoutLosingOptional<RouteGetByKey<TRoutes, TKey>>;
|
|
1292
|
+
|
|
1293
|
+
declare type RouteParamsByKey_2<
|
|
1294
|
+
TRoutes extends Routes_2,
|
|
1295
|
+
TKey extends string
|
|
1296
|
+
> = ExtractRouteParamTypesWithoutLosingOptional_2<RouteGetByKey_2<TRoutes, TKey>>
|
|
803
1297
|
|
|
804
1298
|
/**
|
|
805
1299
|
* Unifies the properties of both parent and child routes, ensuring type safety and consistency across route configurations.
|
|
806
1300
|
*/
|
|
807
1301
|
export declare type RouteProps = Readonly<ParentRouteProps | ChildRouteProps>;
|
|
808
1302
|
|
|
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
|
+
|
|
809
1308
|
/**
|
|
810
1309
|
* The Route properties originally provided to `createRoutes`. The only change is normalizing meta to always default to an empty object.
|
|
811
1310
|
*/
|
|
812
|
-
declare type RoutePropsWithMeta = RouteProps & {
|
|
1311
|
+
export declare type RoutePropsWithMeta = RouteProps & {
|
|
813
1312
|
meta: RouteMeta;
|
|
814
1313
|
};
|
|
815
1314
|
|
|
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
|
+
|
|
816
1320
|
export declare type Router<TRoutes extends Routes = any> = Plugin_2 & {
|
|
817
1321
|
/**
|
|
818
1322
|
* Manages the current route state.
|
|
@@ -884,12 +1388,100 @@ export declare type Router<TRoutes extends Routes = any> = Plugin_2 & {
|
|
|
884
1388
|
initialized: Promise<void>;
|
|
885
1389
|
};
|
|
886
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
|
+
/**
|
|
1439
|
+
* Registers a hook to be called before a route is left.
|
|
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.
|
|
1448
|
+
*/
|
|
1449
|
+
onAfterRouteEnter: AddAfterRouteHook_2,
|
|
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
|
+
}
|
|
1463
|
+
|
|
887
1464
|
declare type RouterFind<TRoutes extends Routes> = {
|
|
888
1465
|
<TSource extends RoutesKey<TRoutes>>(source: TSource, ...args: RouterFindArgs<TRoutes, TSource>): ResolvedRoute | undefined;
|
|
889
1466
|
(source: Url): ResolvedRoute | undefined;
|
|
890
1467
|
};
|
|
891
1468
|
|
|
892
|
-
declare type
|
|
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
|
+
declare type RouterFindArgs<TRoutes extends Routes, TSource extends RoutesKey<TRoutes>, TParams = RouteParamsByKey<TRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: TParams] : [params: TParams];
|
|
1477
|
+
|
|
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]
|
|
893
1485
|
|
|
894
1486
|
declare type RouterHistoryMode = 'auto' | 'browser' | 'memory' | 'hash';
|
|
895
1487
|
|
|
@@ -943,15 +1535,37 @@ declare type RouterPush<TRoutes extends Routes = any> = {
|
|
|
943
1535
|
(source: Url, options?: RouterPushOptions): Promise<void>;
|
|
944
1536
|
};
|
|
945
1537
|
|
|
946
|
-
declare type
|
|
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
|
+
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
|
+
|
|
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]
|
|
947
1554
|
|
|
948
1555
|
declare type RouterPushOptions = {
|
|
949
1556
|
query?: Record<string, string>;
|
|
950
1557
|
replace?: boolean;
|
|
951
1558
|
};
|
|
952
1559
|
|
|
1560
|
+
declare type RouterPushOptions_2 = {
|
|
1561
|
+
query?: Record<string, string>,
|
|
1562
|
+
replace?: boolean,
|
|
1563
|
+
}
|
|
1564
|
+
|
|
953
1565
|
export declare type RouterReject = (type: RouterRejectionType) => void;
|
|
954
1566
|
|
|
1567
|
+
declare type RouterReject_2 = (type: RouterRejectionType_2) => void
|
|
1568
|
+
|
|
955
1569
|
declare type RouterRejection = Ref<null | {
|
|
956
1570
|
type: RouterRejectionType;
|
|
957
1571
|
component: Component;
|
|
@@ -965,39 +1579,102 @@ export declare const routerRejectionKey: InjectionKey<RouterRejection>;
|
|
|
965
1579
|
|
|
966
1580
|
declare type RouterRejectionType = BuiltInRejectionType | RegisteredRejectionType;
|
|
967
1581
|
|
|
1582
|
+
declare type RouterRejectionType_2 = BuiltInRejectionType_2 | RegisteredRejectionType_2
|
|
1583
|
+
|
|
968
1584
|
declare type RouterReplace<TRoutes extends Routes> = {
|
|
969
1585
|
<TSource extends RoutesKey<TRoutes>>(source: TSource, ...args: RouterReplaceArgs<TRoutes, TSource>): Promise<void>;
|
|
970
1586
|
(source: Url, options?: RouterReplaceOptions): Promise<void>;
|
|
971
1587
|
};
|
|
972
1588
|
|
|
973
|
-
declare type
|
|
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
|
+
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
|
+
|
|
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]
|
|
974
1605
|
|
|
975
1606
|
declare type RouterReplaceOptions = Omit<RouterPushOptions, 'replace'>;
|
|
976
1607
|
|
|
1608
|
+
declare type RouterReplaceOptions_2 = Omit<RouterPushOptions_2, 'replace'>
|
|
1609
|
+
|
|
977
1610
|
declare type RouterResolve<TRoutes extends Routes> = {
|
|
978
1611
|
<TSource extends RoutesKey<TRoutes>>(source: TSource, ...args: RouterResolveArgs<TRoutes, TSource>): string;
|
|
979
1612
|
(source: Url, options?: RouterResolveOptions): string;
|
|
980
1613
|
};
|
|
981
1614
|
|
|
982
|
-
declare type
|
|
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
|
+
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
|
+
|
|
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]
|
|
983
1631
|
|
|
984
1632
|
declare type RouterResolveOptions = {
|
|
985
1633
|
query?: Record<string, string>;
|
|
986
1634
|
};
|
|
987
1635
|
|
|
988
|
-
declare type
|
|
1636
|
+
declare type RouterResolveOptions_2 = {
|
|
1637
|
+
query?: Record<string, string>,
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
declare type RouterRoute<TRoute extends ResolvedRoute = ResolvedRoute> = Readonly<{
|
|
1641
|
+
key: TRoute['key'];
|
|
1642
|
+
matched: TRoute['matched'];
|
|
1643
|
+
matches: TRoute['matches'];
|
|
1644
|
+
query: ResolvedRouteQuery;
|
|
989
1645
|
params: Writable<TRoute['params']>;
|
|
990
1646
|
update: RouteUpdate<TRoute>;
|
|
991
|
-
[isRouterRouteSymbol]: true;
|
|
992
1647
|
}>;
|
|
993
1648
|
|
|
1649
|
+
declare type RouterRoute_2<TRoute extends ResolvedRoute_2 = ResolvedRoute_2> = Readonly<{
|
|
1650
|
+
key: TRoute['key'],
|
|
1651
|
+
matched: TRoute['matched'],
|
|
1652
|
+
matches: TRoute['matches'],
|
|
1653
|
+
query: ResolvedRouteQuery_2,
|
|
1654
|
+
params: Writable_2<TRoute['params']>,
|
|
1655
|
+
update: RouteUpdate_2<TRoute>,
|
|
1656
|
+
}>
|
|
1657
|
+
|
|
994
1658
|
export declare const RouterView: __VLS_WithTemplateSlots<DefineComponent<__VLS_TypePropsToRuntimeProps<{
|
|
995
1659
|
name?: string | undefined;
|
|
996
1660
|
}>, {}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
|
|
997
1661
|
name?: string | undefined;
|
|
998
1662
|
}>>>, {}, {}>, Readonly<{
|
|
999
1663
|
default?: ((props: {
|
|
1000
|
-
route:
|
|
1664
|
+
route: Readonly<{
|
|
1665
|
+
key: string;
|
|
1666
|
+
matched: RoutePropsWithMeta;
|
|
1667
|
+
matches: RoutePropsWithMeta[];
|
|
1668
|
+
query: ResolvedRouteQuery;
|
|
1669
|
+
params: Writable<Record<string, unknown>>;
|
|
1670
|
+
update: RouteUpdate<Readonly<{
|
|
1671
|
+
matched: RoutePropsWithMeta_2;
|
|
1672
|
+
matches: RoutePropsWithMeta_2[];
|
|
1673
|
+
key: string;
|
|
1674
|
+
query: ResolvedRouteQuery_2;
|
|
1675
|
+
params: Record<string, unknown>;
|
|
1676
|
+
}>>;
|
|
1677
|
+
}>;
|
|
1001
1678
|
component: Component;
|
|
1002
1679
|
rejection: {
|
|
1003
1680
|
type: "NotFound";
|
|
@@ -1008,7 +1685,20 @@ name?: string | undefined;
|
|
|
1008
1685
|
}>) | undefined;
|
|
1009
1686
|
}> & {
|
|
1010
1687
|
default?: ((props: {
|
|
1011
|
-
route:
|
|
1688
|
+
route: Readonly<{
|
|
1689
|
+
key: string;
|
|
1690
|
+
matched: RoutePropsWithMeta;
|
|
1691
|
+
matches: RoutePropsWithMeta[];
|
|
1692
|
+
query: ResolvedRouteQuery;
|
|
1693
|
+
params: Writable<Record<string, unknown>>;
|
|
1694
|
+
update: RouteUpdate<Readonly<{
|
|
1695
|
+
matched: RoutePropsWithMeta_2;
|
|
1696
|
+
matches: RoutePropsWithMeta_2[];
|
|
1697
|
+
key: string;
|
|
1698
|
+
query: ResolvedRouteQuery_2;
|
|
1699
|
+
params: Record<string, unknown>;
|
|
1700
|
+
}>>;
|
|
1701
|
+
}>;
|
|
1012
1702
|
component: Component;
|
|
1013
1703
|
rejection: {
|
|
1014
1704
|
type: "NotFound";
|
|
@@ -1024,29 +1714,57 @@ name?: string | undefined;
|
|
|
1024
1714
|
*/
|
|
1025
1715
|
export declare type Routes = Readonly<Route[]>;
|
|
1026
1716
|
|
|
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
|
+
|
|
1027
1722
|
declare type RoutesKey<TRoutes extends Routes> = string & keyof RoutesMap<TRoutes>;
|
|
1028
1723
|
|
|
1724
|
+
declare type RoutesKey_2<TRoutes extends Routes_2> = string & keyof RoutesMap_2<TRoutes>
|
|
1725
|
+
|
|
1029
1726
|
declare type RoutesMap<TRoutes extends Routes = []> = {
|
|
1030
1727
|
[K in TRoutes[number] as NamedNotDisabled<K> extends {
|
|
1031
1728
|
key: string;
|
|
1032
1729
|
} ? NamedNotDisabled<K>['key'] : never]: NamedNotDisabled<K>;
|
|
1033
1730
|
};
|
|
1034
1731
|
|
|
1732
|
+
declare type RoutesMap_2<TRoutes extends Routes_2 = []> = {
|
|
1733
|
+
[K in TRoutes[number] as NamedNotDisabled_2<K> extends { key: string } ? NamedNotDisabled_2<K>['key']: never]: NamedNotDisabled_2<K>
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1035
1736
|
declare type RouteUpdate<TRoute extends ResolvedRoute = ResolvedRoute> = {
|
|
1036
1737
|
<TKey extends keyof TRoute['params']>(key: TKey, value: TRoute['params'][TKey], options?: RouterPushOptions): Promise<void>;
|
|
1037
1738
|
(params: Partial<TRoute['params']>, options?: RouterPushOptions): Promise<void>;
|
|
1038
1739
|
};
|
|
1039
1740
|
|
|
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
|
+
|
|
1040
1746
|
declare type StringHasValue<T extends string | undefined> = T extends undefined ? false : '' extends T ? false : true;
|
|
1041
1747
|
|
|
1042
1748
|
declare type ToCallback = (resolve: RegisteredRouter['resolve']) => string;
|
|
1043
1749
|
|
|
1044
1750
|
declare type ToPath<T extends string | Path> = T extends string ? Path<T, {}> : T;
|
|
1045
1751
|
|
|
1752
|
+
declare type ToPath_2<T extends string | Path_2> = T extends string ? Path_2<T, {}> : T
|
|
1753
|
+
|
|
1046
1754
|
declare type ToQuery<T extends string | Query | undefined> = T extends string ? Query<T, {}> : T extends undefined ? Query<'', {}> : unknown extends T ? Query<'', {}> : T;
|
|
1047
1755
|
|
|
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
|
+
|
|
1048
1764
|
declare type Url = `http://${string}` | `https://${string}` | `/${string}` | '/';
|
|
1049
1765
|
|
|
1766
|
+
declare type Url_2 = `http://${string}` | `https://${string}` | `/${string}` | '/'
|
|
1767
|
+
|
|
1050
1768
|
export declare type UseLink = {
|
|
1051
1769
|
/**
|
|
1052
1770
|
* ResolvedRoute if matched. Same value as `router.find`
|
|
@@ -1085,11 +1803,11 @@ export declare type UseLink = {
|
|
|
1085
1803
|
* @returns {UseLink} Reactive context values for as well as navigation methods.
|
|
1086
1804
|
*
|
|
1087
1805
|
*/
|
|
1088
|
-
export declare function useLink<TRouteKey extends
|
|
1806
|
+
export declare function useLink<TRouteKey extends RegisteredRoutesKey>(routeKey: MaybeRefOrGetter<TRouteKey>, ...args: UseLinkArgs<TRouteKey>): UseLink;
|
|
1089
1807
|
|
|
1090
1808
|
export declare function useLink(url: MaybeRefOrGetter<Url>): UseLink;
|
|
1091
1809
|
|
|
1092
|
-
declare type UseLinkArgs<TSource extends
|
|
1810
|
+
declare type UseLinkArgs<TSource extends RegisteredRoutesKey, TParams = RouteParamsByKey<RegisteredRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: MaybeRefOrGetter<TParams>, options?: MaybeRefOrGetter<RouterResolveOptions>] : [params: MaybeRefOrGetter<TParams>, options?: MaybeRefOrGetter<RouterResolveOptions>];
|
|
1093
1811
|
|
|
1094
1812
|
/**
|
|
1095
1813
|
* A composition to access the router's rejection state.
|
|
@@ -1152,6 +1870,13 @@ declare type WithComponent = {
|
|
|
1152
1870
|
component: Component;
|
|
1153
1871
|
};
|
|
1154
1872
|
|
|
1873
|
+
declare type WithComponent_2 = {
|
|
1874
|
+
/**
|
|
1875
|
+
* A Vue component, which can be either synchronous or asynchronous components.
|
|
1876
|
+
*/
|
|
1877
|
+
component: Component,
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1155
1880
|
declare type WithComponents = {
|
|
1156
1881
|
/**
|
|
1157
1882
|
* Multiple components for named views, which can be either synchronous or asynchronous components.
|
|
@@ -1159,6 +1884,15 @@ declare type WithComponents = {
|
|
|
1159
1884
|
components: Record<string, Component>;
|
|
1160
1885
|
};
|
|
1161
1886
|
|
|
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
|
+
export declare function withDefault<TParam extends Param>(param: TParam, defaultValue: ExtractParamType<TParam>): ParamWithDefault<TParam>;
|
|
1895
|
+
|
|
1162
1896
|
/**
|
|
1163
1897
|
* Defines route hooks that can be applied before entering, updating, or leaving a route, as well as after these events.
|
|
1164
1898
|
*/
|
|
@@ -1171,14 +1905,32 @@ declare type WithHooks = {
|
|
|
1171
1905
|
onAfterRouteLeave?: MaybeArray<AfterRouteHook>;
|
|
1172
1906
|
};
|
|
1173
1907
|
|
|
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
|
+
|
|
1174
1920
|
declare type WithOptionalProperties<T> = {
|
|
1175
1921
|
[P in keyof T]-?: undefined extends T[P] ? P : never;
|
|
1176
1922
|
}[keyof T];
|
|
1177
1923
|
|
|
1924
|
+
declare type WithOptionalProperties_2<T> = {
|
|
1925
|
+
[P in keyof T]-?: undefined extends T[P] ? P : never
|
|
1926
|
+
}[keyof T]
|
|
1927
|
+
|
|
1178
1928
|
declare type Writable<T> = {
|
|
1179
1929
|
-readonly [P in keyof T]: T[P];
|
|
1180
1930
|
};
|
|
1181
1931
|
|
|
1932
|
+
declare type Writable_2<T> = { -readonly [P in keyof T]: T[P] }
|
|
1933
|
+
|
|
1182
1934
|
export { }
|
|
1183
1935
|
|
|
1184
1936
|
|