@tanstack/router-core 0.0.1-beta.145 → 0.0.1-beta.147
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 +29 -0
- package/build/cjs/fileRoute.js.map +1 -0
- package/build/cjs/index.js +2 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/route.js +0 -44
- package/build/cjs/route.js.map +1 -1
- package/build/esm/index.js +11 -44
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +139 -107
- package/build/types/index.d.ts +47 -3
- package/build/umd/index.development.js +11 -43
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +3 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/fileRoute.ts +122 -0
- package/src/index.ts +1 -0
- package/src/link.ts +3 -1
- package/src/route.ts +12 -48
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/router-core",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "0.0.1-beta.
|
|
4
|
+
"version": "0.0.1-beta.147",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://tanstack.com/router",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"tiny-invariant": "^1.3.1",
|
|
44
44
|
"tiny-warning": "^1.0.3",
|
|
45
45
|
"@gisatcz/cross-package-react-context": "^0.2.0",
|
|
46
|
-
"@tanstack/react-store": "0.0.1-beta.
|
|
46
|
+
"@tanstack/react-store": "0.0.1-beta.147"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "rollup --config rollup.config.js",
|
package/src/fileRoute.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Last, ParsePathParams, Split } from './link'
|
|
2
|
+
import {
|
|
3
|
+
AnyRoute,
|
|
4
|
+
ResolveFullPath,
|
|
5
|
+
ResolveId,
|
|
6
|
+
AnySearchSchema,
|
|
7
|
+
ResolveFullSearchSchema,
|
|
8
|
+
MergeParamsFromParent,
|
|
9
|
+
RouteContext,
|
|
10
|
+
AnyContext,
|
|
11
|
+
RouteOptions,
|
|
12
|
+
InferFullSearchSchema,
|
|
13
|
+
UpdatableRouteOptions,
|
|
14
|
+
Route,
|
|
15
|
+
} from './route'
|
|
16
|
+
import { DefaultRoutesInfo } from './routeInfo'
|
|
17
|
+
|
|
18
|
+
export interface FileRoutesByPath {
|
|
19
|
+
// '/': {
|
|
20
|
+
// parentRoute: typeof rootRoute
|
|
21
|
+
// }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type Test = Last<Split<'/test/:id'>>
|
|
25
|
+
|
|
26
|
+
export class FileRoute<
|
|
27
|
+
TFilePath extends keyof FileRoutesByPath,
|
|
28
|
+
TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],
|
|
29
|
+
TPath extends string = Last<Split<TFilePath>>,
|
|
30
|
+
TCustomId extends string = TPath extends `_${infer T}` ? T : string,
|
|
31
|
+
> {
|
|
32
|
+
constructor(public path: TFilePath) {}
|
|
33
|
+
|
|
34
|
+
createRoute = <
|
|
35
|
+
TFullPath extends ResolveFullPath<TParentRoute, TPath> = ResolveFullPath<
|
|
36
|
+
TParentRoute,
|
|
37
|
+
TPath
|
|
38
|
+
>,
|
|
39
|
+
TId extends ResolveId<TParentRoute, TCustomId, TPath> = ResolveId<
|
|
40
|
+
TParentRoute,
|
|
41
|
+
TCustomId,
|
|
42
|
+
TPath
|
|
43
|
+
>,
|
|
44
|
+
TLoader = unknown,
|
|
45
|
+
TSearchSchema extends AnySearchSchema = {},
|
|
46
|
+
TFullSearchSchema extends AnySearchSchema = ResolveFullSearchSchema<
|
|
47
|
+
TParentRoute,
|
|
48
|
+
TSearchSchema
|
|
49
|
+
>,
|
|
50
|
+
TParams extends Record<ParsePathParams<TPath>, any> = Record<
|
|
51
|
+
ParsePathParams<TPath>,
|
|
52
|
+
string
|
|
53
|
+
>,
|
|
54
|
+
TAllParams extends MergeParamsFromParent<
|
|
55
|
+
TParentRoute['__types']['allParams'],
|
|
56
|
+
TParams
|
|
57
|
+
> = MergeParamsFromParent<TParentRoute['__types']['allParams'], TParams>,
|
|
58
|
+
TParentContext extends TParentRoute['__types']['routeContext'] = TParentRoute['__types']['routeContext'],
|
|
59
|
+
TAllParentContext extends TParentRoute['__types']['context'] = TParentRoute['__types']['context'],
|
|
60
|
+
TRouteContext extends RouteContext = RouteContext,
|
|
61
|
+
TContext extends MergeParamsFromParent<
|
|
62
|
+
TParentRoute['__types']['context'],
|
|
63
|
+
TRouteContext
|
|
64
|
+
> = MergeParamsFromParent<
|
|
65
|
+
TParentRoute['__types']['context'],
|
|
66
|
+
TRouteContext
|
|
67
|
+
>,
|
|
68
|
+
TRouterContext extends AnyContext = AnyContext,
|
|
69
|
+
TChildren extends unknown = unknown,
|
|
70
|
+
TRoutesInfo extends DefaultRoutesInfo = DefaultRoutesInfo,
|
|
71
|
+
>(
|
|
72
|
+
options: Omit<
|
|
73
|
+
RouteOptions<
|
|
74
|
+
TParentRoute,
|
|
75
|
+
TCustomId,
|
|
76
|
+
TPath,
|
|
77
|
+
TLoader,
|
|
78
|
+
InferFullSearchSchema<TParentRoute>,
|
|
79
|
+
TSearchSchema,
|
|
80
|
+
TFullSearchSchema,
|
|
81
|
+
TParentRoute['__types']['allParams'],
|
|
82
|
+
TParams,
|
|
83
|
+
TAllParams,
|
|
84
|
+
TParentContext,
|
|
85
|
+
TAllParentContext,
|
|
86
|
+
TRouteContext,
|
|
87
|
+
TContext
|
|
88
|
+
>,
|
|
89
|
+
'getParentRoute' | 'path' | 'id'
|
|
90
|
+
> &
|
|
91
|
+
UpdatableRouteOptions<
|
|
92
|
+
TLoader,
|
|
93
|
+
TSearchSchema,
|
|
94
|
+
TFullSearchSchema,
|
|
95
|
+
TAllParams,
|
|
96
|
+
TRouteContext,
|
|
97
|
+
TContext
|
|
98
|
+
>,
|
|
99
|
+
): Route<
|
|
100
|
+
TParentRoute,
|
|
101
|
+
TPath,
|
|
102
|
+
TFullPath,
|
|
103
|
+
TCustomId,
|
|
104
|
+
TId,
|
|
105
|
+
TLoader,
|
|
106
|
+
TSearchSchema,
|
|
107
|
+
TFullSearchSchema,
|
|
108
|
+
TParams,
|
|
109
|
+
TAllParams,
|
|
110
|
+
TParentContext,
|
|
111
|
+
TAllParentContext,
|
|
112
|
+
TRouteContext,
|
|
113
|
+
TContext,
|
|
114
|
+
TRouterContext,
|
|
115
|
+
TChildren,
|
|
116
|
+
TRoutesInfo
|
|
117
|
+
> => {
|
|
118
|
+
const route = new Route(options as any)
|
|
119
|
+
;(route as any).isRoot = false
|
|
120
|
+
return route as any
|
|
121
|
+
}
|
|
122
|
+
}
|
package/src/index.ts
CHANGED
package/src/link.ts
CHANGED
|
@@ -55,7 +55,7 @@ export type ParsePathParams<T extends string> = Split<T>[number] extends infer U
|
|
|
55
55
|
: never
|
|
56
56
|
: never
|
|
57
57
|
|
|
58
|
-
type Join<T, Delimiter extends string = '/'> = T extends []
|
|
58
|
+
export type Join<T, Delimiter extends string = '/'> = T extends []
|
|
59
59
|
? ''
|
|
60
60
|
: T extends [infer L extends string]
|
|
61
61
|
? L
|
|
@@ -63,6 +63,8 @@ type Join<T, Delimiter extends string = '/'> = T extends []
|
|
|
63
63
|
? CleanPath<`${L}${Delimiter}${Join<Tail>}`>
|
|
64
64
|
: never
|
|
65
65
|
|
|
66
|
+
export type Last<T extends any[]> = T extends [...infer _, infer L] ? L : never
|
|
67
|
+
|
|
66
68
|
export type RelativeToPathAutoComplete<
|
|
67
69
|
AllPaths extends string,
|
|
68
70
|
TFrom extends string,
|
package/src/route.ts
CHANGED
|
@@ -310,8 +310,16 @@ export type UpdatableRouteOptions<
|
|
|
310
310
|
RouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TContext>
|
|
311
311
|
>
|
|
312
312
|
// The content to be rendered when the route encounters an error
|
|
313
|
-
errorComponent?:
|
|
314
|
-
|
|
313
|
+
errorComponent?: RegisteredRouteErrorComponent<
|
|
314
|
+
{ error: unknown } & Partial<
|
|
315
|
+
RouteProps<
|
|
316
|
+
TLoader,
|
|
317
|
+
TFullSearchSchema,
|
|
318
|
+
TAllParams,
|
|
319
|
+
TRouteContext,
|
|
320
|
+
TContext
|
|
321
|
+
>
|
|
322
|
+
>
|
|
315
323
|
> //
|
|
316
324
|
// If supported by your framework, the content to be rendered as the fallback content until the route is ready to render
|
|
317
325
|
pendingComponent?: RegisteredRouteComponent<
|
|
@@ -807,7 +815,7 @@ export class RouterContext<TRouterContext extends {}> {
|
|
|
807
815
|
>,
|
|
808
816
|
) => {
|
|
809
817
|
return new RootRoute<TLoader, TSearchSchema, TContext, TRouterContext>(
|
|
810
|
-
options,
|
|
818
|
+
options as any,
|
|
811
819
|
)
|
|
812
820
|
}
|
|
813
821
|
}
|
|
@@ -838,7 +846,7 @@ export class RootRoute<
|
|
|
838
846
|
> {
|
|
839
847
|
constructor(
|
|
840
848
|
options?: Omit<
|
|
841
|
-
RouteOptions<AnyRoute, RootRouteId, '',
|
|
849
|
+
RouteOptions<AnyRoute, RootRouteId, '', TLoader, TSearchSchema, {}, {}>,
|
|
842
850
|
| 'path'
|
|
843
851
|
| 'id'
|
|
844
852
|
| 'getParentRoute'
|
|
@@ -890,47 +898,3 @@ export type TrimPathRight<T extends string> = T extends '/'
|
|
|
890
898
|
: T extends `${infer U}/`
|
|
891
899
|
? TrimPathRight<U>
|
|
892
900
|
: T
|
|
893
|
-
|
|
894
|
-
// const rootRoute = new RootRoute({
|
|
895
|
-
// validateSearch: () => null as unknown as { root?: boolean },
|
|
896
|
-
// })
|
|
897
|
-
|
|
898
|
-
// const aRoute = new Route({
|
|
899
|
-
// getParentRoute: () => rootRoute,
|
|
900
|
-
// path: 'a',
|
|
901
|
-
// validateSearch: () => null as unknown as { a?: string },
|
|
902
|
-
// })
|
|
903
|
-
|
|
904
|
-
// const bRoute = new Route({
|
|
905
|
-
// getParentRoute: () => aRoute,
|
|
906
|
-
// path: 'b',
|
|
907
|
-
// })
|
|
908
|
-
|
|
909
|
-
// const rootIsRoot = rootRoute.isRoot
|
|
910
|
-
// // ^?
|
|
911
|
-
// const aIsRoot = aRoute.isRoot
|
|
912
|
-
// // ^?
|
|
913
|
-
|
|
914
|
-
// const rId = rootRoute.id
|
|
915
|
-
// // ^?
|
|
916
|
-
// const aId = aRoute.id
|
|
917
|
-
// // ^?
|
|
918
|
-
// const bId = bRoute.id
|
|
919
|
-
// // ^?
|
|
920
|
-
|
|
921
|
-
// const rPath = rootRoute.fullPath
|
|
922
|
-
// // ^?
|
|
923
|
-
// const aPath = aRoute.fullPath
|
|
924
|
-
// // ^?
|
|
925
|
-
// const bPath = bRoute.fullPath
|
|
926
|
-
// // ^?
|
|
927
|
-
|
|
928
|
-
// const rSearch = rootRoute.__types.fullSearchSchema
|
|
929
|
-
// // ^?
|
|
930
|
-
// const aSearch = aRoute.__types.fullSearchSchema
|
|
931
|
-
// // ^?
|
|
932
|
-
// const bSearch = bRoute.__types.fullSearchSchema
|
|
933
|
-
// // ^?
|
|
934
|
-
|
|
935
|
-
// const config = rootRoute.addChildren([aRoute.addChildren([bRoute])])
|
|
936
|
-
// // ^?
|