@tanstack/router-core 0.0.1-beta.5 → 0.0.1-beta.50
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/actions.js +94 -0
- package/build/cjs/actions.js.map +1 -0
- package/build/cjs/history.js +163 -0
- package/build/cjs/history.js.map +1 -0
- package/build/cjs/{packages/router-core/src/index.js → index.js} +26 -11
- package/build/cjs/{packages/router-core/src/index.js.map → index.js.map} +1 -1
- package/build/cjs/interop.js +175 -0
- package/build/cjs/interop.js.map +1 -0
- package/build/cjs/{packages/router-core/src/path.js → path.js} +23 -48
- package/build/cjs/path.js.map +1 -0
- package/build/cjs/{packages/router-core/src/qss.js → qss.js} +8 -13
- package/build/cjs/qss.js.map +1 -0
- package/build/cjs/route.js +33 -0
- package/build/cjs/route.js.map +1 -0
- package/build/cjs/{packages/router-core/src/routeConfig.js → routeConfig.js} +13 -18
- package/build/cjs/routeConfig.js.map +1 -0
- package/build/cjs/routeMatch.js +237 -0
- package/build/cjs/routeMatch.js.map +1 -0
- package/build/cjs/router.js +821 -0
- package/build/cjs/router.js.map +1 -0
- package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +10 -12
- package/build/cjs/searchParams.js.map +1 -0
- package/build/cjs/store.js +54 -0
- package/build/cjs/store.js.map +1 -0
- package/build/cjs/utils.js +47 -0
- package/build/cjs/utils.js.map +1 -0
- package/build/esm/index.js +1384 -2059
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +59 -49
- package/build/stats-react.json +248 -193
- package/build/types/index.d.ts +385 -317
- package/build/umd/index.development.js +1486 -2142
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +6 -4
- package/src/actions.ts +157 -0
- package/src/frameworks.ts +2 -2
- package/src/history.ts +199 -0
- package/src/index.ts +4 -7
- package/src/interop.ts +169 -0
- package/src/link.ts +87 -44
- package/src/path.ts +12 -8
- package/src/route.ts +36 -229
- package/src/routeConfig.ts +99 -102
- package/src/routeInfo.ts +28 -25
- package/src/routeMatch.ts +294 -322
- package/src/router.ts +1047 -884
- package/src/store.ts +52 -0
- package/src/utils.ts +14 -72
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
- package/build/cjs/node_modules/history/index.js +0 -815
- package/build/cjs/node_modules/history/index.js.map +0 -1
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
- package/build/cjs/packages/router-core/src/path.js.map +0 -1
- package/build/cjs/packages/router-core/src/qss.js.map +0 -1
- package/build/cjs/packages/router-core/src/route.js +0 -161
- package/build/cjs/packages/router-core/src/route.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeMatch.js +0 -266
- package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
- package/build/cjs/packages/router-core/src/router.js +0 -797
- package/build/cjs/packages/router-core/src/router.js.map +0 -1
- package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
- package/build/cjs/packages/router-core/src/utils.js +0 -118
- package/build/cjs/packages/router-core/src/utils.js.map +0 -1
package/build/types/index.d.ts
CHANGED
|
@@ -8,57 +8,96 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import { BrowserHistory, MemoryHistory, HashHistory, History } from 'history';
|
|
12
|
-
export { createBrowserHistory, createHashHistory, createMemoryHistory } from 'history';
|
|
13
11
|
export { default as invariant } from 'tiny-invariant';
|
|
14
12
|
|
|
13
|
+
interface RouterHistory {
|
|
14
|
+
location: RouterLocation;
|
|
15
|
+
listen: (cb: () => void) => () => void;
|
|
16
|
+
push: (path: string, state: any) => void;
|
|
17
|
+
replace: (path: string, state: any) => void;
|
|
18
|
+
go: (index: number) => void;
|
|
19
|
+
back: () => void;
|
|
20
|
+
forward: () => void;
|
|
21
|
+
}
|
|
22
|
+
interface ParsedPath {
|
|
23
|
+
href: string;
|
|
24
|
+
pathname: string;
|
|
25
|
+
search: string;
|
|
26
|
+
hash: string;
|
|
27
|
+
}
|
|
28
|
+
interface RouterLocation extends ParsedPath {
|
|
29
|
+
state: any;
|
|
30
|
+
}
|
|
31
|
+
declare function createBrowserHistory(opts?: {
|
|
32
|
+
getHref?: () => string;
|
|
33
|
+
createHref?: (path: string) => string;
|
|
34
|
+
}): RouterHistory;
|
|
35
|
+
declare function createHashHistory(): RouterHistory;
|
|
36
|
+
declare function createMemoryHistory(opts?: {
|
|
37
|
+
initialEntries: string[];
|
|
38
|
+
initialIndex?: number;
|
|
39
|
+
}): RouterHistory;
|
|
40
|
+
|
|
15
41
|
interface FrameworkGenerics {
|
|
16
42
|
}
|
|
17
|
-
|
|
43
|
+
type GetFrameworkGeneric<U> = U extends keyof FrameworkGenerics ? FrameworkGenerics[U] : any;
|
|
18
44
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
declare
|
|
25
|
-
declare
|
|
26
|
-
|
|
45
|
+
type Store<TState> = {
|
|
46
|
+
state: TState;
|
|
47
|
+
subscribe: (listener: (next: TState, prev: TState) => void) => () => void;
|
|
48
|
+
setState: (updater: (cb: TState) => void) => void;
|
|
49
|
+
};
|
|
50
|
+
declare function createStore<TState>(initialState: TState, debug?: boolean): Store<TState>;
|
|
51
|
+
declare function batch(cb: () => void): void;
|
|
52
|
+
|
|
53
|
+
type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
54
|
+
type IsAny<T, Y, N> = 1 extends 0 & T ? Y : N;
|
|
55
|
+
type IsAnyBoolean<T> = 1 extends 0 & T ? true : false;
|
|
56
|
+
type IsKnown<T, Y, N> = unknown extends T ? N : Y;
|
|
57
|
+
type PickAsRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
58
|
+
type PickAsPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
59
|
+
type PickUnsafe<T, K> = K extends keyof T ? Pick<T, K> : never;
|
|
60
|
+
type PickExtra<T, K> = Expand<{
|
|
27
61
|
[TKey in keyof K as string extends TKey ? never : TKey extends keyof T ? never : TKey]: K[TKey];
|
|
28
62
|
}>;
|
|
29
|
-
|
|
63
|
+
type PickRequired<T> = {
|
|
30
64
|
[K in keyof T as undefined extends T[K] ? never : K]: T[K];
|
|
31
65
|
};
|
|
32
|
-
|
|
66
|
+
type Expand<T> = T extends object ? T extends infer O ? {
|
|
33
67
|
[K in keyof O]: O[K];
|
|
34
68
|
} : never : T;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
69
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => any ? I : never;
|
|
70
|
+
type Values<O> = O[ValueKeys<O>];
|
|
71
|
+
type ValueKeys<O> = Extract<keyof O, PropertyKey>;
|
|
72
|
+
type DeepAwaited<T> = T extends Promise<infer A> ? DeepAwaited<A> : T extends Record<infer A, Promise<infer B>> ? {
|
|
38
73
|
[K in A]: DeepAwaited<B>;
|
|
39
74
|
} : T;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
75
|
+
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;
|
|
76
|
+
type Timeout = ReturnType<typeof setTimeout>;
|
|
77
|
+
type Updater<TPrevious, TResult = TPrevious> = TResult | ((prev?: TPrevious) => TResult);
|
|
78
|
+
type PickExtract<T, U> = {
|
|
44
79
|
[K in keyof T as T[K] extends U ? K : never]: T[K];
|
|
45
80
|
};
|
|
46
|
-
|
|
81
|
+
type PickExclude<T, U> = {
|
|
47
82
|
[K in keyof T as T[K] extends U ? never : K]: T[K];
|
|
48
83
|
};
|
|
49
|
-
/**
|
|
50
|
-
* This function returns `a` if `b` is deeply equal.
|
|
51
|
-
* If not, it will replace any deeply equal children of `b` with those of `a`.
|
|
52
|
-
* This can be used for structural sharing between JSON values for example.
|
|
53
|
-
*/
|
|
54
|
-
declare function replaceEqualDeep(prev: any, next: any): any;
|
|
55
84
|
declare function last<T>(arr: T[]): T | undefined;
|
|
56
85
|
declare function warning(cond: any, message: string): cond is true;
|
|
57
86
|
declare function functionalUpdate<TResult>(updater: Updater<TResult>, previous: TResult): TResult;
|
|
87
|
+
declare function pick<T, K extends keyof T>(parent: T, keys: K[]): Pick<T, K>;
|
|
58
88
|
|
|
89
|
+
interface RegisterRouter {
|
|
90
|
+
}
|
|
91
|
+
type AnyRouter = Router<any, any, any>;
|
|
92
|
+
type RegisteredRouter = RegisterRouter extends {
|
|
93
|
+
router: Router<infer TRouteConfig, infer TAllRouteInfo, infer TRouterContext>;
|
|
94
|
+
} ? Router<TRouteConfig, TAllRouteInfo, TRouterContext> : Router;
|
|
95
|
+
type RegisteredAllRouteInfo = RegisterRouter extends {
|
|
96
|
+
router: Router<infer TRouteConfig, infer TAllRouteInfo, infer TRouterContext>;
|
|
97
|
+
} ? TAllRouteInfo : AnyAllRouteInfo;
|
|
59
98
|
interface LocationState {
|
|
60
99
|
}
|
|
61
|
-
interface
|
|
100
|
+
interface ParsedLocation<TSearchObj extends AnySearchSchema = {}, TState extends LocationState = LocationState> {
|
|
62
101
|
href: string;
|
|
63
102
|
pathname: string;
|
|
64
103
|
search: TSearchObj;
|
|
@@ -73,11 +112,11 @@ interface FromLocation {
|
|
|
73
112
|
key?: string;
|
|
74
113
|
hash?: string;
|
|
75
114
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
interface RouterOptions<TRouteConfig extends AnyRouteConfig> {
|
|
80
|
-
history?:
|
|
115
|
+
type SearchSerializer = (searchObj: Record<string, any>) => string;
|
|
116
|
+
type SearchParser = (searchStr: string) => Record<string, any>;
|
|
117
|
+
type FilterRoutesFn = <TRoute extends Route<any, RouteInfo>>(routeConfigs: TRoute[]) => TRoute[];
|
|
118
|
+
interface RouterOptions<TRouteConfig extends AnyRouteConfig, TRouterContext> {
|
|
119
|
+
history?: RouterHistory;
|
|
81
120
|
stringifySearch?: SearchSerializer;
|
|
82
121
|
parseSearch?: SearchParser;
|
|
83
122
|
filterRoutes?: FilterRoutesFn;
|
|
@@ -85,38 +124,29 @@ interface RouterOptions<TRouteConfig extends AnyRouteConfig> {
|
|
|
85
124
|
defaultPreloadMaxAge?: number;
|
|
86
125
|
defaultPreloadGcMaxAge?: number;
|
|
87
126
|
defaultPreloadDelay?: number;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
defaultCatchElement?: GetFrameworkGeneric<'Element'>;
|
|
92
|
-
defaultPendingElement?: GetFrameworkGeneric<'Element'>;
|
|
93
|
-
defaultPendingMs?: number;
|
|
94
|
-
defaultPendingMinMs?: number;
|
|
127
|
+
defaultComponent?: GetFrameworkGeneric<'Component'>;
|
|
128
|
+
defaultErrorComponent?: GetFrameworkGeneric<'ErrorComponent'>;
|
|
129
|
+
defaultPendingComponent?: GetFrameworkGeneric<'Component'>;
|
|
95
130
|
defaultLoaderMaxAge?: number;
|
|
96
131
|
defaultLoaderGcMaxAge?: number;
|
|
97
132
|
caseSensitive?: boolean;
|
|
98
133
|
routeConfig?: TRouteConfig;
|
|
99
134
|
basepath?: string;
|
|
100
|
-
|
|
135
|
+
useServerData?: boolean;
|
|
136
|
+
createRouter?: (router: AnyRouter) => void;
|
|
101
137
|
createRoute?: (opts: {
|
|
102
138
|
route: AnyRoute;
|
|
103
|
-
router:
|
|
139
|
+
router: AnyRouter;
|
|
104
140
|
}) => void;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
current?: ActionState<TPayload, TResponse>;
|
|
110
|
-
latest?: ActionState<TPayload, TResponse>;
|
|
111
|
-
pending: ActionState<TPayload, TResponse>[];
|
|
112
|
-
}
|
|
113
|
-
interface ActionState<TPayload = unknown, TResponse = unknown> {
|
|
114
|
-
submittedAt: number;
|
|
115
|
-
status: 'idle' | 'pending' | 'success' | 'error';
|
|
116
|
-
submission: TPayload;
|
|
117
|
-
data?: TResponse;
|
|
118
|
-
error?: unknown;
|
|
141
|
+
context?: TRouterContext;
|
|
142
|
+
loadComponent?: (component: GetFrameworkGeneric<'Component'>) => Promise<GetFrameworkGeneric<'Component'>>;
|
|
143
|
+
onRouteChange?: () => void;
|
|
144
|
+
fetchServerDataFn?: FetchServerDataFn;
|
|
119
145
|
}
|
|
146
|
+
type FetchServerDataFn = (ctx: {
|
|
147
|
+
router: AnyRouter;
|
|
148
|
+
routeMatch: RouteMatch;
|
|
149
|
+
}) => Promise<any>;
|
|
120
150
|
interface Loader<TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}, TRouteLoaderData = AnyLoaderData> {
|
|
121
151
|
fetch: keyof PickRequired<TFullSearchSchema> extends never ? keyof TAllParams extends never ? (loaderContext: {
|
|
122
152
|
signal?: AbortSignal;
|
|
@@ -136,41 +166,37 @@ interface Loader<TFullSearchSchema extends AnySearchSchema = {}, TAllParams exte
|
|
|
136
166
|
latest?: LoaderState<TFullSearchSchema, TAllParams>;
|
|
137
167
|
pending: LoaderState<TFullSearchSchema, TAllParams>[];
|
|
138
168
|
}
|
|
139
|
-
interface LoaderState<TFullSearchSchema =
|
|
169
|
+
interface LoaderState<TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> {
|
|
140
170
|
loadedAt: number;
|
|
141
171
|
loaderContext: LoaderContext<TFullSearchSchema, TAllParams>;
|
|
142
172
|
}
|
|
143
|
-
interface
|
|
173
|
+
interface RouterStore<TSearchObj extends AnySearchSchema = {}, TState extends LocationState = LocationState> {
|
|
144
174
|
status: 'idle' | 'loading';
|
|
145
|
-
|
|
146
|
-
|
|
175
|
+
latestLocation: ParsedLocation<TSearchObj, TState>;
|
|
176
|
+
currentMatches: RouteMatch[];
|
|
177
|
+
currentLocation: ParsedLocation<TSearchObj, TState>;
|
|
178
|
+
pendingMatches?: RouteMatch[];
|
|
179
|
+
pendingLocation?: ParsedLocation<TSearchObj, TState>;
|
|
147
180
|
lastUpdated: number;
|
|
148
|
-
currentAction?: ActionState;
|
|
149
|
-
latestAction?: ActionState;
|
|
150
|
-
actions: Record<string, Action>;
|
|
151
181
|
loaders: Record<string, Loader>;
|
|
152
|
-
pending?: PendingState;
|
|
153
182
|
isFetching: boolean;
|
|
154
183
|
isPreloading: boolean;
|
|
184
|
+
matchCache: Record<string, MatchCacheEntry>;
|
|
155
185
|
}
|
|
156
|
-
|
|
157
|
-
location: Location;
|
|
158
|
-
matches: RouteMatch[];
|
|
159
|
-
}
|
|
160
|
-
declare type Listener = (router: Router<any, any>) => void;
|
|
161
|
-
declare type ListenerFn = () => void;
|
|
186
|
+
type ListenerFn = () => void;
|
|
162
187
|
interface BuildNextOptions {
|
|
163
188
|
to?: string | number | null;
|
|
164
|
-
params?: true | Updater<
|
|
189
|
+
params?: true | Updater<unknown>;
|
|
165
190
|
search?: true | Updater<unknown>;
|
|
166
191
|
hash?: true | Updater<string>;
|
|
192
|
+
state?: LocationState;
|
|
167
193
|
key?: string;
|
|
168
194
|
from?: string;
|
|
169
195
|
fromCurrent?: boolean;
|
|
170
196
|
__preSearchFilters?: SearchFilter<any>[];
|
|
171
197
|
__postSearchFilters?: SearchFilter<any>[];
|
|
172
198
|
}
|
|
173
|
-
|
|
199
|
+
type MatchCacheEntry = {
|
|
174
200
|
gc: number;
|
|
175
201
|
match: RouteMatch;
|
|
176
202
|
};
|
|
@@ -182,50 +208,60 @@ interface MatchLocation {
|
|
|
182
208
|
fromCurrent?: boolean;
|
|
183
209
|
}
|
|
184
210
|
interface MatchRouteOptions {
|
|
185
|
-
pending
|
|
211
|
+
pending?: boolean;
|
|
186
212
|
caseSensitive?: boolean;
|
|
213
|
+
fuzzy?: boolean;
|
|
214
|
+
}
|
|
215
|
+
interface DehydratedRouterState extends Pick<RouterStore, 'status' | 'latestLocation' | 'currentLocation' | 'lastUpdated'> {
|
|
216
|
+
currentMatches: DehydratedRouteMatch[];
|
|
217
|
+
}
|
|
218
|
+
interface DehydratedRouter<TRouterContext = unknown> {
|
|
219
|
+
state: DehydratedRouterState;
|
|
220
|
+
context: TRouterContext;
|
|
221
|
+
}
|
|
222
|
+
type MatchCache = Record<string, MatchCacheEntry>;
|
|
223
|
+
interface DehydratedRouteMatch {
|
|
224
|
+
matchId: string;
|
|
225
|
+
state: Pick<RouteMatchStore<any, any>, 'status' | 'routeLoaderData' | 'invalid' | 'invalidAt'>;
|
|
226
|
+
}
|
|
227
|
+
interface RouterContext {
|
|
187
228
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
229
|
+
declare const defaultFetchServerDataFn: FetchServerDataFn;
|
|
230
|
+
declare class Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>, TRouterContext = unknown> {
|
|
231
|
+
#private;
|
|
232
|
+
types: {
|
|
233
|
+
RouteConfig: TRouteConfig;
|
|
234
|
+
AllRouteInfo: TAllRouteInfo;
|
|
235
|
+
};
|
|
236
|
+
options: PickAsRequired<RouterOptions<TRouteConfig, TRouterContext>, 'stringifySearch' | 'parseSearch' | 'context'>;
|
|
237
|
+
history: RouterHistory;
|
|
191
238
|
basepath: string;
|
|
192
|
-
allRouteInfo: TAllRouteInfo;
|
|
193
|
-
listeners: Listener[];
|
|
194
|
-
location: Location;
|
|
195
|
-
navigateTimeout?: Timeout;
|
|
196
|
-
nextAction?: 'push' | 'replace';
|
|
197
|
-
state: RouterState;
|
|
198
239
|
routeTree: Route<TAllRouteInfo, RouteInfo>;
|
|
199
240
|
routesById: RoutesById<TAllRouteInfo>;
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}[];
|
|
241
|
+
navigateTimeout: undefined | Timeout;
|
|
242
|
+
nextAction: undefined | 'push' | 'replace';
|
|
243
|
+
navigationPromise: undefined | Promise<void>;
|
|
244
|
+
store: Store<RouterStore<TAllRouteInfo['fullSearchSchema']>>;
|
|
205
245
|
startedLoadingAt: number;
|
|
206
246
|
resolveNavigation: () => void;
|
|
207
|
-
|
|
208
|
-
|
|
247
|
+
constructor(options?: RouterOptions<TRouteConfig, TRouterContext>);
|
|
248
|
+
reset: () => void;
|
|
209
249
|
mount: () => () => void;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
buildNext: (opts: BuildNextOptions) => Location;
|
|
250
|
+
update: <TRouteConfig_1 extends RouteConfig<string, string, string, string, AnyLoaderData, AnyLoaderData, {}, AnyLoaderData, {}, {}, {}, {}, {}, {}, unknown> = RouteConfig<string, string, string, string, AnyLoaderData, AnyLoaderData, {}, AnyLoaderData, {}, {}, {}, {}, {}, {}, unknown>, TAllRouteInfo_1 extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig_1>, TRouterContext_1 = unknown>(opts?: RouterOptions<TRouteConfig_1, TRouterContext_1> | undefined) => Router<TRouteConfig_1, TAllRouteInfo_1, TRouterContext_1>;
|
|
251
|
+
buildNext: (opts: BuildNextOptions) => ParsedLocation<{}, LocationState>;
|
|
213
252
|
cancelMatches: () => void;
|
|
214
|
-
|
|
215
|
-
matchCache: Record<string, MatchCacheEntry>;
|
|
253
|
+
load: (next?: ParsedLocation) => Promise<void>;
|
|
216
254
|
cleanMatchCache: () => void;
|
|
217
|
-
getRoute: <TId extends keyof TAllRouteInfo[
|
|
218
|
-
loadRoute: (navigateOpts
|
|
219
|
-
preloadRoute: (navigateOpts: BuildNextOptions, loaderOpts: {
|
|
255
|
+
getRoute: <TId extends keyof TAllRouteInfo["routeInfoById"]>(id: TId) => Route<TAllRouteInfo, TAllRouteInfo["routeInfoById"][TId], unknown>;
|
|
256
|
+
loadRoute: (navigateOpts?: BuildNextOptions) => Promise<RouteMatch[]>;
|
|
257
|
+
preloadRoute: (navigateOpts: BuildNextOptions | undefined, loaderOpts: {
|
|
220
258
|
maxAge?: number;
|
|
221
259
|
gcMaxAge?: number;
|
|
222
|
-
}) => Promise<RouteMatch[]>;
|
|
260
|
+
}) => Promise<RouteMatch<DefaultAllRouteInfo, RouteInfo<string, string, string, "/", {}, {}, {}, {}, {}, {}, {}, {}, {}, {}>>[]>;
|
|
223
261
|
matchRoutes: (pathname: string, opts?: {
|
|
224
262
|
strictParseParams?: boolean;
|
|
225
|
-
}) => RouteMatch[];
|
|
263
|
+
}) => RouteMatch<DefaultAllRouteInfo, RouteInfo<string, string, string, "/", {}, {}, {}, {}, {}, {}, {}, {}, {}, {}>>[];
|
|
226
264
|
loadMatches: (resolvedMatches: RouteMatch[], loaderOpts?: {
|
|
227
|
-
withPending?: boolean;
|
|
228
|
-
} & ({
|
|
229
265
|
preload: true;
|
|
230
266
|
maxAge: number;
|
|
231
267
|
gcMaxAge: number;
|
|
@@ -233,71 +269,59 @@ interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInf
|
|
|
233
269
|
preload?: false;
|
|
234
270
|
maxAge?: never;
|
|
235
271
|
gcMaxAge?: never;
|
|
236
|
-
})
|
|
237
|
-
|
|
238
|
-
|
|
272
|
+
}) => Promise<void>;
|
|
273
|
+
loadMatchData: (routeMatch: RouteMatch<any, any>) => Promise<Record<string, unknown>>;
|
|
274
|
+
invalidateRoute: (opts: MatchLocation) => Promise<void>;
|
|
275
|
+
reload: () => void;
|
|
239
276
|
resolvePath: (from: string, path: string) => string;
|
|
240
|
-
navigate: <TFrom extends ValidFromPath<TAllRouteInfo> =
|
|
241
|
-
matchRoute: <TFrom extends ValidFromPath<TAllRouteInfo> =
|
|
242
|
-
buildLink: <TFrom extends ValidFromPath<TAllRouteInfo> =
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
navigate: (location: BuildNextOptions & {
|
|
249
|
-
replace?: boolean;
|
|
250
|
-
}) => Promise<void>;
|
|
251
|
-
};
|
|
277
|
+
navigate: <TFrom extends ValidFromPath<TAllRouteInfo> = "/", TTo extends string = ".">({ from, to, search, hash, replace, params, }: NavigateOptions<TAllRouteInfo, TFrom, TTo>) => Promise<void>;
|
|
278
|
+
matchRoute: <TFrom extends ValidFromPath<TAllRouteInfo> = "/", TTo extends string = ".">(location: ToOptions<TAllRouteInfo, TFrom, TTo, ResolveRelativePath<TFrom, NoInfer<TTo>>>, opts?: MatchRouteOptions) => false | TAllRouteInfo["routeInfoById"][ResolveRelativePath<TFrom, NoInfer<TTo>>]["allParams"];
|
|
279
|
+
buildLink: <TFrom extends ValidFromPath<TAllRouteInfo> = "/", TTo extends string = ".">({ from, to, search, params, hash, target, replace, activeOptions, preload, preloadMaxAge: userPreloadMaxAge, preloadGcMaxAge: userPreloadGcMaxAge, preloadDelay: userPreloadDelay, disabled, }: LinkOptions<TAllRouteInfo, TFrom, TTo>) => LinkInfo;
|
|
280
|
+
dehydrate: () => DehydratedRouter<TRouterContext>;
|
|
281
|
+
hydrate: (dehydratedRouter: DehydratedRouter<TRouterContext>) => void;
|
|
282
|
+
getLoader: <TFrom extends keyof TAllRouteInfo["routeInfoById"] = "/">(opts: {
|
|
283
|
+
from: TFrom;
|
|
284
|
+
}) => unknown extends TAllRouteInfo["routeInfoById"][TFrom]["routeLoaderData"] ? Loader<LoaderContext<TAllRouteInfo["routeInfoById"][TFrom]["fullSearchSchema"], TAllRouteInfo["routeInfoById"][TFrom]["allParams"]>, TAllRouteInfo["routeInfoById"][TFrom]["routeLoaderData"], AnyLoaderData> | undefined : Loader<TAllRouteInfo["routeInfoById"][TFrom]["fullSearchSchema"], TAllRouteInfo["routeInfoById"][TFrom]["allParams"], TAllRouteInfo["routeInfoById"][TFrom]["routeLoaderData"]>;
|
|
252
285
|
}
|
|
253
|
-
declare function createRouter<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>>(userOptions?: RouterOptions<TRouteConfig>): Router<TRouteConfig, TAllRouteInfo>;
|
|
254
286
|
|
|
255
|
-
interface
|
|
256
|
-
matchId: string;
|
|
257
|
-
pathname: string;
|
|
258
|
-
params: TRouteInfo['params'];
|
|
259
|
-
parentMatch?: RouteMatch;
|
|
260
|
-
childMatches: RouteMatch[];
|
|
287
|
+
interface RouteMatchStore<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> {
|
|
261
288
|
routeSearch: TRouteInfo['searchSchema'];
|
|
262
|
-
search: TRouteInfo['fullSearchSchema']
|
|
289
|
+
search: Expand<TAllRouteInfo['fullSearchSchema'] & TRouteInfo['fullSearchSchema']>;
|
|
263
290
|
status: 'idle' | 'loading' | 'success' | 'error';
|
|
264
291
|
updatedAt?: number;
|
|
265
292
|
error?: unknown;
|
|
266
|
-
|
|
267
|
-
getIsInvalid: () => boolean;
|
|
293
|
+
invalid: boolean;
|
|
268
294
|
loaderData: TRouteInfo['loaderData'];
|
|
269
295
|
routeLoaderData: TRouteInfo['routeLoaderData'];
|
|
270
296
|
isFetching: boolean;
|
|
271
|
-
isPending: boolean;
|
|
272
297
|
invalidAt: number;
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
298
|
+
}
|
|
299
|
+
declare class RouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> {
|
|
300
|
+
#private;
|
|
301
|
+
route: Route<TAllRouteInfo, TRouteInfo>;
|
|
302
|
+
router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>;
|
|
303
|
+
store: Store<RouteMatchStore<TAllRouteInfo, TRouteInfo>>;
|
|
304
|
+
id: string;
|
|
305
|
+
pathname: string;
|
|
306
|
+
params: TRouteInfo['allParams'];
|
|
307
|
+
component: GetFrameworkGeneric<'Component'>;
|
|
308
|
+
errorComponent: GetFrameworkGeneric<'ErrorComponent'>;
|
|
309
|
+
pendingComponent: GetFrameworkGeneric<'Component'>;
|
|
310
|
+
abortController: AbortController;
|
|
311
|
+
onLoaderDataListeners: Set<() => void>;
|
|
312
|
+
parentMatch?: RouteMatch;
|
|
313
|
+
__loadPromise?: Promise<void>;
|
|
314
|
+
__onExit?: void | ((matchContext: {
|
|
315
|
+
params: TRouteInfo['allParams'];
|
|
316
|
+
search: TRouteInfo['fullSearchSchema'];
|
|
317
|
+
}) => void);
|
|
318
|
+
constructor(router: AnyRouter, route: Route<TAllRouteInfo, TRouteInfo>, opts: {
|
|
319
|
+
matchId: string;
|
|
320
|
+
params: TRouteInfo['allParams'];
|
|
321
|
+
pathname: string;
|
|
322
|
+
});
|
|
297
323
|
cancel: () => void;
|
|
298
324
|
load: (loaderOpts?: {
|
|
299
|
-
withPending?: boolean;
|
|
300
|
-
} & ({
|
|
301
325
|
preload: true;
|
|
302
326
|
maxAge: number;
|
|
303
327
|
gcMaxAge: number;
|
|
@@ -305,129 +329,45 @@ interface RouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo
|
|
|
305
329
|
preload?: false;
|
|
306
330
|
maxAge?: never;
|
|
307
331
|
gcMaxAge?: never;
|
|
308
|
-
})
|
|
332
|
+
}) => Promise<void>;
|
|
309
333
|
fetch: (opts?: {
|
|
310
334
|
maxAge?: number;
|
|
311
335
|
}) => Promise<TRouteInfo['routeLoaderData']>;
|
|
312
|
-
invalidate: () => void
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
pathname: string;
|
|
319
|
-
}): RouteMatch<TAllRouteInfo, TRouteInfo>;
|
|
320
|
-
|
|
321
|
-
interface AnyRoute extends Route<any, any> {
|
|
322
|
-
}
|
|
323
|
-
interface Route<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> {
|
|
324
|
-
routeId: TRouteInfo['id'];
|
|
325
|
-
routeRouteId: TRouteInfo['routeId'];
|
|
326
|
-
routePath: TRouteInfo['path'];
|
|
327
|
-
fullPath: TRouteInfo['fullPath'];
|
|
328
|
-
parentRoute?: AnyRoute;
|
|
329
|
-
childRoutes?: AnyRoute[];
|
|
330
|
-
options: RouteOptions;
|
|
331
|
-
router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>;
|
|
332
|
-
buildLink: <TTo extends string = '.'>(options: Omit<LinkOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>, 'from'>) => LinkInfo;
|
|
333
|
-
matchRoute: <TTo extends string = '.', TResolved extends string = ResolveRelativePath<TRouteInfo['id'], TTo>>(matchLocation: CheckRelativePath<TAllRouteInfo, TRouteInfo['fullPath'], NoInfer<TTo>> & Omit<ToOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>, 'from'>, opts?: MatchRouteOptions) => RouteInfoByPath<TAllRouteInfo, TResolved>['allParams'];
|
|
334
|
-
navigate: <TTo extends string = '.'>(options: Omit<LinkOptions<TAllRouteInfo, TRouteInfo['id'], TTo>, 'from'>) => Promise<void>;
|
|
335
|
-
action: unknown extends TRouteInfo['actionResponse'] ? Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']> | undefined : Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']>;
|
|
336
|
-
loader: unknown extends TRouteInfo['routeLoaderData'] ? Action<LoaderContext<TRouteInfo['fullSearchSchema'], TRouteInfo['allParams']>, TRouteInfo['routeLoaderData']> | undefined : Loader<TRouteInfo['fullSearchSchema'], TRouteInfo['allParams'], TRouteInfo['routeLoaderData']>;
|
|
337
|
-
}
|
|
338
|
-
declare function createRoute<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo>(routeConfig: RouteConfig, options: TRouteInfo['options'], parent: undefined | Route<TAllRouteInfo, any>, router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>): Route<TAllRouteInfo, TRouteInfo>;
|
|
339
|
-
declare function cascadeLoaderData(matches: RouteMatch<any, any>[]): void;
|
|
340
|
-
|
|
341
|
-
interface AnyAllRouteInfo {
|
|
342
|
-
routeConfig: AnyRouteConfig;
|
|
343
|
-
routeInfo: AnyRouteInfo;
|
|
344
|
-
routeInfoById: Record<string, AnyRouteInfo>;
|
|
345
|
-
routeInfoByFullPath: Record<string, AnyRouteInfo>;
|
|
346
|
-
routeIds: any;
|
|
347
|
-
routePaths: any;
|
|
348
|
-
}
|
|
349
|
-
interface DefaultAllRouteInfo {
|
|
350
|
-
routeConfig: RouteConfig;
|
|
351
|
-
routeInfo: RouteInfo;
|
|
352
|
-
routeInfoById: Record<string, RouteInfo>;
|
|
353
|
-
routeInfoByFullPath: Record<string, RouteInfo>;
|
|
354
|
-
routeIds: string;
|
|
355
|
-
routePaths: string;
|
|
356
|
-
}
|
|
357
|
-
interface AllRouteInfo<TRouteConfig extends AnyRouteConfig = RouteConfig> extends RoutesInfoInner<TRouteConfig, ParseRouteConfig<TRouteConfig>> {
|
|
358
|
-
}
|
|
359
|
-
declare type ParseRouteConfig<TRouteConfig = AnyRouteConfig> = TRouteConfig extends AnyRouteConfig ? RouteConfigRoute<TRouteConfig> | ParseRouteChildren<TRouteConfig> : never;
|
|
360
|
-
declare type ParseRouteChildren<TRouteConfig> = TRouteConfig extends AnyRouteConfigWithChildren<infer TChildren> ? unknown extends TChildren ? never : TChildren extends AnyRouteConfig[] ? Values<{
|
|
361
|
-
[TId in TChildren[number]['id']]: ParseRouteChild<TChildren[number], TId>;
|
|
362
|
-
}> : never : never;
|
|
363
|
-
declare type ParseRouteChild<TRouteConfig, TId> = TRouteConfig & {
|
|
364
|
-
id: TId;
|
|
365
|
-
} extends AnyRouteConfig ? ParseRouteConfig<TRouteConfig> : never;
|
|
366
|
-
declare type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<infer TId, infer TRouteId, infer TPath, infer TFullPath, infer TRouteLoaderData, infer TLoaderData, infer TActionPayload, infer TActionResponse, infer TParentSearchSchema, infer TSearchSchema, infer TFullSearchSchema, infer TParentParams, infer TParams, infer TAllParams, any> ? string extends TRouteId ? never : RouteInfo<TId, TRouteId, TPath, TFullPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams> : never;
|
|
367
|
-
interface RoutesInfoInner<TRouteConfig extends AnyRouteConfig, TRouteInfo extends RouteInfo<string, string, any, any, any, any, any, any, any, any, any, any, any, any> = RouteInfo, TRouteInfoById = {
|
|
368
|
-
[TInfo in TRouteInfo as TInfo['id']]: TInfo;
|
|
369
|
-
}, TRouteInfoByFullPath = {
|
|
370
|
-
[TInfo in TRouteInfo as TInfo['fullPath'] extends RootRouteId ? never : string extends TInfo['fullPath'] ? never : TInfo['fullPath']]: TInfo;
|
|
371
|
-
}> {
|
|
372
|
-
routeConfig: TRouteConfig;
|
|
373
|
-
routeInfo: TRouteInfo;
|
|
374
|
-
routeInfoById: TRouteInfoById;
|
|
375
|
-
routeInfoByFullPath: TRouteInfoByFullPath;
|
|
376
|
-
routeIds: keyof TRouteInfoById;
|
|
377
|
-
routePaths: keyof TRouteInfoByFullPath;
|
|
378
|
-
}
|
|
379
|
-
interface AnyRouteInfo extends RouteInfo<any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
380
|
-
}
|
|
381
|
-
interface RouteInfo<TId extends string = string, TRouteId extends string = string, TPath extends string = string, TFullPath extends string = string, TRouteLoaderData extends AnyLoaderData = {}, TLoaderData extends AnyLoaderData = {}, TActionPayload = unknown, TActionResponse = unknown, TParentSearchSchema extends {} = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = {}, TParentParams extends AnyPathParams = {}, TParams extends Record<ParsePathParams<TPath>, unknown> = Record<ParsePathParams<TPath>, string>, TAllParams extends AnyPathParams = {}> {
|
|
382
|
-
id: TId;
|
|
383
|
-
routeId: TRouteId;
|
|
384
|
-
path: TPath;
|
|
385
|
-
fullPath: TFullPath;
|
|
386
|
-
routeLoaderData: TRouteLoaderData;
|
|
387
|
-
loaderData: TLoaderData;
|
|
388
|
-
actionPayload: TActionPayload;
|
|
389
|
-
actionResponse: TActionResponse;
|
|
390
|
-
searchSchema: TSearchSchema;
|
|
391
|
-
fullSearchSchema: TFullSearchSchema;
|
|
392
|
-
parentParams: TParentParams;
|
|
393
|
-
params: TParams;
|
|
394
|
-
allParams: TAllParams;
|
|
395
|
-
options: RouteOptions<TRouteId, TPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
|
|
336
|
+
invalidate: () => Promise<void>;
|
|
337
|
+
__hasLoaders: () => boolean;
|
|
338
|
+
getIsInvalid: () => boolean;
|
|
339
|
+
__setParentMatch: (parentMatch?: RouteMatch) => void;
|
|
340
|
+
__onLoaderData: (listener: () => void) => void;
|
|
341
|
+
__validate: () => void;
|
|
396
342
|
}
|
|
397
|
-
declare type RoutesById<TAllRouteInfo extends AnyAllRouteInfo> = {
|
|
398
|
-
[K in keyof TAllRouteInfo['routeInfoById']]: Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][K]>;
|
|
399
|
-
};
|
|
400
|
-
declare type RouteInfoById<TAllRouteInfo extends AnyAllRouteInfo, TId> = TId extends keyof TAllRouteInfo['routeInfoById'] ? IsAny<TAllRouteInfo['routeInfoById'][TId]['id'], RouteInfo, TAllRouteInfo['routeInfoById'][TId]> : never;
|
|
401
|
-
declare type RouteInfoByPath<TAllRouteInfo extends AnyAllRouteInfo, TPath> = TPath extends keyof TAllRouteInfo['routeInfoByFullPath'] ? IsAny<TAllRouteInfo['routeInfoByFullPath'][TPath]['id'], RouteInfo, TAllRouteInfo['routeInfoByFullPath'][TPath]> : never;
|
|
402
343
|
|
|
403
344
|
declare const rootRouteId: "__root__";
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
345
|
+
type RootRouteId = typeof rootRouteId;
|
|
346
|
+
type AnyLoaderData = {};
|
|
347
|
+
type AnyPathParams = {};
|
|
348
|
+
type AnySearchSchema = {};
|
|
408
349
|
interface RouteMeta {
|
|
409
350
|
}
|
|
410
|
-
|
|
411
|
-
|
|
351
|
+
type SearchSchemaValidator<TReturn, TParentSchema> = SearchSchemaValidatorObj<TReturn, TParentSchema> | SearchSchemaValidatorFn<TReturn, TParentSchema>;
|
|
352
|
+
type SearchSchemaValidatorObj<TReturn, TParentSchema> = {
|
|
412
353
|
parse?: SearchSchemaValidatorFn<TReturn, TParentSchema>;
|
|
413
354
|
};
|
|
414
|
-
|
|
355
|
+
type SearchSchemaValidatorFn<TReturn, TParentSchema> = (searchObj: Record<string, unknown>) => {} extends TParentSchema ? TReturn : keyof TReturn extends keyof TParentSchema ? {
|
|
415
356
|
error: 'Top level search params cannot be redefined by child routes!';
|
|
416
357
|
keys: keyof TReturn & keyof TParentSchema;
|
|
417
358
|
} : TReturn;
|
|
418
|
-
|
|
419
|
-
|
|
359
|
+
type DefinedPathParamWarning = 'Path params cannot be redefined by child routes!';
|
|
360
|
+
type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
|
|
420
361
|
[Key in keyof TParentParams]?: DefinedPathParamWarning;
|
|
421
362
|
};
|
|
422
|
-
|
|
363
|
+
type LoaderFn<TRouteLoaderData extends AnyLoaderData = {}, TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> = (loaderContext: LoaderContext<TFullSearchSchema, TAllParams>) => TRouteLoaderData | Promise<TRouteLoaderData>;
|
|
423
364
|
interface LoaderContext<TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> {
|
|
424
365
|
params: TAllParams;
|
|
425
366
|
search: TFullSearchSchema;
|
|
426
367
|
signal?: AbortSignal;
|
|
427
368
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
declare type RouteOptions<TRouteId extends string = string, TPath extends string = string, TRouteLoaderData extends AnyLoaderData = {}, TLoaderData extends AnyLoaderData = {}, TActionPayload = unknown, TActionResponse = unknown, TParentSearchSchema extends {} = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = TSearchSchema, TParentParams extends AnyPathParams = {}, TParams extends Record<ParsePathParams<TPath>, unknown> = Record<ParsePathParams<TPath>, string>, TAllParams extends AnyPathParams = {}> = ({
|
|
369
|
+
type UnloaderFn<TPath extends string> = (routeMatch: RouteMatch<any, RouteInfo<string, TPath>>) => void;
|
|
370
|
+
type RouteOptions<TRouteId extends string = string, TPath extends string = string, TParentRouteLoaderData extends AnyLoaderData = {}, TRouteLoaderData extends AnyLoaderData = {}, TParentLoaderData extends AnyLoaderData = {}, TLoaderData extends AnyLoaderData = {}, TParentSearchSchema extends {} = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = TSearchSchema, TParentParams extends AnyPathParams = {}, TParams extends Record<ParsePathParams<TPath>, unknown> = Record<ParsePathParams<TPath>, string>, TAllParams extends AnyPathParams = {}> = ({
|
|
431
371
|
path: TPath;
|
|
432
372
|
} | {
|
|
433
373
|
id: TRouteId;
|
|
@@ -436,18 +376,18 @@ declare type RouteOptions<TRouteId extends string = string, TPath extends string
|
|
|
436
376
|
validateSearch?: SearchSchemaValidator<TSearchSchema, TParentSearchSchema>;
|
|
437
377
|
preSearchFilters?: SearchFilter<TFullSearchSchema>[];
|
|
438
378
|
postSearchFilters?: SearchFilter<TFullSearchSchema>[];
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
errorElement?: GetFrameworkGeneric<'SyncOrAsyncElement'>;
|
|
443
|
-
catchElement?: GetFrameworkGeneric<'SyncOrAsyncElement'>;
|
|
444
|
-
pendingElement?: GetFrameworkGeneric<'SyncOrAsyncElement'>;
|
|
379
|
+
component?: GetFrameworkGeneric<'Component'>;
|
|
380
|
+
errorComponent?: GetFrameworkGeneric<'ErrorComponent'>;
|
|
381
|
+
pendingComponent?: GetFrameworkGeneric<'Component'>;
|
|
445
382
|
loader?: LoaderFn<TRouteLoaderData, TFullSearchSchema, TAllParams>;
|
|
446
383
|
loaderMaxAge?: number;
|
|
447
384
|
loaderGcMaxAge?: number;
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
385
|
+
beforeLoad?: (opts: {
|
|
386
|
+
router: AnyRouter;
|
|
387
|
+
match: RouteMatch;
|
|
388
|
+
}) => Promise<void> | void;
|
|
389
|
+
onLoadError?: (err: any) => void;
|
|
390
|
+
onLoaded?: (matchContext: {
|
|
451
391
|
params: TAllParams;
|
|
452
392
|
search: TFullSearchSchema;
|
|
453
393
|
}) => void | undefined | ((match: {
|
|
@@ -466,44 +406,130 @@ declare type RouteOptions<TRouteId extends string = string, TPath extends string
|
|
|
466
406
|
parseParams: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams;
|
|
467
407
|
stringifyParams: (params: TParams) => Record<ParsePathParams<TPath>, string>;
|
|
468
408
|
}) & (PickUnsafe<TParentParams, ParsePathParams<TPath>> extends never ? {} : 'Cannot redefined path params in child routes!');
|
|
469
|
-
|
|
470
|
-
interface RouteConfig<TId extends string = string, TRouteId extends string = string, TPath extends string = string, TFullPath extends string = string,
|
|
409
|
+
type SearchFilter<T, U = T> = (prev: T) => U;
|
|
410
|
+
interface RouteConfig<TId extends string = string, TRouteId extends string = string, TPath extends string = string, TFullPath extends string = string, TParentRouteLoaderData extends AnyLoaderData = AnyLoaderData, TRouteLoaderData extends AnyLoaderData = AnyLoaderData, TParentLoaderData extends AnyLoaderData = {}, TLoaderData extends AnyLoaderData = AnyLoaderData, TParentSearchSchema extends {} = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = {}, TParentParams extends AnyPathParams = {}, TParams extends AnyPathParams = {}, TAllParams extends AnyPathParams = {}, TKnownChildren = unknown> {
|
|
471
411
|
id: TId;
|
|
472
412
|
routeId: TRouteId;
|
|
473
413
|
path: NoInfer<TPath>;
|
|
474
414
|
fullPath: TFullPath;
|
|
475
|
-
options: RouteOptions<TRouteId, TPath,
|
|
415
|
+
options: RouteOptions<TRouteId, TPath, TParentRouteLoaderData, TRouteLoaderData, TParentLoaderData, TLoaderData, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
|
|
476
416
|
children?: TKnownChildren;
|
|
477
417
|
addChildren: IsAny<TId, any, <TNewChildren extends any>(children: TNewChildren extends AnyRouteConfig[] ? TNewChildren : {
|
|
478
418
|
error: 'Invalid route detected';
|
|
479
419
|
route: TNewChildren;
|
|
480
|
-
}) => RouteConfig<TId, TRouteId, TPath, TFullPath,
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
route: TNewChildren;
|
|
484
|
-
}) => RouteConfig<TId, TRouteId, TPath, TFullPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams, TNewChildren>>;
|
|
485
|
-
createRoute: CreateRouteConfigFn<false, TId, TFullPath, TLoaderData, TFullSearchSchema, TAllParams>;
|
|
420
|
+
}) => RouteConfig<TId, TRouteId, TPath, TFullPath, TParentRouteLoaderData, TRouteLoaderData, TParentLoaderData, TLoaderData, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams, TNewChildren>>;
|
|
421
|
+
createRoute: CreateRouteConfigFn<false, TId, TFullPath, TRouteLoaderData, TLoaderData, TFullSearchSchema, TAllParams>;
|
|
422
|
+
generate: GenerateFn<TRouteId, TPath, TParentRouteLoaderData, TParentLoaderData, TParentSearchSchema, TParentParams>;
|
|
486
423
|
}
|
|
487
|
-
|
|
424
|
+
type GenerateFn<TRouteId extends string = string, TPath extends string = string, TParentRouteLoaderData extends AnyLoaderData = AnyLoaderData, TParentLoaderData extends AnyLoaderData = {}, TParentSearchSchema extends {} = {}, TParentParams extends AnyPathParams = {}> = <TRouteLoaderData extends AnyLoaderData = AnyLoaderData, TSearchSchema extends AnySearchSchema = {}, TParams extends Record<ParsePathParams<TPath>, unknown> = Record<ParsePathParams<TPath>, string>, TAllParams extends AnyPathParams extends TParams ? Record<ParsePathParams<TPath>, string> : NoInfer<TParams> = AnyPathParams extends TParams ? Record<ParsePathParams<TPath>, string> : NoInfer<TParams>>(options: Omit<RouteOptions<TRouteId, TPath, TParentRouteLoaderData, TRouteLoaderData, TParentLoaderData, Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>>, 'path'>) => void;
|
|
425
|
+
type CreateRouteConfigFn<TIsRoot extends boolean = false, TParentId extends string = string, TParentPath extends string = string, TParentRouteLoaderData extends AnyLoaderData = {}, TParentLoaderData extends AnyLoaderData = {}, TParentSearchSchema extends AnySearchSchema = {}, TParentParams extends AnyPathParams = {}> = <TRouteId extends string, TPath extends string, TRouteLoaderData extends AnyLoaderData, TSearchSchema extends AnySearchSchema = AnySearchSchema, TParams extends Record<ParsePathParams<TPath>, unknown> = Record<ParsePathParams<TPath>, string>, TAllParams extends AnyPathParams extends TParams ? Record<ParsePathParams<TPath>, string> : NoInfer<TParams> = AnyPathParams extends TParams ? Record<ParsePathParams<TPath>, string> : NoInfer<TParams>, TKnownChildren extends RouteConfig[] = RouteConfig[], TResolvedId extends string = string extends TRouteId ? string extends TPath ? string : TPath : TRouteId>(options?: TIsRoot extends true ? Omit<RouteOptions<TRouteId, TPath, TParentRouteLoaderData, TRouteLoaderData, TParentLoaderData, Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>>, 'path'> & {
|
|
488
426
|
path?: never;
|
|
489
|
-
} : RouteOptions<TRouteId, TPath, TRouteLoaderData, Expand<
|
|
490
|
-
|
|
491
|
-
|
|
427
|
+
} : RouteOptions<TRouteId, TPath, TParentRouteLoaderData, TRouteLoaderData, TParentLoaderData, Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>>, children?: TKnownChildren, isRoot?: boolean, parentId?: string, parentPath?: string) => RouteConfig<RoutePrefix<TParentId, TResolvedId>, TResolvedId, TPath, string extends TPath ? '' : RoutePath<RoutePrefix<TParentPath, TPath>>, TParentRouteLoaderData, TRouteLoaderData, TParentLoaderData, Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>, TKnownChildren>;
|
|
428
|
+
type RoutePath<T extends string> = T extends RootRouteId ? '/' : TrimPathRight<`${T}`>;
|
|
429
|
+
type RoutePrefix<TPrefix extends string, TId extends string> = string extends TId ? RootRouteId : TId extends string ? `${TPrefix}/${TId}` extends '/' ? '/' : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TId>}`>}` : never;
|
|
492
430
|
interface AnyRouteConfig extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
493
431
|
}
|
|
494
432
|
interface AnyRouteConfigWithChildren<TChildren> extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any, any, TChildren> {
|
|
495
433
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
434
|
+
type TrimPath<T extends string> = '' extends T ? '' : TrimPathRight<TrimPathLeft<T>>;
|
|
435
|
+
type TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}` ? TrimPathLeft<U> : T extends `/${infer U}` ? TrimPathLeft<U> : T;
|
|
436
|
+
type TrimPathRight<T extends string> = T extends '/' ? '/' : T extends `${infer U}/` ? TrimPathRight<U> : T;
|
|
499
437
|
declare const createRouteConfig: CreateRouteConfigFn<true>;
|
|
500
438
|
|
|
501
|
-
|
|
439
|
+
interface AnyRoute extends Route<any, any, any> {
|
|
440
|
+
}
|
|
441
|
+
declare class Route<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo, TRouterContext = unknown> {
|
|
442
|
+
routeInfo: TRouteInfo;
|
|
443
|
+
id: TRouteInfo['id'];
|
|
444
|
+
customId: TRouteInfo['customId'];
|
|
445
|
+
path: TRouteInfo['path'];
|
|
446
|
+
fullPath: TRouteInfo['fullPath'];
|
|
447
|
+
getParentRoute: () => undefined | AnyRoute;
|
|
448
|
+
childRoutes?: AnyRoute[];
|
|
449
|
+
options: RouteOptions;
|
|
450
|
+
originalIndex: number;
|
|
451
|
+
getRouter: () => Router<TAllRouteInfo['routeConfig'], TAllRouteInfo, TRouterContext>;
|
|
452
|
+
constructor(routeConfig: RouteConfig, options: TRouteInfo['options'], originalIndex: number, parent: undefined | Route<TAllRouteInfo, any>, router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo, TRouterContext>);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
interface AnyAllRouteInfo {
|
|
456
|
+
routeConfig: AnyRouteConfig;
|
|
457
|
+
routeInfo: AnyRouteInfo;
|
|
458
|
+
routeInfoById: Record<string, AnyRouteInfo>;
|
|
459
|
+
routeInfoByFullPath: Record<string, AnyRouteInfo>;
|
|
460
|
+
routeIds: any;
|
|
461
|
+
routePaths: any;
|
|
462
|
+
fullSearchSchema: Record<string, any>;
|
|
463
|
+
allParams: Record<string, any>;
|
|
464
|
+
}
|
|
465
|
+
interface DefaultAllRouteInfo {
|
|
466
|
+
routeConfig: RouteConfig;
|
|
467
|
+
routeInfo: RouteInfo;
|
|
468
|
+
routeInfoById: Record<string, RouteInfo>;
|
|
469
|
+
routeInfoByFullPath: Record<string, RouteInfo>;
|
|
470
|
+
routeIds: string;
|
|
471
|
+
routePaths: string;
|
|
472
|
+
fullSearchSchema: AnySearchSchema;
|
|
473
|
+
allParams: AnyPathParams;
|
|
474
|
+
}
|
|
475
|
+
interface AllRouteInfo<TRouteConfig extends AnyRouteConfig = RouteConfig> extends RoutesInfoInner<TRouteConfig, ParseRouteConfig<TRouteConfig>> {
|
|
476
|
+
}
|
|
477
|
+
type ParseRouteConfig<TRouteConfig = AnyRouteConfig> = TRouteConfig extends AnyRouteConfig ? RouteConfigRoute<TRouteConfig> | ParseRouteChildren<TRouteConfig> : never;
|
|
478
|
+
type ParseRouteChildren<TRouteConfig> = TRouteConfig extends AnyRouteConfigWithChildren<infer TChildren> ? unknown extends TChildren ? never : TChildren extends AnyRouteConfig[] ? Values<{
|
|
479
|
+
[TId in TChildren[number]['id']]: ParseRouteChild<TChildren[number], TId>;
|
|
480
|
+
}> : never : never;
|
|
481
|
+
type ParseRouteChild<TRouteConfig, TId> = TRouteConfig & {
|
|
482
|
+
id: TId;
|
|
483
|
+
} extends AnyRouteConfig ? ParseRouteConfig<TRouteConfig> : never;
|
|
484
|
+
type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<infer TId, infer TCustomId, infer TPath, infer TFullPath, infer TParentRouteLoaderData, infer TRouteLoaderData, infer TParentLoaderData, infer TLoaderData, infer TParentSearchSchema, infer TSearchSchema, infer TFullSearchSchema, infer TParentParams, infer TParams, infer TAllParams, any> ? string extends TCustomId ? never : RouteInfo<TId, TCustomId, TPath, TFullPath, TParentRouteLoaderData, TRouteLoaderData, TParentLoaderData, TLoaderData, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams> : never;
|
|
485
|
+
interface RoutesInfoInner<TRouteConfig extends AnyRouteConfig, TRouteInfo extends RouteInfo<string, string, any, any, any, any, any, any, any, any, any, any, any, any> = RouteInfo, TRouteInfoById = {
|
|
486
|
+
'/': TRouteInfo;
|
|
487
|
+
} & {
|
|
488
|
+
[TInfo in TRouteInfo as TInfo['id']]: TInfo;
|
|
489
|
+
}, TRouteInfoByFullPath = {
|
|
490
|
+
'/': TRouteInfo;
|
|
491
|
+
} & {
|
|
492
|
+
[TInfo in TRouteInfo as TInfo['fullPath'] extends RootRouteId ? never : string extends TInfo['fullPath'] ? never : TInfo['fullPath']]: TInfo;
|
|
493
|
+
}> {
|
|
494
|
+
routeConfig: TRouteConfig;
|
|
495
|
+
routeInfo: TRouteInfo;
|
|
496
|
+
routeInfoById: TRouteInfoById;
|
|
497
|
+
routeInfoByFullPath: TRouteInfoByFullPath;
|
|
498
|
+
routeIds: keyof TRouteInfoById;
|
|
499
|
+
routePaths: keyof TRouteInfoByFullPath;
|
|
500
|
+
fullSearchSchema: Partial<UnionToIntersection<TRouteInfo['fullSearchSchema']>>;
|
|
501
|
+
allParams: Partial<UnionToIntersection<TRouteInfo['allParams']>>;
|
|
502
|
+
}
|
|
503
|
+
interface AnyRouteInfo extends RouteInfo<any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
504
|
+
}
|
|
505
|
+
interface RouteInfo<TId extends string = string, TCustomId extends string = string, TPath extends string = string, TFullPath extends string = '/', TParentRouteLoaderData extends AnyLoaderData = {}, TRouteLoaderData extends AnyLoaderData = {}, TParentLoaderData extends AnyLoaderData = {}, TLoaderData extends AnyLoaderData = {}, TParentSearchSchema extends {} = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = {}, TParentParams extends AnyPathParams = {}, TParams extends AnyPathParams = {}, TAllParams extends AnyPathParams = {}> {
|
|
506
|
+
id: TId;
|
|
507
|
+
customId: TCustomId;
|
|
508
|
+
path: TPath;
|
|
509
|
+
fullPath: TFullPath;
|
|
510
|
+
parentRouteLoaderData: TParentRouteLoaderData;
|
|
511
|
+
routeLoaderData: TRouteLoaderData;
|
|
512
|
+
parentLoaderData: TParentLoaderData;
|
|
513
|
+
loaderData: TLoaderData;
|
|
514
|
+
searchSchema: TSearchSchema;
|
|
515
|
+
fullSearchSchema: TFullSearchSchema;
|
|
516
|
+
parentParams: TParentParams;
|
|
517
|
+
params: TParams;
|
|
518
|
+
allParams: TAllParams;
|
|
519
|
+
options: RouteOptions<TCustomId, TPath, TParentRouteLoaderData, TRouteLoaderData, TParentLoaderData, TLoaderData, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
|
|
520
|
+
}
|
|
521
|
+
type RoutesById<TAllRouteInfo extends AnyAllRouteInfo> = {
|
|
522
|
+
[K in keyof TAllRouteInfo['routeInfoById']]: Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][K]>;
|
|
523
|
+
};
|
|
524
|
+
type RouteInfoById<TAllRouteInfo extends AnyAllRouteInfo, TId> = TId extends keyof TAllRouteInfo['routeInfoById'] ? IsAny<TAllRouteInfo['routeInfoById'][TId]['id'], RouteInfo, TAllRouteInfo['routeInfoById'][TId]> : never;
|
|
525
|
+
type RouteInfoByPath<TAllRouteInfo extends AnyAllRouteInfo, TPath> = TPath extends keyof TAllRouteInfo['routeInfoByFullPath'] ? IsAny<TAllRouteInfo['routeInfoByFullPath'][TPath]['id'], RouteInfo, TAllRouteInfo['routeInfoByFullPath'][TPath]> : never;
|
|
526
|
+
|
|
527
|
+
type LinkInfo = {
|
|
502
528
|
type: 'external';
|
|
503
529
|
href: string;
|
|
504
530
|
} | {
|
|
505
531
|
type: 'internal';
|
|
506
|
-
next:
|
|
532
|
+
next: ParsedLocation;
|
|
507
533
|
handleFocus: (e: any) => void;
|
|
508
534
|
handleClick: (e: any) => void;
|
|
509
535
|
handleEnter: (e: any) => void;
|
|
@@ -511,12 +537,11 @@ declare type LinkInfo = {
|
|
|
511
537
|
isActive: boolean;
|
|
512
538
|
disabled?: boolean;
|
|
513
539
|
};
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
declare type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends string, TTo extends string, SplitPaths extends string[] = Split<AllPaths, false>> = TTo extends `..${infer _}` ? SplitPaths extends [
|
|
540
|
+
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;
|
|
541
|
+
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;
|
|
542
|
+
type ParsePathParams<T extends string> = Split<T>[number] extends infer U ? U extends `$${infer V}` ? V : never : never;
|
|
543
|
+
type Join<T> = T extends [] ? '' : T extends [infer L extends string] ? L : T extends [infer L extends string, ...infer Tail extends [...string[]]] ? CleanPath<`${L}/${Join<Tail>}`> : never;
|
|
544
|
+
type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends string, TTo extends string, SplitPaths extends string[] = Split<AllPaths, false>> = TTo extends `..${infer _}` ? SplitPaths extends [
|
|
520
545
|
...Split<ResolveRelativePath<TFrom, TTo>, false>,
|
|
521
546
|
...infer TToRest
|
|
522
547
|
] ? `${CleanPath<Join<[
|
|
@@ -526,40 +551,39 @@ declare type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends s
|
|
|
526
551
|
...Split<TFrom, false>,
|
|
527
552
|
...Split<RestTTo, false>,
|
|
528
553
|
...infer RestPath
|
|
529
|
-
] ? `${TTo}${Join<RestPath>}` : never :
|
|
530
|
-
|
|
554
|
+
] ? `${TTo}${Join<RestPath>}` : never : (TFrom extends `/` ? never : SplitPaths extends [...Split<TFrom, false>, ...infer RestPath] ? Join<RestPath> extends {
|
|
555
|
+
length: 0;
|
|
556
|
+
} ? never : './' : never) | (TFrom extends `/` ? never : '../') | AllPaths;
|
|
557
|
+
type NavigateOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends TAllRouteInfo['routePaths'] = '/', TTo extends string = '.'> = ToOptions<TAllRouteInfo, TFrom, TTo> & {
|
|
531
558
|
replace?: boolean;
|
|
532
559
|
};
|
|
533
|
-
|
|
560
|
+
type ToOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends TAllRouteInfo['routePaths'] = '/', TTo extends string = '.', TResolvedTo = ResolveRelativePath<TFrom, NoInfer<TTo>>> = {
|
|
534
561
|
to?: ToPathOption<TAllRouteInfo, TFrom, TTo>;
|
|
535
562
|
hash?: Updater<string>;
|
|
563
|
+
state?: LocationState;
|
|
536
564
|
from?: TFrom;
|
|
537
565
|
} & CheckPath<TAllRouteInfo, NoInfer<TResolvedTo>, {}> & SearchParamOptions<TAllRouteInfo, TFrom, TResolvedTo> & PathParamOptions<TAllRouteInfo, TFrom, TResolvedTo>;
|
|
538
|
-
|
|
539
|
-
search?: SearchReducer<
|
|
540
|
-
} : keyof PickRequired<TToSchema> extends never ? {
|
|
541
|
-
search?: SearchReducer<TFromSchema, TToSchema>;
|
|
566
|
+
type SearchParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromSchema = Expand<UnionToIntersection<TAllRouteInfo['fullSearchSchema'] & RouteInfoByPath<TAllRouteInfo, TFrom> extends never ? {} : RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema']>>, TToSchema = Partial<RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema']> & Omit<RouteInfoByPath<TAllRouteInfo, TTo>['fullSearchSchema'], keyof PickRequired<RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema']>>, TFromFullSchema = Expand<UnionToIntersection<TAllRouteInfo['fullSearchSchema'] & TFromSchema>>, TToFullSchema = Expand<UnionToIntersection<TAllRouteInfo['fullSearchSchema'] & TToSchema>>> = keyof PickRequired<TToSchema> extends never ? {
|
|
567
|
+
search?: true | SearchReducer<TFromFullSchema, TToFullSchema>;
|
|
542
568
|
} : {
|
|
543
|
-
search: SearchReducer<
|
|
569
|
+
search: SearchReducer<TFromFullSchema, TToFullSchema>;
|
|
544
570
|
};
|
|
545
|
-
|
|
571
|
+
type SearchReducer<TFrom, TTo> = {
|
|
546
572
|
[TKey in keyof TTo]: TTo[TKey];
|
|
547
573
|
} | ((current: TFrom) => TTo);
|
|
548
|
-
|
|
549
|
-
params?: ParamsReducer<
|
|
550
|
-
} : AnyPathParams extends TToParams ? {
|
|
551
|
-
params?: ParamsReducer<TFromParams, Record<string, never>>;
|
|
574
|
+
type PathParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromSchema = Expand<UnionToIntersection<RouteInfoByPath<TAllRouteInfo, TFrom> extends never ? {} : RouteInfoByPath<TAllRouteInfo, TFrom>['allParams']>>, TToSchema = Partial<RouteInfoByPath<TAllRouteInfo, TFrom>['allParams']> & Omit<RouteInfoByPath<TAllRouteInfo, TTo>['allParams'], keyof PickRequired<RouteInfoByPath<TAllRouteInfo, TFrom>['allParams']>>, TFromFullParams = Expand<UnionToIntersection<TAllRouteInfo['allParams'] & TFromSchema>>, TToFullParams = Expand<UnionToIntersection<TAllRouteInfo['allParams'] & TToSchema>>> = keyof PickRequired<TToSchema> extends never ? {
|
|
575
|
+
params?: ParamsReducer<TFromFullParams, TToFullParams>;
|
|
552
576
|
} : {
|
|
553
|
-
params: ParamsReducer<
|
|
577
|
+
params: ParamsReducer<TFromFullParams, TToFullParams>;
|
|
554
578
|
};
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
579
|
+
type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
|
|
580
|
+
type ToPathOption<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends TAllRouteInfo['routePaths'] = '/', TTo extends string = '.'> = TTo | RelativeToPathAutoComplete<TAllRouteInfo['routePaths'], NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
|
|
581
|
+
type ToIdOption<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends TAllRouteInfo['routePaths'] = '/', TTo extends string = '.'> = TTo | RelativeToPathAutoComplete<TAllRouteInfo['routeIds'], NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
|
|
558
582
|
interface ActiveOptions {
|
|
559
583
|
exact?: boolean;
|
|
560
584
|
includeHash?: boolean;
|
|
561
585
|
}
|
|
562
|
-
|
|
586
|
+
type LinkOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends TAllRouteInfo['routePaths'] = '/', TTo extends string = '.'> = NavigateOptions<TAllRouteInfo, TFrom, TTo> & {
|
|
563
587
|
target?: HTMLAnchorElement['target'];
|
|
564
588
|
activeOptions?: ActiveOptions;
|
|
565
589
|
preload?: false | 'intent';
|
|
@@ -568,22 +592,22 @@ declare type LinkOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRoute
|
|
|
568
592
|
preloadDelay?: number;
|
|
569
593
|
disabled?: boolean;
|
|
570
594
|
};
|
|
571
|
-
|
|
595
|
+
type CheckRelativePath<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo> = TTo extends string ? TFrom extends string ? ResolveRelativePath<TFrom, TTo> extends TAllRouteInfo['routePaths'] ? {} : {
|
|
572
596
|
Error: `${TFrom} + ${TTo} resolves to ${ResolveRelativePath<TFrom, TTo>}, which is not a valid route path.`;
|
|
573
597
|
'Valid Route Paths': TAllRouteInfo['routePaths'];
|
|
574
598
|
} : {} : {};
|
|
575
|
-
|
|
576
|
-
|
|
599
|
+
type CheckPath<TAllRouteInfo extends AnyAllRouteInfo, TPath, TPass> = Exclude<TPath, TAllRouteInfo['routePaths']> extends never ? TPass : CheckPathError<TAllRouteInfo, Exclude<TPath, TAllRouteInfo['routePaths']>>;
|
|
600
|
+
type CheckPathError<TAllRouteInfo extends AnyAllRouteInfo, TInvalids> = Expand<{
|
|
577
601
|
Error: `${TInvalids extends string ? TInvalids : never} is not a valid route path.`;
|
|
578
602
|
'Valid Route Paths': TAllRouteInfo['routePaths'];
|
|
579
603
|
}>;
|
|
580
|
-
|
|
581
|
-
|
|
604
|
+
type CheckId<TAllRouteInfo extends AnyAllRouteInfo, TPath, TPass> = Exclude<TPath, TAllRouteInfo['routeIds']> extends never ? TPass : CheckIdError<TAllRouteInfo, Exclude<TPath, TAllRouteInfo['routeIds']>>;
|
|
605
|
+
type CheckIdError<TAllRouteInfo extends AnyAllRouteInfo, TInvalids> = Expand<{
|
|
582
606
|
Error: `${TInvalids extends string ? TInvalids : never} is not a valid route ID.`;
|
|
583
607
|
'Valid Route IDs': TAllRouteInfo['routeIds'];
|
|
584
608
|
}>;
|
|
585
|
-
|
|
586
|
-
|
|
609
|
+
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;
|
|
610
|
+
type ValidFromPath<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo> = undefined | (string extends TAllRouteInfo['routePaths'] ? string : TAllRouteInfo['routePaths']);
|
|
587
611
|
|
|
588
612
|
interface Segment {
|
|
589
613
|
type: 'pathname' | 'param' | 'wildcard';
|
|
@@ -597,8 +621,8 @@ declare function trimPath(path: string): string;
|
|
|
597
621
|
declare function resolvePath(basepath: string, base: string, to: string): string;
|
|
598
622
|
declare function parsePathname(pathname?: string): Segment[];
|
|
599
623
|
declare function interpolatePath(path: string | undefined, params: any, leaveWildcard?: boolean): string;
|
|
600
|
-
declare function matchPathname(currentPathname: string, matchLocation: Pick<MatchLocation, 'to' | 'fuzzy' | 'caseSensitive'>): AnyPathParams | undefined;
|
|
601
|
-
declare function matchByPath(from: string, matchLocation: Pick<MatchLocation, 'to' | 'caseSensitive' | 'fuzzy'>): Record<string, string> | undefined;
|
|
624
|
+
declare function matchPathname(basepath: string, currentPathname: string, matchLocation: Pick<MatchLocation, 'to' | 'fuzzy' | 'caseSensitive'>): AnyPathParams | undefined;
|
|
625
|
+
declare function matchByPath(basepath: string, from: string, matchLocation: Pick<MatchLocation, 'to' | 'caseSensitive' | 'fuzzy'>): Record<string, string> | undefined;
|
|
602
626
|
|
|
603
627
|
declare function encode(obj: any, pfx?: string): string;
|
|
604
628
|
declare function decode(str: any): {};
|
|
@@ -608,4 +632,48 @@ declare const defaultStringifySearch: (search: Record<string, any>) => string;
|
|
|
608
632
|
declare function parseSearchWith(parser: (str: string) => any): (searchStr: string) => AnySearchSchema;
|
|
609
633
|
declare function stringifySearchWith(stringify: (search: any) => string): (search: Record<string, any>) => string;
|
|
610
634
|
|
|
611
|
-
|
|
635
|
+
/**
|
|
636
|
+
* This function returns `a` if `b` is deeply equal.
|
|
637
|
+
* If not, it will replace any deeply equal children of `b` with those of `a`.
|
|
638
|
+
* This can be used for structural sharing between immutable JSON values for example.
|
|
639
|
+
* Do not use this with signals
|
|
640
|
+
*/
|
|
641
|
+
declare function replaceEqualDeep<T>(prev: any, _next: T): T;
|
|
642
|
+
declare function trackDeep<T>(obj: T): T;
|
|
643
|
+
|
|
644
|
+
interface ActionOptions<TKey extends string = string, TPayload = unknown, TResponse = unknown, TError = Error> {
|
|
645
|
+
key?: TKey;
|
|
646
|
+
action: (payload: TPayload) => TResponse | Promise<TResponse>;
|
|
647
|
+
onLatestSuccess?: ActionCallback<TPayload, TResponse, TError>;
|
|
648
|
+
onEachSuccess?: ActionCallback<TPayload, TResponse, TError>;
|
|
649
|
+
onLatestError?: ActionCallback<TPayload, TResponse, TError>;
|
|
650
|
+
onEachError?: ActionCallback<TPayload, TResponse, TError>;
|
|
651
|
+
onLatestSettled?: ActionCallback<TPayload, TResponse, TError>;
|
|
652
|
+
onEachSettled?: ActionCallback<TPayload, TResponse, TError>;
|
|
653
|
+
maxSubmissions?: number;
|
|
654
|
+
debug?: boolean;
|
|
655
|
+
}
|
|
656
|
+
type ActionCallback<TPayload, TResponse, TError> = (submission: ActionSubmission<TPayload, TResponse, TError>) => void | Promise<void>;
|
|
657
|
+
interface Action<TKey extends string = string, TPayload = unknown, TResponse = unknown, TError = Error> {
|
|
658
|
+
options: ActionOptions<TKey, TPayload, TResponse, TError>;
|
|
659
|
+
submit: (payload?: TPayload) => Promise<TResponse>;
|
|
660
|
+
reset: () => void;
|
|
661
|
+
store: Store<ActionStore<TPayload, TResponse, TError>>;
|
|
662
|
+
}
|
|
663
|
+
interface ActionStore<TPayload = unknown, TResponse = unknown, TError = Error> {
|
|
664
|
+
submissions: ActionSubmission<TPayload, TResponse, TError>[];
|
|
665
|
+
}
|
|
666
|
+
type ActionFn<TActionPayload = unknown, TActionResponse = unknown> = (submission: TActionPayload) => TActionResponse | Promise<TActionResponse>;
|
|
667
|
+
interface ActionSubmission<TPayload = unknown, TResponse = unknown, TError = Error> {
|
|
668
|
+
submittedAt: number;
|
|
669
|
+
status: 'idle' | 'pending' | 'success' | 'error';
|
|
670
|
+
payload: TPayload;
|
|
671
|
+
response?: TResponse;
|
|
672
|
+
error?: TError;
|
|
673
|
+
isInvalid?: boolean;
|
|
674
|
+
invalidate: () => void;
|
|
675
|
+
getIsLatest: () => boolean;
|
|
676
|
+
}
|
|
677
|
+
declare function createAction<TKey extends string, TPayload, TResponse, TError>(options: ActionOptions<TKey, TPayload, TResponse, TError>): Action<TKey, TPayload, TResponse, TError>;
|
|
678
|
+
|
|
679
|
+
export { Action, ActionFn, ActionOptions, ActionStore, ActionSubmission, ActiveOptions, AllRouteInfo, AnyAllRouteInfo, AnyLoaderData, AnyPathParams, AnyRoute, AnyRouteConfig, AnyRouteConfigWithChildren, AnyRouteInfo, AnyRouter, AnySearchSchema, BuildNextOptions, CheckId, CheckIdError, CheckPath, CheckPathError, CheckRelativePath, DeepAwaited, DefaultAllRouteInfo, DefinedPathParamWarning, DehydratedRouter, DehydratedRouterState, Expand, FilterRoutesFn, FrameworkGenerics, FromLocation, GetFrameworkGeneric, IsAny, IsAnyBoolean, IsKnown, LinkInfo, LinkOptions, ListenerFn, Loader, LoaderContext, LoaderFn, LoaderState, LocationState, MatchCache, MatchCacheEntry, MatchLocation, MatchRouteOptions, NavigateOptions, NoInfer, ParentParams, ParsePathParams, ParseRouteConfig, ParsedLocation, ParsedPath, PathParamMask, PathParamOptions, PickAsPartial, PickAsRequired, PickExclude, PickExtra, PickExtract, PickRequired, PickUnsafe, RegisterRouter, RegisteredAllRouteInfo, RegisteredRouter, RelativeToPathAutoComplete, ResolveRelativePath, RootRouteId, Route, RouteConfig, RouteConfigRoute, RouteInfo, RouteInfoById, RouteInfoByPath, RouteMatch, RouteMatchStore, RouteMeta, RouteOptions, Router, RouterContext, RouterHistory, RouterLocation, RouterOptions, RouterStore, RoutesById, RoutesInfoInner, SearchFilter, SearchParamOptions, SearchParser, SearchSchemaValidator, SearchSchemaValidatorFn, SearchSchemaValidatorObj, SearchSerializer, Segment, Split, Store, Timeout, ToIdOption, ToOptions, ToPathOption, UnionToIntersection, UnloaderFn, Updater, ValidFromPath, ValueKeys, Values, batch, cleanPath, createAction, createBrowserHistory, createHashHistory, createMemoryHistory, createRouteConfig, createStore, decode, defaultFetchServerDataFn, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, interpolatePath, joinPaths, last, matchByPath, matchPathname, parsePathname, parseSearchWith, pick, replaceEqualDeep, resolvePath, rootRouteId, stringifySearchWith, trackDeep, trimPath, trimPathLeft, trimPathRight, warning };
|