@tanstack/react-router 0.0.1-beta.235 → 0.0.1-beta.237
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/Matches.js +31 -18
- package/build/cjs/Matches.js.map +1 -1
- package/build/cjs/RouterProvider.js +45 -25
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/cjs/index.js +1 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/route.js +13 -7
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js +49 -37
- package/build/cjs/router.js.map +1 -1
- package/build/cjs/useParams.js +7 -2
- package/build/cjs/useParams.js.map +1 -1
- package/build/cjs/useSearch.js +6 -1
- package/build/cjs/useSearch.js.map +1 -1
- package/build/cjs/utils.js +4 -1
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +155 -92
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +574 -293
- package/build/types/Matches.d.ts +9 -3
- package/build/types/RouterProvider.d.ts +3 -0
- package/build/types/route.d.ts +30 -10
- package/build/types/router.d.ts +6 -3
- package/build/types/useParams.d.ts +3 -1
- package/build/types/useSearch.d.ts +3 -1
- package/build/types/utils.d.ts +3 -1
- package/build/umd/index.development.js +423 -95
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +4 -2
- package/src/Matches.tsx +70 -35
- package/src/RouterProvider.tsx +68 -32
- package/src/route.ts +37 -15
- package/src/router.ts +62 -44
- package/src/useParams.tsx +14 -4
- package/src/useSearch.tsx +11 -3
- package/src/utils.ts +20 -12
package/src/useParams.tsx
CHANGED
|
@@ -2,14 +2,24 @@ import { AnyRoute } from './route'
|
|
|
2
2
|
import { RouteIds, RouteById, AllParams } from './routeInfo'
|
|
3
3
|
import { RegisteredRouter } from './router'
|
|
4
4
|
import { last } from './utils'
|
|
5
|
-
import {
|
|
5
|
+
import { useRouterState } from './RouterProvider'
|
|
6
6
|
import { StrictOrFrom } from './utils'
|
|
7
7
|
|
|
8
8
|
export function useParams<
|
|
9
9
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
10
10
|
TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
|
|
11
|
+
TDefaultSelected = AllParams<TRouteTree> &
|
|
12
|
+
RouteById<TRouteTree, TFrom>['types']['allParams'],
|
|
13
|
+
TSelected = TDefaultSelected,
|
|
11
14
|
>(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
opts: StrictOrFrom<TFrom> & {
|
|
16
|
+
select?: (search: TDefaultSelected) => TSelected
|
|
17
|
+
},
|
|
18
|
+
): TSelected {
|
|
19
|
+
return useRouterState({
|
|
20
|
+
select: (state: any) => {
|
|
21
|
+
const params = (last(state.matches) as any)?.params
|
|
22
|
+
return opts?.select ? opts.select(params) : params
|
|
23
|
+
},
|
|
24
|
+
})
|
|
15
25
|
}
|
package/src/useSearch.tsx
CHANGED
|
@@ -10,8 +10,16 @@ export function useSearch<
|
|
|
10
10
|
TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
|
|
11
11
|
TStrict extends boolean = true,
|
|
12
12
|
TSearch = RouteById<TRouteTree, TFrom>['types']['fullSearchSchema'],
|
|
13
|
+
TSelected = TSearch,
|
|
13
14
|
>(
|
|
14
|
-
opts: StrictOrFrom<TFrom
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
opts: StrictOrFrom<TFrom> & {
|
|
16
|
+
select?: (search: TSearch) => TSelected
|
|
17
|
+
},
|
|
18
|
+
): TStrict extends true ? TSelected : TSelected | undefined {
|
|
19
|
+
return useMatch({
|
|
20
|
+
...(opts as any),
|
|
21
|
+
select: (match: RouteMatch) => {
|
|
22
|
+
return opts?.select ? opts.select(match.search as TSearch) : match.search
|
|
23
|
+
},
|
|
24
|
+
})
|
|
17
25
|
}
|
package/src/utils.ts
CHANGED
|
@@ -18,8 +18,8 @@ export type PickExtra<T, K> = {
|
|
|
18
18
|
[TKey in keyof K as string extends TKey
|
|
19
19
|
? never
|
|
20
20
|
: TKey extends keyof T
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
? never
|
|
22
|
+
: TKey]: K[TKey]
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export type PickRequired<T> = {
|
|
@@ -105,15 +105,15 @@ export type ValueKeys<O> = Extract<keyof O, PropertyKey>
|
|
|
105
105
|
export type DeepAwaited<T> = T extends Promise<infer A>
|
|
106
106
|
? DeepAwaited<A>
|
|
107
107
|
: T extends Record<infer A, Promise<infer B>>
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
? { [K in A]: DeepAwaited<B> }
|
|
109
|
+
: T
|
|
110
110
|
|
|
111
111
|
export type PathParamMask<TRoutePath extends string> =
|
|
112
112
|
TRoutePath extends `${infer L}/$${infer C}/${infer R}`
|
|
113
113
|
? PathParamMask<`${L}/${string}/${R}`>
|
|
114
114
|
: TRoutePath extends `${infer L}/$${infer C}`
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
? PathParamMask<`${L}/${string}`>
|
|
116
|
+
: TRoutePath
|
|
117
117
|
|
|
118
118
|
export type Timeout = ReturnType<typeof setTimeout>
|
|
119
119
|
|
|
@@ -314,10 +314,10 @@ export type RouteFromIdOrRoute<
|
|
|
314
314
|
> = T extends ParseRoute<TRouteTree>
|
|
315
315
|
? T
|
|
316
316
|
: T extends RouteIds<TRouteTree>
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
317
|
+
? RoutesById<TRouteTree>[T]
|
|
318
|
+
: T extends string
|
|
319
|
+
? RouteIds<TRouteTree>
|
|
320
|
+
: never
|
|
321
321
|
|
|
322
322
|
export function useRouteContext<
|
|
323
323
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
@@ -326,9 +326,17 @@ export function useRouteContext<
|
|
|
326
326
|
TRouteContext = RouteById<TRouteTree, TFrom>['types']['allContext'],
|
|
327
327
|
TSelected = TRouteContext,
|
|
328
328
|
>(
|
|
329
|
-
opts: StrictOrFrom<TFrom
|
|
329
|
+
opts: StrictOrFrom<TFrom> & {
|
|
330
|
+
select?: (search: TRouteContext) => TSelected
|
|
331
|
+
},
|
|
330
332
|
): TStrict extends true ? TSelected : TSelected | undefined {
|
|
331
|
-
return useMatch(
|
|
333
|
+
return useMatch({
|
|
334
|
+
...(opts as any),
|
|
335
|
+
select: (match: RouteMatch) =>
|
|
336
|
+
opts?.select
|
|
337
|
+
? opts.select(match.context as TRouteContext)
|
|
338
|
+
: match.context,
|
|
339
|
+
})
|
|
332
340
|
}
|
|
333
341
|
|
|
334
342
|
export const useLayoutEffect =
|