@tanstack/router-core 0.0.1-beta.36 → 0.0.1-beta.39
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/build/cjs/index.js +2 -1
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/path.js +5 -7
- package/build/cjs/path.js.map +1 -1
- package/build/cjs/route.js +112 -95
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/routeConfig.js +2 -2
- package/build/cjs/routeConfig.js.map +1 -1
- package/build/cjs/routeMatch.js +107 -65
- package/build/cjs/routeMatch.js.map +1 -1
- package/build/cjs/router.js +320 -351
- package/build/cjs/router.js.map +1 -1
- package/build/cjs/searchParams.js +4 -3
- package/build/cjs/searchParams.js.map +1 -1
- package/build/cjs/sharedClone.js +122 -0
- package/build/cjs/sharedClone.js.map +1 -0
- package/build/cjs/utils.js +1 -59
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +654 -592
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +183 -158
- package/build/types/index.d.ts +54 -68
- package/build/umd/index.development.js +1000 -595
- 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 +2 -1
- package/src/index.ts +1 -0
- package/src/link.ts +20 -12
- package/src/route.ts +160 -139
- package/src/routeMatch.ts +144 -99
- package/src/router.ts +402 -491
- package/src/sharedClone.ts +118 -0
- package/src/utils.ts +0 -65
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -31
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
package/build/cjs/index.js
CHANGED
|
@@ -22,6 +22,7 @@ var routeMatch = require('./routeMatch.js');
|
|
|
22
22
|
var router = require('./router.js');
|
|
23
23
|
var searchParams = require('./searchParams.js');
|
|
24
24
|
var utils = require('./utils.js');
|
|
25
|
+
var sharedClone = require('./sharedClone.js');
|
|
25
26
|
|
|
26
27
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
27
28
|
|
|
@@ -69,6 +70,6 @@ exports.stringifySearchWith = searchParams.stringifySearchWith;
|
|
|
69
70
|
exports.functionalUpdate = utils.functionalUpdate;
|
|
70
71
|
exports.last = utils.last;
|
|
71
72
|
exports.pick = utils.pick;
|
|
72
|
-
exports.replaceEqualDeep = utils.replaceEqualDeep;
|
|
73
73
|
exports.warning = utils.warning;
|
|
74
|
+
exports.sharedClone = sharedClone.sharedClone;
|
|
74
75
|
//# sourceMappingURL=index.js.map
|
package/build/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/build/cjs/path.js
CHANGED
|
@@ -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) => {
|
|
@@ -113,8 +113,7 @@ function interpolatePath(path, params, leaveWildcard) {
|
|
|
113
113
|
return '';
|
|
114
114
|
}
|
|
115
115
|
if (segment.type === 'param') {
|
|
116
|
-
|
|
117
|
-
return (_segment$value$substr = params[segment.value.substring(1)]) != null ? _segment$value$substr : '';
|
|
116
|
+
return params[segment.value.substring(1)] ?? '';
|
|
118
117
|
}
|
|
119
118
|
return segment.value;
|
|
120
119
|
}));
|
|
@@ -126,16 +125,15 @@ function matchPathname(basepath, currentPathname, matchLocation) {
|
|
|
126
125
|
if (matchLocation.to && !pathParams) {
|
|
127
126
|
return;
|
|
128
127
|
}
|
|
129
|
-
return pathParams
|
|
128
|
+
return pathParams ?? {};
|
|
130
129
|
}
|
|
131
130
|
function matchByPath(basepath, from, matchLocation) {
|
|
132
|
-
var _matchLocation$to;
|
|
133
131
|
if (!from.startsWith(basepath)) {
|
|
134
132
|
return undefined;
|
|
135
133
|
}
|
|
136
134
|
from = basepath != '/' ? from.substring(basepath.length) : from;
|
|
137
135
|
const baseSegments = parsePathname(from);
|
|
138
|
-
const to =
|
|
136
|
+
const to = `${matchLocation.to ?? '*'}`;
|
|
139
137
|
const routeSegments = parsePathname(to);
|
|
140
138
|
const params = {};
|
|
141
139
|
let isMatch = (() => {
|
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,IAAI,CAACC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;AAC1D,CAAA;AAEO,SAASE,aAAa,CAACH,IAAY,EAAE;AAC1C,EAAA,OAAOA,IAAI,KAAK,GAAG,GAAGA,IAAI,GAAGA,IAAI,CAACC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;AAC1D,CAAA;AAEO,SAASG,QAAQ,CAACJ,IAAY,EAAE;AACrC,EAAA,OAAOG,aAAa,CAACD,YAAY,CAACF,IAAI,CAAC,CAAC,CAAA;AAC1C,CAAA;AAEO,SAASK,WAAW,CAACC,QAAgB,EAAEC,IAAY,EAAEC,EAAU,EAAE;AACtED,EAAAA,IAAI,GAAGA,IAAI,CAACN,OAAO,CAAC,IAAIQ,MAAM,CAAA,GAAA,GAAKH,QAAQ,CAAG,EAAE,GAAG,CAAC,CAAA;AACpDE,EAAAA,EAAE,GAAGA,EAAE,CAACP,OAAO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,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,GAAGA,IAAI,GAAGA,IAAI,CAACC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;AAC1D,CAAA;AAEO,SAASG,QAAQ,CAACJ,IAAY,EAAE;AACrC,EAAA,OAAOG,aAAa,CAACD,YAAY,CAACF,IAAI,CAAC,CAAC,CAAA;AAC1C,CAAA;AAEO,SAASK,WAAW,CAACC,QAAgB,EAAEC,IAAY,EAAEC,EAAU,EAAE;AACtED,EAAAA,IAAI,GAAGA,IAAI,CAACN,OAAO,CAAC,IAAIQ,MAAM,CAAE,CAAA,CAAA,EAAGH,QAAS,CAAA,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AACpDE,EAAAA,EA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AACgB,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,121 +12,138 @@
|
|
|
12
12
|
|
|
13
13
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var reactivity = require('@solidjs/reactivity');
|
|
16
16
|
|
|
17
|
-
function createRoute(routeConfig, options, parent, router) {
|
|
17
|
+
function createRoute(routeConfig, options, originalIndex, parent, router) {
|
|
18
18
|
const {
|
|
19
19
|
id,
|
|
20
20
|
routeId,
|
|
21
21
|
path: routePath,
|
|
22
22
|
fullPath
|
|
23
23
|
} = routeConfig;
|
|
24
|
-
const action = router.state.actions[id] || (() => {
|
|
25
|
-
router.state.actions[id] = {
|
|
26
|
-
submissions: [],
|
|
27
|
-
submit: async (submission, actionOpts) => {
|
|
28
|
-
var _actionOpts$invalidat;
|
|
29
|
-
if (!route) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const invalidate = (_actionOpts$invalidat = actionOpts == null ? void 0 : actionOpts.invalidate) != null ? _actionOpts$invalidat : true;
|
|
33
|
-
if (!(actionOpts != null && actionOpts.multi)) {
|
|
34
|
-
action.submissions = action.submissions.filter(d => d.isMulti);
|
|
35
|
-
}
|
|
36
|
-
const actionState = {
|
|
37
|
-
submittedAt: Date.now(),
|
|
38
|
-
status: 'pending',
|
|
39
|
-
submission,
|
|
40
|
-
isMulti: !!(actionOpts != null && actionOpts.multi)
|
|
41
|
-
};
|
|
42
|
-
action.current = actionState;
|
|
43
|
-
action.latest = actionState;
|
|
44
|
-
action.submissions.push(actionState);
|
|
45
|
-
router.notify();
|
|
46
|
-
try {
|
|
47
|
-
const res = await (route.options.action == null ? void 0 : route.options.action(submission));
|
|
48
|
-
actionState.data = res;
|
|
49
|
-
if (invalidate) {
|
|
50
|
-
router.invalidateRoute({
|
|
51
|
-
to: '.',
|
|
52
|
-
fromCurrent: true
|
|
53
|
-
});
|
|
54
|
-
await router.reload();
|
|
55
|
-
}
|
|
56
|
-
actionState.status = 'success';
|
|
57
|
-
return res;
|
|
58
|
-
} catch (err) {
|
|
59
|
-
console.error(err);
|
|
60
|
-
actionState.error = err;
|
|
61
|
-
actionState.status = 'error';
|
|
62
|
-
} finally {
|
|
63
|
-
router.notify();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
return router.state.actions[id];
|
|
68
|
-
})();
|
|
69
|
-
const loader = router.state.loaders[id] || (() => {
|
|
70
|
-
router.state.loaders[id] = {
|
|
71
|
-
pending: [],
|
|
72
|
-
fetch: async loaderContext => {
|
|
73
|
-
if (!route) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const loaderState = {
|
|
77
|
-
loadedAt: Date.now(),
|
|
78
|
-
loaderContext
|
|
79
|
-
};
|
|
80
|
-
loader.current = loaderState;
|
|
81
|
-
loader.latest = loaderState;
|
|
82
|
-
loader.pending.push(loaderState);
|
|
83
|
-
|
|
84
|
-
// router.state = {
|
|
85
|
-
// ...router.state,
|
|
86
|
-
// currentAction: loaderState,
|
|
87
|
-
// latestAction: loaderState,
|
|
88
|
-
// }
|
|
89
|
-
|
|
90
|
-
router.notify();
|
|
91
|
-
try {
|
|
92
|
-
return await (route.options.loader == null ? void 0 : route.options.loader(loaderContext));
|
|
93
|
-
} finally {
|
|
94
|
-
loader.pending = loader.pending.filter(d => d !== loaderState);
|
|
95
|
-
// router.removeActionQueue.push({ loader, loaderState })
|
|
96
|
-
router.notify();
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
return router.state.loaders[id];
|
|
101
|
-
})();
|
|
102
24
|
let route = {
|
|
103
25
|
routeInfo: undefined,
|
|
104
26
|
routeId: id,
|
|
105
27
|
routeRouteId: routeId,
|
|
28
|
+
originalIndex,
|
|
106
29
|
routePath,
|
|
107
30
|
fullPath,
|
|
108
31
|
options,
|
|
109
32
|
router,
|
|
110
33
|
childRoutes: undefined,
|
|
111
34
|
parentRoute: parent,
|
|
112
|
-
action
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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;
|
|
118
88
|
},
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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;
|
|
128
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
|
+
// },
|
|
129
145
|
};
|
|
146
|
+
|
|
130
147
|
router.options.createRoute == null ? void 0 : router.options.createRoute({
|
|
131
148
|
router,
|
|
132
149
|
route
|
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'\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 router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo, TRouterContext>\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 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}\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 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 const action =\n router.state.actions[id] ||\n (() => {\n router.state.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 if (!actionOpts?.multi) {\n action.submissions = action.submissions.filter((d) => d.isMulti)\n }\n\n const actionState: ActionState<T, U> = {\n submittedAt: Date.now(),\n status: 'pending',\n submission,\n isMulti: !!actionOpts?.multi,\n }\n\n action.current = actionState\n action.latest = actionState\n action.submissions.push(actionState)\n\n router.notify()\n\n try {\n const res = await route.options.action?.(submission)\n actionState.data = res as U\n\n if (invalidate) {\n router.invalidateRoute({ to: '.', fromCurrent: true })\n await router.reload()\n }\n actionState.status = 'success'\n return res\n } catch (err) {\n console.error(err)\n actionState.error = err\n actionState.status = 'error'\n } finally {\n router.notify()\n }\n },\n }\n return router.state.actions[id]!\n })()\n\n const loader =\n router.state.loaders[id] ||\n (() => {\n router.state.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 loader.current = loaderState\n loader.latest = loaderState\n loader.pending.push(loaderState)\n\n // router.state = {\n // ...router.state,\n // currentAction: loaderState,\n // latestAction: loaderState,\n // }\n\n router.notify()\n\n try {\n return await route.options.loader?.(loaderContext)\n } finally {\n loader.pending = loader.pending.filter((d) => d !== loaderState)\n // router.removeActionQueue.push({ loader, loaderState })\n router.notify()\n }\n }) as any,\n }\n return router.state.loaders[id]!\n })()\n\n let route: Route<TAllRouteInfo, TRouteInfo, TRouterContext> = {\n routeInfo: undefined!,\n routeId: id,\n routeRouteId: routeId,\n routePath,\n fullPath,\n options,\n router,\n childRoutes: undefined!,\n parentRoute: parent,\n action,\n loader: loader as any,\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","parent","router","id","routeId","path","routePath","fullPath","action","state","actions","submissions","submit","submission","actionOpts","route","invalidate","multi","filter","d","isMulti","actionState","submittedAt","Date","now","status","current","latest","push","notify","res","data","invalidateRoute","to","fromCurrent","reload","err","console","error","loader","loaders","pending","fetch","loaderContext","loaderState","loadedAt","routeInfo","undefined","routeRouteId","childRoutes","parentRoute","buildLink","_extends","from","navigate","matchRoute","matchLocation","opts"],"mappings":";;;;;;;;;;;;;;;;AAuFO,SAASA,WAAW,CAKzBC,WAAwB,EACxBC,OAA8B,EAC9BC,MAA6C,EAC7CC,MAA2E,EACzB;EAClD,MAAM;IAAEC,EAAE;IAAEC,OAAO;AAAEC,IAAAA,IAAI,EAAEC,SAAS;AAAEC,IAAAA,QAAAA;AAAS,GAAC,GAAGR,WAAW,CAAA;AAE9D,EAAA,MAAMS,MAAM,GACVN,MAAM,CAACO,KAAK,CAACC,OAAO,CAACP,EAAE,CAAC,IACxB,CAAC,MAAM;AACLD,IAAAA,MAAM,CAACO,KAAK,CAACC,OAAO,CAACP,EAAE,CAAC,GAAG;AACzBQ,MAAAA,WAAW,EAAE,EAAE;AACfC,MAAAA,MAAM,EAAE,OACNC,UAAa,EACbC,UAAsD,KACnD;AAAA,QAAA,IAAA,qBAAA,CAAA;QACH,IAAI,CAACC,KAAK,EAAE;AACV,UAAA,OAAA;AACF,SAAA;QAEA,MAAMC,UAAU,4BAAGF,UAAU,IAAA,IAAA,GAA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OAAO,CAACF,WAAW,IAAA,IAAA,GAAA,KAAA,CAAA,GAA1BI,MAAM,CAACF,OAAO,CAACF,WAAW,CAAG;IAAEI,MAAM;AAAEa,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 {\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,EAAE,CAAC,GAAG;AACdgB,YAAAA,WAAW,EAAE,EAAE;AACfC,YAAAA,MAAM,EAAE,OACNC,UAAa,EACbC,UAAsD,KACnD;cACH,IAAI,CAACd,KAAK,EAAE;AACV,gBAAA,OAAA;AACF,eAAA;cAEA,MAAMe,UAAU,GAAG,CAAAD,UAAU,oBAAVA,UAAU,CAAEC,UAAU,KAAI,IAAI,CAAA;AA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IAAEK,MAAM;AAAEM,IAAAA,KAAAA;AAAM,GAAC,CAAC,CAAA;AAE/C,EAAA,OAAOA,KAAK,CAAA;AACd;;;;"}
|
package/build/cjs/routeConfig.js
CHANGED
|
@@ -20,7 +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 = function
|
|
23
|
+
const createRouteConfig = function (options, children, isRoot, parentId, parentPath) {
|
|
24
24
|
if (options === void 0) {
|
|
25
25
|
options = {};
|
|
26
26
|
}
|
|
@@ -60,7 +60,7 @@ const createRouteConfig = function createRouteConfig(options, children, isRoot,
|
|
|
60
60
|
addChildren: children => createRouteConfig(options, children, false, parentId, parentPath),
|
|
61
61
|
createRoute: childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath),
|
|
62
62
|
generate: () => {
|
|
63
|
-
invariant__default["default"](false,
|
|
63
|
+
invariant__default["default"](false, `routeConfig.generate() is used by TanStack Router's file-based routing code generation and should not actually be called during runtime. `);
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
};
|
|
@@ -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,SAA/CA,iBAA4C,CACvDC,OAAO,EACPC,QAAQ,EACRC,MAAM,EACNC,QAAQ,EACRC,UAAU,EACP;AAAA,EAAA,IALHJ,OAAO,KAAA,KAAA,CAAA,EAAA;IAAPA,OAAO,GAAG,EAAE,CAAA;AAAA,GAAA;AAAA,EAAA,IAEZE,MAAM,KAAA,KAAA,CAAA,EAAA;AAANA,IAAAA,MAAM,GAAG,IAAI,CAAA;AAAA,GAAA;AAIb,EAAA,IAAIA,MAAM,EAAE;IACRF,OAAO,CAASK,IAAI,GAAGP,WAAW,CAAA;AACtC,GAAA;;AAEA;EACA,IAAIK,QAAQ,KAAKL,WAAW,EAAE;AA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,QAAQ,EAAE,MAAM;MACdC,6BAAS,CACP,KAAK,EAEN,2IAAA,CAAA,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 { 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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