@tanstack/react-router 0.0.1-beta.22 → 0.0.1-beta.220

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.
Files changed (108) hide show
  1. package/LICENSE +21 -0
  2. package/build/cjs/CatchBoundary.js +126 -0
  3. package/build/cjs/CatchBoundary.js.map +1 -0
  4. package/build/cjs/Matches.js +235 -0
  5. package/build/cjs/Matches.js.map +1 -0
  6. package/build/cjs/RouterProvider.js +1085 -0
  7. package/build/cjs/RouterProvider.js.map +1 -0
  8. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +1 -19
  9. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  10. package/build/cjs/awaited.js +45 -0
  11. package/build/cjs/awaited.js.map +1 -0
  12. package/build/cjs/defer.js +39 -0
  13. package/build/cjs/defer.js.map +1 -0
  14. package/build/cjs/fileRoute.js +29 -0
  15. package/build/cjs/fileRoute.js.map +1 -0
  16. package/build/cjs/index.js +135 -0
  17. package/build/cjs/index.js.map +1 -0
  18. package/build/cjs/lazyRouteComponent.js +57 -0
  19. package/build/cjs/lazyRouteComponent.js.map +1 -0
  20. package/build/cjs/link.js +151 -0
  21. package/build/cjs/link.js.map +1 -0
  22. package/build/cjs/path.js +211 -0
  23. package/build/cjs/path.js.map +1 -0
  24. package/build/cjs/qss.js +65 -0
  25. package/build/cjs/qss.js.map +1 -0
  26. package/build/cjs/redirects.js +27 -0
  27. package/build/cjs/redirects.js.map +1 -0
  28. package/build/cjs/route.js +139 -0
  29. package/build/cjs/route.js.map +1 -0
  30. package/build/cjs/router.js +160 -0
  31. package/build/cjs/router.js.map +1 -0
  32. package/build/cjs/scroll-restoration.js +186 -0
  33. package/build/cjs/scroll-restoration.js.map +1 -0
  34. package/build/cjs/searchParams.js +83 -0
  35. package/build/cjs/searchParams.js.map +1 -0
  36. package/build/cjs/useBlocker.js +64 -0
  37. package/build/cjs/useBlocker.js.map +1 -0
  38. package/build/cjs/useNavigate.js +78 -0
  39. package/build/cjs/useNavigate.js.map +1 -0
  40. package/build/cjs/useParams.js +28 -0
  41. package/build/cjs/useParams.js.map +1 -0
  42. package/build/cjs/useSearch.js +27 -0
  43. package/build/cjs/useSearch.js.map +1 -0
  44. package/build/cjs/utils.js +236 -0
  45. package/build/cjs/utils.js.map +1 -0
  46. package/build/esm/index.js +2136 -2564
  47. package/build/esm/index.js.map +1 -1
  48. package/build/stats-html.html +59 -49
  49. package/build/stats-react.json +922 -43
  50. package/build/types/CatchBoundary.d.ts +33 -0
  51. package/build/types/Matches.d.ts +34 -0
  52. package/build/types/RouterProvider.d.ts +87 -0
  53. package/build/types/awaited.d.ts +8 -0
  54. package/build/types/defer.d.ts +19 -0
  55. package/build/types/fileRoute.d.ts +32 -0
  56. package/build/types/history.d.ts +7 -0
  57. package/build/types/index.d.ts +27 -104
  58. package/build/types/injectHtml.d.ts +0 -0
  59. package/build/types/lazyRouteComponent.d.ts +2 -0
  60. package/build/types/link.d.ts +105 -0
  61. package/build/types/location.d.ts +14 -0
  62. package/build/types/path.d.ts +16 -0
  63. package/build/types/qss.d.ts +2 -0
  64. package/build/types/redirects.d.ts +10 -0
  65. package/build/types/route.d.ts +270 -0
  66. package/build/types/routeInfo.d.ts +22 -0
  67. package/build/types/router.d.ts +123 -0
  68. package/build/types/scroll-restoration.d.ts +6 -0
  69. package/build/types/searchParams.d.ts +7 -0
  70. package/build/types/useBlocker.d.ts +8 -0
  71. package/build/types/useNavigate.d.ts +20 -0
  72. package/build/types/useParams.d.ts +7 -0
  73. package/build/types/useSearch.d.ts +7 -0
  74. package/build/types/utils.d.ts +66 -0
  75. package/build/umd/index.development.js +2399 -2484
  76. package/build/umd/index.development.js.map +1 -1
  77. package/build/umd/index.production.js +4 -4
  78. package/build/umd/index.production.js.map +1 -1
  79. package/package.json +9 -10
  80. package/src/CatchBoundary.tsx +98 -0
  81. package/src/Matches.tsx +345 -0
  82. package/src/RouterProvider.tsx +1575 -0
  83. package/src/awaited.tsx +40 -0
  84. package/src/defer.ts +55 -0
  85. package/src/fileRoute.ts +153 -0
  86. package/src/history.ts +8 -0
  87. package/src/index.tsx +28 -693
  88. package/src/injectHtml.ts +28 -0
  89. package/src/lazyRouteComponent.tsx +33 -0
  90. package/src/link.tsx +508 -0
  91. package/src/location.ts +15 -0
  92. package/src/path.ts +256 -0
  93. package/src/qss.ts +53 -0
  94. package/src/redirects.ts +31 -0
  95. package/src/route.ts +837 -0
  96. package/src/routeInfo.ts +68 -0
  97. package/src/router.ts +330 -0
  98. package/src/scroll-restoration.tsx +192 -0
  99. package/src/searchParams.ts +79 -0
  100. package/src/useBlocker.tsx +34 -0
  101. package/src/useNavigate.tsx +109 -0
  102. package/src/useParams.tsx +25 -0
  103. package/src/useSearch.tsx +25 -0
  104. package/src/utils.ts +350 -0
  105. package/build/cjs/react-router/src/index.js +0 -466
  106. package/build/cjs/react-router/src/index.js.map +0 -1
  107. package/build/cjs/router-core/build/esm/index.js +0 -2523
  108. package/build/cjs/router-core/build/esm/index.js.map +0 -1
@@ -0,0 +1,40 @@
1
+ import { useRouter } from './RouterProvider'
2
+ import { DeferredPromise, isDehydratedDeferred } from './defer'
3
+
4
+ export type AwaitOptions<T> = {
5
+ promise: DeferredPromise<T>
6
+ }
7
+
8
+ export function useAwaited<T>({ promise }: AwaitOptions<T>): [T] {
9
+ const router = useRouter()
10
+
11
+ let state = promise.__deferredState
12
+ const key = `__TSR__DEFERRED__${state.uid}`
13
+
14
+ if (isDehydratedDeferred(promise)) {
15
+ state = router.hydrateData(key)!
16
+ promise = Promise.resolve(state.data) as DeferredPromise<any>
17
+ promise.__deferredState = state
18
+ }
19
+
20
+ if (state.status === 'pending') {
21
+ throw promise
22
+ }
23
+
24
+ if (state.status === 'error') {
25
+ throw state.error
26
+ }
27
+
28
+ router.dehydrateData(key, state)
29
+
30
+ return [state.data]
31
+ }
32
+
33
+ export function Await<T>(
34
+ props: AwaitOptions<T> & {
35
+ children: (result: T) => JSX.Element
36
+ },
37
+ ) {
38
+ const awaited = useAwaited(props)
39
+ return props.children(...awaited)
40
+ }
package/src/defer.ts ADDED
@@ -0,0 +1,55 @@
1
+ export type DeferredPromiseState<T> = { uid: string } & (
2
+ | {
3
+ status: 'pending'
4
+ data?: T
5
+ error?: unknown
6
+ }
7
+ | {
8
+ status: 'success'
9
+ data: T
10
+ }
11
+ | {
12
+ status: 'error'
13
+ data?: T
14
+ error: unknown
15
+ }
16
+ )
17
+
18
+ export type DeferredPromise<T> = Promise<T> & {
19
+ __deferredState: DeferredPromiseState<T>
20
+ }
21
+
22
+ export function defer<T>(_promise: Promise<T>) {
23
+ const promise = _promise as DeferredPromise<T>
24
+
25
+ if (!promise.__deferredState) {
26
+ promise.__deferredState = {
27
+ uid: Math.random().toString(36).slice(2),
28
+ status: 'pending',
29
+ }
30
+
31
+ const state = promise.__deferredState
32
+
33
+ promise
34
+ .then((data) => {
35
+ state.status = 'success' as any
36
+ state.data = data
37
+ })
38
+ .catch((error) => {
39
+ state.status = 'error' as any
40
+ state.error = error
41
+ })
42
+ }
43
+
44
+ return promise
45
+ }
46
+
47
+ export function isDehydratedDeferred(obj: any): boolean {
48
+ return (
49
+ typeof obj === 'object' &&
50
+ obj !== null &&
51
+ !(obj instanceof Promise) &&
52
+ !obj.then &&
53
+ '__deferredState' in obj
54
+ )
55
+ }
@@ -0,0 +1,153 @@
1
+ import { ParsePathParams } from './link'
2
+ import {
3
+ AnyRoute,
4
+ ResolveFullPath,
5
+ ResolveFullSearchSchema,
6
+ MergeFromFromParent,
7
+ RouteContext,
8
+ AnyContext,
9
+ RouteOptions,
10
+ UpdatableRouteOptions,
11
+ Route,
12
+ AnyPathParams,
13
+ RootRouteId,
14
+ TrimPathLeft,
15
+ RouteConstraints,
16
+ } from './route'
17
+ import { Assign, AssignAll, Expand, IsAny } from './utils'
18
+
19
+ export interface FileRoutesByPath {
20
+ // '/': {
21
+ // parentRoute: typeof rootRoute
22
+ // }
23
+ }
24
+
25
+ type Replace<
26
+ S extends string,
27
+ From extends string,
28
+ To extends string,
29
+ > = S extends `${infer Start}${From}${infer Rest}`
30
+ ? `${Start}${To}${Replace<Rest, From, To>}`
31
+ : S
32
+
33
+ export type TrimLeft<
34
+ T extends string,
35
+ S extends string,
36
+ > = T extends `${S}${infer U}` ? U : T
37
+
38
+ export type TrimRight<
39
+ T extends string,
40
+ S extends string,
41
+ > = T extends `${infer U}${S}` ? U : T
42
+
43
+ export type Trim<T extends string, S extends string> = TrimLeft<
44
+ TrimRight<T, S>,
45
+ S
46
+ >
47
+
48
+ export type RemoveUnderScores<T extends string> = Replace<
49
+ Replace<TrimRight<TrimLeft<T, '/_'>, '_'>, '_/', '/'>,
50
+ '/_',
51
+ '/'
52
+ >
53
+
54
+ export type ResolveFilePath<
55
+ TParentRoute extends AnyRoute,
56
+ TFilePath extends string,
57
+ > = TParentRoute['id'] extends RootRouteId
58
+ ? TrimPathLeft<TFilePath>
59
+ : Replace<
60
+ TrimPathLeft<TFilePath>,
61
+ TrimPathLeft<TParentRoute['types']['customId']>,
62
+ ''
63
+ >
64
+
65
+ export type FileRoutePath<
66
+ TParentRoute extends AnyRoute,
67
+ TFilePath extends string,
68
+ > = ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}`
69
+ ? string
70
+ : ResolveFilePath<TParentRoute, TFilePath>
71
+
72
+ export class FileRoute<
73
+ TFilePath extends keyof FileRoutesByPath,
74
+ TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],
75
+ TId extends RouteConstraints['TId'] = TFilePath,
76
+ TPath extends RouteConstraints['TPath'] = FileRoutePath<
77
+ TParentRoute,
78
+ TFilePath
79
+ >,
80
+ TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
81
+ TParentRoute,
82
+ RemoveUnderScores<TPath>
83
+ >,
84
+ > {
85
+ constructor(public path: TFilePath) {}
86
+
87
+ createRoute = <
88
+ TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
89
+ TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
90
+ TParentRoute,
91
+ TSearchSchema
92
+ >,
93
+ TParams extends RouteConstraints['TParams'] = ParsePathParams<TPath> extends never
94
+ ? AnyPathParams
95
+ : Record<ParsePathParams<TPath>, RouteConstraints['TPath']>,
96
+ TAllParams extends RouteConstraints['TAllParams'] = MergeFromFromParent<
97
+ TParentRoute['types']['allParams'],
98
+ TParams
99
+ >,
100
+ TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,
101
+ TContext extends Expand<
102
+ Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
103
+ > = Expand<
104
+ Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
105
+ >,
106
+ TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
107
+ TLoaderData extends any = unknown,
108
+ TChildren extends RouteConstraints['TChildren'] = unknown,
109
+ TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
110
+ >(
111
+ options: Omit<
112
+ RouteOptions<
113
+ TParentRoute,
114
+ string,
115
+ string,
116
+ TSearchSchema,
117
+ TFullSearchSchema,
118
+ TParams,
119
+ TAllParams,
120
+ TRouteContext,
121
+ TContext,
122
+ TLoaderData
123
+ >,
124
+ 'getParentRoute' | 'path' | 'id'
125
+ > &
126
+ UpdatableRouteOptions<
127
+ TFullSearchSchema,
128
+ TAllParams,
129
+ TContext,
130
+ TLoaderData
131
+ >,
132
+ ): Route<
133
+ TParentRoute,
134
+ TPath,
135
+ TFullPath,
136
+ TFilePath,
137
+ TId,
138
+ TSearchSchema,
139
+ TFullSearchSchema,
140
+ TParams,
141
+ TAllParams,
142
+ TRouteContext,
143
+ TContext,
144
+ TRouterContext,
145
+ TLoaderData,
146
+ TChildren,
147
+ TRouteTree
148
+ > => {
149
+ const route = new Route(options as any)
150
+ ;(route as any).isRoot = false
151
+ return route as any
152
+ }
153
+ }
package/src/history.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { HistoryLocation } from '@tanstack/history'
2
+
3
+ declare module '@tanstack/history' {
4
+ interface HistoryState {
5
+ __tempLocation?: HistoryLocation
6
+ __tempKey?: string
7
+ }
8
+ }