@tanstack/router-core 0.0.1-beta.4 → 0.0.1-beta.45

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 (62) hide show
  1. package/LICENSE +21 -0
  2. package/build/cjs/{packages/router-core/src/index.js → index.js} +25 -8
  3. package/build/cjs/{packages/router-core/src/index.js.map → index.js.map} +1 -1
  4. package/build/cjs/{packages/router-core/src/path.js → path.js} +19 -43
  5. package/build/cjs/path.js.map +1 -0
  6. package/build/cjs/{packages/router-core/src/qss.js → qss.js} +8 -13
  7. package/build/cjs/qss.js.map +1 -0
  8. package/build/cjs/route.js +155 -0
  9. package/build/cjs/route.js.map +1 -0
  10. package/build/cjs/{packages/router-core/src/routeConfig.js → routeConfig.js} +14 -13
  11. package/build/cjs/routeConfig.js.map +1 -0
  12. package/build/cjs/routeMatch.js +242 -0
  13. package/build/cjs/routeMatch.js.map +1 -0
  14. package/build/cjs/router.js +807 -0
  15. package/build/cjs/router.js.map +1 -0
  16. package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +10 -12
  17. package/build/cjs/searchParams.js.map +1 -0
  18. package/build/cjs/sharedClone.js +122 -0
  19. package/build/cjs/sharedClone.js.map +1 -0
  20. package/build/cjs/utils.js +47 -0
  21. package/build/cjs/utils.js.map +1 -0
  22. package/build/esm/index.js +890 -1739
  23. package/build/esm/index.js.map +1 -1
  24. package/build/stats-html.html +59 -49
  25. package/build/stats-react.json +196 -178
  26. package/build/types/index.d.ts +287 -283
  27. package/build/umd/index.development.js +1233 -922
  28. package/build/umd/index.development.js.map +1 -1
  29. package/build/umd/index.production.js +1 -1
  30. package/build/umd/index.production.js.map +1 -1
  31. package/package.json +5 -3
  32. package/src/frameworks.ts +2 -2
  33. package/src/index.ts +1 -1
  34. package/src/link.ts +86 -43
  35. package/src/path.ts +12 -8
  36. package/src/route.ts +170 -158
  37. package/src/routeConfig.ts +105 -77
  38. package/src/routeInfo.ts +26 -8
  39. package/src/routeMatch.ts +204 -217
  40. package/src/router.ts +680 -503
  41. package/src/sharedClone.ts +118 -0
  42. package/src/utils.ts +14 -72
  43. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
  44. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  45. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
  46. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
  47. package/build/cjs/node_modules/history/index.js +0 -815
  48. package/build/cjs/node_modules/history/index.js.map +0 -1
  49. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
  50. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
  51. package/build/cjs/packages/router-core/src/path.js.map +0 -1
  52. package/build/cjs/packages/router-core/src/qss.js.map +0 -1
  53. package/build/cjs/packages/router-core/src/route.js +0 -161
  54. package/build/cjs/packages/router-core/src/route.js.map +0 -1
  55. package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
  56. package/build/cjs/packages/router-core/src/routeMatch.js +0 -266
  57. package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
  58. package/build/cjs/packages/router-core/src/router.js +0 -789
  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 +0 -118
  62. 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",
4
+ "version": "0.0.1-beta.45",
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/packages/router-core/src/index.js",
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,16 +33,18 @@
33
33
  "build/**",
34
34
  "src"
35
35
  ],
36
+ "sideEffects": false,
36
37
  "peerDependencies": {
37
38
  "react": ">=16",
38
39
  "react-dom": ">=16"
39
40
  },
40
41
  "dependencies": {
41
42
  "@babel/runtime": "^7.16.7",
43
+ "@solidjs/reactivity": "^0.0.6",
42
44
  "history": "^5.2.0",
43
45
  "tiny-invariant": "^1.3.1"
44
46
  },
45
47
  "devDependencies": {
46
48
  "babel-plugin-transform-async-to-promises": "^0.8.18"
47
49
  }
48
- }
50
+ }
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
- // Element: any
7
- // SyncOrAsyncElement?: any
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
@@ -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'
@@ -18,3 +17,4 @@ export * from './routeMatch'
18
17
  export * from './router'
19
18
  export * from './searchParams'
20
19
  export * from './utils'
20
+ export * from './sharedClone'
package/src/link.ts CHANGED
@@ -1,11 +1,16 @@
1
- import { AnyPathParams } from './routeConfig'
2
1
  import {
3
2
  AnyAllRouteInfo,
4
3
  DefaultAllRouteInfo,
5
4
  RouteInfoByPath,
6
5
  } from './routeInfo'
7
- import { Location } from './router'
8
- import { Expand, NoInfer, PickAsRequired, PickRequired, Updater } from './utils'
6
+ import { Location, LocationState } from './router'
7
+ import {
8
+ Expand,
9
+ NoInfer,
10
+ PickRequired,
11
+ UnionToIntersection,
12
+ Updater,
13
+ } from './utils'
9
14
 
10
15
  export type LinkInfo =
11
16
  | {
@@ -58,7 +63,7 @@ export type Split<S, TIncludeTrailingSlash = true> = S extends unknown
58
63
  : never
59
64
 
60
65
  export type ParsePathParams<T extends string> = Split<T>[number] extends infer U
61
- ? U extends `:${infer V}`
66
+ ? U extends `$${infer V}`
62
67
  ? V
63
68
  : never
64
69
  : never
@@ -106,11 +111,20 @@ export type RelativeToPathAutoComplete<
106
111
  ]
107
112
  ? `${TTo}${Join<RestPath>}`
108
113
  : never
109
- : './' | '../' | AllPaths
114
+ :
115
+ | (TFrom extends `/`
116
+ ? never
117
+ : SplitPaths extends [...Split<TFrom, false>, ...infer RestPath]
118
+ ? Join<RestPath> extends { length: 0 }
119
+ ? never
120
+ : './'
121
+ : never)
122
+ | (TFrom extends `/` ? never : '../')
123
+ | AllPaths
110
124
 
111
- export type NavigateOptionsAbsolute<
125
+ export type NavigateOptions<
112
126
  TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,
113
- TFrom extends ValidFromPath<TAllRouteInfo> = '/',
127
+ TFrom extends TAllRouteInfo['routePaths'] = '/',
114
128
  TTo extends string = '.',
115
129
  > = ToOptions<TAllRouteInfo, TFrom, TTo> & {
116
130
  // Whether to replace the current history stack instead of pushing a new one
@@ -119,13 +133,15 @@ export type NavigateOptionsAbsolute<
119
133
 
120
134
  export type ToOptions<
121
135
  TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,
122
- TFrom extends ValidFromPath<TAllRouteInfo> = '/',
136
+ TFrom extends TAllRouteInfo['routePaths'] = '/',
123
137
  TTo extends string = '.',
124
138
  TResolvedTo = ResolveRelativePath<TFrom, NoInfer<TTo>>,
125
139
  > = {
126
140
  to?: ToPathOption<TAllRouteInfo, TFrom, TTo>
127
141
  // The new has string or a function to update it
128
142
  hash?: Updater<string>
143
+ // State to pass to the history stack
144
+ state?: LocationState
129
145
  // 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
146
  from?: TFrom
131
147
  // // When using relative route paths, this option forces resolution from the current path, instead of the route API's path or `from` path
@@ -134,57 +150,84 @@ export type ToOptions<
134
150
  SearchParamOptions<TAllRouteInfo, TFrom, TResolvedTo> &
135
151
  PathParamOptions<TAllRouteInfo, TFrom, TResolvedTo>
136
152
 
137
- type SearchParamOptions<
153
+ export type SearchParamOptions<
138
154
  TAllRouteInfo extends AnyAllRouteInfo,
139
155
  TFrom,
140
156
  TTo,
141
- TFromSchema = RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema'],
142
- TToSchema = RouteInfoByPath<TAllRouteInfo, TTo>['fullSearchSchema'],
143
- > = StartsWith<TFrom, TTo> extends true // If the next route search extend or cover the from route, params will be optional
144
- ? {
145
- search?: SearchReducer<TFromSchema, TToSchema>
146
- }
147
- : // Optional search params? Allow it
148
- keyof PickRequired<TToSchema> extends never
157
+ TFromSchema = Expand<
158
+ UnionToIntersection<
159
+ TAllRouteInfo['fullSearchSchema'] &
160
+ RouteInfoByPath<TAllRouteInfo, TFrom> extends never
161
+ ? {}
162
+ : RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema']
163
+ >
164
+ >,
165
+ // Find the schema for the new path, and make optional any keys
166
+ // that are already defined in the current schema
167
+ TToSchema = Partial<
168
+ RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema']
169
+ > &
170
+ Omit<
171
+ RouteInfoByPath<TAllRouteInfo, TTo>['fullSearchSchema'],
172
+ keyof PickRequired<
173
+ RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema']
174
+ >
175
+ >,
176
+ TFromFullSchema = Expand<
177
+ UnionToIntersection<TAllRouteInfo['fullSearchSchema'] & TFromSchema>
178
+ >,
179
+ TToFullSchema = Expand<
180
+ UnionToIntersection<TAllRouteInfo['fullSearchSchema'] & TToSchema>
181
+ >,
182
+ > = keyof PickRequired<TToSchema> extends never
149
183
  ? {
150
- search?: SearchReducer<TFromSchema, TToSchema>
184
+ search?: true | SearchReducer<TFromFullSchema, TToFullSchema>
151
185
  }
152
186
  : {
153
- // Must have required search params, enforce it
154
- search: SearchReducer<TFromSchema, TToSchema>
187
+ search: SearchReducer<TFromFullSchema, TToFullSchema>
155
188
  }
156
189
 
157
190
  type SearchReducer<TFrom, TTo> =
158
191
  | { [TKey in keyof TTo]: TTo[TKey] }
159
192
  | ((current: TFrom) => TTo)
160
193
 
161
- type PathParamOptions<
194
+ export type PathParamOptions<
162
195
  TAllRouteInfo extends AnyAllRouteInfo,
163
196
  TFrom,
164
197
  TTo,
165
- TFromParams = RouteInfoByPath<TAllRouteInfo, TFrom>['allParams'],
166
- TToParams = RouteInfoByPath<TAllRouteInfo, TTo>['allParams'],
167
- > =
168
- // If the next routes params extend or cover the from route, params will be optional
169
- StartsWith<TFrom, TTo> extends true
170
- ? {
171
- params?: ParamsReducer<TFromParams, TToParams>
172
- }
173
- : // If the next route doesn't have params, warn if any have been passed
174
- AnyPathParams extends TToParams
175
- ? {
176
- params?: ParamsReducer<TFromParams, Record<string, never>>
177
- }
178
- : // If the next route has params, enforce them
179
- {
180
- params: ParamsReducer<TFromParams, TToParams>
181
- }
198
+ TFromSchema = Expand<
199
+ UnionToIntersection<
200
+ RouteInfoByPath<TAllRouteInfo, TFrom> extends never
201
+ ? {}
202
+ : RouteInfoByPath<TAllRouteInfo, TFrom>['allParams']
203
+ >
204
+ >,
205
+ // Find the schema for the new path, and make optional any keys
206
+ // that are already defined in the current schema
207
+ TToSchema = Partial<RouteInfoByPath<TAllRouteInfo, TFrom>['allParams']> &
208
+ Omit<
209
+ RouteInfoByPath<TAllRouteInfo, TTo>['allParams'],
210
+ keyof PickRequired<RouteInfoByPath<TAllRouteInfo, TFrom>['allParams']>
211
+ >,
212
+ TFromFullParams = Expand<
213
+ UnionToIntersection<TAllRouteInfo['allParams'] & TFromSchema>
214
+ >,
215
+ TToFullParams = Expand<
216
+ UnionToIntersection<TAllRouteInfo['allParams'] & TToSchema>
217
+ >,
218
+ > = keyof PickRequired<TToSchema> extends never
219
+ ? {
220
+ params?: ParamsReducer<TFromFullParams, TToFullParams>
221
+ }
222
+ : {
223
+ params: ParamsReducer<TFromFullParams, TToFullParams>
224
+ }
182
225
 
183
226
  type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo)
184
227
 
185
228
  export type ToPathOption<
186
229
  TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,
187
- TFrom extends ValidFromPath<TAllRouteInfo> = '/',
230
+ TFrom extends TAllRouteInfo['routePaths'] = '/',
188
231
  TTo extends string = '.',
189
232
  > =
190
233
  | TTo
@@ -196,7 +239,7 @@ export type ToPathOption<
196
239
 
197
240
  export type ToIdOption<
198
241
  TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,
199
- TFrom extends ValidFromPath<TAllRouteInfo> = '/',
242
+ TFrom extends TAllRouteInfo['routePaths'] = '/',
200
243
  TTo extends string = '.',
201
244
  > =
202
245
  | TTo
@@ -206,16 +249,16 @@ export type ToIdOption<
206
249
  NoInfer<TTo> & string
207
250
  >
208
251
 
209
- interface ActiveOptions {
252
+ export interface ActiveOptions {
210
253
  exact?: boolean
211
254
  includeHash?: boolean
212
255
  }
213
256
 
214
257
  export type LinkOptions<
215
258
  TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,
216
- TFrom extends ValidFromPath<TAllRouteInfo> = '/',
259
+ TFrom extends TAllRouteInfo['routePaths'] = '/',
217
260
  TTo extends string = '.',
218
- > = NavigateOptionsAbsolute<TAllRouteInfo, TFrom, TTo> & {
261
+ > = NavigateOptions<TAllRouteInfo, TFrom, TTo> & {
219
262
  // The standard anchor tag target attribute
220
263
  target?: HTMLAnchorElement['target']
221
264
  // Defaults to `{ exact: false, includeHash: false }`
package/src/path.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import invariant from 'tiny-invariant'
1
2
  import { AnyPathParams } from './routeConfig'
2
3
  import { MatchLocation } from './router'
3
4
  import { last } from './utils'
@@ -97,7 +98,7 @@ export function parsePathname(pathname?: string): Segment[] {
97
98
  }
98
99
  }
99
100
 
100
- if (part.charAt(0) === ':') {
101
+ if (part.charAt(0) === '$') {
101
102
  return {
102
103
  type: 'param',
103
104
  value: part,
@@ -145,29 +146,32 @@ export function interpolatePath(
145
146
  }
146
147
 
147
148
  export function matchPathname(
149
+ basepath: string,
148
150
  currentPathname: string,
149
151
  matchLocation: Pick<MatchLocation, 'to' | 'fuzzy' | 'caseSensitive'>,
150
152
  ): AnyPathParams | undefined {
151
- const pathParams = matchByPath(currentPathname, matchLocation)
153
+ const pathParams = matchByPath(basepath, currentPathname, matchLocation)
152
154
  // const searchMatched = matchBySearch(currentLocation.search, matchLocation)
153
155
 
154
156
  if (matchLocation.to && !pathParams) {
155
157
  return
156
158
  }
157
159
 
158
- // if (matchLocation.search && !searchMatched) {
159
- // return
160
- // }
161
-
162
160
  return pathParams ?? {}
163
161
  }
164
162
 
165
163
  export function matchByPath(
164
+ basepath: string,
166
165
  from: string,
167
166
  matchLocation: Pick<MatchLocation, 'to' | 'caseSensitive' | 'fuzzy'>,
168
167
  ): Record<string, string> | undefined {
168
+ if (!from.startsWith(basepath)) {
169
+ return undefined
170
+ }
171
+ from = basepath != '/' ? from.substring(basepath.length) : from
169
172
  const baseSegments = parsePathname(from)
170
- const routeSegments = parsePathname(`${matchLocation.to ?? '*'}`)
173
+ const to = `${matchLocation.to ?? '*'}`
174
+ const routeSegments = parsePathname(to)
171
175
 
172
176
  const params: Record<string, string> = {}
173
177
 
@@ -219,7 +223,7 @@ export function matchByPath(
219
223
  if (baseSegment?.value === '/') {
220
224
  return false
221
225
  }
222
- if (!baseSegment.value.startsWith(':')) {
226
+ if (baseSegment.value.charAt(0) !== '$') {
223
227
  params[routeSegment.value.substring(1)] = baseSegment.value
224
228
  }
225
229
  }