@tanstack/router-core 0.0.1-beta.3 → 0.0.1-beta.31
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/_virtual/_rollupPluginBabelHelpers.js +0 -2
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/build/cjs/{packages/router-core/src/index.js → index.js} +23 -7
- package/build/cjs/{packages/router-core/src/index.js.map → index.js.map} +1 -1
- package/build/cjs/{packages/router-core/src/path.js → path.js} +7 -34
- package/build/cjs/path.js.map +1 -0
- package/build/cjs/{packages/router-core/src/qss.js → qss.js} +9 -13
- package/build/cjs/qss.js.map +1 -0
- package/build/cjs/{packages/router-core/src/route.js → route.js} +15 -37
- package/build/cjs/route.js.map +1 -0
- package/build/cjs/{packages/router-core/src/routeConfig.js → routeConfig.js} +13 -12
- package/build/cjs/routeConfig.js.map +1 -0
- package/build/cjs/routeMatch.js +200 -0
- package/build/cjs/routeMatch.js.map +1 -0
- package/build/cjs/{packages/router-core/src/router.js → router.js} +257 -221
- package/build/cjs/router.js.map +1 -0
- package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +7 -10
- package/build/cjs/searchParams.js.map +1 -0
- package/build/cjs/{packages/router-core/src/utils.js → utils.js} +17 -30
- package/build/cjs/utils.js.map +1 -0
- package/build/esm/index.js +395 -1322
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +59 -49
- package/build/stats-react.json +161 -168
- package/build/types/index.d.ts +247 -227
- package/build/umd/index.development.js +385 -495
- 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 +3 -2
- package/src/frameworks.ts +2 -2
- package/src/index.ts +0 -1
- package/src/link.ts +66 -31
- package/src/path.ts +2 -6
- package/src/qss.ts +1 -0
- package/src/route.ts +25 -33
- package/src/routeConfig.ts +100 -77
- package/src/routeInfo.ts +26 -8
- package/src/routeMatch.ts +100 -160
- package/src/router.ts +363 -141
- package/src/utils.ts +14 -7
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
- package/build/cjs/node_modules/history/index.js +0 -815
- package/build/cjs/node_modules/history/index.js.map +0 -1
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
- package/build/cjs/packages/router-core/src/path.js.map +0 -1
- package/build/cjs/packages/router-core/src/qss.js.map +0 -1
- package/build/cjs/packages/router-core/src/route.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeMatch.js +0 -266
- package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
- package/build/cjs/packages/router-core/src/router.js.map +0 -1
- package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
- package/build/cjs/packages/router-core/src/utils.js.map +0 -1
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.31",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://tanstack.com/router",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"url": "https://github.com/sponsors/tannerlinsley"
|
|
24
24
|
},
|
|
25
25
|
"module": "build/esm/index.js",
|
|
26
|
-
"main": "build/cjs/
|
|
26
|
+
"main": "build/cjs/index.js",
|
|
27
27
|
"browser": "build/umd/index.production.js",
|
|
28
28
|
"types": "build/types/index.d.ts",
|
|
29
29
|
"engines": {
|
|
@@ -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,8 @@ export interface FrameworkGenerics {
|
|
|
3
3
|
// and are extended by framework adapters, but cannot be
|
|
4
4
|
// pre-defined as constraints:
|
|
5
5
|
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
6
|
+
// Component: any
|
|
7
|
+
// ErrorComponent: any
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export type GetFrameworkGeneric<U> = U extends keyof FrameworkGenerics
|
package/src/index.ts
CHANGED
package/src/link.ts
CHANGED
|
@@ -4,8 +4,14 @@ import {
|
|
|
4
4
|
DefaultAllRouteInfo,
|
|
5
5
|
RouteInfoByPath,
|
|
6
6
|
} from './routeInfo'
|
|
7
|
-
import { Location } from './router'
|
|
8
|
-
import {
|
|
7
|
+
import { Location, LocationState } from './router'
|
|
8
|
+
import {
|
|
9
|
+
Expand,
|
|
10
|
+
NoInfer,
|
|
11
|
+
PickRequired,
|
|
12
|
+
UnionToIntersection,
|
|
13
|
+
Updater,
|
|
14
|
+
} from './utils'
|
|
9
15
|
|
|
10
16
|
export type LinkInfo =
|
|
11
17
|
| {
|
|
@@ -58,7 +64,7 @@ export type Split<S, TIncludeTrailingSlash = true> = S extends unknown
|
|
|
58
64
|
: never
|
|
59
65
|
|
|
60
66
|
export type ParsePathParams<T extends string> = Split<T>[number] extends infer U
|
|
61
|
-
? U extends
|
|
67
|
+
? U extends `$${infer V}`
|
|
62
68
|
? V
|
|
63
69
|
: never
|
|
64
70
|
: never
|
|
@@ -126,6 +132,8 @@ export type ToOptions<
|
|
|
126
132
|
to?: ToPathOption<TAllRouteInfo, TFrom, TTo>
|
|
127
133
|
// The new has string or a function to update it
|
|
128
134
|
hash?: Updater<string>
|
|
135
|
+
// State to pass to the history stack
|
|
136
|
+
state?: LocationState
|
|
129
137
|
// 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
138
|
from?: TFrom
|
|
131
139
|
// // When using relative route paths, this option forces resolution from the current path, instead of the route API's path or `from` path
|
|
@@ -138,20 +146,37 @@ type SearchParamOptions<
|
|
|
138
146
|
TAllRouteInfo extends AnyAllRouteInfo,
|
|
139
147
|
TFrom,
|
|
140
148
|
TTo,
|
|
141
|
-
TFromSchema =
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
+
TFromSchema = Expand<
|
|
150
|
+
UnionToIntersection<
|
|
151
|
+
TAllRouteInfo['fullSearchSchema'] &
|
|
152
|
+
RouteInfoByPath<TAllRouteInfo, TFrom> extends never
|
|
153
|
+
? {}
|
|
154
|
+
: RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema']
|
|
155
|
+
>
|
|
156
|
+
>,
|
|
157
|
+
// Find the schema for the new path, and make optional any keys
|
|
158
|
+
// that are already defined in the current schema
|
|
159
|
+
TToSchema = Partial<
|
|
160
|
+
RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema']
|
|
161
|
+
> &
|
|
162
|
+
Omit<
|
|
163
|
+
RouteInfoByPath<TAllRouteInfo, TTo>['fullSearchSchema'],
|
|
164
|
+
keyof PickRequired<
|
|
165
|
+
RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema']
|
|
166
|
+
>
|
|
167
|
+
>,
|
|
168
|
+
TFromFullSchema = Expand<
|
|
169
|
+
UnionToIntersection<TAllRouteInfo['fullSearchSchema'] & TFromSchema>
|
|
170
|
+
>,
|
|
171
|
+
TToFullSchema = Expand<
|
|
172
|
+
UnionToIntersection<TAllRouteInfo['fullSearchSchema'] & TToSchema>
|
|
173
|
+
>,
|
|
174
|
+
> = keyof PickRequired<TToSchema> extends never
|
|
149
175
|
? {
|
|
150
|
-
search?: SearchReducer<
|
|
176
|
+
search?: true | SearchReducer<TFromFullSchema, TToFullSchema>
|
|
151
177
|
}
|
|
152
178
|
: {
|
|
153
|
-
|
|
154
|
-
search: SearchReducer<TFromSchema, TToSchema>
|
|
179
|
+
search: SearchReducer<TFromFullSchema, TToFullSchema>
|
|
155
180
|
}
|
|
156
181
|
|
|
157
182
|
type SearchReducer<TFrom, TTo> =
|
|
@@ -162,23 +187,33 @@ type PathParamOptions<
|
|
|
162
187
|
TAllRouteInfo extends AnyAllRouteInfo,
|
|
163
188
|
TFrom,
|
|
164
189
|
TTo,
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
>
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
190
|
+
TFromSchema = Expand<
|
|
191
|
+
UnionToIntersection<
|
|
192
|
+
RouteInfoByPath<TAllRouteInfo, TFrom> extends never
|
|
193
|
+
? {}
|
|
194
|
+
: RouteInfoByPath<TAllRouteInfo, TFrom>['allParams']
|
|
195
|
+
>
|
|
196
|
+
>,
|
|
197
|
+
// Find the schema for the new path, and make optional any keys
|
|
198
|
+
// that are already defined in the current schema
|
|
199
|
+
TToSchema = Partial<RouteInfoByPath<TAllRouteInfo, TFrom>['allParams']> &
|
|
200
|
+
Omit<
|
|
201
|
+
RouteInfoByPath<TAllRouteInfo, TTo>['allParams'],
|
|
202
|
+
keyof PickRequired<RouteInfoByPath<TAllRouteInfo, TFrom>['allParams']>
|
|
203
|
+
>,
|
|
204
|
+
TFromFullParams = Expand<
|
|
205
|
+
UnionToIntersection<TAllRouteInfo['allParams'] & TFromSchema>
|
|
206
|
+
>,
|
|
207
|
+
TToFullParams = Expand<
|
|
208
|
+
UnionToIntersection<TAllRouteInfo['allParams'] & TToSchema>
|
|
209
|
+
>,
|
|
210
|
+
> = keyof PickRequired<TToSchema> extends never
|
|
211
|
+
? {
|
|
212
|
+
params?: ParamsReducer<TFromFullParams, TToFullParams>
|
|
213
|
+
}
|
|
214
|
+
: {
|
|
215
|
+
params: ParamsReducer<TFromFullParams, TToFullParams>
|
|
216
|
+
}
|
|
182
217
|
|
|
183
218
|
type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo)
|
|
184
219
|
|
package/src/path.ts
CHANGED
|
@@ -97,7 +97,7 @@ export function parsePathname(pathname?: string): Segment[] {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
if (part.charAt(0) === '
|
|
100
|
+
if (part.charAt(0) === '$') {
|
|
101
101
|
return {
|
|
102
102
|
type: 'param',
|
|
103
103
|
value: part,
|
|
@@ -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
|
|
|
@@ -219,7 +215,7 @@ export function matchByPath(
|
|
|
219
215
|
if (baseSegment?.value === '/') {
|
|
220
216
|
return false
|
|
221
217
|
}
|
|
222
|
-
if (
|
|
218
|
+
if (baseSegment.value.charAt(0) !== '$') {
|
|
223
219
|
params[routeSegment.value.substring(1)] = baseSegment.value
|
|
224
220
|
}
|
|
225
221
|
}
|
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,14 +21,16 @@ import {
|
|
|
22
21
|
MatchRouteOptions,
|
|
23
22
|
Router,
|
|
24
23
|
} from './router'
|
|
25
|
-
import { NoInfer
|
|
24
|
+
import { NoInfer } from './utils'
|
|
26
25
|
|
|
27
|
-
export interface AnyRoute extends Route<any, any> {}
|
|
26
|
+
export interface AnyRoute extends Route<any, any, any> {}
|
|
28
27
|
|
|
29
28
|
export interface Route<
|
|
30
29
|
TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,
|
|
31
30
|
TRouteInfo extends AnyRouteInfo = RouteInfo,
|
|
31
|
+
TRouterContext = unknown,
|
|
32
32
|
> {
|
|
33
|
+
routeInfo: TRouteInfo
|
|
33
34
|
routeId: TRouteInfo['id']
|
|
34
35
|
routeRouteId: TRouteInfo['routeId']
|
|
35
36
|
routePath: TRouteInfo['path']
|
|
@@ -37,7 +38,7 @@ export interface Route<
|
|
|
37
38
|
parentRoute?: AnyRoute
|
|
38
39
|
childRoutes?: AnyRoute[]
|
|
39
40
|
options: RouteOptions
|
|
40
|
-
router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>
|
|
41
|
+
router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo, TRouterContext>
|
|
41
42
|
buildLink: <TTo extends string = '.'>(
|
|
42
43
|
options: Omit<
|
|
43
44
|
LinkOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>,
|
|
@@ -57,7 +58,10 @@ export interface Route<
|
|
|
57
58
|
opts?: MatchRouteOptions,
|
|
58
59
|
) => RouteInfoByPath<TAllRouteInfo, TResolved>['allParams']
|
|
59
60
|
navigate: <TTo extends string = '.'>(
|
|
60
|
-
options: Omit<
|
|
61
|
+
options: Omit<
|
|
62
|
+
LinkOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>,
|
|
63
|
+
'from'
|
|
64
|
+
>,
|
|
61
65
|
) => Promise<void>
|
|
62
66
|
action: unknown extends TRouteInfo['actionResponse']
|
|
63
67
|
?
|
|
@@ -84,22 +88,23 @@ export interface Route<
|
|
|
84
88
|
export function createRoute<
|
|
85
89
|
TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,
|
|
86
90
|
TRouteInfo extends AnyRouteInfo = RouteInfo,
|
|
91
|
+
TRouterContext = unknown,
|
|
87
92
|
>(
|
|
88
93
|
routeConfig: RouteConfig,
|
|
89
94
|
options: TRouteInfo['options'],
|
|
90
95
|
parent: undefined | Route<TAllRouteInfo, any>,
|
|
91
|
-
router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>,
|
|
92
|
-
): Route<TAllRouteInfo, TRouteInfo> {
|
|
96
|
+
router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo, TRouterContext>,
|
|
97
|
+
): Route<TAllRouteInfo, TRouteInfo, TRouterContext> {
|
|
93
98
|
const { id, routeId, path: routePath, fullPath } = routeConfig
|
|
94
99
|
|
|
95
100
|
const action =
|
|
96
101
|
router.state.actions[id] ||
|
|
97
102
|
(() => {
|
|
98
103
|
router.state.actions[id] = {
|
|
99
|
-
|
|
104
|
+
submissions: [],
|
|
100
105
|
submit: async <T, U>(
|
|
101
106
|
submission: T,
|
|
102
|
-
actionOpts?: { invalidate?: boolean },
|
|
107
|
+
actionOpts?: { invalidate?: boolean; multi?: boolean },
|
|
103
108
|
) => {
|
|
104
109
|
if (!route) {
|
|
105
110
|
return
|
|
@@ -107,27 +112,27 @@ export function createRoute<
|
|
|
107
112
|
|
|
108
113
|
const invalidate = actionOpts?.invalidate ?? true
|
|
109
114
|
|
|
115
|
+
if (!actionOpts?.multi) {
|
|
116
|
+
action.submissions = action.submissions.filter((d) => d.isMulti)
|
|
117
|
+
}
|
|
118
|
+
|
|
110
119
|
const actionState: ActionState<T, U> = {
|
|
111
120
|
submittedAt: Date.now(),
|
|
112
121
|
status: 'pending',
|
|
113
122
|
submission,
|
|
123
|
+
isMulti: !!actionOpts?.multi,
|
|
114
124
|
}
|
|
115
125
|
|
|
116
126
|
action.current = actionState
|
|
117
127
|
action.latest = actionState
|
|
118
|
-
action.
|
|
119
|
-
|
|
120
|
-
router.state = {
|
|
121
|
-
...router.state,
|
|
122
|
-
currentAction: actionState,
|
|
123
|
-
latestAction: actionState,
|
|
124
|
-
}
|
|
128
|
+
action.submissions.push(actionState)
|
|
125
129
|
|
|
126
130
|
router.notify()
|
|
127
131
|
|
|
128
132
|
try {
|
|
129
133
|
const res = await route.options.action?.(submission)
|
|
130
134
|
actionState.data = res as U
|
|
135
|
+
|
|
131
136
|
if (invalidate) {
|
|
132
137
|
router.invalidateRoute({ to: '.', fromCurrent: true })
|
|
133
138
|
await router.reload()
|
|
@@ -135,12 +140,11 @@ export function createRoute<
|
|
|
135
140
|
actionState.status = 'success'
|
|
136
141
|
return res
|
|
137
142
|
} catch (err) {
|
|
143
|
+
console.log('tanner')
|
|
138
144
|
console.error(err)
|
|
139
145
|
actionState.error = err
|
|
140
146
|
actionState.status = 'error'
|
|
141
147
|
} finally {
|
|
142
|
-
action.pending = action.pending.filter((d) => d !== actionState)
|
|
143
|
-
router.removeActionQueue.push({ action, actionState })
|
|
144
148
|
router.notify()
|
|
145
149
|
}
|
|
146
150
|
},
|
|
@@ -187,7 +191,8 @@ export function createRoute<
|
|
|
187
191
|
return router.state.loaders[id]!
|
|
188
192
|
})()
|
|
189
193
|
|
|
190
|
-
let route: Route<TAllRouteInfo, TRouteInfo> = {
|
|
194
|
+
let route: Route<TAllRouteInfo, TRouteInfo, TRouterContext> = {
|
|
195
|
+
routeInfo: undefined!,
|
|
191
196
|
routeId: id,
|
|
192
197
|
routeRouteId: routeId,
|
|
193
198
|
routePath,
|
|
@@ -220,7 +225,7 @@ export function createRoute<
|
|
|
220
225
|
from: fullPath,
|
|
221
226
|
} as any,
|
|
222
227
|
opts,
|
|
223
|
-
)
|
|
228
|
+
) as any
|
|
224
229
|
},
|
|
225
230
|
}
|
|
226
231
|
|
|
@@ -228,16 +233,3 @@ export function createRoute<
|
|
|
228
233
|
|
|
229
234
|
return route
|
|
230
235
|
}
|
|
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
|
-
}
|