@tanstack/router-core 0.0.1-beta.19 → 0.0.1-beta.191

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