@tanstack/router-core 0.0.1-beta.1 → 0.0.1-beta.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/packages/router-core/src/index.js +1 -1
- package/build/cjs/packages/router-core/src/qss.js +1 -0
- package/build/cjs/packages/router-core/src/qss.js.map +1 -1
- package/build/cjs/packages/router-core/src/route.js +9 -23
- package/build/cjs/packages/router-core/src/route.js.map +1 -1
- package/build/cjs/packages/router-core/src/routeMatch.js +24 -27
- package/build/cjs/packages/router-core/src/routeMatch.js.map +1 -1
- package/build/cjs/packages/router-core/src/router.js +105 -73
- package/build/cjs/packages/router-core/src/router.js.map +1 -1
- package/build/cjs/packages/router-core/src/utils.js +7 -0
- package/build/cjs/packages/router-core/src/utils.js.map +1 -1
- package/build/esm/index.js +143 -119
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +138 -144
- package/build/types/index.d.ts +85 -80
- package/build/umd/index.development.js +143 -119
- 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 -1
- package/src/qss.ts +1 -0
- package/src/route.ts +10 -26
- package/src/routeMatch.ts +29 -33
- package/src/router.ts +140 -70
- package/src/utils.ts +7 -0
package/build/types/index.d.ts
CHANGED
|
@@ -55,6 +55,73 @@ declare function replaceEqualDeep(prev: any, next: any): any;
|
|
|
55
55
|
declare function last<T>(arr: T[]): T | undefined;
|
|
56
56
|
declare function warning(cond: any, message: string): cond is true;
|
|
57
57
|
declare function functionalUpdate<TResult>(updater: Updater<TResult>, previous: TResult): TResult;
|
|
58
|
+
declare function pick<T, K extends keyof T>(parent: T, keys: K[]): Pick<T, K>;
|
|
59
|
+
|
|
60
|
+
interface RouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> extends Route<TAllRouteInfo, TRouteInfo> {
|
|
61
|
+
matchId: string;
|
|
62
|
+
pathname: string;
|
|
63
|
+
params: TRouteInfo['params'];
|
|
64
|
+
parentMatch?: RouteMatch;
|
|
65
|
+
childMatches: RouteMatch[];
|
|
66
|
+
routeSearch: TRouteInfo['searchSchema'];
|
|
67
|
+
search: TRouteInfo['fullSearchSchema'];
|
|
68
|
+
status: 'idle' | 'loading' | 'success' | 'error';
|
|
69
|
+
updatedAt?: number;
|
|
70
|
+
error?: unknown;
|
|
71
|
+
isInvalid: boolean;
|
|
72
|
+
getIsInvalid: () => boolean;
|
|
73
|
+
loaderData: TRouteInfo['loaderData'];
|
|
74
|
+
routeLoaderData: TRouteInfo['routeLoaderData'];
|
|
75
|
+
isFetching: boolean;
|
|
76
|
+
isPending: boolean;
|
|
77
|
+
invalidAt: number;
|
|
78
|
+
__: {
|
|
79
|
+
element?: GetFrameworkGeneric<'Element'>;
|
|
80
|
+
errorElement?: GetFrameworkGeneric<'Element'>;
|
|
81
|
+
catchElement?: GetFrameworkGeneric<'Element'>;
|
|
82
|
+
pendingElement?: GetFrameworkGeneric<'Element'>;
|
|
83
|
+
loadPromise?: Promise<void>;
|
|
84
|
+
loaderDataPromise?: Promise<void>;
|
|
85
|
+
elementsPromise?: Promise<void>;
|
|
86
|
+
dataPromise?: Promise<void>;
|
|
87
|
+
pendingTimeout?: Timeout;
|
|
88
|
+
pendingMinTimeout?: Timeout;
|
|
89
|
+
pendingMinPromise?: Promise<void>;
|
|
90
|
+
onExit?: void | ((matchContext: {
|
|
91
|
+
params: TRouteInfo['allParams'];
|
|
92
|
+
search: TRouteInfo['fullSearchSchema'];
|
|
93
|
+
}) => void);
|
|
94
|
+
abortController: AbortController;
|
|
95
|
+
latestId: string;
|
|
96
|
+
validate: () => void;
|
|
97
|
+
startPending: () => void;
|
|
98
|
+
cancelPending: () => void;
|
|
99
|
+
notify: () => void;
|
|
100
|
+
resolve: () => void;
|
|
101
|
+
};
|
|
102
|
+
cancel: () => void;
|
|
103
|
+
load: (loaderOpts?: {
|
|
104
|
+
withPending?: boolean;
|
|
105
|
+
} & ({
|
|
106
|
+
preload: true;
|
|
107
|
+
maxAge: number;
|
|
108
|
+
gcMaxAge: number;
|
|
109
|
+
} | {
|
|
110
|
+
preload?: false;
|
|
111
|
+
maxAge?: never;
|
|
112
|
+
gcMaxAge?: never;
|
|
113
|
+
})) => Promise<TRouteInfo['routeLoaderData']>;
|
|
114
|
+
fetch: (opts?: {
|
|
115
|
+
maxAge?: number;
|
|
116
|
+
}) => Promise<TRouteInfo['routeLoaderData']>;
|
|
117
|
+
invalidate: () => void;
|
|
118
|
+
hasLoaders: () => boolean;
|
|
119
|
+
}
|
|
120
|
+
declare function createRouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo>(router: Router<any, any>, route: Route<TAllRouteInfo, TRouteInfo>, opts: {
|
|
121
|
+
matchId: string;
|
|
122
|
+
params: TRouteInfo['allParams'];
|
|
123
|
+
pathname: string;
|
|
124
|
+
}): RouteMatch<TAllRouteInfo, TRouteInfo>;
|
|
58
125
|
|
|
59
126
|
interface LocationState {
|
|
60
127
|
}
|
|
@@ -102,18 +169,22 @@ interface RouterOptions<TRouteConfig extends AnyRouteConfig> {
|
|
|
102
169
|
route: AnyRoute;
|
|
103
170
|
router: Router<any, any>;
|
|
104
171
|
}) => void;
|
|
105
|
-
createElement?: (element: GetFrameworkGeneric<'
|
|
172
|
+
createElement?: (element: GetFrameworkGeneric<'SyncOrAsyncElement'>) => Promise<GetFrameworkGeneric<'Element'>>;
|
|
106
173
|
}
|
|
107
174
|
interface Action<TPayload = unknown, TResponse = unknown> {
|
|
108
|
-
submit: (submission?: TPayload
|
|
175
|
+
submit: (submission?: TPayload, actionOpts?: {
|
|
176
|
+
invalidate?: boolean;
|
|
177
|
+
multi?: boolean;
|
|
178
|
+
}) => Promise<TResponse>;
|
|
109
179
|
current?: ActionState<TPayload, TResponse>;
|
|
110
180
|
latest?: ActionState<TPayload, TResponse>;
|
|
111
|
-
|
|
181
|
+
submissions: ActionState<TPayload, TResponse>[];
|
|
112
182
|
}
|
|
113
183
|
interface ActionState<TPayload = unknown, TResponse = unknown> {
|
|
114
184
|
submittedAt: number;
|
|
115
185
|
status: 'idle' | 'pending' | 'success' | 'error';
|
|
116
186
|
submission: TPayload;
|
|
187
|
+
isMulti: boolean;
|
|
117
188
|
data?: TResponse;
|
|
118
189
|
error?: unknown;
|
|
119
190
|
}
|
|
@@ -145,9 +216,6 @@ interface RouterState {
|
|
|
145
216
|
location: Location;
|
|
146
217
|
matches: RouteMatch[];
|
|
147
218
|
lastUpdated: number;
|
|
148
|
-
loaderData: unknown;
|
|
149
|
-
currentAction?: ActionState;
|
|
150
|
-
latestAction?: ActionState;
|
|
151
219
|
actions: Record<string, Action>;
|
|
152
220
|
loaders: Record<string, Loader>;
|
|
153
221
|
pending?: PendingState;
|
|
@@ -158,7 +226,7 @@ interface PendingState {
|
|
|
158
226
|
location: Location;
|
|
159
227
|
matches: RouteMatch[];
|
|
160
228
|
}
|
|
161
|
-
declare type Listener = () => void;
|
|
229
|
+
declare type Listener = (router: Router<any, any>) => void;
|
|
162
230
|
declare type ListenerFn = () => void;
|
|
163
231
|
interface BuildNextOptions {
|
|
164
232
|
to?: string | number | null;
|
|
@@ -186,6 +254,11 @@ interface MatchRouteOptions {
|
|
|
186
254
|
pending: boolean;
|
|
187
255
|
caseSensitive?: boolean;
|
|
188
256
|
}
|
|
257
|
+
interface DehydratedRouterState extends Pick<RouterState, 'status' | 'location' | 'lastUpdated'> {
|
|
258
|
+
matches: DehydratedRouteMatch[];
|
|
259
|
+
}
|
|
260
|
+
interface DehydratedRouteMatch extends Pick<RouteMatch<any, any>, 'matchId' | 'status' | 'routeLoaderData' | 'loaderData' | 'isInvalid' | 'invalidAt'> {
|
|
261
|
+
}
|
|
189
262
|
interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>> {
|
|
190
263
|
history: BrowserHistory | MemoryHistory | HashHistory;
|
|
191
264
|
options: PickAsRequired<RouterOptions<TRouteConfig>, 'stringifySearch' | 'parseSearch'>;
|
|
@@ -199,20 +272,17 @@ interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInf
|
|
|
199
272
|
routeTree: Route<TAllRouteInfo, RouteInfo>;
|
|
200
273
|
routesById: RoutesById<TAllRouteInfo>;
|
|
201
274
|
navigationPromise: Promise<void>;
|
|
202
|
-
removeActionQueue: {
|
|
203
|
-
action: Action;
|
|
204
|
-
actionState: ActionState;
|
|
205
|
-
}[];
|
|
206
275
|
startedLoadingAt: number;
|
|
207
276
|
resolveNavigation: () => void;
|
|
208
277
|
subscribe: (listener: Listener) => () => void;
|
|
278
|
+
reset: () => void;
|
|
209
279
|
notify: () => void;
|
|
210
280
|
mount: () => () => void;
|
|
211
281
|
onFocus: () => void;
|
|
212
282
|
update: <TRouteConfig extends RouteConfig = RouteConfig>(opts?: RouterOptions<TRouteConfig>) => Router<TRouteConfig>;
|
|
213
283
|
buildNext: (opts: BuildNextOptions) => Location;
|
|
214
284
|
cancelMatches: () => void;
|
|
215
|
-
|
|
285
|
+
load: (next?: Location) => Promise<void>;
|
|
216
286
|
matchCache: Record<string, MatchCacheEntry>;
|
|
217
287
|
cleanMatchCache: () => void;
|
|
218
288
|
getRoute: <TId extends keyof TAllRouteInfo['routeInfoById']>(id: TId) => Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TId]>;
|
|
@@ -241,6 +311,8 @@ interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInf
|
|
|
241
311
|
navigate: <TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'>(opts: NavigateOptionsAbsolute<TAllRouteInfo, TFrom, TTo>) => Promise<void>;
|
|
242
312
|
matchRoute: <TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'>(matchLocation: ToOptions<TAllRouteInfo, TFrom, TTo>, opts?: MatchRouteOptions) => boolean;
|
|
243
313
|
buildLink: <TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'>(opts: LinkOptions<TAllRouteInfo, TFrom, TTo>) => LinkInfo;
|
|
314
|
+
dehydrateState: () => DehydratedRouterState;
|
|
315
|
+
hydrateState: (state: DehydratedRouterState) => void;
|
|
244
316
|
__: {
|
|
245
317
|
buildRouteTree: (routeConfig: RouteConfig) => Route<TAllRouteInfo, AnyRouteInfo>;
|
|
246
318
|
parseLocation: (location: History['location'], previousLocation?: Location) => Location;
|
|
@@ -253,72 +325,6 @@ interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInf
|
|
|
253
325
|
}
|
|
254
326
|
declare function createRouter<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>>(userOptions?: RouterOptions<TRouteConfig>): Router<TRouteConfig, TAllRouteInfo>;
|
|
255
327
|
|
|
256
|
-
interface RouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> extends Route<TAllRouteInfo, TRouteInfo> {
|
|
257
|
-
matchId: string;
|
|
258
|
-
pathname: string;
|
|
259
|
-
params: TRouteInfo['params'];
|
|
260
|
-
parentMatch?: RouteMatch;
|
|
261
|
-
childMatches: RouteMatch[];
|
|
262
|
-
routeSearch: TRouteInfo['searchSchema'];
|
|
263
|
-
search: TRouteInfo['fullSearchSchema'];
|
|
264
|
-
status: 'idle' | 'loading' | 'success' | 'error';
|
|
265
|
-
updatedAt?: number;
|
|
266
|
-
error?: unknown;
|
|
267
|
-
isInvalid: boolean;
|
|
268
|
-
getIsInvalid: () => boolean;
|
|
269
|
-
loaderData: TRouteInfo['loaderData'];
|
|
270
|
-
routeLoaderData: TRouteInfo['routeLoaderData'];
|
|
271
|
-
isFetching: boolean;
|
|
272
|
-
isPending: boolean;
|
|
273
|
-
invalidAt: number;
|
|
274
|
-
__: {
|
|
275
|
-
element?: GetFrameworkGeneric<'Element'>;
|
|
276
|
-
errorElement?: GetFrameworkGeneric<'Element'>;
|
|
277
|
-
catchElement?: GetFrameworkGeneric<'Element'>;
|
|
278
|
-
pendingElement?: GetFrameworkGeneric<'Element'>;
|
|
279
|
-
loadPromise?: Promise<void>;
|
|
280
|
-
loaderPromise?: Promise<void>;
|
|
281
|
-
elementsPromise?: Promise<void>;
|
|
282
|
-
dataPromise?: Promise<void>;
|
|
283
|
-
pendingTimeout?: Timeout;
|
|
284
|
-
pendingMinTimeout?: Timeout;
|
|
285
|
-
pendingMinPromise?: Promise<void>;
|
|
286
|
-
onExit?: void | ((matchContext: {
|
|
287
|
-
params: TRouteInfo['allParams'];
|
|
288
|
-
search: TRouteInfo['fullSearchSchema'];
|
|
289
|
-
}) => void);
|
|
290
|
-
abortController: AbortController;
|
|
291
|
-
latestId: string;
|
|
292
|
-
validate: () => void;
|
|
293
|
-
startPending: () => void;
|
|
294
|
-
cancelPending: () => void;
|
|
295
|
-
notify: () => void;
|
|
296
|
-
resolve: () => void;
|
|
297
|
-
};
|
|
298
|
-
cancel: () => void;
|
|
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;
|
|
315
|
-
}
|
|
316
|
-
declare function createRouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo>(router: Router<any, any>, route: Route<TAllRouteInfo, TRouteInfo>, opts: {
|
|
317
|
-
matchId: string;
|
|
318
|
-
params: TRouteInfo['allParams'];
|
|
319
|
-
pathname: string;
|
|
320
|
-
}): RouteMatch<TAllRouteInfo, TRouteInfo>;
|
|
321
|
-
|
|
322
328
|
interface AnyRoute extends Route<any, any> {
|
|
323
329
|
}
|
|
324
330
|
interface Route<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> {
|
|
@@ -337,7 +343,6 @@ interface Route<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRo
|
|
|
337
343
|
loader: unknown extends TRouteInfo['routeLoaderData'] ? Action<LoaderContext<TRouteInfo['fullSearchSchema'], TRouteInfo['allParams']>, TRouteInfo['routeLoaderData']> | undefined : Loader<TRouteInfo['fullSearchSchema'], TRouteInfo['allParams'], TRouteInfo['routeLoaderData']>;
|
|
338
344
|
}
|
|
339
345
|
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
346
|
|
|
342
347
|
interface AnyAllRouteInfo {
|
|
343
348
|
routeConfig: AnyRouteConfig;
|
|
@@ -609,4 +614,4 @@ declare const defaultStringifySearch: (search: Record<string, any>) => string;
|
|
|
609
614
|
declare function parseSearchWith(parser: (str: string) => any): (searchStr: string) => AnySearchSchema;
|
|
610
615
|
declare function stringifySearchWith(stringify: (search: any) => string): (search: Record<string, any>) => string;
|
|
611
616
|
|
|
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,
|
|
617
|
+
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, cleanPath, createRoute, createRouteConfig, createRouteMatch, createRouter, decode, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, interpolatePath, joinPaths, last, matchByPath, matchPathname, parsePathname, parseSearchWith, pick, replaceEqualDeep, resolvePath, rootRouteId, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, warning };
|