@tanstack/react-router 0.0.1-beta.28 → 0.0.1-beta.280
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/CatchBoundary.js +128 -0
- package/build/cjs/CatchBoundary.js.map +1 -0
- package/build/cjs/Matches.js +233 -0
- package/build/cjs/Matches.js.map +1 -0
- package/build/cjs/RouterProvider.js +170 -0
- package/build/cjs/RouterProvider.js.map +1 -0
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +2 -22
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/build/cjs/awaited.js +43 -0
- package/build/cjs/awaited.js.map +1 -0
- package/build/cjs/defer.js +37 -0
- package/build/cjs/defer.js.map +1 -0
- package/build/cjs/fileRoute.js +27 -0
- package/build/cjs/fileRoute.js.map +1 -0
- package/build/cjs/index.js +130 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/lazyRouteComponent.js +54 -0
- package/build/cjs/lazyRouteComponent.js.map +1 -0
- package/build/cjs/link.js +223 -0
- package/build/cjs/link.js.map +1 -0
- package/build/cjs/path.js +214 -0
- package/build/cjs/path.js.map +1 -0
- package/build/cjs/qss.js +63 -0
- package/build/cjs/qss.js.map +1 -0
- package/build/cjs/redirects.js +28 -0
- package/build/cjs/redirects.js.map +1 -0
- package/build/cjs/route.js +191 -0
- package/build/cjs/route.js.map +1 -0
- package/build/cjs/router.js +1049 -0
- package/build/cjs/router.js.map +1 -0
- package/build/cjs/scroll-restoration.js +202 -0
- package/build/cjs/scroll-restoration.js.map +1 -0
- package/build/cjs/searchParams.js +81 -0
- package/build/cjs/searchParams.js.map +1 -0
- package/build/cjs/useBlocker.js +55 -0
- package/build/cjs/useBlocker.js.map +1 -0
- package/build/cjs/useNavigate.js +86 -0
- package/build/cjs/useNavigate.js.map +1 -0
- package/build/cjs/useParams.js +26 -0
- package/build/cjs/useParams.js.map +1 -0
- package/build/cjs/useSearch.js +25 -0
- package/build/cjs/useSearch.js.map +1 -0
- package/build/cjs/utils.js +239 -0
- package/build/cjs/utils.js.map +1 -0
- package/build/esm/index.js +2255 -2571
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +3498 -2694
- package/build/stats-react.json +1204 -44
- package/build/types/CatchBoundary.d.ts +36 -0
- package/build/types/Matches.d.ts +62 -0
- package/build/types/RouterProvider.d.ts +35 -0
- package/build/types/awaited.d.ts +9 -0
- package/build/types/defer.d.ts +19 -0
- package/build/types/fileRoute.d.ts +38 -0
- package/build/types/history.d.ts +7 -0
- package/build/types/index.d.ts +27 -114
- package/build/types/lazyRouteComponent.d.ts +2 -0
- package/build/types/link.d.ts +91 -0
- package/build/types/location.d.ts +12 -0
- package/build/types/path.d.ts +17 -0
- package/build/types/qss.d.ts +2 -0
- package/build/types/redirects.d.ts +11 -0
- package/build/types/route.d.ts +282 -0
- package/build/types/routeInfo.d.ts +22 -0
- package/build/types/router.d.ts +188 -0
- package/build/types/scroll-restoration.d.ts +18 -0
- package/build/types/searchParams.d.ts +7 -0
- package/build/types/useBlocker.d.ts +9 -0
- package/build/types/useNavigate.d.ts +19 -0
- package/build/types/useParams.d.ts +7 -0
- package/build/types/useSearch.d.ts +7 -0
- package/build/types/utils.d.ts +66 -0
- package/build/umd/index.development.js +2858 -2548
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +4 -4
- package/build/umd/index.production.js.map +1 -1
- package/package.json +11 -10
- package/src/CatchBoundary.tsx +101 -0
- package/src/Matches.tsx +421 -0
- package/src/RouterProvider.tsx +252 -0
- package/src/awaited.tsx +40 -0
- package/src/defer.ts +55 -0
- package/src/fileRoute.ts +152 -0
- package/src/history.ts +8 -0
- package/src/index.tsx +28 -761
- package/src/lazyRouteComponent.tsx +33 -0
- package/src/link.tsx +598 -0
- package/src/location.ts +13 -0
- package/src/path.ts +261 -0
- package/src/qss.ts +53 -0
- package/src/redirects.ts +39 -0
- package/src/route.ts +872 -0
- package/src/routeInfo.ts +70 -0
- package/src/router.ts +1630 -0
- package/src/scroll-restoration.tsx +230 -0
- package/src/searchParams.ts +79 -0
- package/src/useBlocker.tsx +27 -0
- package/src/useNavigate.tsx +111 -0
- package/src/useParams.tsx +25 -0
- package/src/useSearch.tsx +25 -0
- package/src/utils.ts +350 -0
- package/build/cjs/react-router/src/index.js +0 -508
- package/build/cjs/react-router/src/index.js.map +0 -1
- package/build/cjs/router-core/build/esm/index.js +0 -2530
- package/build/cjs/router-core/build/esm/index.js.map +0 -1
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { AnyRouteMatch } from './Matches';
|
|
3
|
+
import { NavigateOptions, ParsePathParams, ToSubOptions } from './link';
|
|
4
|
+
import { ParsedLocation } from './location';
|
|
5
|
+
import { RouteById, RouteIds, RoutePaths } from './routeInfo';
|
|
6
|
+
import { AnyRouter, RegisteredRouter } from './router';
|
|
7
|
+
import { Assign, Expand, IsAny, NoInfer, PickRequired, UnionToIntersection } from './utils';
|
|
8
|
+
import { BuildLocationFn, NavigateFn } from './RouterProvider';
|
|
9
|
+
export declare const rootRouteId: "__root__";
|
|
10
|
+
export type RootRouteId = typeof rootRouteId;
|
|
11
|
+
export type AnyPathParams = {};
|
|
12
|
+
export type AnySearchSchema = {};
|
|
13
|
+
export type AnyContext = {};
|
|
14
|
+
export interface RouteContext {
|
|
15
|
+
}
|
|
16
|
+
export interface RouteMeta {
|
|
17
|
+
}
|
|
18
|
+
export type PreloadableObj = {
|
|
19
|
+
preload?: () => Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
export type RoutePathOptions<TCustomId, TPath> = {
|
|
22
|
+
path: TPath;
|
|
23
|
+
} | {
|
|
24
|
+
id: TCustomId;
|
|
25
|
+
};
|
|
26
|
+
export type RoutePathOptionsIntersection<TCustomId, TPath> = UnionToIntersection<RoutePathOptions<TCustomId, TPath>>;
|
|
27
|
+
export type MetaOptions = keyof PickRequired<RouteMeta> extends never ? {
|
|
28
|
+
meta?: RouteMeta;
|
|
29
|
+
} : {
|
|
30
|
+
meta: RouteMeta;
|
|
31
|
+
};
|
|
32
|
+
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, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TLoaderDeps, TLoaderData> & UpdatableRouteOptions<NoInfer<TFullSearchSchema>>;
|
|
33
|
+
export type ParamsFallback<TPath extends string, TParams> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams;
|
|
34
|
+
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>, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown> = RoutePathOptions<TCustomId, TPath> & {
|
|
35
|
+
getParentRoute: () => TParentRoute;
|
|
36
|
+
validateSearch?: SearchSchemaValidator<TSearchSchema>;
|
|
37
|
+
} & (keyof PickRequired<RouteContext> extends never ? {
|
|
38
|
+
beforeLoad?: BeforeLoadFn<TFullSearchSchema, TParentRoute, TAllParams, TRouteContext>;
|
|
39
|
+
} : {
|
|
40
|
+
beforeLoad: BeforeLoadFn<TFullSearchSchema, TParentRoute, TAllParams, TRouteContext>;
|
|
41
|
+
}) & {
|
|
42
|
+
loaderDeps?: (opts: {
|
|
43
|
+
search: TFullSearchSchema;
|
|
44
|
+
}) => TLoaderDeps;
|
|
45
|
+
loader?: RouteLoaderFn<TAllParams, NoInfer<TLoaderDeps>, NoInfer<TAllContext>, NoInfer<TRouteContext>, TLoaderData>;
|
|
46
|
+
} & ({
|
|
47
|
+
parseParams?: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams extends Record<ParsePathParams<TPath>, any> ? TParams : 'parseParams must return an object';
|
|
48
|
+
stringifyParams?: (params: NoInfer<ParamsFallback<TPath, TParams>>) => Record<ParsePathParams<TPath>, string>;
|
|
49
|
+
} | {
|
|
50
|
+
stringifyParams?: never;
|
|
51
|
+
parseParams?: never;
|
|
52
|
+
});
|
|
53
|
+
type BeforeLoadFn<TFullSearchSchema extends Record<string, any>, TParentRoute extends AnyRoute, TAllParams, TRouteContext> = (opts: {
|
|
54
|
+
search: TFullSearchSchema;
|
|
55
|
+
abortController: AbortController;
|
|
56
|
+
preload: boolean;
|
|
57
|
+
params: TAllParams;
|
|
58
|
+
context: TParentRoute['types']['allContext'];
|
|
59
|
+
location: ParsedLocation;
|
|
60
|
+
navigate: NavigateFn<AnyRoute>;
|
|
61
|
+
buildLocation: BuildLocationFn<TParentRoute>;
|
|
62
|
+
cause: 'preload' | 'enter' | 'stay';
|
|
63
|
+
}) => Promise<TRouteContext> | TRouteContext | void;
|
|
64
|
+
export type UpdatableRouteOptions<TFullSearchSchema extends Record<string, any>> = MetaOptions & {
|
|
65
|
+
caseSensitive?: boolean;
|
|
66
|
+
wrapInSuspense?: boolean;
|
|
67
|
+
component?: RouteComponent;
|
|
68
|
+
errorComponent?: false | null | ErrorRouteComponent;
|
|
69
|
+
pendingComponent?: RouteComponent;
|
|
70
|
+
pendingMs?: number;
|
|
71
|
+
pendingMinMs?: number;
|
|
72
|
+
staleTime?: number;
|
|
73
|
+
gcTime?: number;
|
|
74
|
+
preloadStaleTime?: number;
|
|
75
|
+
preloadGcTime?: number;
|
|
76
|
+
preSearchFilters?: SearchFilter<TFullSearchSchema>[];
|
|
77
|
+
postSearchFilters?: SearchFilter<TFullSearchSchema>[];
|
|
78
|
+
onError?: (err: any) => void;
|
|
79
|
+
onEnter?: (match: AnyRouteMatch) => void;
|
|
80
|
+
onStay?: (match: AnyRouteMatch) => void;
|
|
81
|
+
onLeave?: (match: AnyRouteMatch) => void;
|
|
82
|
+
};
|
|
83
|
+
export type ParseParamsOption<TPath extends string, TParams> = ParseParamsFn<TPath, TParams>;
|
|
84
|
+
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';
|
|
85
|
+
export type ParseParamsObj<TPath extends string, TParams> = {
|
|
86
|
+
parse?: ParseParamsFn<TPath, TParams>;
|
|
87
|
+
};
|
|
88
|
+
export type SearchSchemaValidator<TReturn> = SearchSchemaValidatorObj<TReturn> | SearchSchemaValidatorFn<TReturn>;
|
|
89
|
+
export type SearchSchemaValidatorObj<TReturn> = {
|
|
90
|
+
parse?: SearchSchemaValidatorFn<TReturn>;
|
|
91
|
+
};
|
|
92
|
+
export type SearchSchemaValidatorFn<TReturn> = (searchObj: Record<string, unknown>) => TReturn;
|
|
93
|
+
export type DefinedPathParamWarning = 'Path params cannot be redefined by child routes!';
|
|
94
|
+
export type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
|
|
95
|
+
[Key in keyof TParentParams]?: DefinedPathParamWarning;
|
|
96
|
+
};
|
|
97
|
+
export type RouteLoaderFn<TAllParams = {}, TLoaderDeps extends Record<string, any> = {}, TAllContext extends Record<string, any> = AnyContext, TRouteContext extends Record<string, any> = AnyContext, TLoaderData extends any = unknown> = (match: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext, TRouteContext>) => Promise<TLoaderData> | TLoaderData;
|
|
98
|
+
export interface LoaderFnContext<TAllParams = {}, TLoaderDeps extends Record<string, any> = {}, TAllContext extends Record<string, any> = AnyContext, TRouteContext extends Record<string, any> = AnyContext> {
|
|
99
|
+
abortController: AbortController;
|
|
100
|
+
preload: boolean;
|
|
101
|
+
params: TAllParams;
|
|
102
|
+
deps: TLoaderDeps;
|
|
103
|
+
context: Expand<Assign<TAllContext, TRouteContext>>;
|
|
104
|
+
location: ParsedLocation;
|
|
105
|
+
navigate: (opts: NavigateOptions<AnyRoute>) => Promise<void>;
|
|
106
|
+
parentMatchPromise?: Promise<void>;
|
|
107
|
+
cause: 'preload' | 'enter' | 'stay';
|
|
108
|
+
}
|
|
109
|
+
export type SearchFilter<T, U = T> = (prev: T) => U;
|
|
110
|
+
export type ResolveId<TParentRoute, TCustomId extends string, TPath extends string> = TParentRoute extends {
|
|
111
|
+
id: infer TParentId extends string;
|
|
112
|
+
} ? RoutePrefix<TParentId, string extends TCustomId ? TPath : TCustomId> : RootRouteId;
|
|
113
|
+
export type InferFullSearchSchema<TRoute> = TRoute extends {
|
|
114
|
+
types: {
|
|
115
|
+
fullSearchSchema: infer TFullSearchSchema;
|
|
116
|
+
};
|
|
117
|
+
} ? TFullSearchSchema : {};
|
|
118
|
+
export type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = Expand<Assign<InferFullSearchSchema<TParentRoute>, TSearchSchema>>;
|
|
119
|
+
export interface AnyRoute extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
120
|
+
}
|
|
121
|
+
export type MergeFromFromParent<T, U> = IsAny<T, U, T & U>;
|
|
122
|
+
export type ResolveAllParams<TParentRoute extends AnyRoute, TParams extends AnyPathParams> = Record<never, string> extends TParentRoute['types']['allParams'] ? TParams : Expand<UnionToIntersection<TParentRoute['types']['allParams'] & TParams> & {}>;
|
|
123
|
+
export type RouteConstraints = {
|
|
124
|
+
TParentRoute: AnyRoute;
|
|
125
|
+
TPath: string;
|
|
126
|
+
TFullPath: string;
|
|
127
|
+
TCustomId: string;
|
|
128
|
+
TId: string;
|
|
129
|
+
TSearchSchema: AnySearchSchema;
|
|
130
|
+
TFullSearchSchema: AnySearchSchema;
|
|
131
|
+
TParams: Record<string, any>;
|
|
132
|
+
TAllParams: Record<string, any>;
|
|
133
|
+
TParentContext: AnyContext;
|
|
134
|
+
TRouteContext: RouteContext;
|
|
135
|
+
TAllContext: AnyContext;
|
|
136
|
+
TRouterContext: AnyContext;
|
|
137
|
+
TChildren: unknown;
|
|
138
|
+
TRouteTree: AnyRoute;
|
|
139
|
+
};
|
|
140
|
+
export declare class RouteApi<TId extends RouteIds<RegisteredRouter['routeTree']>, TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>, TFullSearchSchema extends Record<string, any> = TRoute['types']['fullSearchSchema'], TAllParams extends AnyPathParams = TRoute['types']['allParams'], TAllContext extends Record<string, any> = TRoute['types']['allContext'], TLoaderDeps extends Record<string, any> = TRoute['types']['loaderDeps'], TLoaderData extends any = TRoute['types']['loaderData']> {
|
|
141
|
+
id: TId;
|
|
142
|
+
constructor({ id }: {
|
|
143
|
+
id: TId;
|
|
144
|
+
});
|
|
145
|
+
useMatch: <TSelected = TAllContext>(opts?: {
|
|
146
|
+
select?: ((s: TAllContext) => TSelected) | undefined;
|
|
147
|
+
} | undefined) => TSelected;
|
|
148
|
+
useRouteContext: <TSelected = TAllContext>(opts?: {
|
|
149
|
+
select?: ((s: TAllContext) => TSelected) | undefined;
|
|
150
|
+
} | undefined) => TSelected;
|
|
151
|
+
useSearch: <TSelected = TFullSearchSchema>(opts?: {
|
|
152
|
+
select?: ((s: TFullSearchSchema) => TSelected) | undefined;
|
|
153
|
+
} | undefined) => TSelected;
|
|
154
|
+
useParams: <TSelected = TAllParams>(opts?: {
|
|
155
|
+
select?: ((s: TAllParams) => TSelected) | undefined;
|
|
156
|
+
} | undefined) => TSelected;
|
|
157
|
+
useLoaderDeps: <TSelected = TLoaderDeps>(opts?: {
|
|
158
|
+
select?: ((s: TLoaderDeps) => TSelected) | undefined;
|
|
159
|
+
} | undefined) => TSelected;
|
|
160
|
+
useLoaderData: <TSelected = TLoaderData>(opts?: {
|
|
161
|
+
select?: ((s: TLoaderData) => TSelected) | undefined;
|
|
162
|
+
} | undefined) => TSelected;
|
|
163
|
+
}
|
|
164
|
+
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>, TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext, TAllContext extends Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
|
|
165
|
+
isRoot: TParentRoute extends Route<any> ? true : false;
|
|
166
|
+
options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TLoaderDeps, TLoaderData>;
|
|
167
|
+
test: Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>>;
|
|
168
|
+
parentRoute: TParentRoute;
|
|
169
|
+
id: TId;
|
|
170
|
+
path: TPath;
|
|
171
|
+
fullPath: TFullPath;
|
|
172
|
+
to: TrimPathRight<TFullPath>;
|
|
173
|
+
children?: TChildren;
|
|
174
|
+
originalIndex?: number;
|
|
175
|
+
router?: AnyRouter;
|
|
176
|
+
rank: number;
|
|
177
|
+
constructor(options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TLoaderDeps, TLoaderData>);
|
|
178
|
+
types: {
|
|
179
|
+
parentRoute: TParentRoute;
|
|
180
|
+
path: TPath;
|
|
181
|
+
to: TrimPathRight<TFullPath>;
|
|
182
|
+
fullPath: TFullPath;
|
|
183
|
+
customId: TCustomId;
|
|
184
|
+
id: TId;
|
|
185
|
+
searchSchema: TSearchSchema;
|
|
186
|
+
fullSearchSchema: TFullSearchSchema;
|
|
187
|
+
params: TParams;
|
|
188
|
+
allParams: TAllParams;
|
|
189
|
+
routeContext: TRouteContext;
|
|
190
|
+
allContext: TAllContext;
|
|
191
|
+
children: TChildren;
|
|
192
|
+
routeTree: TRouteTree;
|
|
193
|
+
routerContext: TRouterContext;
|
|
194
|
+
loaderData: TLoaderData;
|
|
195
|
+
loaderDeps: TLoaderDeps;
|
|
196
|
+
};
|
|
197
|
+
init: (opts: {
|
|
198
|
+
originalIndex: number;
|
|
199
|
+
}) => void;
|
|
200
|
+
addChildren: <TNewChildren extends AnyRoute[]>(children: TNewChildren) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TRouterContext, TLoaderDeps, TLoaderData, TNewChildren, TRouteTree>;
|
|
201
|
+
update: (options: UpdatableRouteOptions<TFullSearchSchema>) => this;
|
|
202
|
+
useMatch: <TSelected = TAllContext>(opts?: {
|
|
203
|
+
select?: ((search: TAllContext) => TSelected) | undefined;
|
|
204
|
+
} | undefined) => TSelected;
|
|
205
|
+
useRouteContext: <TSelected = TAllContext>(opts?: {
|
|
206
|
+
select?: ((search: TAllContext) => TSelected) | undefined;
|
|
207
|
+
} | undefined) => TSelected;
|
|
208
|
+
useSearch: <TSelected = TFullSearchSchema>(opts?: {
|
|
209
|
+
select?: ((search: TFullSearchSchema) => TSelected) | undefined;
|
|
210
|
+
} | undefined) => TSelected;
|
|
211
|
+
useParams: <TSelected = TAllParams>(opts?: {
|
|
212
|
+
select?: ((search: TAllParams) => TSelected) | undefined;
|
|
213
|
+
} | undefined) => TSelected;
|
|
214
|
+
useLoaderDeps: <TSelected = TLoaderDeps>(opts?: {
|
|
215
|
+
select?: ((s: TLoaderDeps) => TSelected) | undefined;
|
|
216
|
+
} | undefined) => TSelected;
|
|
217
|
+
useLoaderData: <TSelected = TLoaderData>(opts?: {
|
|
218
|
+
select?: ((search: TLoaderData) => TSelected) | undefined;
|
|
219
|
+
} | undefined) => TSelected;
|
|
220
|
+
}
|
|
221
|
+
export type AnyRootRoute = RootRoute<any, any, any, any>;
|
|
222
|
+
export declare function rootRouteWithContext<TRouterContext extends {}>(): <TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends unknown = unknown>(options?: Omit<RouteOptions<AnyRoute, "__root__", "", TSearchSchema, TSearchSchema, {}, {}, TRouteContext, Assign<TRouterContext, TRouteContext>, TLoaderDeps, TLoaderData>, "path" | "id" | "getParentRoute" | "stringifyParams" | "parseParams" | "caseSensitive"> | undefined) => RootRoute<TSearchSchema, TRouteContext, TRouterContext, {}, unknown>;
|
|
223
|
+
export declare class RootRoute<TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext, TRouterContext extends {} = {}, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown> extends Route<any, // TParentRoute
|
|
224
|
+
'/', // TPath
|
|
225
|
+
'/', // TFullPath
|
|
226
|
+
string, // TCustomId
|
|
227
|
+
RootRouteId, // TId
|
|
228
|
+
TSearchSchema, // TSearchSchema
|
|
229
|
+
TSearchSchema, // TFullSearchSchema
|
|
230
|
+
{}, // TParams
|
|
231
|
+
{}, // TAllParams
|
|
232
|
+
TRouteContext, // TRouteContext
|
|
233
|
+
Expand<Assign<TRouterContext, TRouteContext>>, // TAllContext
|
|
234
|
+
TRouterContext, // TRouterContext
|
|
235
|
+
TLoaderDeps, TLoaderData, any, // TChildren
|
|
236
|
+
any> {
|
|
237
|
+
constructor(options?: Omit<RouteOptions<AnyRoute, // TParentRoute
|
|
238
|
+
RootRouteId, // TCustomId
|
|
239
|
+
'', // TPath
|
|
240
|
+
TSearchSchema, // TSearchSchema
|
|
241
|
+
TSearchSchema, // TFullSearchSchema
|
|
242
|
+
{}, // TParams
|
|
243
|
+
{}, // TAllParams
|
|
244
|
+
TRouteContext, // TRouteContext
|
|
245
|
+
Assign<TRouterContext, TRouteContext>, // TAllContext
|
|
246
|
+
TLoaderDeps, TLoaderData>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams'>);
|
|
247
|
+
}
|
|
248
|
+
export type ResolveFullPath<TParentRoute extends AnyRoute, TPath extends string, TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>> = TPrefixed extends RootRouteId ? '/' : TPrefixed;
|
|
249
|
+
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;
|
|
250
|
+
export type TrimPath<T extends string> = '' extends T ? '' : TrimPathRight<TrimPathLeft<T>>;
|
|
251
|
+
export type TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}` ? TrimPathLeft<U> : T extends `/${infer U}` ? TrimPathLeft<U> : T;
|
|
252
|
+
export type TrimPathRight<T extends string> = T extends '/' ? '/' : T extends `${infer U}/` ? TrimPathRight<U> : T;
|
|
253
|
+
export type RouteMask<TRouteTree extends AnyRoute> = {
|
|
254
|
+
routeTree: TRouteTree;
|
|
255
|
+
from: RoutePaths<TRouteTree>;
|
|
256
|
+
to?: any;
|
|
257
|
+
params?: any;
|
|
258
|
+
search?: any;
|
|
259
|
+
hash?: any;
|
|
260
|
+
state?: any;
|
|
261
|
+
unmaskOnReload?: boolean;
|
|
262
|
+
};
|
|
263
|
+
export declare function createRouteMask<TRouteTree extends AnyRoute, TFrom extends RoutePaths<TRouteTree>, TTo extends string>(opts: {
|
|
264
|
+
routeTree: TRouteTree;
|
|
265
|
+
} & ToSubOptions<TRouteTree, TFrom, TTo>): RouteMask<TRouteTree>;
|
|
266
|
+
export type ErrorRouteProps = {
|
|
267
|
+
error: unknown;
|
|
268
|
+
info: {
|
|
269
|
+
componentStack: string;
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
export type ReactNode = any;
|
|
273
|
+
export type SyncRouteComponent<TProps> = ((props: TProps) => ReactNode) | React.LazyExoticComponent<(props: TProps) => ReactNode>;
|
|
274
|
+
export type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {
|
|
275
|
+
preload?: () => Promise<void>;
|
|
276
|
+
};
|
|
277
|
+
export type RouteComponent<TProps = any> = SyncRouteComponent<TProps> & AsyncRouteComponent<TProps>;
|
|
278
|
+
export type ErrorRouteComponent = RouteComponent<ErrorRouteProps>;
|
|
279
|
+
export declare class NotFoundRoute<TParentRoute extends AnyRootRoute, TSearchSchema extends RouteConstraints['TSearchSchema'] = {}, TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext, TAllContext extends Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> extends Route<TParentRoute, '/404', '/404', '404', '404', TSearchSchema, TFullSearchSchema, {}, {}, TRouteContext, TAllContext, TRouterContext, TLoaderDeps, TLoaderData, TChildren, TRouteTree> {
|
|
280
|
+
constructor(options: Omit<RouteOptions<TParentRoute, string, string, TSearchSchema, TFullSearchSchema, {}, {}, TRouteContext, TAllContext, TLoaderDeps, TLoaderData>, 'caseSensitive' | 'parseParams' | 'stringifyParams' | 'path' | 'id'>);
|
|
281
|
+
}
|
|
282
|
+
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']>>;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { HistoryState, RouterHistory } from '@tanstack/history';
|
|
3
|
+
import { Store } from '@tanstack/store';
|
|
4
|
+
import { AnySearchSchema, AnyRoute, AnyContext, RouteMask } from './route';
|
|
5
|
+
import { FullSearchSchema, RoutesById, RoutesByPath } from './routeInfo';
|
|
6
|
+
import { PickAsRequired, Updater, NonNullableUpdater, Timeout } from './utils';
|
|
7
|
+
import { RouteComponent } from './route';
|
|
8
|
+
import { AnyRouteMatch, RouteMatch } from './Matches';
|
|
9
|
+
import { ParsedLocation } from './location';
|
|
10
|
+
import { SearchSerializer, SearchParser } from './searchParams';
|
|
11
|
+
import { BuildLocationFn, CommitLocationOptions, InjectedHtmlEntry, MatchRouteFn, NavigateFn } from './RouterProvider';
|
|
12
|
+
import { ToOptions } from './link';
|
|
13
|
+
declare global {
|
|
14
|
+
interface Window {
|
|
15
|
+
__TSR_DEHYDRATED__?: HydrationCtx;
|
|
16
|
+
__TSR_ROUTER_CONTEXT__?: React.Context<Router<any>>;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export interface Register {
|
|
20
|
+
}
|
|
21
|
+
export type AnyRouter = Router<AnyRoute, any>;
|
|
22
|
+
export type RegisteredRouter = Register extends {
|
|
23
|
+
router: infer TRouter extends AnyRouter;
|
|
24
|
+
} ? TRouter : AnyRouter;
|
|
25
|
+
export type HydrationCtx = {
|
|
26
|
+
router: DehydratedRouter;
|
|
27
|
+
payload: Record<string, any>;
|
|
28
|
+
};
|
|
29
|
+
export type RouterContextOptions<TRouteTree extends AnyRoute> = AnyContext extends TRouteTree['types']['routerContext'] ? {
|
|
30
|
+
context?: TRouteTree['types']['routerContext'];
|
|
31
|
+
} : {
|
|
32
|
+
context: TRouteTree['types']['routerContext'];
|
|
33
|
+
};
|
|
34
|
+
export interface RouterOptions<TRouteTree extends AnyRoute, TDehydrated extends Record<string, any> = Record<string, any>> {
|
|
35
|
+
history?: RouterHistory;
|
|
36
|
+
stringifySearch?: SearchSerializer;
|
|
37
|
+
parseSearch?: SearchParser;
|
|
38
|
+
defaultPreload?: false | 'intent';
|
|
39
|
+
defaultPreloadDelay?: number;
|
|
40
|
+
defaultComponent?: RouteComponent;
|
|
41
|
+
defaultErrorComponent?: RouteComponent;
|
|
42
|
+
defaultPendingComponent?: RouteComponent;
|
|
43
|
+
defaultPendingMs?: number;
|
|
44
|
+
defaultPendingMinMs?: number;
|
|
45
|
+
defaultStaleTime?: number;
|
|
46
|
+
defaultPreloadStaleTime?: number;
|
|
47
|
+
defaultPreloadGcTime?: number;
|
|
48
|
+
defaultGcTime?: number;
|
|
49
|
+
caseSensitive?: boolean;
|
|
50
|
+
routeTree?: TRouteTree;
|
|
51
|
+
basepath?: string;
|
|
52
|
+
context?: TRouteTree['types']['routerContext'];
|
|
53
|
+
dehydrate?: () => TDehydrated;
|
|
54
|
+
hydrate?: (dehydrated: TDehydrated) => void;
|
|
55
|
+
routeMasks?: RouteMask<TRouteTree>[];
|
|
56
|
+
unmaskOnReload?: boolean;
|
|
57
|
+
Wrap?: (props: {
|
|
58
|
+
children: any;
|
|
59
|
+
}) => JSX.Element;
|
|
60
|
+
InnerWrap?: (props: {
|
|
61
|
+
children: any;
|
|
62
|
+
}) => JSX.Element;
|
|
63
|
+
notFoundRoute?: AnyRoute;
|
|
64
|
+
}
|
|
65
|
+
export interface RouterState<TRouteTree extends AnyRoute = AnyRoute> {
|
|
66
|
+
status: 'pending' | 'idle';
|
|
67
|
+
isLoading: boolean;
|
|
68
|
+
isTransitioning: boolean;
|
|
69
|
+
matches: RouteMatch<TRouteTree>[];
|
|
70
|
+
pendingMatches?: RouteMatch<TRouteTree>[];
|
|
71
|
+
cachedMatches: RouteMatch<TRouteTree>[];
|
|
72
|
+
location: ParsedLocation<FullSearchSchema<TRouteTree>>;
|
|
73
|
+
resolvedLocation: ParsedLocation<FullSearchSchema<TRouteTree>>;
|
|
74
|
+
lastUpdated: number;
|
|
75
|
+
}
|
|
76
|
+
export type ListenerFn<TEvent extends RouterEvent> = (event: TEvent) => void;
|
|
77
|
+
export interface BuildNextOptions {
|
|
78
|
+
to?: string | number | null;
|
|
79
|
+
params?: true | Updater<unknown>;
|
|
80
|
+
search?: true | Updater<unknown>;
|
|
81
|
+
hash?: true | Updater<string>;
|
|
82
|
+
state?: true | NonNullableUpdater<HistoryState>;
|
|
83
|
+
mask?: {
|
|
84
|
+
to?: string | number | null;
|
|
85
|
+
params?: true | Updater<unknown>;
|
|
86
|
+
search?: true | Updater<unknown>;
|
|
87
|
+
hash?: true | Updater<string>;
|
|
88
|
+
state?: true | NonNullableUpdater<HistoryState>;
|
|
89
|
+
unmaskOnReload?: boolean;
|
|
90
|
+
};
|
|
91
|
+
from?: string;
|
|
92
|
+
}
|
|
93
|
+
export interface DehydratedRouterState {
|
|
94
|
+
dehydratedMatches: DehydratedRouteMatch[];
|
|
95
|
+
}
|
|
96
|
+
export type DehydratedRouteMatch = Pick<RouteMatch, 'id' | 'status' | 'updatedAt'>;
|
|
97
|
+
export interface DehydratedRouter {
|
|
98
|
+
state: DehydratedRouterState;
|
|
99
|
+
}
|
|
100
|
+
export type RouterConstructorOptions<TRouteTree extends AnyRoute, TDehydrated extends Record<string, any>> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> & RouterContextOptions<TRouteTree>;
|
|
101
|
+
export declare const componentTypes: readonly ["component", "errorComponent", "pendingComponent"];
|
|
102
|
+
export type RouterEvents = {
|
|
103
|
+
onBeforeLoad: {
|
|
104
|
+
type: 'onBeforeLoad';
|
|
105
|
+
fromLocation: ParsedLocation;
|
|
106
|
+
toLocation: ParsedLocation;
|
|
107
|
+
pathChanged: boolean;
|
|
108
|
+
};
|
|
109
|
+
onLoad: {
|
|
110
|
+
type: 'onLoad';
|
|
111
|
+
fromLocation: ParsedLocation;
|
|
112
|
+
toLocation: ParsedLocation;
|
|
113
|
+
pathChanged: boolean;
|
|
114
|
+
};
|
|
115
|
+
onResolved: {
|
|
116
|
+
type: 'onResolved';
|
|
117
|
+
fromLocation: ParsedLocation;
|
|
118
|
+
toLocation: ParsedLocation;
|
|
119
|
+
pathChanged: boolean;
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
export type RouterEvent = RouterEvents[keyof RouterEvents];
|
|
123
|
+
export type RouterListener<TRouterEvent extends RouterEvent> = {
|
|
124
|
+
eventType: TRouterEvent['type'];
|
|
125
|
+
fn: ListenerFn<TRouterEvent>;
|
|
126
|
+
};
|
|
127
|
+
export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated extends Record<string, any> = Record<string, any>> {
|
|
128
|
+
tempLocationKey: string | undefined;
|
|
129
|
+
resetNextScroll: boolean;
|
|
130
|
+
navigateTimeout: Timeout | null;
|
|
131
|
+
latestLoadPromise: Promise<void>;
|
|
132
|
+
subscribers: Set<RouterListener<RouterEvent>>;
|
|
133
|
+
injectedHtml: InjectedHtmlEntry[];
|
|
134
|
+
dehydratedData?: TDehydrated;
|
|
135
|
+
__store: Store<RouterState<TRouteTree>>;
|
|
136
|
+
options: PickAsRequired<RouterOptions<TRouteTree, TDehydrated>, 'stringifySearch' | 'parseSearch' | 'context'>;
|
|
137
|
+
history: RouterHistory;
|
|
138
|
+
latestLocation: ParsedLocation;
|
|
139
|
+
basepath: string;
|
|
140
|
+
routeTree: TRouteTree;
|
|
141
|
+
routesById: RoutesById<TRouteTree>;
|
|
142
|
+
routesByPath: RoutesByPath<TRouteTree>;
|
|
143
|
+
flatRoutes: AnyRoute[];
|
|
144
|
+
constructor(options: RouterConstructorOptions<TRouteTree, TDehydrated>);
|
|
145
|
+
startReactTransition: (fn: () => void) => void;
|
|
146
|
+
update: (newOptions: RouterConstructorOptions<TRouteTree, TDehydrated>) => void;
|
|
147
|
+
get state(): RouterState<TRouteTree>;
|
|
148
|
+
buildRouteTree: () => void;
|
|
149
|
+
subscribe: <TType extends keyof RouterEvents>(eventType: TType, fn: ListenerFn<RouterEvents[TType]>) => () => void;
|
|
150
|
+
emit: (routerEvent: RouterEvent) => void;
|
|
151
|
+
checkLatest: (promise: Promise<void>) => undefined | Promise<void>;
|
|
152
|
+
parseLocation: (previousLocation?: ParsedLocation) => ParsedLocation<FullSearchSchema<TRouteTree>>;
|
|
153
|
+
resolvePathWithBase: (from: string, path: string) => string;
|
|
154
|
+
get looseRoutesById(): Record<string, AnyRoute>;
|
|
155
|
+
matchRoutes: <TRouteTree_1 extends AnyRoute>(pathname: string, locationSearch: AnySearchSchema, opts?: {
|
|
156
|
+
throwOnError?: boolean;
|
|
157
|
+
debug?: boolean;
|
|
158
|
+
}) => RouteMatch<TRouteTree_1, import("./routeInfo").ParseRoute<TRouteTree_1>["id"]>[];
|
|
159
|
+
cancelMatch: (id: string) => void;
|
|
160
|
+
cancelMatches: () => void;
|
|
161
|
+
buildLocation: BuildLocationFn<TRouteTree>;
|
|
162
|
+
commitLocation: ({ startTransition, ...next }: ParsedLocation & CommitLocationOptions) => Promise<void>;
|
|
163
|
+
buildAndCommitLocation: ({ replace, resetScroll, startTransition, ...rest }?: BuildNextOptions & CommitLocationOptions) => Promise<void>;
|
|
164
|
+
navigate: NavigateFn<TRouteTree>;
|
|
165
|
+
loadMatches: ({ checkLatest, matches, preload, invalidate, }: {
|
|
166
|
+
checkLatest: () => Promise<void> | undefined;
|
|
167
|
+
matches: AnyRouteMatch[];
|
|
168
|
+
preload?: boolean | undefined;
|
|
169
|
+
invalidate?: boolean | undefined;
|
|
170
|
+
}) => Promise<RouteMatch[]>;
|
|
171
|
+
invalidate: () => Promise<void>;
|
|
172
|
+
load: (opts?: {
|
|
173
|
+
invalidate?: boolean;
|
|
174
|
+
}) => Promise<void>;
|
|
175
|
+
preloadRoute: (navigateOpts?: ToOptions<TRouteTree>) => Promise<RouteMatch<AnyRoute, any>[]>;
|
|
176
|
+
matchRoute: MatchRouteFn<TRouteTree>;
|
|
177
|
+
injectHtml: (html: string | (() => Promise<string> | string)) => Promise<void>;
|
|
178
|
+
dehydrateData: <T>(key: any, getData: T | (() => T | Promise<T>)) => () => T | undefined;
|
|
179
|
+
hydrateData: <T extends unknown = unknown>(key: any) => T | undefined;
|
|
180
|
+
dehydrate: () => DehydratedRouter;
|
|
181
|
+
hydrate: (__do_not_use_server_ctx?: HydrationCtx) => Promise<void>;
|
|
182
|
+
}
|
|
183
|
+
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]>>;
|
|
184
|
+
export declare class SearchParamError extends Error {
|
|
185
|
+
}
|
|
186
|
+
export declare class PathParamError extends Error {
|
|
187
|
+
}
|
|
188
|
+
export declare function getInitialRouterState(location: ParsedLocation): RouterState<any>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ParsedLocation } from './location';
|
|
2
|
+
export type ScrollRestorationOptions = {
|
|
3
|
+
getKey?: (location: ParsedLocation) => string;
|
|
4
|
+
};
|
|
5
|
+
export declare function useScrollRestoration(options?: ScrollRestorationOptions): void;
|
|
6
|
+
export declare function ScrollRestoration(props: ScrollRestorationOptions): null;
|
|
7
|
+
export declare function useElementScrollRestoration(options: ({
|
|
8
|
+
id: string;
|
|
9
|
+
getElement?: () => Element | undefined | null;
|
|
10
|
+
} | {
|
|
11
|
+
id?: string;
|
|
12
|
+
getElement: () => Element | undefined | null;
|
|
13
|
+
}) & {
|
|
14
|
+
getKey?: (location: ParsedLocation) => string;
|
|
15
|
+
}): {
|
|
16
|
+
scrollX: number;
|
|
17
|
+
scrollY: number;
|
|
18
|
+
} | undefined;
|
|
@@ -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,9 @@
|
|
|
1
|
+
import { ReactNode } from './route';
|
|
2
|
+
import { BlockerFn } from '@tanstack/history';
|
|
3
|
+
export declare function useBlocker(blockerFn: BlockerFn, condition?: boolean | any): void;
|
|
4
|
+
export declare function Block({ blocker, condition, children }: PromptProps): any;
|
|
5
|
+
export type PromptProps = {
|
|
6
|
+
blocker: BlockerFn;
|
|
7
|
+
condition?: boolean | any;
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { LinkOptions, NavigateOptions } from './link';
|
|
3
|
+
import { AnyRoute } from './route';
|
|
4
|
+
import { RoutePaths } from './routeInfo';
|
|
5
|
+
import { RegisteredRouter } from './router';
|
|
6
|
+
export declare function useNavigate<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TDefaultFrom extends RoutePaths<TRouteTree> = '/'>(defaultOpts?: {
|
|
7
|
+
from?: TDefaultFrom;
|
|
8
|
+
}): <TFrom extends RoutePaths<TRouteTree> = TDefaultFrom, TTo extends string = "", TMaskFrom extends RoutePaths<TRouteTree> = "/", TMaskTo extends string = "">(opts?: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> | undefined) => Promise<void>;
|
|
9
|
+
export declare function Navigate<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''>(props: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>): null;
|
|
10
|
+
export type UseLinkPropsOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''> = ActiveLinkOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
11
|
+
export type LinkProps<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''> = ActiveLinkOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'children'> & {
|
|
12
|
+
children?: React.ReactNode | ((state: {
|
|
13
|
+
isActive: boolean;
|
|
14
|
+
}) => React.ReactNode);
|
|
15
|
+
};
|
|
16
|
+
export type ActiveLinkOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''> = LinkOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
|
17
|
+
activeProps?: React.AnchorHTMLAttributes<HTMLAnchorElement> | (() => React.AnchorHTMLAttributes<HTMLAnchorElement>);
|
|
18
|
+
inactiveProps?: React.AnchorHTMLAttributes<HTMLAnchorElement> | (() => React.AnchorHTMLAttributes<HTMLAnchorElement>);
|
|
19
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AnyRoute } from './route';
|
|
2
|
+
import { RouteIds, RouteById, AllParams } from './routeInfo';
|
|
3
|
+
import { RegisteredRouter } from './router';
|
|
4
|
+
import { StrictOrFrom } from './utils';
|
|
5
|
+
export declare function useParams<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TDefaultSelected = AllParams<TRouteTree> & RouteById<TRouteTree, TFrom>['types']['allParams'], TSelected = TDefaultSelected>(opts: StrictOrFrom<TFrom> & {
|
|
6
|
+
select?: (search: TDefaultSelected) => TSelected;
|
|
7
|
+
}): TSelected;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AnyRoute } from './route';
|
|
2
|
+
import { RouteIds, RouteById } from './routeInfo';
|
|
3
|
+
import { RegisteredRouter } from './router';
|
|
4
|
+
import { StrictOrFrom } from './utils';
|
|
5
|
+
export declare function useSearch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TSearch = RouteById<TRouteTree, TFrom>['types']['fullSearchSchema'], TSelected = TSearch>(opts: StrictOrFrom<TFrom> & {
|
|
6
|
+
select?: (search: TSearch) => TSelected;
|
|
7
|
+
}): TStrict extends true ? TSelected : TSelected | undefined;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { AnyRoute } from './route';
|
|
3
|
+
import { ParseRoute, RouteIds, RoutesById, RouteById } from './routeInfo';
|
|
4
|
+
import { RegisteredRouter } from './router';
|
|
5
|
+
export type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
6
|
+
export type IsAny<T, Y, N = T> = 1 extends 0 & T ? Y : N;
|
|
7
|
+
export type IsAnyBoolean<T> = 1 extends 0 & T ? true : false;
|
|
8
|
+
export type IsKnown<T, Y, N> = unknown extends T ? N : Y;
|
|
9
|
+
export type PickAsRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
10
|
+
export type PickAsPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
11
|
+
export type PickUnsafe<T, K> = K extends keyof T ? Pick<T, K> : never;
|
|
12
|
+
export type PickExtra<T, K> = {
|
|
13
|
+
[TKey in keyof K as string extends TKey ? never : TKey extends keyof T ? never : TKey]: K[TKey];
|
|
14
|
+
};
|
|
15
|
+
export type PickRequired<T> = {
|
|
16
|
+
[K in keyof T as undefined extends T[K] ? never : K]: T[K];
|
|
17
|
+
};
|
|
18
|
+
export type Expand<T> = T extends object ? T extends infer O ? {
|
|
19
|
+
[K in keyof O]: O[K];
|
|
20
|
+
} : never : T;
|
|
21
|
+
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => any ? I : never;
|
|
22
|
+
export type Assign<Left, Right> = Omit<Left, keyof Right> & Right;
|
|
23
|
+
export type AssignAll<T extends any[]> = T extends [infer Left, ...infer Right] ? Right extends any[] ? Assign<Left, AssignAll<Right>> : Left : {};
|
|
24
|
+
export type Values<O> = O[ValueKeys<O>];
|
|
25
|
+
export type ValueKeys<O> = Extract<keyof O, PropertyKey>;
|
|
26
|
+
export type DeepAwaited<T> = T extends Promise<infer A> ? DeepAwaited<A> : T extends Record<infer A, Promise<infer B>> ? {
|
|
27
|
+
[K in A]: DeepAwaited<B>;
|
|
28
|
+
} : T;
|
|
29
|
+
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;
|
|
30
|
+
export type Timeout = ReturnType<typeof setTimeout>;
|
|
31
|
+
export type Updater<TPrevious, TResult = TPrevious> = TResult | ((prev?: TPrevious) => TResult);
|
|
32
|
+
export type NonNullableUpdater<TPrevious, TResult = TPrevious> = TResult | ((prev: TPrevious) => TResult);
|
|
33
|
+
export type PickExtract<T, U> = {
|
|
34
|
+
[K in keyof T as T[K] extends U ? K : never]: T[K];
|
|
35
|
+
};
|
|
36
|
+
export type PickExclude<T, U> = {
|
|
37
|
+
[K in keyof T as T[K] extends U ? never : K]: T[K];
|
|
38
|
+
};
|
|
39
|
+
export declare const isServer: boolean;
|
|
40
|
+
export declare function last<T>(arr: T[]): T | undefined;
|
|
41
|
+
export declare function functionalUpdate<TResult>(updater: Updater<TResult> | NonNullableUpdater<TResult>, previous: TResult): TResult;
|
|
42
|
+
export declare function pick<T, K extends keyof T>(parent: T, keys: K[]): Pick<T, K>;
|
|
43
|
+
/**
|
|
44
|
+
* This function returns `a` if `b` is deeply equal.
|
|
45
|
+
* If not, it will replace any deeply equal children of `b` with those of `a`.
|
|
46
|
+
* This can be used for structural sharing between immutable JSON values for example.
|
|
47
|
+
* Do not use this with signals
|
|
48
|
+
*/
|
|
49
|
+
export declare function replaceEqualDeep<T>(prev: any, _next: T): T;
|
|
50
|
+
export declare function isPlainObject(o: any): boolean;
|
|
51
|
+
export declare function deepEqual(a: any, b: any, partial?: boolean): boolean;
|
|
52
|
+
export declare function useStableCallback<T extends (...args: any[]) => any>(fn: T): T;
|
|
53
|
+
export declare function shallow<T>(objA: T, objB: T): boolean;
|
|
54
|
+
export type StrictOrFrom<TFrom> = {
|
|
55
|
+
from: TFrom;
|
|
56
|
+
strict?: true;
|
|
57
|
+
} | {
|
|
58
|
+
from?: never;
|
|
59
|
+
strict: false;
|
|
60
|
+
};
|
|
61
|
+
export type RouteFromIdOrRoute<T, TRouteTree extends AnyRoute = RegisteredRouter['routeTree']> = T extends ParseRoute<TRouteTree> ? T : T extends RouteIds<TRouteTree> ? RoutesById<TRouteTree>[T] : T extends string ? RouteIds<TRouteTree> : never;
|
|
62
|
+
export declare function useRouteContext<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TRouteContext = RouteById<TRouteTree, TFrom>['types']['allContext'], TSelected = TRouteContext>(opts: StrictOrFrom<TFrom> & {
|
|
63
|
+
select?: (search: TRouteContext) => TSelected;
|
|
64
|
+
}): TStrict extends true ? TSelected : TSelected | undefined;
|
|
65
|
+
export declare const useLayoutEffect: typeof React.useLayoutEffect;
|
|
66
|
+
export declare function escapeJSON(jsonString: string): string;
|