@tanstack/router-core 0.0.1-beta.2 → 0.0.1-beta.23

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 (35) hide show
  1. package/build/cjs/packages/router-core/src/index.js +1 -1
  2. package/build/cjs/packages/router-core/src/path.js +1 -4
  3. package/build/cjs/packages/router-core/src/path.js.map +1 -1
  4. package/build/cjs/packages/router-core/src/qss.js +1 -0
  5. package/build/cjs/packages/router-core/src/qss.js.map +1 -1
  6. package/build/cjs/packages/router-core/src/route.js +9 -23
  7. package/build/cjs/packages/router-core/src/route.js.map +1 -1
  8. package/build/cjs/packages/router-core/src/routeConfig.js.map +1 -1
  9. package/build/cjs/packages/router-core/src/routeMatch.js +75 -121
  10. package/build/cjs/packages/router-core/src/routeMatch.js.map +1 -1
  11. package/build/cjs/packages/router-core/src/router.js +183 -89
  12. package/build/cjs/packages/router-core/src/router.js.map +1 -1
  13. package/build/cjs/packages/router-core/src/utils.js +7 -6
  14. package/build/cjs/packages/router-core/src/utils.js.map +1 -1
  15. package/build/esm/index.js +271 -237
  16. package/build/esm/index.js.map +1 -1
  17. package/build/stats-html.html +1 -1
  18. package/build/stats-react.json +139 -152
  19. package/build/types/index.d.ts +199 -191
  20. package/build/umd/index.development.js +271 -237
  21. package/build/umd/index.development.js.map +1 -1
  22. package/build/umd/index.production.js +1 -1
  23. package/build/umd/index.production.js.map +1 -1
  24. package/package.json +2 -1
  25. package/src/frameworks.ts +1 -2
  26. package/src/index.ts +0 -1
  27. package/src/link.ts +3 -1
  28. package/src/path.ts +0 -4
  29. package/src/qss.ts +1 -0
  30. package/src/route.ts +10 -26
  31. package/src/routeConfig.ts +30 -21
  32. package/src/routeInfo.ts +13 -3
  33. package/src/routeMatch.ts +94 -156
  34. package/src/router.ts +269 -109
  35. package/src/utils.ts +12 -5
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/router-core",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.2",
4
+ "version": "0.0.1-beta.23",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -33,6 +33,7 @@
33
33
  "build/**",
34
34
  "src"
35
35
  ],
36
+ "sideEffects": false,
36
37
  "peerDependencies": {
37
38
  "react": ">=16",
38
39
  "react-dom": ">=16"
package/src/frameworks.ts CHANGED
@@ -3,8 +3,7 @@ export interface FrameworkGenerics {
3
3
  // and are extended by framework adapters, but cannot be
4
4
  // pre-defined as constraints:
5
5
  //
6
- // Element: any
7
- // SyncOrAsyncElement?: any
6
+ // Component: any
8
7
  }
9
8
 
10
9
  export type GetFrameworkGeneric<U> = U extends keyof FrameworkGenerics
package/src/index.ts CHANGED
@@ -7,7 +7,6 @@ export {
7
7
  export { default as invariant } from 'tiny-invariant'
8
8
 
9
9
  export * from './frameworks'
10
- export * from './index'
11
10
  export * from './link'
12
11
  export * from './path'
13
12
  export * from './qss'
package/src/link.ts CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  DefaultAllRouteInfo,
5
5
  RouteInfoByPath,
6
6
  } from './routeInfo'
7
- import { Location } from './router'
7
+ import { Location, LocationState } from './router'
8
8
  import { Expand, NoInfer, PickAsRequired, PickRequired, Updater } from './utils'
9
9
 
10
10
  export type LinkInfo =
@@ -126,6 +126,8 @@ export type ToOptions<
126
126
  to?: ToPathOption<TAllRouteInfo, TFrom, TTo>
127
127
  // The new has string or a function to update it
128
128
  hash?: Updater<string>
129
+ // State to pass to the history stack
130
+ state?: LocationState
129
131
  // The source route path. This is automatically set when using route-level APIs, but for type-safe relative routing on the router itself, this is required
130
132
  from?: TFrom
131
133
  // // When using relative route paths, this option forces resolution from the current path, instead of the route API's path or `from` path
package/src/path.ts CHANGED
@@ -155,10 +155,6 @@ export function matchPathname(
155
155
  return
156
156
  }
157
157
 
158
- // if (matchLocation.search && !searchMatched) {
159
- // return
160
- // }
161
-
162
158
  return pathParams ?? {}
163
159
  }
164
160
 
package/src/qss.ts CHANGED
@@ -30,6 +30,7 @@ function toValue(mix) {
30
30
  var str = decodeURIComponent(mix)
31
31
  if (str === 'false') return false
32
32
  if (str === 'true') return true
33
+ if (str.charAt(0) === '0') return str
33
34
  return +str * 0 === 0 ? +str : str
34
35
  }
35
36
 
package/src/route.ts CHANGED
@@ -13,7 +13,6 @@ import {
13
13
  RouteInfo,
14
14
  RouteInfoByPath,
15
15
  } from './routeInfo'
16
- import { RouteMatch } from './routeMatch'
17
16
  import {
18
17
  Action,
19
18
  ActionState,
@@ -22,7 +21,7 @@ import {
22
21
  MatchRouteOptions,
23
22
  Router,
24
23
  } from './router'
25
- import { NoInfer, replaceEqualDeep } from './utils'
24
+ import { NoInfer } from './utils'
26
25
 
27
26
  export interface AnyRoute extends Route<any, any> {}
28
27
 
@@ -96,10 +95,10 @@ export function createRoute<
96
95
  router.state.actions[id] ||
97
96
  (() => {
98
97
  router.state.actions[id] = {
99
- pending: [],
98
+ submissions: [],
100
99
  submit: async <T, U>(
101
100
  submission: T,
102
- actionOpts?: { invalidate?: boolean },
101
+ actionOpts?: { invalidate?: boolean; multi?: boolean },
103
102
  ) => {
104
103
  if (!route) {
105
104
  return
@@ -107,27 +106,27 @@ export function createRoute<
107
106
 
108
107
  const invalidate = actionOpts?.invalidate ?? true
109
108
 
109
+ if (!actionOpts?.multi) {
110
+ action.submissions = action.submissions.filter((d) => d.isMulti)
111
+ }
112
+
110
113
  const actionState: ActionState<T, U> = {
111
114
  submittedAt: Date.now(),
112
115
  status: 'pending',
113
116
  submission,
117
+ isMulti: !!actionOpts?.multi,
114
118
  }
115
119
 
116
120
  action.current = actionState
117
121
  action.latest = actionState
118
- action.pending.push(actionState)
119
-
120
- router.state = {
121
- ...router.state,
122
- currentAction: actionState,
123
- latestAction: actionState,
124
- }
122
+ action.submissions.push(actionState)
125
123
 
126
124
  router.notify()
127
125
 
128
126
  try {
129
127
  const res = await route.options.action?.(submission)
130
128
  actionState.data = res as U
129
+
131
130
  if (invalidate) {
132
131
  router.invalidateRoute({ to: '.', fromCurrent: true })
133
132
  await router.reload()
@@ -139,8 +138,6 @@ export function createRoute<
139
138
  actionState.error = err
140
139
  actionState.status = 'error'
141
140
  } finally {
142
- action.pending = action.pending.filter((d) => d !== actionState)
143
- router.removeActionQueue.push({ action, actionState })
144
141
  router.notify()
145
142
  }
146
143
  },
@@ -228,16 +225,3 @@ export function createRoute<
228
225
 
229
226
  return route
230
227
  }
231
-
232
- export function cascadeLoaderData(matches: RouteMatch<any, any>[]) {
233
- matches.forEach((match, index) => {
234
- const parent = matches[index - 1]
235
-
236
- if (parent) {
237
- match.loaderData = replaceEqualDeep(match.loaderData, {
238
- ...parent.loaderData,
239
- ...match.routeLoaderData,
240
- })
241
- }
242
- })
243
- }
@@ -3,6 +3,7 @@ import { ParsePathParams } from './link'
3
3
  import { joinPaths, trimPath, trimPathRight } from './path'
4
4
  import { RouteInfo } from './routeInfo'
5
5
  import { RouteMatch } from './routeMatch'
6
+ import { RouterContext } from './router'
6
7
  import {
7
8
  DeepAwaited,
8
9
  Expand,
@@ -50,7 +51,7 @@ export type ParentParams<TParentParams> = AnyPathParams extends TParentParams
50
51
  }
51
52
 
52
53
  export type LoaderFn<
53
- TRouteLoaderData extends AnyLoaderData,
54
+ TRouteLoaderData extends AnyLoaderData = {},
54
55
  TFullSearchSchema extends AnySearchSchema = {},
55
56
  TAllParams extends AnyPathParams = {},
56
57
  > = (
@@ -64,6 +65,7 @@ export interface LoaderContext<
64
65
  params: TAllParams
65
66
  search: TFullSearchSchema
66
67
  signal?: AbortSignal
68
+ // parentLoaderPromise?: Promise<TParentRouteLoaderData>
67
69
  }
68
70
 
69
71
  export type ActionFn<TActionPayload = unknown, TActionResponse = unknown> = (
@@ -77,6 +79,7 @@ export type UnloaderFn<TPath extends string> = (
77
79
  export type RouteOptions<
78
80
  TRouteId extends string = string,
79
81
  TPath extends string = string,
82
+ TParentRouteLoaderData extends AnyLoaderData = {},
80
83
  TRouteLoaderData extends AnyLoaderData = {},
81
84
  TLoaderData extends AnyLoaderData = {},
82
85
  TActionPayload = unknown,
@@ -108,18 +111,12 @@ export type RouteOptions<
108
111
  // Filter functions that can manipulate search params *after* they are passed to links and navigate
109
112
  // calls that match this route.
110
113
  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>>
114
+ // The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`
115
+ component?: GetFrameworkGeneric<'Component'> // , NoInfer<TParentLoaderData>>
116
+ // The content to be rendered when the route encounters an error
117
+ errorComponent?: GetFrameworkGeneric<'Component'> // , NoInfer<TParentLoaderData>>
118
+ // If supported by your framework, the content to be rendered as the fallback content until the route is ready to render
119
+ pendingComponent?: GetFrameworkGeneric<'Component'> //, NoInfer<TParentLoaderData>>
123
120
  // An asynchronous function responsible for preparing or fetching data for the route before it is rendered
124
121
  loader?: LoaderFn<TRouteLoaderData, TFullSearchSchema, TAllParams>
125
122
  // The max age to consider loader data fresh (not-stale) for this route in milliseconds from the time of fetch
@@ -131,13 +128,13 @@ export type RouteOptions<
131
128
  // An asynchronous function made available to the route for performing asynchronous or mutative actions that
132
129
  // might invalidate the route's data.
133
130
  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
131
+ // This async function is called before a route is loaded. If an error is thrown, the navigation is cancelled.
132
+ // If you want to redirect instead, throw a call to the `router.navigate()` function
133
+ beforeLoad?: (opts: { context: RouterContext }) => Promise<void> | void
137
134
  // This function is called
138
135
  // when moving from an inactive state to an active one. Likewise, when moving from
139
136
  // an active to an inactive state, the return function (if provided) is called.
140
- onMatch?: (matchContext: {
137
+ onLoaded?: (matchContext: {
141
138
  params: TAllParams
142
139
  search: TFullSearchSchema
143
140
  }) =>
@@ -177,6 +174,7 @@ export interface RouteConfig<
177
174
  TRouteId extends string = string,
178
175
  TPath extends string = string,
179
176
  TFullPath extends string = string,
177
+ TParentRouteLoaderData extends AnyLoaderData = AnyLoaderData,
180
178
  TRouteLoaderData extends AnyLoaderData = AnyLoaderData,
181
179
  TLoaderData extends AnyLoaderData = AnyLoaderData,
182
180
  TActionPayload = unknown,
@@ -199,6 +197,7 @@ export interface RouteConfig<
199
197
  options: RouteOptions<
200
198
  TRouteId,
201
199
  TPath,
200
+ TParentRouteLoaderData,
202
201
  TRouteLoaderData,
203
202
  TLoaderData,
204
203
  TActionPayload,
@@ -223,6 +222,7 @@ export interface RouteConfig<
223
222
  TRouteId,
224
223
  TPath,
225
224
  TFullPath,
225
+ TParentRouteLoaderData,
226
226
  TRouteLoaderData,
227
227
  TLoaderData,
228
228
  TActionPayload,
@@ -245,6 +245,7 @@ export interface RouteConfig<
245
245
  false,
246
246
  TId,
247
247
  TFullPath,
248
+ TRouteLoaderData,
248
249
  TLoaderData,
249
250
  TFullSearchSchema,
250
251
  TAllParams
@@ -257,6 +258,7 @@ export interface RouteConfig<
257
258
  TRouteId,
258
259
  TPath,
259
260
  TFullPath,
261
+ TParentRouteLoaderData,
260
262
  TRouteLoaderData,
261
263
  TLoaderData,
262
264
  TActionPayload,
@@ -274,6 +276,7 @@ export interface RouteConfig<
274
276
  false,
275
277
  TId,
276
278
  TFullPath,
279
+ TRouteLoaderData,
277
280
  TLoaderData,
278
281
  TFullSearchSchema,
279
282
  TAllParams
@@ -284,7 +287,8 @@ type CreateRouteConfigFn<
284
287
  TIsRoot extends boolean = false,
285
288
  TParentId extends string = string,
286
289
  TParentPath extends string = string,
287
- TParentAllLoaderData extends AnyLoaderData = {},
290
+ TParentRouteLoaderData extends AnyLoaderData = {},
291
+ TParentLoaderData extends AnyLoaderData = {},
288
292
  TParentSearchSchema extends AnySearchSchema = {},
289
293
  TParentParams extends AnyPathParams = {},
290
294
  > = <
@@ -315,8 +319,9 @@ type CreateRouteConfigFn<
315
319
  RouteOptions<
316
320
  TRouteId,
317
321
  TPath,
322
+ TParentRouteLoaderData,
318
323
  TRouteLoaderData,
319
- Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
324
+ Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
320
325
  TActionPayload,
321
326
  TActionResponse,
322
327
  TParentSearchSchema,
@@ -331,8 +336,9 @@ type CreateRouteConfigFn<
331
336
  : RouteOptions<
332
337
  TRouteId,
333
338
  TPath,
339
+ TParentRouteLoaderData,
334
340
  TRouteLoaderData,
335
- Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
341
+ Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
336
342
  TActionPayload,
337
343
  TActionResponse,
338
344
  TParentSearchSchema,
@@ -351,8 +357,9 @@ type CreateRouteConfigFn<
351
357
  TResolvedId,
352
358
  TPath,
353
359
  string extends TPath ? '' : RoutePath<RoutePrefix<TParentPath, TPath>>,
360
+ TParentRouteLoaderData,
354
361
  TRouteLoaderData,
355
- Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
362
+ Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
356
363
  TActionPayload,
357
364
  TActionResponse,
358
365
  TParentSearchSchema,
@@ -395,6 +402,7 @@ export interface AnyRouteConfig
395
402
  any,
396
403
  any,
397
404
  any,
405
+ any,
398
406
  any
399
407
  > {}
400
408
 
@@ -414,6 +422,7 @@ export interface AnyRouteConfigWithChildren<TChildren>
414
422
  any,
415
423
  any,
416
424
  any,
425
+ any,
417
426
  TChildren
418
427
  > {}
419
428
 
package/src/routeInfo.ts CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  RouteConfig,
11
11
  RouteOptions,
12
12
  } from './routeConfig'
13
- import { IsAny, Values } from './utils'
13
+ import { IsAny, UnionToIntersection, Values } from './utils'
14
14
 
15
15
  export interface AnyAllRouteInfo {
16
16
  routeConfig: AnyRouteConfig
@@ -19,6 +19,7 @@ export interface AnyAllRouteInfo {
19
19
  routeInfoByFullPath: Record<string, AnyRouteInfo>
20
20
  routeIds: any
21
21
  routePaths: any
22
+ fullSearchSchema: Record<string, any>
22
23
  }
23
24
 
24
25
  export interface DefaultAllRouteInfo {
@@ -28,6 +29,7 @@ export interface DefaultAllRouteInfo {
28
29
  routeInfoByFullPath: Record<string, RouteInfo>
29
30
  routeIds: string
30
31
  routePaths: string
32
+ fullSearchSchema: AnySearchSchema
31
33
  }
32
34
 
33
35
  export interface AllRouteInfo<TRouteConfig extends AnyRouteConfig = RouteConfig>
@@ -63,6 +65,7 @@ export type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<
63
65
  infer TRouteId,
64
66
  infer TPath,
65
67
  infer TFullPath,
68
+ infer TParentLoaderData,
66
69
  infer TRouteLoaderData,
67
70
  infer TLoaderData,
68
71
  infer TActionPayload,
@@ -82,6 +85,7 @@ export type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<
82
85
  TRouteId,
83
86
  TPath,
84
87
  TFullPath,
88
+ TParentLoaderData,
85
89
  TRouteLoaderData,
86
90
  TLoaderData,
87
91
  TActionPayload,
@@ -111,12 +115,13 @@ export interface RoutesInfoInner<
111
115
  any,
112
116
  any,
113
117
  any,
118
+ any,
114
119
  any
115
120
  > = RouteInfo,
116
- TRouteInfoById = {
121
+ TRouteInfoById = { '/': TRouteInfo } & {
117
122
  [TInfo in TRouteInfo as TInfo['id']]: TInfo
118
123
  },
119
- TRouteInfoByFullPath = {
124
+ TRouteInfoByFullPath = { '/': TRouteInfo } & {
120
125
  [TInfo in TRouteInfo as TInfo['fullPath'] extends RootRouteId
121
126
  ? never
122
127
  : string extends TInfo['fullPath']
@@ -130,6 +135,7 @@ export interface RoutesInfoInner<
130
135
  routeInfoByFullPath: TRouteInfoByFullPath
131
136
  routeIds: keyof TRouteInfoById
132
137
  routePaths: keyof TRouteInfoByFullPath
138
+ fullSearchSchema: Partial<UnionToIntersection<TRouteInfo['fullSearchSchema']>>
133
139
  }
134
140
 
135
141
  export interface AnyRouteInfo
@@ -147,6 +153,7 @@ export interface AnyRouteInfo
147
153
  any,
148
154
  any,
149
155
  any,
156
+ any,
150
157
  any
151
158
  > {}
152
159
 
@@ -155,6 +162,7 @@ export interface RouteInfo<
155
162
  TRouteId extends string = string,
156
163
  TPath extends string = string,
157
164
  TFullPath extends string = string,
165
+ TParentRouteLoaderData extends AnyLoaderData = {},
158
166
  TRouteLoaderData extends AnyLoaderData = {},
159
167
  TLoaderData extends AnyLoaderData = {},
160
168
  TActionPayload = unknown,
@@ -173,6 +181,7 @@ export interface RouteInfo<
173
181
  routeId: TRouteId
174
182
  path: TPath
175
183
  fullPath: TFullPath
184
+ parentRouteLoaderData: TParentRouteLoaderData
176
185
  routeLoaderData: TRouteLoaderData
177
186
  loaderData: TLoaderData
178
187
  actionPayload: TActionPayload
@@ -185,6 +194,7 @@ export interface RouteInfo<
185
194
  options: RouteOptions<
186
195
  TRouteId,
187
196
  TPath,
197
+ TParentRouteLoaderData,
188
198
  TRouteLoaderData,
189
199
  TLoaderData,
190
200
  TActionPayload,