@tanstack/router-core 0.0.1-beta.16 → 0.0.1-beta.160

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 +101 -0
  13. package/build/cjs/route.js.map +1 -0
  14. package/build/cjs/router.js +1128 -0
  15. package/build/cjs/router.js.map +1 -0
  16. package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +34 -19
  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 +1431 -2089
  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 +573 -431
  25. package/build/umd/index.development.js +1667 -2221
  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 +162 -0
  31. package/src/history.ts +292 -0
  32. package/src/index.ts +3 -10
  33. package/src/link.ts +121 -118
  34. package/src/path.ts +37 -17
  35. package/src/qss.ts +1 -2
  36. package/src/route.ts +874 -218
  37. package/src/routeInfo.ts +47 -211
  38. package/src/router.ts +1503 -1023
  39. package/src/searchParams.ts +33 -9
  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 -231
  57. package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
  58. package/build/cjs/packages/router-core/src/router.js +0 -833
  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 -514
  64. package/src/routeMatch.ts +0 -319
@@ -1,514 +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
- // Set this to true to rethrow errors up the component tree to either the nearest error boundary or
142
- // route with error component, whichever comes first.
143
- useErrorBoundary?: boolean
144
- // This function is called
145
- // when moving from an inactive state to an active one. Likewise, when moving from
146
- // an active to an inactive state, the return function (if provided) is called.
147
- onMatch?: (matchContext: {
148
- params: TAllParams
149
- search: TFullSearchSchema
150
- }) =>
151
- | void
152
- | undefined
153
- | ((match: { params: TAllParams; search: TFullSearchSchema }) => void)
154
- // This function is called when the route remains active from one transition to the next.
155
- onTransition?: (match: {
156
- params: TAllParams
157
- search: TFullSearchSchema
158
- }) => void
159
- // An object of whatever you want! This object is accessible anywhere matches are.
160
- meta?: RouteMeta // TODO: Make this nested and mergeable
161
- } & (
162
- | {
163
- parseParams?: never
164
- stringifyParams?: never
165
- }
166
- | {
167
- // Parse params optionally receives path params as strings and returns them in a parsed format (like a number or boolean)
168
- parseParams: (
169
- rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,
170
- ) => TParams
171
- stringifyParams: (
172
- params: TParams,
173
- ) => Record<ParsePathParams<TPath>, string>
174
- }
175
- ) &
176
- (PickUnsafe<TParentParams, ParsePathParams<TPath>> extends never // Detect if an existing path param is being redefined
177
- ? {}
178
- : 'Cannot redefined path params in child routes!')
179
-
180
- export type SearchFilter<T, U = T> = (prev: T) => U
181
-
182
- export interface RouteConfig<
183
- TId extends string = string,
184
- TRouteId extends string = string,
185
- TPath extends string = string,
186
- TFullPath extends string = string,
187
- TParentRouteLoaderData extends AnyLoaderData = AnyLoaderData,
188
- TRouteLoaderData extends AnyLoaderData = AnyLoaderData,
189
- TLoaderData extends AnyLoaderData = AnyLoaderData,
190
- TActionPayload = unknown,
191
- TActionResponse = unknown,
192
- TParentSearchSchema extends {} = {},
193
- TSearchSchema extends AnySearchSchema = {},
194
- TFullSearchSchema extends AnySearchSchema = {},
195
- TParentParams extends AnyPathParams = {},
196
- TParams extends Record<ParsePathParams<TPath>, unknown> = Record<
197
- ParsePathParams<TPath>,
198
- string
199
- >,
200
- TAllParams extends AnyPathParams = {},
201
- TKnownChildren = unknown,
202
- > {
203
- id: TId
204
- routeId: TRouteId
205
- path: NoInfer<TPath>
206
- fullPath: TFullPath
207
- options: RouteOptions<
208
- TRouteId,
209
- TPath,
210
- TParentRouteLoaderData,
211
- TRouteLoaderData,
212
- TLoaderData,
213
- TActionPayload,
214
- TActionResponse,
215
- TParentSearchSchema,
216
- TSearchSchema,
217
- TFullSearchSchema,
218
- TParentParams,
219
- TParams,
220
- TAllParams
221
- >
222
- children?: TKnownChildren
223
- addChildren: IsAny<
224
- TId,
225
- any,
226
- <TNewChildren extends any>(
227
- children: TNewChildren extends AnyRouteConfig[]
228
- ? TNewChildren
229
- : { error: 'Invalid route detected'; route: TNewChildren },
230
- ) => RouteConfig<
231
- TId,
232
- TRouteId,
233
- TPath,
234
- TFullPath,
235
- TParentRouteLoaderData,
236
- TRouteLoaderData,
237
- TLoaderData,
238
- TActionPayload,
239
- TActionResponse,
240
- TParentSearchSchema,
241
- TSearchSchema,
242
- TFullSearchSchema,
243
- TParentParams,
244
- TParams,
245
- TAllParams,
246
- TNewChildren
247
- >
248
- >
249
- createChildren: IsAny<
250
- TId,
251
- any,
252
- <TNewChildren extends any>(
253
- cb: (
254
- createChildRoute: CreateRouteConfigFn<
255
- false,
256
- TId,
257
- TFullPath,
258
- TRouteLoaderData,
259
- TLoaderData,
260
- TFullSearchSchema,
261
- TAllParams
262
- >,
263
- ) => TNewChildren extends AnyRouteConfig[]
264
- ? TNewChildren
265
- : { error: 'Invalid route detected'; route: TNewChildren },
266
- ) => RouteConfig<
267
- TId,
268
- TRouteId,
269
- TPath,
270
- TFullPath,
271
- TParentRouteLoaderData,
272
- TRouteLoaderData,
273
- TLoaderData,
274
- TActionPayload,
275
- TActionResponse,
276
- TParentSearchSchema,
277
- TSearchSchema,
278
- TFullSearchSchema,
279
- TParentParams,
280
- TParams,
281
- TAllParams,
282
- TNewChildren
283
- >
284
- >
285
- createRoute: CreateRouteConfigFn<
286
- false,
287
- TId,
288
- TFullPath,
289
- TRouteLoaderData,
290
- TLoaderData,
291
- TFullSearchSchema,
292
- TAllParams
293
- >
294
- }
295
-
296
- type CreateRouteConfigFn<
297
- TIsRoot extends boolean = false,
298
- TParentId extends string = string,
299
- TParentPath extends string = string,
300
- TParentRouteLoaderData extends AnyLoaderData = {},
301
- TParentLoaderData extends AnyLoaderData = {},
302
- TParentSearchSchema extends AnySearchSchema = {},
303
- TParentParams extends AnyPathParams = {},
304
- > = <
305
- TRouteId extends string,
306
- TPath extends string,
307
- TRouteLoaderData extends AnyLoaderData,
308
- TActionPayload,
309
- TActionResponse,
310
- TSearchSchema extends AnySearchSchema = AnySearchSchema,
311
- TParams extends Record<ParsePathParams<TPath>, unknown> = Record<
312
- ParsePathParams<TPath>,
313
- string
314
- >,
315
- TAllParams extends AnyPathParams extends TParams
316
- ? Record<ParsePathParams<TPath>, string>
317
- : NoInfer<TParams> = AnyPathParams extends TParams
318
- ? Record<ParsePathParams<TPath>, string>
319
- : NoInfer<TParams>,
320
- TKnownChildren extends RouteConfig[] = RouteConfig[],
321
- TResolvedId extends string = string extends TRouteId
322
- ? string extends TPath
323
- ? string
324
- : TPath
325
- : TRouteId,
326
- >(
327
- options?: TIsRoot extends true
328
- ? Omit<
329
- RouteOptions<
330
- TRouteId,
331
- TPath,
332
- TParentRouteLoaderData,
333
- TRouteLoaderData,
334
- Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
335
- TActionPayload,
336
- TActionResponse,
337
- TParentSearchSchema,
338
- TSearchSchema,
339
- Expand<TParentSearchSchema & TSearchSchema>,
340
- TParentParams,
341
- TParams,
342
- Expand<TParentParams & TAllParams>
343
- >,
344
- 'path'
345
- > & { path?: never }
346
- : RouteOptions<
347
- TRouteId,
348
- TPath,
349
- TParentRouteLoaderData,
350
- TRouteLoaderData,
351
- Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
352
- TActionPayload,
353
- TActionResponse,
354
- TParentSearchSchema,
355
- TSearchSchema,
356
- Expand<TParentSearchSchema & TSearchSchema>,
357
- TParentParams,
358
- TParams,
359
- Expand<TParentParams & TAllParams>
360
- >,
361
- children?: TKnownChildren,
362
- isRoot?: boolean,
363
- parentId?: string,
364
- parentPath?: string,
365
- ) => RouteConfig<
366
- RoutePrefix<TParentId, TResolvedId>,
367
- TResolvedId,
368
- TPath,
369
- string extends TPath ? '' : RoutePath<RoutePrefix<TParentPath, TPath>>,
370
- TParentRouteLoaderData,
371
- TRouteLoaderData,
372
- Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
373
- TActionPayload,
374
- TActionResponse,
375
- TParentSearchSchema,
376
- TSearchSchema,
377
- Expand<TParentSearchSchema & TSearchSchema>,
378
- TParentParams,
379
- TParams,
380
- Expand<TParentParams & TAllParams>,
381
- TKnownChildren
382
- >
383
-
384
- type RoutePath<T extends string> = T extends RootRouteId
385
- ? '/'
386
- : TrimPathRight<`${T}`>
387
-
388
- type RoutePrefix<
389
- TPrefix extends string,
390
- TId extends string,
391
- > = string extends TId
392
- ? RootRouteId
393
- : TId extends string
394
- ? `${TPrefix}/${TId}` extends '/'
395
- ? '/'
396
- : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TId>}`>}`
397
- : never
398
-
399
- export interface AnyRouteConfig
400
- extends RouteConfig<
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
- any,
415
- any,
416
- any
417
- > {}
418
-
419
- export interface AnyRouteConfigWithChildren<TChildren>
420
- extends RouteConfig<
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
- any,
434
- any,
435
- any,
436
- TChildren
437
- > {}
438
-
439
- type TrimPath<T extends string> = '' extends T
440
- ? ''
441
- : TrimPathRight<TrimPathLeft<T>>
442
-
443
- type TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}`
444
- ? TrimPathLeft<U>
445
- : T extends `/${infer U}`
446
- ? TrimPathLeft<U>
447
- : T
448
- type TrimPathRight<T extends string> = T extends '/'
449
- ? '/'
450
- : T extends `${infer U}/`
451
- ? TrimPathRight<U>
452
- : T
453
-
454
- export const createRouteConfig: CreateRouteConfigFn<true> = (
455
- options = {} as any,
456
- children,
457
- isRoot = true,
458
- parentId,
459
- parentPath,
460
- ) => {
461
- if (isRoot) {
462
- ;(options as any).path = rootRouteId
463
- }
464
-
465
- // Strip the root from parentIds
466
- if (parentId === rootRouteId) {
467
- parentId = ''
468
- }
469
-
470
- let path: undefined | string = isRoot ? rootRouteId : options.path
471
-
472
- // If the path is anything other than an index path, trim it up
473
- if (path && path !== '/') {
474
- path = trimPath(path)
475
- }
476
-
477
- const routeId = path || (options as { id?: string }).id
478
-
479
- let id = joinPaths([parentId, routeId])
480
-
481
- if (path === rootRouteId) {
482
- path = '/'
483
- }
484
-
485
- if (id !== rootRouteId) {
486
- id = joinPaths(['/', id])
487
- }
488
-
489
- const fullPath =
490
- id === rootRouteId ? '/' : trimPathRight(joinPaths([parentPath, path]))
491
-
492
- return {
493
- id: id as any,
494
- routeId: routeId as any,
495
- path: path as any,
496
- fullPath: fullPath as any,
497
- options: options as any,
498
- children,
499
- createChildren: (cb: any) =>
500
- createRouteConfig(
501
- options,
502
- cb((childOptions: any) =>
503
- createRouteConfig(childOptions, undefined, false, id, fullPath),
504
- ),
505
- false,
506
- parentId,
507
- parentPath,
508
- ),
509
- addChildren: (children: any) =>
510
- createRouteConfig(options, children, false, parentId, parentPath),
511
- createRoute: (childOptions: any) =>
512
- createRouteConfig(childOptions, undefined, false, id, fullPath) as any,
513
- }
514
- }