@tanstack/router-core 0.0.1-beta.9 → 1.20.3-alpha.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.
Files changed (194) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/dist/cjs/Matches.cjs +13 -0
  4. package/dist/cjs/Matches.cjs.map +1 -0
  5. package/dist/cjs/Matches.d.cts +109 -0
  6. package/dist/cjs/RouterProvider.d.cts +26 -0
  7. package/dist/cjs/defer.cjs +25 -0
  8. package/dist/cjs/defer.cjs.map +1 -0
  9. package/dist/cjs/defer.d.cts +20 -0
  10. package/dist/cjs/fileRoute.d.cts +23 -0
  11. package/dist/cjs/history.d.cts +8 -0
  12. package/dist/cjs/index.cjs +80 -0
  13. package/dist/cjs/index.cjs.map +1 -0
  14. package/dist/cjs/index.d.cts +41 -0
  15. package/dist/cjs/link.cjs +5 -0
  16. package/dist/cjs/link.cjs.map +1 -0
  17. package/dist/cjs/link.d.cts +200 -0
  18. package/dist/cjs/location.d.cts +12 -0
  19. package/dist/cjs/manifest.d.cts +24 -0
  20. package/dist/cjs/not-found.cjs +13 -0
  21. package/dist/cjs/not-found.cjs.map +1 -0
  22. package/dist/cjs/not-found.d.cts +20 -0
  23. package/dist/cjs/path.cjs +412 -0
  24. package/dist/cjs/path.cjs.map +1 -0
  25. package/dist/cjs/path.d.cts +56 -0
  26. package/dist/cjs/qss.cjs +38 -0
  27. package/dist/cjs/qss.cjs.map +1 -0
  28. package/dist/cjs/qss.d.cts +22 -0
  29. package/dist/cjs/redirect.cjs +34 -0
  30. package/dist/cjs/redirect.cjs.map +1 -0
  31. package/dist/cjs/redirect.d.cts +38 -0
  32. package/dist/cjs/root.cjs +5 -0
  33. package/dist/cjs/root.cjs.map +1 -0
  34. package/dist/cjs/root.d.cts +2 -0
  35. package/dist/cjs/route.cjs +119 -0
  36. package/dist/cjs/route.cjs.map +1 -0
  37. package/dist/cjs/route.d.cts +422 -0
  38. package/dist/cjs/routeInfo.d.cts +54 -0
  39. package/dist/cjs/router.cjs +1800 -0
  40. package/dist/cjs/router.cjs.map +1 -0
  41. package/dist/cjs/router.d.cts +630 -0
  42. package/dist/cjs/scroll-restoration.cjs +196 -0
  43. package/dist/cjs/scroll-restoration.cjs.map +1 -0
  44. package/dist/cjs/scroll-restoration.d.cts +38 -0
  45. package/dist/cjs/searchMiddleware.cjs +42 -0
  46. package/dist/cjs/searchMiddleware.cjs.map +1 -0
  47. package/dist/cjs/searchMiddleware.d.cts +5 -0
  48. package/dist/cjs/searchParams.cjs +61 -0
  49. package/dist/cjs/searchParams.cjs.map +1 -0
  50. package/dist/cjs/searchParams.d.cts +7 -0
  51. package/dist/cjs/serializer.d.cts +22 -0
  52. package/dist/cjs/structuralSharing.d.cts +4 -0
  53. package/dist/cjs/typePrimitives.d.cts +65 -0
  54. package/dist/cjs/useLoaderData.d.cts +5 -0
  55. package/dist/cjs/useLoaderDeps.d.cts +5 -0
  56. package/dist/cjs/useNavigate.d.cts +3 -0
  57. package/dist/cjs/useParams.d.cts +5 -0
  58. package/dist/cjs/useRouteContext.d.cts +9 -0
  59. package/dist/cjs/useSearch.d.cts +5 -0
  60. package/dist/cjs/utils.cjs +160 -0
  61. package/dist/cjs/utils.cjs.map +1 -0
  62. package/dist/cjs/utils.d.cts +105 -0
  63. package/dist/cjs/validators.d.cts +51 -0
  64. package/dist/esm/Matches.d.ts +109 -0
  65. package/dist/esm/Matches.js +13 -0
  66. package/dist/esm/Matches.js.map +1 -0
  67. package/dist/esm/RouterProvider.d.ts +26 -0
  68. package/dist/esm/defer.d.ts +20 -0
  69. package/dist/esm/defer.js +25 -0
  70. package/dist/esm/defer.js.map +1 -0
  71. package/dist/esm/fileRoute.d.ts +23 -0
  72. package/dist/esm/history.d.ts +8 -0
  73. package/dist/esm/index.d.ts +41 -0
  74. package/dist/esm/index.js +80 -0
  75. package/dist/esm/index.js.map +1 -0
  76. package/dist/esm/link.d.ts +200 -0
  77. package/dist/esm/link.js +5 -0
  78. package/dist/esm/link.js.map +1 -0
  79. package/dist/esm/location.d.ts +12 -0
  80. package/dist/esm/manifest.d.ts +24 -0
  81. package/dist/esm/not-found.d.ts +20 -0
  82. package/dist/esm/not-found.js +13 -0
  83. package/dist/esm/not-found.js.map +1 -0
  84. package/dist/esm/path.d.ts +56 -0
  85. package/dist/esm/path.js +412 -0
  86. package/dist/esm/path.js.map +1 -0
  87. package/dist/esm/qss.d.ts +22 -0
  88. package/dist/esm/qss.js +38 -0
  89. package/dist/esm/qss.js.map +1 -0
  90. package/dist/esm/redirect.d.ts +38 -0
  91. package/dist/esm/redirect.js +34 -0
  92. package/dist/esm/redirect.js.map +1 -0
  93. package/dist/esm/root.d.ts +2 -0
  94. package/dist/esm/root.js +5 -0
  95. package/dist/esm/root.js.map +1 -0
  96. package/dist/esm/route.d.ts +422 -0
  97. package/dist/esm/route.js +119 -0
  98. package/dist/esm/route.js.map +1 -0
  99. package/dist/esm/routeInfo.d.ts +54 -0
  100. package/dist/esm/router.d.ts +630 -0
  101. package/dist/esm/router.js +1800 -0
  102. package/dist/esm/router.js.map +1 -0
  103. package/dist/esm/scroll-restoration.d.ts +38 -0
  104. package/dist/esm/scroll-restoration.js +196 -0
  105. package/dist/esm/scroll-restoration.js.map +1 -0
  106. package/dist/esm/searchMiddleware.d.ts +5 -0
  107. package/dist/esm/searchMiddleware.js +42 -0
  108. package/dist/esm/searchMiddleware.js.map +1 -0
  109. package/dist/esm/searchParams.d.ts +7 -0
  110. package/dist/esm/searchParams.js +61 -0
  111. package/dist/esm/searchParams.js.map +1 -0
  112. package/dist/esm/serializer.d.ts +22 -0
  113. package/dist/esm/structuralSharing.d.ts +4 -0
  114. package/dist/esm/typePrimitives.d.ts +65 -0
  115. package/dist/esm/useLoaderData.d.ts +5 -0
  116. package/dist/esm/useLoaderDeps.d.ts +5 -0
  117. package/dist/esm/useNavigate.d.ts +3 -0
  118. package/dist/esm/useParams.d.ts +5 -0
  119. package/dist/esm/useRouteContext.d.ts +9 -0
  120. package/dist/esm/useSearch.d.ts +5 -0
  121. package/dist/esm/utils.d.ts +105 -0
  122. package/dist/esm/utils.js +160 -0
  123. package/dist/esm/utils.js.map +1 -0
  124. package/dist/esm/validators.d.ts +51 -0
  125. package/package.json +36 -32
  126. package/src/Matches.ts +239 -0
  127. package/src/RouterProvider.ts +50 -0
  128. package/src/defer.ts +52 -0
  129. package/src/fileRoute.ts +140 -0
  130. package/src/history.ts +9 -0
  131. package/src/index.ts +421 -19
  132. package/src/link.ts +580 -286
  133. package/src/location.ts +13 -0
  134. package/src/manifest.ts +32 -0
  135. package/src/not-found.ts +29 -0
  136. package/src/path.ts +425 -49
  137. package/src/qss.ts +70 -41
  138. package/src/redirect.ts +100 -0
  139. package/src/root.ts +2 -0
  140. package/src/route.ts +1682 -218
  141. package/src/routeInfo.ts +224 -217
  142. package/src/router.ts +3100 -1073
  143. package/src/scroll-restoration.ts +340 -0
  144. package/src/searchMiddleware.ts +54 -0
  145. package/src/searchParams.ts +43 -20
  146. package/src/serializer.ts +32 -0
  147. package/src/structuralSharing.ts +7 -0
  148. package/src/typePrimitives.ts +181 -0
  149. package/src/useLoaderData.ts +20 -0
  150. package/src/useLoaderDeps.ts +13 -0
  151. package/src/useNavigate.ts +13 -0
  152. package/src/useParams.ts +20 -0
  153. package/src/useRouteContext.ts +39 -0
  154. package/src/useSearch.ts +20 -0
  155. package/src/utils.ts +369 -75
  156. package/src/validators.ts +121 -0
  157. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
  158. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  159. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
  160. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
  161. package/build/cjs/node_modules/history/index.js +0 -815
  162. package/build/cjs/node_modules/history/index.js.map +0 -1
  163. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
  164. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
  165. package/build/cjs/packages/router-core/src/index.js +0 -58
  166. package/build/cjs/packages/router-core/src/index.js.map +0 -1
  167. package/build/cjs/packages/router-core/src/path.js +0 -222
  168. package/build/cjs/packages/router-core/src/path.js.map +0 -1
  169. package/build/cjs/packages/router-core/src/qss.js +0 -71
  170. package/build/cjs/packages/router-core/src/qss.js.map +0 -1
  171. package/build/cjs/packages/router-core/src/route.js +0 -150
  172. package/build/cjs/packages/router-core/src/route.js.map +0 -1
  173. package/build/cjs/packages/router-core/src/routeConfig.js +0 -69
  174. package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
  175. package/build/cjs/packages/router-core/src/routeMatch.js +0 -266
  176. package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
  177. package/build/cjs/packages/router-core/src/router.js +0 -822
  178. package/build/cjs/packages/router-core/src/router.js.map +0 -1
  179. package/build/cjs/packages/router-core/src/searchParams.js +0 -70
  180. package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
  181. package/build/cjs/packages/router-core/src/utils.js +0 -125
  182. package/build/cjs/packages/router-core/src/utils.js.map +0 -1
  183. package/build/esm/index.js +0 -2481
  184. package/build/esm/index.js.map +0 -1
  185. package/build/stats-html.html +0 -4034
  186. package/build/stats-react.json +0 -493
  187. package/build/types/index.d.ts +0 -618
  188. package/build/umd/index.development.js +0 -2514
  189. package/build/umd/index.development.js.map +0 -1
  190. package/build/umd/index.production.js +0 -12
  191. package/build/umd/index.production.js.map +0 -1
  192. package/src/frameworks.ts +0 -12
  193. package/src/routeConfig.ts +0 -495
  194. package/src/routeMatch.ts +0 -374
@@ -1,495 +0,0 @@
1
- import { GetFrameworkGeneric } from './frameworks'
2
- import { ParsePathParams } from './link'
3
- import { joinPaths, trimPath, trimPathRight } from './path'
4
- import { RouteInfo } from './routeInfo'
5
- import { RouteMatch } from './routeMatch'
6
- import {
7
- DeepAwaited,
8
- Expand,
9
- IsAny,
10
- NoInfer,
11
- PickUnsafe,
12
- Values,
13
- } from './utils'
14
-
15
- export const rootRouteId = '__root__' as const
16
- export type RootRouteId = typeof rootRouteId
17
-
18
- export type AnyLoaderData = {}
19
- export type AnyPathParams = {}
20
- export type AnySearchSchema = {}
21
- export interface RouteMeta {}
22
-
23
- // The parse type here allows a zod schema to be passed directly to the validator
24
- export type SearchSchemaValidator<TReturn, TParentSchema> =
25
- | SearchSchemaValidatorObj<TReturn, TParentSchema>
26
- | SearchSchemaValidatorFn<TReturn, TParentSchema>
27
-
28
- export type SearchSchemaValidatorObj<TReturn, TParentSchema> = {
29
- parse?: SearchSchemaValidatorFn<TReturn, TParentSchema>
30
- }
31
-
32
- export type SearchSchemaValidatorFn<TReturn, TParentSchema> = (
33
- searchObj: Record<string, unknown>,
34
- ) => {} extends TParentSchema
35
- ? TReturn
36
- : keyof TReturn extends keyof TParentSchema
37
- ? {
38
- error: 'Top level search params cannot be redefined by child routes!'
39
- keys: keyof TReturn & keyof TParentSchema
40
- }
41
- : TReturn
42
-
43
- export type DefinedPathParamWarning =
44
- 'Path params cannot be redefined by child routes!'
45
-
46
- export type ParentParams<TParentParams> = AnyPathParams extends TParentParams
47
- ? {}
48
- : {
49
- [Key in keyof TParentParams]?: DefinedPathParamWarning
50
- }
51
-
52
- export type LoaderFn<
53
- TRouteLoaderData extends AnyLoaderData,
54
- TFullSearchSchema extends AnySearchSchema = {},
55
- TAllParams extends AnyPathParams = {},
56
- > = (
57
- loaderContext: LoaderContext<TFullSearchSchema, TAllParams>,
58
- ) => Promise<TRouteLoaderData>
59
-
60
- export interface LoaderContext<
61
- TFullSearchSchema extends AnySearchSchema = {},
62
- TAllParams extends AnyPathParams = {},
63
- > {
64
- params: TAllParams
65
- search: TFullSearchSchema
66
- signal?: AbortSignal
67
- }
68
-
69
- export type ActionFn<TActionPayload = unknown, TActionResponse = unknown> = (
70
- submission: TActionPayload,
71
- ) => TActionResponse | Promise<TActionResponse>
72
-
73
- export type UnloaderFn<TPath extends string> = (
74
- routeMatch: RouteMatch<any, RouteInfo<string, TPath>>,
75
- ) => void
76
-
77
- export type RouteOptions<
78
- TRouteId extends string = string,
79
- TPath extends string = string,
80
- TRouteLoaderData extends AnyLoaderData = {},
81
- TLoaderData extends AnyLoaderData = {},
82
- TActionPayload = unknown,
83
- TActionResponse = unknown,
84
- TParentSearchSchema extends {} = {},
85
- TSearchSchema extends AnySearchSchema = {},
86
- TFullSearchSchema extends AnySearchSchema = TSearchSchema,
87
- TParentParams extends AnyPathParams = {},
88
- TParams extends Record<ParsePathParams<TPath>, unknown> = Record<
89
- ParsePathParams<TPath>,
90
- string
91
- >,
92
- TAllParams extends AnyPathParams = {},
93
- > = (
94
- | {
95
- // The path to match (relative to the nearest parent `Route` component or root basepath)
96
- path: TPath
97
- }
98
- | {
99
- id: TRouteId
100
- }
101
- ) & {
102
- // If true, this route will be matched as case-sensitive
103
- caseSensitive?: boolean
104
- validateSearch?: SearchSchemaValidator<TSearchSchema, TParentSearchSchema>
105
- // Filter functions that can manipulate search params *before* they are passed to links and navigate
106
- // calls that match this route.
107
- preSearchFilters?: SearchFilter<TFullSearchSchema>[]
108
- // Filter functions that can manipulate search params *after* they are passed to links and navigate
109
- // calls that match this route.
110
- postSearchFilters?: SearchFilter<TFullSearchSchema>[]
111
- // The duration to wait during `loader` execution before showing the `pendingElement`
112
- pendingMs?: number
113
- // _If the `pendingElement` is shown_, the minimum duration for which it will be visible.
114
- pendingMinMs?: number
115
- // The content to be rendered when the route is matched. If no element is provided, defaults to `<Outlet />`
116
- element?: GetFrameworkGeneric<'SyncOrAsyncElement'> // , NoInfer<TLoaderData>>
117
- // The content to be rendered when `loader` encounters an error
118
- errorElement?: GetFrameworkGeneric<'SyncOrAsyncElement'> // , NoInfer<TLoaderData>>
119
- // The content to be rendered when rendering encounters an error
120
- catchElement?: GetFrameworkGeneric<'SyncOrAsyncElement'> // , NoInfer<TLoaderData>>
121
- // The content to be rendered when the duration of `loader` execution surpasses the `pendingMs` duration
122
- pendingElement?: GetFrameworkGeneric<'SyncOrAsyncElement'> //, NoInfer<TLoaderData>>
123
- // An asynchronous function responsible for preparing or fetching data for the route before it is rendered
124
- loader?: LoaderFn<TRouteLoaderData, TFullSearchSchema, TAllParams>
125
- // The max age to consider loader data fresh (not-stale) for this route in milliseconds from the time of fetch
126
- // Defaults to 0. Only stale loader data is refetched.
127
- loaderMaxAge?: number
128
- // The max age to cache the loader data for this route in milliseconds from the time of route inactivity
129
- // before it is garbage collected.
130
- loaderGcMaxAge?: number
131
- // An asynchronous function made available to the route for performing asynchronous or mutative actions that
132
- // might invalidate the route's data.
133
- action?: ActionFn<TActionPayload, TActionResponse>
134
- // Set this to true to rethrow errors up the component tree to either the nearest error boundary or
135
- // route with error element, whichever comes first.
136
- useErrorBoundary?: boolean
137
- // This function is called
138
- // when moving from an inactive state to an active one. Likewise, when moving from
139
- // an active to an inactive state, the return function (if provided) is called.
140
- onMatch?: (matchContext: {
141
- params: TAllParams
142
- search: TFullSearchSchema
143
- }) =>
144
- | void
145
- | undefined
146
- | ((match: { params: TAllParams; search: TFullSearchSchema }) => void)
147
- // This function is called when the route remains active from one transition to the next.
148
- onTransition?: (match: {
149
- params: TAllParams
150
- search: TFullSearchSchema
151
- }) => void
152
- // An object of whatever you want! This object is accessible anywhere matches are.
153
- meta?: RouteMeta // TODO: Make this nested and mergeable
154
- } & (
155
- | {
156
- parseParams?: never
157
- stringifyParams?: never
158
- }
159
- | {
160
- // Parse params optionally receives path params as strings and returns them in a parsed format (like a number or boolean)
161
- parseParams: (
162
- rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,
163
- ) => TParams
164
- stringifyParams: (
165
- params: TParams,
166
- ) => Record<ParsePathParams<TPath>, string>
167
- }
168
- ) &
169
- (PickUnsafe<TParentParams, ParsePathParams<TPath>> extends never // Detect if an existing path param is being redefined
170
- ? {}
171
- : 'Cannot redefined path params in child routes!')
172
-
173
- export type SearchFilter<T, U = T> = (prev: T) => U
174
-
175
- export interface RouteConfig<
176
- TId extends string = string,
177
- TRouteId extends string = string,
178
- TPath extends string = string,
179
- TFullPath extends string = string,
180
- TRouteLoaderData extends AnyLoaderData = AnyLoaderData,
181
- TLoaderData extends AnyLoaderData = AnyLoaderData,
182
- TActionPayload = unknown,
183
- TActionResponse = unknown,
184
- TParentSearchSchema extends {} = {},
185
- TSearchSchema extends AnySearchSchema = {},
186
- TFullSearchSchema extends AnySearchSchema = {},
187
- TParentParams extends AnyPathParams = {},
188
- TParams extends Record<ParsePathParams<TPath>, unknown> = Record<
189
- ParsePathParams<TPath>,
190
- string
191
- >,
192
- TAllParams extends AnyPathParams = {},
193
- TKnownChildren = unknown,
194
- > {
195
- id: TId
196
- routeId: TRouteId
197
- path: NoInfer<TPath>
198
- fullPath: TFullPath
199
- options: RouteOptions<
200
- TRouteId,
201
- TPath,
202
- TRouteLoaderData,
203
- TLoaderData,
204
- TActionPayload,
205
- TActionResponse,
206
- TParentSearchSchema,
207
- TSearchSchema,
208
- TFullSearchSchema,
209
- TParentParams,
210
- TParams,
211
- TAllParams
212
- >
213
- children?: TKnownChildren
214
- addChildren: IsAny<
215
- TId,
216
- any,
217
- <TNewChildren extends any>(
218
- children: TNewChildren extends AnyRouteConfig[]
219
- ? TNewChildren
220
- : { error: 'Invalid route detected'; route: TNewChildren },
221
- ) => RouteConfig<
222
- TId,
223
- TRouteId,
224
- TPath,
225
- TFullPath,
226
- TRouteLoaderData,
227
- TLoaderData,
228
- TActionPayload,
229
- TActionResponse,
230
- TParentSearchSchema,
231
- TSearchSchema,
232
- TFullSearchSchema,
233
- TParentParams,
234
- TParams,
235
- TAllParams,
236
- TNewChildren
237
- >
238
- >
239
- createChildren: IsAny<
240
- TId,
241
- any,
242
- <TNewChildren extends any>(
243
- cb: (
244
- createChildRoute: CreateRouteConfigFn<
245
- false,
246
- TId,
247
- TFullPath,
248
- TLoaderData,
249
- TFullSearchSchema,
250
- TAllParams
251
- >,
252
- ) => TNewChildren extends AnyRouteConfig[]
253
- ? TNewChildren
254
- : { error: 'Invalid route detected'; route: TNewChildren },
255
- ) => RouteConfig<
256
- TId,
257
- TRouteId,
258
- TPath,
259
- TFullPath,
260
- TRouteLoaderData,
261
- TLoaderData,
262
- TActionPayload,
263
- TActionResponse,
264
- TParentSearchSchema,
265
- TSearchSchema,
266
- TFullSearchSchema,
267
- TParentParams,
268
- TParams,
269
- TAllParams,
270
- TNewChildren
271
- >
272
- >
273
- createRoute: CreateRouteConfigFn<
274
- false,
275
- TId,
276
- TFullPath,
277
- TLoaderData,
278
- TFullSearchSchema,
279
- TAllParams
280
- >
281
- }
282
-
283
- type CreateRouteConfigFn<
284
- TIsRoot extends boolean = false,
285
- TParentId extends string = string,
286
- TParentPath extends string = string,
287
- TParentAllLoaderData extends AnyLoaderData = {},
288
- TParentSearchSchema extends AnySearchSchema = {},
289
- TParentParams extends AnyPathParams = {},
290
- > = <
291
- TRouteId extends string,
292
- TPath extends string,
293
- TRouteLoaderData extends AnyLoaderData,
294
- TActionPayload,
295
- TActionResponse,
296
- TSearchSchema extends AnySearchSchema = AnySearchSchema,
297
- TParams extends Record<ParsePathParams<TPath>, unknown> = Record<
298
- ParsePathParams<TPath>,
299
- string
300
- >,
301
- TAllParams extends AnyPathParams extends TParams
302
- ? Record<ParsePathParams<TPath>, string>
303
- : NoInfer<TParams> = AnyPathParams extends TParams
304
- ? Record<ParsePathParams<TPath>, string>
305
- : NoInfer<TParams>,
306
- TKnownChildren extends RouteConfig[] = RouteConfig[],
307
- TResolvedId extends string = string extends TRouteId
308
- ? string extends TPath
309
- ? string
310
- : TPath
311
- : TRouteId,
312
- >(
313
- options?: TIsRoot extends true
314
- ? Omit<
315
- RouteOptions<
316
- TRouteId,
317
- TPath,
318
- TRouteLoaderData,
319
- Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
320
- TActionPayload,
321
- TActionResponse,
322
- TParentSearchSchema,
323
- TSearchSchema,
324
- Expand<TParentSearchSchema & TSearchSchema>,
325
- TParentParams,
326
- TParams,
327
- Expand<TParentParams & TAllParams>
328
- >,
329
- 'path'
330
- > & { path?: never }
331
- : RouteOptions<
332
- TRouteId,
333
- TPath,
334
- TRouteLoaderData,
335
- Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
336
- TActionPayload,
337
- TActionResponse,
338
- TParentSearchSchema,
339
- TSearchSchema,
340
- Expand<TParentSearchSchema & TSearchSchema>,
341
- TParentParams,
342
- TParams,
343
- Expand<TParentParams & TAllParams>
344
- >,
345
- children?: TKnownChildren,
346
- isRoot?: boolean,
347
- parentId?: string,
348
- parentPath?: string,
349
- ) => RouteConfig<
350
- RoutePrefix<TParentId, TResolvedId>,
351
- TResolvedId,
352
- TPath,
353
- string extends TPath ? '' : RoutePath<RoutePrefix<TParentPath, TPath>>,
354
- TRouteLoaderData,
355
- Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
356
- TActionPayload,
357
- TActionResponse,
358
- TParentSearchSchema,
359
- TSearchSchema,
360
- Expand<TParentSearchSchema & TSearchSchema>,
361
- TParentParams,
362
- TParams,
363
- Expand<TParentParams & TAllParams>,
364
- TKnownChildren
365
- >
366
-
367
- type RoutePath<T extends string> = T extends RootRouteId
368
- ? '/'
369
- : TrimPathRight<`${T}`>
370
-
371
- type RoutePrefix<
372
- TPrefix extends string,
373
- TId extends string,
374
- > = string extends TId
375
- ? RootRouteId
376
- : TId extends string
377
- ? `${TPrefix}/${TId}` extends '/'
378
- ? '/'
379
- : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TId>}`>}`
380
- : never
381
-
382
- export interface AnyRouteConfig
383
- extends RouteConfig<
384
- any,
385
- any,
386
- any,
387
- any,
388
- any,
389
- any,
390
- any,
391
- any,
392
- any,
393
- any,
394
- any,
395
- any,
396
- any,
397
- any,
398
- any
399
- > {}
400
-
401
- export interface AnyRouteConfigWithChildren<TChildren>
402
- extends RouteConfig<
403
- any,
404
- any,
405
- any,
406
- any,
407
- any,
408
- any,
409
- any,
410
- any,
411
- any,
412
- any,
413
- any,
414
- any,
415
- any,
416
- any,
417
- TChildren
418
- > {}
419
-
420
- type TrimPath<T extends string> = '' extends T
421
- ? ''
422
- : TrimPathRight<TrimPathLeft<T>>
423
-
424
- type TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}`
425
- ? TrimPathLeft<U>
426
- : T extends `/${infer U}`
427
- ? TrimPathLeft<U>
428
- : T
429
- type TrimPathRight<T extends string> = T extends '/'
430
- ? '/'
431
- : T extends `${infer U}/`
432
- ? TrimPathRight<U>
433
- : T
434
-
435
- export const createRouteConfig: CreateRouteConfigFn<true> = (
436
- options = {} as any,
437
- children,
438
- isRoot = true,
439
- parentId,
440
- parentPath,
441
- ) => {
442
- if (isRoot) {
443
- ;(options as any).path = rootRouteId
444
- }
445
-
446
- // Strip the root from parentIds
447
- if (parentId === rootRouteId) {
448
- parentId = ''
449
- }
450
-
451
- let path: undefined | string = isRoot ? rootRouteId : options.path
452
-
453
- // If the path is anything other than an index path, trim it up
454
- if (path && path !== '/') {
455
- path = trimPath(path)
456
- }
457
-
458
- const routeId = path || (options as { id?: string }).id
459
-
460
- let id = joinPaths([parentId, routeId])
461
-
462
- if (path === rootRouteId) {
463
- path = '/'
464
- }
465
-
466
- if (id !== rootRouteId) {
467
- id = joinPaths(['/', id])
468
- }
469
-
470
- const fullPath =
471
- id === rootRouteId ? '/' : trimPathRight(joinPaths([parentPath, path]))
472
-
473
- return {
474
- id: id as any,
475
- routeId: routeId as any,
476
- path: path as any,
477
- fullPath: fullPath as any,
478
- options: options as any,
479
- children,
480
- createChildren: (cb: any) =>
481
- createRouteConfig(
482
- options,
483
- cb((childOptions: any) =>
484
- createRouteConfig(childOptions, undefined, false, id, fullPath),
485
- ),
486
- false,
487
- parentId,
488
- parentPath,
489
- ),
490
- addChildren: (children: any) =>
491
- createRouteConfig(options, children, false, parentId, parentPath),
492
- createRoute: (childOptions: any) =>
493
- createRouteConfig(childOptions, undefined, false, id, fullPath) as any,
494
- }
495
- }