@kitbag/router 0.27.0 → 0.28.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/components/routerLink.d.ts +1 -0
- package/dist/components/viewTransition.browser.spec.d.ts +1 -0
- package/dist/components/viewTransition.d.ts +16 -0
- package/dist/components/viewTransition.spec-d.d.ts +1 -0
- package/dist/compositions/useViewTransition.d.ts +5 -0
- package/dist/kitbag-router.js +1758 -1524
- package/dist/kitbag-router.umd.cjs +2 -2
- package/dist/main.d.ts +12 -1
- package/dist/services/addView.d.ts +3 -3
- package/dist/services/createRoute.d.ts +2 -4
- package/dist/services/createRouter.d.ts +2 -2
- package/dist/services/createRouterAssets.d.ts +11 -0
- package/dist/services/createRouterHistory.d.ts +10 -2
- package/dist/services/createViewTransitions.browser.spec.d.ts +1 -0
- package/dist/services/createViewTransitions.d.ts +38 -0
- package/dist/services/history.d.ts +1 -0
- package/dist/services/routeViews.d.ts +7 -0
- package/dist/tests/navigationBehavior.browser.spec.d.ts +1 -0
- package/dist/tests/viewTransitions.browser.spec.d.ts +1 -0
- package/dist/types/addView.d.ts +3 -4
- package/dist/types/createRouteOptions.d.ts +17 -61
- package/dist/types/navigation.d.ts +2 -0
- package/dist/types/props.d.ts +0 -18
- package/dist/types/route.d.ts +2 -3
- package/dist/types/routeViews.d.ts +5 -7
- package/dist/types/router.d.ts +13 -0
- package/dist/types/routerPush.d.ts +8 -0
- package/dist/types/routerReplace.d.ts +3 -0
- package/dist/types/useLink.d.ts +5 -0
- package/dist/types/viewTransition.d.ts +49 -0
- package/dist/utilities/navigation.d.ts +15 -0
- package/dist/utilities/promises.d.ts +4 -0
- package/dist/utilities/promises.spec.d.ts +1 -0
- package/dist/utilities/testHelpers.d.ts +32 -100
- package/dist/utilities/viewTransition.d.ts +11 -0
- package/dist/utilities/viewTransition.spec.d.ts +1 -0
- package/package.json +7 -6
- package/dist/services/createRouteViews.d.ts +0 -16
package/dist/main.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RouterAssets } from './services/createRouterAssets';
|
|
2
2
|
import { RegisteredRouter } from './types/register';
|
|
3
|
-
export type { WithHost, WithoutHost, WithParent, WithoutParent, CreateRouteOptions,
|
|
3
|
+
export type { WithHost, WithoutHost, WithParent, WithoutParent, CreateRouteOptions, ToRoute } from './types/createRouteOptions';
|
|
4
4
|
export type { RouteAddView, AddViewOptions, AddViewPropsGetter, AddViewPropsCallbackContext } from './types/addView';
|
|
5
5
|
export type { RouteAddLoader, AddLoaderOptions, LoaderGetter } from './types/addLoader';
|
|
6
6
|
export type { RouteAddAlias, AddAliasOptions } from './types/addAlias';
|
|
@@ -34,6 +34,7 @@ export * from './types/routerRoute';
|
|
|
34
34
|
export * from './types/urlString';
|
|
35
35
|
export type { Url, CreateUrlOptions, ParseUrlOptions } from './types/url';
|
|
36
36
|
export * from './types/useLink';
|
|
37
|
+
export * from './types/viewTransition';
|
|
37
38
|
export * from './types/navigation';
|
|
38
39
|
export { DuplicateParamsError } from './errors/duplicateParamsError';
|
|
39
40
|
export { LoaderDataAccessError } from './errors/loaderDataAccessError';
|
|
@@ -59,6 +60,7 @@ export { literal } from './services/literal';
|
|
|
59
60
|
export { createParam } from './services/createParam';
|
|
60
61
|
export { createRouter } from './services/createRouter';
|
|
61
62
|
export { createUrl } from './services/createUrl';
|
|
63
|
+
export type { ViewTransitionProps } from './components/viewTransition';
|
|
62
64
|
/**
|
|
63
65
|
* Registers a hook that is called before a route is left. Must be called from setup.
|
|
64
66
|
* This is useful for performing actions or cleanups before navigating away from a route component.
|
|
@@ -119,6 +121,8 @@ export declare const RouterView: RouterAssets<RegisteredRouter>['RouterView'];
|
|
|
119
121
|
* @group Components
|
|
120
122
|
*/
|
|
121
123
|
export declare const RouterLink: RouterAssets<RegisteredRouter>['RouterLink'];
|
|
124
|
+
/** Names a shared element for a view transition. @group Components */
|
|
125
|
+
export declare const ViewTransition: new <TElement extends keyof HTMLElementTagNameMap = "span">(props: import('./main').ViewTransitionProps<TElement>) => import('vue').ComponentPublicInstance<import('./main').ViewTransitionProps<TElement>>;
|
|
122
126
|
/**
|
|
123
127
|
* A component to render a bar across the top of the page while a navigation is pending, filled by how
|
|
124
128
|
* much of the navigation's work has settled.
|
|
@@ -179,6 +183,13 @@ export declare const useLink: RouterAssets<RegisteredRouter>['useLink'];
|
|
|
179
183
|
* @group Compositions
|
|
180
184
|
*/
|
|
181
185
|
export declare const useRejection: RouterAssets<RegisteredRouter>['useRejection'];
|
|
186
|
+
/**
|
|
187
|
+
* A composition to access the view transition in flight, if any.
|
|
188
|
+
*
|
|
189
|
+
* @returns The router's view transition state.
|
|
190
|
+
* @group Compositions
|
|
191
|
+
*/
|
|
192
|
+
export declare const useViewTransition: RouterAssets<RegisteredRouter>['useViewTransition'];
|
|
182
193
|
/**
|
|
183
194
|
* A composition to access the navigation under way: whether one is pending, which routes it leaves and
|
|
184
195
|
* leads to, and how much of the work it waits on has settled.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Component } from 'vue';
|
|
2
2
|
import { AnyPayloadTransformer } from './payload';
|
|
3
|
-
import {
|
|
3
|
+
import { AddViewPropsGetter } from '../types/addView';
|
|
4
4
|
import { PrefetchConfig } from '../types/prefetch';
|
|
5
5
|
import { CreatedRouteOptions, Route } from '../types/route';
|
|
6
6
|
/**
|
|
@@ -9,7 +9,7 @@ import { CreatedRouteOptions, Route } from '../types/route';
|
|
|
9
9
|
*/
|
|
10
10
|
type ViewOptions = {
|
|
11
11
|
name?: string;
|
|
12
|
-
props?:
|
|
12
|
+
props?: AddViewPropsGetter<Route, Component>;
|
|
13
13
|
prefetch?: PrefetchConfig;
|
|
14
14
|
transformer?: AnyPayloadTransformer;
|
|
15
15
|
};
|
|
@@ -25,7 +25,7 @@ export type AddView = (...args: AddViewParameters) => Route;
|
|
|
25
25
|
type View = {
|
|
26
26
|
name: string;
|
|
27
27
|
component: Component;
|
|
28
|
-
props:
|
|
28
|
+
props: AddViewPropsGetter<Route, Component> | undefined;
|
|
29
29
|
prefetch: PrefetchConfig | undefined;
|
|
30
30
|
transformer: AnyPayloadTransformer | undefined;
|
|
31
31
|
};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { CreateRouteOptions,
|
|
1
|
+
import { CreateRouteOptions, ToRouteMatches, ToRouteUrl } from '../types/createRouteOptions';
|
|
2
2
|
import { RouteWithMethods } from '../types/routeWithMethods';
|
|
3
|
-
|
|
4
|
-
export declare function createRoute<const TOptions extends CreateRouteOptions, const TProps extends CreateRouteProps<TOptions>>(options: TOptions, ...args: CreateRouteWithProps<TOptions, TProps>): RouteWithMethods<ToRouteUrl<TOptions>, ToRouteMatches<TOptions, TProps>>;
|
|
5
|
-
export {};
|
|
3
|
+
export declare function createRoute<const TOptions extends CreateRouteOptions>(options: TOptions): RouteWithMethods<ToRouteUrl<TOptions>, ToRouteMatches<TOptions>>;
|
|
@@ -17,8 +17,8 @@ import { EmptyRouterPlugin, RouterPlugin } from '../types/routerPlugin';
|
|
|
17
17
|
* const About = { template: '<div>About</div>' }
|
|
18
18
|
*
|
|
19
19
|
* export const routes = [
|
|
20
|
-
* createRoute({ name: 'home', path: '/'
|
|
21
|
-
* createRoute({ name: 'path', path: '/about'
|
|
20
|
+
* createRoute({ name: 'home', path: '/' }).addView(Home),
|
|
21
|
+
* createRoute({ name: 'path', path: '/about' }).addView(About),
|
|
22
22
|
* ] as const
|
|
23
23
|
*
|
|
24
24
|
* const router = createRouter(routes)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ViewTransition } from '../components/viewTransition';
|
|
1
2
|
import { Router, RouterRoutes, RouterRejections } from '../types/router';
|
|
2
3
|
import { InjectionKey } from 'vue';
|
|
3
4
|
import { createRouterView } from '../components/routerView';
|
|
@@ -10,6 +11,7 @@ import { createUseLink } from '../compositions/useLink';
|
|
|
10
11
|
import { createIsRoute } from '../guards/routes';
|
|
11
12
|
import { AddBeforeLeaveHook, AddBeforeUpdateHook, AddAfterLeaveHook, AddAfterUpdateHook } from '../types/hooks';
|
|
12
13
|
import { createUseRejection } from '../compositions/useRejection';
|
|
14
|
+
import { createUseViewTransition } from '../compositions/useViewTransition';
|
|
13
15
|
import { createUseNavigation } from '../compositions/useNavigation';
|
|
14
16
|
export type RouterAssets<TRouter extends Router> = {
|
|
15
17
|
/**
|
|
@@ -72,6 +74,8 @@ export type RouterAssets<TRouter extends Router> = {
|
|
|
72
74
|
* @group Components
|
|
73
75
|
*/
|
|
74
76
|
RouterLink: ReturnType<typeof createRouterLink<TRouter>>;
|
|
77
|
+
/** Names a shared element for a view transition. @group Components */
|
|
78
|
+
ViewTransition: typeof ViewTransition;
|
|
75
79
|
/**
|
|
76
80
|
* A component to render a bar across the top of the page while a navigation is pending, filled by how
|
|
77
81
|
* much of the navigation's work has settled.
|
|
@@ -132,6 +136,13 @@ export type RouterAssets<TRouter extends Router> = {
|
|
|
132
136
|
* @group Compositions
|
|
133
137
|
*/
|
|
134
138
|
useRejection: ReturnType<typeof createUseRejection<TRouter>>;
|
|
139
|
+
/**
|
|
140
|
+
* A composition to access the view transition in flight, if any.
|
|
141
|
+
*
|
|
142
|
+
* @returns The router's view transition state.
|
|
143
|
+
* @group Compositions
|
|
144
|
+
*/
|
|
145
|
+
useViewTransition: ReturnType<typeof createUseViewTransition<TRouter>>;
|
|
135
146
|
/**
|
|
136
147
|
* A composition to access the navigation under way: whether one is pending, which routes it leaves and
|
|
137
148
|
* leads to, and how much of the work it waits on has settled.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { History,
|
|
1
|
+
import { History, Update } from './history';
|
|
2
2
|
type NavigationPushOptions = {
|
|
3
3
|
replace?: boolean;
|
|
4
4
|
state?: unknown;
|
|
@@ -12,8 +12,16 @@ type RouterHistory = History & {
|
|
|
12
12
|
stopListening: () => void;
|
|
13
13
|
};
|
|
14
14
|
export type RouterHistoryMode = 'auto' | 'browser' | 'memory' | 'hash';
|
|
15
|
+
/** Called by the router while the traversal navigation is active. */
|
|
16
|
+
export type RouterHistoryTraversal = {
|
|
17
|
+
commit: () => void;
|
|
18
|
+
restore: () => void;
|
|
19
|
+
};
|
|
20
|
+
type RouterHistoryUpdate = Update & {
|
|
21
|
+
traversal?: RouterHistoryTraversal;
|
|
22
|
+
};
|
|
15
23
|
type RouterHistoryOptions = {
|
|
16
|
-
listener:
|
|
24
|
+
listener: (event: RouterHistoryUpdate) => void;
|
|
17
25
|
mode?: RouterHistoryMode;
|
|
18
26
|
};
|
|
19
27
|
export declare function createRouterHistory({ mode, listener }: RouterHistoryOptions): RouterHistory;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ResolvedRoute } from '../types/resolved';
|
|
2
|
+
import { RouterViewTransition, ViewTransitionTypes } from '../types/viewTransition';
|
|
3
|
+
export type PendingViewTransition = {
|
|
4
|
+
to: ResolvedRoute;
|
|
5
|
+
from: ResolvedRoute;
|
|
6
|
+
types: ViewTransitionTypes;
|
|
7
|
+
};
|
|
8
|
+
export type ViewTransitions = {
|
|
9
|
+
/**
|
|
10
|
+
* The transition in flight, as the router exposes it.
|
|
11
|
+
*/
|
|
12
|
+
viewTransition: RouterViewTransition;
|
|
13
|
+
/**
|
|
14
|
+
* Records the navigation about to transition, ahead of its data loading, so the page being left can
|
|
15
|
+
* prepare before it is captured.
|
|
16
|
+
*/
|
|
17
|
+
prepare: (navigation: PendingViewTransition) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Forgets a prepared navigation that was superseded before it transitioned, unless a newer one has
|
|
20
|
+
* taken over the state since.
|
|
21
|
+
*/
|
|
22
|
+
cancel: (navigation: PendingViewTransition) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Forgets the transition in flight, for a navigation that commits without one.
|
|
25
|
+
*/
|
|
26
|
+
reset: () => void;
|
|
27
|
+
/**
|
|
28
|
+
* Runs the update inside a view transition. Resolves after the update and Vue flush, ahead of the animation.
|
|
29
|
+
*/
|
|
30
|
+
start: (update: () => void | Promise<unknown>) => Promise<void>;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Owns the one transition the document runs at a time. Starting another while the first has not yet run
|
|
34
|
+
* its callback leaves the browser free to run the two callbacks in either order, so a navigation arriving
|
|
35
|
+
* then takes over the pending callback instead. Once the callback has run the browser skips the old
|
|
36
|
+
* animation on its own.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createViewTransitions(): ViewTransitions;
|
|
@@ -23,6 +23,7 @@ export interface Transition extends Update {
|
|
|
23
23
|
export type Blocker = (tx: Transition) => void;
|
|
24
24
|
export type To = string | Partial<Path>;
|
|
25
25
|
export interface History {
|
|
26
|
+
readonly index: number | null;
|
|
26
27
|
readonly action: Action;
|
|
27
28
|
readonly location: Location;
|
|
28
29
|
createHref: (to: To) => string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RouteViews } from '../types/routeViews';
|
|
2
|
+
export declare const DEFAULT_VIEW_NAME = "default";
|
|
3
|
+
/**
|
|
4
|
+
* The names of the views that have a props getter. A view without one is never computed, so waiting on it
|
|
5
|
+
* would never settle.
|
|
6
|
+
*/
|
|
7
|
+
export declare function viewNamesWithProps(views: RouteViews): string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/addView.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Component } from 'vue';
|
|
2
2
|
import { ComponentProps } from '../services/component';
|
|
3
|
-
import { ComponentPropsAreOptional, PropsGetter } from './createRouteOptions';
|
|
4
3
|
import { ResolvedRoute, WithData } from './resolved';
|
|
5
4
|
import { CreatedRouteOptions, Route } from './route';
|
|
6
5
|
import { RouteCallbackContext } from './routeCallbackContext';
|
|
@@ -11,8 +10,7 @@ import { RouteView, RouteViews } from './routeViews';
|
|
|
11
10
|
import { Url } from './url';
|
|
12
11
|
import { AnyFunction, Identity, LastInArray, MaybePromise } from './utilities';
|
|
13
12
|
/**
|
|
14
|
-
* The props getter for a view added via `addView`. Receives the
|
|
15
|
-
* `createRoute` props callback: the resolved route and a context object.
|
|
13
|
+
* The props getter for a view added via `addView`. Receives the resolved route and a context object.
|
|
16
14
|
*/
|
|
17
15
|
export type AddViewPropsGetter<TRoute extends Route, TComponent extends Component> = (route: ResolvedRoute<TRoute> & WithData<TRoute>, context: AddViewPropsCallbackContext<TRoute>) => MaybePromise<ComponentProps<TComponent>>;
|
|
18
16
|
/**
|
|
@@ -20,6 +18,7 @@ export type AddViewPropsGetter<TRoute extends Route, TComponent extends Componen
|
|
|
20
18
|
* callbacks attached to a route.
|
|
21
19
|
*/
|
|
22
20
|
export type AddViewPropsCallbackContext<TRoute extends Route> = RouteCallbackContext<TRoute>;
|
|
21
|
+
type ComponentPropsAreOptional<TComponent extends Component> = Partial<ComponentProps<TComponent>> extends ComponentProps<TComponent> ? true : false;
|
|
23
22
|
/**
|
|
24
23
|
* When the getter is omitted the default type param resolves to the wide getter type, which then
|
|
25
24
|
* "extends" itself and collapses to undefined. When a getter is provided its return type is kept — the
|
|
@@ -32,7 +31,7 @@ type NewViewProps<TRoute extends Route, TComponent extends Component, TGetter ex
|
|
|
32
31
|
* @template TName - The view's name, inferred from the `name` option.
|
|
33
32
|
* @template TGetter - The view's props getter, inferred from the `props` option.
|
|
34
33
|
*/
|
|
35
|
-
export type AddViewOptions<TName extends string | undefined = string, TGetter =
|
|
34
|
+
export type AddViewOptions<TName extends string | undefined = string, TGetter = AddViewPropsGetter<Route, Component>> = TransformerOptions<PayloadValueOf<TGetter>> & {
|
|
36
35
|
/**
|
|
37
36
|
* The name of the view, rendered by `<router-view name="..." />`. Defaults to the unnamed view.
|
|
38
37
|
*/
|
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NavigationBehavior } from './navigation';
|
|
2
2
|
import { Param } from './paramTypes';
|
|
3
3
|
import { PrefetchConfig } from './prefetch';
|
|
4
|
+
import { ViewTransitionConfig } from './viewTransition';
|
|
4
5
|
import { RouteMeta } from './register';
|
|
5
6
|
import { Route, RouteInternal } from './route';
|
|
6
|
-
import { ResolvedRoute, WithData } from './resolved';
|
|
7
|
-
import { ComponentProps } from '../services/component';
|
|
8
|
-
import { PropsCallbackContext } from './props';
|
|
9
|
-
import { AnyFunction, Identity, MaybePromise } from './utilities';
|
|
10
7
|
import { ToMeta } from './meta';
|
|
11
8
|
import { ToName } from './name';
|
|
12
9
|
import { UrlPart, UrlQueryPart } from '../services/withParams';
|
|
13
10
|
import { RouteContext } from './routeContext';
|
|
14
|
-
import { RouterViewProps } from '../components/routerView';
|
|
15
11
|
import { ToUrl } from './url';
|
|
16
12
|
import { CombineUrl } from '../services/combineUrl';
|
|
17
|
-
import { RouteView } from './routeViews';
|
|
18
13
|
export type WithHost<THost extends string | UrlPart = string | UrlPart> = {
|
|
19
14
|
/**
|
|
20
15
|
* Host part of URL.
|
|
@@ -31,20 +26,6 @@ export declare function isWithParent<T extends Record<string, unknown>>(options:
|
|
|
31
26
|
export type WithoutParent = {
|
|
32
27
|
parent?: never;
|
|
33
28
|
};
|
|
34
|
-
/**
|
|
35
|
-
* This type is used to strip the component and components properties from the options object
|
|
36
|
-
* when creating a Route to simplify and minimize the output type.
|
|
37
|
-
*/
|
|
38
|
-
type WithoutComponents = {
|
|
39
|
-
component: never;
|
|
40
|
-
components: never;
|
|
41
|
-
};
|
|
42
|
-
export declare function isWithComponent<T extends Record<string, unknown>>(options: T): options is T & {
|
|
43
|
-
component: Component;
|
|
44
|
-
};
|
|
45
|
-
export declare function isWithComponents<T extends Record<string, unknown>>(options: T): options is T & {
|
|
46
|
-
components: Record<string, Component>;
|
|
47
|
-
};
|
|
48
29
|
export type CreateRouteOptions<TName extends string | undefined = string | undefined, TMeta extends RouteMeta = RouteMeta> = {
|
|
49
30
|
/**
|
|
50
31
|
* Name for route, used to create route keys and in navigation.
|
|
@@ -70,6 +51,12 @@ export type CreateRouteOptions<TName extends string | undefined = string | undef
|
|
|
70
51
|
* Determines what assets are prefetched when router-link is rendered for this route. Overrides router level prefetch.
|
|
71
52
|
*/
|
|
72
53
|
prefetch?: PrefetchConfig;
|
|
54
|
+
/** Overrides the parent route and router navigation behavior. */
|
|
55
|
+
navigation?: NavigationBehavior;
|
|
56
|
+
/**
|
|
57
|
+
* Animates navigations to this route with the View Transitions API. Overrides router level viewTransition.
|
|
58
|
+
*/
|
|
59
|
+
viewTransition?: ViewTransitionConfig;
|
|
73
60
|
/**
|
|
74
61
|
* Type params for additional data intended to be stored in history state, all keys will be optional unless a default is provided.
|
|
75
62
|
*/
|
|
@@ -78,19 +65,6 @@ export type CreateRouteOptions<TName extends string | undefined = string | undef
|
|
|
78
65
|
* An optional parent route to nest this route under.
|
|
79
66
|
*/
|
|
80
67
|
parent?: Route;
|
|
81
|
-
/**
|
|
82
|
-
* An optional component to render when this route is matched.
|
|
83
|
-
*
|
|
84
|
-
* @default RouterView
|
|
85
|
-
* @deprecated Use the chainable `addView` method on the route instead: `createRoute({ ... }).addView(component, { props })`.
|
|
86
|
-
*/
|
|
87
|
-
component?: Component;
|
|
88
|
-
/**
|
|
89
|
-
* An object of named components to render using named views
|
|
90
|
-
*
|
|
91
|
-
* @deprecated Use the chainable `addView` method on the route instead: `createRoute({ ... }).addView(component, { name, props })`.
|
|
92
|
-
*/
|
|
93
|
-
components?: Record<string, Component>;
|
|
94
68
|
/**
|
|
95
69
|
* Related routes and rejections for the route. The context is exposed to the hooks and props callback functions for this route.
|
|
96
70
|
*/
|
|
@@ -100,16 +74,7 @@ export type CreateRouteOptions<TName extends string | undefined = string | undef
|
|
|
100
74
|
*/
|
|
101
75
|
hoist?: boolean;
|
|
102
76
|
};
|
|
103
|
-
|
|
104
|
-
export type RouterViewPropsGetter<TOptions extends CreateRouteOptions = CreateRouteOptions> = (route: ResolvedRoute<ToRoute<TOptions>> & WithData<ToRoute<TOptions>>, context: PropsCallbackContext<ToRoute<TOptions>, TOptions>) => MaybePromise<RouterViewProps & Record<string, unknown>>;
|
|
105
|
-
export type ComponentPropsAreOptional<TComponent extends Component> = Partial<ComponentProps<TComponent>> extends ComponentProps<TComponent> ? true : false;
|
|
106
|
-
type RoutePropsRecord<TOptions extends CreateRouteOptions = CreateRouteOptions, TComponents extends Record<string, Component> = Record<string, Component>> = {
|
|
107
|
-
[K in keyof TComponents as ComponentPropsAreOptional<TComponents[K]> extends true ? K : never]?: PropsGetter<TOptions, TComponents[K]>;
|
|
108
|
-
} & {
|
|
109
|
-
[K in keyof TComponents as ComponentPropsAreOptional<TComponents[K]> extends false ? K : never]: PropsGetter<TOptions, TComponents[K]>;
|
|
110
|
-
};
|
|
111
|
-
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>;
|
|
112
|
-
type ToMatch<TOptions extends CreateRouteOptions, TProps = undefined> = Omit<TOptions, 'meta' | 'name' | 'component' | 'components' | 'parent'> & {
|
|
77
|
+
type ToMatch<TOptions extends CreateRouteOptions> = Omit<TOptions, 'meta' | 'name' | 'parent'> & {
|
|
113
78
|
id: string;
|
|
114
79
|
name: ToName<TOptions['name']>;
|
|
115
80
|
/**
|
|
@@ -117,9 +82,9 @@ type ToMatch<TOptions extends CreateRouteOptions, TProps = undefined> = Omit<TOp
|
|
|
117
82
|
*/
|
|
118
83
|
meta: ToMeta<TOptions['meta']>;
|
|
119
84
|
/**
|
|
120
|
-
* The views this route renders, keyed by view name.
|
|
85
|
+
* The views this route renders, keyed by view name. Added by `addView`.
|
|
121
86
|
*/
|
|
122
|
-
views:
|
|
87
|
+
views: {};
|
|
123
88
|
/**
|
|
124
89
|
* The loaders this route runs, keyed by loader name. Always empty here — loaders are only added via
|
|
125
90
|
* the route's `addLoader`.
|
|
@@ -130,29 +95,20 @@ type ToMatch<TOptions extends CreateRouteOptions, TProps = undefined> = Omit<TOp
|
|
|
130
95
|
* The matches for a route, from greatest ancestor to the route itself. Each carries its own views, so
|
|
131
96
|
* there is no second tuple to keep aligned with this one.
|
|
132
97
|
*/
|
|
133
|
-
type ToMatches<TOptions extends CreateRouteOptions
|
|
98
|
+
type ToMatches<TOptions extends CreateRouteOptions> = TOptions extends {
|
|
134
99
|
parent: infer TParent extends Route;
|
|
135
|
-
} ? [...TParent['matches'], ToMatch<TOptions
|
|
136
|
-
/**
|
|
137
|
-
* Builds a views record from the props argument, which is either a single getter for the unnamed view or
|
|
138
|
-
* a record of getters keyed by view name.
|
|
139
|
-
*/
|
|
140
|
-
type PropsToViews<TProps> = [TProps] extends [AnyFunction] ? {
|
|
141
|
-
default: RouteView<ReturnType<TProps>>;
|
|
142
|
-
} : [TProps] extends [Record<string, AnyFunction>] ? {
|
|
143
|
-
[K in keyof TProps]: RouteView<ReturnType<TProps[K]>>;
|
|
144
|
-
} : {};
|
|
100
|
+
} ? [...TParent['matches'], ToMatch<TOptions>] : [ToMatch<TOptions>];
|
|
145
101
|
/**
|
|
146
102
|
* The url a route resolves to, combined with its parent's unless the route is hoisted.
|
|
147
103
|
*/
|
|
148
104
|
export type ToRouteUrl<TOptions extends CreateRouteOptions> = TOptions extends {
|
|
149
105
|
parent: infer TParent extends Route;
|
|
150
|
-
} ? TOptions['hoist'] extends true ? ToUrl<TOptions
|
|
106
|
+
} ? TOptions['hoist'] extends true ? ToUrl<TOptions> : CombineUrl<TParent, ToUrl<TOptions>> : ToUrl<TOptions>;
|
|
151
107
|
/**
|
|
152
|
-
* The matches for a route,
|
|
108
|
+
* The matches for a route, before any views or loaders are added.
|
|
153
109
|
*/
|
|
154
|
-
export type ToRouteMatches<TOptions extends CreateRouteOptions
|
|
155
|
-
export type ToRoute<TOptions extends CreateRouteOptions
|
|
110
|
+
export type ToRouteMatches<TOptions extends CreateRouteOptions> = ToMatches<TOptions>;
|
|
111
|
+
export type ToRoute<TOptions extends CreateRouteOptions> = CreateRouteOptions extends TOptions ? Route : Route<ToRouteUrl<TOptions>, ToRouteMatches<TOptions>>;
|
|
156
112
|
/**
|
|
157
113
|
* Nests a route under its parent. A hoisted route keeps everything of its parent's except the url: its own
|
|
158
114
|
* url stands alone and it inherits none of the parent's aliases.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ComputedRef } from 'vue';
|
|
2
2
|
import { ResolvedRoute } from './resolved';
|
|
3
|
+
/** Whether navigation commits immediately or waits for its props, loaders, and components. */
|
|
4
|
+
export type NavigationBehavior = 'progressive' | 'blocking';
|
|
3
5
|
/**
|
|
4
6
|
* The navigation under way, if any, and how far it has come. A navigation is under way from the moment it
|
|
5
7
|
* is asked for until the route it leads to has everything it renders with, or it is rejected, aborted, or
|
package/dist/types/props.d.ts
CHANGED
|
@@ -1,25 +1,7 @@
|
|
|
1
|
-
import { CreateRouteOptions } from './createRouteOptions';
|
|
2
1
|
import { Route } from './route';
|
|
3
|
-
import { RouterReject } from './routerReject';
|
|
4
|
-
import { RouterPush } from './routerPush';
|
|
5
|
-
import { RouterReplace } from './routerReplace';
|
|
6
|
-
import { ExtractRouteContextRejections, ExtractRouteContextRoutes } from './routeContext';
|
|
7
|
-
import { ResolvedRoute } from './resolved';
|
|
8
|
-
import { RouteUpdate } from './routeUpdate';
|
|
9
2
|
import { LoadersDataReturnType } from './routeLoaders';
|
|
10
3
|
import { ViewsPropsReturnType } from './routeViews';
|
|
11
4
|
import { LastInArray } from './utilities';
|
|
12
|
-
/**
|
|
13
|
-
* Context provided to props callback functions
|
|
14
|
-
*/
|
|
15
|
-
export type PropsCallbackContext<TRoute extends Route = Route, TOptions extends CreateRouteOptions = CreateRouteOptions> = {
|
|
16
|
-
reject: RouterReject<ExtractRouteContextRejections<TOptions>>;
|
|
17
|
-
push: RouterPush<[TRoute] | ExtractRouteContextRoutes<TOptions>>;
|
|
18
|
-
replace: RouterReplace<[TRoute] | ExtractRouteContextRoutes<TOptions>>;
|
|
19
|
-
update: RouteUpdate<ResolvedRoute<TRoute>>;
|
|
20
|
-
signal: AbortSignal;
|
|
21
|
-
parent: PropsCallbackParent<TOptions['parent']>;
|
|
22
|
-
};
|
|
23
5
|
export type PropsCallbackParent<TParent extends Route | undefined = Route | undefined> = Route | undefined extends TParent ? undefined | {
|
|
24
6
|
name: string;
|
|
25
7
|
props: unknown;
|
package/dist/types/route.d.ts
CHANGED
|
@@ -29,10 +29,9 @@ export type RouteInternal = {
|
|
|
29
29
|
export type Routes = readonly Route[];
|
|
30
30
|
/**
|
|
31
31
|
* The Route properties originally provided to `createRoute`, plus the views that route renders and the
|
|
32
|
-
* loaders it runs.
|
|
33
|
-
* {@link RouteViews}).
|
|
32
|
+
* loaders it runs.
|
|
34
33
|
*/
|
|
35
|
-
export type CreatedRouteOptions =
|
|
34
|
+
export type CreatedRouteOptions = CreateRouteOptions & {
|
|
36
35
|
id: string;
|
|
37
36
|
views: RouteViews;
|
|
38
37
|
loaders: RouteLoaders;
|
|
@@ -3,26 +3,24 @@ import { Component } from 'vue';
|
|
|
3
3
|
import { PrefetchConfig } from './prefetch';
|
|
4
4
|
import { AnyFunction } from './utilities';
|
|
5
5
|
/**
|
|
6
|
-
* A single view: what to render, how to get its props, and how to prefetch it.
|
|
7
|
-
* because a route can bind props to the nested RouterView it renders without declaring a component.
|
|
6
|
+
* A single view: what to render, how to get its props, and how to prefetch it.
|
|
8
7
|
*
|
|
9
8
|
* @template TProps - What this view's props getter returns, carried so parent props can be typed from it.
|
|
10
9
|
*/
|
|
11
10
|
export type RouteView<TProps = undefined> = {
|
|
12
|
-
component
|
|
11
|
+
component: Component;
|
|
13
12
|
props?: AnyFunction<TProps>;
|
|
14
13
|
prefetch?: PrefetchConfig;
|
|
15
14
|
transformer?: AnyPayloadTransformer;
|
|
16
15
|
};
|
|
17
16
|
/**
|
|
18
|
-
* The views for a single
|
|
19
|
-
* `route.
|
|
20
|
-
* comes from at a given depth.
|
|
17
|
+
* The views for a single match, keyed by view name (the unnamed view under 'default'). Each match in
|
|
18
|
+
* `route.matches` carries its own views.
|
|
21
19
|
*/
|
|
22
20
|
export type RouteViews = Record<string, RouteView<unknown>>;
|
|
23
21
|
/**
|
|
24
22
|
* The props a child sees for a parent's views. A lone unnamed view is given directly rather than under a
|
|
25
|
-
* 'default' key
|
|
23
|
+
* 'default' key. Each view's props are always a promise,
|
|
26
24
|
* since the parent's props may not have been computed when the child's getter runs.
|
|
27
25
|
*/
|
|
28
26
|
export type ViewsPropsReturnType<TViews> = keyof ViewsWithProps<TViews> extends never ? undefined : keyof ViewsWithProps<TViews> extends 'default' ? ParentViewProps<Extract<ViewsWithProps<TViews>, {
|
package/dist/types/router.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NavigationBehavior } from './navigation';
|
|
1
2
|
import { App, InjectionKey, Ref } from 'vue';
|
|
2
3
|
import { RouterHistoryMode } from '../services/createRouterHistory';
|
|
3
4
|
import { TransformerOptions } from '../services/payload';
|
|
@@ -14,6 +15,7 @@ import { RouterPlugin } from './routerPlugin';
|
|
|
14
15
|
import { RoutesName } from './routesMap';
|
|
15
16
|
import { ExtractRejections, ExtractRejectionTypes, Rejections, BuiltInRejectionType } from './rejection';
|
|
16
17
|
import { PayloadValueError } from '../errors/payloadValueError';
|
|
18
|
+
import { ViewTransitionConfig } from './viewTransition';
|
|
17
19
|
/**
|
|
18
20
|
* Options to initialize a {@link Router} instance.
|
|
19
21
|
*/
|
|
@@ -44,6 +46,17 @@ export type RouterOptions = TransformerOptions & {
|
|
|
44
46
|
* Determines what assets are prefetched when router-link is rendered for a specific route
|
|
45
47
|
*/
|
|
46
48
|
prefetch?: PrefetchConfig;
|
|
49
|
+
/**
|
|
50
|
+
* Whether navigation waits for props, loaders, and components before committing.
|
|
51
|
+
* @default 'progressive'
|
|
52
|
+
*/
|
|
53
|
+
navigation?: NavigationBehavior;
|
|
54
|
+
/**
|
|
55
|
+
* Animates navigations with the View Transitions API. Overridden per route and per navigation.
|
|
56
|
+
*
|
|
57
|
+
* @default false
|
|
58
|
+
*/
|
|
59
|
+
viewTransition?: ViewTransitionConfig;
|
|
47
60
|
/**
|
|
48
61
|
* Components assigned to each type of rejection your router supports.
|
|
49
62
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NavigationBehavior } from './navigation';
|
|
1
2
|
import { Routes } from './route';
|
|
2
3
|
import { RoutesName } from './routesMap';
|
|
3
4
|
import { RouteParamsByKey } from './routeWithParams';
|
|
@@ -6,6 +7,7 @@ import { UrlString } from './urlString';
|
|
|
6
7
|
import { AllPropertiesAreOptional } from './utilities';
|
|
7
8
|
import { QuerySource } from './querySource';
|
|
8
9
|
import { ResolvedRoute } from './resolved';
|
|
10
|
+
import { ViewTransitionConfig } from './viewTransition';
|
|
9
11
|
export type RouterPushOptions<TState = unknown> = {
|
|
10
12
|
/**
|
|
11
13
|
* The query string to add to the url.
|
|
@@ -19,10 +21,16 @@ export type RouterPushOptions<TState = unknown> = {
|
|
|
19
21
|
* Whether to replace the current history entry.
|
|
20
22
|
*/
|
|
21
23
|
replace?: boolean;
|
|
24
|
+
/** Overrides the route and router navigation behavior. */
|
|
25
|
+
navigation?: NavigationBehavior;
|
|
22
26
|
/**
|
|
23
27
|
* State values to pass to the route.
|
|
24
28
|
*/
|
|
25
29
|
state?: Partial<TState>;
|
|
30
|
+
/**
|
|
31
|
+
* Animates the navigation with the View Transitions API. Overrides route and router level viewTransition.
|
|
32
|
+
*/
|
|
33
|
+
viewTransition?: ViewTransitionConfig;
|
|
26
34
|
};
|
|
27
35
|
type RouterPushArgs<TRoutes extends Routes, TSource extends RoutesName<TRoutes>> = AllPropertiesAreOptional<RouteParamsByKey<TRoutes, TSource>> extends true ? [params?: RouteParamsByKey<TRoutes, TSource>, options?: RouterPushOptions<RouteStateByName<TRoutes, TSource>>] : [params: RouteParamsByKey<TRoutes, TSource>, options?: RouterPushOptions<RouteStateByName<TRoutes, TSource>>];
|
|
28
36
|
export type RouterPush<TRoutes extends Routes = any> = {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NavigationBehavior } from './navigation';
|
|
1
2
|
import { Routes } from './route';
|
|
2
3
|
import { RoutesName } from './routesMap';
|
|
3
4
|
import { RouteParamsByKey } from './routeWithParams';
|
|
@@ -8,6 +9,8 @@ import { QuerySource } from './querySource';
|
|
|
8
9
|
import { ResolvedRoute } from './resolved';
|
|
9
10
|
export type RouterReplaceOptions<TState = unknown> = {
|
|
10
11
|
query?: QuerySource;
|
|
12
|
+
/** Overrides the route and router navigation behavior. */
|
|
13
|
+
navigation?: NavigationBehavior;
|
|
11
14
|
hash?: string;
|
|
12
15
|
state?: Partial<TState>;
|
|
13
16
|
};
|
package/dist/types/useLink.d.ts
CHANGED
|
@@ -37,6 +37,11 @@ export type UseLink = {
|
|
|
37
37
|
*
|
|
38
38
|
*/
|
|
39
39
|
isExternal: ComputedRef<boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* True while a view transition to this link's location is in flight, so the elements it animates from
|
|
42
|
+
* can be named before the page is captured.
|
|
43
|
+
*/
|
|
44
|
+
isTransitioning: ComputedRef<boolean>;
|
|
40
45
|
/**
|
|
41
46
|
* Convenience method for executing `router.push` with route context passed in.
|
|
42
47
|
*/
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ResolvedRoute, RouterResolvedRouteUnion } from './resolved';
|
|
2
|
+
import { CreatedRouteOptions, Routes } from './route';
|
|
3
|
+
/**
|
|
4
|
+
* Types set on a view transition, which css targets with `:active-view-transition-type()`.
|
|
5
|
+
*/
|
|
6
|
+
export type ViewTransitionTypes = string[];
|
|
7
|
+
/**
|
|
8
|
+
* The navigation a view transition animates. There is always a route to animate from, since the first
|
|
9
|
+
* navigation never transitions.
|
|
10
|
+
*/
|
|
11
|
+
export type ViewTransitionContext = {
|
|
12
|
+
to: ResolvedRoute;
|
|
13
|
+
from: ResolvedRoute;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Decides the types for a navigation. Returning `false` skips the transition for that navigation.
|
|
17
|
+
*/
|
|
18
|
+
export type ViewTransitionTypesCallback = (context: ViewTransitionContext) => ViewTransitionTypes | false;
|
|
19
|
+
export type ViewTransitionConfigOptions = {
|
|
20
|
+
/**
|
|
21
|
+
* Types set on the transition, combined with the types of every other level that applies.
|
|
22
|
+
*/
|
|
23
|
+
types?: ViewTransitionTypes | ViewTransitionTypesCallback;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Whether a navigation animates with the View Transitions API. A boolean enables or disables the
|
|
27
|
+
* transition, an array of types or an options object enables it.
|
|
28
|
+
*/
|
|
29
|
+
export type ViewTransitionConfig = boolean | ViewTransitionTypes | ViewTransitionConfigOptions;
|
|
30
|
+
export type ViewTransitionConfigs = {
|
|
31
|
+
routerViewTransition?: ViewTransitionConfig;
|
|
32
|
+
routeViewTransition?: ViewTransitionConfig;
|
|
33
|
+
navigationViewTransition?: ViewTransitionConfig;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* The view transition in flight, from the moment a navigation is decided to transition until its
|
|
37
|
+
* animation finishes. `to` and `from` are known throughout, so the page being left can prepare its elements
|
|
38
|
+
* before it is captured. `transition` is set once the browser has been asked to transition.
|
|
39
|
+
*/
|
|
40
|
+
export type RouterViewTransition<TRoutes extends Routes = Routes> = {
|
|
41
|
+
readonly isTransitioning: boolean;
|
|
42
|
+
readonly to: RouterResolvedRouteUnion<TRoutes> | undefined;
|
|
43
|
+
readonly from: RouterResolvedRouteUnion<TRoutes> | undefined;
|
|
44
|
+
readonly types: ViewTransitionTypes;
|
|
45
|
+
readonly transition: ViewTransition | undefined;
|
|
46
|
+
};
|
|
47
|
+
export declare function hasViewTransition(match: CreatedRouteOptions): match is CreatedRouteOptions & {
|
|
48
|
+
viewTransition: ViewTransitionConfig;
|
|
49
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NavigationBehavior } from '../types/navigation';
|
|
2
|
+
import { ResolvedRoute } from '../types/resolved';
|
|
3
|
+
type NavigationOptions = {
|
|
4
|
+
routerNavigation?: NavigationBehavior;
|
|
5
|
+
routeNavigation?: NavigationBehavior;
|
|
6
|
+
navigation?: NavigationBehavior;
|
|
7
|
+
};
|
|
8
|
+
type NavigationOption = {
|
|
9
|
+
navigation: NavigationBehavior;
|
|
10
|
+
isBlockingNavigation: boolean;
|
|
11
|
+
isProgressiveNavigation: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare function getRouteNavigationOption(to: ResolvedRoute | null): NavigationBehavior | undefined;
|
|
14
|
+
export declare function getNavigationOption(options: NavigationOptions): NavigationOption;
|
|
15
|
+
export {};
|