@tanstack/router-core 0.0.1-beta.19 → 0.0.1-beta.191
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/history.js +228 -0
- package/build/cjs/history.js.map +1 -0
- package/build/cjs/index.js +86 -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 -16
- 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 +1267 -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/{packages/router-core/src/utils.js → utils.js} +69 -64
- package/build/cjs/utils.js.map +1 -0
- package/build/esm/index.js +1746 -2121
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +59 -49
- package/build/stats-react.json +197 -211
- package/build/types/defer.d.ts +19 -0
- package/build/types/fileRoute.d.ts +35 -0
- package/build/types/history.d.ts +36 -0
- package/build/types/index.d.ts +13 -609
- 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 +251 -0
- package/build/types/routeInfo.d.ts +22 -0
- package/build/types/router.d.ts +260 -0
- package/build/types/scroll-restoration.d.ts +6 -0
- package/build/types/searchParams.d.ts +5 -0
- package/build/types/utils.d.ts +44 -0
- package/build/umd/index.development.js +1978 -2243
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +13 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +11 -7
- package/src/defer.ts +55 -0
- package/src/fileRoute.ts +161 -0
- package/src/history.ts +300 -0
- package/src/index.ts +5 -10
- package/src/link.ts +136 -125
- package/src/path.ts +37 -17
- package/src/qss.ts +1 -2
- package/src/route.ts +948 -218
- package/src/routeInfo.ts +45 -211
- package/src/router.ts +1778 -1075
- package/src/scroll-restoration.ts +179 -0
- package/src/searchParams.ts +31 -9
- package/src/utils.ts +84 -49
- 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 -147
- 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 -220
- package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
- package/build/cjs/packages/router-core/src/router.js +0 -870
- 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/src/frameworks.ts +0 -11
- package/src/routeConfig.ts +0 -511
- package/src/routeMatch.ts +0 -312
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* router-core
|
|
2
|
+
* @tanstack/router-core/src/index.ts
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) TanStack
|
|
5
5
|
*
|
|
@@ -31,8 +31,8 @@ function trimPath(path) {
|
|
|
31
31
|
return trimPathRight(trimPathLeft(path));
|
|
32
32
|
}
|
|
33
33
|
function resolvePath(basepath, base, to) {
|
|
34
|
-
base = base.replace(new RegExp(
|
|
35
|
-
to = to.replace(new RegExp(
|
|
34
|
+
base = base.replace(new RegExp(`^${basepath}`), '/');
|
|
35
|
+
to = to.replace(new RegExp(`^${basepath}`), '/');
|
|
36
36
|
let baseSegments = parsePathname(base);
|
|
37
37
|
const toSegments = parsePathname(to);
|
|
38
38
|
toSegments.forEach((toSegment, index) => {
|
|
@@ -45,13 +45,10 @@ function resolvePath(basepath, base, to) {
|
|
|
45
45
|
baseSegments.push(toSegment);
|
|
46
46
|
} else ;
|
|
47
47
|
} else if (toSegment.value === '..') {
|
|
48
|
-
var _last;
|
|
49
|
-
|
|
50
48
|
// Extra trailing slash? pop it off
|
|
51
|
-
if (baseSegments.length > 1 &&
|
|
49
|
+
if (baseSegments.length > 1 && utils.last(baseSegments)?.value === '/') {
|
|
52
50
|
baseSegments.pop();
|
|
53
51
|
}
|
|
54
|
-
|
|
55
52
|
baseSegments.pop();
|
|
56
53
|
} else if (toSegment.value === '.') {
|
|
57
54
|
return;
|
|
@@ -66,10 +63,8 @@ function parsePathname(pathname) {
|
|
|
66
63
|
if (!pathname) {
|
|
67
64
|
return [];
|
|
68
65
|
}
|
|
69
|
-
|
|
70
66
|
pathname = cleanPath(pathname);
|
|
71
67
|
const segments = [];
|
|
72
|
-
|
|
73
68
|
if (pathname.slice(0, 1) === '/') {
|
|
74
69
|
pathname = pathname.substring(1);
|
|
75
70
|
segments.push({
|
|
@@ -77,34 +72,30 @@ function parsePathname(pathname) {
|
|
|
77
72
|
value: '/'
|
|
78
73
|
});
|
|
79
74
|
}
|
|
80
|
-
|
|
81
75
|
if (!pathname) {
|
|
82
76
|
return segments;
|
|
83
|
-
}
|
|
84
|
-
|
|
77
|
+
}
|
|
85
78
|
|
|
79
|
+
// Remove empty segments and '.' segments
|
|
86
80
|
const split = pathname.split('/').filter(Boolean);
|
|
87
81
|
segments.push(...split.map(part => {
|
|
88
|
-
if (part
|
|
82
|
+
if (part === '$' || part === '*') {
|
|
89
83
|
return {
|
|
90
84
|
type: 'wildcard',
|
|
91
85
|
value: part
|
|
92
86
|
};
|
|
93
87
|
}
|
|
94
|
-
|
|
95
|
-
if (part.charAt(0) === ':') {
|
|
88
|
+
if (part.charAt(0) === '$') {
|
|
96
89
|
return {
|
|
97
90
|
type: 'param',
|
|
98
91
|
value: part
|
|
99
92
|
};
|
|
100
93
|
}
|
|
101
|
-
|
|
102
94
|
return {
|
|
103
95
|
type: 'pathname',
|
|
104
96
|
value: part
|
|
105
97
|
};
|
|
106
98
|
}));
|
|
107
|
-
|
|
108
99
|
if (pathname.slice(-1) === '/') {
|
|
109
100
|
pathname = pathname.substring(1);
|
|
110
101
|
segments.push({
|
|
@@ -112,66 +103,70 @@ function parsePathname(pathname) {
|
|
|
112
103
|
value: '/'
|
|
113
104
|
});
|
|
114
105
|
}
|
|
115
|
-
|
|
116
106
|
return segments;
|
|
117
107
|
}
|
|
118
|
-
function interpolatePath(path, params,
|
|
108
|
+
function interpolatePath(path, params, leaveWildcards = false) {
|
|
119
109
|
const interpolatedPathSegments = parsePathname(path);
|
|
120
110
|
return joinPaths(interpolatedPathSegments.map(segment => {
|
|
121
|
-
if (segment.
|
|
122
|
-
|
|
111
|
+
if (segment.type === 'wildcard') {
|
|
112
|
+
const value = params[segment.value];
|
|
113
|
+
if (leaveWildcards) return `${segment.value}${value ?? ''}`;
|
|
114
|
+
return value;
|
|
123
115
|
}
|
|
124
|
-
|
|
125
116
|
if (segment.type === 'param') {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return (_segment$value$substr = params[segment.value.substring(1)]) != null ? _segment$value$substr : '';
|
|
117
|
+
return params[segment.value.substring(1)] ?? '';
|
|
129
118
|
}
|
|
130
|
-
|
|
131
119
|
return segment.value;
|
|
132
120
|
}));
|
|
133
121
|
}
|
|
134
|
-
function matchPathname(currentPathname, matchLocation) {
|
|
135
|
-
const pathParams = matchByPath(currentPathname, matchLocation);
|
|
122
|
+
function matchPathname(basepath, currentPathname, matchLocation) {
|
|
123
|
+
const pathParams = matchByPath(basepath, currentPathname, matchLocation);
|
|
124
|
+
// const searchMatched = matchBySearch(location.search, matchLocation)
|
|
136
125
|
|
|
137
126
|
if (matchLocation.to && !pathParams) {
|
|
138
127
|
return;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// }
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return pathParams != null ? pathParams : {};
|
|
128
|
+
}
|
|
129
|
+
return pathParams ?? {};
|
|
145
130
|
}
|
|
146
|
-
function matchByPath(from, matchLocation) {
|
|
147
|
-
|
|
148
|
-
|
|
131
|
+
function matchByPath(basepath, from, matchLocation) {
|
|
132
|
+
// Remove the base path from the pathname
|
|
133
|
+
from = basepath != '/' ? from.substring(basepath.length) : from;
|
|
134
|
+
// Default to to $ (wildcard)
|
|
135
|
+
const to = `${matchLocation.to ?? '$'}`;
|
|
136
|
+
// Parse the from and to
|
|
149
137
|
const baseSegments = parsePathname(from);
|
|
150
|
-
const routeSegments = parsePathname(
|
|
138
|
+
const routeSegments = parsePathname(to);
|
|
139
|
+
if (!from.startsWith('/')) {
|
|
140
|
+
baseSegments.unshift({
|
|
141
|
+
type: 'pathname',
|
|
142
|
+
value: '/'
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
if (!to.startsWith('/')) {
|
|
146
|
+
routeSegments.unshift({
|
|
147
|
+
type: 'pathname',
|
|
148
|
+
value: '/'
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
151
|
const params = {};
|
|
152
|
-
|
|
153
152
|
let isMatch = (() => {
|
|
154
153
|
for (let i = 0; i < Math.max(baseSegments.length, routeSegments.length); i++) {
|
|
155
154
|
const baseSegment = baseSegments[i];
|
|
156
155
|
const routeSegment = routeSegments[i];
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
|
|
156
|
+
const isLastBaseSegment = i >= baseSegments.length - 1;
|
|
157
|
+
const isLastRouteSegment = i >= routeSegments.length - 1;
|
|
160
158
|
if (routeSegment) {
|
|
161
159
|
if (routeSegment.type === 'wildcard') {
|
|
162
|
-
if (baseSegment
|
|
160
|
+
if (baseSegment?.value) {
|
|
163
161
|
params['*'] = joinPaths(baseSegments.slice(i).map(d => d.value));
|
|
164
162
|
return true;
|
|
165
163
|
}
|
|
166
|
-
|
|
167
164
|
return false;
|
|
168
165
|
}
|
|
169
|
-
|
|
170
166
|
if (routeSegment.type === 'pathname') {
|
|
171
|
-
if (routeSegment.value === '/' && !
|
|
167
|
+
if (routeSegment.value === '/' && !baseSegment?.value) {
|
|
172
168
|
return true;
|
|
173
169
|
}
|
|
174
|
-
|
|
175
170
|
if (baseSegment) {
|
|
176
171
|
if (matchLocation.caseSensitive) {
|
|
177
172
|
if (routeSegment.value !== baseSegment.value) {
|
|
@@ -182,30 +177,24 @@ function matchByPath(from, matchLocation) {
|
|
|
182
177
|
}
|
|
183
178
|
}
|
|
184
179
|
}
|
|
185
|
-
|
|
186
180
|
if (!baseSegment) {
|
|
187
181
|
return false;
|
|
188
182
|
}
|
|
189
|
-
|
|
190
183
|
if (routeSegment.type === 'param') {
|
|
191
|
-
if (
|
|
184
|
+
if (baseSegment?.value === '/') {
|
|
192
185
|
return false;
|
|
193
186
|
}
|
|
194
|
-
|
|
195
|
-
if (!baseSegment.value.startsWith(':')) {
|
|
187
|
+
if (baseSegment.value.charAt(0) !== '$') {
|
|
196
188
|
params[routeSegment.value.substring(1)] = baseSegment.value;
|
|
197
189
|
}
|
|
198
190
|
}
|
|
199
191
|
}
|
|
200
|
-
|
|
201
|
-
if (isLastRouteSegment && !isLastBaseSegment) {
|
|
192
|
+
if (!isLastBaseSegment && isLastRouteSegment) {
|
|
202
193
|
return !!matchLocation.fuzzy;
|
|
203
194
|
}
|
|
204
195
|
}
|
|
205
|
-
|
|
206
196
|
return true;
|
|
207
197
|
})();
|
|
208
|
-
|
|
209
198
|
return isMatch ? params : undefined;
|
|
210
199
|
}
|
|
211
200
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.js","sources":["../../src/path.ts"],"sourcesContent":["import { AnyPathParams } from './route'\nimport { MatchLocation } from './router'\nimport { last } from './utils'\n\nexport interface Segment {\n type: 'pathname' | 'param' | 'wildcard'\n value: string\n}\n\nexport function joinPaths(paths: (string | undefined)[]) {\n return cleanPath(paths.filter(Boolean).join('/'))\n}\n\nexport function cleanPath(path: string) {\n // remove double slashes\n return path.replace(/\\/{2,}/g, '/')\n}\n\nexport function trimPathLeft(path: string) {\n return path === '/' ? path : path.replace(/^\\/{1,}/, '')\n}\n\nexport function trimPathRight(path: string) {\n return path === '/' ? path : path.replace(/\\/{1,}$/, '')\n}\n\nexport function trimPath(path: string) {\n return trimPathRight(trimPathLeft(path))\n}\n\nexport function resolvePath(basepath: string, base: string, to: string) {\n base = base.replace(new RegExp(`^${basepath}`), '/')\n to = to.replace(new RegExp(`^${basepath}`), '/')\n\n let baseSegments = parsePathname(base)\n const toSegments = parsePathname(to)\n\n toSegments.forEach((toSegment, index) => {\n if (toSegment.value === '/') {\n if (!index) {\n // Leading slash\n baseSegments = [toSegment]\n } else if (index === toSegments.length - 1) {\n // Trailing Slash\n baseSegments.push(toSegment)\n } else {\n // ignore inter-slashes\n }\n } else if (toSegment.value === '..') {\n // Extra trailing slash? pop it off\n if (baseSegments.length > 1 && last(baseSegments)?.value === '/') {\n baseSegments.pop()\n }\n baseSegments.pop()\n } else if (toSegment.value === '.') {\n return\n } else {\n baseSegments.push(toSegment)\n }\n })\n\n const joined = joinPaths([basepath, ...baseSegments.map((d) => d.value)])\n\n return cleanPath(joined)\n}\n\nexport function parsePathname(pathname?: string): Segment[] {\n if (!pathname) {\n return []\n }\n\n pathname = cleanPath(pathname)\n\n const segments: Segment[] = []\n\n if (pathname.slice(0, 1) === '/') {\n pathname = pathname.substring(1)\n segments.push({\n type: 'pathname',\n value: '/',\n })\n }\n\n if (!pathname) {\n return segments\n }\n\n // Remove empty segments and '.' segments\n const split = pathname.split('/').filter(Boolean)\n\n segments.push(\n ...split.map((part): Segment => {\n if (part === '$' || part === '*') {\n return {\n type: 'wildcard',\n value: part,\n }\n }\n\n if (part.charAt(0) === '$') {\n return {\n type: 'param',\n value: part,\n }\n }\n\n return {\n type: 'pathname',\n value: part,\n }\n }),\n )\n\n if (pathname.slice(-1) === '/') {\n pathname = pathname.substring(1)\n segments.push({\n type: 'pathname',\n value: '/',\n })\n }\n\n return segments\n}\n\nexport function interpolatePath(\n path: string | undefined,\n params: any,\n leaveWildcards: boolean = false,\n) {\n const interpolatedPathSegments = parsePathname(path)\n\n return joinPaths(\n interpolatedPathSegments.map((segment) => {\n if (segment.type === 'wildcard') {\n const value = params[segment.value]\n if (leaveWildcards) return `${segment.value}${value ?? ''}`\n return value\n }\n\n if (segment.type === 'param') {\n return params![segment.value.substring(1)] ?? ''\n }\n\n return segment.value\n }),\n )\n}\n\nexport function matchPathname(\n basepath: string,\n currentPathname: string,\n matchLocation: Pick<MatchLocation, 'to' | 'fuzzy' | 'caseSensitive'>,\n): AnyPathParams | undefined {\n const pathParams = matchByPath(basepath, currentPathname, matchLocation)\n // const searchMatched = matchBySearch(location.search, matchLocation)\n\n if (matchLocation.to && !pathParams) {\n return\n }\n\n return pathParams ?? {}\n}\n\nexport function matchByPath(\n basepath: string,\n from: string,\n matchLocation: Pick<MatchLocation, 'to' | 'caseSensitive' | 'fuzzy'>,\n): Record<string, string> | undefined {\n // Remove the base path from the pathname\n from = basepath != '/' ? from.substring(basepath.length) : from\n // Default to to $ (wildcard)\n const to = `${matchLocation.to ?? '$'}`\n // Parse the from and to\n const baseSegments = parsePathname(from)\n const routeSegments = parsePathname(to)\n\n if (!from.startsWith('/')) {\n baseSegments.unshift({\n type: 'pathname',\n value: '/',\n })\n }\n\n if (!to.startsWith('/')) {\n routeSegments.unshift({\n type: 'pathname',\n value: '/',\n })\n }\n\n const params: Record<string, string> = {}\n\n let isMatch = (() => {\n for (\n let i = 0;\n i < Math.max(baseSegments.length, routeSegments.length);\n i++\n ) {\n const baseSegment = baseSegments[i]\n const routeSegment = routeSegments[i]\n\n const isLastBaseSegment = i >= baseSegments.length - 1\n const isLastRouteSegment = i >= routeSegments.length - 1\n\n if (routeSegment) {\n if (routeSegment.type === 'wildcard') {\n if (baseSegment?.value) {\n params['*'] = joinPaths(baseSegments.slice(i).map((d) => d.value))\n return true\n }\n return false\n }\n\n if (routeSegment.type === 'pathname') {\n if (routeSegment.value === '/' && !baseSegment?.value) {\n return true\n }\n\n if (baseSegment) {\n if (matchLocation.caseSensitive) {\n if (routeSegment.value !== baseSegment.value) {\n return false\n }\n } else if (\n routeSegment.value.toLowerCase() !==\n baseSegment.value.toLowerCase()\n ) {\n return false\n }\n }\n }\n\n if (!baseSegment) {\n return false\n }\n\n if (routeSegment.type === 'param') {\n if (baseSegment?.value === '/') {\n return false\n }\n if (baseSegment.value.charAt(0) !== '$') {\n params[routeSegment.value.substring(1)] = baseSegment.value\n }\n }\n }\n\n if (!isLastBaseSegment && isLastRouteSegment) {\n return !!matchLocation.fuzzy\n }\n }\n\n return true\n })()\n\n return isMatch ? (params as Record<string, string>) : undefined\n}\n"],"names":["joinPaths","paths","cleanPath","filter","Boolean","join","path","replace","trimPathLeft","trimPathRight","trimPath","resolvePath","basepath","base","to","RegExp","baseSegments","parsePathname","toSegments","forEach","toSegment","index","value","length","push","last","pop","joined","map","d","pathname","segments","slice","substring","type","split","part","charAt","interpolatePath","params","leaveWildcards","interpolatedPathSegments","segment","matchPathname","currentPathname","matchLocation","pathParams","matchByPath","from","routeSegments","startsWith","unshift","isMatch","i","Math","max","baseSegment","routeSegment","isLastBase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E;AAC9B,YAAA,OAAO,KAAK,CAAA;AACd,WAAA;UACA,IAAIkC,WAAW,CAAClC,KAAK,CAACe,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;AACvCE,YAAAA,MAAM,CAACkB,YAAY,CAACnC,KAAK,CAACW,SAAS,CAAC,CAAC,CAAC,CAAC,GAAGuB,WAAW,CAAClC,KAAK,CAAA;AAC7D,WAAA;AACF,SAAA;AACF,OAAA;AAEA,MAAA,IAAI,CAACoC,iBAAiB,IAAIC,kBAAkB,EAAE;AAC5C,QAAA,OAAO,CAAC,CAACd,aAAa,CAACiB,KAAK,CAAA;AAC9B,OAAA;AACF,KAAA;AAEA,IAAA,OAAO,IAAI,CAAA;AACb,GAAC,GAAG,CAAA;AAEJ,EAAA,OAAOV,OAAO,GAAIb,MAAM,GAA8BwB,SAAS,CAAA;AACjE;;;;;;;;;;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* router-core
|
|
2
|
+
* @tanstack/router-core/src/index.ts
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) TanStack
|
|
5
5
|
*
|
|
@@ -13,13 +13,14 @@
|
|
|
13
13
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
14
|
|
|
15
15
|
// @ts-nocheck
|
|
16
|
+
|
|
16
17
|
// qss has been slightly modified and inlined here for our use cases (and compression's sake). We've included it as a hard dependency for MIT license attribution.
|
|
18
|
+
|
|
17
19
|
function encode(obj, pfx) {
|
|
18
20
|
var k,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
i,
|
|
22
|
+
tmp,
|
|
23
|
+
str = '';
|
|
23
24
|
for (k in obj) {
|
|
24
25
|
if ((tmp = obj[k]) !== void 0) {
|
|
25
26
|
if (Array.isArray(tmp)) {
|
|
@@ -33,36 +34,29 @@ function encode(obj, pfx) {
|
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
|
-
|
|
37
37
|
return (pfx || '') + str;
|
|
38
38
|
}
|
|
39
|
-
|
|
40
39
|
function toValue(mix) {
|
|
41
40
|
if (!mix) return '';
|
|
42
41
|
var str = decodeURIComponent(mix);
|
|
43
42
|
if (str === 'false') return false;
|
|
44
43
|
if (str === 'true') return true;
|
|
45
|
-
|
|
46
|
-
return +str * 0 === 0 ? +str : str;
|
|
44
|
+
return +str * 0 === 0 && +str + '' === str ? +str : str;
|
|
47
45
|
}
|
|
48
|
-
|
|
49
46
|
function decode(str) {
|
|
50
47
|
var tmp,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
k,
|
|
49
|
+
out = {},
|
|
50
|
+
arr = str.split('&');
|
|
55
51
|
while (tmp = arr.shift()) {
|
|
56
52
|
tmp = tmp.split('=');
|
|
57
53
|
k = tmp.shift();
|
|
58
|
-
|
|
59
54
|
if (out[k] !== void 0) {
|
|
60
55
|
out[k] = [].concat(out[k], toValue(tmp.shift()));
|
|
61
56
|
} else {
|
|
62
57
|
out[k] = toValue(tmp.shift());
|
|
63
58
|
}
|
|
64
59
|
}
|
|
65
|
-
|
|
66
60
|
return out;
|
|
67
61
|
}
|
|
68
62
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qss.js","sources":["../../src/qss.ts"],"sourcesContent":["// @ts-nocheck\n\n// qss has been slightly modified and inlined here for our use cases (and compression's sake). We've included it as a hard dependency for MIT license attribution.\n\nexport function encode(obj, pfx?: string) {\n var k,\n i,\n tmp,\n str = ''\n\n for (k in obj) {\n if ((tmp = obj[k]) !== void 0) {\n if (Array.isArray(tmp)) {\n for (i = 0; i < tmp.length; i++) {\n str && (str += '&')\n str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp[i])\n }\n } else {\n str && (str += '&')\n str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp)\n }\n }\n }\n\n return (pfx || '') + str\n}\n\nfunction toValue(mix) {\n if (!mix) return ''\n var str = decodeURIComponent(mix)\n if (str === 'false') return false\n if (str === 'true') return true\n return +str * 0 === 0 && +str + '' === str ? +str : str\n}\n\nexport function decode(str) {\n var tmp,\n k,\n out = {},\n arr = str.split('&')\n\n while ((tmp = arr.shift())) {\n tmp = tmp.split('=')\n k = tmp.shift()\n if (out[k] !== void 0) {\n out[k] = [].concat(out[k], toValue(tmp.shift()))\n } else {\n out[k] = toValue(tmp.shift())\n }\n }\n\n return out\n}\n"],"names":["encode","obj","pfx","k","i","tmp","str","Array","isArray","length","encodeURIComponent","toValue","mix","decodeURIComponent","decode","out","arr","split","shift","concat"],"mappings":";;;;;;;;;;;;;;AAAA;;AAEA;;AAEO,SAASA,MAAMA,CAACC,GAAG,EAAEC,GAAY,EAAE;AACxC,EAAA,IAAIC,CAAC;IACHC,CAAC;IACDC,GAAG;AACHC,IAAAA,GAAG,GAAG,EAAE,CAAA;EAEV,KAAKH,CAAC,IAAIF,GAAG,EAAE;IACb,IAAI,CAACI,GAAG,GAAGJ,GAAG,CAACE,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;AAC7B,MAAA,IAAII,KAAK,CAACC,OAAO,CAACH,GAAG,CAAC,EAAE;AACtB,QAAA,KAAKD,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGC,GAAG,CAACI,MAAM,EAAEL,CAAC,EAAE,EAAE;AAC/BE,UAAAA,GAAG,KAAKA,GAAG,IAAI,GAAG,CAAC,CAAA;AACnBA,UAAAA,GAAG,IAAII,kBAAkB,CAACP,CAAC,CAAC,GAAG,GAAG,GAAGO,kBAAkB,CAACL,GAAG,CAACD,CAAC,CAAC,CAAC,CAAA;AACjE,SAAA;AACF,OAAC,MAAM;AACLE,QAAAA,GAAG,KAAKA,GAAG,IAAI,GAAG,CAAC,CAAA;QACnBA,GAAG,IAAII,kBAAkB,CAACP,CAAC,CAAC,GAAG,GAAG,GAAGO,kBAAkB,CAACL,GAAG,CAAC,CAAA;AAC9D,OAAA;AACF,KAAA;AACF,GAAA;AAEA,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,CAAA;AACZ;;;;;"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tanstack/router-core/src/index.ts
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) TanStack
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
+
|
|
15
|
+
var invariant = require('tiny-invariant');
|
|
16
|
+
var path = require('./path.js');
|
|
17
|
+
|
|
18
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
19
|
+
|
|
20
|
+
var invariant__default = /*#__PURE__*/_interopDefaultLegacy(invariant);
|
|
21
|
+
|
|
22
|
+
const rootRouteId = '__root__';
|
|
23
|
+
|
|
24
|
+
// The parse type here allows a zod schema to be passed directly to the validator
|
|
25
|
+
|
|
26
|
+
// T extends Record<PropertyKey, infer U>
|
|
27
|
+
// ? {
|
|
28
|
+
// [K in keyof T]: UseLoaderResultPromise<T[K]>
|
|
29
|
+
// }
|
|
30
|
+
// : UseLoaderResultPromise<T>
|
|
31
|
+
|
|
32
|
+
// export type UseLoaderResultPromise<T> = T extends Promise<infer U>
|
|
33
|
+
// ? StreamedPromise<U>
|
|
34
|
+
// : T
|
|
35
|
+
class Route {
|
|
36
|
+
// Set up in this.init()
|
|
37
|
+
|
|
38
|
+
// customId!: TCustomId
|
|
39
|
+
|
|
40
|
+
// Optional
|
|
41
|
+
|
|
42
|
+
constructor(options) {
|
|
43
|
+
this.options = options || {};
|
|
44
|
+
this.isRoot = !options?.getParentRoute;
|
|
45
|
+
Route.__onInit(this);
|
|
46
|
+
}
|
|
47
|
+
init = opts => {
|
|
48
|
+
this.originalIndex = opts.originalIndex;
|
|
49
|
+
this.router = opts.router;
|
|
50
|
+
const options = this.options;
|
|
51
|
+
const isRoot = !options?.path && !options?.id;
|
|
52
|
+
this.parentRoute = this.options?.getParentRoute?.();
|
|
53
|
+
if (isRoot) {
|
|
54
|
+
this.path = rootRouteId;
|
|
55
|
+
} else {
|
|
56
|
+
invariant__default["default"](this.parentRoute, `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`);
|
|
57
|
+
}
|
|
58
|
+
let path$1 = isRoot ? rootRouteId : options.path;
|
|
59
|
+
|
|
60
|
+
// If the path is anything other than an index path, trim it up
|
|
61
|
+
if (path$1 && path$1 !== '/') {
|
|
62
|
+
path$1 = path.trimPath(path$1);
|
|
63
|
+
}
|
|
64
|
+
const customId = options?.id || path$1;
|
|
65
|
+
|
|
66
|
+
// Strip the parentId prefix from the first level of children
|
|
67
|
+
let id = isRoot ? rootRouteId : path.joinPaths([this.parentRoute.id === rootRouteId ? '' : this.parentRoute.id, customId]);
|
|
68
|
+
if (path$1 === rootRouteId) {
|
|
69
|
+
path$1 = '/';
|
|
70
|
+
}
|
|
71
|
+
if (id !== rootRouteId) {
|
|
72
|
+
id = path.joinPaths(['/', id]);
|
|
73
|
+
}
|
|
74
|
+
const fullPath = id === rootRouteId ? '/' : path.joinPaths([this.parentRoute.fullPath, path$1]);
|
|
75
|
+
this.path = path$1;
|
|
76
|
+
this.id = id;
|
|
77
|
+
// this.customId = customId as TCustomId
|
|
78
|
+
this.fullPath = fullPath;
|
|
79
|
+
this.to = fullPath;
|
|
80
|
+
};
|
|
81
|
+
addChildren = children => {
|
|
82
|
+
this.children = children;
|
|
83
|
+
return this;
|
|
84
|
+
};
|
|
85
|
+
update = options => {
|
|
86
|
+
Object.assign(this.options, options);
|
|
87
|
+
return this;
|
|
88
|
+
};
|
|
89
|
+
static __onInit = route => {
|
|
90
|
+
// This is a dummy static method that should get
|
|
91
|
+
// replaced by a framework specific implementation if necessary
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
class RouterContext {
|
|
95
|
+
constructor() {}
|
|
96
|
+
createRootRoute = options => {
|
|
97
|
+
return new RootRoute(options);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
class RootRoute extends Route {
|
|
101
|
+
constructor(options) {
|
|
102
|
+
super(options);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function createRouteMask(opts) {
|
|
106
|
+
return opts;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
exports.RootRoute = RootRoute;
|
|
110
|
+
exports.Route = Route;
|
|
111
|
+
exports.RouterContext = RouterContext;
|
|
112
|
+
exports.createRouteMask = createRouteMask;
|
|
113
|
+
exports.rootRouteId = rootRouteId;
|
|
114
|
+
//# sourceMappingURL=route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.js","sources":["../../src/route.ts"],"sourcesContent":["import invariant from 'tiny-invariant'\nimport { RoutePaths } from './routeInfo'\nimport { joinPaths, trimPath } from './path'\nimport { AnyRouter, RouteMatch, AnyRouteMatch } from './router'\nimport {\n Expand,\n IsAny,\n NoInfer,\n PickRequired,\n UnionToIntersection,\n} from './utils'\nimport { ParsePathParams, ToSubOptions } from './link'\n\nexport const rootRouteId = '__root__' as const\nexport type RootRouteId = typeof rootRouteId\nexport type AnyPathParams = {}\nexport type AnySearchSchema = {}\nexport type AnyContext = {}\nexport interface RouteMeta {}\nexport interface RouteContext {}\nexport interface RegisterRouteComponent<\n TLoader = unknown,\n TFullSearchSchema extends AnySearchSchema = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends AnyContext = AnyContext,\n TAllContext extends AnyContext = AnyContext,\n> {\n // RouteComponent: unknown // This is registered by the framework\n}\nexport interface RegisterErrorRouteComponent<\n TFullSearchSchema extends AnySearchSchema = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends AnyContext = AnyContext,\n TAllContext extends AnyContext = AnyContext,\n> {\n // ErrorRouteComponent: unknown // This is registered by the framework\n}\nexport interface RegisterPendingRouteComponent<\n TFullSearchSchema extends AnySearchSchema = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends AnyContext = AnyContext,\n TAllContext extends AnyContext = AnyContext,\n> {\n // PendingRouteComponent: unknown // This is registered by the framework\n}\n\nexport interface RegisterRouteProps<\n TLoader = unknown,\n TFullSearchSchema extends AnySearchSchema = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends AnyContext = AnyContext,\n TAllContext extends AnyContext = AnyContext,\n> {\n // RouteProps: unknown // This is registered by the framework\n}\nexport interface RegisterErrorRouteProps<\n TFullSearchSchema extends AnySearchSchema = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends AnyContext = AnyContext,\n TAllContext extends AnyContext = AnyContext,\n> {\n // ErrorRouteProps: unknown // This is registered by the framework\n}\n\nexport interface RegisterPendingRouteProps<\n TFullSearchSchema extends AnySearchSchema = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends AnyContext = AnyContext,\n TAllContext extends AnyContext = AnyContext,\n> {\n // PendingRouteProps: unknown // This is registered by the framework\n}\n\nexport type RegisteredRouteComponent<\n TLoader = unknown,\n TFullSearchSchema extends AnySearchSchema = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends AnyContext = AnyContext,\n TAllContext extends AnyContext = AnyContext,\n> = RegisterRouteComponent<\n TLoader,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n> extends {\n RouteComponent: infer T\n}\n ? T\n : () => unknown\n\nexport type RegisteredErrorRouteComponent<\n TFullSearchSchema extends AnySearchSchema = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends AnyContext = AnyContext,\n TAllContext extends AnyContext = AnyContext,\n> = RegisterErrorRouteComponent<\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n> extends {\n ErrorRouteComponent: infer T\n}\n ? T\n : () => unknown\n\nexport type RegisteredPendingRouteComponent<\n TFullSearchSchema extends AnySearchSchema = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends AnyContext = AnyContext,\n TAllContext extends AnyContext = AnyContext,\n> = RegisterPendingRouteComponent<\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n> extends {\n PendingRouteComponent: infer T\n}\n ? T\n : () => unknown\n\nexport type RegisteredRouteProps<\n TLoader = unknown,\n TFullSearchSchema extends AnySearchSchema = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends AnyContext = AnyContext,\n TAllContext extends AnyContext = AnyContext,\n> = RegisterRouteProps<\n TLoader,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n> extends {\n RouteProps: infer T\n}\n ? T\n : {}\n\nexport type RegisteredErrorRouteProps<\n TFullSearchSchema extends AnySearchSchema = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends AnyContext = AnyContext,\n TAllContext extends AnyContext = AnyContext,\n> = RegisterRouteProps<\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n> extends {\n ErrorRouteProps: infer T\n}\n ? T\n : {}\n\nexport type RegisteredPendingRouteProps<\n TFullSearchSchema extends AnySearchSchema = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends AnyContext = AnyContext,\n TAllContext extends AnyContext = AnyContext,\n> = RegisterRouteProps<\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n> extends {\n PendingRouteProps: infer T\n}\n ? T\n : {}\n\nexport type PreloadableObj = { preload?: () => Promise<void> }\n\nexport type RoutePathOptions<TCustomId, TPath> =\n | {\n path: TPath\n }\n | {\n id: TCustomId\n }\n\nexport type RoutePathOptionsIntersection<TCustomId, TPath> =\n UnionToIntersection<RoutePathOptions<TCustomId, TPath>>\n\nexport type MetaOptions = keyof PickRequired<RouteMeta> extends never\n ? {\n meta?: RouteMeta\n }\n : {\n meta: RouteMeta\n }\n\nexport type AnyRouteProps = RegisteredRouteProps<any, any, any, any, any>\n\nexport type RouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TCustomId extends string = string,\n TPath extends string = string,\n TLoader = unknown,\n TParentSearchSchema extends AnySearchSchema = {},\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = TSearchSchema,\n TParams extends AnyPathParams = AnyPathParams,\n TAllParams extends AnyPathParams = TParams,\n TParentContext extends AnyContext = AnyContext,\n TAllParentContext extends AnyContext = AnyContext,\n TRouteContext extends RouteContext = RouteContext,\n TAllContext extends AnyContext = AnyContext,\n> = BaseRouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TLoader,\n TParentSearchSchema,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TParentContext,\n TAllParentContext,\n TRouteContext,\n TAllContext\n> &\n UpdatableRouteOptions<\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n >\n\nexport type ParamsFallback<\n TPath extends string,\n TParams,\n> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams\n\ntype Prefix<T extends string, U extends string> = U extends `${T}${infer _}`\n ? U\n : never\n\nexport type BaseRouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TCustomId extends string = string,\n TPath extends string = string,\n TLoader = unknown,\n TParentSearchSchema extends AnySearchSchema = {},\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = TSearchSchema,\n TParams extends AnyPathParams = {},\n TAllParams = ParamsFallback<TPath, TParams>,\n TParentContext extends AnyContext = AnyContext,\n TAllParentContext extends AnyContext = AnyContext,\n TRouteContext extends RouteContext = RouteContext,\n TAllContext extends AnyContext = AnyContext,\n> = RoutePathOptions<TCustomId, TPath> & {\n getParentRoute: () => TParentRoute\n validateSearch?: SearchSchemaValidator<TSearchSchema>\n loader?: LoaderFn<\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n NoInfer<TRouteContext>,\n TAllContext\n >\n} & (keyof PickRequired<RouteContext> extends never\n ? // This async function is called before a route is loaded.\n // If an error is thrown here, the route's loader will not be called.\n // If thrown during a navigation, the navigation will be cancelled and the error will be passed to the `onError` function.\n // If thrown during a preload event, the error will be logged to the console.\n {\n beforeLoad?: BeforeLoadFn<\n TParentRoute,\n TAllParams,\n TSearchSchema,\n TFullSearchSchema,\n TParentContext,\n TAllParentContext,\n TRouteContext\n >\n }\n : {\n beforeLoad: BeforeLoadFn<\n TParentRoute,\n TAllParams,\n TSearchSchema,\n TFullSearchSchema,\n TParentContext,\n TAllParentContext,\n TRouteContext\n >\n }) &\n ([TLoader] extends [never]\n ? {\n loader: 'Loaders must return a type other than never. If you are throwing a redirect() and not returning anything, return a redirect() instead.'\n }\n : {}) &\n (\n | {\n // Both or none\n parseParams?: (\n rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,\n ) => TParams extends Record<ParsePathParams<TPath>, any>\n ? TParams\n : 'parseParams must return an object'\n stringifyParams?: (\n params: NoInfer<ParamsFallback<TPath, TParams>>,\n ) => Record<ParsePathParams<TPath>, string>\n }\n | {\n stringifyParams?: never\n parseParams?: never\n }\n )\n\ntype BeforeLoadFn<\n TParentRoute,\n TAllParams,\n TSearchSchema,\n TFullSearchSchema,\n TParentContext,\n TAllParentContext,\n TRouteContext,\n> = (\n opts: {\n params: TAllParams\n routeSearch: TSearchSchema\n search: TFullSearchSchema\n abortController: AbortController\n preload: boolean\n } & (TParentRoute extends undefined\n ? {\n context?: TAllParentContext\n parentContext?: TParentContext\n }\n : {\n context: TAllParentContext\n parentContext: TParentContext\n }),\n) => Promise<TRouteContext> | TRouteContext | void\n\nexport type UpdatableRouteOptions<\n TLoader,\n TSearchSchema extends AnySearchSchema,\n TFullSearchSchema extends AnySearchSchema,\n TAllParams extends AnyPathParams,\n TRouteContext extends AnyContext,\n TAllContext extends AnyContext,\n> = MetaOptions & {\n key?: null | false | GetKeyFn<TFullSearchSchema, TAllParams>\n // If true, this route will be matched as case-sensitive\n caseSensitive?: boolean\n // If true, this route will be forcefully wrapped in a suspense boundary\n wrapInSuspense?: boolean\n // The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`\n component?: RegisteredRouteComponent<\n TLoader,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n >\n // The content to be rendered when the route encounters an error\n errorComponent?: RegisteredErrorRouteComponent<\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n > //\n // If supported by your framework, the content to be rendered as the fallback content until the route is ready to render\n pendingComponent?: RegisteredPendingRouteComponent<\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n >\n // Filter functions that can manipulate search params *before* they are passed to links and navigate\n // calls that match this route.\n preSearchFilters?: SearchFilter<TFullSearchSchema>[]\n // Filter functions that can manipulate search params *after* they are passed to links and navigate\n // calls that match this route.\n postSearchFilters?: SearchFilter<TFullSearchSchema>[]\n // If set, preload matches of this route will be considered fresh for this many milliseconds.\n preloadMaxAge?: number\n // If set, a match of this route will be considered fresh for this many milliseconds.\n maxAge?: number\n // If set, a match of this route that becomes inactive (or unused) will be garbage collected after this many milliseconds\n gcMaxAge?: number\n onError?: (err: any) => void\n // These functions are called as route matches are loaded, stick around and leave the active\n // matches\n onEnter?: (match: AnyRouteMatch) => void\n onTransition?: (match: AnyRouteMatch) => void\n onLeave?: (match: AnyRouteMatch) => void\n // Set this to true or false to specifically set whether or not this route should be preloaded. If unset, will\n // default to router.options.reloadOnWindowFocus\n reloadOnWindowFocus?: boolean\n}\n\nexport type ParseParamsOption<TPath extends string, TParams> = ParseParamsFn<\n TPath,\n TParams\n>\n\nexport type ParseParamsFn<TPath extends string, TParams> = (\n rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,\n) => TParams extends Record<ParsePathParams<TPath>, any>\n ? TParams\n : 'parseParams must return an object'\n\nexport type ParseParamsObj<TPath extends string, TParams> = {\n parse?: ParseParamsFn<TPath, TParams>\n}\n\n// The parse type here allows a zod schema to be passed directly to the validator\nexport type SearchSchemaValidator<TReturn> =\n | SearchSchemaValidatorObj<TReturn>\n | SearchSchemaValidatorFn<TReturn>\n\nexport type SearchSchemaValidatorObj<TReturn> = {\n parse?: SearchSchemaValidatorFn<TReturn>\n}\n\nexport type SearchSchemaValidatorFn<TReturn> = (\n searchObj: Record<string, unknown>,\n) => TReturn\n\nexport type DefinedPathParamWarning =\n 'Path params cannot be redefined by child routes!'\n\nexport type ParentParams<TParentParams> = AnyPathParams extends TParentParams\n ? {}\n : {\n [Key in keyof TParentParams]?: DefinedPathParamWarning\n }\n\nexport type LoaderFn<\n TLoader = unknown,\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = {},\n TAllParams = {},\n TContext extends AnyContext = AnyContext,\n TAllContext extends AnyContext = AnyContext,\n> = (\n match: LoaderContext<\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n TContext,\n TAllContext\n > & {\n parentMatchPromise?: Promise<void>\n },\n) => Promise<TLoader> | TLoader\n\nexport type GetKeyFn<\n TFullSearchSchema extends AnySearchSchema = {},\n TAllParams = {},\n> = (loaderContext: { params: TAllParams; search: TFullSearchSchema }) => any\n\nexport interface LoaderContext<\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = {},\n TAllParams = {},\n TContext extends AnyContext = AnyContext,\n TAllContext extends AnyContext = AnyContext,\n> {\n params: TAllParams\n routeSearch: TSearchSchema\n search: TFullSearchSchema\n abortController: AbortController\n preload: boolean\n routeContext: TContext\n context: TAllContext\n}\n\nexport type UnloaderFn<TPath extends string> = (\n routeMatch: RouteMatch<any, Route>,\n) => void\n\nexport type SearchFilter<T, U = T> = (prev: T) => U\n\nexport type ResolveId<\n TParentRoute,\n TCustomId extends string,\n TPath extends string,\n> = TParentRoute extends { id: infer TParentId extends string }\n ? RoutePrefix<TParentId, string extends TCustomId ? TPath : TCustomId>\n : RootRouteId\n\nexport type InferFullSearchSchema<TRoute> = TRoute extends {\n isRoot: true\n types: {\n searchSchema: infer TSearchSchema\n }\n}\n ? TSearchSchema\n : TRoute extends {\n types: {\n fullSearchSchema: infer TFullSearchSchema\n }\n }\n ? TFullSearchSchema\n : {}\n\nexport type ResolveFullSearchSchema<TParentRoute, TSearchSchema> =\n InferFullSearchSchema<TParentRoute> & TSearchSchema\n\nexport interface AnyRoute\n extends Route<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > {}\n\nexport type MergeFromFromParent<T, U> = IsAny<T, U, T & U>\n\nexport type UseLoaderResult<T> = T\n// T extends Record<PropertyKey, infer U>\n// ? {\n// [K in keyof T]: UseLoaderResultPromise<T[K]>\n// }\n// : UseLoaderResultPromise<T>\n\n// export type UseLoaderResultPromise<T> = T extends Promise<infer U>\n// ? StreamedPromise<U>\n// : T\n\nexport type StreamedPromise<T> = {\n promise: Promise<T>\n status: 'resolved' | 'pending'\n data: T\n resolve: (value: T) => void\n}\n\nexport type ResolveAllParams<\n TParentRoute extends AnyRoute,\n TParams extends AnyPathParams,\n> = Record<never, string> extends TParentRoute['types']['allParams']\n ? TParams\n : Expand<\n UnionToIntersection<TParentRoute['types']['allParams'] & TParams> & {}\n >\n\nexport type RouteConstraints = {\n TParentRoute: AnyRoute\n TPath: string\n TFullPath: string\n TCustomId: string\n TId: string\n TSearchSchema: AnySearchSchema\n TFullSearchSchema: AnySearchSchema\n TParams: Record<string, any>\n TAllParams: Record<string, any>\n TParentContext: AnyContext\n TAllParentContext: AnyContext\n TRouteContext: RouteContext\n TAllContext: AnyContext\n TRouterContext: AnyContext\n TChildren: unknown\n TRouteTree: AnyRoute\n}\n\nexport class Route<\n TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,\n TPath extends RouteConstraints['TPath'] = '/',\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n TPath\n >,\n TCustomId extends RouteConstraints['TCustomId'] = string,\n TId extends RouteConstraints['TId'] = ResolveId<\n TParentRoute,\n TCustomId,\n TPath\n >,\n TLoader = unknown,\n TSearchSchema extends RouteConstraints['TSearchSchema'] = {},\n TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<\n TParentRoute,\n TSearchSchema\n >,\n TParams extends RouteConstraints['TParams'] = Expand<\n Record<ParsePathParams<TPath>, string>\n >,\n TAllParams extends RouteConstraints['TAllParams'] = ResolveAllParams<\n TParentRoute,\n TParams\n >,\n TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['types']['routeContext'],\n TAllParentContext extends RouteConstraints['TAllParentContext'] = TParentRoute['types']['context'],\n TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,\n TAllContext extends RouteConstraints['TAllContext'] = MergeFromFromParent<\n TParentRoute['types']['context'],\n TRouteContext\n >,\n TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,\n TChildren extends RouteConstraints['TChildren'] = unknown,\n TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,\n> {\n types!: {\n parentRoute: TParentRoute\n path: TPath\n to: TrimPathRight<TFullPath>\n fullPath: TFullPath\n customId: TCustomId\n id: TId\n loader: TLoader\n searchSchema: TSearchSchema\n fullSearchSchema: TFullSearchSchema\n params: TParams\n allParams: TAllParams\n parentContext: TParentContext\n allParentContext: TAllParentContext\n routeContext: TRouteContext\n context: TAllContext\n children: TChildren\n routeTree: TRouteTree\n routerContext: TRouterContext\n }\n isRoot: TParentRoute extends Route<any> ? true : false\n options: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TLoader,\n InferFullSearchSchema<TParentRoute>,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TParentContext,\n TAllParentContext,\n TRouteContext,\n TAllContext\n >\n\n // Set up in this.init()\n parentRoute!: TParentRoute\n id!: TId\n // customId!: TCustomId\n path!: TPath\n fullPath!: TFullPath\n to!: TrimPathRight<TFullPath>\n\n // Optional\n children?: TChildren\n originalIndex?: number\n router?: AnyRouter\n rank!: number\n\n constructor(\n options: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TLoader,\n InferFullSearchSchema<TParentRoute>,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TParentContext,\n TAllParentContext,\n TRouteContext,\n TAllContext\n > &\n UpdatableRouteOptions<\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n >,\n ) {\n this.options = (options as any) || {}\n this.isRoot = !options?.getParentRoute as any\n Route.__onInit(this)\n }\n\n init = (opts: { originalIndex: number; router: AnyRouter }) => {\n this.originalIndex = opts.originalIndex\n this.router = opts.router\n\n const options = this.options as RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n InferFullSearchSchema<TParentRoute>,\n TSearchSchema,\n TParams\n > &\n RoutePathOptionsIntersection<TCustomId, TPath>\n\n const isRoot = !options?.path && !options?.id\n\n this.parentRoute = this.options?.getParentRoute?.()\n\n if (isRoot) {\n this.path = rootRouteId as TPath\n } else {\n invariant(\n this.parentRoute,\n `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`,\n )\n }\n\n let path: undefined | string = isRoot ? rootRouteId : options.path\n\n // If the path is anything other than an index path, trim it up\n if (path && path !== '/') {\n path = trimPath(path)\n }\n\n const customId = options?.id || path\n\n // Strip the parentId prefix from the first level of children\n let id = isRoot\n ? rootRouteId\n : joinPaths([\n (this.parentRoute.id as any) === rootRouteId\n ? ''\n : this.parentRoute.id,\n customId,\n ])\n\n if (path === rootRouteId) {\n path = '/'\n }\n\n if (id !== rootRouteId) {\n id = joinPaths(['/', id])\n }\n\n const fullPath =\n id === rootRouteId ? '/' : joinPaths([this.parentRoute.fullPath, path])\n\n this.path = path as TPath\n this.id = id as TId\n // this.customId = customId as TCustomId\n this.fullPath = fullPath as TFullPath\n this.to = fullPath as TrimPathRight<TFullPath>\n }\n\n addChildren = <TNewChildren extends AnyRoute[]>(\n children: TNewChildren,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TParentContext,\n TAllParentContext,\n TRouteContext,\n TAllContext,\n TRouterContext,\n TNewChildren,\n TRouteTree\n > => {\n this.children = children as any\n return this as any\n }\n\n update = (\n options: UpdatableRouteOptions<\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n >,\n ) => {\n Object.assign(this.options, options)\n return this\n }\n\n static __onInit = (route: any) => {\n // This is a dummy static method that should get\n // replaced by a framework specific implementation if necessary\n }\n}\n\nexport type AnyRootRoute = RootRoute<any, any, any, any>\n\nexport class RouterContext<TRouterContext extends {}> {\n constructor() {}\n\n createRootRoute = <\n TLoader = unknown,\n TSearchSchema extends AnySearchSchema = {},\n TRouteContext extends RouteContext = RouteContext,\n >(\n options?: Omit<\n RouteOptions<\n AnyRoute,\n RootRouteId,\n '',\n TLoader,\n TSearchSchema,\n TSearchSchema,\n TSearchSchema,\n {},\n {},\n TRouterContext,\n TRouterContext,\n TRouteContext,\n MergeFromFromParent<TRouterContext, TRouteContext>\n >,\n | 'path'\n | 'id'\n | 'getParentRoute'\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n >,\n ): RootRoute<TLoader, TSearchSchema, TRouteContext, TRouterContext> => {\n return new RootRoute(options) as any\n }\n}\n\nexport class RootRoute<\n TLoader = unknown,\n TSearchSchema extends AnySearchSchema = {},\n TRouteContext extends RouteContext = RouteContext,\n TRouterContext extends {} = {},\n> extends Route<\n any,\n '/',\n '/',\n string,\n RootRouteId,\n TLoader,\n TSearchSchema,\n TSearchSchema,\n {},\n {},\n TRouterContext,\n TRouterContext,\n TRouteContext,\n MergeFromFromParent<TRouterContext, TRouteContext>,\n TRouterContext,\n any,\n any\n> {\n constructor(\n options?: Omit<\n RouteOptions<\n AnyRoute,\n RootRouteId,\n '',\n TLoader,\n TSearchSchema,\n TSearchSchema,\n TSearchSchema,\n {},\n {},\n TRouterContext,\n TRouterContext,\n TRouteContext,\n MergeFromFromParent<TRouterContext, TRouteContext>\n >,\n | 'path'\n | 'id'\n | 'getParentRoute'\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n >,\n ) {\n super(options as any)\n }\n}\n\nexport type ResolveFullPath<\n TParentRoute extends AnyRoute,\n TPath extends string,\n TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>,\n> = TPrefixed extends RootRouteId ? '/' : TPrefixed\n\ntype RoutePrefix<\n TPrefix extends string,\n TPath extends string,\n> = string extends TPath\n ? RootRouteId\n : TPath extends string\n ? TPrefix extends RootRouteId\n ? TPath extends '/'\n ? '/'\n : `/${TrimPath<TPath>}`\n : `${TPrefix}/${TPath}` extends '/'\n ? '/'\n : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}`\n : never\n\nexport type TrimPath<T extends string> = '' extends T\n ? ''\n : TrimPathRight<TrimPathLeft<T>>\n\nexport type TrimPathLeft<T extends string> =\n T extends `${RootRouteId}/${infer U}`\n ? TrimPathLeft<U>\n : T extends `/${infer U}`\n ? TrimPathLeft<U>\n : T\nexport type TrimPathRight<T extends string> = T extends '/'\n ? '/'\n : T extends `${infer U}/`\n ? TrimPathRight<U>\n : T\n\nexport type RouteMask<TRouteTree extends AnyRoute> = {\n routeTree: TRouteTree\n from: RoutePaths<TRouteTree>\n to?: any\n params?: any\n search?: any\n hash?: any\n state?: any\n unmaskOnReload?: boolean\n}\n\nexport function createRouteMask<\n TRouteTree extends AnyRoute,\n TFrom extends RoutePaths<TRouteTree>,\n TTo extends string,\n>(\n opts: {\n routeTree: TRouteTree\n } & ToSubOptions<TRouteTree, TFrom, TTo>,\n): RouteMask<TRouteTree> {\n return opts as any\n}\n"],"names":["rootRouteId","Route","constructor","options","isRoot","getParentRoute","__onInit","init","opts","originalIndex","router","path","id","parentRoute","invariant","trimPath","customId","joinPaths","fullPath","to","addChildren","children","update","Object","assign","route","RouterContext","createRootRoute","RootRoute","createRouteMask"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAaO,MAAMA,WAAW,GAAG,WAAmB;;AAoZ9C;;AAsHA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AAqCO,MAAMC,KAAK,CAoChB;AAsCA;;AAGA;;AAKA;;EAMAC,WAAWA,CACTC,OAsBG,EACH;AACA,IAAA,IAAI,CAACA,OAAO,GAAIA,OAAO,IAAY,EAAE,CAAA;AACrC,IAAA,IAAI,CAACC,MAAM,GAAG,CAACD,OAAO,EAAEE,cAAqB,CAAA;AAC7CJ,IAAAA,KAAK,CAACK,QAAQ,CAAC,IAAI,CAAC,CAAA;AACtB,GAAA;EAEAC,IAAI,GAAIC,IAAkD,IAAK;AAC7D,IAAA,IAAI,CAACC,aAAa,GAAGD,IAAI,CAACC,aAAa,CAAA;AACvC,IAAA,IAAI,CAACC,MAAM,GAAGF,IAAI,CAACE,MAAM,CAAA;AAEzB,IAAA,MAAMP,OAAO,GAAG,IAAI,CAACA,OAQ2B,CAAA;IAEhD,MAAMC,MAAM,GAAG,CAACD,OAAO,EAAEQ,IAAI,IAAI,CAACR,OAAO,EAAES,EAAE,CAAA;IAE7C,IAAI,CAACC,WAAW,GAAG,IAAI,CAACV,OAAO,EAAEE,cAAc,IAAI,CAAA;AAEnD,IAAA,IAAID,MAAM,EAAE;MACV,IAAI,CAACO,IAAI,GAAGX,WAAoB,CAAA;AAClC,KAAC,MAAM;AACLc,MAAAA,6BAAS,CACP,IAAI,CAACD,WAAW,EACf,6GACH,CAAC,CAAA;AACH,KAAA;IAEA,IAAIF,MAAwB,GAAGP,MAAM,GAAGJ,WAAW,GAAGG,OAAO,CAACQ,IAAI,CAAA;;AAElE;AACA,IAAA,IAAIA,MAAI,IAAIA,MAAI,K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