@tanstack/react-router 0.0.1-beta.204 → 0.0.1-beta.205

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 (73) hide show
  1. package/build/cjs/RouterProvider.js +961 -0
  2. package/build/cjs/RouterProvider.js.map +1 -0
  3. package/build/cjs/fileRoute.js +29 -0
  4. package/build/cjs/fileRoute.js.map +1 -0
  5. package/build/cjs/index.js +69 -21
  6. package/build/cjs/index.js.map +1 -1
  7. package/build/cjs/path.js +211 -0
  8. package/build/cjs/path.js.map +1 -0
  9. package/build/cjs/qss.js +65 -0
  10. package/build/cjs/qss.js.map +1 -0
  11. package/build/cjs/react.js +148 -190
  12. package/build/cjs/react.js.map +1 -1
  13. package/build/cjs/redirects.js +27 -0
  14. package/build/cjs/redirects.js.map +1 -0
  15. package/build/cjs/route.js +136 -0
  16. package/build/cjs/route.js.map +1 -0
  17. package/build/cjs/router.js +203 -0
  18. package/build/cjs/router.js.map +1 -0
  19. package/build/cjs/searchParams.js +83 -0
  20. package/build/cjs/searchParams.js.map +1 -0
  21. package/build/cjs/utils.js +196 -0
  22. package/build/cjs/utils.js.map +1 -0
  23. package/build/esm/index.js +1799 -211
  24. package/build/esm/index.js.map +1 -1
  25. package/build/stats-html.html +1 -1
  26. package/build/stats-react.json +385 -164
  27. package/build/types/RouteMatch.d.ts +23 -0
  28. package/build/types/RouterProvider.d.ts +54 -0
  29. package/build/types/awaited.d.ts +0 -8
  30. package/build/types/defer.d.ts +0 -0
  31. package/build/types/fileRoute.d.ts +17 -0
  32. package/build/types/history.d.ts +7 -0
  33. package/build/types/index.d.ts +17 -4
  34. package/build/types/link.d.ts +98 -0
  35. package/build/types/location.d.ts +14 -0
  36. package/build/types/path.d.ts +16 -0
  37. package/build/types/qss.d.ts +2 -0
  38. package/build/types/react.d.ts +23 -83
  39. package/build/types/redirects.d.ts +10 -0
  40. package/build/types/route.d.ts +222 -0
  41. package/build/types/routeInfo.d.ts +22 -0
  42. package/build/types/router.d.ts +115 -0
  43. package/build/types/scroll-restoration.d.ts +0 -3
  44. package/build/types/searchParams.d.ts +7 -0
  45. package/build/types/utils.d.ts +48 -0
  46. package/build/umd/index.development.js +1116 -1540
  47. package/build/umd/index.development.js.map +1 -1
  48. package/build/umd/index.production.js +2 -33
  49. package/build/umd/index.production.js.map +1 -1
  50. package/package.json +4 -4
  51. package/src/RouteMatch.ts +28 -0
  52. package/src/RouterProvider.tsx +1384 -0
  53. package/src/awaited.tsx +40 -40
  54. package/src/defer.ts +55 -0
  55. package/src/fileRoute.ts +143 -0
  56. package/src/history.ts +8 -0
  57. package/src/index.tsx +18 -5
  58. package/src/link.ts +347 -0
  59. package/src/location.ts +14 -0
  60. package/src/path.ts +256 -0
  61. package/src/qss.ts +53 -0
  62. package/src/react.tsx +174 -422
  63. package/src/redirects.ts +31 -0
  64. package/src/route.ts +710 -0
  65. package/src/routeInfo.ts +68 -0
  66. package/src/router.ts +373 -0
  67. package/src/scroll-restoration.tsx +205 -27
  68. package/src/searchParams.ts +78 -0
  69. package/src/utils.ts +257 -0
  70. package/build/cjs/awaited.js +0 -45
  71. package/build/cjs/awaited.js.map +0 -1
  72. package/build/cjs/scroll-restoration.js +0 -56
  73. package/build/cjs/scroll-restoration.js.map +0 -1
@@ -0,0 +1,222 @@
1
+ import { RoutePaths } from './routeInfo';
2
+ import { AnyRouter } from './router';
3
+ import { AnyRouteMatch } from './RouteMatch';
4
+ import { Expand, IsAny, NoInfer, PickRequired, UnionToIntersection, Assign } from './utils';
5
+ import { ParsePathParams, ToSubOptions } from './link';
6
+ import { ErrorRouteComponent, PendingRouteComponent, RouteComponent } from './react';
7
+ import { ParsedLocation } from './location';
8
+ export declare const rootRouteId: "__root__";
9
+ export type RootRouteId = typeof rootRouteId;
10
+ export type AnyPathParams = {};
11
+ export type AnySearchSchema = {};
12
+ export type AnyContext = {};
13
+ export interface RouteMeta {
14
+ }
15
+ export type PreloadableObj = {
16
+ preload?: () => Promise<void>;
17
+ };
18
+ export type RoutePathOptions<TCustomId, TPath> = {
19
+ path: TPath;
20
+ } | {
21
+ id: TCustomId;
22
+ };
23
+ export type RoutePathOptionsIntersection<TCustomId, TPath> = UnionToIntersection<RoutePathOptions<TCustomId, TPath>>;
24
+ export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = AnyPathParams, TAllParams extends AnyPathParams = TParams, TRouteMeta extends RouteMeta = RouteMeta, TAllMeta extends Record<string, any> = AnyContext> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteMeta, TAllMeta> & NoInfer<UpdatableRouteOptions<TFullSearchSchema, TAllParams, TAllMeta>>;
25
+ export type ParamsFallback<TPath extends string, TParams> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams;
26
+ export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = {}, TAllParams = ParamsFallback<TPath, TParams>, TRouteMeta extends RouteMeta = RouteMeta, TAllContext extends Record<string, any> = AnyContext> = RoutePathOptions<TCustomId, TPath> & {
27
+ getParentRoute: () => TParentRoute;
28
+ validateSearch?: SearchSchemaValidator<TSearchSchema>;
29
+ } & (keyof PickRequired<RouteMeta> extends never ? {
30
+ beforeLoad?: BeforeLoadFn<TFullSearchSchema, TParentRoute, TAllParams, TRouteMeta>;
31
+ } : {
32
+ beforeLoad: BeforeLoadFn<TFullSearchSchema, TParentRoute, TAllParams, TRouteMeta>;
33
+ }) & {
34
+ load?: RouteLoadFn<TAllParams, TFullSearchSchema, NoInfer<TAllContext>, NoInfer<TRouteMeta>>;
35
+ } & ({
36
+ parseParams?: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams extends Record<ParsePathParams<TPath>, any> ? TParams : 'parseParams must return an object';
37
+ stringifyParams?: (params: NoInfer<ParamsFallback<TPath, TParams>>) => Record<ParsePathParams<TPath>, string>;
38
+ } | {
39
+ stringifyParams?: never;
40
+ parseParams?: never;
41
+ });
42
+ type BeforeLoadFn<TFullSearchSchema extends Record<string, any>, TParentRoute extends AnyRoute, TAllParams, TRouteMeta> = (opts: {
43
+ search: TFullSearchSchema;
44
+ abortController: AbortController;
45
+ preload: boolean;
46
+ params: TAllParams;
47
+ meta: TParentRoute['types']['allMeta'];
48
+ location: ParsedLocation;
49
+ }) => Promise<TRouteMeta> | TRouteMeta | void;
50
+ export type UpdatableRouteOptions<TFullSearchSchema extends Record<string, any>, TAllParams extends AnyPathParams, TAllContext extends AnyContext> = {
51
+ caseSensitive?: boolean;
52
+ wrapInSuspense?: boolean;
53
+ component?: RouteComponent<TFullSearchSchema, TAllParams, TAllContext>;
54
+ errorComponent?: ErrorRouteComponent<TFullSearchSchema, TAllParams, {}>;
55
+ pendingComponent?: PendingRouteComponent<TFullSearchSchema, TAllParams, TAllContext>;
56
+ preSearchFilters?: SearchFilter<TFullSearchSchema>[];
57
+ postSearchFilters?: SearchFilter<TFullSearchSchema>[];
58
+ onError?: (err: any) => void;
59
+ onEnter?: (match: AnyRouteMatch) => void;
60
+ onTransition?: (match: AnyRouteMatch) => void;
61
+ onLeave?: (match: AnyRouteMatch) => void;
62
+ reloadOnWindowFocus?: boolean;
63
+ };
64
+ export type ParseParamsOption<TPath extends string, TParams> = ParseParamsFn<TPath, TParams>;
65
+ 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';
66
+ export type ParseParamsObj<TPath extends string, TParams> = {
67
+ parse?: ParseParamsFn<TPath, TParams>;
68
+ };
69
+ export type SearchSchemaValidator<TReturn> = SearchSchemaValidatorObj<TReturn> | SearchSchemaValidatorFn<TReturn>;
70
+ export type SearchSchemaValidatorObj<TReturn> = {
71
+ parse?: SearchSchemaValidatorFn<TReturn>;
72
+ };
73
+ export type SearchSchemaValidatorFn<TReturn> = (searchObj: Record<string, unknown>) => TReturn;
74
+ export type DefinedPathParamWarning = 'Path params cannot be redefined by child routes!';
75
+ export type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
76
+ [Key in keyof TParentParams]?: DefinedPathParamWarning;
77
+ };
78
+ export type RouteLoadFn<TAllParams = {}, TFullSearchSchema extends Record<string, any> = {}, TAllContext extends Record<string, any> = AnyContext, TRouteMeta extends Record<string, any> = AnyContext> = (match: LoadFnContext<TAllParams, TFullSearchSchema, TAllContext, TRouteMeta> & {
79
+ parentMatchPromise?: Promise<void>;
80
+ }) => any;
81
+ export interface LoadFnContext<TAllParams = {}, TFullSearchSchema extends Record<string, any> = {}, TAllContext extends Record<string, any> = AnyContext, TRouteMeta extends Record<string, any> = AnyContext> {
82
+ abortController: AbortController;
83
+ preload: boolean;
84
+ params: TAllParams;
85
+ search: TFullSearchSchema;
86
+ meta: Expand<Assign<TAllContext, TRouteMeta>>;
87
+ }
88
+ export type SearchFilter<T, U = T> = (prev: T) => U;
89
+ export type ResolveId<TParentRoute, TCustomId extends string, TPath extends string> = TParentRoute extends {
90
+ id: infer TParentId extends string;
91
+ } ? RoutePrefix<TParentId, string extends TCustomId ? TPath : TCustomId> : RootRouteId;
92
+ export type InferFullSearchSchema<TRoute> = TRoute extends {
93
+ types: {
94
+ fullSearchSchema: infer TFullSearchSchema;
95
+ };
96
+ } ? TFullSearchSchema : {};
97
+ export type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = Expand<Assign<InferFullSearchSchema<TParentRoute>, TSearchSchema>>;
98
+ export interface AnyRoute extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
99
+ }
100
+ export type MergeFromFromParent<T, U> = IsAny<T, U, T & U>;
101
+ export type StreamedPromise<T> = {
102
+ promise: Promise<T>;
103
+ status: 'resolved' | 'pending';
104
+ data: T;
105
+ resolve: (value: T) => void;
106
+ };
107
+ export type ResolveAllParams<TParentRoute extends AnyRoute, TParams extends AnyPathParams> = Record<never, string> extends TParentRoute['types']['allParams'] ? TParams : Expand<UnionToIntersection<TParentRoute['types']['allParams'] & TParams> & {}>;
108
+ export type RouteConstraints = {
109
+ TParentRoute: AnyRoute;
110
+ TPath: string;
111
+ TFullPath: string;
112
+ TCustomId: string;
113
+ TId: string;
114
+ TSearchSchema: AnySearchSchema;
115
+ TFullSearchSchema: AnySearchSchema;
116
+ TParams: Record<string, any>;
117
+ TAllParams: Record<string, any>;
118
+ TParentContext: AnyContext;
119
+ TRouteMeta: RouteMeta;
120
+ TAllContext: AnyContext;
121
+ TRouterMeta: AnyContext;
122
+ TChildren: unknown;
123
+ TRouteTree: AnyRoute;
124
+ };
125
+ 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>, 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>, TRouteMeta extends RouteConstraints['TRouteMeta'] = RouteMeta, TAllMeta extends Expand<Assign<IsAny<TParentRoute['types']['allMeta'], {}>, TRouteMeta>> = Expand<Assign<IsAny<TParentRoute['types']['allMeta'], {}>, TRouteMeta>>, TRouterMeta extends RouteConstraints['TRouterMeta'] = AnyContext, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
126
+ isRoot: TParentRoute extends Route<any> ? true : false;
127
+ options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteMeta, TAllMeta>;
128
+ test: Expand<Assign<IsAny<TParentRoute['types']['allMeta'], {}>, TRouteMeta>>;
129
+ parentRoute: TParentRoute;
130
+ id: TId;
131
+ path: TPath;
132
+ fullPath: TFullPath;
133
+ to: TrimPathRight<TFullPath>;
134
+ children?: TChildren;
135
+ originalIndex?: number;
136
+ router?: AnyRouter;
137
+ rank: number;
138
+ constructor(options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteMeta, TAllMeta>);
139
+ types: {
140
+ parentRoute: TParentRoute;
141
+ path: TPath;
142
+ to: TrimPathRight<TFullPath>;
143
+ fullPath: TFullPath;
144
+ customId: TCustomId;
145
+ id: TId;
146
+ searchSchema: TSearchSchema;
147
+ fullSearchSchema: TFullSearchSchema;
148
+ params: TParams;
149
+ allParams: TAllParams;
150
+ routeMeta: TRouteMeta;
151
+ allMeta: TAllMeta;
152
+ children: TChildren;
153
+ routeTree: TRouteTree;
154
+ routerMeta: TRouterMeta;
155
+ };
156
+ init: (opts: {
157
+ originalIndex: number;
158
+ }) => void;
159
+ addChildren: <TNewChildren extends AnyRoute[]>(children: TNewChildren) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteMeta, TAllMeta, TRouterMeta, TNewChildren, TRouteTree>;
160
+ update: (options: UpdatableRouteOptions<TFullSearchSchema, TAllParams, Expand<Assign<IsAny<TParentRoute['types']['allMeta'], {}>, TRouteMeta>>>) => this;
161
+ static __onInit: (route: any) => void;
162
+ useMatch: <TSelected = TAllMeta>(opts?: {
163
+ select?: ((search: TAllMeta) => TSelected) | undefined;
164
+ } | undefined) => TSelected;
165
+ useRouteMeta: <TSelected = TAllMeta>(opts?: {
166
+ select?: ((search: TAllMeta) => TSelected) | undefined;
167
+ } | undefined) => TSelected;
168
+ useSearch: <TSelected = TFullSearchSchema>(opts?: {
169
+ select?: ((search: TFullSearchSchema) => TSelected) | undefined;
170
+ } | undefined) => TSelected;
171
+ useParams: <TSelected = TAllParams>(opts?: {
172
+ select?: ((search: TAllParams) => TSelected) | undefined;
173
+ } | undefined) => TSelected;
174
+ }
175
+ export type AnyRootRoute = RootRoute<any, any, any>;
176
+ export declare class RouterMeta<TRouterMeta extends {}> {
177
+ constructor();
178
+ createRootRoute: <TSearchSchema extends Record<string, any> = {}, TRouteMeta extends RouteMeta = RouteMeta>(options?: Omit<RouteOptions<AnyRoute, "__root__", "", TSearchSchema, TSearchSchema, {}, {}, TRouteMeta, Assign<TRouterMeta, TRouteMeta>>, "id" | "path" | "getParentRoute" | "stringifyParams" | "parseParams" | "caseSensitive"> | undefined) => RootRoute<TSearchSchema, TRouteMeta, TRouterMeta>;
179
+ }
180
+ export declare class RootRoute<TSearchSchema extends Record<string, any> = {}, TRouteMeta extends RouteMeta = RouteMeta, TRouterMeta extends {} = {}> extends Route<any, // TParentRoute
181
+ '/', // TPath
182
+ '/', // TFullPath
183
+ string, // TCustomId
184
+ RootRouteId, // TId
185
+ TSearchSchema, // TSearchSchema
186
+ TSearchSchema, // TFullSearchSchema
187
+ {}, // TParams
188
+ {}, // TAllParams
189
+ TRouteMeta, // TRouteMeta
190
+ Expand<Assign<TRouterMeta, TRouteMeta>>, // TAllContext
191
+ TRouterMeta, // TRouterMeta
192
+ any, // TChildren
193
+ any> {
194
+ constructor(options?: Omit<RouteOptions<AnyRoute, // TParentRoute
195
+ RootRouteId, // TCustomId
196
+ '', // TPath
197
+ TSearchSchema, // TSearchSchema
198
+ TSearchSchema, // TFullSearchSchema
199
+ {}, // TParams
200
+ {}, // TAllParams
201
+ TRouteMeta, // TRouteMeta
202
+ Assign<TRouterMeta, TRouteMeta>>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams'>);
203
+ }
204
+ export type ResolveFullPath<TParentRoute extends AnyRoute, TPath extends string, TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>> = TPrefixed extends RootRouteId ? '/' : TPrefixed;
205
+ 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;
206
+ export type TrimPath<T extends string> = '' extends T ? '' : TrimPathRight<TrimPathLeft<T>>;
207
+ export type TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}` ? TrimPathLeft<U> : T extends `/${infer U}` ? TrimPathLeft<U> : T;
208
+ export type TrimPathRight<T extends string> = T extends '/' ? '/' : T extends `${infer U}/` ? TrimPathRight<U> : T;
209
+ export type RouteMask<TRouteTree extends AnyRoute> = {
210
+ routeTree: TRouteTree;
211
+ from: RoutePaths<TRouteTree>;
212
+ to?: any;
213
+ params?: any;
214
+ search?: any;
215
+ hash?: any;
216
+ state?: any;
217
+ unmaskOnReload?: boolean;
218
+ };
219
+ export declare function createRouteMask<TRouteTree extends AnyRoute, TFrom extends RoutePaths<TRouteTree>, TTo extends string>(opts: {
220
+ routeTree: TRouteTree;
221
+ } & ToSubOptions<TRouteTree, TFrom, TTo>): RouteMask<TRouteTree>;
222
+ 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, 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']>>;
@@ -0,0 +1,115 @@
1
+ import { RouterHistory } from '@tanstack/history';
2
+ import { AnySearchSchema, AnyRoute, AnyContext, AnyPathParams, RouteMask } from './route';
3
+ import { FullSearchSchema } from './routeInfo';
4
+ import { PickAsRequired, Updater, NonNullableUpdater } from './utils';
5
+ import { ErrorRouteComponent, PendingRouteComponent, RouteComponent } from './react';
6
+ import { RouteMatch } from './RouteMatch';
7
+ import { ParsedLocation } from './location';
8
+ import { LocationState } from './location';
9
+ import { SearchSerializer, SearchParser } from './searchParams';
10
+ declare global {
11
+ interface Window {
12
+ __TSR_DEHYDRATED__?: HydrationCtx;
13
+ }
14
+ }
15
+ export interface Register {
16
+ }
17
+ export type AnyRouter = Router<any, any>;
18
+ export type RegisteredRouter = Register extends {
19
+ router: infer TRouter extends AnyRouter;
20
+ } ? TRouter : AnyRouter;
21
+ export type HydrationCtx = {
22
+ router: DehydratedRouter;
23
+ payload: Record<string, any>;
24
+ };
25
+ export type RouterContextOptions<TRouteTree extends AnyRoute> = AnyContext extends TRouteTree['types']['routerMeta'] ? {
26
+ meta?: TRouteTree['types']['routerMeta'];
27
+ } : {
28
+ meta: TRouteTree['types']['routerMeta'];
29
+ };
30
+ export interface RouterOptions<TRouteTree extends AnyRoute, TDehydrated extends Record<string, any> = Record<string, any>> {
31
+ history?: RouterHistory;
32
+ stringifySearch?: SearchSerializer;
33
+ parseSearch?: SearchParser;
34
+ defaultPreload?: false | 'intent';
35
+ defaultPreloadDelay?: number;
36
+ defaultComponent?: RouteComponent<AnySearchSchema, AnyPathParams, AnyContext>;
37
+ defaultErrorComponent?: ErrorRouteComponent<AnySearchSchema, AnyPathParams, AnyContext>;
38
+ defaultPendingComponent?: PendingRouteComponent<AnySearchSchema, AnyPathParams, AnyContext>;
39
+ defaultMaxAge?: number;
40
+ defaultGcMaxAge?: number;
41
+ defaultPreloadMaxAge?: number;
42
+ caseSensitive?: boolean;
43
+ routeTree?: TRouteTree;
44
+ basepath?: string;
45
+ createRoute?: (opts: {
46
+ route: AnyRoute;
47
+ router: AnyRouter;
48
+ }) => void;
49
+ meta?: TRouteTree['types']['routerMeta'];
50
+ routeMasks?: RouteMask<TRouteTree>[];
51
+ unmaskOnReload?: boolean;
52
+ }
53
+ export interface RouterState<TRouteTree extends AnyRoute = AnyRoute> {
54
+ status: 'idle' | 'pending';
55
+ isFetching: boolean;
56
+ matches: RouteMatch<TRouteTree>[];
57
+ pendingMatches: RouteMatch<TRouteTree>[];
58
+ location: ParsedLocation<FullSearchSchema<TRouteTree>>;
59
+ resolvedLocation: ParsedLocation<FullSearchSchema<TRouteTree>>;
60
+ lastUpdated: number;
61
+ }
62
+ export type ListenerFn<TEvent extends RouterEvent> = (event: TEvent) => void;
63
+ export interface BuildNextOptions {
64
+ to?: string | number | null;
65
+ params?: true | Updater<unknown>;
66
+ search?: true | Updater<unknown>;
67
+ hash?: true | Updater<string>;
68
+ state?: true | NonNullableUpdater<LocationState>;
69
+ mask?: {
70
+ to?: string | number | null;
71
+ params?: true | Updater<unknown>;
72
+ search?: true | Updater<unknown>;
73
+ hash?: true | Updater<string>;
74
+ state?: true | NonNullableUpdater<LocationState>;
75
+ unmaskOnReload?: boolean;
76
+ };
77
+ from?: string;
78
+ }
79
+ export interface DehydratedRouterState {
80
+ dehydratedMatches: DehydratedRouteMatch[];
81
+ }
82
+ export type DehydratedRouteMatch = Pick<RouteMatch, 'fetchedAt' | 'invalid' | 'id' | 'status' | 'updatedAt'>;
83
+ export interface DehydratedRouter {
84
+ state: DehydratedRouterState;
85
+ }
86
+ export type RouterConstructorOptions<TRouteTree extends AnyRoute, TDehydrated extends Record<string, any>> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> & RouterContextOptions<TRouteTree>;
87
+ export declare const componentTypes: readonly ["component", "errorComponent", "pendingComponent"];
88
+ export type RouterEvents = {
89
+ onBeforeLoad: {
90
+ type: 'onBeforeLoad';
91
+ from: ParsedLocation;
92
+ to: ParsedLocation;
93
+ pathChanged: boolean;
94
+ };
95
+ onLoad: {
96
+ type: 'onLoad';
97
+ from: ParsedLocation;
98
+ to: ParsedLocation;
99
+ pathChanged: boolean;
100
+ };
101
+ };
102
+ export type RouterEvent = RouterEvents[keyof RouterEvents];
103
+ export type RouterListener<TRouterEvent extends RouterEvent> = {
104
+ eventType: TRouterEvent['type'];
105
+ fn: ListenerFn<TRouterEvent>;
106
+ };
107
+ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated extends Record<string, any> = Record<string, any>> {
108
+ options: PickAsRequired<RouterOptions<TRouteTree, TDehydrated>, 'stringifySearch' | 'parseSearch' | 'meta'>;
109
+ routeTree: TRouteTree;
110
+ constructor(options: RouterConstructorOptions<TRouteTree, TDehydrated>);
111
+ subscribers: Set<RouterListener<RouterEvent>>;
112
+ subscribe: <TType extends keyof RouterEvents>(eventType: TType, fn: ListenerFn<RouterEvents[TType]>) => () => void;
113
+ emit: (routerEvent: RouterEvent) => void;
114
+ }
115
+ export declare function lazyFn<T extends Record<string, (...args: any[]) => any>, TKey extends keyof T = 'default'>(fn: () => Promise<T>, key?: TKey): (...args: Parameters<T[TKey]>) => Promise<ReturnType<T[TKey]>>;
@@ -1,3 +0,0 @@
1
- import { ScrollRestorationOptions } from '@tanstack/router-core';
2
- export declare function useScrollRestoration(options?: ScrollRestorationOptions): void;
3
- export declare function ScrollRestoration(props: ScrollRestorationOptions): null;
@@ -0,0 +1,7 @@
1
+ import { AnySearchSchema } from './route';
2
+ export declare const defaultParseSearch: (searchStr: string) => AnySearchSchema;
3
+ export declare const defaultStringifySearch: (search: Record<string, any>) => string;
4
+ export declare function parseSearchWith(parser: (str: string) => any): (searchStr: string) => AnySearchSchema;
5
+ export declare function stringifySearchWith(stringify: (search: any) => string, parser?: (str: string) => any): (search: Record<string, any>) => string;
6
+ export type SearchSerializer = (searchObj: Record<string, any>) => string;
7
+ export type SearchParser = (searchStr: string) => Record<string, any>;
@@ -0,0 +1,48 @@
1
+ export type NoInfer<T> = [T][T extends any ? 0 : never];
2
+ export type IsAny<T, Y, N = T> = 1 extends 0 & T ? Y : N;
3
+ export type IsAnyBoolean<T> = 1 extends 0 & T ? true : false;
4
+ export type IsKnown<T, Y, N> = unknown extends T ? N : Y;
5
+ export type PickAsRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
6
+ export type PickAsPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
7
+ export type PickUnsafe<T, K> = K extends keyof T ? Pick<T, K> : never;
8
+ export type PickExtra<T, K> = {
9
+ [TKey in keyof K as string extends TKey ? never : TKey extends keyof T ? never : TKey]: K[TKey];
10
+ };
11
+ export type PickRequired<T> = {
12
+ [K in keyof T as undefined extends T[K] ? never : K]: T[K];
13
+ };
14
+ export type Expand<T> = T extends object ? T extends infer O ? {
15
+ [K in keyof O]: O[K];
16
+ } : never : T;
17
+ export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => any ? I : never;
18
+ export type Assign<Left, Right> = Omit<Left, keyof Right> & Right;
19
+ export type AssignAll<T extends any[]> = T extends [infer Left, ...infer Right] ? Right extends any[] ? Assign<Left, AssignAll<Right>> : Left : {};
20
+ export type Values<O> = O[ValueKeys<O>];
21
+ export type ValueKeys<O> = Extract<keyof O, PropertyKey>;
22
+ export type DeepAwaited<T> = T extends Promise<infer A> ? DeepAwaited<A> : T extends Record<infer A, Promise<infer B>> ? {
23
+ [K in A]: DeepAwaited<B>;
24
+ } : T;
25
+ 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;
26
+ export type Timeout = ReturnType<typeof setTimeout>;
27
+ export type Updater<TPrevious, TResult = TPrevious> = TResult | ((prev?: TPrevious) => TResult);
28
+ export type NonNullableUpdater<TPrevious, TResult = TPrevious> = TResult | ((prev: TPrevious) => TResult);
29
+ export type PickExtract<T, U> = {
30
+ [K in keyof T as T[K] extends U ? K : never]: T[K];
31
+ };
32
+ export type PickExclude<T, U> = {
33
+ [K in keyof T as T[K] extends U ? never : K]: T[K];
34
+ };
35
+ export declare const isServer: boolean;
36
+ export declare function last<T>(arr: T[]): T | undefined;
37
+ export declare function functionalUpdate<TResult>(updater: Updater<TResult> | NonNullableUpdater<TResult>, previous: TResult): TResult;
38
+ export declare function pick<T, K extends keyof T>(parent: T, keys: K[]): Pick<T, K>;
39
+ /**
40
+ * This function returns `a` if `b` is deeply equal.
41
+ * If not, it will replace any deeply equal children of `b` with those of `a`.
42
+ * This can be used for structural sharing between immutable JSON values for example.
43
+ * Do not use this with signals
44
+ */
45
+ export declare function replaceEqualDeep<T>(prev: any, _next: T): T;
46
+ export declare function isPlainObject(o: any): boolean;
47
+ export declare function partialDeepEqual(a: any, b: any): boolean;
48
+ export declare function useStableCallback<T extends (...args: any[]) => any>(fn: T): T;