@kitbag/router 0.22.7 → 0.23.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/dist/components/routerLink.d.ts +2 -3
- package/dist/kitbag-router.js +1569 -1525
- package/dist/kitbag-router.umd.cjs +3 -3
- package/dist/main.d.ts +3 -0
- package/dist/services/createRoute.d.ts +2 -1
- package/dist/services/getMatchesForUrl.d.ts +3 -2
- package/dist/services/literal.d.ts +2 -0
- package/dist/services/queryParamFilter.d.ts +2 -0
- package/dist/services/queryParamFilter.spec.d.ts +1 -0
- package/dist/types/createRouteOptions.d.ts +15 -6
- package/dist/types/hooks.d.ts +15 -0
- package/dist/types/params.d.ts +1 -1
- package/dist/types/resolved.d.ts +0 -7
- package/dist/types/route.d.ts +0 -7
- package/dist/types/routerRoute.d.ts +0 -5
- package/dist/types/titles.browser.spec.d.ts +1 -0
- package/dist/types/titles.d.ts +26 -0
- package/dist/utilities/setDocumentTitle.d.ts +2 -0
- package/dist/utilities/testHelpers.d.ts +1643 -301
- package/package.json +5 -5
package/dist/main.d.ts
CHANGED
|
@@ -6,7 +6,9 @@ export * from './types/paramTypes';
|
|
|
6
6
|
export * from './types/prefetch';
|
|
7
7
|
export * from './types/props';
|
|
8
8
|
export * from './types/querySource';
|
|
9
|
+
export type { RouteRedirects } from './types/redirects';
|
|
9
10
|
export * from './types/register';
|
|
11
|
+
export type { Rejection, RejectionType, Rejections } from './types/rejection';
|
|
10
12
|
export * from './types/resolved';
|
|
11
13
|
export * from './types/route';
|
|
12
14
|
export * from './types/router';
|
|
@@ -37,6 +39,7 @@ export { createRouterPlugin } from './services/createRouterPlugin';
|
|
|
37
39
|
export { unionOf } from './services/unionOf';
|
|
38
40
|
export { arrayOf } from './services/arrayOf';
|
|
39
41
|
export { tupleOf } from './services/tupleOf';
|
|
42
|
+
export { literal } from './services/literal';
|
|
40
43
|
export { createParam } from './services/createParam';
|
|
41
44
|
export { createRouter } from './services/createRouter';
|
|
42
45
|
export { createUrl } from './services/createUrl';
|
|
@@ -2,6 +2,7 @@ import { CreateRouteOptions, PropsGetter, CreateRouteProps, ToRoute, RouterViewP
|
|
|
2
2
|
import { InternalRouteHooks } from '../types/hooks';
|
|
3
3
|
import { ExtractRouteContext } from '../types/routeContext';
|
|
4
4
|
import { RouteRedirects } from '../types/redirects';
|
|
5
|
+
import { RouteSetTitle } from '../types/titles';
|
|
5
6
|
type CreateRouteWithProps<TOptions extends CreateRouteOptions, TProps extends CreateRouteProps<TOptions>> = CreateRouteProps<TOptions> extends RouterViewPropsGetter<TOptions> ? [props?: RouterViewPropsGetter<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];
|
|
6
|
-
export declare function createRoute<const TOptions extends CreateRouteOptions, const TProps extends CreateRouteProps<TOptions>>(options: TOptions, ...args: CreateRouteWithProps<TOptions, TProps>): ToRoute<TOptions, TProps> & InternalRouteHooks<ToRoute<TOptions>, ExtractRouteContext<TOptions>> & RouteRedirects<ToRoute<TOptions>>;
|
|
7
|
+
export declare function createRoute<const TOptions extends CreateRouteOptions, const TProps extends CreateRouteProps<TOptions>>(options: TOptions, ...args: CreateRouteWithProps<TOptions, TProps>): ToRoute<TOptions, TProps> & InternalRouteHooks<ToRoute<TOptions>, ExtractRouteContext<TOptions>> & RouteRedirects<ToRoute<TOptions>> & RouteSetTitle<ToRoute<TOptions>>;
|
|
7
8
|
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ResolvedRoute } from '../types/resolved';
|
|
2
2
|
import { Routes } from '../types/route';
|
|
3
|
-
import { RouterResolveOptions } from '../types/routerResolve';
|
|
4
3
|
import { ParseUrlOptions } from '../types/url';
|
|
5
|
-
type MatchOptions =
|
|
4
|
+
type MatchOptions = {
|
|
5
|
+
state?: Partial<unknown>;
|
|
6
|
+
} & ParseUrlOptions;
|
|
6
7
|
export declare function getMatchForUrl(routes: Routes, url: string, options?: MatchOptions): ResolvedRoute | undefined;
|
|
7
8
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Component } from 'vue';
|
|
2
2
|
import { CombineMeta } from '../services/combineMeta';
|
|
3
3
|
import { CombineState } from '../services/combineState';
|
|
4
|
+
import { WithHooks } from './hooks';
|
|
4
5
|
import { Param } from './paramTypes';
|
|
5
6
|
import { PrefetchConfig } from './prefetch';
|
|
6
7
|
import { RouteMeta } from './register';
|
|
@@ -8,7 +9,7 @@ import { Route } from './route';
|
|
|
8
9
|
import { ResolvedRoute } from './resolved';
|
|
9
10
|
import { ComponentProps } from '../services/component';
|
|
10
11
|
import { PropsCallbackContext } from './props';
|
|
11
|
-
import { MaybePromise } from './utilities';
|
|
12
|
+
import { Identity, MaybePromise } from './utilities';
|
|
12
13
|
import { ToMeta } from './meta';
|
|
13
14
|
import { ToState } from './state';
|
|
14
15
|
import { ToName } from './name';
|
|
@@ -33,6 +34,14 @@ export declare function isWithParent<T extends Record<string, unknown>>(options:
|
|
|
33
34
|
export type WithoutParent = {
|
|
34
35
|
parent?: never;
|
|
35
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* This type is used to strip the component and components properties from the options object
|
|
39
|
+
* when creating a Route to simplify and minimize the output type.
|
|
40
|
+
*/
|
|
41
|
+
type WithoutComponents = {
|
|
42
|
+
component: never;
|
|
43
|
+
components: never;
|
|
44
|
+
};
|
|
36
45
|
export declare function isWithComponent<T extends Record<string, unknown>>(options: T): options is T & {
|
|
37
46
|
component: Component;
|
|
38
47
|
};
|
|
@@ -102,7 +111,7 @@ type RoutePropsRecord<TOptions extends CreateRouteOptions = CreateRouteOptions,
|
|
|
102
111
|
[K in keyof TComponents as ComponentPropsAreOptional<TComponents[K]> extends false ? K : never]: PropsGetter<TOptions, TComponents[K]>;
|
|
103
112
|
};
|
|
104
113
|
export type CreateRouteProps<TOptions extends CreateRouteOptions = CreateRouteOptions> = TOptions['component'] extends Component ? PropsGetter<TOptions, TOptions['component']> : TOptions['components'] extends Record<string, Component> ? RoutePropsRecord<TOptions, TOptions['components']> : RouterViewPropsGetter<TOptions>;
|
|
105
|
-
type ToMatch<TOptions extends CreateRouteOptions, TProps
|
|
114
|
+
type ToMatch<TOptions extends CreateRouteOptions, TProps> = Omit<TOptions, 'props' | 'meta' | 'name'> & {
|
|
106
115
|
id: string;
|
|
107
116
|
name: ToName<TOptions['name']>;
|
|
108
117
|
props: TProps;
|
|
@@ -113,12 +122,12 @@ type ToMatch<TOptions extends CreateRouteOptions, TProps extends CreateRouteProp
|
|
|
113
122
|
};
|
|
114
123
|
type ToMatches<TOptions extends CreateRouteOptions, TProps extends CreateRouteProps<TOptions> | undefined> = TOptions extends {
|
|
115
124
|
parent: infer TParent extends Route;
|
|
116
|
-
} ? [...TParent['matches'], ToMatch<TOptions, TProps>] : [ToMatch<TOptions
|
|
125
|
+
} ? [...TParent['matches'], ToMatch<TOptions, TProps>] : [ToMatch<Identity<TOptions & WithoutComponents>, TProps>];
|
|
117
126
|
export type ToRoute<TOptions extends CreateRouteOptions, TProps extends CreateRouteProps<TOptions> | undefined = undefined> = CreateRouteOptions extends TOptions ? Route : TOptions extends {
|
|
118
127
|
parent: infer TParent extends Route;
|
|
119
|
-
} ? Route<ToName<TOptions['name']>, CombineUrl<TParent, ToUrl<TOptions>>, CombineMeta<ToMeta<TParent['meta']>, ToMeta<TOptions['meta']>>, CombineState<ToState<TParent['state']>, ToState<TOptions['state']>>, ToMatches<TOptions, CreateRouteProps<TOptions> extends TProps ? undefined : TProps>, [
|
|
128
|
+
} ? Route<ToName<TOptions['name']>, CombineUrl<TParent, ToUrl<TOptions & WithoutComponents>>, CombineMeta<ToMeta<TParent['meta']>, ToMeta<TOptions['meta']>>, CombineState<ToState<TParent['state']>, ToState<TOptions['state']>>, ToMatches<TOptions, CreateRouteProps<TOptions> extends TProps ? undefined : TProps>, [
|
|
120
129
|
...ToRouteContext<TParent['context']>,
|
|
121
130
|
...ToRouteContext<TOptions['context']>
|
|
122
|
-
]> : Route<ToName<TOptions['name']>, ToUrl<TOptions
|
|
123
|
-
export declare function combineRoutes(parent: Route, child: Route): Route;
|
|
131
|
+
]> : Route<ToName<TOptions['name']>, ToUrl<Identity<TOptions & WithoutComponents>>, ToMeta<TOptions['meta']>, ToState<TOptions['state']>, ToMatches<TOptions, CreateRouteProps<TOptions> extends TProps ? undefined : TProps>, ToRouteContext<TOptions['context']>>;
|
|
132
|
+
export declare function combineRoutes(parent: Route, child: Route): Route & WithHooks;
|
|
124
133
|
export {};
|
package/dist/types/hooks.d.ts
CHANGED
|
@@ -10,6 +10,21 @@ import { RouteContext, RouteContextToRejection, RouteContextToRoute } from './ro
|
|
|
10
10
|
import { RouterAbort } from './routerAbort';
|
|
11
11
|
import { CallbackContextAbort, CallbackContextPush, CallbackContextReject, CallbackContextSuccess } from './callbackContext';
|
|
12
12
|
import { RouteUpdate } from './routeUpdate';
|
|
13
|
+
/**
|
|
14
|
+
* The stores for routes including ancestors.
|
|
15
|
+
* Order of routes will be from greatest ancestor to narrowest matched.
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export type WithHooks = {
|
|
19
|
+
hooks: Hooks[];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Type guard to assert that a route has hooks.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export declare function isWithHooks<T extends Record<string, unknown>>(route: T): route is T & WithHooks;
|
|
26
|
+
export declare function getHooks(route: Record<string, unknown> | undefined | null): Hooks[];
|
|
27
|
+
export declare function combineHooks(parent: Route, child: Route): Hooks[];
|
|
13
28
|
export type InternalRouteHooks<TRoute extends Route = Route, TContext extends RouteContext[] = []> = {
|
|
14
29
|
/**
|
|
15
30
|
* Registers a route hook to be called before the route is entered.
|
package/dist/types/params.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export type ExtractParamName<TParam extends PropertyKey> = TParam extends string
|
|
|
33
33
|
* @template TParam - The parameter type.
|
|
34
34
|
* @returns The extracted type, or 'string' as a fallback.
|
|
35
35
|
*/
|
|
36
|
-
export type ExtractParamType<TParam extends Param> = Param extends TParam ? unknown : TParam extends ParamGetSet<infer Type> ? Type : TParam extends ParamGetter ? ReturnType<TParam> : TParam extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TParam> : TParam extends LiteralParam ? TParam : string;
|
|
36
|
+
export type ExtractParamType<TParam extends Param> = Param extends TParam ? unknown : TParam extends ParamGetSet<infer Type> ? Type : TParam extends DateConstructor ? Date : TParam extends JSON ? unknown : TParam extends ParamGetter ? ReturnType<TParam> : TParam extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TParam> : TParam extends LiteralParam ? TParam : string;
|
|
37
37
|
export type ParamIsOptional<TParam extends string> = TParam extends `?${string}` ? true : false;
|
|
38
38
|
export type ParamIsGreedy<TParam extends string> = TParam extends `${string}*` ? true : false;
|
|
39
39
|
export type ParamIsOptionalOrHasDefault<TParamName extends string, TParam extends Param | undefined> = ParamIsOptional<TParamName> extends true ? true : TParam extends Required<ParamGetSet> ? true : false;
|
package/dist/types/resolved.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Hooks } from '../models/hooks';
|
|
2
1
|
import { Route, Routes } from './route';
|
|
3
2
|
import { ExtractRouteStateParamsAsOptional } from './state';
|
|
4
3
|
import { UrlString } from './urlString';
|
|
@@ -45,12 +44,6 @@ export type ResolvedRoute<TRoute extends Route = Route> = Readonly<{
|
|
|
45
44
|
* Hash value of the route.
|
|
46
45
|
*/
|
|
47
46
|
hash: string;
|
|
48
|
-
/**
|
|
49
|
-
* The stores for routes including ancestors.
|
|
50
|
-
* Order of routes will be from greatest ancestor to narrowest matched.
|
|
51
|
-
* @internal
|
|
52
|
-
*/
|
|
53
|
-
hooks: Hooks[];
|
|
54
47
|
}>;
|
|
55
48
|
/**
|
|
56
49
|
* This type is the same as `ResolvedRoute<TRoutes[number]>` while remaining distributive
|
package/dist/types/route.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { PrefetchConfig } from './prefetch';
|
|
|
3
3
|
import { RouteMeta } from './register';
|
|
4
4
|
import { LastInArray } from './utilities';
|
|
5
5
|
import { CreateRouteOptions } from './createRouteOptions';
|
|
6
|
-
import { Hooks } from '../models/hooks';
|
|
7
6
|
import { RouteContext } from './routeContext';
|
|
8
7
|
import { Url } from './url';
|
|
9
8
|
/**
|
|
@@ -57,12 +56,6 @@ export type Route<TName extends string = string, TUrl extends Url = Url, TMeta e
|
|
|
57
56
|
* Related routes and rejections for the route. The context is exposed to the hooks and props callback functions for this route.
|
|
58
57
|
*/
|
|
59
58
|
context: TContext;
|
|
60
|
-
/**
|
|
61
|
-
* The stores for routes including ancestors.
|
|
62
|
-
* Order of routes will be from greatest ancestor to narrowest matched.
|
|
63
|
-
* @internal
|
|
64
|
-
*/
|
|
65
|
-
hooks: Hooks[];
|
|
66
59
|
/**
|
|
67
60
|
* A value that represents how many parents a route has. Used for route matching
|
|
68
61
|
* @internal
|
|
@@ -19,11 +19,6 @@ export type RouterRoute<TRoute extends ResolvedRoute = ResolvedRoute> = {
|
|
|
19
19
|
* Order of routes will be from greatest ancestor to narrowest matched.
|
|
20
20
|
*/
|
|
21
21
|
readonly matches: TRoute['matches'];
|
|
22
|
-
/**
|
|
23
|
-
* The stores for routes including ancestors.
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
readonly hooks: TRoute['hooks'];
|
|
27
22
|
/**
|
|
28
23
|
* Hash value of the route.
|
|
29
24
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ResolvedRoute, ResolvedRouteUnion } from './resolved';
|
|
2
|
+
import { Route } from './route';
|
|
3
|
+
import { MaybePromise } from './utilities';
|
|
4
|
+
export type SetTitleContext = {
|
|
5
|
+
from: ResolvedRoute;
|
|
6
|
+
getParentTitle: () => Promise<string | undefined>;
|
|
7
|
+
};
|
|
8
|
+
export type SetTitleCallback<TRoute extends Route = Route> = (to: ResolvedRouteUnion<TRoute>, context: SetTitleContext) => MaybePromise<string>;
|
|
9
|
+
export type GetTitle<TRoute extends Route = Route> = (to: ResolvedRouteUnion<TRoute>) => Promise<string | undefined>;
|
|
10
|
+
export type SetTitle<TRoute extends Route = Route> = (callback: SetTitleCallback<TRoute>) => void;
|
|
11
|
+
export type RouteSetTitle<TRoute extends Route = Route> = {
|
|
12
|
+
/**
|
|
13
|
+
* Adds a callback to set the document title for the route.
|
|
14
|
+
*/
|
|
15
|
+
setTitle: SetTitle<TRoute>;
|
|
16
|
+
};
|
|
17
|
+
export type RouteGetTitle<TRoute extends Route = Route> = {
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
* Gets the title for the route.
|
|
21
|
+
*/
|
|
22
|
+
getTitle: GetTitle<TRoute>;
|
|
23
|
+
};
|
|
24
|
+
export declare function isRouteWithTitleSetter<T extends Route | ResolvedRoute>(route: T): route is T & RouteSetTitle;
|
|
25
|
+
export declare function isRouteWithTitleGetter<T extends Route | ResolvedRoute>(route: T): route is T & RouteGetTitle;
|
|
26
|
+
export declare function createRouteTitle(parent: Route | undefined): RouteGetTitle & RouteSetTitle;
|