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