@tanstack/router-core 0.0.1-beta.2 → 0.0.1-beta.200

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.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/build/cjs/defer.js +39 -0
  3. package/build/cjs/defer.js.map +1 -0
  4. package/build/cjs/fileRoute.js +29 -0
  5. package/build/cjs/fileRoute.js.map +1 -0
  6. package/build/cjs/index.js +89 -0
  7. package/build/cjs/{packages/router-core/src/index.js.map → index.js.map} +1 -1
  8. package/build/cjs/{packages/router-core/src/path.js → path.js} +45 -56
  9. package/build/cjs/path.js.map +1 -0
  10. package/build/cjs/{packages/router-core/src/qss.js → qss.js} +10 -15
  11. package/build/cjs/qss.js.map +1 -0
  12. package/build/cjs/route.js +114 -0
  13. package/build/cjs/route.js.map +1 -0
  14. package/build/cjs/router.js +1277 -0
  15. package/build/cjs/router.js.map +1 -0
  16. package/build/cjs/scroll-restoration.js +139 -0
  17. package/build/cjs/scroll-restoration.js.map +1 -0
  18. package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +32 -19
  19. package/build/cjs/searchParams.js.map +1 -0
  20. package/build/cjs/utils.js +132 -0
  21. package/build/cjs/utils.js.map +1 -0
  22. package/build/esm/index.js +1565 -2106
  23. package/build/esm/index.js.map +1 -1
  24. package/build/stats-html.html +59 -49
  25. package/build/stats-react.json +219 -241
  26. package/build/types/defer.d.ts +19 -0
  27. package/build/types/fileRoute.d.ts +35 -0
  28. package/build/types/index.d.ts +13 -611
  29. package/build/types/link.d.ts +96 -0
  30. package/build/types/path.d.ts +16 -0
  31. package/build/types/qss.d.ts +2 -0
  32. package/build/types/route.d.ts +261 -0
  33. package/build/types/routeInfo.d.ts +22 -0
  34. package/build/types/router.d.ts +265 -0
  35. package/build/types/scroll-restoration.d.ts +6 -0
  36. package/build/types/searchParams.d.ts +5 -0
  37. package/build/types/utils.d.ts +51 -0
  38. package/build/umd/index.development.js +1917 -2070
  39. package/build/umd/index.development.js.map +1 -1
  40. package/build/umd/index.production.js +23 -2
  41. package/build/umd/index.production.js.map +1 -1
  42. package/package.json +13 -7
  43. package/src/defer.ts +55 -0
  44. package/src/fileRoute.ts +156 -0
  45. package/src/index.ts +5 -11
  46. package/src/link.ts +149 -123
  47. package/src/path.ts +37 -17
  48. package/src/qss.ts +1 -1
  49. package/src/route.ts +861 -231
  50. package/src/routeInfo.ts +47 -205
  51. package/src/router.ts +1818 -952
  52. package/src/scroll-restoration.ts +179 -0
  53. package/src/searchParams.ts +31 -9
  54. package/src/utils.ts +106 -43
  55. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
  56. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  57. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
  58. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
  59. package/build/cjs/node_modules/history/index.js +0 -815
  60. package/build/cjs/node_modules/history/index.js.map +0 -1
  61. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
  62. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
  63. package/build/cjs/packages/router-core/src/index.js +0 -58
  64. package/build/cjs/packages/router-core/src/path.js.map +0 -1
  65. package/build/cjs/packages/router-core/src/qss.js.map +0 -1
  66. package/build/cjs/packages/router-core/src/route.js +0 -161
  67. package/build/cjs/packages/router-core/src/route.js.map +0 -1
  68. package/build/cjs/packages/router-core/src/routeConfig.js +0 -69
  69. package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
  70. package/build/cjs/packages/router-core/src/routeMatch.js +0 -266
  71. package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
  72. package/build/cjs/packages/router-core/src/router.js +0 -789
  73. package/build/cjs/packages/router-core/src/router.js.map +0 -1
  74. package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
  75. package/build/cjs/packages/router-core/src/utils.js +0 -118
  76. package/build/cjs/packages/router-core/src/utils.js.map +0 -1
  77. package/src/frameworks.ts +0 -12
  78. package/src/routeConfig.ts +0 -495
  79. package/src/routeMatch.ts +0 -374
@@ -0,0 +1,96 @@
1
+ import { Trim } from './fileRoute';
2
+ import { AnyRoute } from './route';
3
+ import { AllParams, FullSearchSchema, RouteByPath, RouteIds, RoutePaths } from './routeInfo';
4
+ import { LocationState, ParsedLocation, RegisteredRouter } 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 = RegisteredRouter['routeTree'], 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 = RegisteredRouter['routeTree'], 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 = RegisteredRouter['routeTree'], TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''> = ToSubOptions<TRouteTree, TMaskFrom, TMaskTo> & {
48
+ unmaskOnReload?: boolean;
49
+ };
50
+ export type ToSubOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], 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, TTo, TResolved> & PathParamOptions<TRouteTree, TFrom, TResolved>;
56
+ export type SearchParamOptions<TRouteTree extends AnyRoute, TFrom, TTo, TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>, TFromSearchEnsured = '/' extends TFrom ? FullSearchSchema<TRouteTree> : Expand<UnionToIntersection<PickRequired<RouteByPath<TRouteTree, TFrom>['types']['fullSearchSchema']>>>, TFromSearchOptional = Omit<AllParams<TRouteTree>, keyof TFromSearchEnsured>, TFromSearch = Expand<TFromSearchEnsured & TFromSearchOptional>, TToSearch = '' extends TTo ? FullSearchSchema<TRouteTree> : Expand<RouteByPath<TRouteTree, TResolved>['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 = RegisteredRouter['routeTree'], 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,2 @@
1
+ export declare function encode(obj: any, pfx?: string): string;
2
+ export declare function decode(str: any): {};
@@ -0,0 +1,261 @@
1
+ import { RoutePaths } from './routeInfo';
2
+ import { AnyRouter, AnyRouteMatch } from './router';
3
+ import { DeepMerge, DeepMergeAll, 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 Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> {
15
+ }
16
+ export interface RegisterErrorRouteComponent<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> {
17
+ }
18
+ export interface RegisterPendingRouteComponent<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> {
19
+ }
20
+ export interface RegisterRouteProps<TLoader = unknown, TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> {
21
+ }
22
+ export interface RegisterErrorRouteProps<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> {
23
+ }
24
+ export interface RegisterPendingRouteProps<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> {
25
+ }
26
+ export type RegisteredRouteComponent<TLoader = unknown, TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> = RegisterRouteComponent<TLoader, TFullSearchSchema, TAllParams, TAllContext> extends {
27
+ RouteComponent: infer T;
28
+ } ? T : () => unknown;
29
+ export type RegisteredErrorRouteComponent<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> = RegisterErrorRouteComponent<TFullSearchSchema, TAllParams, TAllContext> extends {
30
+ ErrorRouteComponent: infer T;
31
+ } ? T : () => unknown;
32
+ export type RegisteredPendingRouteComponent<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> = RegisterPendingRouteComponent<TFullSearchSchema, TAllParams, TAllContext> extends {
33
+ PendingRouteComponent: infer T;
34
+ } ? T : () => unknown;
35
+ export type RegisteredRouteProps<TLoader = unknown, TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> = RegisterRouteProps<TLoader, TFullSearchSchema, TAllParams, TAllContext> extends {
36
+ RouteProps: infer T;
37
+ } ? T : {};
38
+ export type RegisteredErrorRouteProps<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> = RegisterRouteProps<TFullSearchSchema, TAllParams, TAllContext> extends {
39
+ ErrorRouteProps: infer T;
40
+ } ? T : {};
41
+ export type RegisteredPendingRouteProps<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> = RegisterRouteProps<TFullSearchSchema, TAllParams, 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>;
59
+ export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = AnyPathParams, TAllParams extends AnyPathParams = TParams, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext> & UpdatableRouteOptions<TLoader, TFullSearchSchema, TAllParams, 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, TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = {}, TAllParams = ParamsFallback<TPath, TParams>, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext> = RoutePathOptions<TCustomId, TPath> & {
62
+ getParentRoute: () => TParentRoute;
63
+ validateSearch?: SearchSchemaValidator<TSearchSchema>;
64
+ loaderContext?: (opts: {
65
+ search: TFullSearchSchema;
66
+ }) => TLoaderContext;
67
+ } & (keyof PickRequired<RouteContext> extends never ? {
68
+ beforeLoad?: BeforeLoadFn<TParentRoute, TAllParams, NoInfer<TLoaderContext>, TRouteContext>;
69
+ } : {
70
+ beforeLoad: BeforeLoadFn<TParentRoute, TAllParams, NoInfer<TLoaderContext>, TRouteContext>;
71
+ }) & {
72
+ loader?: LoaderFn<TLoader, TAllParams, NoInfer<TLoaderContext>, NoInfer<TAllContext>, NoInfer<TRouteContext>>;
73
+ } & ([TLoader] extends [never] ? {
74
+ loader: 'Loaders must return a type other than never. If you are throwing a redirect() and not returning anything, return a redirect() instead.';
75
+ } : {}) & ({
76
+ parseParams?: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams extends Record<ParsePathParams<TPath>, any> ? TParams : 'parseParams must return an object';
77
+ stringifyParams?: (params: NoInfer<ParamsFallback<TPath, TParams>>) => Record<ParsePathParams<TPath>, string>;
78
+ } | {
79
+ stringifyParams?: never;
80
+ parseParams?: never;
81
+ });
82
+ type BeforeLoadFn<TParentRoute extends AnyRoute, TAllParams, TLoaderContext, TRouteContext> = (opts: {
83
+ abortController: AbortController;
84
+ preload: boolean;
85
+ params: TAllParams;
86
+ context: Expand<TParentRoute['types']['context'] & TLoaderContext>;
87
+ }) => Promise<TRouteContext> | TRouteContext | void;
88
+ export type UpdatableRouteOptions<TLoader, TFullSearchSchema extends Record<string, any>, TAllParams extends AnyPathParams, TAllContext extends Record<string, any>> = MetaOptions & {
89
+ caseSensitive?: boolean;
90
+ wrapInSuspense?: boolean;
91
+ component?: RegisteredRouteComponent<TLoader, TFullSearchSchema, TAllParams, TAllContext>;
92
+ errorComponent?: RegisteredErrorRouteComponent<TFullSearchSchema, TAllParams, TAllContext>;
93
+ pendingComponent?: RegisteredPendingRouteComponent<TFullSearchSchema, TAllParams, TAllContext>;
94
+ preSearchFilters?: SearchFilter<TFullSearchSchema>[];
95
+ postSearchFilters?: SearchFilter<TFullSearchSchema>[];
96
+ preloadMaxAge?: number;
97
+ maxAge?: number;
98
+ gcMaxAge?: number;
99
+ onError?: (err: any) => void;
100
+ onEnter?: (match: AnyRouteMatch) => void;
101
+ onTransition?: (match: AnyRouteMatch) => void;
102
+ onLeave?: (match: AnyRouteMatch) => void;
103
+ reloadOnWindowFocus?: boolean;
104
+ };
105
+ export type ParseParamsOption<TPath extends string, TParams> = ParseParamsFn<TPath, TParams>;
106
+ 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';
107
+ export type ParseParamsObj<TPath extends string, TParams> = {
108
+ parse?: ParseParamsFn<TPath, TParams>;
109
+ };
110
+ export type SearchSchemaValidator<TReturn> = SearchSchemaValidatorObj<TReturn> | SearchSchemaValidatorFn<TReturn>;
111
+ export type SearchSchemaValidatorObj<TReturn> = {
112
+ parse?: SearchSchemaValidatorFn<TReturn>;
113
+ };
114
+ export type SearchSchemaValidatorFn<TReturn> = (searchObj: Record<string, unknown>) => TReturn;
115
+ export type DefinedPathParamWarning = 'Path params cannot be redefined by child routes!';
116
+ export type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
117
+ [Key in keyof TParentParams]?: DefinedPathParamWarning;
118
+ };
119
+ export type LoaderFn<TLoader = unknown, TAllParams = {}, TLoaderContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext, TRouteContext extends Record<string, any> = AnyContext> = (match: LoaderContext<TAllParams, TLoaderContext, TAllContext, TRouteContext> & {
120
+ parentMatchPromise?: Promise<void>;
121
+ }) => Promise<TLoader> | TLoader;
122
+ export interface LoaderContext<TAllParams = {}, TLoaderContext = {}, TAllContext extends Record<string, any> = AnyContext, TRouteContext extends Record<string, any> = AnyContext> {
123
+ abortController: AbortController;
124
+ preload: boolean;
125
+ params: TAllParams;
126
+ context: Expand<DeepMergeAll<[TAllContext, TLoaderContext, TRouteContext]>>;
127
+ }
128
+ export type SearchFilter<T, U = T> = (prev: T) => U;
129
+ export type ResolveId<TParentRoute, TCustomId extends string, TPath extends string> = TParentRoute extends {
130
+ id: infer TParentId extends string;
131
+ } ? RoutePrefix<TParentId, string extends TCustomId ? TPath : TCustomId> : RootRouteId;
132
+ export type InferFullSearchSchema<TRoute> = TRoute extends {
133
+ types: {
134
+ fullSearchSchema: infer TFullSearchSchema;
135
+ };
136
+ } ? TFullSearchSchema : {};
137
+ export type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = Expand<DeepMerge<InferFullSearchSchema<TParentRoute>, TSearchSchema>>;
138
+ export interface AnyRoute extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
139
+ }
140
+ export type MergeFromFromParent<T, U> = IsAny<T, U, T & U>;
141
+ export type UseLoaderResult<T> = T;
142
+ export type StreamedPromise<T> = {
143
+ promise: Promise<T>;
144
+ status: 'resolved' | 'pending';
145
+ data: T;
146
+ resolve: (value: T) => void;
147
+ };
148
+ export type ResolveAllParams<TParentRoute extends AnyRoute, TParams extends AnyPathParams> = Record<never, string> extends TParentRoute['types']['allParams'] ? TParams : Expand<UnionToIntersection<TParentRoute['types']['allParams'] & TParams> & {}>;
149
+ export type RouteConstraints = {
150
+ TParentRoute: AnyRoute;
151
+ TPath: string;
152
+ TFullPath: string;
153
+ TCustomId: string;
154
+ TId: string;
155
+ TLoaderContext: Record<string, any>;
156
+ TSearchSchema: AnySearchSchema;
157
+ TFullSearchSchema: AnySearchSchema;
158
+ TParams: Record<string, any>;
159
+ TAllParams: Record<string, any>;
160
+ TParentContext: AnyContext;
161
+ TRouteContext: RouteContext;
162
+ TAllContext: AnyContext;
163
+ TRouterContext: AnyContext;
164
+ TChildren: unknown;
165
+ TRouteTree: AnyRoute;
166
+ };
167
+ 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>, TLoaderContext extends RouteConstraints['TLoaderContext'] = {}, 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>, TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext, TAllContext extends RouteConstraints['TAllContext'] = Expand<DeepMergeAll<[
168
+ IsAny<TParentRoute['types']['context'], {}>,
169
+ TLoaderContext,
170
+ TRouteContext
171
+ ]>>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
172
+ types: {
173
+ parentRoute: TParentRoute;
174
+ path: TPath;
175
+ to: TrimPathRight<TFullPath>;
176
+ fullPath: TFullPath;
177
+ customId: TCustomId;
178
+ id: TId;
179
+ loader: TLoader;
180
+ searchSchema: TSearchSchema;
181
+ fullSearchSchema: TFullSearchSchema;
182
+ params: TParams;
183
+ allParams: TAllParams;
184
+ routeContext: TRouteContext;
185
+ context: TAllContext;
186
+ children: TChildren;
187
+ routeTree: TRouteTree;
188
+ routerContext: TRouterContext;
189
+ };
190
+ isRoot: TParentRoute extends Route<any> ? true : false;
191
+ options: RouteOptions<TParentRoute, TCustomId, TPath, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext>;
192
+ parentRoute: TParentRoute;
193
+ id: TId;
194
+ path: TPath;
195
+ fullPath: TFullPath;
196
+ to: TrimPathRight<TFullPath>;
197
+ children?: TChildren;
198
+ originalIndex?: number;
199
+ router?: AnyRouter;
200
+ rank: number;
201
+ constructor(options: RouteOptions<TParentRoute, TCustomId, TPath, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext> & UpdatableRouteOptions<TLoader, TFullSearchSchema, TAllParams, TAllContext>);
202
+ init: (opts: {
203
+ originalIndex: number;
204
+ router: AnyRouter;
205
+ }) => void;
206
+ addChildren: <TNewChildren extends AnyRoute[]>(children: TNewChildren) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TRouterContext, TNewChildren, TRouteTree>;
207
+ update: (options: UpdatableRouteOptions<TLoader, TFullSearchSchema, TAllParams, TAllContext>) => this;
208
+ static __onInit: (route: any) => void;
209
+ }
210
+ export type AnyRootRoute = RootRoute<any, any, any, any>;
211
+ export declare class RouterContext<TRouterContext extends {}> {
212
+ constructor();
213
+ createRootRoute: <TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext>(options?: Omit<RouteOptions<AnyRoute, "__root__", "", TLoaderContext, TLoader, TSearchSchema, TSearchSchema, {}, {}, TRouteContext, DeepMerge<TRouterContext, DeepMerge<TLoaderContext, DeepMerge<TRouteContext, {}>>>>, "id" | "path" | "getParentRoute" | "stringifyParams" | "parseParams" | "caseSensitive"> | undefined) => RootRoute<TLoaderContext, TLoader, TSearchSchema, TRouteContext, TRouterContext>;
214
+ }
215
+ export declare class RootRoute<TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext, TRouterContext extends {} = {}> extends Route<any, // TParentRoute
216
+ '/', // TPath
217
+ '/', // TFullPath
218
+ string, // TCustomId
219
+ RootRouteId, // TId
220
+ TLoaderContext, // TLoaderContext
221
+ TLoader, // TLoader
222
+ TSearchSchema, // TSearchSchema
223
+ TSearchSchema, // TFullSearchSchema
224
+ {}, // TParams
225
+ {}, // TAllParams
226
+ TRouteContext, // TRouteContext
227
+ DeepMergeAll<[TRouterContext, TLoaderContext, TRouteContext]>, // TAllContext
228
+ TRouterContext, // TRouterContext
229
+ any, // TChildren
230
+ any> {
231
+ constructor(options?: Omit<RouteOptions<AnyRoute, // TParentRoute
232
+ RootRouteId, // TCustomId
233
+ '', // TPath
234
+ TLoaderContext, // TLoaderContext
235
+ TLoader, // TLoader
236
+ TSearchSchema, // TSearchSchema
237
+ TSearchSchema, // TFullSearchSchema
238
+ {}, // TParams
239
+ {}, // TAllParams
240
+ TRouteContext, // TRouteContext
241
+ DeepMergeAll<[TRouterContext, TLoaderContext, TRouteContext]>>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams'>);
242
+ }
243
+ export type ResolveFullPath<TParentRoute extends AnyRoute, TPath extends string, TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>> = TPrefixed extends RootRouteId ? '/' : TPrefixed;
244
+ 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;
245
+ export type TrimPath<T extends string> = '' extends T ? '' : TrimPathRight<TrimPathLeft<T>>;
246
+ export type TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}` ? TrimPathLeft<U> : T extends `/${infer U}` ? TrimPathLeft<U> : T;
247
+ export type TrimPathRight<T extends string> = T extends '/' ? '/' : T extends `${infer U}/` ? TrimPathRight<U> : T;
248
+ export type RouteMask<TRouteTree extends AnyRoute> = {
249
+ routeTree: TRouteTree;
250
+ from: RoutePaths<TRouteTree>;
251
+ to?: any;
252
+ params?: any;
253
+ search?: any;
254
+ hash?: any;
255
+ state?: any;
256
+ unmaskOnReload?: boolean;
257
+ };
258
+ export declare function createRouteMask<TRouteTree extends AnyRoute, TFrom extends RoutePaths<TRouteTree>, TTo extends string>(opts: {
259
+ routeTree: TRouteTree;
260
+ } & ToSubOptions<TRouteTree, TFrom, TTo>): RouteMask<TRouteTree>;
261
+ export {};
@@ -0,0 +1,22 @@
1
+ import { AnyRoute, Route } from './route';
2
+ import { Expand, 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, 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> = Partial<Expand<UnionToIntersection<ParseRoute<TRouteTree>['types']['fullSearchSchema']>>>;
22
+ export type AllParams<TRouteTree extends AnyRoute> = Expand<UnionToIntersection<ParseRoute<TRouteTree>['types']['allParams']>>;