@kitbag/router 0.15.3 → 0.16.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 +70 -58
- package/dist/kitbag-router.js +606 -600
- package/dist/kitbag-router.umd.cjs +1 -1
- package/package.json +6 -6
package/dist/kitbag-router.d.ts
CHANGED
|
@@ -207,10 +207,20 @@ declare type CombineQueryString<TParent extends string | undefined, TChild exten
|
|
|
207
207
|
|
|
208
208
|
declare type CombineState<TParent extends Record<string, Param>, TChild extends Record<string, Param>> = TParent & TChild;
|
|
209
209
|
|
|
210
|
-
declare type ComponentProps<TComponent extends Component> = TComponent extends Constructor ? InstanceType<TComponent>['$props'] : TComponent extends AsyncComponentLoader<infer T extends Component> ? ComponentProps<T> : TComponent extends FunctionalComponent<infer T> ? T :
|
|
210
|
+
declare type ComponentProps<TComponent extends Component> = TComponent extends Constructor ? InstanceType<TComponent>['$props'] : TComponent extends AsyncComponentLoader<infer T extends Component> ? ComponentProps<T> : TComponent extends FunctionalComponent<infer T> ? T : {};
|
|
211
|
+
|
|
212
|
+
declare type ComponentPropsAreOptional<TComponent extends Component> = Partial<ComponentProps<TComponent>> extends ComponentProps<TComponent> ? true : false;
|
|
211
213
|
|
|
212
214
|
declare type Constructor = new (...args: any) => any;
|
|
213
215
|
|
|
216
|
+
/**
|
|
217
|
+
* The Route properties originally provided to `createRoute`. The only change is normalizing meta to always default to an empty object.
|
|
218
|
+
*/
|
|
219
|
+
export declare type CreatedRouteOptions = Omit<CreateRouteOptions, 'props'> & WithHooks & {
|
|
220
|
+
id: string;
|
|
221
|
+
props?: unknown;
|
|
222
|
+
};
|
|
223
|
+
|
|
214
224
|
export declare function createExternalRoute<const THost extends string | Host, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const THash extends string | Hash | undefined = undefined, const TMeta extends RouteMeta = RouteMeta>(options: CreateRouteOptions<TName, TPath, TQuery> & WithHost<THost> & WithoutParent): Route<ToName<TName>, ToHost<THost>, ToPath<TPath>, ToQuery<TQuery>, ToHash<THash>, TMeta>;
|
|
215
225
|
|
|
216
226
|
export declare function createExternalRoute<const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const THash extends string | Hash | undefined = undefined, const TMeta extends RouteMeta = RouteMeta>(options: CreateRouteOptions<TName, TPath, TQuery> & WithoutHost & WithParent<TParent>): Route<ToName<TName>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineHash<TParent['hash'], ToHash<THash>>, CombineMeta<TMeta, TParent['meta']>>;
|
|
@@ -221,19 +231,9 @@ export declare function createParam<TParam extends Param>(param: TParam): ParamG
|
|
|
221
231
|
|
|
222
232
|
export declare function createParam<TParam extends Param>(param: TParam, defaultValue: ExtractParamType<TParam>): ParamWithDefault<TParam>;
|
|
223
233
|
|
|
224
|
-
export declare function createRoute<const
|
|
225
|
-
|
|
226
|
-
export declare function createRoute<const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const THash extends string | Hash | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, THash, TMeta> & WithHooks & WithoutComponents & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineHash<TParent['hash'], ToHash<THash>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>, TName | TParent['matches'][number]['name']>;
|
|
234
|
+
export declare function createRoute<const TOptions extends CreateRouteOptions, const TProps extends CreateRouteProps<TOptions>>(options: TOptions, ...args: CreateRouteWithProps<TOptions, TProps>): ToRoute<TOptions, CreateRouteProps<TOptions> extends TProps ? undefined : TProps>;
|
|
227
235
|
|
|
228
|
-
export declare
|
|
229
|
-
|
|
230
|
-
export declare function createRoute<TComponent extends Component, const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const THash extends string | Hash | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, THash, TMeta> & WithHooks & WithComponent<TComponent, Route<ToName<TName>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineHash<TParent['hash'], ToHash<THash>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>, TName | TParent['matches'][number]['name']>> & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineHash<TParent['hash'], ToHash<THash>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>, TName | TParent['matches'][number]['name']>;
|
|
231
|
-
|
|
232
|
-
export declare function createRoute<TComponents extends Record<string, Component>, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const THash extends string | Hash | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, THash, TMeta> & WithHooks & WithComponents<TComponents, Route<ToName<TName>, Host<'', {}>, ToPath<TPath>, ToQuery<TQuery>, ToHash<THash>, TMeta, TState, TName>> & WithoutParent & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, ToPath<TPath>, ToQuery<TQuery>, ToHash<THash>, TMeta, TState, TName>;
|
|
233
|
-
|
|
234
|
-
export declare function createRoute<TComponents extends Record<string, Component>, const TParent extends Route, const TName extends string | undefined = undefined, const TPath extends string | Path | undefined = undefined, const TQuery extends string | Query | undefined = undefined, const THash extends string | Hash | undefined = undefined, const TMeta extends RouteMeta = RouteMeta, const TState extends Record<string, Param> = Record<string, Param>>(options: CreateRouteOptions<TName, TPath, TQuery, THash, TMeta> & WithHooks & WithComponents<TComponents, Route<ToName<TName>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineHash<TParent['hash'], ToHash<THash>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>, TName | TParent['matches'][number]['name']>> & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<ToName<TName>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineHash<TParent['hash'], ToHash<THash>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>, TName | TParent['matches'][number]['name']>;
|
|
235
|
-
|
|
236
|
-
export declare type CreateRouteOptions<TName extends string | undefined = string | undefined, TPath extends string | Path | undefined = string | Path | undefined, TQuery extends string | Query | undefined = string | Query | undefined, THash extends string | Hash | undefined = string | Hash | undefined, TMeta extends RouteMeta = RouteMeta> = {
|
|
236
|
+
export declare type CreateRouteOptions<TName extends string | undefined = string | undefined, TPath extends string | Path | undefined = string | Path | undefined, TQuery extends string | Query | undefined = string | Query | undefined, THash extends string | Hash | undefined = string | Hash | undefined, TMeta extends RouteMeta = RouteMeta> = WithHooks & {
|
|
237
237
|
/**
|
|
238
238
|
* Name for route, used to create route keys and in navigation.
|
|
239
239
|
*/
|
|
@@ -258,15 +258,33 @@ export declare type CreateRouteOptions<TName extends string | undefined = string
|
|
|
258
258
|
* Determines what assets are prefetched when router-link is rendered for this route. Overrides router level prefetch.
|
|
259
259
|
*/
|
|
260
260
|
prefetch?: PrefetchConfig;
|
|
261
|
+
/**
|
|
262
|
+
* Type params for additional data intended to be stored in history state, all keys will be optional unless a default is provided.
|
|
263
|
+
*/
|
|
264
|
+
state?: Record<string, Param>;
|
|
265
|
+
/**
|
|
266
|
+
* An optional parent route to nest this route under.
|
|
267
|
+
*/
|
|
268
|
+
parent?: Route;
|
|
269
|
+
/**
|
|
270
|
+
* An optional component to render when this route is matched.
|
|
271
|
+
*
|
|
272
|
+
* @default RouterView
|
|
273
|
+
*/
|
|
274
|
+
component?: Component;
|
|
275
|
+
/**
|
|
276
|
+
* An object of named components to render using named views
|
|
277
|
+
*/
|
|
278
|
+
components?: Record<string, Component>;
|
|
279
|
+
/**
|
|
280
|
+
* Props have been moved to the second argument of `createRoute`. This property can no longer be used.
|
|
281
|
+
*
|
|
282
|
+
* @deprecated
|
|
283
|
+
*/
|
|
284
|
+
props?: never;
|
|
261
285
|
};
|
|
262
286
|
|
|
263
|
-
|
|
264
|
-
* The Route properties originally provided to `createRoute`. The only change is normalizing meta to always default to an empty object.
|
|
265
|
-
*/
|
|
266
|
-
declare type CreateRouteOptionsMatched<TName extends string | undefined = string | undefined> = CreateRouteOptions<TName> & WithHooks & (WithHost | WithoutHost) & (WithComponent | WithComponents | WithoutComponents) & (WithParent | WithoutParent) & (WithState | WithoutState) & {
|
|
267
|
-
id: string;
|
|
268
|
-
meta: RouteMeta;
|
|
269
|
-
};
|
|
287
|
+
declare type CreateRouteProps<TOptions extends CreateRouteOptions = CreateRouteOptions> = TOptions['component'] extends Component ? PropsGetter<TOptions, TOptions['component']> : TOptions['components'] extends Record<string, Component> ? RoutePropsRecord<TOptions, TOptions['components']> : PropsGetter<TOptions, typeof RouterView>;
|
|
270
288
|
|
|
271
289
|
/**
|
|
272
290
|
* Creates a router instance for a Vue application, equipped with methods for route handling, lifecycle hooks, and state management.
|
|
@@ -297,6 +315,8 @@ export declare function createRouter<const TRoutes extends Routes, const TOption
|
|
|
297
315
|
|
|
298
316
|
export declare function createRouterPlugin<TRoutes extends Routes = [], TRejections extends Record<string, Component> = {}>(plugin: Partial<RouterPlugin<TRoutes, TRejections>>): RouterPlugin<TRoutes, TRejections>;
|
|
299
317
|
|
|
318
|
+
declare type CreateRouteWithProps<TOptions extends CreateRouteOptions, TProps extends CreateRouteProps<TOptions>> = CreateRouteProps<TOptions> extends PropsGetter<TOptions> ? Partial<ReturnType<CreateRouteProps<TOptions>>> extends ReturnType<CreateRouteProps<TOptions>> ? [props?: TProps] : [props: TProps] : Partial<CreateRouteProps<TOptions>> extends CreateRouteProps<TOptions> ? [props?: TProps] : [props: TProps];
|
|
319
|
+
|
|
300
320
|
/**
|
|
301
321
|
* An error thrown when duplicate parameters are detected in a route.
|
|
302
322
|
* Param names must be unique. This includes params defined in a path
|
|
@@ -497,6 +517,8 @@ export declare function isUrl(value: unknown): value is Url;
|
|
|
497
517
|
*/
|
|
498
518
|
declare type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
499
519
|
|
|
520
|
+
declare type LastInArray<T, TFallback = never> = T extends [...any[], infer Last] ? Last : TFallback;
|
|
521
|
+
|
|
500
522
|
declare type MakeOptional<T> = {
|
|
501
523
|
[P in WithOptionalProperties<T>]?: T[P];
|
|
502
524
|
} & {
|
|
@@ -652,6 +674,8 @@ export declare type PropsCallbackContext = {
|
|
|
652
674
|
reject: CallbackContext['reject'];
|
|
653
675
|
};
|
|
654
676
|
|
|
677
|
+
declare type PropsGetter<TOptions extends CreateRouteOptions = CreateRouteOptions, TComponent extends Component = Component> = (route: ResolvedRoute<ToRoute<TOptions, undefined>>, context: PropsCallbackContext) => MaybePromise<ComponentProps<TComponent>>;
|
|
678
|
+
|
|
655
679
|
declare type Query<TQuery extends string = string, TQueryParams extends QueryParamsWithParamNameExtracted<TQuery> = Record<string, Param | undefined>> = {
|
|
656
680
|
value: TQuery;
|
|
657
681
|
params: string extends TQuery ? Record<string, Param> : Identity<ExtractQueryParamsFromQueryString<TQuery, TQueryParams>>;
|
|
@@ -810,7 +834,7 @@ export declare type ResolvedRoute<TRoute extends Route = Route> = Readonly<{
|
|
|
810
834
|
* @template TPath - The type or structure of the route's path.
|
|
811
835
|
* @template TQuery - The type or structure of the query parameters associated with the route.
|
|
812
836
|
*/
|
|
813
|
-
export declare type Route<TName extends string = string, THost extends Host = Host, TPath extends Path = Path, TQuery extends Query = Query, THash extends Hash = Hash, TMeta extends RouteMeta = RouteMeta, TState extends Record<string, Param> = Record<string, Param>,
|
|
837
|
+
export declare type Route<TName extends string = string, THost extends Host = Host, TPath extends Path = Path, TQuery extends Query = Query, THash extends Hash = Hash, TMeta extends RouteMeta = RouteMeta, TState extends Record<string, Param> = Record<string, Param>, TMatches extends CreatedRouteOptions[] = CreatedRouteOptions[]> = {
|
|
814
838
|
/**
|
|
815
839
|
* Unique identifier for the route, generated by router.
|
|
816
840
|
*/
|
|
@@ -818,12 +842,12 @@ export declare type Route<TName extends string = string, THost extends Host = Ho
|
|
|
818
842
|
/**
|
|
819
843
|
* The specific route properties that were matched in the current route.
|
|
820
844
|
*/
|
|
821
|
-
matched:
|
|
845
|
+
matched: LastInArray<TMatches, CreatedRouteOptions>;
|
|
822
846
|
/**
|
|
823
847
|
* The specific route properties that were matched in the current route, including any ancestors.
|
|
824
848
|
* Order of routes will be from greatest ancestor to narrowest matched.
|
|
825
849
|
*/
|
|
826
|
-
matches:
|
|
850
|
+
matches: TMatches;
|
|
827
851
|
/**
|
|
828
852
|
* Identifier for the route as defined by user. Name must be unique among named routes. Name is used for routing and for matching.
|
|
829
853
|
*/
|
|
@@ -916,6 +940,12 @@ export declare type RouteMeta<T = Register> = T extends {
|
|
|
916
940
|
|
|
917
941
|
declare type RouteParamsByKey<TRoutes extends Routes, TKey extends string> = ExtractRouteParamTypesWithoutLosingOptional<RouteGetByKey<TRoutes, TKey>>;
|
|
918
942
|
|
|
943
|
+
declare type RoutePropsRecord<TOptions extends CreateRouteOptions = CreateRouteOptions, TComponents extends Record<string, Component> = Record<string, Component>> = {
|
|
944
|
+
[K in keyof TComponents as ComponentPropsAreOptional<TComponents[K]> extends true ? K : never]?: PropsGetter<TOptions, TComponents[K]>;
|
|
945
|
+
} & {
|
|
946
|
+
[K in keyof TComponents as ComponentPropsAreOptional<TComponents[K]> extends false ? K : never]: PropsGetter<TOptions, TComponents[K]>;
|
|
947
|
+
};
|
|
948
|
+
|
|
919
949
|
export declare type Router<TRoutes extends Routes = any, TOptions extends RouterOptions = any, TPlugin extends RouterPlugin = any> = {
|
|
920
950
|
/**
|
|
921
951
|
* Installs the router into a Vue application instance.
|
|
@@ -1220,12 +1250,29 @@ declare type ToHash<T extends string | Hash | undefined> = T extends string ? Ha
|
|
|
1220
1250
|
|
|
1221
1251
|
declare type ToHost<T extends string | Host | undefined> = T extends string ? Host<T, {}> : T extends undefined ? Host<'', {}> : unknown extends T ? Host<'', {}> : T;
|
|
1222
1252
|
|
|
1253
|
+
declare type ToMatch<TOptions extends CreateRouteOptions, TProps extends CreateRouteProps<TOptions> | undefined> = Omit<TOptions, 'props'> & {
|
|
1254
|
+
id: string;
|
|
1255
|
+
props: TProps;
|
|
1256
|
+
};
|
|
1257
|
+
|
|
1258
|
+
declare type ToMatches<TOptions extends CreateRouteOptions, TProps extends CreateRouteProps<TOptions> | undefined> = TOptions extends {
|
|
1259
|
+
parent: infer TParent extends Route;
|
|
1260
|
+
} ? [...TParent['matches'], ToMatch<TOptions, TProps>] : [ToMatch<TOptions, TProps>];
|
|
1261
|
+
|
|
1262
|
+
declare type ToMeta<TMeta extends RouteMeta | undefined> = TMeta extends undefined ? {} : unknown extends TMeta ? {} : TMeta;
|
|
1263
|
+
|
|
1223
1264
|
declare type ToName<T extends string | undefined> = T extends string ? T : '';
|
|
1224
1265
|
|
|
1225
1266
|
declare type ToPath<T extends string | Path | undefined> = T extends string ? Path<T, {}> : T extends undefined ? Path<'', {}> : unknown extends T ? Path<'', {}> : T;
|
|
1226
1267
|
|
|
1227
1268
|
declare type ToQuery<T extends string | Query | undefined> = T extends string ? Query<T, {}> : T extends undefined ? Query<'', {}> : unknown extends T ? Query<'', {}> : T;
|
|
1228
1269
|
|
|
1270
|
+
declare type ToRoute<TOptions extends CreateRouteOptions, TProps extends CreateRouteProps<TOptions> | undefined> = CreateRouteOptions extends TOptions ? Route : TOptions extends {
|
|
1271
|
+
parent: infer TParent extends Route;
|
|
1272
|
+
} ? Route<ToName<TOptions['name']>, Host<'', {}>, CombinePath<ToPath<TParent['path']>, ToPath<TOptions['path']>>, CombineQuery<ToQuery<TParent['query']>, ToQuery<TOptions['query']>>, CombineHash<ToHash<TParent['hash']>, ToHash<TOptions['hash']>>, CombineMeta<ToMeta<TParent['meta']>, ToMeta<TOptions['meta']>>, CombineState<ToState<TParent['state']>, ToState<TOptions['state']>>, ToMatches<TOptions, TProps>> : Route<ToName<TOptions['name']>, Host<'', {}>, ToPath<TOptions['path']>, ToQuery<TOptions['query']>, ToHash<TOptions['hash']>, ToMeta<TOptions['meta']>, ToState<TOptions['state']>, ToMatches<TOptions, TProps>>;
|
|
1273
|
+
|
|
1274
|
+
declare type ToState<TState extends Record<string, Param> | undefined> = TState extends undefined ? Record<string, Param> : unknown extends TState ? {} : TState;
|
|
1275
|
+
|
|
1229
1276
|
export declare type Url = `http://${string}` | `https://${string}` | `/${string}`;
|
|
1230
1277
|
|
|
1231
1278
|
export declare type UrlParts = {
|
|
@@ -1348,24 +1395,6 @@ export declare class UseRouteInvalidError extends Error {
|
|
|
1348
1395
|
*/
|
|
1349
1396
|
export declare function useRouter(): RegisteredRouter;
|
|
1350
1397
|
|
|
1351
|
-
declare type WithComponent<TComponent extends Component = Component, TRoute extends Route = Route> = {
|
|
1352
|
-
/**
|
|
1353
|
-
* A Vue component, which can be either synchronous or asynchronous components.
|
|
1354
|
-
*/
|
|
1355
|
-
component: TComponent;
|
|
1356
|
-
props?: (route: ResolvedRoute<TRoute>, context: PropsCallbackContext) => TComponent extends Component ? MaybePromise<ComponentProps<TComponent>> : {};
|
|
1357
|
-
};
|
|
1358
|
-
|
|
1359
|
-
declare type WithComponents<TComponents extends Record<string, Component> = Record<string, Component>, TRoute extends Route = Route> = {
|
|
1360
|
-
/**
|
|
1361
|
-
* Multiple components for named views, which can be either synchronous or asynchronous components.
|
|
1362
|
-
*/
|
|
1363
|
-
components: TComponents;
|
|
1364
|
-
props?: {
|
|
1365
|
-
[TKey in keyof TComponents]?: (route: ResolvedRoute<TRoute>, context: PropsCallbackContext) => TComponents[TKey] extends Component ? MaybePromise<ComponentProps<TComponents[TKey]>> : {};
|
|
1366
|
-
};
|
|
1367
|
-
};
|
|
1368
|
-
|
|
1369
1398
|
export declare function withDefault<TParam extends Param>(param: TParam, defaultValue: ExtractParamType<TParam>): ParamWithDefault<TParam>;
|
|
1370
1399
|
|
|
1371
1400
|
/**
|
|
@@ -1391,12 +1420,6 @@ declare type WithOptionalProperties<T> = {
|
|
|
1391
1420
|
[P in keyof T]-?: undefined extends T[P] ? P : never;
|
|
1392
1421
|
}[keyof T];
|
|
1393
1422
|
|
|
1394
|
-
declare type WithoutComponents = {
|
|
1395
|
-
component?: never;
|
|
1396
|
-
components?: never;
|
|
1397
|
-
props?: never;
|
|
1398
|
-
};
|
|
1399
|
-
|
|
1400
1423
|
declare type WithoutHost = {
|
|
1401
1424
|
host?: never;
|
|
1402
1425
|
};
|
|
@@ -1405,21 +1428,10 @@ declare type WithoutParent = {
|
|
|
1405
1428
|
parent?: never;
|
|
1406
1429
|
};
|
|
1407
1430
|
|
|
1408
|
-
declare type WithoutState = {
|
|
1409
|
-
state?: never;
|
|
1410
|
-
};
|
|
1411
|
-
|
|
1412
1431
|
declare type WithParent<TParent extends Route = Route> = {
|
|
1413
1432
|
parent: TParent;
|
|
1414
1433
|
};
|
|
1415
1434
|
|
|
1416
|
-
declare type WithState<TState extends Record<string, Param> = Record<string, Param>> = {
|
|
1417
|
-
/**
|
|
1418
|
-
* Type params for additional data intended to be stored in history state, all keys will be optional unless a default is provided.
|
|
1419
|
-
*/
|
|
1420
|
-
state: TState;
|
|
1421
|
-
};
|
|
1422
|
-
|
|
1423
1435
|
export { }
|
|
1424
1436
|
|
|
1425
1437
|
|