@tanstack/router-core 0.0.1-beta.2 → 0.0.1-beta.21
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.
- package/build/cjs/packages/router-core/src/index.js +1 -1
- package/build/cjs/packages/router-core/src/qss.js +1 -0
- package/build/cjs/packages/router-core/src/qss.js.map +1 -1
- package/build/cjs/packages/router-core/src/route.js +9 -23
- package/build/cjs/packages/router-core/src/route.js.map +1 -1
- package/build/cjs/packages/router-core/src/routeConfig.js.map +1 -1
- package/build/cjs/packages/router-core/src/routeMatch.js +75 -121
- package/build/cjs/packages/router-core/src/routeMatch.js.map +1 -1
- package/build/cjs/packages/router-core/src/router.js +170 -89
- package/build/cjs/packages/router-core/src/router.js.map +1 -1
- package/build/cjs/packages/router-core/src/utils.js +7 -0
- package/build/cjs/packages/router-core/src/utils.js.map +1 -1
- package/build/esm/index.js +257 -227
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +137 -150
- package/build/types/index.d.ts +184 -186
- package/build/umd/index.development.js +257 -227
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -1
- package/src/frameworks.ts +1 -2
- package/src/index.ts +0 -1
- package/src/link.ts +3 -1
- package/src/qss.ts +1 -0
- package/src/route.ts +10 -26
- package/src/routeConfig.ts +25 -20
- package/src/routeInfo.ts +9 -2
- package/src/routeMatch.ts +94 -156
- package/src/router.ts +241 -104
- package/src/utils.ts +7 -0
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.
|
|
4
|
+
"version": "0.0.1-beta.21",
|
|
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
|
-
//
|
|
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
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/qss.ts
CHANGED
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
|
|
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
|
-
|
|
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.
|
|
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
|
-
}
|
package/src/routeConfig.ts
CHANGED
|
@@ -50,7 +50,7 @@ export type ParentParams<TParentParams> = AnyPathParams extends TParentParams
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export type LoaderFn<
|
|
53
|
-
TRouteLoaderData extends AnyLoaderData,
|
|
53
|
+
TRouteLoaderData extends AnyLoaderData = {},
|
|
54
54
|
TFullSearchSchema extends AnySearchSchema = {},
|
|
55
55
|
TAllParams extends AnyPathParams = {},
|
|
56
56
|
> = (
|
|
@@ -64,6 +64,7 @@ export interface LoaderContext<
|
|
|
64
64
|
params: TAllParams
|
|
65
65
|
search: TFullSearchSchema
|
|
66
66
|
signal?: AbortSignal
|
|
67
|
+
// parentLoaderPromise?: Promise<TParentRouteLoaderData>
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
export type ActionFn<TActionPayload = unknown, TActionResponse = unknown> = (
|
|
@@ -77,6 +78,7 @@ export type UnloaderFn<TPath extends string> = (
|
|
|
77
78
|
export type RouteOptions<
|
|
78
79
|
TRouteId extends string = string,
|
|
79
80
|
TPath extends string = string,
|
|
81
|
+
TParentRouteLoaderData extends AnyLoaderData = {},
|
|
80
82
|
TRouteLoaderData extends AnyLoaderData = {},
|
|
81
83
|
TLoaderData extends AnyLoaderData = {},
|
|
82
84
|
TActionPayload = unknown,
|
|
@@ -108,18 +110,12 @@ export type RouteOptions<
|
|
|
108
110
|
// Filter functions that can manipulate search params *after* they are passed to links and navigate
|
|
109
111
|
// calls that match this route.
|
|
110
112
|
postSearchFilters?: SearchFilter<TFullSearchSchema>[]
|
|
111
|
-
// The
|
|
112
|
-
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
//
|
|
116
|
-
|
|
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>>
|
|
113
|
+
// The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`
|
|
114
|
+
component?: GetFrameworkGeneric<'Component'> // , NoInfer<TParentLoaderData>>
|
|
115
|
+
// The content to be rendered when the route encounters an error
|
|
116
|
+
errorComponent?: GetFrameworkGeneric<'Component'> // , NoInfer<TParentLoaderData>>
|
|
117
|
+
// If supported by your framework, the content to be rendered as the fallback content until the route is ready to render
|
|
118
|
+
pendingComponent?: GetFrameworkGeneric<'Component'> //, NoInfer<TParentLoaderData>>
|
|
123
119
|
// An asynchronous function responsible for preparing or fetching data for the route before it is rendered
|
|
124
120
|
loader?: LoaderFn<TRouteLoaderData, TFullSearchSchema, TAllParams>
|
|
125
121
|
// The max age to consider loader data fresh (not-stale) for this route in milliseconds from the time of fetch
|
|
@@ -131,9 +127,6 @@ export type RouteOptions<
|
|
|
131
127
|
// An asynchronous function made available to the route for performing asynchronous or mutative actions that
|
|
132
128
|
// might invalidate the route's data.
|
|
133
129
|
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
130
|
// This function is called
|
|
138
131
|
// when moving from an inactive state to an active one. Likewise, when moving from
|
|
139
132
|
// an active to an inactive state, the return function (if provided) is called.
|
|
@@ -177,6 +170,7 @@ export interface RouteConfig<
|
|
|
177
170
|
TRouteId extends string = string,
|
|
178
171
|
TPath extends string = string,
|
|
179
172
|
TFullPath extends string = string,
|
|
173
|
+
TParentRouteLoaderData extends AnyLoaderData = AnyLoaderData,
|
|
180
174
|
TRouteLoaderData extends AnyLoaderData = AnyLoaderData,
|
|
181
175
|
TLoaderData extends AnyLoaderData = AnyLoaderData,
|
|
182
176
|
TActionPayload = unknown,
|
|
@@ -199,6 +193,7 @@ export interface RouteConfig<
|
|
|
199
193
|
options: RouteOptions<
|
|
200
194
|
TRouteId,
|
|
201
195
|
TPath,
|
|
196
|
+
TParentRouteLoaderData,
|
|
202
197
|
TRouteLoaderData,
|
|
203
198
|
TLoaderData,
|
|
204
199
|
TActionPayload,
|
|
@@ -223,6 +218,7 @@ export interface RouteConfig<
|
|
|
223
218
|
TRouteId,
|
|
224
219
|
TPath,
|
|
225
220
|
TFullPath,
|
|
221
|
+
TParentRouteLoaderData,
|
|
226
222
|
TRouteLoaderData,
|
|
227
223
|
TLoaderData,
|
|
228
224
|
TActionPayload,
|
|
@@ -245,6 +241,7 @@ export interface RouteConfig<
|
|
|
245
241
|
false,
|
|
246
242
|
TId,
|
|
247
243
|
TFullPath,
|
|
244
|
+
TRouteLoaderData,
|
|
248
245
|
TLoaderData,
|
|
249
246
|
TFullSearchSchema,
|
|
250
247
|
TAllParams
|
|
@@ -257,6 +254,7 @@ export interface RouteConfig<
|
|
|
257
254
|
TRouteId,
|
|
258
255
|
TPath,
|
|
259
256
|
TFullPath,
|
|
257
|
+
TParentRouteLoaderData,
|
|
260
258
|
TRouteLoaderData,
|
|
261
259
|
TLoaderData,
|
|
262
260
|
TActionPayload,
|
|
@@ -274,6 +272,7 @@ export interface RouteConfig<
|
|
|
274
272
|
false,
|
|
275
273
|
TId,
|
|
276
274
|
TFullPath,
|
|
275
|
+
TRouteLoaderData,
|
|
277
276
|
TLoaderData,
|
|
278
277
|
TFullSearchSchema,
|
|
279
278
|
TAllParams
|
|
@@ -284,7 +283,8 @@ type CreateRouteConfigFn<
|
|
|
284
283
|
TIsRoot extends boolean = false,
|
|
285
284
|
TParentId extends string = string,
|
|
286
285
|
TParentPath extends string = string,
|
|
287
|
-
|
|
286
|
+
TParentRouteLoaderData extends AnyLoaderData = {},
|
|
287
|
+
TParentLoaderData extends AnyLoaderData = {},
|
|
288
288
|
TParentSearchSchema extends AnySearchSchema = {},
|
|
289
289
|
TParentParams extends AnyPathParams = {},
|
|
290
290
|
> = <
|
|
@@ -315,8 +315,9 @@ type CreateRouteConfigFn<
|
|
|
315
315
|
RouteOptions<
|
|
316
316
|
TRouteId,
|
|
317
317
|
TPath,
|
|
318
|
+
TParentRouteLoaderData,
|
|
318
319
|
TRouteLoaderData,
|
|
319
|
-
Expand<
|
|
320
|
+
Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
|
|
320
321
|
TActionPayload,
|
|
321
322
|
TActionResponse,
|
|
322
323
|
TParentSearchSchema,
|
|
@@ -331,8 +332,9 @@ type CreateRouteConfigFn<
|
|
|
331
332
|
: RouteOptions<
|
|
332
333
|
TRouteId,
|
|
333
334
|
TPath,
|
|
335
|
+
TParentRouteLoaderData,
|
|
334
336
|
TRouteLoaderData,
|
|
335
|
-
Expand<
|
|
337
|
+
Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
|
|
336
338
|
TActionPayload,
|
|
337
339
|
TActionResponse,
|
|
338
340
|
TParentSearchSchema,
|
|
@@ -351,8 +353,9 @@ type CreateRouteConfigFn<
|
|
|
351
353
|
TResolvedId,
|
|
352
354
|
TPath,
|
|
353
355
|
string extends TPath ? '' : RoutePath<RoutePrefix<TParentPath, TPath>>,
|
|
356
|
+
TParentRouteLoaderData,
|
|
354
357
|
TRouteLoaderData,
|
|
355
|
-
Expand<
|
|
358
|
+
Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
|
|
356
359
|
TActionPayload,
|
|
357
360
|
TActionResponse,
|
|
358
361
|
TParentSearchSchema,
|
|
@@ -395,6 +398,7 @@ export interface AnyRouteConfig
|
|
|
395
398
|
any,
|
|
396
399
|
any,
|
|
397
400
|
any,
|
|
401
|
+
any,
|
|
398
402
|
any
|
|
399
403
|
> {}
|
|
400
404
|
|
|
@@ -414,6 +418,7 @@ export interface AnyRouteConfigWithChildren<TChildren>
|
|
|
414
418
|
any,
|
|
415
419
|
any,
|
|
416
420
|
any,
|
|
421
|
+
any,
|
|
417
422
|
TChildren
|
|
418
423
|
> {}
|
|
419
424
|
|
package/src/routeInfo.ts
CHANGED
|
@@ -63,6 +63,7 @@ export type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<
|
|
|
63
63
|
infer TRouteId,
|
|
64
64
|
infer TPath,
|
|
65
65
|
infer TFullPath,
|
|
66
|
+
infer TParentLoaderData,
|
|
66
67
|
infer TRouteLoaderData,
|
|
67
68
|
infer TLoaderData,
|
|
68
69
|
infer TActionPayload,
|
|
@@ -82,6 +83,7 @@ export type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<
|
|
|
82
83
|
TRouteId,
|
|
83
84
|
TPath,
|
|
84
85
|
TFullPath,
|
|
86
|
+
TParentLoaderData,
|
|
85
87
|
TRouteLoaderData,
|
|
86
88
|
TLoaderData,
|
|
87
89
|
TActionPayload,
|
|
@@ -111,12 +113,13 @@ export interface RoutesInfoInner<
|
|
|
111
113
|
any,
|
|
112
114
|
any,
|
|
113
115
|
any,
|
|
116
|
+
any,
|
|
114
117
|
any
|
|
115
118
|
> = RouteInfo,
|
|
116
|
-
TRouteInfoById = {
|
|
119
|
+
TRouteInfoById = { '/': TRouteInfo } & {
|
|
117
120
|
[TInfo in TRouteInfo as TInfo['id']]: TInfo
|
|
118
121
|
},
|
|
119
|
-
TRouteInfoByFullPath = {
|
|
122
|
+
TRouteInfoByFullPath = { '/': TRouteInfo } & {
|
|
120
123
|
[TInfo in TRouteInfo as TInfo['fullPath'] extends RootRouteId
|
|
121
124
|
? never
|
|
122
125
|
: string extends TInfo['fullPath']
|
|
@@ -147,6 +150,7 @@ export interface AnyRouteInfo
|
|
|
147
150
|
any,
|
|
148
151
|
any,
|
|
149
152
|
any,
|
|
153
|
+
any,
|
|
150
154
|
any
|
|
151
155
|
> {}
|
|
152
156
|
|
|
@@ -155,6 +159,7 @@ export interface RouteInfo<
|
|
|
155
159
|
TRouteId extends string = string,
|
|
156
160
|
TPath extends string = string,
|
|
157
161
|
TFullPath extends string = string,
|
|
162
|
+
TParentRouteLoaderData extends AnyLoaderData = {},
|
|
158
163
|
TRouteLoaderData extends AnyLoaderData = {},
|
|
159
164
|
TLoaderData extends AnyLoaderData = {},
|
|
160
165
|
TActionPayload = unknown,
|
|
@@ -173,6 +178,7 @@ export interface RouteInfo<
|
|
|
173
178
|
routeId: TRouteId
|
|
174
179
|
path: TPath
|
|
175
180
|
fullPath: TFullPath
|
|
181
|
+
parentRouteLoaderData: TParentRouteLoaderData
|
|
176
182
|
routeLoaderData: TRouteLoaderData
|
|
177
183
|
loaderData: TLoaderData
|
|
178
184
|
actionPayload: TActionPayload
|
|
@@ -185,6 +191,7 @@ export interface RouteInfo<
|
|
|
185
191
|
options: RouteOptions<
|
|
186
192
|
TRouteId,
|
|
187
193
|
TPath,
|
|
194
|
+
TParentRouteLoaderData,
|
|
188
195
|
TRouteLoaderData,
|
|
189
196
|
TLoaderData,
|
|
190
197
|
TActionPayload,
|