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

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 (79) hide show
  1. package/LICENSE +21 -0
  2. package/build/cjs/defer.js +39 -0
  3. package/build/cjs/defer.js.map +1 -0
  4. package/build/cjs/fileRoute.js +29 -0
  5. package/build/cjs/fileRoute.js.map +1 -0
  6. package/build/cjs/index.js +89 -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 -15
  11. package/build/cjs/qss.js.map +1 -0
  12. package/build/cjs/route.js +114 -0
  13. package/build/cjs/route.js.map +1 -0
  14. package/build/cjs/router.js +1277 -0
  15. package/build/cjs/router.js.map +1 -0
  16. package/build/cjs/scroll-restoration.js +139 -0
  17. package/build/cjs/scroll-restoration.js.map +1 -0
  18. package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +32 -19
  19. package/build/cjs/searchParams.js.map +1 -0
  20. package/build/cjs/utils.js +132 -0
  21. package/build/cjs/utils.js.map +1 -0
  22. package/build/esm/index.js +1565 -2106
  23. package/build/esm/index.js.map +1 -1
  24. package/build/stats-html.html +59 -49
  25. package/build/stats-react.json +219 -241
  26. package/build/types/defer.d.ts +19 -0
  27. package/build/types/fileRoute.d.ts +35 -0
  28. package/build/types/index.d.ts +13 -611
  29. package/build/types/link.d.ts +96 -0
  30. package/build/types/path.d.ts +16 -0
  31. package/build/types/qss.d.ts +2 -0
  32. package/build/types/route.d.ts +261 -0
  33. package/build/types/routeInfo.d.ts +22 -0
  34. package/build/types/router.d.ts +265 -0
  35. package/build/types/scroll-restoration.d.ts +6 -0
  36. package/build/types/searchParams.d.ts +5 -0
  37. package/build/types/utils.d.ts +51 -0
  38. package/build/umd/index.development.js +1917 -2070
  39. package/build/umd/index.development.js.map +1 -1
  40. package/build/umd/index.production.js +23 -2
  41. package/build/umd/index.production.js.map +1 -1
  42. package/package.json +13 -7
  43. package/src/defer.ts +55 -0
  44. package/src/fileRoute.ts +156 -0
  45. package/src/index.ts +5 -11
  46. package/src/link.ts +149 -123
  47. package/src/path.ts +37 -17
  48. package/src/qss.ts +1 -1
  49. package/src/route.ts +861 -231
  50. package/src/routeInfo.ts +47 -205
  51. package/src/router.ts +1818 -952
  52. package/src/scroll-restoration.ts +179 -0
  53. package/src/searchParams.ts +31 -9
  54. package/src/utils.ts +106 -43
  55. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
  56. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  57. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
  58. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
  59. package/build/cjs/node_modules/history/index.js +0 -815
  60. package/build/cjs/node_modules/history/index.js.map +0 -1
  61. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
  62. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
  63. package/build/cjs/packages/router-core/src/index.js +0 -58
  64. package/build/cjs/packages/router-core/src/path.js.map +0 -1
  65. package/build/cjs/packages/router-core/src/qss.js.map +0 -1
  66. package/build/cjs/packages/router-core/src/route.js +0 -161
  67. package/build/cjs/packages/router-core/src/route.js.map +0 -1
  68. package/build/cjs/packages/router-core/src/routeConfig.js +0 -69
  69. package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
  70. package/build/cjs/packages/router-core/src/routeMatch.js +0 -266
  71. package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
  72. package/build/cjs/packages/router-core/src/router.js +0 -789
  73. package/build/cjs/packages/router-core/src/router.js.map +0 -1
  74. package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
  75. package/build/cjs/packages/router-core/src/utils.js +0 -118
  76. package/build/cjs/packages/router-core/src/utils.js.map +0 -1
  77. package/src/frameworks.ts +0 -12
  78. package/src/routeConfig.ts +0 -495
  79. package/src/routeMatch.ts +0 -374
package/src/path.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnyPathParams } from './routeConfig'
1
+ import { AnyPathParams } from './route'
2
2
  import { MatchLocation } from './router'
3
3
  import { last } from './utils'
4
4
 
@@ -90,14 +90,14 @@ export function parsePathname(pathname?: string): Segment[] {
90
90
 
91
91
  segments.push(
92
92
  ...split.map((part): Segment => {
93
- if (part.startsWith('*')) {
93
+ if (part === '$' || part === '*') {
94
94
  return {
95
95
  type: 'wildcard',
96
96
  value: part,
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,
@@ -125,14 +125,16 @@ export function parsePathname(pathname?: string): Segment[] {
125
125
  export function interpolatePath(
126
126
  path: string | undefined,
127
127
  params: any,
128
- leaveWildcard?: boolean,
128
+ leaveWildcards: boolean = false,
129
129
  ) {
130
130
  const interpolatedPathSegments = parsePathname(path)
131
131
 
132
132
  return joinPaths(
133
133
  interpolatedPathSegments.map((segment) => {
134
- if (segment.value === '*' && !leaveWildcard) {
135
- return ''
134
+ if (segment.type === 'wildcard') {
135
+ const value = params[segment.value]
136
+ if (leaveWildcards) return `${segment.value}${value ?? ''}`
137
+ return value
136
138
  }
137
139
 
138
140
  if (segment.type === 'param') {
@@ -145,29 +147,46 @@ export function interpolatePath(
145
147
  }
146
148
 
147
149
  export function matchPathname(
150
+ basepath: string,
148
151
  currentPathname: string,
149
152
  matchLocation: Pick<MatchLocation, 'to' | 'fuzzy' | 'caseSensitive'>,
150
153
  ): AnyPathParams | undefined {
151
- const pathParams = matchByPath(currentPathname, matchLocation)
152
- // const searchMatched = matchBySearch(currentLocation.search, matchLocation)
154
+ const pathParams = matchByPath(basepath, currentPathname, matchLocation)
155
+ // const searchMatched = matchBySearch(location.search, matchLocation)
153
156
 
154
157
  if (matchLocation.to && !pathParams) {
155
158
  return
156
159
  }
157
160
 
158
- // if (matchLocation.search && !searchMatched) {
159
- // return
160
- // }
161
-
162
161
  return pathParams ?? {}
163
162
  }
164
163
 
165
164
  export function matchByPath(
165
+ basepath: string,
166
166
  from: string,
167
167
  matchLocation: Pick<MatchLocation, 'to' | 'caseSensitive' | 'fuzzy'>,
168
168
  ): Record<string, string> | undefined {
169
+ // Remove the base path from the pathname
170
+ from = basepath != '/' ? from.substring(basepath.length) : from
171
+ // Default to to $ (wildcard)
172
+ const to = `${matchLocation.to ?? '$'}`
173
+ // Parse the from and to
169
174
  const baseSegments = parsePathname(from)
170
- const routeSegments = parsePathname(`${matchLocation.to ?? '*'}`)
175
+ const routeSegments = parsePathname(to)
176
+
177
+ if (!from.startsWith('/')) {
178
+ baseSegments.unshift({
179
+ type: 'pathname',
180
+ value: '/',
181
+ })
182
+ }
183
+
184
+ if (!to.startsWith('/')) {
185
+ routeSegments.unshift({
186
+ type: 'pathname',
187
+ value: '/',
188
+ })
189
+ }
171
190
 
172
191
  const params: Record<string, string> = {}
173
192
 
@@ -180,8 +199,8 @@ export function matchByPath(
180
199
  const baseSegment = baseSegments[i]
181
200
  const routeSegment = routeSegments[i]
182
201
 
183
- const isLastRouteSegment = i === routeSegments.length - 1
184
- const isLastBaseSegment = i === baseSegments.length - 1
202
+ const isLastBaseSegment = i >= baseSegments.length - 1
203
+ const isLastRouteSegment = i >= routeSegments.length - 1
185
204
 
186
205
  if (routeSegment) {
187
206
  if (routeSegment.type === 'wildcard') {
@@ -219,16 +238,17 @@ export function matchByPath(
219
238
  if (baseSegment?.value === '/') {
220
239
  return false
221
240
  }
222
- if (!baseSegment.value.startsWith(':')) {
241
+ if (baseSegment.value.charAt(0) !== '$') {
223
242
  params[routeSegment.value.substring(1)] = baseSegment.value
224
243
  }
225
244
  }
226
245
  }
227
246
 
228
- if (isLastRouteSegment && !isLastBaseSegment) {
247
+ if (!isLastBaseSegment && isLastRouteSegment) {
229
248
  return !!matchLocation.fuzzy
230
249
  }
231
250
  }
251
+
232
252
  return true
233
253
  })()
234
254
 
package/src/qss.ts CHANGED
@@ -30,7 +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
- return +str * 0 === 0 ? +str : str
33
+ return +str * 0 === 0 && +str + '' === str ? +str : str
34
34
  }
35
35
 
36
36
  export function decode(str) {