@tanstack/router-core 0.0.1-alpha.6 → 0.0.1-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/build/cjs/packages/router-core/src/index.js +33 -1456
  2. package/build/cjs/packages/router-core/src/index.js.map +1 -1
  3. package/build/cjs/packages/router-core/src/path.js +222 -0
  4. package/build/cjs/packages/router-core/src/path.js.map +1 -0
  5. package/build/cjs/packages/router-core/src/qss.js +1 -1
  6. package/build/cjs/packages/router-core/src/qss.js.map +1 -1
  7. package/build/cjs/packages/router-core/src/route.js +126 -0
  8. package/build/cjs/packages/router-core/src/route.js.map +1 -0
  9. package/build/cjs/packages/router-core/src/routeConfig.js +69 -0
  10. package/build/cjs/packages/router-core/src/routeConfig.js.map +1 -0
  11. package/build/cjs/packages/router-core/src/routeMatch.js +260 -0
  12. package/build/cjs/packages/router-core/src/routeMatch.js.map +1 -0
  13. package/build/cjs/packages/router-core/src/router.js +787 -0
  14. package/build/cjs/packages/router-core/src/router.js.map +1 -0
  15. package/build/cjs/packages/router-core/src/searchParams.js +70 -0
  16. package/build/cjs/packages/router-core/src/searchParams.js.map +1 -0
  17. package/build/cjs/packages/router-core/src/utils.js +118 -0
  18. package/build/cjs/packages/router-core/src/utils.js.map +1 -0
  19. package/build/esm/index.js +1303 -1242
  20. package/build/esm/index.js.map +1 -1
  21. package/build/stats-html.html +1 -1
  22. package/build/stats-react.json +374 -57
  23. package/build/types/index.d.ts +361 -336
  24. package/build/umd/index.development.js +1312 -1242
  25. package/build/umd/index.development.js.map +1 -1
  26. package/build/umd/index.production.js +1 -1
  27. package/build/umd/index.production.js.map +1 -1
  28. package/package.json +2 -3
  29. package/src/frameworks.ts +13 -0
  30. package/src/index.ts +15 -3060
  31. package/src/link.ts +289 -0
  32. package/src/path.ts +236 -0
  33. package/src/qss.ts +1 -1
  34. package/src/route.ts +181 -0
  35. package/src/routeConfig.ts +523 -0
  36. package/src/routeInfo.ts +228 -0
  37. package/src/routeMatch.ts +357 -0
  38. package/src/router.ts +1182 -0
  39. package/src/searchParams.ts +54 -0
  40. package/src/utils.ts +157 -0
@@ -12,6 +12,10 @@ import { BrowserHistory, MemoryHistory, HashHistory, History } from 'history';
12
12
  export { createBrowserHistory, createHashHistory, createMemoryHistory } from 'history';
13
13
  export { default as invariant } from 'tiny-invariant';
14
14
 
15
+ interface FrameworkGenerics {
16
+ }
17
+ declare type GetFrameworkGeneric<U> = U extends keyof FrameworkGenerics ? FrameworkGenerics[U] : any;
18
+
15
19
  declare type NoInfer<T> = [T][T extends any ? 0 : never];
16
20
  declare type IsAny<T, Y, N> = 1 extends 0 & T ? Y : N;
17
21
  declare type IsAnyBoolean<T> = 1 extends 0 & T ? true : false;
@@ -25,118 +29,35 @@ declare type PickExtra<T, K> = Expand<{
25
29
  declare type PickRequired<T> = {
26
30
  [K in keyof T as undefined extends T[K] ? never : K]: T[K];
27
31
  };
28
- declare type StartsWith<A, B> = A extends `${B extends string ? B : never}${infer _}` ? true : false;
29
32
  declare type Expand<T> = T extends object ? T extends infer O ? {
30
33
  [K in keyof O]: O[K];
31
34
  } : never : T;
32
- interface FrameworkGenerics {
33
- }
34
- interface RouteConfig<TId extends string = string, TRouteId extends string = string, TPath extends string = string, TFullPath extends string = string, TRouteLoaderData extends AnyLoaderData = AnyLoaderData, TLoaderData extends AnyLoaderData = 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 = {}, TKnownChildren = unknown> {
35
- id: TId;
36
- routeId: TRouteId;
37
- path: NoInfer<TPath>;
38
- fullPath: TFullPath;
39
- options: RouteOptions<TRouteId, TPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
40
- children?: TKnownChildren;
41
- addChildren: IsAny<TId, any, <TNewChildren extends any>(cb: (createChildRoute: CreateRouteConfigFn<false, TId, TFullPath, TLoaderData, TFullSearchSchema, TAllParams>) => TNewChildren extends AnyRouteConfig[] ? TNewChildren : {
42
- error: 'Invalid route detected';
43
- route: TNewChildren;
44
- }) => RouteConfig<TId, TRouteId, TPath, TFullPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams, TNewChildren>>;
45
- }
46
- declare type CreateRouteConfigFn<TIsRoot extends boolean = false, TParentId extends string = string, TParentPath extends string = string, TParentAllLoaderData extends AnyLoaderData = {}, TParentSearchSchema extends AnySearchSchema = {}, TParentParams extends AnyPathParams = {}> = <TRouteId extends string, TPath extends string, TRouteLoaderData extends AnyLoaderData, TActionPayload, TActionResponse, 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, TRouteLoaderData, Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>>, 'path'> & {
47
- path?: never;
48
- } : RouteOptions<TRouteId, TPath, TRouteLoaderData, Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, 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>>, TRouteLoaderData, Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>, TKnownChildren>;
49
- declare const createRouteConfig: CreateRouteConfigFn<true>;
50
- interface AnyRouteConfig extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
51
- }
52
- interface AnyRouteConfigWithChildren<TChildren> extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any, any, TChildren> {
53
- }
54
- interface AnyAllRouteInfo {
55
- routeConfig: AnyRouteConfig;
56
- routeInfo: AnyRouteInfo;
57
- routeInfoById: Record<string, AnyRouteInfo>;
58
- routeInfoByFullPath: Record<string, AnyRouteInfo>;
59
- routeIds: any;
60
- routePaths: any;
61
- }
62
- interface DefaultAllRouteInfo {
63
- routeConfig: RouteConfig;
64
- routeInfo: RouteInfo;
65
- routeInfoById: Record<string, RouteInfo>;
66
- routeInfoByFullPath: Record<string, RouteInfo>;
67
- routeIds: string;
68
- routePaths: string;
69
- }
70
- interface AllRouteInfo<TRouteConfig extends AnyRouteConfig = RouteConfig> extends RoutesInfoInner<TRouteConfig, ParseRouteConfig<TRouteConfig>> {
71
- }
72
- interface RoutesInfoInner<TRouteConfig extends AnyRouteConfig, TRouteInfo extends RouteInfo<string, string, any, any, any, any, any, any, any, any, any, any, any, any> = RouteInfo, TRouteInfoById = {
73
- [TInfo in TRouteInfo as TInfo['id']]: TInfo;
74
- }, TRouteInfoByFullPath = {
75
- [TInfo in TRouteInfo as TInfo['fullPath'] extends RootRouteId ? never : string extends TInfo['fullPath'] ? never : TInfo['fullPath']]: TInfo;
76
- }> {
77
- routeConfig: TRouteConfig;
78
- routeInfo: TRouteInfo;
79
- routeInfoById: TRouteInfoById;
80
- routeInfoByFullPath: TRouteInfoByFullPath;
81
- routeIds: keyof TRouteInfoById;
82
- routePaths: keyof TRouteInfoByFullPath;
83
- }
84
- interface AnyRoute extends Route<any, any> {
85
- }
86
- interface AnyRouteInfo extends RouteInfo<any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
87
- }
88
- declare type RoutePath<T extends string> = T extends RootRouteId ? '/' : TrimPathRight<`${T}`>;
89
- declare type ParseRouteConfig<TRouteConfig = AnyRouteConfig> = TRouteConfig extends AnyRouteConfig ? RouteConfigRoute<TRouteConfig> | ParseRouteChildren<TRouteConfig> : never;
90
- declare type ParseRouteChildren<TRouteConfig> = TRouteConfig extends AnyRouteConfigWithChildren<infer TChildren> ? unknown extends TChildren ? never : TChildren extends AnyRouteConfig[] ? Values<{
91
- [TId in TChildren[number]['id']]: ParseRouteChild<TChildren[number], TId>;
92
- }> : never : never;
93
- declare type ParseRouteChild<TRouteConfig, TId> = TRouteConfig & {
94
- id: TId;
95
- } extends AnyRouteConfig ? ParseRouteConfig<TRouteConfig> : never;
96
35
  declare type Values<O> = O[ValueKeys<O>];
97
36
  declare type ValueKeys<O> = Extract<keyof O, PropertyKey>;
98
- 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;
99
- 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 = {}> {
100
- id: TId;
101
- routeId: TRouteId;
102
- path: TPath;
103
- fullPath: TFullPath;
104
- routeLoaderData: TRouteLoaderData;
105
- loaderData: TLoaderData;
106
- actionPayload: TActionPayload;
107
- actionResponse: TActionResponse;
108
- searchSchema: TSearchSchema;
109
- fullSearchSchema: TFullSearchSchema;
110
- parentParams: TParentParams;
111
- params: TParams;
112
- allParams: TAllParams;
113
- options: RouteOptions<TRouteId, TPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
114
- }
115
37
  declare type DeepAwaited<T> = T extends Promise<infer A> ? DeepAwaited<A> : T extends Record<infer A, Promise<infer B>> ? {
116
38
  [K in A]: DeepAwaited<B>;
117
39
  } : T;
118
- declare const rootRouteId: "__root__";
119
- declare type RootRouteId = typeof rootRouteId;
120
- declare type RoutePrefix<TPrefix extends string, TId extends string> = string extends TId ? RootRouteId : TId extends string ? `${TPrefix}/${TId}` extends '/' ? '/' : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TId>}`>}` : never;
121
- declare 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;
122
- declare type TrimPath<T extends string> = '' extends T ? '' : TrimPathRight<TrimPathLeft<T>>;
123
- declare type TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}` ? TrimPathLeft<U> : T extends `/${infer U}` ? TrimPathLeft<U> : T;
124
- declare type TrimPathRight<T extends string> = T extends '/' ? '/' : T extends `${infer U}/` ? TrimPathRight<U> : T;
125
- declare type ParsePathParams<T extends string> = Split<T>[number] extends infer U ? U extends `:${infer V}` ? V : never : never;
126
40
  declare 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;
127
- declare type Split<S, TTrailing = true> = S extends unknown ? string extends S ? string[] : S extends string ? CleanPath<S> extends '' ? [] : TTrailing extends true ? CleanPath<S> extends `${infer T}/` ? [T, '/'] : CleanPath<S> extends `/${infer U}` ? ['/', U] : CleanPath<S> extends `${infer T}/${infer U}` ? [T, ...Split<U>] : [S] : CleanPath<S> extends `${infer T}/${infer U}` ? [T, ...Split<U>] : [S] : never : never;
128
- declare 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;
129
- declare type AnySearchSchema = {};
130
- declare type AnyLoaderData = {};
131
- declare type AnyPathParams = {};
132
- interface RouteMeta {
133
- }
134
- interface LocationState {
135
- }
136
41
  declare type Timeout = ReturnType<typeof setTimeout>;
137
- declare type SearchSerializer = (searchObj: Record<string, any>) => string;
138
- declare type SearchParser = (searchStr: string) => Record<string, any>;
139
42
  declare type Updater<TPrevious, TResult = TPrevious> = TResult | ((prev?: TPrevious) => TResult);
43
+ declare type PickExtract<T, U> = {
44
+ [K in keyof T as T[K] extends U ? K : never]: T[K];
45
+ };
46
+ declare type PickExclude<T, U> = {
47
+ [K in keyof T as T[K] extends U ? never : K]: T[K];
48
+ };
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
+ declare function last<T>(arr: T[]): T | undefined;
56
+ declare function warning(cond: any, message: string): cond is true;
57
+ declare function functionalUpdate<TResult>(updater: Updater<TResult>, previous: TResult): TResult;
58
+
59
+ interface LocationState {
60
+ }
140
61
  interface Location<TSearchObj extends AnySearchSchema = {}, TState extends LocationState = LocationState> {
141
62
  href: string;
142
63
  pathname: string;
@@ -152,146 +73,9 @@ interface FromLocation {
152
73
  key?: string;
153
74
  hash?: string;
154
75
  }
155
- declare type PickExtract<T, U> = {
156
- [K in keyof T as T[K] extends U ? K : never]: T[K];
157
- };
158
- declare type PickExclude<T, U> = {
159
- [K in keyof T as T[K] extends U ? never : K]: T[K];
160
- };
161
- declare type SearchSchemaValidator<TReturn, TParentSchema> = (searchObj: Record<string, unknown>) => {} extends TParentSchema ? TReturn : keyof TReturn extends keyof TParentSchema ? {
162
- error: 'Top level search params cannot be redefined by child routes!';
163
- keys: keyof TReturn & keyof TParentSchema;
164
- } : TReturn;
165
- declare type DefinedPathParamWarning = 'Path params cannot be redefined by child routes!';
166
- declare type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
167
- [Key in keyof TParentParams]?: DefinedPathParamWarning;
168
- };
169
- 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 = {}> = ({
170
- path: TPath;
171
- } | {
172
- id: TRouteId;
173
- }) & {
174
- caseSensitive?: boolean;
175
- validateSearch?: SearchSchemaValidator<TSearchSchema, TParentSearchSchema>;
176
- preSearchFilters?: SearchFilter<TFullSearchSchema>[];
177
- postSearchFilters?: SearchFilter<TFullSearchSchema>[];
178
- pendingMs?: number;
179
- pendingMinMs?: number;
180
- } & ({
181
- parseParams?: never;
182
- stringifyParams?: never;
183
- } | {
184
- parseParams: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams;
185
- stringifyParams: (params: TParams) => Record<ParsePathParams<TPath>, string>;
186
- }) & RouteLoaders<TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TFullSearchSchema, TAllParams> & {
187
- import?: (opts: {
188
- params: AnyPathParams;
189
- }) => Promise<RouteLoaders<TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TFullSearchSchema, TAllParams>>;
190
- } & (PickUnsafe<TParentParams, ParsePathParams<TPath>> extends never ? {} : 'Cannot redefined path params in child routes!');
191
- interface RouteLoaders<TRouteLoaderData extends AnyLoaderData = {}, TLoaderData extends AnyLoaderData = {}, TActionPayload = unknown, TActionResponse = unknown, TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> {
192
- element?: GetFrameworkGeneric<'SyncOrAsyncElement', NoInfer<TLoaderData>>;
193
- errorElement?: GetFrameworkGeneric<'SyncOrAsyncElement', NoInfer<TLoaderData>>;
194
- catchElement?: GetFrameworkGeneric<'SyncOrAsyncElement', NoInfer<TLoaderData>>;
195
- pendingElement?: GetFrameworkGeneric<'SyncOrAsyncElement', NoInfer<TLoaderData>>;
196
- loader?: LoaderFn<TRouteLoaderData, TFullSearchSchema, TAllParams>;
197
- action?: ActionFn<TActionPayload, TActionResponse>;
198
- useErrorBoundary?: boolean;
199
- onMatch?: (matchContext: {
200
- params: TAllParams;
201
- search: TFullSearchSchema;
202
- }) => void | undefined | ((match: {
203
- params: TAllParams;
204
- search: TFullSearchSchema;
205
- }) => void);
206
- onTransition?: (match: {
207
- params: TAllParams;
208
- search: TFullSearchSchema;
209
- }) => void;
210
- meta?: RouteMeta;
211
- }
212
- declare type SearchFilter<T, U = T> = (prev: T) => U;
213
- interface MatchLocation {
214
- to?: string | number | null;
215
- fuzzy?: boolean;
216
- caseSensitive?: boolean;
217
- from?: string;
218
- fromCurrent?: boolean;
219
- }
220
- declare type SearchPredicate<TSearch extends AnySearchSchema = {}> = (search: TSearch) => any;
221
- declare type LoaderFn<TRouteLoaderData extends AnyLoaderData, TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> = (loaderContext: {
222
- params: TAllParams;
223
- search: TFullSearchSchema;
224
- signal?: AbortSignal;
225
- }) => Promise<TRouteLoaderData>;
226
- declare type ActionFn<TActionPayload = unknown, TActionResponse = unknown> = (submission: TActionPayload) => TActionResponse | Promise<TActionResponse>;
227
- declare type UnloaderFn<TPath extends string> = (routeMatch: RouteMatch<any, RouteInfo<string, TPath>>) => void;
228
- interface RouterState {
229
- status: 'idle' | 'loading';
230
- location: Location;
231
- matches: RouteMatch[];
232
- lastUpdated: number;
233
- loaderData: unknown;
234
- currentAction?: ActionState;
235
- latestAction?: ActionState;
236
- actions: Record<string, Action>;
237
- pending?: PendingState;
238
- }
239
- interface PendingState {
240
- location: Location;
241
- matches: RouteMatch[];
242
- }
243
- declare type ListenerFn = () => void;
244
- interface Segment {
245
- type: 'pathname' | 'param' | 'wildcard';
246
- value: string;
247
- }
248
- declare type GetFrameworkGeneric<U, TData = unknown> = U extends keyof FrameworkGenerics ? FrameworkGenerics[U] : any;
249
- interface __Experimental__RouterSnapshot {
250
- location: Location;
251
- matches: SnapshotRouteMatch<unknown>[];
252
- }
253
- interface SnapshotRouteMatch<TData> {
254
- matchId: string;
255
- loaderData: TData;
256
- }
257
- interface BuildNextOptions {
258
- to?: string | number | null;
259
- params?: true | Updater<Record<string, any>>;
260
- search?: true | Updater<unknown>;
261
- hash?: true | Updater<string>;
262
- key?: string;
263
- from?: string;
264
- fromCurrent?: boolean;
265
- __preSearchFilters?: SearchFilter<any>[];
266
- __postSearchFilters?: SearchFilter<any>[];
267
- }
268
- interface ActiveOptions {
269
- exact?: boolean;
270
- includeHash?: boolean;
271
- }
76
+ declare type SearchSerializer = (searchObj: Record<string, any>) => string;
77
+ declare type SearchParser = (searchStr: string) => Record<string, any>;
272
78
  declare type FilterRoutesFn = <TRoute extends Route<any, RouteInfo>>(routeConfigs: TRoute[]) => TRoute[];
273
- declare type Listener = () => void;
274
- interface MatchRouteOptions {
275
- pending: boolean;
276
- caseSensitive?: boolean;
277
- }
278
- declare type LinkInfo = {
279
- type: 'external';
280
- href: string;
281
- } | {
282
- type: 'internal';
283
- next: Location;
284
- handleFocus: (e: any) => void;
285
- handleClick: (e: any) => void;
286
- handleEnter: (e: any) => void;
287
- handleLeave: (e: any) => void;
288
- isActive: boolean;
289
- disabled?: boolean;
290
- };
291
- declare type PreloadCacheEntry = {
292
- maxAge: number;
293
- match: RouteMatch;
294
- };
295
79
  interface RouterOptions<TRouteConfig extends AnyRouteConfig> {
296
80
  history?: BrowserHistory | MemoryHistory | HashHistory;
297
81
  stringifySearch?: SearchSerializer;
@@ -307,8 +91,9 @@ interface RouterOptions<TRouteConfig extends AnyRouteConfig> {
307
91
  defaultPendingElement?: GetFrameworkGeneric<'Element'>;
308
92
  defaultPendingMs?: number;
309
93
  defaultPendingMinMs?: number;
94
+ defaultLoaderMaxAge?: number;
95
+ defaultLoaderGcMaxAge?: number;
310
96
  caseSensitive?: boolean;
311
- __experimental__snapshot?: __Experimental__RouterSnapshot;
312
97
  routeConfig?: TRouteConfig;
313
98
  basepath?: string;
314
99
  createRouter?: (router: Router<any, any>) => void;
@@ -330,14 +115,55 @@ interface ActionState<TPayload = unknown, TResponse = unknown> {
330
115
  data?: TResponse;
331
116
  error?: unknown;
332
117
  }
333
- declare type RoutesById<TAllRouteInfo extends AnyAllRouteInfo> = {
334
- [K in keyof TAllRouteInfo['routeInfoById']]: Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][K]>;
335
- };
336
- declare type ValidFromPath<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo> = undefined | (string extends TAllRouteInfo['routePaths'] ? string : TAllRouteInfo['routePaths']);
337
- interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>> {
338
- options: PickAsRequired<RouterOptions<TRouteConfig>, 'stringifySearch' | 'parseSearch'>;
339
- basepath: string;
340
- allRouteInfo: TAllRouteInfo;
118
+ interface RouterState {
119
+ status: 'idle' | 'loading';
120
+ location: Location;
121
+ matches: RouteMatch[];
122
+ lastUpdated: number;
123
+ loaderData: unknown;
124
+ currentAction?: ActionState;
125
+ latestAction?: ActionState;
126
+ actions: Record<string, Action>;
127
+ pending?: PendingState;
128
+ isFetching: boolean;
129
+ isPreloading: boolean;
130
+ }
131
+ interface PendingState {
132
+ location: Location;
133
+ matches: RouteMatch[];
134
+ }
135
+ declare type Listener = () => void;
136
+ declare type ListenerFn = () => void;
137
+ interface BuildNextOptions {
138
+ to?: string | number | null;
139
+ params?: true | Updater<Record<string, any>>;
140
+ search?: true | Updater<unknown>;
141
+ hash?: true | Updater<string>;
142
+ key?: string;
143
+ from?: string;
144
+ fromCurrent?: boolean;
145
+ __preSearchFilters?: SearchFilter<any>[];
146
+ __postSearchFilters?: SearchFilter<any>[];
147
+ }
148
+ declare type MatchCacheEntry = {
149
+ gc: number;
150
+ match: RouteMatch;
151
+ };
152
+ interface MatchLocation {
153
+ to?: string | number | null;
154
+ fuzzy?: boolean;
155
+ caseSensitive?: boolean;
156
+ from?: string;
157
+ fromCurrent?: boolean;
158
+ }
159
+ interface MatchRouteOptions {
160
+ pending: boolean;
161
+ caseSensitive?: boolean;
162
+ }
163
+ interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>> {
164
+ options: PickAsRequired<RouterOptions<TRouteConfig>, 'stringifySearch' | 'parseSearch'>;
165
+ basepath: string;
166
+ allRouteInfo: TAllRouteInfo;
341
167
  listeners: Listener[];
342
168
  location: Location;
343
169
  navigateTimeout?: Timeout;
@@ -351,11 +177,11 @@ interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInf
351
177
  actionState: ActionState;
352
178
  }[];
353
179
  startedLoadingAt: number;
354
- destroy: () => void;
355
180
  resolveNavigation: () => void;
356
181
  subscribe: (listener: Listener) => () => void;
357
182
  notify: () => void;
358
- mount: () => Promise<void>;
183
+ mount: () => () => void;
184
+ onFocus: () => void;
359
185
  update: <TRouteConfig extends RouteConfig = RouteConfig>(opts?: RouterOptions<TRouteConfig>) => Router<TRouteConfig>;
360
186
  buildRouteTree: (routeConfig: RouteConfig) => Route<TAllRouteInfo, AnyRouteInfo>;
361
187
  parseLocation: (location: History['location'], previousLocation?: Location) => Location;
@@ -364,8 +190,8 @@ interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInf
364
190
  buildNext: (opts: BuildNextOptions) => Location;
365
191
  cancelMatches: () => void;
366
192
  loadLocation: (next?: Location) => Promise<void>;
367
- preloadCache: Record<string, PreloadCacheEntry>;
368
- cleanPreloadCache: () => void;
193
+ matchCache: Record<string, MatchCacheEntry>;
194
+ cleanMatchCache: () => void;
369
195
  getRoute: <TId extends keyof TAllRouteInfo['routeInfoById']>(id: TId) => Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TId]>;
370
196
  loadRoute: (navigateOpts: BuildNextOptions, loaderOpts: {
371
197
  maxAge: number;
@@ -381,7 +207,7 @@ interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInf
381
207
  } | {
382
208
  preload?: false;
383
209
  maxAge?: never;
384
- })) => Promise<RouteMatch[]>;
210
+ })) => Promise<void>;
385
211
  invalidateRoute: (opts: MatchLocation) => void;
386
212
  reload: () => Promise<void>;
387
213
  resolvePath: (from: string, path: string) => string;
@@ -391,9 +217,64 @@ interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInf
391
217
  navigate: <TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'>(opts: NavigateOptionsAbsolute<TAllRouteInfo, TFrom, TTo>) => Promise<void>;
392
218
  matchRoute: <TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'>(matchLocation: ToOptions<TAllRouteInfo, TFrom, TTo>, opts?: MatchRouteOptions) => boolean;
393
219
  buildLink: <TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'>(opts: LinkOptions<TAllRouteInfo, TFrom, TTo>) => LinkInfo;
394
- __experimental__createSnapshot: () => __Experimental__RouterSnapshot;
395
220
  }
396
221
  declare function createRouter<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>>(userOptions?: RouterOptions<TRouteConfig>): Router<TRouteConfig, TAllRouteInfo>;
222
+
223
+ interface RouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> extends Route<TAllRouteInfo, TRouteInfo> {
224
+ matchId: string;
225
+ pathname: string;
226
+ params: AnyPathParams;
227
+ parentMatch?: RouteMatch;
228
+ childMatches: RouteMatch[];
229
+ routeSearch: TRouteInfo['searchSchema'];
230
+ search: TRouteInfo['fullSearchSchema'];
231
+ status: 'idle' | 'loading' | 'success' | 'error';
232
+ updatedAt?: number;
233
+ error?: unknown;
234
+ isInvalid: boolean;
235
+ getIsInvalid: () => boolean;
236
+ loaderData: TRouteInfo['loaderData'];
237
+ routeLoaderData: TRouteInfo['routeLoaderData'];
238
+ isFetching: boolean;
239
+ isPending: boolean;
240
+ __: {
241
+ element?: GetFrameworkGeneric<'Element'>;
242
+ errorElement?: GetFrameworkGeneric<'Element'>;
243
+ catchElement?: GetFrameworkGeneric<'Element'>;
244
+ pendingElement?: GetFrameworkGeneric<'Element'>;
245
+ loadPromise?: Promise<void>;
246
+ loaderPromise?: Promise<void>;
247
+ importPromise?: Promise<void>;
248
+ elementsPromise?: Promise<void>;
249
+ dataPromise?: Promise<void>;
250
+ pendingTimeout?: Timeout;
251
+ pendingMinTimeout?: Timeout;
252
+ pendingMinPromise?: Promise<void>;
253
+ onExit?: void | ((matchContext: {
254
+ params: TRouteInfo['allParams'];
255
+ search: TRouteInfo['fullSearchSchema'];
256
+ }) => void);
257
+ abortController: AbortController;
258
+ latestId: string;
259
+ validate: () => void;
260
+ startPending: () => void;
261
+ cancelPending: () => void;
262
+ notify: () => void;
263
+ resolve: () => void;
264
+ };
265
+ cancel: () => void;
266
+ load: () => Promise<void>;
267
+ invalidate: () => void;
268
+ hasLoaders: () => boolean;
269
+ }
270
+ declare function createRouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo>(router: Router<any, any>, route: Route<TAllRouteInfo, TRouteInfo>, opts: {
271
+ matchId: string;
272
+ params: TRouteInfo['allParams'];
273
+ pathname: string;
274
+ }): RouteMatch<TAllRouteInfo, TRouteInfo>;
275
+
276
+ interface AnyRoute extends Route<any, any> {
277
+ }
397
278
  interface Route<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> {
398
279
  routeId: TRouteInfo['id'];
399
280
  routeRouteId: TRouteInfo['routeId'];
@@ -409,6 +290,191 @@ interface Route<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRo
409
290
  action: unknown extends TRouteInfo['actionResponse'] ? Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']> | undefined : Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']>;
410
291
  }
411
292
  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>;
293
+ declare function cascadeLoaderData(matches: RouteMatch<any, any>[]): void;
294
+
295
+ interface AnyAllRouteInfo {
296
+ routeConfig: AnyRouteConfig;
297
+ routeInfo: AnyRouteInfo;
298
+ routeInfoById: Record<string, AnyRouteInfo>;
299
+ routeInfoByFullPath: Record<string, AnyRouteInfo>;
300
+ routeIds: any;
301
+ routePaths: any;
302
+ }
303
+ interface DefaultAllRouteInfo {
304
+ routeConfig: RouteConfig;
305
+ routeInfo: RouteInfo;
306
+ routeInfoById: Record<string, RouteInfo>;
307
+ routeInfoByFullPath: Record<string, RouteInfo>;
308
+ routeIds: string;
309
+ routePaths: string;
310
+ }
311
+ interface AllRouteInfo<TRouteConfig extends AnyRouteConfig = RouteConfig> extends RoutesInfoInner<TRouteConfig, ParseRouteConfig<TRouteConfig>> {
312
+ }
313
+ declare type ParseRouteConfig<TRouteConfig = AnyRouteConfig> = TRouteConfig extends AnyRouteConfig ? RouteConfigRoute<TRouteConfig> | ParseRouteChildren<TRouteConfig> : never;
314
+ declare type ParseRouteChildren<TRouteConfig> = TRouteConfig extends AnyRouteConfigWithChildren<infer TChildren> ? unknown extends TChildren ? never : TChildren extends AnyRouteConfig[] ? Values<{
315
+ [TId in TChildren[number]['id']]: ParseRouteChild<TChildren[number], TId>;
316
+ }> : never : never;
317
+ declare type ParseRouteChild<TRouteConfig, TId> = TRouteConfig & {
318
+ id: TId;
319
+ } extends AnyRouteConfig ? ParseRouteConfig<TRouteConfig> : never;
320
+ 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;
321
+ interface RoutesInfoInner<TRouteConfig extends AnyRouteConfig, TRouteInfo extends RouteInfo<string, string, any, any, any, any, any, any, any, any, any, any, any, any> = RouteInfo, TRouteInfoById = {
322
+ [TInfo in TRouteInfo as TInfo['id']]: TInfo;
323
+ }, TRouteInfoByFullPath = {
324
+ [TInfo in TRouteInfo as TInfo['fullPath'] extends RootRouteId ? never : string extends TInfo['fullPath'] ? never : TInfo['fullPath']]: TInfo;
325
+ }> {
326
+ routeConfig: TRouteConfig;
327
+ routeInfo: TRouteInfo;
328
+ routeInfoById: TRouteInfoById;
329
+ routeInfoByFullPath: TRouteInfoByFullPath;
330
+ routeIds: keyof TRouteInfoById;
331
+ routePaths: keyof TRouteInfoByFullPath;
332
+ }
333
+ interface AnyRouteInfo extends RouteInfo<any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
334
+ }
335
+ 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 = {}> {
336
+ id: TId;
337
+ routeId: TRouteId;
338
+ path: TPath;
339
+ fullPath: TFullPath;
340
+ routeLoaderData: TRouteLoaderData;
341
+ loaderData: TLoaderData;
342
+ actionPayload: TActionPayload;
343
+ actionResponse: TActionResponse;
344
+ searchSchema: TSearchSchema;
345
+ fullSearchSchema: TFullSearchSchema;
346
+ parentParams: TParentParams;
347
+ params: TParams;
348
+ allParams: TAllParams;
349
+ options: RouteOptions<TRouteId, TPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
350
+ }
351
+ declare type RoutesById<TAllRouteInfo extends AnyAllRouteInfo> = {
352
+ [K in keyof TAllRouteInfo['routeInfoById']]: Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][K]>;
353
+ };
354
+ declare type RouteInfoById<TAllRouteInfo extends AnyAllRouteInfo, TId> = TId extends keyof TAllRouteInfo['routeInfoById'] ? IsAny<TAllRouteInfo['routeInfoById'][TId]['id'], RouteInfo, TAllRouteInfo['routeInfoById'][TId]> : never;
355
+ declare type RouteInfoByPath<TAllRouteInfo extends AnyAllRouteInfo, TPath> = TPath extends keyof TAllRouteInfo['routeInfoByFullPath'] ? IsAny<TAllRouteInfo['routeInfoByFullPath'][TPath]['id'], RouteInfo, TAllRouteInfo['routeInfoByFullPath'][TPath]> : never;
356
+
357
+ declare const rootRouteId: "__root__";
358
+ declare type RootRouteId = typeof rootRouteId;
359
+ declare type AnyLoaderData = {};
360
+ declare type AnyPathParams = {};
361
+ declare type AnySearchSchema = {};
362
+ interface RouteMeta {
363
+ }
364
+ declare type SearchSchemaValidator<TReturn, TParentSchema> = SearchSchemaValidatorObj<TReturn, TParentSchema> | SearchSchemaValidatorFn<TReturn, TParentSchema>;
365
+ declare type SearchSchemaValidatorObj<TReturn, TParentSchema> = {
366
+ parse?: SearchSchemaValidatorFn<TReturn, TParentSchema>;
367
+ };
368
+ declare type SearchSchemaValidatorFn<TReturn, TParentSchema> = (searchObj: Record<string, unknown>) => {} extends TParentSchema ? TReturn : keyof TReturn extends keyof TParentSchema ? {
369
+ error: 'Top level search params cannot be redefined by child routes!';
370
+ keys: keyof TReturn & keyof TParentSchema;
371
+ } : TReturn;
372
+ declare type DefinedPathParamWarning = 'Path params cannot be redefined by child routes!';
373
+ declare type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
374
+ [Key in keyof TParentParams]?: DefinedPathParamWarning;
375
+ };
376
+ declare type LoaderFn<TRouteLoaderData extends AnyLoaderData, TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> = (loaderContext: {
377
+ params: TAllParams;
378
+ search: TFullSearchSchema;
379
+ signal?: AbortSignal;
380
+ }) => Promise<TRouteLoaderData>;
381
+ declare type ActionFn<TActionPayload = unknown, TActionResponse = unknown> = (submission: TActionPayload) => TActionResponse | Promise<TActionResponse>;
382
+ declare type UnloaderFn<TPath extends string> = (routeMatch: RouteMatch<any, RouteInfo<string, TPath>>) => void;
383
+ 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 = {}> = ({
384
+ path: TPath;
385
+ } | {
386
+ id: TRouteId;
387
+ }) & {
388
+ caseSensitive?: boolean;
389
+ validateSearch?: SearchSchemaValidator<TSearchSchema, TParentSearchSchema>;
390
+ preSearchFilters?: SearchFilter<TFullSearchSchema>[];
391
+ postSearchFilters?: SearchFilter<TFullSearchSchema>[];
392
+ pendingMs?: number;
393
+ pendingMinMs?: number;
394
+ } & ({
395
+ parseParams?: never;
396
+ stringifyParams?: never;
397
+ } | {
398
+ parseParams: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams;
399
+ stringifyParams: (params: TParams) => Record<ParsePathParams<TPath>, string>;
400
+ }) & RouteLoaders<TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TFullSearchSchema, TAllParams> & {
401
+ import?: (opts: {
402
+ params: AnyPathParams;
403
+ }) => Promise<RouteLoaders<TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TFullSearchSchema, TAllParams>>;
404
+ } & (PickUnsafe<TParentParams, ParsePathParams<TPath>> extends never ? {} : 'Cannot redefined path params in child routes!');
405
+ interface RouteLoaders<TRouteLoaderData extends AnyLoaderData = {}, TLoaderData extends AnyLoaderData = {}, TActionPayload = unknown, TActionResponse = unknown, TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> {
406
+ element?: GetFrameworkGeneric<'SyncOrAsyncElement'>;
407
+ errorElement?: GetFrameworkGeneric<'SyncOrAsyncElement'>;
408
+ catchElement?: GetFrameworkGeneric<'SyncOrAsyncElement'>;
409
+ pendingElement?: GetFrameworkGeneric<'SyncOrAsyncElement'>;
410
+ loader?: LoaderFn<TRouteLoaderData, TFullSearchSchema, TAllParams>;
411
+ loaderMaxAge?: number;
412
+ loaderGcMaxAge?: number;
413
+ action?: ActionFn<TActionPayload, TActionResponse>;
414
+ useErrorBoundary?: boolean;
415
+ onMatch?: (matchContext: {
416
+ params: TAllParams;
417
+ search: TFullSearchSchema;
418
+ }) => void | undefined | ((match: {
419
+ params: TAllParams;
420
+ search: TFullSearchSchema;
421
+ }) => void);
422
+ onTransition?: (match: {
423
+ params: TAllParams;
424
+ search: TFullSearchSchema;
425
+ }) => void;
426
+ meta?: RouteMeta;
427
+ }
428
+ declare type SearchFilter<T, U = T> = (prev: T) => U;
429
+ interface RouteConfig<TId extends string = string, TRouteId extends string = string, TPath extends string = string, TFullPath extends string = string, TRouteLoaderData extends AnyLoaderData = AnyLoaderData, TLoaderData extends AnyLoaderData = 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 = {}, TKnownChildren = unknown> {
430
+ id: TId;
431
+ routeId: TRouteId;
432
+ path: NoInfer<TPath>;
433
+ fullPath: TFullPath;
434
+ options: RouteOptions<TRouteId, TPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
435
+ children?: TKnownChildren;
436
+ addChildren: IsAny<TId, any, <TNewChildren extends any>(children: TNewChildren extends AnyRouteConfig[] ? TNewChildren : {
437
+ error: 'Invalid route detected';
438
+ route: TNewChildren;
439
+ }) => RouteConfig<TId, TRouteId, TPath, TFullPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams, TNewChildren>>;
440
+ createChildren: IsAny<TId, any, <TNewChildren extends any>(cb: (createChildRoute: CreateRouteConfigFn<false, TId, TFullPath, TLoaderData, TFullSearchSchema, TAllParams>) => TNewChildren extends AnyRouteConfig[] ? TNewChildren : {
441
+ error: 'Invalid route detected';
442
+ route: TNewChildren;
443
+ }) => RouteConfig<TId, TRouteId, TPath, TFullPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams, TNewChildren>>;
444
+ createRoute: CreateRouteConfigFn<false, TId, TFullPath, TLoaderData, TFullSearchSchema, TAllParams>;
445
+ }
446
+ declare type CreateRouteConfigFn<TIsRoot extends boolean = false, TParentId extends string = string, TParentPath extends string = string, TParentAllLoaderData extends AnyLoaderData = {}, TParentSearchSchema extends AnySearchSchema = {}, TParentParams extends AnyPathParams = {}> = <TRouteId extends string, TPath extends string, TRouteLoaderData extends AnyLoaderData, TActionPayload, TActionResponse, 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, TRouteLoaderData, Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>>, 'path'> & {
447
+ path?: never;
448
+ } : RouteOptions<TRouteId, TPath, TRouteLoaderData, Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, 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>>, TRouteLoaderData, Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>, TKnownChildren>;
449
+ declare type RoutePath<T extends string> = T extends RootRouteId ? '/' : TrimPathRight<`${T}`>;
450
+ declare type RoutePrefix<TPrefix extends string, TId extends string> = string extends TId ? RootRouteId : TId extends string ? `${TPrefix}/${TId}` extends '/' ? '/' : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TId>}`>}` : never;
451
+ interface AnyRouteConfig extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
452
+ }
453
+ interface AnyRouteConfigWithChildren<TChildren> extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any, any, TChildren> {
454
+ }
455
+ declare type TrimPath<T extends string> = '' extends T ? '' : TrimPathRight<TrimPathLeft<T>>;
456
+ declare type TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}` ? TrimPathLeft<U> : T extends `/${infer U}` ? TrimPathLeft<U> : T;
457
+ declare type TrimPathRight<T extends string> = T extends '/' ? '/' : T extends `${infer U}/` ? TrimPathRight<U> : T;
458
+ declare const createRouteConfig: CreateRouteConfigFn<true>;
459
+
460
+ declare type LinkInfo = {
461
+ type: 'external';
462
+ href: string;
463
+ } | {
464
+ type: 'internal';
465
+ next: Location;
466
+ handleFocus: (e: any) => void;
467
+ handleClick: (e: any) => void;
468
+ handleEnter: (e: any) => void;
469
+ handleLeave: (e: any) => void;
470
+ isActive: boolean;
471
+ disabled?: boolean;
472
+ };
473
+ declare type StartsWith<A, B> = A extends `${B extends string ? B : never}${infer _}` ? true : false;
474
+ declare 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;
475
+ declare type Split<S, TTrailing = true> = S extends unknown ? string extends S ? string[] : S extends string ? CleanPath<S> extends '' ? [] : TTrailing extends true ? CleanPath<S> extends `${infer T}/` ? [T, '/'] : CleanPath<S> extends `/${infer U}` ? ['/', U] : CleanPath<S> extends `${infer T}/${infer U}` ? [T, ...Split<U>] : [S] : CleanPath<S> extends `${infer T}/${infer U}` ? [T, ...Split<U>] : [S] : never : never;
476
+ declare type ParsePathParams<T extends string> = Split<T>[number] extends infer U ? U extends `:${infer V}` ? V : never : never;
477
+ declare 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;
412
478
  declare type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends string, TTo extends string, SplitPaths extends string[] = Split<AllPaths, false>> = TTo extends `..${infer _}` ? SplitPaths extends [
413
479
  ...Split<ResolveRelativePath<TFrom, TTo>, false>,
414
480
  ...infer TToRest
@@ -428,8 +494,30 @@ declare type ToOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteIn
428
494
  hash?: Updater<string>;
429
495
  from?: TFrom;
430
496
  } & CheckPath<TAllRouteInfo, NoInfer<TResolvedTo>> & SearchParamOptions<TAllRouteInfo, TFrom, TResolvedTo> & PathParamOptions<TAllRouteInfo, TFrom, TResolvedTo>;
497
+ declare type SearchParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromSchema = RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema'], TToSchema = RouteInfoByPath<TAllRouteInfo, TTo>['fullSearchSchema']> = StartsWith<TFrom, TTo> extends true ? {
498
+ search?: SearchReducer<TFromSchema, TToSchema>;
499
+ } : keyof PickRequired<TToSchema> extends never ? {
500
+ search?: SearchReducer<TFromSchema, TToSchema>;
501
+ } : {
502
+ search: SearchReducer<TFromSchema, TToSchema>;
503
+ };
504
+ declare type SearchReducer<TFrom, TTo> = {
505
+ [TKey in keyof TTo]: TTo[TKey];
506
+ } | ((current: TFrom) => TTo);
507
+ declare type PathParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromParams = RouteInfoByPath<TAllRouteInfo, TFrom>['allParams'], TToParams = RouteInfoByPath<TAllRouteInfo, TTo>['allParams']> = StartsWith<TFrom, TTo> extends true ? {
508
+ params?: ParamsReducer<TFromParams, TToParams>;
509
+ } : AnyPathParams extends TToParams ? {
510
+ params?: ParamsReducer<TFromParams, Record<string, never>>;
511
+ } : {
512
+ params: ParamsReducer<TFromParams, TToParams>;
513
+ };
514
+ declare type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
431
515
  declare type ToPathOption<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = TTo | RelativeToPathAutoComplete<TAllRouteInfo['routePaths'], NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
432
516
  declare type ToIdOption<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = TTo | RelativeToPathAutoComplete<TAllRouteInfo['routeIds'], NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
517
+ interface ActiveOptions {
518
+ exact?: boolean;
519
+ includeHash?: boolean;
520
+ }
433
521
  declare type LinkOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = NavigateOptionsAbsolute<TAllRouteInfo, TFrom, TTo> & {
434
522
  target?: HTMLAnchorElement['target'];
435
523
  activeOptions?: ActiveOptions;
@@ -448,92 +536,29 @@ declare type CheckPathError<TAllRouteInfo extends AnyAllRouteInfo, TInvalids> =
448
536
  'Valid Route Paths': TAllRouteInfo['routePaths'];
449
537
  };
450
538
  declare 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] ? ResolveRelativePath<Join<FromRest>, Join<ToRest>> : never : Split<TTo> extends ['.', ...infer ToRest] ? ResolveRelativePath<TFrom, Join<ToRest>> : CleanPath<Join<['/', ...Split<TFrom>, ...Split<TTo>]>> : never : never;
451
- declare type RouteInfoById<TAllRouteInfo extends AnyAllRouteInfo, TId> = TId extends keyof TAllRouteInfo['routeInfoById'] ? IsAny<TAllRouteInfo['routeInfoById'][TId]['id'], RouteInfo, TAllRouteInfo['routeInfoById'][TId]> : never;
452
- declare type RouteInfoByPath<TAllRouteInfo extends AnyAllRouteInfo, TPath> = TPath extends keyof TAllRouteInfo['routeInfoByFullPath'] ? IsAny<TAllRouteInfo['routeInfoByFullPath'][TPath]['id'], RouteInfo, TAllRouteInfo['routeInfoByFullPath'][TPath]> : never;
453
- declare type SearchParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromSchema = RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema'], TToSchema = RouteInfoByPath<TAllRouteInfo, TTo>['fullSearchSchema']> = StartsWith<TFrom, TTo> extends true ? {
454
- search?: SearchReducer<TFromSchema, TToSchema>;
455
- } : keyof PickRequired<TToSchema> extends never ? {
456
- search?: SearchReducer<TFromSchema, TToSchema>;
457
- } : {
458
- search: SearchReducer<TFromSchema, TToSchema>;
459
- };
460
- declare type SearchReducer<TFrom, TTo> = {
461
- [TKey in keyof TTo]: TTo[TKey];
462
- } | ((current: TFrom) => TTo);
463
- declare type PathParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromParams = RouteInfoByPath<TAllRouteInfo, TFrom>['allParams'], TToParams = RouteInfoByPath<TAllRouteInfo, TTo>['allParams']> = StartsWith<TFrom, TTo> extends true ? {
464
- params?: ParamsReducer<TFromParams, TToParams>;
465
- } : AnyPathParams extends TToParams ? {
466
- params?: ParamsReducer<TFromParams, Record<string, never>>;
467
- } : {
468
- params: ParamsReducer<TFromParams, TToParams>;
469
- };
470
- declare type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
471
- interface RouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> extends Route<TAllRouteInfo, TRouteInfo> {
472
- matchId: string;
473
- pathname: string;
474
- params: AnyPathParams;
475
- parentMatch?: RouteMatch;
476
- childMatches: RouteMatch[];
477
- routeSearch: TRouteInfo['searchSchema'];
478
- search: TRouteInfo['fullSearchSchema'];
479
- status: 'idle' | 'loading' | 'success' | 'error';
480
- updatedAt?: number;
481
- error?: unknown;
482
- isInvalid: boolean;
483
- loaderData: TRouteInfo['loaderData'];
484
- routeLoaderData: TRouteInfo['routeLoaderData'];
485
- isFetching: boolean;
486
- isPending: boolean;
487
- __: {
488
- element?: GetFrameworkGeneric<'Element', TRouteInfo['loaderData']>;
489
- errorElement?: GetFrameworkGeneric<'Element', TRouteInfo['loaderData']>;
490
- catchElement?: GetFrameworkGeneric<'Element', TRouteInfo['loaderData']>;
491
- pendingElement?: GetFrameworkGeneric<'Element', TRouteInfo['loaderData']>;
492
- loadPromise?: Promise<void>;
493
- loaderPromise?: Promise<void>;
494
- importPromise?: Promise<void>;
495
- elementsPromise?: Promise<void>;
496
- dataPromise?: Promise<void>;
497
- pendingTimeout?: Timeout;
498
- pendingMinTimeout?: Timeout;
499
- pendingMinPromise?: Promise<void>;
500
- onExit?: void | ((matchContext: {
501
- params: TRouteInfo['allParams'];
502
- search: TRouteInfo['fullSearchSchema'];
503
- }) => void);
504
- abortController: AbortController;
505
- latestId: string;
506
- validate: () => void;
507
- startPending: () => void;
508
- cancelPending: () => void;
509
- notify: () => void;
510
- resolve: () => void;
511
- };
512
- cancel: () => void;
513
- load: () => Promise<void>;
514
- invalidate: () => void;
539
+ declare type ValidFromPath<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo> = undefined | (string extends TAllRouteInfo['routePaths'] ? string : TAllRouteInfo['routePaths']);
540
+
541
+ interface Segment {
542
+ type: 'pathname' | 'param' | 'wildcard';
543
+ value: string;
515
544
  }
516
- declare function createRouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo>(router: Router<any, any>, route: Route<TAllRouteInfo, TRouteInfo>, opts: {
517
- matchId: string;
518
- params: TRouteInfo['allParams'];
519
- pathname: string;
520
- }): RouteMatch<TAllRouteInfo, TRouteInfo>;
545
+ declare function joinPaths(paths: (string | undefined)[]): string;
546
+ declare function cleanPath(path: string): string;
547
+ declare function trimPathLeft(path: string): string;
548
+ declare function trimPathRight(path: string): string;
549
+ declare function trimPath(path: string): string;
550
+ declare function resolvePath(basepath: string, base: string, to: string): string;
551
+ declare function parsePathname(pathname?: string): Segment[];
552
+ declare function interpolatePath(path: string | undefined, params: any, leaveWildcard?: boolean): string;
521
553
  declare function matchPathname(currentPathname: string, matchLocation: Pick<MatchLocation, 'to' | 'fuzzy' | 'caseSensitive'>): AnyPathParams | undefined;
522
- declare function warning(cond: any, message: string): cond is true;
523
- declare function functionalUpdate<TResult>(updater?: Updater<TResult>, previous?: TResult): TResult | undefined;
524
554
  declare function matchByPath(from: string, matchLocation: Pick<MatchLocation, 'to' | 'caseSensitive' | 'fuzzy'>): Record<string, string> | undefined;
525
- declare function parsePathname(pathname?: string): Segment[];
526
- declare function resolvePath(basepath: string, base: string, to: string): string;
527
- /**
528
- * This function returns `a` if `b` is deeply equal.
529
- * If not, it will replace any deeply equal children of `b` with those of `a`.
530
- * This can be used for structural sharing between JSON values for example.
531
- */
532
- declare function replaceEqualDeep(prev: any, next: any): any;
555
+
556
+ declare function encode(obj: any, pfx?: string): string;
557
+ declare function decode(str: any): {};
558
+
533
559
  declare const defaultParseSearch: (searchStr: string) => AnySearchSchema;
534
560
  declare const defaultStringifySearch: (search: Record<string, any>) => string;
535
561
  declare function parseSearchWith(parser: (str: string) => any): (searchStr: string) => AnySearchSchema;
536
562
  declare function stringifySearchWith(stringify: (search: any) => string): (search: Record<string, any>) => string;
537
- declare function last<T>(arr: T[]): T | undefined;
538
563
 
539
- export { Action, ActionFn, ActionState, AllRouteInfo, AnyAllRouteInfo, AnyLoaderData, AnyPathParams, AnyRoute, AnyRouteConfig, AnyRouteConfigWithChildren, AnyRouteInfo, AnySearchSchema, BuildNextOptions, CheckPath, CheckPathError, CheckRelativePath, DefaultAllRouteInfo, DefinedPathParamWarning, FilterRoutesFn, FrameworkGenerics, FromLocation, IsAny, IsAnyBoolean, IsKnown, LinkInfo, LinkOptions, ListenerFn, LoaderFn, Location, LocationState, MatchLocation, MatchRouteOptions, NavigateOptionsAbsolute, NoInfer, ParentParams, ParsePathParams, PathParamMask, PendingState, PickAsPartial, PickAsRequired, PickExclude, PickExtra, PickExtract, PickUnsafe, PreloadCacheEntry, RelativeToPathAutoComplete, ResolveRelativePath, RootRouteId, Route, RouteConfig, RouteConfigRoute, RouteInfo, RouteInfoById, RouteInfoByPath, RouteLoaders, RouteMatch, RouteMeta, RouteOptions, Router, RouterOptions, RouterState, RoutesInfoInner, SearchFilter, SearchParser, SearchPredicate, SearchSchemaValidator, SearchSerializer, Segment, SnapshotRouteMatch, ToIdOption, ToOptions, ToPathOption, UnloaderFn, Updater, ValidFromPath, ValueKeys, Values, __Experimental__RouterSnapshot, createRoute, createRouteConfig, createRouteMatch, createRouter, defaultParseSearch, defaultStringifySearch, functionalUpdate, last, matchByPath, matchPathname, parsePathname, parseSearchWith, replaceEqualDeep, resolvePath, rootRouteId, stringifySearchWith, warning };
564
+ export { Action, ActionFn, ActionState, AllRouteInfo, AnyAllRouteInfo, AnyLoaderData, AnyPathParams, AnyRoute, AnyRouteConfig, AnyRouteConfigWithChildren, AnyRouteInfo, AnySearchSchema, BuildNextOptions, CheckPath, CheckPathError, CheckRelativePath, DeepAwaited, DefaultAllRouteInfo, DefinedPathParamWarning, Expand, FilterRoutesFn, FrameworkGenerics, FromLocation, GetFrameworkGeneric, IsAny, IsAnyBoolean, IsKnown, LinkInfo, LinkOptions, ListenerFn, LoaderFn, Location, LocationState, MatchCacheEntry, MatchLocation, MatchRouteOptions, NavigateOptionsAbsolute, NoInfer, ParentParams, ParsePathParams, ParseRouteConfig, PathParamMask, PendingState, PickAsPartial, PickAsRequired, PickExclude, PickExtra, PickExtract, PickRequired, PickUnsafe, RelativeToPathAutoComplete, ResolveRelativePath, RootRouteId, Route, RouteConfig, RouteConfigRoute, RouteInfo, RouteInfoById, RouteInfoByPath, RouteLoaders, RouteMatch, RouteMeta, RouteOptions, Router, RouterOptions, RouterState, RoutesById, RoutesInfoInner, SearchFilter, SearchParser, SearchSchemaValidator, SearchSchemaValidatorFn, SearchSchemaValidatorObj, SearchSerializer, Segment, Split, Timeout, ToIdOption, ToOptions, ToPathOption, UnloaderFn, Updater, ValidFromPath, ValueKeys, Values, cascadeLoaderData, cleanPath, createRoute, createRouteConfig, createRouteMatch, createRouter, decode, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, interpolatePath, joinPaths, last, matchByPath, matchPathname, parsePathname, parseSearchWith, replaceEqualDeep, resolvePath, rootRouteId, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, warning };