@tanstack/router-core 0.0.1-beta.185 → 0.0.1-beta.187
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/build/cjs/fileRoute.js.map +1 -1
- package/build/cjs/history.js +20 -18
- package/build/cjs/history.js.map +1 -1
- package/build/cjs/index.js +1 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/route.js +4 -0
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js +211 -101
- package/build/cjs/router.js.map +1 -1
- package/build/cjs/scroll-restoration.js +1 -1
- package/build/cjs/scroll-restoration.js.map +1 -1
- package/build/cjs/utils.js +15 -0
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +252 -122
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +132 -132
- package/build/types/fileRoute.d.ts +1 -0
- package/build/types/history.d.ts +8 -3
- package/build/types/link.d.ts +23 -18
- package/build/types/route.d.ts +23 -7
- package/build/types/routeInfo.d.ts +3 -3
- package/build/types/router.d.ts +30 -20
- package/build/types/utils.d.ts +2 -11
- package/build/umd/index.development.js +252 -121
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/fileRoute.ts +3 -3
- package/src/history.ts +33 -25
- package/src/link.ts +66 -51
- package/src/route.ts +61 -16
- package/src/routeInfo.ts +3 -3
- package/src/router.ts +331 -177
- package/src/scroll-restoration.ts +1 -1
- package/src/utils.ts +21 -17
package/build/types/history.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export interface RouterHistory {
|
|
2
|
-
location:
|
|
2
|
+
location: HistoryLocation;
|
|
3
3
|
subscribe: (cb: () => void) => () => void;
|
|
4
4
|
push: (path: string, state?: any) => void;
|
|
5
5
|
replace: (path: string, state?: any) => void;
|
|
@@ -9,14 +9,19 @@ export interface RouterHistory {
|
|
|
9
9
|
createHref: (href: string) => string;
|
|
10
10
|
block: (blockerFn: BlockerFn) => () => void;
|
|
11
11
|
}
|
|
12
|
+
export interface HistoryLocation extends ParsedPath {
|
|
13
|
+
state: LocationState;
|
|
14
|
+
}
|
|
12
15
|
export interface ParsedPath {
|
|
13
16
|
href: string;
|
|
14
17
|
pathname: string;
|
|
15
18
|
search: string;
|
|
16
19
|
hash: string;
|
|
17
20
|
}
|
|
18
|
-
export interface
|
|
19
|
-
|
|
21
|
+
export interface LocationState {
|
|
22
|
+
key: string;
|
|
23
|
+
__tempLocation?: HistoryLocation;
|
|
24
|
+
__tempKey?: string;
|
|
20
25
|
}
|
|
21
26
|
type BlockerFn = (retry: () => void, cancel: () => void) => void;
|
|
22
27
|
export declare function createBrowserHistory(opts?: {
|
package/build/types/link.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Trim } from './fileRoute';
|
|
2
|
+
import { LocationState } from './history';
|
|
2
3
|
import { AnyRoute } from './route';
|
|
3
|
-
import { AllParams,
|
|
4
|
-
import { ParsedLocation
|
|
5
|
-
import { NoInfer, PickRequired, UnionToIntersection, Updater } from './utils';
|
|
4
|
+
import { AllParams, RouteByPath, RouteIds, RoutePaths } from './routeInfo';
|
|
5
|
+
import { ParsedLocation } from './router';
|
|
6
|
+
import { Expand, NoInfer, NonNullableUpdater, PickRequired, UnionToIntersection, Updater } from './utils';
|
|
6
7
|
export type LinkInfo = {
|
|
7
8
|
type: 'external';
|
|
8
9
|
href: string;
|
|
@@ -37,28 +38,32 @@ export type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends st
|
|
|
37
38
|
] ? `${TTo}${Join<RestPath>}` : never : (TFrom extends `/` ? never : SplitPaths extends [...Split<TFrom, false>, ...infer RestPath] ? Join<RestPath> extends {
|
|
38
39
|
length: 0;
|
|
39
40
|
} ? never : './' : never) | (TFrom extends `/` ? never : '../') | AllPaths;
|
|
40
|
-
export type NavigateOptions<TRouteTree extends AnyRoute = AnyRoute, TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = ''> = ToOptions<TRouteTree, TFrom, TTo> & {
|
|
41
|
+
export type NavigateOptions<TRouteTree extends AnyRoute = AnyRoute, TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = TFrom, TMaskTo extends string = ''> = ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
|
41
42
|
replace?: boolean;
|
|
42
43
|
resetScroll?: boolean;
|
|
43
44
|
};
|
|
44
|
-
export type ToOptions<TRouteTree extends AnyRoute = AnyRoute, TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '',
|
|
45
|
+
export type ToOptions<TRouteTree extends AnyRoute = AnyRoute, TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''> = ToSubOptions<TRouteTree, TFrom, TTo> & {
|
|
46
|
+
mask?: ToMaskOptions<TRouteTree, TMaskFrom, TMaskTo>;
|
|
47
|
+
};
|
|
48
|
+
export type ToMaskOptions<TRouteTree extends AnyRoute = AnyRoute, TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''> = ToSubOptions<TRouteTree, TMaskFrom, TMaskTo> & {
|
|
49
|
+
unmaskOnReload?: boolean;
|
|
50
|
+
};
|
|
51
|
+
export type ToSubOptions<TRouteTree extends AnyRoute = AnyRoute, TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>> = {
|
|
45
52
|
to?: ToPathOption<TRouteTree, TFrom, TTo>;
|
|
46
|
-
hash?: Updater<string>;
|
|
47
|
-
state?: LocationState
|
|
53
|
+
hash?: true | Updater<string>;
|
|
54
|
+
state?: true | NonNullableUpdater<LocationState>;
|
|
48
55
|
from?: TFrom;
|
|
49
|
-
} & CheckPath<TRouteTree, NoInfer<
|
|
50
|
-
export type SearchParamOptions<TRouteTree extends AnyRoute, TFrom, TTo,
|
|
51
|
-
search?: true | SearchReducer<
|
|
56
|
+
} & CheckPath<TRouteTree, NoInfer<TResolved>, {}> & SearchParamOptions<TRouteTree, TFrom, TResolved> & PathParamOptions<TRouteTree, TFrom, TResolved>;
|
|
57
|
+
export type SearchParamOptions<TRouteTree extends AnyRoute, TFrom, TTo, TFromSearchEnsured = Expand<UnionToIntersection<PickRequired<RouteByPath<TRouteTree, TFrom>['types']['fullSearchSchema']>>>, TFromSearchOptional = Omit<AllParams<TRouteTree>, keyof TFromSearchEnsured>, TFromSearch = Expand<TFromSearchEnsured & TFromSearchOptional>, TToSearch = Expand<RouteByPath<TRouteTree, TTo>['types']['fullSearchSchema']>> = keyof PickRequired<TToSearch> extends never ? {
|
|
58
|
+
search?: true | SearchReducer<TFromSearch, TToSearch>;
|
|
52
59
|
} : {
|
|
53
|
-
search: SearchReducer<
|
|
60
|
+
search: TFromSearchEnsured extends PickRequired<TToSearch> ? true | SearchReducer<TFromSearch, TToSearch> : SearchReducer<TFromSearch, TToSearch>;
|
|
54
61
|
};
|
|
55
|
-
type SearchReducer<TFrom, TTo> =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
export type PathParamOptions<TRouteTree extends AnyRoute, TFrom, TTo, TFromSchema = UnionToIntersection<RouteByPath<TRouteTree, TFrom> extends never ? {} : RouteByPath<TRouteTree, TFrom>['types']['allParams']>, TToSchema = Partial<RouteByPath<TRouteTree, TFrom>['types']['allParams']> & Omit<RouteByPath<TRouteTree, TTo>['types']['allParams'], keyof PickRequired<RouteByPath<TRouteTree, TFrom>['types']['allParams']>>, TFromFullParams = UnionToIntersection<AllParams<TRouteTree> & TFromSchema>, TToFullParams = UnionToIntersection<AllParams<TRouteTree> & TToSchema>> = keyof PickRequired<TToSchema> extends never ? {
|
|
59
|
-
params?: ParamsReducer<TFromFullParams, TToFullParams>;
|
|
62
|
+
type SearchReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
|
|
63
|
+
export type PathParamOptions<TRouteTree extends AnyRoute, TFrom, TTo, TFromParamsEnsured = Expand<UnionToIntersection<PickRequired<RouteByPath<TRouteTree, TFrom>['types']['allParams']>>>, TFromParamsOptional = Omit<AllParams<TRouteTree>, keyof TFromParamsEnsured>, TFromParams = Expand<TFromParamsOptional & TFromParamsEnsured>, TToParams = Expand<RouteByPath<TRouteTree, TTo>['types']['allParams']>> = keyof PickRequired<TToParams> extends never ? {
|
|
64
|
+
params?: true | ParamsReducer<TFromParams, TToParams>;
|
|
60
65
|
} : {
|
|
61
|
-
params: ParamsReducer<
|
|
66
|
+
params: TFromParamsEnsured extends PickRequired<TToParams> ? true | ParamsReducer<TFromParams, TToParams> : ParamsReducer<TFromParams, TToParams>;
|
|
62
67
|
};
|
|
63
68
|
type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
|
|
64
69
|
export type ToPathOption<TRouteTree extends AnyRoute = AnyRoute, TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = ''> = TTo | RelativeToPathAutoComplete<RoutePaths<TRouteTree>, NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
|
|
@@ -68,7 +73,7 @@ export interface ActiveOptions {
|
|
|
68
73
|
includeHash?: boolean;
|
|
69
74
|
includeSearch?: boolean;
|
|
70
75
|
}
|
|
71
|
-
export type LinkOptions<TRouteTree extends AnyRoute = AnyRoute, TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = ''> = NavigateOptions<TRouteTree, TFrom, TTo> & {
|
|
76
|
+
export type LinkOptions<TRouteTree extends AnyRoute = AnyRoute, TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = TFrom, TMaskTo extends string = ''> = NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
|
72
77
|
target?: HTMLAnchorElement['target'];
|
|
73
78
|
activeOptions?: ActiveOptions;
|
|
74
79
|
preload?: false | 'intent';
|
package/build/types/route.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RoutePaths } from './routeInfo';
|
|
2
2
|
import { AnyRouter, RouteMatch, AnyRouteMatch } from './router';
|
|
3
|
-
import { IsAny, NoInfer, PickRequired, UnionToIntersection } from './utils';
|
|
3
|
+
import { Expand, IsAny, NoInfer, PickRequired, UnionToIntersection } from './utils';
|
|
4
|
+
import { ParsePathParams, ToSubOptions } from './link';
|
|
4
5
|
export declare const rootRouteId: "__root__";
|
|
5
6
|
export type RootRouteId = typeof rootRouteId;
|
|
6
7
|
export type AnyPathParams = {};
|
|
@@ -103,6 +104,7 @@ export type UpdatableRouteOptions<TLoader, TSearchSchema extends AnySearchSchema
|
|
|
103
104
|
onEnter?: (match: AnyRouteMatch) => void;
|
|
104
105
|
onTransition?: (match: AnyRouteMatch) => void;
|
|
105
106
|
onLeave?: (match: AnyRouteMatch) => void;
|
|
107
|
+
reloadOnWindowFocus?: boolean;
|
|
106
108
|
};
|
|
107
109
|
export type ParseParamsOption<TPath extends string, TParams> = ParseParamsFn<TPath, TParams>;
|
|
108
110
|
export type ParseParamsFn<TPath extends string, TParams> = (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams extends Record<ParsePathParams<TPath>, any> ? TParams : 'parseParams must return an object';
|
|
@@ -152,7 +154,7 @@ export type InferFullSearchSchema<TRoute> = TRoute extends {
|
|
|
152
154
|
export type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = InferFullSearchSchema<TParentRoute> & TSearchSchema;
|
|
153
155
|
export interface AnyRoute extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
154
156
|
}
|
|
155
|
-
export type
|
|
157
|
+
export type MergeFromFromParent<T, U> = IsAny<T, U, T & U>;
|
|
156
158
|
export type UseLoaderResult<T> = T;
|
|
157
159
|
export type StreamedPromise<T> = {
|
|
158
160
|
promise: Promise<T>;
|
|
@@ -160,6 +162,7 @@ export type StreamedPromise<T> = {
|
|
|
160
162
|
data: T;
|
|
161
163
|
resolve: (value: T) => void;
|
|
162
164
|
};
|
|
165
|
+
export type ResolveAllParams<TParentRoute extends AnyRoute, TParams extends AnyPathParams> = Record<never, string> extends TParentRoute['types']['allParams'] ? TParams : Expand<UnionToIntersection<TParentRoute['types']['allParams'] & TParams> & {}>;
|
|
163
166
|
export type RouteConstraints = {
|
|
164
167
|
TParentRoute: AnyRoute;
|
|
165
168
|
TPath: string;
|
|
@@ -178,7 +181,7 @@ export type RouteConstraints = {
|
|
|
178
181
|
TChildren: unknown;
|
|
179
182
|
TRouteTree: AnyRoute;
|
|
180
183
|
};
|
|
181
|
-
export declare class Route<TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, TPath extends RouteConstraints['TPath'] = '/', TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, TCustomId extends RouteConstraints['TCustomId'] = string, TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, TLoader = unknown, TSearchSchema extends RouteConstraints['TSearchSchema'] = {}, TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends RouteConstraints['TParams'] = Record<ParsePathParams<TPath>, string
|
|
184
|
+
export declare class Route<TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, TPath extends RouteConstraints['TPath'] = '/', TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, TCustomId extends RouteConstraints['TCustomId'] = string, TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, TLoader = unknown, TSearchSchema extends RouteConstraints['TSearchSchema'] = {}, TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends RouteConstraints['TParams'] = Expand<Record<ParsePathParams<TPath>, string>>, TAllParams extends RouteConstraints['TAllParams'] = ResolveAllParams<TParentRoute, TParams>, TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['types']['routeContext'], TAllParentContext extends RouteConstraints['TAllParentContext'] = TParentRoute['types']['context'], TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext, TAllContext extends RouteConstraints['TAllContext'] = MergeFromFromParent<TParentRoute['types']['context'], TRouteContext>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
|
|
182
185
|
types: {
|
|
183
186
|
parentRoute: TParentRoute;
|
|
184
187
|
path: TPath;
|
|
@@ -222,14 +225,27 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
|
|
|
222
225
|
export type AnyRootRoute = RootRoute<any, any, any, any>;
|
|
223
226
|
export declare class RouterContext<TRouterContext extends {}> {
|
|
224
227
|
constructor();
|
|
225
|
-
createRootRoute: <TLoader = unknown, TSearchSchema extends AnySearchSchema = {}, TRouteContext extends RouteContext = RouteContext>(options?: Omit<RouteOptions<AnyRoute, "__root__", "", TLoader, TSearchSchema, TSearchSchema, TSearchSchema, {}, {}, TRouterContext, TRouterContext, TRouteContext, IsAny<TRouterContext, TRouteContext, TRouterContext & TRouteContext>>, "
|
|
228
|
+
createRootRoute: <TLoader = unknown, TSearchSchema extends AnySearchSchema = {}, TRouteContext extends RouteContext = RouteContext>(options?: Omit<RouteOptions<AnyRoute, "__root__", "", TLoader, TSearchSchema, TSearchSchema, TSearchSchema, {}, {}, TRouterContext, TRouterContext, TRouteContext, IsAny<TRouterContext, TRouteContext, TRouterContext & TRouteContext>>, "id" | "path" | "getParentRoute" | "stringifyParams" | "parseParams" | "caseSensitive"> | undefined) => RootRoute<TLoader, TSearchSchema, TRouteContext, TRouterContext>;
|
|
226
229
|
}
|
|
227
|
-
export declare class RootRoute<TLoader = unknown, TSearchSchema extends AnySearchSchema = {}, TRouteContext extends RouteContext = RouteContext, TRouterContext extends {} = {}> extends Route<any, '/', '/', string, RootRouteId, TLoader, TSearchSchema, TSearchSchema, {}, {}, TRouterContext, TRouterContext, TRouteContext,
|
|
228
|
-
constructor(options?: Omit<RouteOptions<AnyRoute, RootRouteId, '', TLoader, TSearchSchema, TSearchSchema, TSearchSchema, {}, {}, TRouterContext, TRouterContext, TRouteContext,
|
|
230
|
+
export declare class RootRoute<TLoader = unknown, TSearchSchema extends AnySearchSchema = {}, TRouteContext extends RouteContext = RouteContext, TRouterContext extends {} = {}> extends Route<any, '/', '/', string, RootRouteId, TLoader, TSearchSchema, TSearchSchema, {}, {}, TRouterContext, TRouterContext, TRouteContext, MergeFromFromParent<TRouterContext, TRouteContext>, TRouterContext, any, any> {
|
|
231
|
+
constructor(options?: Omit<RouteOptions<AnyRoute, RootRouteId, '', TLoader, TSearchSchema, TSearchSchema, TSearchSchema, {}, {}, TRouterContext, TRouterContext, TRouteContext, MergeFromFromParent<TRouterContext, TRouteContext>>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams'>);
|
|
229
232
|
}
|
|
230
233
|
export type ResolveFullPath<TParentRoute extends AnyRoute, TPath extends string, TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>> = TPrefixed extends RootRouteId ? '/' : TPrefixed;
|
|
231
234
|
type RoutePrefix<TPrefix extends string, TPath extends string> = string extends TPath ? RootRouteId : TPath extends string ? TPrefix extends RootRouteId ? TPath extends '/' ? '/' : `/${TrimPath<TPath>}` : `${TPrefix}/${TPath}` extends '/' ? '/' : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}` : never;
|
|
232
235
|
export type TrimPath<T extends string> = '' extends T ? '' : TrimPathRight<TrimPathLeft<T>>;
|
|
233
236
|
export type TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}` ? TrimPathLeft<U> : T extends `/${infer U}` ? TrimPathLeft<U> : T;
|
|
234
237
|
export type TrimPathRight<T extends string> = T extends '/' ? '/' : T extends `${infer U}/` ? TrimPathRight<U> : T;
|
|
238
|
+
export type RouteMask<TRouteTree extends AnyRoute> = {
|
|
239
|
+
routeTree: TRouteTree;
|
|
240
|
+
from: RoutePaths<TRouteTree>;
|
|
241
|
+
to?: any;
|
|
242
|
+
params?: any;
|
|
243
|
+
search?: any;
|
|
244
|
+
hash?: any;
|
|
245
|
+
state?: any;
|
|
246
|
+
unmaskOnReload?: boolean;
|
|
247
|
+
};
|
|
248
|
+
export declare function createRouteMask<TRouteTree extends AnyRoute, TFrom extends RoutePaths<TRouteTree>, TTo extends string>(opts: {
|
|
249
|
+
routeTree: TRouteTree;
|
|
250
|
+
} & ToSubOptions<TRouteTree, TFrom, TTo>): RouteMask<TRouteTree>;
|
|
235
251
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnyRoute, Route } from './route';
|
|
2
|
-
import {
|
|
2
|
+
import { UnionToIntersection } from './utils';
|
|
3
3
|
export type ParseRoute<TRouteTree extends AnyRoute> = TRouteTree | ParseRouteChildren<TRouteTree>;
|
|
4
4
|
export type ParseRouteChildren<TRouteTree extends AnyRoute> = TRouteTree extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, infer TChildren, any> ? unknown extends TChildren ? never : TChildren extends AnyRoute[] ? {
|
|
5
5
|
[TId in TChildren[number]['id'] as string]: ParseRoute<TChildren[number]>;
|
|
@@ -18,5 +18,5 @@ export type RouteByPath<TRouteTree extends AnyRoute, TPath> = Extract<ParseRoute
|
|
|
18
18
|
fullPath: TPath;
|
|
19
19
|
}>;
|
|
20
20
|
export type RoutePaths<TRouteTree extends AnyRoute> = ParseRoute<TRouteTree>['fullPath'] | '/';
|
|
21
|
-
export type FullSearchSchema<TRouteTree extends AnyRoute> =
|
|
22
|
-
export type AllParams<TRouteTree extends AnyRoute> =
|
|
21
|
+
export type FullSearchSchema<TRouteTree extends AnyRoute> = UnionToIntersection<ParseRoute<TRouteTree>['types']['fullSearchSchema']> & {};
|
|
22
|
+
export type AllParams<TRouteTree extends AnyRoute> = UnionToIntersection<ParseRoute<TRouteTree>['types']['allParams']>;
|
package/build/types/router.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Store } from '@tanstack/store';
|
|
3
3
|
import { LinkInfo, LinkOptions, NavigateOptions, ToOptions, ResolveRelativePath } from './link';
|
|
4
|
-
import { Route, AnySearchSchema, AnyRoute, AnyContext, AnyPathParams, RegisteredRouteComponent, RegisteredErrorRouteComponent, RegisteredPendingRouteComponent } from './route';
|
|
4
|
+
import { Route, AnySearchSchema, AnyRoute, AnyContext, AnyPathParams, RegisteredRouteComponent, RegisteredErrorRouteComponent, RegisteredPendingRouteComponent, RouteMask } from './route';
|
|
5
5
|
import { RoutesById, RoutesByPath, ParseRoute, FullSearchSchema, RouteById, RoutePaths, RouteIds } from './routeInfo';
|
|
6
|
-
import { NoInfer, PickAsRequired, Timeout, Updater } from './utils';
|
|
7
|
-
import { RouterHistory } from './history';
|
|
6
|
+
import { NoInfer, PickAsRequired, Timeout, Updater, NonNullableUpdater } from './utils';
|
|
7
|
+
import { LocationState, RouterHistory } from './history';
|
|
8
8
|
declare global {
|
|
9
9
|
interface Window {
|
|
10
10
|
__TSR_DEHYDRATED__?: HydrationCtx;
|
|
@@ -16,8 +16,6 @@ export type AnyRouter = Router<any, any>;
|
|
|
16
16
|
export type RegisteredRouter = Register extends {
|
|
17
17
|
router: infer TRouter extends AnyRouter;
|
|
18
18
|
} ? TRouter : AnyRouter;
|
|
19
|
-
export interface LocationState {
|
|
20
|
-
}
|
|
21
19
|
export interface ParsedLocation<TSearchObj extends AnySearchSchema = {}> {
|
|
22
20
|
href: string;
|
|
23
21
|
pathname: string;
|
|
@@ -25,12 +23,12 @@ export interface ParsedLocation<TSearchObj extends AnySearchSchema = {}> {
|
|
|
25
23
|
searchStr: string;
|
|
26
24
|
state: LocationState;
|
|
27
25
|
hash: string;
|
|
28
|
-
|
|
26
|
+
maskedLocation?: ParsedLocation<TSearchObj>;
|
|
27
|
+
unmaskOnReload?: boolean;
|
|
29
28
|
}
|
|
30
29
|
export interface FromLocation {
|
|
31
30
|
pathname: string;
|
|
32
31
|
search?: unknown;
|
|
33
|
-
key?: string;
|
|
34
32
|
hash?: string;
|
|
35
33
|
}
|
|
36
34
|
export type SearchSerializer = (searchObj: Record<string, any>) => string;
|
|
@@ -76,7 +74,7 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TDehydrated extends
|
|
|
76
74
|
parseSearch?: SearchParser;
|
|
77
75
|
defaultPreload?: false | 'intent';
|
|
78
76
|
defaultPreloadDelay?: number;
|
|
79
|
-
|
|
77
|
+
reloadOnWindowFocus?: boolean;
|
|
80
78
|
defaultComponent?: RegisteredRouteComponent<unknown, AnySearchSchema, AnyPathParams, AnyContext, AnyContext>;
|
|
81
79
|
defaultErrorComponent?: RegisteredErrorRouteComponent<AnySearchSchema, AnyPathParams, AnyContext, AnyContext>;
|
|
82
80
|
defaultPendingComponent?: RegisteredPendingRouteComponent<AnySearchSchema, AnyPathParams, AnyContext, AnyContext>;
|
|
@@ -97,6 +95,8 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TDehydrated extends
|
|
|
97
95
|
}>;
|
|
98
96
|
dehydrate?: () => TDehydrated;
|
|
99
97
|
hydrate?: (dehydrated: TDehydrated) => void;
|
|
98
|
+
routeMasks?: RouteMask<TRouteTree>[];
|
|
99
|
+
unmaskOnReload?: boolean;
|
|
100
100
|
}
|
|
101
101
|
export interface RouterState<TRouteTree extends AnyRoute = AnyRoute> {
|
|
102
102
|
status: 'idle' | 'pending';
|
|
@@ -118,18 +118,26 @@ export interface BuildNextOptions {
|
|
|
118
118
|
params?: true | Updater<unknown>;
|
|
119
119
|
search?: true | Updater<unknown>;
|
|
120
120
|
hash?: true | Updater<string>;
|
|
121
|
-
state?: LocationState
|
|
122
|
-
|
|
121
|
+
state?: true | NonNullableUpdater<LocationState>;
|
|
122
|
+
mask?: {
|
|
123
|
+
to?: string | number | null;
|
|
124
|
+
params?: true | Updater<unknown>;
|
|
125
|
+
search?: true | Updater<unknown>;
|
|
126
|
+
hash?: true | Updater<string>;
|
|
127
|
+
state?: true | NonNullableUpdater<LocationState>;
|
|
128
|
+
unmaskOnReload?: boolean;
|
|
129
|
+
};
|
|
123
130
|
from?: string;
|
|
124
|
-
|
|
125
|
-
|
|
131
|
+
}
|
|
132
|
+
export interface CommitLocationOptions {
|
|
133
|
+
replace?: boolean;
|
|
134
|
+
resetScroll?: boolean;
|
|
126
135
|
}
|
|
127
136
|
export interface MatchLocation {
|
|
128
137
|
to?: string | number | null;
|
|
129
138
|
fuzzy?: boolean;
|
|
130
139
|
caseSensitive?: boolean;
|
|
131
140
|
from?: string;
|
|
132
|
-
fromCurrent?: boolean;
|
|
133
141
|
}
|
|
134
142
|
export interface MatchRouteOptions {
|
|
135
143
|
pending?: boolean;
|
|
@@ -185,13 +193,13 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
|
|
|
185
193
|
state: RouterState<TRouteTree>;
|
|
186
194
|
dehydratedData?: TDehydrated;
|
|
187
195
|
resetNextScroll: boolean;
|
|
196
|
+
tempLocationKey: string;
|
|
188
197
|
constructor(options: RouterConstructorOptions<TRouteTree, TDehydrated>);
|
|
189
198
|
subscribers: Set<RouterListener<RouterEvent>>;
|
|
190
199
|
subscribe: <TType extends keyof RouterEvents>(eventType: TType, fn: ListenerFn<RouterEvents[TType]>) => () => void;
|
|
191
200
|
reset: () => void;
|
|
192
201
|
mount: () => () => void;
|
|
193
202
|
update: (opts?: RouterOptions<any, any>) => this;
|
|
194
|
-
buildNext: (opts: BuildNextOptions) => ParsedLocation;
|
|
195
203
|
cancelMatches: () => void;
|
|
196
204
|
cancelMatch: (id: string) => void;
|
|
197
205
|
safeLoad: (opts?: {
|
|
@@ -206,26 +214,27 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
|
|
|
206
214
|
getRoute: (id: string) => Route;
|
|
207
215
|
preloadRoute: (navigateOpts?: BuildNextOptions & {
|
|
208
216
|
maxAge?: number;
|
|
209
|
-
}) => Promise<RouteMatch<TRouteTree, ParseRoute<TRouteTree>["id"]>[]>;
|
|
217
|
+
}) => Promise<readonly [RouteMatch<TRouteTree, ParseRoute<TRouteTree>["id"]>, RouteMatch<TRouteTree, ParseRoute<TRouteTree>["id"]>[]]>;
|
|
210
218
|
cleanMatches: () => void;
|
|
211
219
|
matchRoutes: (pathname: string, locationSearch: AnySearchSchema, opts?: {
|
|
212
220
|
throwOnError?: boolean;
|
|
213
221
|
debug?: boolean;
|
|
214
222
|
}) => RouteMatch<TRouteTree>[];
|
|
215
|
-
loadMatches: (
|
|
223
|
+
loadMatches: (matchIds: string[], opts?: {
|
|
216
224
|
preload?: boolean;
|
|
217
225
|
maxAge?: number;
|
|
218
226
|
}) => Promise<void>;
|
|
219
227
|
resolvePath: (from: string, path: string) => string;
|
|
220
|
-
navigate: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string = "">({ from, to, search, hash, replace, params, resetScroll, }: NavigateOptions<TRouteTree, TFrom, TTo>) => Promise<void>;
|
|
221
|
-
matchRoute: <TFrom extends RoutePaths<
|
|
222
|
-
buildLink: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string = "">({ from, to, search, params, hash, target, replace, activeOptions, preload, preloadDelay: userPreloadDelay, disabled, state, resetScroll, }: LinkOptions<TRouteTree, TFrom, TTo>) => LinkInfo;
|
|
228
|
+
navigate: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string = "", TMaskFrom extends RoutePaths<TRouteTree> = TFrom, TMaskTo extends string = "">({ from, to, search, hash, replace, params, resetScroll, }: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<void>;
|
|
229
|
+
matchRoute: <TRouteTree_1 extends AnyRoute = AnyRoute, TFrom extends RoutePaths<TRouteTree_1> = "/", TTo extends string = "", TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<TRouteTree_1, TFrom, TTo, "/", "">, opts?: MatchRouteOptions) => false | RouteById<TRouteTree_1, TResolved>["types"]["allParams"];
|
|
230
|
+
buildLink: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string = "">({ from, to, search, params, hash, target, replace, activeOptions, preload, preloadDelay: userPreloadDelay, disabled, state, mask, resetScroll, }: LinkOptions<TRouteTree, TFrom, TTo, TFrom, "">) => LinkInfo;
|
|
223
231
|
dehydrate: () => DehydratedRouter;
|
|
224
232
|
hydrate: (__do_not_use_server_ctx?: HydrationCtx) => Promise<void>;
|
|
225
233
|
injectedHtml: (string | (() => Promise<string> | string))[];
|
|
226
234
|
injectHtml: (html: string | (() => Promise<string> | string)) => Promise<void>;
|
|
227
235
|
dehydrateData: <T>(key: any, getData: T | (() => T | Promise<T>)) => () => T | undefined;
|
|
228
236
|
hydrateData: <T = unknown>(key: any) => T | undefined;
|
|
237
|
+
buildLocation: (opts?: BuildNextOptions) => ParsedLocation;
|
|
229
238
|
getRouteMatch: (id: string) => undefined | RouteMatch<TRouteTree>;
|
|
230
239
|
setRouteMatch: (id: string, updater: (prev: RouteMatch<TRouteTree>) => RouteMatch<TRouteTree>) => void;
|
|
231
240
|
setRouteMatchData: (id: string, updater: (prev: any) => any, opts?: {
|
|
@@ -235,10 +244,11 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
|
|
|
235
244
|
invalidate: (opts?: {
|
|
236
245
|
matchId?: string;
|
|
237
246
|
reload?: boolean;
|
|
247
|
+
__fromFocus?: boolean;
|
|
238
248
|
}) => Promise<void>;
|
|
239
249
|
}
|
|
240
250
|
export type AnyRedirect = Redirect<any, any, any>;
|
|
241
|
-
export type Redirect<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = ''> = NavigateOptions<TRouteTree, TFrom, TTo> & {
|
|
251
|
+
export type Redirect<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = TFrom, TMaskTo extends string = ''> = NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
|
242
252
|
code?: number;
|
|
243
253
|
};
|
|
244
254
|
export declare function redirect<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = ''>(opts: Redirect<TRouteTree, TFrom, TTo>): Redirect<TRouteTree, TFrom, TTo>;
|
package/build/types/utils.d.ts
CHANGED
|
@@ -15,15 +15,6 @@ export type Expand<T> = T extends object ? T extends infer O ? {
|
|
|
15
15
|
[K in keyof O]: O[K];
|
|
16
16
|
} : never : T;
|
|
17
17
|
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => any ? I : never;
|
|
18
|
-
type Compute<T> = {
|
|
19
|
-
[K in keyof T]: T[K];
|
|
20
|
-
} | never;
|
|
21
|
-
type AllKeys<T> = T extends any ? keyof T : never;
|
|
22
|
-
export type MergeUnion<T, Keys extends keyof T = keyof T> = Compute<{
|
|
23
|
-
[K in Keys]: T[Keys];
|
|
24
|
-
} & {
|
|
25
|
-
[K in AllKeys<T>]?: T extends any ? K extends keyof T ? T[K] : never : never;
|
|
26
|
-
}>;
|
|
27
18
|
export type Values<O> = O[ValueKeys<O>];
|
|
28
19
|
export type ValueKeys<O> = Extract<keyof O, PropertyKey>;
|
|
29
20
|
export type DeepAwaited<T> = T extends Promise<infer A> ? DeepAwaited<A> : T extends Record<infer A, Promise<infer B>> ? {
|
|
@@ -32,6 +23,7 @@ export type DeepAwaited<T> = T extends Promise<infer A> ? DeepAwaited<A> : T ext
|
|
|
32
23
|
export type PathParamMask<TRoutePath extends string> = TRoutePath extends `${infer L}/$${infer C}/${infer R}` ? PathParamMask<`${L}/${string}/${R}`> : TRoutePath extends `${infer L}/$${infer C}` ? PathParamMask<`${L}/${string}`> : TRoutePath;
|
|
33
24
|
export type Timeout = ReturnType<typeof setTimeout>;
|
|
34
25
|
export type Updater<TPrevious, TResult = TPrevious> = TResult | ((prev?: TPrevious) => TResult);
|
|
26
|
+
export type NonNullableUpdater<TPrevious, TResult = TPrevious> = TResult | ((prev: TPrevious) => TResult);
|
|
35
27
|
export type PickExtract<T, U> = {
|
|
36
28
|
[K in keyof T as T[K] extends U ? K : never]: T[K];
|
|
37
29
|
};
|
|
@@ -39,7 +31,7 @@ export type PickExclude<T, U> = {
|
|
|
39
31
|
[K in keyof T as T[K] extends U ? never : K]: T[K];
|
|
40
32
|
};
|
|
41
33
|
export declare function last<T>(arr: T[]): T | undefined;
|
|
42
|
-
export declare function functionalUpdate<TResult>(updater: Updater<TResult>, previous: TResult): TResult;
|
|
34
|
+
export declare function functionalUpdate<TResult>(updater: Updater<TResult> | NonNullableUpdater<TResult>, previous: TResult): TResult;
|
|
43
35
|
export declare function pick<T, K extends keyof T>(parent: T, keys: K[]): Pick<T, K>;
|
|
44
36
|
/**
|
|
45
37
|
* This function returns `a` if `b` is deeply equal.
|
|
@@ -50,4 +42,3 @@ export declare function pick<T, K extends keyof T>(parent: T, keys: K[]): Pick<T
|
|
|
50
42
|
export declare function replaceEqualDeep<T>(prev: any, _next: T): T;
|
|
51
43
|
export declare function isPlainObject(o: any): boolean;
|
|
52
44
|
export declare function partialDeepEqual(a: any, b: any): boolean;
|
|
53
|
-
export {};
|