@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.
- package/LICENSE +21 -0
- package/build/cjs/defer.js +39 -0
- package/build/cjs/defer.js.map +1 -0
- package/build/cjs/fileRoute.js +29 -0
- package/build/cjs/fileRoute.js.map +1 -0
- package/build/cjs/index.js +89 -0
- 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} +45 -56
- package/build/cjs/path.js.map +1 -0
- package/build/cjs/{packages/router-core/src/qss.js → qss.js} +10 -15
- package/build/cjs/qss.js.map +1 -0
- package/build/cjs/route.js +114 -0
- package/build/cjs/route.js.map +1 -0
- package/build/cjs/router.js +1277 -0
- package/build/cjs/router.js.map +1 -0
- package/build/cjs/scroll-restoration.js +139 -0
- package/build/cjs/scroll-restoration.js.map +1 -0
- package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +32 -19
- package/build/cjs/searchParams.js.map +1 -0
- package/build/cjs/utils.js +132 -0
- package/build/cjs/utils.js.map +1 -0
- package/build/esm/index.js +1565 -2106
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +59 -49
- package/build/stats-react.json +219 -241
- package/build/types/defer.d.ts +19 -0
- package/build/types/fileRoute.d.ts +35 -0
- package/build/types/index.d.ts +13 -611
- package/build/types/link.d.ts +96 -0
- package/build/types/path.d.ts +16 -0
- package/build/types/qss.d.ts +2 -0
- package/build/types/route.d.ts +261 -0
- package/build/types/routeInfo.d.ts +22 -0
- package/build/types/router.d.ts +265 -0
- package/build/types/scroll-restoration.d.ts +6 -0
- package/build/types/searchParams.d.ts +5 -0
- package/build/types/utils.d.ts +51 -0
- package/build/umd/index.development.js +1917 -2070
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +23 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +13 -7
- package/src/defer.ts +55 -0
- package/src/fileRoute.ts +156 -0
- package/src/index.ts +5 -11
- package/src/link.ts +149 -123
- package/src/path.ts +37 -17
- package/src/qss.ts +1 -1
- package/src/route.ts +861 -231
- package/src/routeInfo.ts +47 -205
- package/src/router.ts +1818 -952
- package/src/scroll-restoration.ts +179 -0
- package/src/searchParams.ts +31 -9
- package/src/utils.ts +106 -43
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- 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/index.js +0 -58
- 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 +0 -161
- package/build/cjs/packages/router-core/src/route.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeConfig.js +0 -69
- 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 +0 -789
- 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 +0 -118
- package/build/cjs/packages/router-core/src/utils.js.map +0 -1
- package/src/frameworks.ts +0 -12
- package/src/routeConfig.ts +0 -495
- package/src/routeMatch.ts +0 -374
package/src/path.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyPathParams } from './
|
|
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
|
|
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
|
-
|
|
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.
|
|
135
|
-
|
|
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(
|
|
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(
|
|
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
|
|
184
|
-
const
|
|
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 (
|
|
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 (
|
|
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) {
|