@tanstack/router-core 0.0.1-beta.41 → 0.0.1-beta.49
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/actions.js +94 -0
- package/build/cjs/actions.js.map +1 -0
- package/build/cjs/history.js +163 -0
- package/build/cjs/history.js.map +1 -0
- package/build/cjs/index.js +18 -20
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/interop.js +175 -0
- package/build/cjs/interop.js.map +1 -0
- package/build/cjs/path.js +4 -5
- package/build/cjs/path.js.map +1 -1
- package/build/cjs/route.js +16 -138
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/routeConfig.js +1 -7
- package/build/cjs/routeConfig.js.map +1 -1
- package/build/cjs/routeMatch.js +194 -199
- package/build/cjs/routeMatch.js.map +1 -1
- package/build/cjs/router.js +726 -703
- package/build/cjs/router.js.map +1 -1
- package/build/cjs/store.js +54 -0
- package/build/cjs/store.js.map +1 -0
- package/build/esm/index.js +1305 -1114
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +229 -192
- package/build/types/index.d.ts +172 -109
- package/build/umd/index.development.js +1381 -2331
- 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 +4 -4
- package/src/actions.ts +157 -0
- package/src/history.ts +199 -0
- package/src/index.ts +4 -7
- package/src/interop.ts +169 -0
- package/src/link.ts +2 -2
- package/src/route.ts +34 -239
- package/src/routeConfig.ts +3 -34
- package/src/routeInfo.ts +6 -21
- package/src/routeMatch.ts +270 -285
- package/src/router.ts +967 -963
- package/src/store.ts +52 -0
- package/build/cjs/sharedClone.js +0 -122
- package/build/cjs/sharedClone.js.map +0 -1
- package/src/sharedClone.ts +0 -118
package/build/cjs/path.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.js","sources":["../../src/path.ts"],"sourcesContent":["import invariant from 'tiny-invariant'\nimport { AnyPathParams } from './routeConfig'\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.startsWith('*')) {\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 leaveWildcard?: boolean,\n) {\n const interpolatedPathSegments = parsePathname(path)\n\n return joinPaths(\n interpolatedPathSegments.map((segment) => {\n if (segment.value === '*' && !leaveWildcard) {\n return ''\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(currentLocation.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 if (!from.startsWith(basepath)) {\n return undefined\n }\n from = basepath != '/' ? from.substring(basepath.length) : from\n const baseSegments = parsePathname(from)\n const to = `${matchLocation.to ?? '*'}`\n const routeSegments = parsePathname(to)\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 isLastRouteSegment = i === routeSegments.length - 1\n const isLastBaseSegment = i === baseSegments.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 (isLastRouteSegment && !isLastBaseSegment) {\n return !!matchLocation.fuzzy\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","startsWith","charAt","interpolatePath","params","leaveWildcard","interpolatedPathSegments","segment","matchPathname","currentPathname","matchLocation","pathParams","matchByPath","from","undefined","routeSegments","isMatch","i","Math","max","baseSegment","routeSegment","isLastRouteSegment","isLastBaseSegment","caseSensitive","toLowerCase","fuzzy"],"mappings":";;;;;;;;;;;;;;;;AAUO,SAASA,SAAS,CAACC,KAA6B,EAAE;AACvD,EAAA,OAAOC,SAAS,CAACD,KAAK,CAACE,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AACnD,CAAA;AAEO,SAASH,SAAS,CAACI,IAAY,EAAE;AACtC;AACA,EAAA,OAAOA,IAAI,CAACC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAA;AACrC,CAAA;AAEO,SAASC,YAAY,CAACF,IAAY,EAAE;AACzC,EAAA,OAAOA,IAAI,KAAK,GAAG,GAAGA,IAAI,GAAGA,IA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,KAAKkC,WAAW,CAAClC,KAAK,EAAE;AAC5C,gBAAA,OAAO,KAAK,CAAA;AACd,eAAA;AACF,aAAC,MAAM,IACLmC,YAAY,CAACnC,KAAK,CAACuC,WAAW,EAAE,KAChCL,WAAW,CAAClC,KAAK,CAACuC,WAAW,EAAE,EAC/B;AACA,cAAA,OAAO,KAAK,CAAA;AACd,aAAA;AACF,WAAA;AACF,SAAA;QAEA,IAAI,CAACL,WAAW,EAAE;AAChB,UAAA,OAAO,KAAK,CAAA;AACd,SAAA;AAEA,QAAA,IAAIC,YAAY,CAACvB,IAAI,KAAK,OAAO,EAAE;UACjC,IAAI,CAAAsB,WAAW,IAAXA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,WAAW,CAAElC,KAAK,MAAK,GAAG,EAAE;AAC9B,YAAA,OAAO,KAAK,CAAA;AACd,WAAA;UACA,IAAIkC,WAAW,CAAClC,KAAK,CAACgB,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;AACvCE,YAAAA,MAAM,CAACiB,YAAY,CAACnC,KAAK,CAACW,SAAS,CAAC,CAAC,CAAC,CAAC,GAAGuB,WAAW,CAAClC,KAAK,CAAA;AAC7D,WAAA;AACF,SAAA;AACF,OAAA;AAEA,MAAA,IAAIoC,kBAAkB,IAAI,CAACC,iBAAiB,EAAE;AAC5C,QAAA,OAAO,CAAC,CAACb,aAAa,CAACgB,KAAK,CAAA;AAC9B,OAAA;AACF,KAAA;AACA,IAAA,OAAO,IAAI,CAAA;AACb,GAAC,GAAG,CAAA;AAEJ,EAAA,OAAOV,OAAO,GAAIZ,MAAM,GAA8BU,SAAS,CAAA;AACjE;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"path.js","sources":["../../src/path.ts"],"sourcesContent":["import invariant from 'tiny-invariant'\nimport { AnyPathParams } from './routeConfig'\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.startsWith('*')) {\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 leaveWildcard?: boolean,\n) {\n const interpolatedPathSegments = parsePathname(path)\n\n return joinPaths(\n interpolatedPathSegments.map((segment) => {\n if (segment.value === '*' && !leaveWildcard) {\n return ''\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(currentLocation.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 if (!from.startsWith(basepath)) {\n return undefined\n }\n from = basepath != '/' ? from.substring(basepath.length) : from\n const baseSegments = parsePathname(from)\n const to = `${matchLocation.to ?? '*'}`\n const routeSegments = parsePathname(to)\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 isLastRouteSegment = i === routeSegments.length - 1\n const isLastBaseSegment = i === baseSegments.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 (isLastRouteSegment && !isLastBaseSegment) {\n return !!matchLocation.fuzzy\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","startsWith","charAt","interpolatePath","params","leaveWildcard","interpolatedPathSegments","segment","matchPathname","currentPathname","matchLocation","pathParams","matchByPath","from","undefined","routeSegments","isMatch","i","Math","max","baseSegment","routeSegment","isLastRouteSegment","isLastBaseSegment","caseSensitive","toLowerCase","fuzzy"],"mappings":";;;;;;;;;;;;;;;;AAUO,SAASA,SAAS,CAACC,KAA6B,EAAE;AACvD,EAAA,OAAOC,SAAS,CAACD,KAAK,CAACE,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AACnD,CAAA;AAEO,SAASH,SAAS,CAACI,IAAY,EAAE;AACtC;AACA,EAAA,OAAOA,IAAI,CAACC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAA;AACrC,CAAA;AAEO,SAASC,YAAY,CAACF,IAAY,EAAE;AACzC,EAAA,OAAOA,IAAI,KAAK,GAAG,GAAGA,IAAI,GAAGA,IAAI,CAACC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;AAC1D,CAAA;AAEO,SAASE,aAAa,CAACH,IAAY,EAAE;AAC1C,EAAA,OAAOA,IAAI,KAAK,GAAG,GAA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ACd,SAAA;AAEA,QAAA,IAAIC,YAAY,CAACvB,IAAI,KAAK,OAAO,EAAE;AACjC,UAAA,IAAIsB,WAAW,EAAElC,KAAK,KAAK,GAAG,EAAE;AAC9B,YAAA,OAAO,KAAK,CAAA;AACd,WAAA;UACA,IAAIkC,WAAW,CAAClC,KAAK,CAACgB,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;AACvCE,YAAAA,MAAM,CAACiB,YAAY,CAACnC,KAAK,CAACW,SAAS,CAAC,CAAC,CAAC,CAAC,GAAGuB,WAAW,CAAClC,KAAK,CAAA;AAC7D,WAAA;AACF,SAAA;AACF,OAAA;AAEA,MAAA,IAAIoC,kBAAkB,IAAI,CAACC,iBAAiB,EAAE;AAC5C,QAAA,OAAO,CAAC,CAACb,aAAa,CAACgB,KAAK,CAAA;AAC9B,OAAA;AACF,KAAA;AACA,IAAA,OAAO,IAAI,CAAA;AACb,GAAC,GAAG,CAAA;AAEJ,EAAA,OAAOV,OAAO,GAAIZ,MAAM,GAA8BU,SAAS,CAAA;AACjE;;;;;;;;;;;;;"}
|
package/build/cjs/route.js
CHANGED
|
@@ -12,144 +12,22 @@
|
|
|
12
12
|
|
|
13
13
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
fullPath,
|
|
31
|
-
options,
|
|
32
|
-
router,
|
|
33
|
-
childRoutes: undefined,
|
|
34
|
-
parentRoute: parent,
|
|
35
|
-
get action() {
|
|
36
|
-
let action = router.store.actions[id] || (() => {
|
|
37
|
-
router.setStore(s => {
|
|
38
|
-
s.actions[id] = {
|
|
39
|
-
submissions: [],
|
|
40
|
-
submit: async (submission, actionOpts) => {
|
|
41
|
-
if (!route) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const invalidate = (actionOpts == null ? void 0 : actionOpts.invalidate) ?? true;
|
|
45
|
-
const [actionStore, setActionStore] = reactivity.createStore({
|
|
46
|
-
submittedAt: Date.now(),
|
|
47
|
-
status: 'pending',
|
|
48
|
-
submission,
|
|
49
|
-
isMulti: !!(actionOpts != null && actionOpts.multi)
|
|
50
|
-
});
|
|
51
|
-
router.setStore(s => {
|
|
52
|
-
if (!(actionOpts != null && actionOpts.multi)) {
|
|
53
|
-
s.actions[id].submissions = action.submissions.filter(d => d.isMulti);
|
|
54
|
-
}
|
|
55
|
-
s.actions[id].current = actionStore;
|
|
56
|
-
s.actions[id].latest = actionStore;
|
|
57
|
-
s.actions[id].submissions.push(actionStore);
|
|
58
|
-
});
|
|
59
|
-
try {
|
|
60
|
-
const res = await (route.options.action == null ? void 0 : route.options.action(submission));
|
|
61
|
-
setActionStore(s => {
|
|
62
|
-
s.data = res;
|
|
63
|
-
});
|
|
64
|
-
if (invalidate) {
|
|
65
|
-
router.invalidateRoute({
|
|
66
|
-
to: '.',
|
|
67
|
-
fromCurrent: true
|
|
68
|
-
});
|
|
69
|
-
await router.reload();
|
|
70
|
-
}
|
|
71
|
-
setActionStore(s => {
|
|
72
|
-
s.status = 'success';
|
|
73
|
-
});
|
|
74
|
-
return res;
|
|
75
|
-
} catch (err) {
|
|
76
|
-
console.error(err);
|
|
77
|
-
setActionStore(s => {
|
|
78
|
-
s.error = err;
|
|
79
|
-
s.status = 'error';
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
});
|
|
85
|
-
return router.store.actions[id];
|
|
86
|
-
})();
|
|
87
|
-
return action;
|
|
88
|
-
},
|
|
89
|
-
get loader() {
|
|
90
|
-
let loader = router.store.loaders[id] || (() => {
|
|
91
|
-
router.setStore(s => {
|
|
92
|
-
s.loaders[id] = {
|
|
93
|
-
pending: [],
|
|
94
|
-
fetch: async loaderContext => {
|
|
95
|
-
if (!route) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const loaderState = {
|
|
99
|
-
loadedAt: Date.now(),
|
|
100
|
-
loaderContext
|
|
101
|
-
};
|
|
102
|
-
router.setStore(s => {
|
|
103
|
-
s.loaders[id].current = loaderState;
|
|
104
|
-
s.loaders[id].latest = loaderState;
|
|
105
|
-
s.loaders[id].pending.push(loaderState);
|
|
106
|
-
});
|
|
107
|
-
try {
|
|
108
|
-
return await (route.options.loader == null ? void 0 : route.options.loader(loaderContext));
|
|
109
|
-
} finally {
|
|
110
|
-
router.setStore(s => {
|
|
111
|
-
s.loaders[id].pending = s.loaders[id].pending.filter(d => d !== loaderState);
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
});
|
|
117
|
-
return router.store.loaders[id];
|
|
118
|
-
})();
|
|
119
|
-
return loader;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// buildLink: (options) => {
|
|
123
|
-
// return router.buildLink({
|
|
124
|
-
// ...options,
|
|
125
|
-
// from: fullPath,
|
|
126
|
-
// } as any) as any
|
|
127
|
-
// },
|
|
128
|
-
|
|
129
|
-
// navigate: (options) => {
|
|
130
|
-
// return router.navigate({
|
|
131
|
-
// ...options,
|
|
132
|
-
// from: fullPath,
|
|
133
|
-
// } as any) as any
|
|
134
|
-
// },
|
|
135
|
-
|
|
136
|
-
// matchRoute: (matchLocation, opts) => {
|
|
137
|
-
// return router.matchRoute(
|
|
138
|
-
// {
|
|
139
|
-
// ...matchLocation,
|
|
140
|
-
// from: fullPath,
|
|
141
|
-
// } as any,
|
|
142
|
-
// opts,
|
|
143
|
-
// ) as any
|
|
144
|
-
// },
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
router.options.createRoute == null ? void 0 : router.options.createRoute({
|
|
148
|
-
router,
|
|
149
|
-
route
|
|
150
|
-
});
|
|
151
|
-
return route;
|
|
15
|
+
class Route {
|
|
16
|
+
constructor(routeConfig, options, originalIndex, parent, router) {
|
|
17
|
+
Object.assign(this, {
|
|
18
|
+
...routeConfig,
|
|
19
|
+
originalIndex,
|
|
20
|
+
options,
|
|
21
|
+
getRouter: () => router,
|
|
22
|
+
childRoutes: undefined,
|
|
23
|
+
getParentRoute: () => parent
|
|
24
|
+
});
|
|
25
|
+
router.options.createRoute?.({
|
|
26
|
+
router,
|
|
27
|
+
route: this
|
|
28
|
+
});
|
|
29
|
+
}
|
|
152
30
|
}
|
|
153
31
|
|
|
154
|
-
exports.
|
|
32
|
+
exports.Route = Route;
|
|
155
33
|
//# sourceMappingURL=route.js.map
|
package/build/cjs/route.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.js","sources":["../../src/route.ts"],"sourcesContent":["import {\n CheckRelativePath,\n LinkInfo,\n LinkOptions,\n ResolveRelativePath,\n ToOptions,\n} from './link'\nimport { LoaderContext, RouteConfig, RouteOptions } from './routeConfig'\nimport {\n AnyAllRouteInfo,\n AnyRouteInfo,\n DefaultAllRouteInfo,\n RouteInfo,\n RouteInfoByPath,\n} from './routeInfo'\nimport {\n Action,\n ActionState,\n Loader,\n LoaderState,\n MatchRouteOptions,\n Router,\n} from './router'\nimport { NoInfer } from './utils'\nimport { createStore } from '@solidjs/reactivity'\n\nexport interface AnyRoute extends Route<any, any, any> {}\n\nexport interface Route<\n TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,\n TRouteInfo extends AnyRouteInfo = RouteInfo,\n TRouterContext = unknown,\n> {\n routeInfo: TRouteInfo\n routeId: TRouteInfo['id']\n routeRouteId: TRouteInfo['routeId']\n routePath: TRouteInfo['path']\n fullPath: TRouteInfo['fullPath']\n parentRoute?: AnyRoute\n childRoutes?: AnyRoute[]\n options: RouteOptions\n originalIndex: number\n router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo, TRouterContext>\n action: unknown extends TRouteInfo['actionResponse']\n ?\n | Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']>\n | undefined\n : Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']>\n loader: unknown extends TRouteInfo['routeLoaderData']\n ?\n | Action<\n LoaderContext<\n TRouteInfo['fullSearchSchema'],\n TRouteInfo['allParams']\n >,\n TRouteInfo['routeLoaderData']\n >\n | undefined\n : Loader<\n TRouteInfo['fullSearchSchema'],\n TRouteInfo['allParams'],\n TRouteInfo['routeLoaderData']\n >\n // buildLink: <TTo extends string = '.'>(\n // options: Omit<\n // LinkOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>,\n // 'from'\n // >,\n // ) => LinkInfo\n // matchRoute: <\n // TTo extends string = '.',\n // TResolved extends string = ResolveRelativePath<TRouteInfo['id'], TTo>,\n // >(\n // matchLocation: CheckRelativePath<\n // TAllRouteInfo,\n // TRouteInfo['fullPath'],\n // NoInfer<TTo>\n // > &\n // Omit<ToOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>, 'from'>,\n // opts?: MatchRouteOptions,\n // ) => RouteInfoByPath<TAllRouteInfo, TResolved>['allParams']\n // navigate: <TTo extends string = '.'>(\n // options: Omit<\n // LinkOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>,\n // 'from'\n // >,\n // ) => Promise<void>\n}\n\nexport function createRoute<\n TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,\n TRouteInfo extends AnyRouteInfo = RouteInfo,\n TRouterContext = unknown,\n>(\n routeConfig: RouteConfig,\n options: TRouteInfo['options'],\n originalIndex: number,\n parent: undefined | Route<TAllRouteInfo, any>,\n router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo, TRouterContext>,\n): Route<TAllRouteInfo, TRouteInfo, TRouterContext> {\n const { id, routeId, path: routePath, fullPath } = routeConfig\n\n let route: Route<TAllRouteInfo, TRouteInfo, TRouterContext> = {\n routeInfo: undefined!,\n routeId: id,\n routeRouteId: routeId,\n originalIndex,\n routePath,\n fullPath,\n options,\n router,\n childRoutes: undefined!,\n parentRoute: parent,\n get action() {\n let action =\n router.store.actions[id] ||\n (() => {\n router.setStore((s) => {\n s.actions[id] = {\n submissions: [],\n submit: async <T, U>(\n submission: T,\n actionOpts?: { invalidate?: boolean; multi?: boolean },\n ) => {\n if (!route) {\n return\n }\n\n const invalidate = actionOpts?.invalidate ?? true\n\n const [actionStore, setActionStore] = createStore<\n ActionState<T, U>\n >({\n submittedAt: Date.now(),\n status: 'pending',\n submission,\n isMulti: !!actionOpts?.multi,\n })\n\n router.setStore((s) => {\n if (!actionOpts?.multi) {\n s.actions[id]!.submissions = action.submissions.filter(\n (d) => d.isMulti,\n )\n }\n\n s.actions[id]!.current = actionStore\n s.actions[id]!.latest = actionStore\n s.actions[id]!.submissions.push(actionStore)\n })\n\n try {\n const res = await route.options.action?.(submission)\n\n setActionStore((s) => {\n s.data = res as U\n })\n\n if (invalidate) {\n router.invalidateRoute({ to: '.', fromCurrent: true })\n await router.reload()\n }\n\n setActionStore((s) => {\n s.status = 'success'\n })\n\n return res\n } catch (err) {\n console.error(err)\n setActionStore((s) => {\n s.error = err\n s.status = 'error'\n })\n }\n },\n }\n })\n\n return router.store.actions[id]!\n })()\n\n return action\n },\n get loader() {\n let loader =\n router.store.loaders[id] ||\n (() => {\n router.setStore((s) => {\n s.loaders[id] = {\n pending: [],\n fetch: (async (loaderContext: LoaderContext<any, any>) => {\n if (!route) {\n return\n }\n\n const loaderState: LoaderState<any, any> = {\n loadedAt: Date.now(),\n loaderContext,\n }\n\n router.setStore((s) => {\n s.loaders[id]!.current = loaderState\n s.loaders[id]!.latest = loaderState\n s.loaders[id]!.pending.push(loaderState)\n })\n\n try {\n return await route.options.loader?.(loaderContext)\n } finally {\n router.setStore((s) => {\n s.loaders[id]!.pending = s.loaders[id]!.pending.filter(\n (d) => d !== loaderState,\n )\n })\n }\n }) as any,\n }\n })\n\n return router.store.loaders[id]!\n })()\n\n return loader as any\n },\n\n // buildLink: (options) => {\n // return router.buildLink({\n // ...options,\n // from: fullPath,\n // } as any) as any\n // },\n\n // navigate: (options) => {\n // return router.navigate({\n // ...options,\n // from: fullPath,\n // } as any) as any\n // },\n\n // matchRoute: (matchLocation, opts) => {\n // return router.matchRoute(\n // {\n // ...matchLocation,\n // from: fullPath,\n // } as any,\n // opts,\n // ) as any\n // },\n }\n\n router.options.createRoute?.({ router, route })\n\n return route\n}\n"],"names":["createRoute","routeConfig","options","originalIndex","parent","router","id","routeId","path","routePath","fullPath","route","routeInfo","undefined","routeRouteId","childRoutes","parentRoute","action","store","actions","setStore","s","submissions","submit","submission","actionOpts","invalidate","actionStore","setActionStore","createStore","submittedAt","Date","now","status","isMulti","multi","filter","d","current","latest","push","res","data","invalidateRoute","to","fromCurrent","reload","err","console","error","loader","loaders","pending","fetch","loaderContext","loaderState","loadedAt"],"mappings":";;;;;;;;;;;;;;;;AAyFO,SAASA,WAAW,CAKzBC,WAAwB,EACxBC,OAA8B,EAC9BC,aAAqB,EACrBC,MAA6C,EAC7CC,MAA2E,EACzB;EAClD,MAAM;IAAEC,EAAE;IAAEC,OAAO;AAAEC,IAAAA,IAAI,EAAEC,SAAS;AAAEC,IAAAA,QAAAA;AAAS,GAAC,GAAGT,WAAW,CAAA;AAE9D,EAAA,IAAIU,KAAuD,GAAG;AAC5DC,IAAAA,SAAS,EAAEC,SAAU;AACrBN,IAAAA,OAAO,EAAED,EAAE;AACXQ,IAAAA,YAAY,EAAEP,OAAO;IACrBJ,aAAa;IACbM,SAAS;IACTC,QAAQ;IACRR,OAAO;IACPG,MAAM;AACNU,IAAAA,WAAW,EAAEF,SAAU;AACvBG,IAAAA,WAAW,EAAEZ,MAAM;AACnB,IAAA,IAAIa,MAAM,GAAG;AACX,MAAA,IAAIA,MAAM,GACRZ,MAAM,CAACa,KAAK,CAACC,OAAO,CAACb,EAAE,CAAC,IACxB,CAAC,MAAM;AACLD,QAAAA,MAAM,CAACe,QAAQ,CAAEC,CAAC,IAAK;AACrBA,UAAAA,CAAC,CAACF,OAAO,CAACb,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M,CAAA;AACf,KAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;GACD,CAAA;;EAED7C,MAAM,CAACH,OAAO,CAACF,WAAW,IAAA,IAAA,GAAA,KAAA,CAAA,GAA1BK,MAAM,CAACH,OAAO,CAACF,WAAW,CAAG;IAAEK,MAAM;AAAEM,IAAAA,KAAAA;AAAM,GAAC,CAAC,CAAA;AAE/C,EAAA,OAAOA,KAAK,CAAA;AACd;;;;"}
|
|
1
|
+
{"version":3,"file":"route.js","sources":["../../src/route.ts"],"sourcesContent":["import { Action, ActionOptions } from './actions'\nimport { RouteConfig, RouteOptions } from './routeConfig'\nimport {\n AnyAllRouteInfo,\n AnyRouteInfo,\n DefaultAllRouteInfo,\n RouteInfo,\n} from './routeInfo'\nimport { Router } from './router'\n\nexport interface AnyRoute extends Route<any, any, any> {}\n\nexport class Route<\n TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,\n TRouteInfo extends AnyRouteInfo = RouteInfo,\n TRouterContext = unknown,\n> {\n routeInfo!: TRouteInfo\n id!: TRouteInfo['id']\n customId!: TRouteInfo['customId']\n path!: TRouteInfo['path']\n fullPath!: TRouteInfo['fullPath']\n getParentRoute!: () => undefined | AnyRoute\n childRoutes?: AnyRoute[]\n options!: RouteOptions\n originalIndex!: number\n getRouter!: () => Router<\n TAllRouteInfo['routeConfig'],\n TAllRouteInfo,\n TRouterContext\n >\n constructor(\n routeConfig: RouteConfig,\n options: TRouteInfo['options'],\n originalIndex: number,\n parent: undefined | Route<TAllRouteInfo, any>,\n router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo, TRouterContext>,\n ) {\n Object.assign(this, {\n ...routeConfig,\n originalIndex,\n options,\n getRouter: () => router,\n childRoutes: undefined!,\n getParentRoute: () => parent,\n })\n\n router.options.createRoute?.({ router, route: this })\n }\n}\n"],"names":["Route","constructor","routeConfig","options","originalIndex","parent","router","Object","assign","getRouter","childRoutes","undefined","getParentRoute","createRoute","route"],"mappings":";;;;;;;;;;;;;;AAYO,MAAMA,KAAK,CAIhB;EAeAC,WAAW,CACTC,WAAwB,EACxBC,OAA8B,EAC9BC,aAAqB,EACrBC,MAA6C,EAC7CC,MAA2E,EAC3E;AACAC,IAAAA,MAAM,CAACC,MAAM,CAAC,IAAI,EAAE;AAClB,MAAA,GAAGN,WAAW;MACdE,aAAa;MACbD,OAAO;MACPM,SAAS,EAAE,MAAMH,MAAM;AACvBI,MAAAA,WAAW,EAAEC,SAAU;AACvBC,MAAAA,cAAc,EAAE,MAAMP,MAAAA;AACxB,KAAC,CAAC,CAAA;AAEFC,IAAAA,MAAM,CAACH,OAAO,CAACU,WAAW,GAAG;MAAEP,MAAM;AAAEQ,MAAAA,KAAK,EAAE,IAAA;AAAK,KAAC,CAAC,CAAA;AACvD,GAAA;AACF;;;;"}
|
package/build/cjs/routeConfig.js
CHANGED
|
@@ -20,13 +20,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
20
20
|
var invariant__default = /*#__PURE__*/_interopDefaultLegacy(invariant);
|
|
21
21
|
|
|
22
22
|
const rootRouteId = '__root__';
|
|
23
|
-
const createRouteConfig =
|
|
24
|
-
if (options === void 0) {
|
|
25
|
-
options = {};
|
|
26
|
-
}
|
|
27
|
-
if (isRoot === void 0) {
|
|
28
|
-
isRoot = true;
|
|
29
|
-
}
|
|
23
|
+
const createRouteConfig = (options = {}, children = [], isRoot = true, parentId, parentPath) => {
|
|
30
24
|
if (isRoot) {
|
|
31
25
|
options.path = rootRouteId;
|
|
32
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routeConfig.js","sources":["../../src/routeConfig.ts"],"sourcesContent":["import invariant from 'tiny-invariant'\nimport { GetFrameworkGeneric } from './frameworks'\nimport { ParsePathParams } from './link'\nimport { joinPaths, trimPath, trimPathRight } from './path'\nimport { RouteInfo } from './routeInfo'\nimport { RouteMatch } from './routeMatch'\nimport { RegisteredRouter, Router } from './router'\nimport { Expand, IsAny, NoInfer, PickUnsafe } from './utils'\n\nexport const rootRouteId = '__root__' as const\nexport type RootRouteId = typeof rootRouteId\n\nexport type AnyLoaderData = {}\nexport type AnyPathParams = {}\nexport type AnySearchSchema = {}\nexport interface RouteMeta {}\n\n// The parse type here allows a zod schema to be passed directly to the validator\nexport type SearchSchemaValidator<TReturn, TParentSchema> =\n | SearchSchemaValidatorObj<TReturn, TParentSchema>\n | SearchSchemaValidatorFn<TReturn, TParentSchema>\n\nexport type SearchSchemaValidatorObj<TReturn, TParentSchema> = {\n parse?: SearchSchemaValidatorFn<TReturn, TParentSchema>\n}\n\nexport type SearchSchemaValidatorFn<TReturn, TParentSchema> = (\n searchObj: Record<string, unknown>,\n) => {} extends TParentSchema\n ? TReturn\n : keyof TReturn extends keyof TParentSchema\n ? {\n error: 'Top level search params cannot be redefined by child routes!'\n keys: keyof TReturn & keyof TParentSchema\n }\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 TRouteLoaderData extends AnyLoaderData = {},\n TFullSearchSchema extends AnySearchSchema = {},\n TAllParams extends AnyPathParams = {},\n> = (\n loaderContext: LoaderContext<TFullSearchSchema, TAllParams>,\n) => TRouteLoaderData | Promise<TRouteLoaderData>\n\nexport interface LoaderContext<\n TFullSearchSchema extends AnySearchSchema = {},\n TAllParams extends AnyPathParams = {},\n> {\n params: TAllParams\n search: TFullSearchSchema\n signal?: AbortSignal\n // parentLoaderPromise?: Promise<TParentRouteLoaderData>\n}\n\nexport type ActionFn<TActionPayload = unknown, TActionResponse = unknown> = (\n submission: TActionPayload,\n) => TActionResponse | Promise<TActionResponse>\n\nexport type UnloaderFn<TPath extends string> = (\n routeMatch: RouteMatch<any, RouteInfo<string, TPath>>,\n) => void\n\nexport type RouteOptions<\n TRouteId extends string = string,\n TPath extends string = string,\n TParentRouteLoaderData extends AnyLoaderData = {},\n TRouteLoaderData extends AnyLoaderData = {},\n TParentLoaderData extends AnyLoaderData = {},\n TLoaderData extends AnyLoaderData = {},\n TActionPayload = unknown,\n TActionResponse = unknown,\n TParentSearchSchema extends {} = {},\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = TSearchSchema,\n TParentParams extends AnyPathParams = {},\n TParams extends Record<ParsePathParams<TPath>, unknown> = Record<\n ParsePathParams<TPath>,\n string\n >,\n TAllParams extends AnyPathParams = {},\n> = (\n | {\n // The path to match (relative to the nearest parent `Route` component or root basepath)\n path: TPath\n }\n | {\n id: TRouteId\n }\n) & {\n // If true, this route will be matched as case-sensitive\n caseSensitive?: boolean\n validateSearch?: SearchSchemaValidator<TSearchSchema, TParentSearchSchema>\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 // The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`\n component?: GetFrameworkGeneric<'Component'> // , NoInfer<TParentLoaderData>>\n // The content to be rendered when the route encounters an error\n errorComponent?: GetFrameworkGeneric<'ErrorComponent'> // , NoInfer<TParentLoaderData>>\n // If supported by your framework, the content to be rendered as the fallback content until the route is ready to render\n pendingComponent?: GetFrameworkGeneric<'Component'> //, NoInfer<TParentLoaderData>>\n // An asynchronous function responsible for preparing or fetching data for the route before it is rendered\n loader?: LoaderFn<TRouteLoaderData, TFullSearchSchema, TAllParams>\n // The max age to consider loader data fresh (not-stale) for this route in milliseconds from the time of fetch\n // Defaults to 0. Only stale loader data is refetched.\n loaderMaxAge?: number\n // The max age to cache the loader data for this route in milliseconds from the time of route inactivity\n // before it is garbage collected.\n loaderGcMaxAge?: number\n // An asynchronous function made available to the route for performing asynchronous or mutative actions that\n // might invalidate the route's data.\n action?: ActionFn<TActionPayload, TActionResponse>\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 `onLoadError` function.\n // If thrown during a preload event, the error will be logged to the console.\n beforeLoad?: (opts: {\n router: Router<any, any, unknown>\n match: RouteMatch\n }) => Promise<void> | void\n // This function will be called if the route's loader throws an error **during an attempted navigation**.\n // If you want to redirect due to an error, call `router.navigate()` from within this function.\n onLoadError?: (err: any) => void\n // This function is called\n // when moving from an inactive state to an active one. Likewise, when moving from\n // an active to an inactive state, the return function (if provided) is called.\n onLoaded?: (matchContext: {\n params: TAllParams\n search: TFullSearchSchema\n }) =>\n | void\n | undefined\n | ((match: { params: TAllParams; search: TFullSearchSchema }) => void)\n // This function is called when the route remains active from one transition to the next.\n onTransition?: (match: {\n params: TAllParams\n search: TFullSearchSchema\n }) => void\n // An object of whatever you want! This object is accessible anywhere matches are.\n meta?: RouteMeta // TODO: Make this nested and mergeable\n} & (\n | {\n parseParams?: never\n stringifyParams?: never\n }\n | {\n // Parse params optionally receives path params as strings and returns them in a parsed format (like a number or boolean)\n parseParams: (\n rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,\n ) => TParams\n stringifyParams: (\n params: TParams,\n ) => Record<ParsePathParams<TPath>, string>\n }\n ) &\n (PickUnsafe<TParentParams, ParsePathParams<TPath>> extends never // Detect if an existing path param is being redefined\n ? {}\n : 'Cannot redefined path params in child routes!')\n\nexport type SearchFilter<T, U = T> = (prev: T) => U\n\nexport interface RouteConfig<\n TId extends string = string,\n TRouteId extends string = string,\n TPath extends string = string,\n TFullPath extends string = string,\n TParentRouteLoaderData extends AnyLoaderData = AnyLoaderData,\n TRouteLoaderData extends AnyLoaderData = AnyLoaderData,\n TParentLoaderData extends AnyLoaderData = {},\n TLoaderData extends AnyLoaderData = AnyLoaderData,\n TActionPayload = unknown,\n TActionResponse = unknown,\n TParentSearchSchema extends {} = {},\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = {},\n TParentParams extends AnyPathParams = {},\n TParams extends AnyPathParams = {},\n TAllParams extends AnyPathParams = {},\n TKnownChildren = unknown,\n> {\n id: TId\n routeId: TRouteId\n path: NoInfer<TPath>\n fullPath: TFullPath\n options: RouteOptions<\n TRouteId,\n TPath,\n TParentRouteLoaderData,\n TRouteLoaderData,\n TParentLoaderData,\n TLoaderData,\n TActionPayload,\n TActionResponse,\n TParentSearchSchema,\n TSearchSchema,\n TFullSearchSchema,\n TParentParams,\n TParams,\n TAllParams\n >\n children?: TKnownChildren\n addChildren: IsAny<\n TId,\n any,\n <TNewChildren extends any>(\n children: TNewChildren extends AnyRouteConfig[]\n ? TNewChildren\n : { error: 'Invalid route detected'; route: TNewChildren },\n ) => RouteConfig<\n TId,\n TRouteId,\n TPath,\n TFullPath,\n TParentRouteLoaderData,\n TRouteLoaderData,\n TParentLoaderData,\n TLoaderData,\n TActionPayload,\n TActionResponse,\n TParentSearchSchema,\n TSearchSchema,\n TFullSearchSchema,\n TParentParams,\n TParams,\n TAllParams,\n TNewChildren\n >\n >\n createRoute: CreateRouteConfigFn<\n false,\n TId,\n TFullPath,\n TRouteLoaderData,\n TLoaderData,\n TFullSearchSchema,\n TAllParams\n >\n generate: GenerateFn<\n TRouteId,\n TPath,\n TParentRouteLoaderData,\n TParentLoaderData,\n TParentSearchSchema,\n TParentParams\n >\n}\n\ntype GenerateFn<\n TRouteId extends string = string,\n TPath extends string = string,\n TParentRouteLoaderData extends AnyLoaderData = AnyLoaderData,\n TParentLoaderData extends AnyLoaderData = {},\n TParentSearchSchema extends {} = {},\n TParentParams extends AnyPathParams = {},\n> = <\n TRouteLoaderData extends AnyLoaderData = AnyLoaderData,\n TActionPayload = unknown,\n TActionResponse = unknown,\n TSearchSchema extends AnySearchSchema = {},\n TParams extends Record<ParsePathParams<TPath>, unknown> = Record<\n ParsePathParams<TPath>,\n string\n >,\n TAllParams extends AnyPathParams extends TParams\n ? Record<ParsePathParams<TPath>, string>\n : NoInfer<TParams> = AnyPathParams extends TParams\n ? Record<ParsePathParams<TPath>, string>\n : NoInfer<TParams>,\n>(\n options: Omit<\n RouteOptions<\n TRouteId,\n TPath,\n TParentRouteLoaderData,\n TRouteLoaderData,\n TParentLoaderData,\n Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>,\n TActionPayload,\n TActionResponse,\n TParentSearchSchema,\n TSearchSchema,\n Expand<TParentSearchSchema & TSearchSchema>,\n TParentParams,\n TParams,\n Expand<TParentParams & TAllParams>\n >,\n 'path'\n >,\n) => void\n\ntype CreateRouteConfigFn<\n TIsRoot extends boolean = false,\n TParentId extends string = string,\n TParentPath extends string = string,\n TParentRouteLoaderData extends AnyLoaderData = {},\n TParentLoaderData extends AnyLoaderData = {},\n TParentSearchSchema extends AnySearchSchema = {},\n TParentParams extends AnyPathParams = {},\n> = <\n TRouteId extends string,\n TPath extends string,\n TRouteLoaderData extends AnyLoaderData,\n TActionPayload,\n TActionResponse,\n TSearchSchema extends AnySearchSchema = AnySearchSchema,\n TParams extends Record<ParsePathParams<TPath>, unknown> = Record<\n ParsePathParams<TPath>,\n string\n >,\n TAllParams extends AnyPathParams extends TParams\n ? Record<ParsePathParams<TPath>, string>\n : NoInfer<TParams> = AnyPathParams extends TParams\n ? Record<ParsePathParams<TPath>, string>\n : NoInfer<TParams>,\n TKnownChildren extends RouteConfig[] = RouteConfig[],\n TResolvedId extends string = string extends TRouteId\n ? string extends TPath\n ? string\n : TPath\n : TRouteId,\n>(\n options?: TIsRoot extends true\n ? Omit<\n RouteOptions<\n TRouteId,\n TPath,\n TParentRouteLoaderData,\n TRouteLoaderData,\n TParentLoaderData,\n Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>,\n TActionPayload,\n TActionResponse,\n TParentSearchSchema,\n TSearchSchema,\n Expand<TParentSearchSchema & TSearchSchema>,\n TParentParams,\n TParams,\n Expand<TParentParams & TAllParams>\n >,\n 'path'\n > & { path?: never }\n : RouteOptions<\n TRouteId,\n TPath,\n TParentRouteLoaderData,\n TRouteLoaderData,\n TParentLoaderData,\n Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>,\n TActionPayload,\n TActionResponse,\n TParentSearchSchema,\n TSearchSchema,\n Expand<TParentSearchSchema & TSearchSchema>,\n TParentParams,\n TParams,\n Expand<TParentParams & TAllParams>\n >,\n children?: TKnownChildren,\n isRoot?: boolean,\n parentId?: string,\n parentPath?: string,\n) => RouteConfig<\n RoutePrefix<TParentId, TResolvedId>,\n TResolvedId,\n TPath,\n string extends TPath ? '' : RoutePath<RoutePrefix<TParentPath, TPath>>,\n TParentRouteLoaderData,\n TRouteLoaderData,\n TParentLoaderData,\n Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>,\n TActionPayload,\n TActionResponse,\n TParentSearchSchema,\n TSearchSchema,\n Expand<TParentSearchSchema & TSearchSchema>,\n TParentParams,\n TParams,\n Expand<TParentParams & TAllParams>,\n TKnownChildren\n>\n\ntype RoutePath<T extends string> = T extends RootRouteId\n ? '/'\n : TrimPathRight<`${T}`>\n\ntype RoutePrefix<\n TPrefix extends string,\n TId extends string,\n> = string extends TId\n ? RootRouteId\n : TId extends string\n ? `${TPrefix}/${TId}` extends '/'\n ? '/'\n : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TId>}`>}`\n : never\n\nexport interface AnyRouteConfig\n extends RouteConfig<\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 interface AnyRouteConfigWithChildren<TChildren>\n extends RouteConfig<\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 TChildren\n > {}\n\ntype TrimPath<T extends string> = '' extends T\n ? ''\n : TrimPathRight<TrimPathLeft<T>>\n\ntype TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}`\n ? TrimPathLeft<U>\n : T extends `/${infer U}`\n ? TrimPathLeft<U>\n : T\ntype TrimPathRight<T extends string> = T extends '/'\n ? '/'\n : T extends `${infer U}/`\n ? TrimPathRight<U>\n : T\n\nexport const createRouteConfig: CreateRouteConfigFn<true> = (\n options = {} as any,\n children,\n isRoot = true,\n parentId,\n parentPath,\n) => {\n if (isRoot) {\n ;(options as any).path = rootRouteId\n }\n\n // Strip the root from parentIds\n if (parentId === rootRouteId) {\n parentId = ''\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 routeId = path || (options as { id?: string }).id\n\n let id = joinPaths([parentId, routeId])\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 ? '/' : trimPathRight(joinPaths([parentPath, path]))\n\n return {\n id: id as any,\n routeId: routeId as any,\n path: path as any,\n fullPath: fullPath as any,\n options: options as any,\n children,\n addChildren: (children: any) =>\n createRouteConfig(options, children, false, parentId, parentPath),\n createRoute: (childOptions: any) =>\n createRouteConfig(childOptions, undefined, false, id, fullPath) as any,\n generate: () => {\n invariant(\n false,\n `routeConfig.generate() is used by TanStack Router's file-based routing code generation and should not actually be called during runtime. `,\n )\n },\n }\n}\n"],"names":["rootRouteId","createRouteConfig","options","children","isRoot","parentId","parentPath","path","trimPath","routeId","id","joinPaths","fullPath","trimPathRight","addChildren","createRoute","childOptions","undefined","generate","invariant"],"mappings":";;;;;;;;;;;;;;;;;;;;;AASO,MAAMA,WAAW,GAAG,WAAmB;AAycjCC,MAAAA,iBAA4C,GAAG,UAC1DC,OAAO,EACPC,QAAQ,EACRC,MAAM,EACNC,QAAQ,EACRC,UAAU,EACP;AAAA,EAAA,IALHJ,OAAO,KAAA,KAAA,CAAA,EAAA;IAAPA,OAAO,GAAG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;AACRW,IAAAA,WAAW,EAAGX,QAAa,IACzBF,iBAAiB,CAACC,OAAO,EAAEC,QAAQ,EAAE,KAAK,EAAEE,QAAQ,EAAEC,UAAU,CAAC;AACnES,IAAAA,WAAW,EAAGC,YAAiB,IAC7Bf,iBAAiB,CAACe,YAAY,EAAEC,SAAS,EAAE,KAAK,EAAEP,EAAE,EAAEE,QAAQ,CAAQ;AACxEM,IAAAA,QAAQ,EAAE,MAAM;AACdC,MAAAA,6BAAS,CACP,KAAK,EACJ,CAAA,yIAAA,CAA0I,CAC5I,CAAA;AACH,KAAA;GACD,CAAA;AACH;;;;;"}
|
|
1
|
+
{"version":3,"file":"routeConfig.js","sources":["../../src/routeConfig.ts"],"sourcesContent":["import invariant from 'tiny-invariant'\nimport { GetFrameworkGeneric } from './frameworks'\nimport { ParsePathParams } from './link'\nimport { joinPaths, trimPath, trimPathRight } from './path'\nimport { RouteInfo } from './routeInfo'\nimport { RouteMatch } from './routeMatch'\nimport { AnyRouter, RegisteredRouter, Router } from './router'\nimport { Expand, IsAny, NoInfer, PickUnsafe } from './utils'\n\nexport const rootRouteId = '__root__' as const\nexport type RootRouteId = typeof rootRouteId\n\nexport type AnyLoaderData = {}\nexport type AnyPathParams = {}\nexport type AnySearchSchema = {}\nexport interface RouteMeta {}\n\n// The parse type here allows a zod schema to be passed directly to the validator\nexport type SearchSchemaValidator<TReturn, TParentSchema> =\n | SearchSchemaValidatorObj<TReturn, TParentSchema>\n | SearchSchemaValidatorFn<TReturn, TParentSchema>\n\nexport type SearchSchemaValidatorObj<TReturn, TParentSchema> = {\n parse?: SearchSchemaValidatorFn<TReturn, TParentSchema>\n}\n\nexport type SearchSchemaValidatorFn<TReturn, TParentSchema> = (\n searchObj: Record<string, unknown>,\n) => {} extends TParentSchema\n ? TReturn\n : keyof TReturn extends keyof TParentSchema\n ? {\n error: 'Top level search params cannot be redefined by child routes!'\n keys: keyof TReturn & keyof TParentSchema\n }\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 TRouteLoaderData extends AnyLoaderData = {},\n TFullSearchSchema extends AnySearchSchema = {},\n TAllParams extends AnyPathParams = {},\n> = (\n loaderContext: LoaderContext<TFullSearchSchema, TAllParams>,\n) => TRouteLoaderData | Promise<TRouteLoaderData>\n\nexport interface LoaderContext<\n TFullSearchSchema extends AnySearchSchema = {},\n TAllParams extends AnyPathParams = {},\n> {\n params: TAllParams\n search: TFullSearchSchema\n signal?: AbortSignal\n // parentLoaderPromise?: Promise<TParentRouteLoaderData>\n}\n\nexport type UnloaderFn<TPath extends string> = (\n routeMatch: RouteMatch<any, RouteInfo<string, TPath>>,\n) => void\n\nexport type RouteOptions<\n TRouteId extends string = string,\n TPath extends string = string,\n TParentRouteLoaderData extends AnyLoaderData = {},\n TRouteLoaderData extends AnyLoaderData = {},\n TParentLoaderData extends AnyLoaderData = {},\n TLoaderData extends AnyLoaderData = {},\n TParentSearchSchema extends {} = {},\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = TSearchSchema,\n TParentParams extends AnyPathParams = {},\n TParams extends Record<ParsePathParams<TPath>, unknown> = Record<\n ParsePathParams<TPath>,\n string\n >,\n TAllParams extends AnyPathParams = {},\n> = (\n | {\n // The path to match (relative to the nearest parent `Route` component or root basepath)\n path: TPath\n }\n | {\n id: TRouteId\n }\n) & {\n // If true, this route will be matched as case-sensitive\n caseSensitive?: boolean\n validateSearch?: SearchSchemaValidator<TSearchSchema, TParentSearchSchema>\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 // The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`\n component?: GetFrameworkGeneric<'Component'> // , NoInfer<TParentLoaderData>>\n // The content to be rendered when the route encounters an error\n errorComponent?: GetFrameworkGeneric<'ErrorComponent'> // , NoInfer<TParentLoaderData>>\n // If supported by your framework, the content to be rendered as the fallback content until the route is ready to render\n pendingComponent?: GetFrameworkGeneric<'Component'> //, NoInfer<TParentLoaderData>>\n // An asynchronous function responsible for preparing or fetching data for the route before it is rendered\n loader?: LoaderFn<TRouteLoaderData, TFullSearchSchema, TAllParams>\n // The max age to consider loader data fresh (not-stale) for this route in milliseconds from the time of fetch\n // Defaults to 0. Only stale loader data is refetched.\n loaderMaxAge?: number\n // The max age to cache the loader data for this route in milliseconds from the time of route inactivity\n // before it is garbage collected.\n loaderGcMaxAge?: number\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 `onLoadError` function.\n // If thrown during a preload event, the error will be logged to the console.\n beforeLoad?: (opts: {\n router: AnyRouter\n match: RouteMatch\n }) => Promise<void> | void\n // This function will be called if the route's loader throws an error **during an attempted navigation**.\n // If you want to redirect due to an error, call `router.navigate()` from within this function.\n onLoadError?: (err: any) => void\n // This function is called\n // when moving from an inactive state to an active one. Likewise, when moving from\n // an active to an inactive state, the return function (if provided) is called.\n onLoaded?: (matchContext: {\n params: TAllParams\n search: TFullSearchSchema\n }) =>\n | void\n | undefined\n | ((match: { params: TAllParams; search: TFullSearchSchema }) => void)\n // This function is called when the route remains active from one transition to the next.\n onTransition?: (match: {\n params: TAllParams\n search: TFullSearchSchema\n }) => void\n // An object of whatever you want! This object is accessible anywhere matches are.\n meta?: RouteMeta // TODO: Make this nested and mergeable\n} & (\n | {\n parseParams?: never\n stringifyParams?: never\n }\n | {\n // Parse params optionally receives path params as strings and returns them in a parsed format (like a number or boolean)\n parseParams: (\n rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,\n ) => TParams\n stringifyParams: (\n params: TParams,\n ) => Record<ParsePathParams<TPath>, string>\n }\n ) &\n (PickUnsafe<TParentParams, ParsePathParams<TPath>> extends never // Detect if an existing path param is being redefined\n ? {}\n : 'Cannot redefined path params in child routes!')\n\nexport type SearchFilter<T, U = T> = (prev: T) => U\n\nexport interface RouteConfig<\n TId extends string = string,\n TRouteId extends string = string,\n TPath extends string = string,\n TFullPath extends string = string,\n TParentRouteLoaderData extends AnyLoaderData = AnyLoaderData,\n TRouteLoaderData extends AnyLoaderData = AnyLoaderData,\n TParentLoaderData extends AnyLoaderData = {},\n TLoaderData extends AnyLoaderData = AnyLoaderData,\n TParentSearchSchema extends {} = {},\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = {},\n TParentParams extends AnyPathParams = {},\n TParams extends AnyPathParams = {},\n TAllParams extends AnyPathParams = {},\n TKnownChildren = unknown,\n> {\n id: TId\n routeId: TRouteId\n path: NoInfer<TPath>\n fullPath: TFullPath\n options: RouteOptions<\n TRouteId,\n TPath,\n TParentRouteLoaderData,\n TRouteLoaderData,\n TParentLoaderData,\n TLoaderData,\n TParentSearchSchema,\n TSearchSchema,\n TFullSearchSchema,\n TParentParams,\n TParams,\n TAllParams\n >\n children?: TKnownChildren\n addChildren: IsAny<\n TId,\n any,\n <TNewChildren extends any>(\n children: TNewChildren extends AnyRouteConfig[]\n ? TNewChildren\n : { error: 'Invalid route detected'; route: TNewChildren },\n ) => RouteConfig<\n TId,\n TRouteId,\n TPath,\n TFullPath,\n TParentRouteLoaderData,\n TRouteLoaderData,\n TParentLoaderData,\n TLoaderData,\n TParentSearchSchema,\n TSearchSchema,\n TFullSearchSchema,\n TParentParams,\n TParams,\n TAllParams,\n TNewChildren\n >\n >\n createRoute: CreateRouteConfigFn<\n false,\n TId,\n TFullPath,\n TRouteLoaderData,\n TLoaderData,\n TFullSearchSchema,\n TAllParams\n >\n generate: GenerateFn<\n TRouteId,\n TPath,\n TParentRouteLoaderData,\n TParentLoaderData,\n TParentSearchSchema,\n TParentParams\n >\n}\n\ntype GenerateFn<\n TRouteId extends string = string,\n TPath extends string = string,\n TParentRouteLoaderData extends AnyLoaderData = AnyLoaderData,\n TParentLoaderData extends AnyLoaderData = {},\n TParentSearchSchema extends {} = {},\n TParentParams extends AnyPathParams = {},\n> = <\n TRouteLoaderData extends AnyLoaderData = AnyLoaderData,\n TSearchSchema extends AnySearchSchema = {},\n TParams extends Record<ParsePathParams<TPath>, unknown> = Record<\n ParsePathParams<TPath>,\n string\n >,\n TAllParams extends AnyPathParams extends TParams\n ? Record<ParsePathParams<TPath>, string>\n : NoInfer<TParams> = AnyPathParams extends TParams\n ? Record<ParsePathParams<TPath>, string>\n : NoInfer<TParams>,\n>(\n options: Omit<\n RouteOptions<\n TRouteId,\n TPath,\n TParentRouteLoaderData,\n TRouteLoaderData,\n TParentLoaderData,\n Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>,\n TParentSearchSchema,\n TSearchSchema,\n Expand<TParentSearchSchema & TSearchSchema>,\n TParentParams,\n TParams,\n Expand<TParentParams & TAllParams>\n >,\n 'path'\n >,\n) => void\n\ntype CreateRouteConfigFn<\n TIsRoot extends boolean = false,\n TParentId extends string = string,\n TParentPath extends string = string,\n TParentRouteLoaderData extends AnyLoaderData = {},\n TParentLoaderData extends AnyLoaderData = {},\n TParentSearchSchema extends AnySearchSchema = {},\n TParentParams extends AnyPathParams = {},\n> = <\n TRouteId extends string,\n TPath extends string,\n TRouteLoaderData extends AnyLoaderData,\n TSearchSchema extends AnySearchSchema = AnySearchSchema,\n TParams extends Record<ParsePathParams<TPath>, unknown> = Record<\n ParsePathParams<TPath>,\n string\n >,\n TAllParams extends AnyPathParams extends TParams\n ? Record<ParsePathParams<TPath>, string>\n : NoInfer<TParams> = AnyPathParams extends TParams\n ? Record<ParsePathParams<TPath>, string>\n : NoInfer<TParams>,\n TKnownChildren extends RouteConfig[] = RouteConfig[],\n TResolvedId extends string = string extends TRouteId\n ? string extends TPath\n ? string\n : TPath\n : TRouteId,\n>(\n options?: TIsRoot extends true\n ? Omit<\n RouteOptions<\n TRouteId,\n TPath,\n TParentRouteLoaderData,\n TRouteLoaderData,\n TParentLoaderData,\n Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>,\n TParentSearchSchema,\n TSearchSchema,\n Expand<TParentSearchSchema & TSearchSchema>,\n TParentParams,\n TParams,\n Expand<TParentParams & TAllParams>\n >,\n 'path'\n > & { path?: never }\n : RouteOptions<\n TRouteId,\n TPath,\n TParentRouteLoaderData,\n TRouteLoaderData,\n TParentLoaderData,\n Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>,\n TParentSearchSchema,\n TSearchSchema,\n Expand<TParentSearchSchema & TSearchSchema>,\n TParentParams,\n TParams,\n Expand<TParentParams & TAllParams>\n >,\n children?: TKnownChildren,\n isRoot?: boolean,\n parentId?: string,\n parentPath?: string,\n) => RouteConfig<\n RoutePrefix<TParentId, TResolvedId>,\n TResolvedId,\n TPath,\n string extends TPath ? '' : RoutePath<RoutePrefix<TParentPath, TPath>>,\n TParentRouteLoaderData,\n TRouteLoaderData,\n TParentLoaderData,\n Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>,\n TParentSearchSchema,\n TSearchSchema,\n Expand<TParentSearchSchema & TSearchSchema>,\n TParentParams,\n TParams,\n Expand<TParentParams & TAllParams>,\n TKnownChildren\n>\n\ntype RoutePath<T extends string> = T extends RootRouteId\n ? '/'\n : TrimPathRight<`${T}`>\n\ntype RoutePrefix<\n TPrefix extends string,\n TId extends string,\n> = string extends TId\n ? RootRouteId\n : TId extends string\n ? `${TPrefix}/${TId}` extends '/'\n ? '/'\n : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TId>}`>}`\n : never\n\nexport interface AnyRouteConfig\n extends RouteConfig<\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 interface AnyRouteConfigWithChildren<TChildren>\n extends RouteConfig<\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 TChildren\n > {}\n\ntype TrimPath<T extends string> = '' extends T\n ? ''\n : TrimPathRight<TrimPathLeft<T>>\n\ntype TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}`\n ? TrimPathLeft<U>\n : T extends `/${infer U}`\n ? TrimPathLeft<U>\n : T\ntype TrimPathRight<T extends string> = T extends '/'\n ? '/'\n : T extends `${infer U}/`\n ? TrimPathRight<U>\n : T\n\nexport const createRouteConfig: CreateRouteConfigFn<true> = (\n options = {} as any,\n children = [] as any,\n isRoot = true,\n parentId,\n parentPath,\n) => {\n if (isRoot) {\n ;(options as any).path = rootRouteId\n }\n\n // Strip the root from parentIds\n if (parentId === rootRouteId) {\n parentId = ''\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 routeId = path || (options as { id?: string }).id\n\n let id = joinPaths([parentId, routeId])\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 ? '/' : trimPathRight(joinPaths([parentPath, path]))\n\n return {\n id: id as any,\n routeId: routeId as any,\n path: path as any,\n fullPath: fullPath as any,\n options: options as any,\n children,\n addChildren: (children: any) =>\n createRouteConfig(options, children, false, parentId, parentPath),\n createRoute: (childOptions: any) =>\n createRouteConfig(childOptions, undefined, false, id, fullPath) as any,\n generate: () => {\n invariant(\n false,\n `routeConfig.generate() is used by TanStack Router's file-based routing code generation and should not actually be called during runtime. `,\n )\n },\n }\n}\n"],"names":["rootRouteId","createRouteConfig","options","children","isRoot","parentId","parentPath","path","trimPath","routeId","id","joinPaths","fullPath","trimPathRight","addChildren","createRoute","childOptions","undefined","generate","invariant"],"mappings":";;;;;;;;;;;;;;;;;;;;;AASO,MAAMA,WAAW,GAAG,WAAmB;AA0avC,MAAMC,iBAA4C,GA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