@tanstack/router-core 0.0.1-beta.19 → 0.0.1-beta.191
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/LICENSE +21 -0
- package/build/cjs/defer.js +39 -0
- package/build/cjs/defer.js.map +1 -0
- package/build/cjs/fileRoute.js +29 -0
- package/build/cjs/fileRoute.js.map +1 -0
- package/build/cjs/history.js +228 -0
- package/build/cjs/history.js.map +1 -0
- package/build/cjs/index.js +86 -0
- package/build/cjs/{packages/router-core/src/index.js.map → index.js.map} +1 -1
- package/build/cjs/{packages/router-core/src/path.js → path.js} +45 -56
- package/build/cjs/path.js.map +1 -0
- package/build/cjs/{packages/router-core/src/qss.js → qss.js} +10 -16
- package/build/cjs/qss.js.map +1 -0
- package/build/cjs/route.js +114 -0
- package/build/cjs/route.js.map +1 -0
- package/build/cjs/router.js +1267 -0
- package/build/cjs/router.js.map +1 -0
- package/build/cjs/scroll-restoration.js +139 -0
- package/build/cjs/scroll-restoration.js.map +1 -0
- package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +32 -19
- package/build/cjs/searchParams.js.map +1 -0
- package/build/cjs/{packages/router-core/src/utils.js → utils.js} +69 -64
- package/build/cjs/utils.js.map +1 -0
- package/build/esm/index.js +1746 -2121
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +59 -49
- package/build/stats-react.json +197 -211
- package/build/types/defer.d.ts +19 -0
- package/build/types/fileRoute.d.ts +35 -0
- package/build/types/history.d.ts +36 -0
- package/build/types/index.d.ts +13 -609
- package/build/types/link.d.ts +96 -0
- package/build/types/path.d.ts +16 -0
- package/build/types/qss.d.ts +2 -0
- package/build/types/route.d.ts +251 -0
- package/build/types/routeInfo.d.ts +22 -0
- package/build/types/router.d.ts +260 -0
- package/build/types/scroll-restoration.d.ts +6 -0
- package/build/types/searchParams.d.ts +5 -0
- package/build/types/utils.d.ts +44 -0
- package/build/umd/index.development.js +1978 -2243
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +13 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +11 -7
- package/src/defer.ts +55 -0
- package/src/fileRoute.ts +161 -0
- package/src/history.ts +300 -0
- package/src/index.ts +5 -10
- package/src/link.ts +136 -125
- package/src/path.ts +37 -17
- package/src/qss.ts +1 -2
- package/src/route.ts +948 -218
- package/src/routeInfo.ts +45 -211
- package/src/router.ts +1778 -1075
- package/src/scroll-restoration.ts +179 -0
- package/src/searchParams.ts +31 -9
- package/src/utils.ts +84 -49
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
- package/build/cjs/node_modules/history/index.js +0 -815
- package/build/cjs/node_modules/history/index.js.map +0 -1
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
- package/build/cjs/packages/router-core/src/index.js +0 -58
- package/build/cjs/packages/router-core/src/path.js.map +0 -1
- package/build/cjs/packages/router-core/src/qss.js.map +0 -1
- package/build/cjs/packages/router-core/src/route.js +0 -147
- package/build/cjs/packages/router-core/src/route.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeConfig.js +0 -69
- package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeMatch.js +0 -220
- package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
- package/build/cjs/packages/router-core/src/router.js +0 -870
- package/build/cjs/packages/router-core/src/router.js.map +0 -1
- package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
- package/build/cjs/packages/router-core/src/utils.js.map +0 -1
- package/src/frameworks.ts +0 -11
- package/src/routeConfig.ts +0 -511
- package/src/routeMatch.ts +0 -312
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Trim } from './fileRoute';
|
|
2
|
+
import { AnyRoute } from './route';
|
|
3
|
+
import { AllParams, RouteByPath, RouteIds, RoutePaths } from './routeInfo';
|
|
4
|
+
import { LocationState, ParsedLocation } from './router';
|
|
5
|
+
import { Expand, NoInfer, NonNullableUpdater, PickRequired, UnionToIntersection, Updater } from './utils';
|
|
6
|
+
export type LinkInfo = {
|
|
7
|
+
type: 'external';
|
|
8
|
+
href: string;
|
|
9
|
+
} | {
|
|
10
|
+
type: 'internal';
|
|
11
|
+
next: ParsedLocation;
|
|
12
|
+
handleFocus: (e: any) => void;
|
|
13
|
+
handleClick: (e: any) => void;
|
|
14
|
+
handleEnter: (e: any) => void;
|
|
15
|
+
handleLeave: (e: any) => void;
|
|
16
|
+
handleTouchStart: (e: any) => void;
|
|
17
|
+
isActive: boolean;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
};
|
|
20
|
+
export type CleanPath<T extends string> = T extends `${infer L}//${infer R}` ? CleanPath<`${CleanPath<L>}/${CleanPath<R>}`> : T extends `${infer L}//` ? `${CleanPath<L>}/` : T extends `//${infer L}` ? `/${CleanPath<L>}` : T;
|
|
21
|
+
export type Split<S, TIncludeTrailingSlash = true> = S extends unknown ? string extends S ? string[] : S extends string ? CleanPath<S> extends '' ? [] : TIncludeTrailingSlash extends true ? CleanPath<S> extends `${infer T}/` ? [...Split<T>, '/'] : CleanPath<S> extends `/${infer U}` ? Split<U> : CleanPath<S> extends `${infer T}/${infer U}` ? [...Split<T>, ...Split<U>] : [S] : CleanPath<S> extends `${infer T}/${infer U}` ? [...Split<T>, ...Split<U>] : S extends string ? [S] : never : never : never;
|
|
22
|
+
export type ParsePathParams<T extends string> = keyof {
|
|
23
|
+
[K in Trim<Split<T>[number], '_'> as K extends `$${infer L}` ? L : never]: K;
|
|
24
|
+
};
|
|
25
|
+
export type Join<T, Delimiter extends string = '/'> = T extends [] ? '' : T extends [infer L extends string] ? L : T extends [infer L extends string, ...infer Tail extends [...string[]]] ? CleanPath<`${L}${Delimiter}${Join<Tail>}`> : never;
|
|
26
|
+
export type Last<T extends any[]> = T extends [...infer _, infer L] ? L : never;
|
|
27
|
+
export type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends string, TTo extends string, SplitPaths extends string[] = Split<AllPaths, false>> = TTo extends `..${infer _}` ? SplitPaths extends [
|
|
28
|
+
...Split<ResolveRelativePath<TFrom, TTo>, false>,
|
|
29
|
+
...infer TToRest
|
|
30
|
+
] ? `${CleanPath<Join<[
|
|
31
|
+
...Split<TTo, false>,
|
|
32
|
+
...(TToRest | (Split<ResolveRelativePath<TFrom, TTo>, false>['length'] extends 1 ? never : ['../']))
|
|
33
|
+
]>>}` : never : TTo extends `./${infer RestTTo}` ? SplitPaths extends [
|
|
34
|
+
...Split<TFrom, false>,
|
|
35
|
+
...Split<RestTTo, false>,
|
|
36
|
+
...infer RestPath
|
|
37
|
+
] ? `${TTo}${Join<RestPath>}` : never : (TFrom extends `/` ? never : SplitPaths extends [...Split<TFrom, false>, ...infer RestPath] ? Join<RestPath> extends {
|
|
38
|
+
length: 0;
|
|
39
|
+
} ? never : './' : never) | (TFrom extends `/` ? never : '../') | AllPaths;
|
|
40
|
+
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
|
+
replace?: boolean;
|
|
42
|
+
resetScroll?: boolean;
|
|
43
|
+
};
|
|
44
|
+
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> & {
|
|
45
|
+
mask?: ToMaskOptions<TRouteTree, TMaskFrom, TMaskTo>;
|
|
46
|
+
};
|
|
47
|
+
export type ToMaskOptions<TRouteTree extends AnyRoute = AnyRoute, TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''> = ToSubOptions<TRouteTree, TMaskFrom, TMaskTo> & {
|
|
48
|
+
unmaskOnReload?: boolean;
|
|
49
|
+
};
|
|
50
|
+
export type ToSubOptions<TRouteTree extends AnyRoute = AnyRoute, TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>> = {
|
|
51
|
+
to?: ToPathOption<TRouteTree, TFrom, TTo>;
|
|
52
|
+
hash?: true | Updater<string>;
|
|
53
|
+
state?: true | NonNullableUpdater<LocationState>;
|
|
54
|
+
from?: TFrom;
|
|
55
|
+
} & CheckPath<TRouteTree, NoInfer<TResolved>, {}> & SearchParamOptions<TRouteTree, TFrom, TResolved> & PathParamOptions<TRouteTree, TFrom, TResolved>;
|
|
56
|
+
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 ? {
|
|
57
|
+
search?: true | SearchReducer<TFromSearch, TToSearch>;
|
|
58
|
+
} : {
|
|
59
|
+
search: TFromSearchEnsured extends PickRequired<TToSearch> ? true | SearchReducer<TFromSearch, TToSearch> : SearchReducer<TFromSearch, TToSearch>;
|
|
60
|
+
};
|
|
61
|
+
type SearchReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
|
|
62
|
+
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 ? {
|
|
63
|
+
params?: true | ParamsReducer<TFromParams, TToParams>;
|
|
64
|
+
} : {
|
|
65
|
+
params: TFromParamsEnsured extends PickRequired<TToParams> ? true | ParamsReducer<TFromParams, TToParams> : ParamsReducer<TFromParams, TToParams>;
|
|
66
|
+
};
|
|
67
|
+
type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
|
|
68
|
+
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>;
|
|
69
|
+
export type ToIdOption<TRouteTree extends AnyRoute = AnyRoute, TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = ''> = TTo | RelativeToPathAutoComplete<RouteIds<TRouteTree>, NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
|
|
70
|
+
export interface ActiveOptions {
|
|
71
|
+
exact?: boolean;
|
|
72
|
+
includeHash?: boolean;
|
|
73
|
+
includeSearch?: boolean;
|
|
74
|
+
}
|
|
75
|
+
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> & {
|
|
76
|
+
target?: HTMLAnchorElement['target'];
|
|
77
|
+
activeOptions?: ActiveOptions;
|
|
78
|
+
preload?: false | 'intent';
|
|
79
|
+
preloadDelay?: number;
|
|
80
|
+
disabled?: boolean;
|
|
81
|
+
};
|
|
82
|
+
export type CheckRelativePath<TRouteTree extends AnyRoute, TFrom, TTo> = TTo extends string ? TFrom extends string ? ResolveRelativePath<TFrom, TTo> extends RoutePaths<TRouteTree> ? {} : {
|
|
83
|
+
Error: `${TFrom} + ${TTo} resolves to ${ResolveRelativePath<TFrom, TTo>}, which is not a valid route path.`;
|
|
84
|
+
'Valid Route Paths': RoutePaths<TRouteTree>;
|
|
85
|
+
} : {} : {};
|
|
86
|
+
export type CheckPath<TRouteTree extends AnyRoute, TPath, TPass> = Exclude<TPath, RoutePaths<TRouteTree>> extends never ? TPass : CheckPathError<TRouteTree, Exclude<TPath, RoutePaths<TRouteTree>>>;
|
|
87
|
+
export type CheckPathError<TRouteTree extends AnyRoute, TInvalids> = {
|
|
88
|
+
to: RoutePaths<TRouteTree>;
|
|
89
|
+
};
|
|
90
|
+
export type CheckId<TRouteTree extends AnyRoute, TPath, TPass> = Exclude<TPath, RouteIds<TRouteTree>> extends never ? TPass : CheckIdError<TRouteTree, Exclude<TPath, RouteIds<TRouteTree>>>;
|
|
91
|
+
export type CheckIdError<TRouteTree extends AnyRoute, TInvalids> = {
|
|
92
|
+
Error: `${TInvalids extends string ? TInvalids : never} is not a valid route ID.`;
|
|
93
|
+
'Valid Route IDs': RouteIds<TRouteTree>;
|
|
94
|
+
};
|
|
95
|
+
export type ResolveRelativePath<TFrom, TTo = '.'> = TFrom extends string ? TTo extends string ? TTo extends '.' ? TFrom : TTo extends `./` ? Join<[TFrom, '/']> : TTo extends `./${infer TRest}` ? ResolveRelativePath<TFrom, TRest> : TTo extends `/${infer TRest}` ? TTo : Split<TTo> extends ['..', ...infer ToRest] ? Split<TFrom> extends [...infer FromRest, infer FromTail] ? ToRest extends ['/'] ? Join<[...FromRest, '/']> : ResolveRelativePath<Join<FromRest>, Join<ToRest>> : never : Split<TTo> extends ['.', ...infer ToRest] ? ToRest extends ['/'] ? Join<[TFrom, '/']> : ResolveRelativePath<TFrom, Join<ToRest>> : CleanPath<Join<['/', ...Split<TFrom>, ...Split<TTo>]>> : never : never;
|
|
96
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AnyPathParams } from './route';
|
|
2
|
+
import { MatchLocation } from './router';
|
|
3
|
+
export interface Segment {
|
|
4
|
+
type: 'pathname' | 'param' | 'wildcard';
|
|
5
|
+
value: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function joinPaths(paths: (string | undefined)[]): string;
|
|
8
|
+
export declare function cleanPath(path: string): string;
|
|
9
|
+
export declare function trimPathLeft(path: string): string;
|
|
10
|
+
export declare function trimPathRight(path: string): string;
|
|
11
|
+
export declare function trimPath(path: string): string;
|
|
12
|
+
export declare function resolvePath(basepath: string, base: string, to: string): string;
|
|
13
|
+
export declare function parsePathname(pathname?: string): Segment[];
|
|
14
|
+
export declare function interpolatePath(path: string | undefined, params: any, leaveWildcards?: boolean): string;
|
|
15
|
+
export declare function matchPathname(basepath: string, currentPathname: string, matchLocation: Pick<MatchLocation, 'to' | 'fuzzy' | 'caseSensitive'>): AnyPathParams | undefined;
|
|
16
|
+
export declare function matchByPath(basepath: string, from: string, matchLocation: Pick<MatchLocation, 'to' | 'caseSensitive' | 'fuzzy'>): Record<string, string> | undefined;
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { RoutePaths } from './routeInfo';
|
|
2
|
+
import { AnyRouter, RouteMatch, AnyRouteMatch } from './router';
|
|
3
|
+
import { Expand, IsAny, NoInfer, PickRequired, UnionToIntersection } from './utils';
|
|
4
|
+
import { ParsePathParams, ToSubOptions } from './link';
|
|
5
|
+
export declare const rootRouteId: "__root__";
|
|
6
|
+
export type RootRouteId = typeof rootRouteId;
|
|
7
|
+
export type AnyPathParams = {};
|
|
8
|
+
export type AnySearchSchema = {};
|
|
9
|
+
export type AnyContext = {};
|
|
10
|
+
export interface RouteMeta {
|
|
11
|
+
}
|
|
12
|
+
export interface RouteContext {
|
|
13
|
+
}
|
|
14
|
+
export interface RegisterRouteComponent<TLoader = unknown, TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
15
|
+
}
|
|
16
|
+
export interface RegisterErrorRouteComponent<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
17
|
+
}
|
|
18
|
+
export interface RegisterPendingRouteComponent<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
19
|
+
}
|
|
20
|
+
export interface RegisterRouteProps<TLoader = unknown, TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
21
|
+
}
|
|
22
|
+
export interface RegisterErrorRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
23
|
+
}
|
|
24
|
+
export interface RegisterPendingRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
25
|
+
}
|
|
26
|
+
export type RegisteredRouteComponent<TLoader = unknown, TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = RegisterRouteComponent<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
|
|
27
|
+
RouteComponent: infer T;
|
|
28
|
+
} ? T : () => unknown;
|
|
29
|
+
export type RegisteredErrorRouteComponent<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = RegisterErrorRouteComponent<TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
|
|
30
|
+
ErrorRouteComponent: infer T;
|
|
31
|
+
} ? T : () => unknown;
|
|
32
|
+
export type RegisteredPendingRouteComponent<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = RegisterPendingRouteComponent<TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
|
|
33
|
+
PendingRouteComponent: infer T;
|
|
34
|
+
} ? T : () => unknown;
|
|
35
|
+
export type RegisteredRouteProps<TLoader = unknown, TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = RegisterRouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
|
|
36
|
+
RouteProps: infer T;
|
|
37
|
+
} ? T : {};
|
|
38
|
+
export type RegisteredErrorRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = RegisterRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
|
|
39
|
+
ErrorRouteProps: infer T;
|
|
40
|
+
} ? T : {};
|
|
41
|
+
export type RegisteredPendingRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = RegisterRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
|
|
42
|
+
PendingRouteProps: infer T;
|
|
43
|
+
} ? T : {};
|
|
44
|
+
export type PreloadableObj = {
|
|
45
|
+
preload?: () => Promise<void>;
|
|
46
|
+
};
|
|
47
|
+
export type RoutePathOptions<TCustomId, TPath> = {
|
|
48
|
+
path: TPath;
|
|
49
|
+
} | {
|
|
50
|
+
id: TCustomId;
|
|
51
|
+
};
|
|
52
|
+
export type RoutePathOptionsIntersection<TCustomId, TPath> = UnionToIntersection<RoutePathOptions<TCustomId, TPath>>;
|
|
53
|
+
export type MetaOptions = keyof PickRequired<RouteMeta> extends never ? {
|
|
54
|
+
meta?: RouteMeta;
|
|
55
|
+
} : {
|
|
56
|
+
meta: RouteMeta;
|
|
57
|
+
};
|
|
58
|
+
export type AnyRouteProps = RegisteredRouteProps<any, any, any, any, any>;
|
|
59
|
+
export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoader = unknown, TParentSearchSchema extends AnySearchSchema = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = TSearchSchema, TParams extends AnyPathParams = AnyPathParams, TAllParams extends AnyPathParams = TParams, TParentContext extends AnyContext = AnyContext, TAllParentContext extends AnyContext = AnyContext, TRouteContext extends RouteContext = RouteContext, TAllContext extends AnyContext = AnyContext> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TLoader, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext> & UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
|
|
60
|
+
export type ParamsFallback<TPath extends string, TParams> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams;
|
|
61
|
+
export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoader = unknown, TParentSearchSchema extends AnySearchSchema = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = TSearchSchema, TParams extends AnyPathParams = {}, TAllParams = ParamsFallback<TPath, TParams>, TParentContext extends AnyContext = AnyContext, TAllParentContext extends AnyContext = AnyContext, TRouteContext extends RouteContext = RouteContext, TAllContext extends AnyContext = AnyContext> = RoutePathOptions<TCustomId, TPath> & {
|
|
62
|
+
getParentRoute: () => TParentRoute;
|
|
63
|
+
validateSearch?: SearchSchemaValidator<TSearchSchema>;
|
|
64
|
+
loader?: LoaderFn<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, NoInfer<TRouteContext>, TAllContext>;
|
|
65
|
+
} & (keyof PickRequired<RouteContext> extends never ? {
|
|
66
|
+
beforeLoad?: BeforeLoadFn<TParentRoute, TAllParams, TSearchSchema, TFullSearchSchema, TParentContext, TAllParentContext, TRouteContext>;
|
|
67
|
+
} : {
|
|
68
|
+
beforeLoad: BeforeLoadFn<TParentRoute, TAllParams, TSearchSchema, TFullSearchSchema, TParentContext, TAllParentContext, TRouteContext>;
|
|
69
|
+
}) & ([TLoader] extends [never] ? {
|
|
70
|
+
loader: 'Loaders must return a type other than never. If you are throwing a redirect() and not returning anything, return a redirect() instead.';
|
|
71
|
+
} : {}) & ({
|
|
72
|
+
parseParams?: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams extends Record<ParsePathParams<TPath>, any> ? TParams : 'parseParams must return an object';
|
|
73
|
+
stringifyParams?: (params: NoInfer<ParamsFallback<TPath, TParams>>) => Record<ParsePathParams<TPath>, string>;
|
|
74
|
+
} | {
|
|
75
|
+
stringifyParams?: never;
|
|
76
|
+
parseParams?: never;
|
|
77
|
+
});
|
|
78
|
+
type BeforeLoadFn<TParentRoute, TAllParams, TSearchSchema, TFullSearchSchema, TParentContext, TAllParentContext, TRouteContext> = (opts: {
|
|
79
|
+
params: TAllParams;
|
|
80
|
+
routeSearch: TSearchSchema;
|
|
81
|
+
search: TFullSearchSchema;
|
|
82
|
+
abortController: AbortController;
|
|
83
|
+
preload: boolean;
|
|
84
|
+
} & (TParentRoute extends undefined ? {
|
|
85
|
+
context?: TAllParentContext;
|
|
86
|
+
parentContext?: TParentContext;
|
|
87
|
+
} : {
|
|
88
|
+
context: TAllParentContext;
|
|
89
|
+
parentContext: TParentContext;
|
|
90
|
+
})) => Promise<TRouteContext> | TRouteContext | void;
|
|
91
|
+
export type UpdatableRouteOptions<TLoader, TSearchSchema extends AnySearchSchema, TFullSearchSchema extends AnySearchSchema, TAllParams extends AnyPathParams, TRouteContext extends AnyContext, TAllContext extends AnyContext> = MetaOptions & {
|
|
92
|
+
key?: null | false | GetKeyFn<TFullSearchSchema, TAllParams>;
|
|
93
|
+
caseSensitive?: boolean;
|
|
94
|
+
wrapInSuspense?: boolean;
|
|
95
|
+
component?: RegisteredRouteComponent<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
|
|
96
|
+
errorComponent?: RegisteredErrorRouteComponent<TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
|
|
97
|
+
pendingComponent?: RegisteredPendingRouteComponent<TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
|
|
98
|
+
preSearchFilters?: SearchFilter<TFullSearchSchema>[];
|
|
99
|
+
postSearchFilters?: SearchFilter<TFullSearchSchema>[];
|
|
100
|
+
preloadMaxAge?: number;
|
|
101
|
+
maxAge?: number;
|
|
102
|
+
gcMaxAge?: number;
|
|
103
|
+
onError?: (err: any) => void;
|
|
104
|
+
onEnter?: (match: AnyRouteMatch) => void;
|
|
105
|
+
onTransition?: (match: AnyRouteMatch) => void;
|
|
106
|
+
onLeave?: (match: AnyRouteMatch) => void;
|
|
107
|
+
reloadOnWindowFocus?: boolean;
|
|
108
|
+
};
|
|
109
|
+
export type ParseParamsOption<TPath extends string, TParams> = ParseParamsFn<TPath, TParams>;
|
|
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';
|
|
111
|
+
export type ParseParamsObj<TPath extends string, TParams> = {
|
|
112
|
+
parse?: ParseParamsFn<TPath, TParams>;
|
|
113
|
+
};
|
|
114
|
+
export type SearchSchemaValidator<TReturn> = SearchSchemaValidatorObj<TReturn> | SearchSchemaValidatorFn<TReturn>;
|
|
115
|
+
export type SearchSchemaValidatorObj<TReturn> = {
|
|
116
|
+
parse?: SearchSchemaValidatorFn<TReturn>;
|
|
117
|
+
};
|
|
118
|
+
export type SearchSchemaValidatorFn<TReturn> = (searchObj: Record<string, unknown>) => TReturn;
|
|
119
|
+
export type DefinedPathParamWarning = 'Path params cannot be redefined by child routes!';
|
|
120
|
+
export type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
|
|
121
|
+
[Key in keyof TParentParams]?: DefinedPathParamWarning;
|
|
122
|
+
};
|
|
123
|
+
export type LoaderFn<TLoader = unknown, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = {}, TAllParams = {}, TContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = (match: LoaderContext<TSearchSchema, TFullSearchSchema, TAllParams, TContext, TAllContext> & {
|
|
124
|
+
parentMatchPromise?: Promise<void>;
|
|
125
|
+
}) => Promise<TLoader> | TLoader;
|
|
126
|
+
export type GetKeyFn<TFullSearchSchema extends AnySearchSchema = {}, TAllParams = {}> = (loaderContext: {
|
|
127
|
+
params: TAllParams;
|
|
128
|
+
search: TFullSearchSchema;
|
|
129
|
+
}) => any;
|
|
130
|
+
export interface LoaderContext<TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = {}, TAllParams = {}, TContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
131
|
+
params: TAllParams;
|
|
132
|
+
routeSearch: TSearchSchema;
|
|
133
|
+
search: TFullSearchSchema;
|
|
134
|
+
abortController: AbortController;
|
|
135
|
+
preload: boolean;
|
|
136
|
+
routeContext: TContext;
|
|
137
|
+
context: TAllContext;
|
|
138
|
+
}
|
|
139
|
+
export type UnloaderFn<TPath extends string> = (routeMatch: RouteMatch<any, Route>) => void;
|
|
140
|
+
export type SearchFilter<T, U = T> = (prev: T) => U;
|
|
141
|
+
export type ResolveId<TParentRoute, TCustomId extends string, TPath extends string> = TParentRoute extends {
|
|
142
|
+
id: infer TParentId extends string;
|
|
143
|
+
} ? RoutePrefix<TParentId, string extends TCustomId ? TPath : TCustomId> : RootRouteId;
|
|
144
|
+
export type InferFullSearchSchema<TRoute> = TRoute extends {
|
|
145
|
+
isRoot: true;
|
|
146
|
+
types: {
|
|
147
|
+
searchSchema: infer TSearchSchema;
|
|
148
|
+
};
|
|
149
|
+
} ? TSearchSchema : TRoute extends {
|
|
150
|
+
types: {
|
|
151
|
+
fullSearchSchema: infer TFullSearchSchema;
|
|
152
|
+
};
|
|
153
|
+
} ? TFullSearchSchema : {};
|
|
154
|
+
export type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = InferFullSearchSchema<TParentRoute> & TSearchSchema;
|
|
155
|
+
export interface AnyRoute extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
156
|
+
}
|
|
157
|
+
export type MergeFromFromParent<T, U> = IsAny<T, U, T & U>;
|
|
158
|
+
export type UseLoaderResult<T> = T;
|
|
159
|
+
export type StreamedPromise<T> = {
|
|
160
|
+
promise: Promise<T>;
|
|
161
|
+
status: 'resolved' | 'pending';
|
|
162
|
+
data: T;
|
|
163
|
+
resolve: (value: T) => void;
|
|
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> & {}>;
|
|
166
|
+
export type RouteConstraints = {
|
|
167
|
+
TParentRoute: AnyRoute;
|
|
168
|
+
TPath: string;
|
|
169
|
+
TFullPath: string;
|
|
170
|
+
TCustomId: string;
|
|
171
|
+
TId: string;
|
|
172
|
+
TSearchSchema: AnySearchSchema;
|
|
173
|
+
TFullSearchSchema: AnySearchSchema;
|
|
174
|
+
TParams: Record<string, any>;
|
|
175
|
+
TAllParams: Record<string, any>;
|
|
176
|
+
TParentContext: AnyContext;
|
|
177
|
+
TAllParentContext: AnyContext;
|
|
178
|
+
TRouteContext: RouteContext;
|
|
179
|
+
TAllContext: AnyContext;
|
|
180
|
+
TRouterContext: AnyContext;
|
|
181
|
+
TChildren: unknown;
|
|
182
|
+
TRouteTree: AnyRoute;
|
|
183
|
+
};
|
|
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> {
|
|
185
|
+
types: {
|
|
186
|
+
parentRoute: TParentRoute;
|
|
187
|
+
path: TPath;
|
|
188
|
+
to: TrimPathRight<TFullPath>;
|
|
189
|
+
fullPath: TFullPath;
|
|
190
|
+
customId: TCustomId;
|
|
191
|
+
id: TId;
|
|
192
|
+
loader: TLoader;
|
|
193
|
+
searchSchema: TSearchSchema;
|
|
194
|
+
fullSearchSchema: TFullSearchSchema;
|
|
195
|
+
params: TParams;
|
|
196
|
+
allParams: TAllParams;
|
|
197
|
+
parentContext: TParentContext;
|
|
198
|
+
allParentContext: TAllParentContext;
|
|
199
|
+
routeContext: TRouteContext;
|
|
200
|
+
context: TAllContext;
|
|
201
|
+
children: TChildren;
|
|
202
|
+
routeTree: TRouteTree;
|
|
203
|
+
routerContext: TRouterContext;
|
|
204
|
+
};
|
|
205
|
+
isRoot: TParentRoute extends Route<any> ? true : false;
|
|
206
|
+
options: RouteOptions<TParentRoute, TCustomId, TPath, TLoader, InferFullSearchSchema<TParentRoute>, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext>;
|
|
207
|
+
parentRoute: TParentRoute;
|
|
208
|
+
id: TId;
|
|
209
|
+
path: TPath;
|
|
210
|
+
fullPath: TFullPath;
|
|
211
|
+
to: TrimPathRight<TFullPath>;
|
|
212
|
+
children?: TChildren;
|
|
213
|
+
originalIndex?: number;
|
|
214
|
+
router?: AnyRouter;
|
|
215
|
+
rank: number;
|
|
216
|
+
constructor(options: RouteOptions<TParentRoute, TCustomId, TPath, TLoader, InferFullSearchSchema<TParentRoute>, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext> & UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>);
|
|
217
|
+
init: (opts: {
|
|
218
|
+
originalIndex: number;
|
|
219
|
+
router: AnyRouter;
|
|
220
|
+
}) => void;
|
|
221
|
+
addChildren: <TNewChildren extends AnyRoute[]>(children: TNewChildren) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext, TRouterContext, TNewChildren, TRouteTree>;
|
|
222
|
+
update: (options: UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>) => this;
|
|
223
|
+
static __onInit: (route: any) => void;
|
|
224
|
+
}
|
|
225
|
+
export type AnyRootRoute = RootRoute<any, any, any, any>;
|
|
226
|
+
export declare class RouterContext<TRouterContext extends {}> {
|
|
227
|
+
constructor();
|
|
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>;
|
|
229
|
+
}
|
|
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'>);
|
|
232
|
+
}
|
|
233
|
+
export type ResolveFullPath<TParentRoute extends AnyRoute, TPath extends string, TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>> = TPrefixed extends RootRouteId ? '/' : TPrefixed;
|
|
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;
|
|
235
|
+
export type TrimPath<T extends string> = '' extends T ? '' : TrimPathRight<TrimPathLeft<T>>;
|
|
236
|
+
export type TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}` ? TrimPathLeft<U> : T extends `/${infer U}` ? TrimPathLeft<U> : T;
|
|
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>;
|
|
251
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AnyRoute, Route } from './route';
|
|
2
|
+
import { UnionToIntersection } from './utils';
|
|
3
|
+
export type ParseRoute<TRouteTree extends AnyRoute> = TRouteTree | ParseRouteChildren<TRouteTree>;
|
|
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
|
+
[TId in TChildren[number]['id'] as string]: ParseRoute<TChildren[number]>;
|
|
6
|
+
}[string] : never : never;
|
|
7
|
+
export type RoutesById<TRouteTree extends AnyRoute> = {
|
|
8
|
+
[K in ParseRoute<TRouteTree> as K['id']]: K;
|
|
9
|
+
};
|
|
10
|
+
export type RouteById<TRouteTree extends AnyRoute, TId> = Extract<ParseRoute<TRouteTree>, {
|
|
11
|
+
id: TId;
|
|
12
|
+
}>;
|
|
13
|
+
export type RouteIds<TRouteTree extends AnyRoute> = ParseRoute<TRouteTree>['id'];
|
|
14
|
+
export type RoutesByPath<TRouteTree extends AnyRoute> = {
|
|
15
|
+
[K in ParseRoute<TRouteTree> as K['fullPath']]: K;
|
|
16
|
+
};
|
|
17
|
+
export type RouteByPath<TRouteTree extends AnyRoute, TPath> = Extract<ParseRoute<TRouteTree>, {
|
|
18
|
+
fullPath: TPath;
|
|
19
|
+
}>;
|
|
20
|
+
export type RoutePaths<TRouteTree extends AnyRoute> = ParseRoute<TRouteTree>['fullPath'] | '/';
|
|
21
|
+
export type FullSearchSchema<TRouteTree extends AnyRoute> = UnionToIntersection<ParseRoute<TRouteTree>['types']['fullSearchSchema']> & {};
|
|
22
|
+
export type AllParams<TRouteTree extends AnyRoute> = UnionToIntersection<ParseRoute<TRouteTree>['types']['allParams']>;
|