@tanstack/router-core 0.0.1-beta.14 → 0.0.1-beta.146

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