@tanstack/react-router 1.2.6 → 1.3.1
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/fileRoute.js.map +1 -1
- package/build/cjs/link.js.map +1 -1
- package/build/cjs/route.js +98 -0
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js.map +1 -1
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +98 -0
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +353 -353
- package/build/types/link.d.ts +2 -12
- package/build/types/utils.d.ts +1 -21
- package/build/umd/index.development.js +98 -0
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/fileRoute.ts +0 -1
- package/src/link.tsx +1 -48
- package/src/route.ts +98 -0
- package/src/router.ts +0 -1
- package/src/utils.ts +1 -48
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://tanstack.com/router",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@tanstack/store": "^0.1.3",
|
|
45
45
|
"tiny-invariant": "^1.3.1",
|
|
46
46
|
"tiny-warning": "^1.0.3",
|
|
47
|
-
"@tanstack/history": "1.
|
|
47
|
+
"@tanstack/history": "1.3.1"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "rollup --config rollup.config.js"
|
package/src/fileRoute.ts
CHANGED
package/src/link.tsx
CHANGED
|
@@ -4,8 +4,6 @@ import { useRouter, useRouterState } from './RouterProvider'
|
|
|
4
4
|
import { Trim } from './fileRoute'
|
|
5
5
|
import { AnyRoute, ReactNode, RootSearchSchema } from './route'
|
|
6
6
|
import {
|
|
7
|
-
AllParams,
|
|
8
|
-
FullSearchSchema,
|
|
9
7
|
RouteByPath,
|
|
10
8
|
RouteIds,
|
|
11
9
|
RoutePaths,
|
|
@@ -17,7 +15,6 @@ import {
|
|
|
17
15
|
NoInfer,
|
|
18
16
|
NonNullableUpdater,
|
|
19
17
|
PickRequired,
|
|
20
|
-
UnionToIntersection,
|
|
21
18
|
Updater,
|
|
22
19
|
WithoutEmpty,
|
|
23
20
|
deepEqual,
|
|
@@ -190,7 +187,7 @@ export type ParamOptions<
|
|
|
190
187
|
RootSearchSchema
|
|
191
188
|
>
|
|
192
189
|
>,
|
|
193
|
-
TToIndex = RouteByPath<TRouteTree, `${TTo}/`> extends never ? TTo : `${TTo}/`,
|
|
190
|
+
TToIndex = TTo extends '' ? '' : RouteByPath<TRouteTree, `${TTo}/`> extends never ? TTo : `${TTo}/`,
|
|
194
191
|
TToParams = TToIndex extends ''
|
|
195
192
|
? TFromParams
|
|
196
193
|
: never extends TResolved
|
|
@@ -248,18 +245,6 @@ export type ToPathOption<
|
|
|
248
245
|
NoInfer<TTo> & string
|
|
249
246
|
>
|
|
250
247
|
|
|
251
|
-
export type ToIdOption<
|
|
252
|
-
TRouteTree extends AnyRoute = AnyRoute,
|
|
253
|
-
TFrom extends RoutePaths<TRouteTree> | undefined = undefined,
|
|
254
|
-
TTo extends string = '',
|
|
255
|
-
> =
|
|
256
|
-
| TTo
|
|
257
|
-
| RelativeToPathAutoComplete<
|
|
258
|
-
RouteIds<TRouteTree>,
|
|
259
|
-
NoInfer<TFrom> extends string ? NoInfer<TFrom> : '',
|
|
260
|
-
NoInfer<TTo> & string
|
|
261
|
-
>
|
|
262
|
-
|
|
263
248
|
export interface ActiveOptions {
|
|
264
249
|
exact?: boolean
|
|
265
250
|
includeHash?: boolean
|
|
@@ -285,24 +270,6 @@ export type LinkOptions<
|
|
|
285
270
|
disabled?: boolean
|
|
286
271
|
}
|
|
287
272
|
|
|
288
|
-
export type CheckRelativePath<
|
|
289
|
-
TRouteTree extends AnyRoute,
|
|
290
|
-
TFrom,
|
|
291
|
-
TTo,
|
|
292
|
-
> = TTo extends string
|
|
293
|
-
? TFrom extends string
|
|
294
|
-
? ResolveRelativePath<TFrom, TTo> extends RoutePaths<TRouteTree>
|
|
295
|
-
? {}
|
|
296
|
-
: {
|
|
297
|
-
Error: `${TFrom} + ${TTo} resolves to ${ResolveRelativePath<
|
|
298
|
-
TFrom,
|
|
299
|
-
TTo
|
|
300
|
-
>}, which is not a valid route path.`
|
|
301
|
-
'Valid Route Paths': RoutePaths<TRouteTree>
|
|
302
|
-
}
|
|
303
|
-
: {}
|
|
304
|
-
: {}
|
|
305
|
-
|
|
306
273
|
export type CheckPath<TRouteTree extends AnyRoute, TPath, TPass> = Exclude<
|
|
307
274
|
TPath,
|
|
308
275
|
RoutePaths<TRouteTree>
|
|
@@ -314,20 +281,6 @@ export type CheckPathError<TRouteTree extends AnyRoute, TInvalids> = {
|
|
|
314
281
|
to: RoutePaths<TRouteTree>
|
|
315
282
|
}
|
|
316
283
|
|
|
317
|
-
export type CheckId<TRouteTree extends AnyRoute, TPath, TPass> = Exclude<
|
|
318
|
-
TPath,
|
|
319
|
-
RouteIds<TRouteTree>
|
|
320
|
-
> extends never
|
|
321
|
-
? TPass
|
|
322
|
-
: CheckIdError<TRouteTree, Exclude<TPath, RouteIds<TRouteTree>>>
|
|
323
|
-
|
|
324
|
-
export type CheckIdError<TRouteTree extends AnyRoute, TInvalids> = {
|
|
325
|
-
Error: `${TInvalids extends string
|
|
326
|
-
? TInvalids
|
|
327
|
-
: never} is not a valid route ID.`
|
|
328
|
-
'Valid Route IDs': RouteIds<TRouteTree>
|
|
329
|
-
}
|
|
330
|
-
|
|
331
284
|
export type ResolveRelativePath<TFrom, TTo = '.'> = TFrom extends string
|
|
332
285
|
? TTo extends string
|
|
333
286
|
? TTo extends '.'
|
package/src/route.ts
CHANGED
|
@@ -366,6 +366,104 @@ export type RouteConstraints = {
|
|
|
366
366
|
TRouteTree: AnyRoute
|
|
367
367
|
}
|
|
368
368
|
|
|
369
|
+
// TODO: This is part of a future APi to move away from classes and
|
|
370
|
+
// towards a more functional API. It's not ready yet.
|
|
371
|
+
|
|
372
|
+
// type RouteApiInstance<
|
|
373
|
+
// TId extends RouteIds<RegisteredRouter['routeTree']>,
|
|
374
|
+
// TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,
|
|
375
|
+
// TFullSearchSchema extends Record<
|
|
376
|
+
// string,
|
|
377
|
+
// any
|
|
378
|
+
// > = TRoute['types']['fullSearchSchema'],
|
|
379
|
+
// TAllParams extends AnyPathParams = TRoute['types']['allParams'],
|
|
380
|
+
// TAllContext extends Record<string, any> = TRoute['types']['allContext'],
|
|
381
|
+
// TLoaderDeps extends Record<string, any> = TRoute['types']['loaderDeps'],
|
|
382
|
+
// TLoaderData extends any = TRoute['types']['loaderData'],
|
|
383
|
+
// > = {
|
|
384
|
+
// id: TId
|
|
385
|
+
// useMatch: <TSelected = TAllContext>(opts?: {
|
|
386
|
+
// select?: (s: TAllContext) => TSelected
|
|
387
|
+
// }) => TSelected
|
|
388
|
+
|
|
389
|
+
// useRouteContext: <TSelected = TAllContext>(opts?: {
|
|
390
|
+
// select?: (s: TAllContext) => TSelected
|
|
391
|
+
// }) => TSelected
|
|
392
|
+
|
|
393
|
+
// useSearch: <TSelected = TFullSearchSchema>(opts?: {
|
|
394
|
+
// select?: (s: TFullSearchSchema) => TSelected
|
|
395
|
+
// }) => TSelected
|
|
396
|
+
|
|
397
|
+
// useParams: <TSelected = TAllParams>(opts?: {
|
|
398
|
+
// select?: (s: TAllParams) => TSelected
|
|
399
|
+
// }) => TSelected
|
|
400
|
+
|
|
401
|
+
// useLoaderDeps: <TSelected = TLoaderDeps>(opts?: {
|
|
402
|
+
// select?: (s: TLoaderDeps) => TSelected
|
|
403
|
+
// }) => TSelected
|
|
404
|
+
|
|
405
|
+
// useLoaderData: <TSelected = TLoaderData>(opts?: {
|
|
406
|
+
// select?: (s: TLoaderData) => TSelected
|
|
407
|
+
// }) => TSelected
|
|
408
|
+
// }
|
|
409
|
+
|
|
410
|
+
// export function RouteApi_v2<
|
|
411
|
+
// TId extends RouteIds<RegisteredRouter['routeTree']>,
|
|
412
|
+
// TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,
|
|
413
|
+
// TFullSearchSchema extends Record<
|
|
414
|
+
// string,
|
|
415
|
+
// any
|
|
416
|
+
// > = TRoute['types']['fullSearchSchema'],
|
|
417
|
+
// TAllParams extends AnyPathParams = TRoute['types']['allParams'],
|
|
418
|
+
// TAllContext extends Record<string, any> = TRoute['types']['allContext'],
|
|
419
|
+
// TLoaderDeps extends Record<string, any> = TRoute['types']['loaderDeps'],
|
|
420
|
+
// TLoaderData extends any = TRoute['types']['loaderData'],
|
|
421
|
+
// >({
|
|
422
|
+
// id,
|
|
423
|
+
// }: {
|
|
424
|
+
// id: TId
|
|
425
|
+
// }): RouteApiInstance<
|
|
426
|
+
// TId,
|
|
427
|
+
// TRoute,
|
|
428
|
+
// TFullSearchSchema,
|
|
429
|
+
// TAllParams,
|
|
430
|
+
// TAllContext,
|
|
431
|
+
// TLoaderDeps,
|
|
432
|
+
// TLoaderData
|
|
433
|
+
// > {
|
|
434
|
+
// return {
|
|
435
|
+
// id,
|
|
436
|
+
|
|
437
|
+
// useMatch: (opts) => {
|
|
438
|
+
// return useMatch({ ...opts, from: id })
|
|
439
|
+
// },
|
|
440
|
+
|
|
441
|
+
// useRouteContext: (opts) => {
|
|
442
|
+
// return useMatch({
|
|
443
|
+
// ...opts,
|
|
444
|
+
// from: id,
|
|
445
|
+
// select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),
|
|
446
|
+
// } as any)
|
|
447
|
+
// },
|
|
448
|
+
|
|
449
|
+
// useSearch: (opts) => {
|
|
450
|
+
// return useSearch({ ...opts, from: id } as any)
|
|
451
|
+
// },
|
|
452
|
+
|
|
453
|
+
// useParams: (opts) => {
|
|
454
|
+
// return useParams({ ...opts, from: id } as any)
|
|
455
|
+
// },
|
|
456
|
+
|
|
457
|
+
// useLoaderDeps: (opts) => {
|
|
458
|
+
// return useLoaderDeps({ ...opts, from: id } as any) as any
|
|
459
|
+
// },
|
|
460
|
+
|
|
461
|
+
// useLoaderData: (opts) => {
|
|
462
|
+
// return useLoaderData({ ...opts, from: id } as any) as any
|
|
463
|
+
// },
|
|
464
|
+
// }
|
|
465
|
+
// }
|
|
466
|
+
|
|
369
467
|
export class RouteApi<
|
|
370
468
|
TId extends RouteIds<RegisteredRouter['routeTree']>,
|
|
371
469
|
TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,
|
package/src/router.ts
CHANGED
package/src/utils.ts
CHANGED
|
@@ -2,25 +2,13 @@ import * as React from 'react'
|
|
|
2
2
|
import { useMatch } from './Matches'
|
|
3
3
|
import { RouteMatch } from './Matches'
|
|
4
4
|
import { AnyRoute } from './route'
|
|
5
|
-
import {
|
|
5
|
+
import { RouteIds, RouteById } from './routeInfo'
|
|
6
6
|
import { RegisteredRouter } from './router'
|
|
7
7
|
|
|
8
8
|
export type NoInfer<T> = [T][T extends any ? 0 : never]
|
|
9
9
|
export type IsAny<T, Y, N = T> = 1 extends 0 & T ? Y : N
|
|
10
|
-
export type IsAnyBoolean<T> = 1 extends 0 & T ? true : false
|
|
11
|
-
export type IsKnown<T, Y, N> = unknown extends T ? N : Y
|
|
12
10
|
export type PickAsRequired<T, K extends keyof T> = Omit<T, K> &
|
|
13
11
|
Required<Pick<T, K>>
|
|
14
|
-
export type PickAsPartial<T, K extends keyof T> = Omit<T, K> &
|
|
15
|
-
Partial<Pick<T, K>>
|
|
16
|
-
export type PickUnsafe<T, K> = K extends keyof T ? Pick<T, K> : never
|
|
17
|
-
export type PickExtra<T, K> = {
|
|
18
|
-
[TKey in keyof K as string extends TKey
|
|
19
|
-
? never
|
|
20
|
-
: TKey extends keyof T
|
|
21
|
-
? never
|
|
22
|
-
: TKey]: K[TKey]
|
|
23
|
-
}
|
|
24
12
|
|
|
25
13
|
export type PickRequired<T> = {
|
|
26
14
|
[K in keyof T as undefined extends T[K] ? never : K]: T[K]
|
|
@@ -102,22 +90,6 @@ export type AssignAll<T extends any[]> = T extends [infer Left, ...infer Right]
|
|
|
102
90
|
// // Using DeepMerge to merge TypeA and TypeB
|
|
103
91
|
// type MergedType = Expand<AssignAll<[TypeA, TypeB, TypeC]>>
|
|
104
92
|
|
|
105
|
-
export type Values<O> = O[ValueKeys<O>]
|
|
106
|
-
export type ValueKeys<O> = Extract<keyof O, PropertyKey>
|
|
107
|
-
|
|
108
|
-
export type DeepAwaited<T> = T extends Promise<infer A>
|
|
109
|
-
? DeepAwaited<A>
|
|
110
|
-
: T extends Record<infer A, Promise<infer B>>
|
|
111
|
-
? { [K in A]: DeepAwaited<B> }
|
|
112
|
-
: T
|
|
113
|
-
|
|
114
|
-
export type PathParamMask<TRoutePath extends string> =
|
|
115
|
-
TRoutePath extends `${infer L}/$${infer C}/${infer R}`
|
|
116
|
-
? PathParamMask<`${L}/${string}/${R}`>
|
|
117
|
-
: TRoutePath extends `${infer L}/$${infer C}`
|
|
118
|
-
? PathParamMask<`${L}/${string}`>
|
|
119
|
-
: TRoutePath
|
|
120
|
-
|
|
121
93
|
export type Timeout = ReturnType<typeof setTimeout>
|
|
122
94
|
|
|
123
95
|
export type Updater<TPrevious, TResult = TPrevious> =
|
|
@@ -128,14 +100,6 @@ export type NonNullableUpdater<TPrevious, TResult = TPrevious> =
|
|
|
128
100
|
| TResult
|
|
129
101
|
| ((prev: TPrevious) => TResult)
|
|
130
102
|
|
|
131
|
-
export type PickExtract<T, U> = {
|
|
132
|
-
[K in keyof T as T[K] extends U ? K : never]: T[K]
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export type PickExclude<T, U> = {
|
|
136
|
-
[K in keyof T as T[K] extends U ? never : K]: T[K]
|
|
137
|
-
}
|
|
138
|
-
|
|
139
103
|
// from https://github.com/type-challenges/type-challenges/issues/737
|
|
140
104
|
type LastInUnion<U> = UnionToIntersection<
|
|
141
105
|
U extends unknown ? (x: U) => 0 : never
|
|
@@ -321,17 +285,6 @@ export type StrictOrFrom<TFrom> =
|
|
|
321
285
|
strict: false
|
|
322
286
|
}
|
|
323
287
|
|
|
324
|
-
export type RouteFromIdOrRoute<
|
|
325
|
-
T,
|
|
326
|
-
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
327
|
-
> = T extends ParseRoute<TRouteTree>
|
|
328
|
-
? T
|
|
329
|
-
: T extends RouteIds<TRouteTree>
|
|
330
|
-
? RoutesById<TRouteTree>[T]
|
|
331
|
-
: T extends string
|
|
332
|
-
? RouteIds<TRouteTree>
|
|
333
|
-
: never
|
|
334
|
-
|
|
335
288
|
export function useRouteContext<
|
|
336
289
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
337
290
|
TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
|