Skip to content

Commit 780faf6

Browse files
committed
Add router-core package
1 parent 255f316 commit 780faf6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1355
-1150
lines changed

packages/react-router/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"dependencies": {
6969
"@tanstack/history": "workspace:*",
7070
"@tanstack/react-store": "^0.7.0",
71+
"@tanstack/router-core": "workspace:*",
7172
"jsesc": "^3.0.2",
7273
"tiny-invariant": "^1.3.3",
7374
"tiny-warning": "^1.0.3"

packages/react-router/src/Match.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
import * as React from 'react'
44
import invariant from 'tiny-invariant'
55
import warning from 'tiny-warning'
6+
import { createControlledPromise, defaultDeserializeError, isServerSideError , pick, rootRouteId } from '@tanstack/router-core'
67
import { CatchBoundary, ErrorComponent } from './CatchBoundary'
78
import { useRouterState } from './useRouterState'
89
import { useRouter } from './useRouter'
9-
import { createControlledPromise, pick } from './utils'
1010
import { CatchNotFound, isNotFound } from './not-found'
1111
import { isRedirect } from './redirects'
1212
import { matchContext } from './matchContext'
13-
import { defaultDeserializeError, isServerSideError } from './isServerSideError'
1413
import { SafeFragment } from './SafeFragment'
1514
import { renderRouteNotFound } from './renderRouteNotFound'
16-
import { rootRouteId } from './root'
1715
import type { AnyRoute } from './route'
1816

1917
export const Match = React.memo(function MatchImpl({

packages/react-router/src/Matches.tsx

Lines changed: 6 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ import type {
1111
StructuralSharingOption,
1212
ValidateSelected,
1313
} from './structuralSharing'
14-
import type { AnyRoute, ReactNode, StaticDataRouteOption } from './route'
14+
import type { AnyRoute, ReactNode } from './route'
15+
import type { ControlledPromise,
16+
DeepPartial,
17+
NoInfer,
18+
ResolveRelativePath,
19+
StaticDataRouteOption } from '@tanstack/router-core'
1520
import type { AnyRouter, RegisteredRouter, RouterState } from './router'
1621
import type {
1722
MakeOptionalPathParams,
1823
MakeOptionalSearchParams,
1924
MaskOptions,
20-
ResolveRelativePath,
2125
ResolveRoute,
2226
ToSubOptionsProps,
2327
} from './link'
@@ -31,105 +35,6 @@ import type {
3135
RouteByPath,
3236
RouteIds,
3337
} from './routeInfo'
34-
import type {
35-
Constrain,
36-
ControlledPromise,
37-
DeepPartial,
38-
NoInfer,
39-
} from './utils'
40-
41-
export type AnyMatchAndValue = { match: any; value: any }
42-
43-
export type FindValueByIndex<
44-
TKey,
45-
TValue extends ReadonlyArray<any>,
46-
> = TKey extends `${infer TIndex extends number}` ? TValue[TIndex] : never
47-
48-
export type FindValueByKey<TKey, TValue> =
49-
TValue extends ReadonlyArray<any>
50-
? FindValueByIndex<TKey, TValue>
51-
: TValue[TKey & keyof TValue]
52-
53-
export type CreateMatchAndValue<TMatch, TValue> = TValue extends any
54-
? {
55-
match: TMatch
56-
value: TValue
57-
}
58-
: never
59-
60-
export type NextMatchAndValue<
61-
TKey,
62-
TMatchAndValue extends AnyMatchAndValue,
63-
> = TMatchAndValue extends any
64-
? CreateMatchAndValue<
65-
TMatchAndValue['match'],
66-
FindValueByKey<TKey, TMatchAndValue['value']>
67-
>
68-
: never
69-
70-
export type IsMatchKeyOf<TValue> =
71-
TValue extends ReadonlyArray<any>
72-
? number extends TValue['length']
73-
? `${number}`
74-
: keyof TValue & `${number}`
75-
: TValue extends object
76-
? keyof TValue & string
77-
: never
78-
79-
export type IsMatchPath<
80-
TParentPath extends string,
81-
TMatchAndValue extends AnyMatchAndValue,
82-
> = `${TParentPath}${IsMatchKeyOf<TMatchAndValue['value']>}`
83-
84-
export type IsMatchResult<
85-
TKey,
86-
TMatchAndValue extends AnyMatchAndValue,
87-
> = TMatchAndValue extends any
88-
? TKey extends keyof TMatchAndValue['value']
89-
? TMatchAndValue['match']
90-
: never
91-
: never
92-
93-
export type IsMatchParse<
94-
TPath,
95-
TMatchAndValue extends AnyMatchAndValue,
96-
TParentPath extends string = '',
97-
> = TPath extends `${string}.${string}`
98-
? TPath extends `${infer TFirst}.${infer TRest}`
99-
? IsMatchParse<
100-
TRest,
101-
NextMatchAndValue<TFirst, TMatchAndValue>,
102-
`${TParentPath}${TFirst}.`
103-
>
104-
: never
105-
: {
106-
path: IsMatchPath<TParentPath, TMatchAndValue>
107-
result: IsMatchResult<TPath, TMatchAndValue>
108-
}
109-
110-
export type IsMatch<TMatch, TPath> = IsMatchParse<
111-
TPath,
112-
TMatch extends any ? { match: TMatch; value: TMatch } : never
113-
>
114-
115-
/**
116-
* Narrows matches based on a path
117-
* @experimental
118-
*/
119-
export const isMatch = <TMatch, TPath extends string>(
120-
match: TMatch,
121-
path: Constrain<TPath, IsMatch<TMatch, TPath>['path']>,
122-
): match is IsMatch<TMatch, TPath>['result'] => {
123-
const parts = (path as string).split('.')
124-
let part
125-
let value: any = match
126-
127-
while ((part = parts.shift()) != null && value != null) {
128-
value = value[part]
129-
}
130-
131-
return value != null
132-
}
13338

13439
export type MakeRouteMatchFromRoute<TRoute extends AnyRoute> = RouteMatch<
13540
TRoute['types']['id'],

packages/react-router/src/RouterProvider.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ import * as React from 'react'
22
import { Matches } from './Matches'
33
import { getRouterContext } from './routerContext'
44
import type { NavigateOptions, ToOptions } from './link'
5-
import type { ParsedLocation } from './location'
5+
import type { ParsedLocation, ViewTransitionOptions } from '@tanstack/router-core'
66
import type { RoutePaths } from './routeInfo'
77
import type {
88
AnyRouter,
99
RegisteredRouter,
1010
Router,
1111
RouterOptions,
12-
ViewTransitionOptions,
1312
} from './router'
1413

1514
export interface CommitLocationOptions {

packages/react-router/src/Transitioner.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as React from 'react'
2+
import { trimPathRight } from '@tanstack/router-core'
23
import { useLayoutEffect, usePrevious } from './utils'
34
import { useRouter } from './useRouter'
45
import { useRouterState } from './useRouterState'
5-
import { trimPathRight } from './path'
66

77
export function Transitioner() {
88
const router = useRouter()

packages/react-router/src/awaited.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import * as React from 'react'
22
import warning from 'tiny-warning'
3+
import { TSR_DEFERRED_PROMISE, defaultDeserializeError, defaultSerializeError, defer, isServerSideError } from '@tanstack/router-core'
34
import { useRouter } from './useRouter'
4-
import { defaultSerializeError } from './router'
5-
import { TSR_DEFERRED_PROMISE, defer } from './defer'
6-
import { defaultDeserializeError, isServerSideError } from './isServerSideError'
7-
import type { DeferredPromise } from './defer'
5+
import type { DeferredPromise } from '@tanstack/router-core'
86

97
export type AwaitOptions<T> = {
108
promise: Promise<T>

packages/react-router/src/fileRoute.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ import { useNavigate } from './useNavigate'
1010
import type { UseParamsRoute } from './useParams'
1111
import type { UseMatchRoute } from './useMatch'
1212
import type { UseSearchRoute } from './useSearch'
13-
import type { Constrain } from './utils'
13+
import type { AnyContext,AnyPathParams, AnyValidator, Constrain,ResolveParams } from '@tanstack/router-core'
14+
1415
import type {
15-
AnyContext,
16-
AnyPathParams,
1716
AnyRoute,
1817
FileBaseRouteOptions,
19-
ResolveParams,
2018
RootRoute,
2119
Route,
2220
RouteConstraints,
@@ -25,7 +23,6 @@ import type {
2523
} from './route'
2624
import type { RegisteredRouter } from './router'
2725
import type { RouteById, RouteIds } from './routeInfo'
28-
import type { AnyValidator } from './validators'
2926
import type { UseLoaderDepsRoute } from './useLoaderDeps'
3027
import type { UseLoaderDataRoute } from './useLoaderData'
3128
import type { UseRouteContextRoute } from './useRouteContext'

0 commit comments

Comments
 (0)