@tanstack/react-router 0.0.1-beta.280 → 0.0.1-beta.282
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/Matches.js.map +1 -1
- package/build/cjs/link.js.map +1 -1
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js +48 -30
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +48 -30
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +351 -351
- package/build/types/Matches.d.ts +1 -0
- package/build/types/link.d.ts +1 -1
- package/build/types/route.d.ts +1 -0
- package/build/types/router.d.ts +3 -6
- package/build/umd/index.development.js +48 -30
- 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 -2
- package/src/Matches.tsx +1 -0
- package/src/link.tsx +1 -1
- package/src/route.ts +10 -0
- package/src/router.ts +47 -26
package/build/cjs/Matches.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Matches.js","sources":["../../src/Matches.tsx"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport warning from 'tiny-warning'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouter, useRouterState } from './RouterProvider'\nimport { ResolveRelativePath, ToOptions } from './link'\nimport { AnyRoute, ReactNode, rootRouteId } from './route'\nimport {\n FullSearchSchema,\n ParseRoute,\n RouteById,\n RouteByPath,\n RouteIds,\n RoutePaths,\n} from './routeInfo'\nimport { RegisteredRouter, RouterState } from './router'\nimport { NoInfer, StrictOrFrom, pick } from './utils'\n\nexport const matchContext = React.createContext<string | undefined>(undefined)\n\nexport interface RouteMatch<\n TRouteTree extends AnyRoute = AnyRoute,\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n> {\n id: string\n routeId: TRouteId\n pathname: string\n params: RouteById<TRouteTree, TRouteId>['types']['allParams']\n status: 'pending' | 'success' | 'error'\n isFetching: boolean\n showPending: boolean\n error: unknown\n paramsError: unknown\n searchError: unknown\n updatedAt: number\n loadPromise?: Promise<void>\n loaderData?: RouteById<TRouteTree, TRouteId>['types']['loaderData']\n routeContext: RouteById<TRouteTree, TRouteId>['types']['routeContext']\n context: RouteById<TRouteTree, TRouteId>['types']['allContext']\n search: FullSearchSchema<TRouteTree> &\n RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema']\n fetchCount: number\n abortController: AbortController\n cause: 'preload' | 'enter' | 'stay'\n loaderDeps: RouteById<TRouteTree, TRouteId>['types']['loaderDeps']\n}\n\nexport type AnyRouteMatch = RouteMatch<any, any>\n\nexport function Matches() {\n const router = useRouter()\n const matchId = useRouterState({\n select: (s) => {\n return getRenderedMatches(s)[0]?.id\n },\n })\n\n return (\n <matchContext.Provider value={matchId}>\n <CatchBoundary\n getResetKey={() => router.state.resolvedLocation.state?.key}\n errorComponent={ErrorComponent}\n onCatch={() => {\n warning(\n false,\n `Error in router! Consider setting an 'errorComponent' in your RootRoute! 👍`,\n )\n }}\n >\n {matchId ? <Match matchId={matchId} /> : null}\n </CatchBoundary>\n </matchContext.Provider>\n )\n}\n\nfunction SafeFragment(props: any) {\n return <>{props.children}</>\n}\n\nexport function Match({ matchId }: { matchId: string }) {\n const router = useRouter()\n const routeId = useRouterState({\n select: (s) =>\n getRenderedMatches(s).find((d) => d.id === matchId)?.routeId as string,\n })\n\n invariant(\n routeId,\n `Could not find routeId for matchId \"${matchId}\". Please file an issue!`,\n )\n\n const route = router.routesById[routeId]!\n\n const PendingComponent = (route.options.pendingComponent ??\n router.options.defaultPendingComponent) as any\n\n const pendingElement = PendingComponent ? <PendingComponent /> : null\n\n const routeErrorComponent =\n route.options.errorComponent ??\n router.options.defaultErrorComponent ??\n ErrorComponent\n\n const ResolvedSuspenseBoundary =\n route.options.wrapInSuspense ??\n PendingComponent ??\n route.options.component?.preload ??\n route.options.pendingComponent?.preload ??\n (route.options.errorComponent as any)?.preload\n ? React.Suspense\n : SafeFragment\n\n const ResolvedCatchBoundary = routeErrorComponent\n ? CatchBoundary\n : SafeFragment\n\n return (\n <matchContext.Provider value={matchId}>\n <ResolvedSuspenseBoundary fallback={pendingElement}>\n <ResolvedCatchBoundary\n getResetKey={() => router.state.resolvedLocation.state?.key}\n errorComponent={routeErrorComponent}\n onCatch={() => {\n warning(false, `Error in route match: ${matchId}`)\n }}\n >\n <MatchInner matchId={matchId!} pendingElement={pendingElement} />\n </ResolvedCatchBoundary>\n </ResolvedSuspenseBoundary>\n </matchContext.Provider>\n )\n}\n\nfunction MatchInner({\n matchId,\n pendingElement,\n}: {\n matchId: string\n pendingElement: any\n}): any {\n const router = useRouter()\n const routeId = useRouterState({\n select: (s) =>\n getRenderedMatches(s).find((d) => d.id === matchId)?.routeId as string,\n })\n\n const route = router.routesById[routeId]!\n\n const match = useRouterState({\n select: (s) =>\n pick(getRenderedMatches(s).find((d) => d.id === matchId)!, [\n 'status',\n 'error',\n 'showPending',\n 'loadPromise',\n ]),\n })\n\n if (match.status === 'error') {\n throw match.error\n }\n\n if (match.status === 'pending') {\n if (match.showPending) {\n return pendingElement\n }\n throw match.loadPromise\n }\n\n if (match.status === 'success') {\n let Comp = route.options.component ?? router.options.defaultComponent\n\n if (Comp) {\n return <Comp />\n }\n\n return <Outlet />\n }\n\n invariant(\n false,\n 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!',\n )\n}\n\nexport const Outlet = React.memo(function Outlet() {\n const matchId = React.useContext(matchContext)\n\n const childMatchId = useRouterState({\n select: (s) => {\n const matches = getRenderedMatches(s)\n const index = matches.findIndex((d) => d.id === matchId)\n return matches[index + 1]?.id\n },\n })\n\n if (!childMatchId) {\n return null\n }\n\n return <Match matchId={childMatchId} />\n})\n\nexport interface MatchRouteOptions {\n pending?: boolean\n caseSensitive?: boolean\n includeSearch?: boolean\n fuzzy?: boolean\n}\n\nexport type UseMatchRouteOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n> = ToOptions<AnyRoute, TFrom, TTo, TMaskFrom, TMaskTo> & MatchRouteOptions\n\nexport function useMatchRoute<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n>() {\n useRouterState({ select: (s) => [s.location, s.resolvedLocation] })\n const { matchRoute } = useRouter()\n\n return React.useCallback(\n <\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n TResolved extends string = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n >(\n opts: UseMatchRouteOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n ): false | RouteById<TRouteTree, TResolved>['types']['allParams'] => {\n const { pending, caseSensitive, ...rest } = opts\n\n return matchRoute(rest as any, {\n pending,\n caseSensitive,\n })\n },\n [],\n )\n}\n\nexport type MakeMatchRouteOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n> = ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> &\n MatchRouteOptions & {\n // If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns\n children?:\n | ((\n params?: RouteByPath<\n TRouteTree,\n ResolveRelativePath<TFrom, NoInfer<TTo>>\n >['types']['allParams'],\n ) => ReactNode)\n | React.ReactNode\n }\n\nexport function MatchRoute<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n>(\n props: MakeMatchRouteOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n): any {\n const matchRoute = useMatchRoute()\n const params = matchRoute(props as any)\n\n if (typeof props.children === 'function') {\n return (props.children as any)(params)\n }\n\n return !!params ? props.children : null\n}\n\nfunction getRenderedMatches(state: RouterState) {\n return state.pendingMatches?.some((d) => d.showPending)\n ? state.pendingMatches\n : state.matches\n}\n\nexport function useMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TRouteMatchState = RouteMatch<TRouteTree, TFrom>,\n TSelected = TRouteMatchState,\n>(\n opts: StrictOrFrom<TFrom> & {\n select?: (match: TRouteMatchState) => TSelected\n },\n): TStrict extends true ? TSelected : TSelected | undefined {\n const router = useRouter()\n const nearestMatchId = React.useContext(matchContext)\n\n const nearestMatchRouteId = getRenderedMatches(router.state).find(\n (d) => d.id === nearestMatchId,\n )?.routeId\n\n const matchRouteId = (() => {\n const matches = getRenderedMatches(router.state)\n const match = opts?.from\n ? matches.find((d) => d.routeId === opts?.from)\n : matches.find((d) => d.id === nearestMatchId)\n return match!.routeId\n })()\n\n if (opts?.strict ?? true) {\n invariant(\n nearestMatchRouteId == matchRouteId,\n `useMatch(\"${\n matchRouteId as string\n }\") is being called in a component that is meant to render the '${nearestMatchRouteId}' route. Did you mean to 'useMatch(\"${\n matchRouteId as string\n }\", { strict: false })' or 'useRoute(\"${\n matchRouteId as string\n }\")' instead?`,\n )\n }\n\n const matchSelection = useRouterState({\n select: (state) => {\n const match = getRenderedMatches(state).find(\n (d) => d.id === nearestMatchId,\n )\n\n invariant(\n match,\n `Could not find ${\n opts?.from\n ? `an active match from \"${opts.from}\"`\n : 'a nearest match!'\n }`,\n )\n\n return opts?.select ? opts.select(match as any) : match\n },\n })\n\n return matchSelection as any\n}\n\nexport function useMatches<T = RouteMatch[]>(opts?: {\n select?: (matches: RouteMatch[]) => T\n}): T {\n return useRouterState({\n select: (state) => {\n let matches = getRenderedMatches(state)\n return opts?.select ? opts.select(matches) : (matches as T)\n },\n })\n}\n\nexport function useParentMatches<T = RouteMatch[]>(opts?: {\n select?: (matches: RouteMatch[]) => T\n}): T {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches) => {\n matches = matches.slice(matches.findIndex((d) => d.id === contextMatchId))\n return opts?.select ? opts.select(matches) : (matches as T)\n },\n })\n}\n\nexport function useLoaderDeps<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TRouteMatch extends RouteMatch<TRouteTree, TFrom> = RouteMatch<\n TRouteTree,\n TFrom\n >,\n TSelected = Required<TRouteMatch>['loaderDeps'],\n>(\n opts: StrictOrFrom<TFrom> & {\n select?: (match: TRouteMatch) => TSelected\n },\n): TStrict extends true ? TSelected : TSelected | undefined {\n return useMatch({\n ...opts,\n select: (s) => {\n return typeof opts.select === 'function'\n ? opts.select(s?.loaderDeps)\n : s?.loaderDeps\n },\n })!\n}\n\nexport function useLoaderData<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TRouteMatch extends RouteMatch<TRouteTree, TFrom> = RouteMatch<\n TRouteTree,\n TFrom\n >,\n TSelected = Required<TRouteMatch>['loaderData'],\n>(\n opts: StrictOrFrom<TFrom> & {\n select?: (match: TRouteMatch) => TSelected\n },\n): TStrict extends true ? TSelected : TSelected | undefined {\n return useMatch({\n ...opts,\n select: (s) => {\n return typeof opts.select === 'function'\n ? opts.select(s?.loaderData)\n : s?.loaderData\n },\n })!\n}\n"],"names":["matchContext","React","createContext","undefined","Matches","router","useRouter","matchId","useRouterState","select","s","getRenderedMatches","id","createElement","Provider","value","CatchBoundary","getResetKey","state","resolvedLocation","key","errorComponent","ErrorComponent","onCatch","warning","Match","SafeFragment","props","Fragment","children","routeId","find","d","invariant","route","routesById","PendingComponent","options","pendingComponent","defaultPendingComponent","pendingElement","routeErrorComponent","defaultErrorComponent","ResolvedSuspenseBoundary","wrapInSuspense","component","preload","Suspense","ResolvedCatchBoundary","fallback","MatchInner","match","pick","status","error","showPending","loadPromise","Comp","defaultComponent","Outlet","memo","useContext","childMatchId","matches","index","findIndex","useMatchRoute","location","matchRoute","useCallback","opts","pending","caseSensitive","rest","MatchRoute","params","pendingMatches","some","useMatch","nearestMatchId","nearestMatchRouteId","matchRouteId","from","strict","matchSelection","useMatches","useParentMatches","contextMatchId","slice","useLoaderDeps","loaderDeps","useLoaderData","loaderData"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBO,MAAMA,YAAY,gBAAGC,gBAAK,CAACC,aAAa,CAAqBC,SAAS,EAAC;AA+BvE,SAASC,OAAOA,GAAG;AACxB,EAAA,MAAMC,MAAM,GAAGC,wBAAS,EAAE,CAAA;EAC1B,MAAMC,OAAO,GAAGC,6BAAc,CAAC;IAC7BC,MAAM,EAAGC,CAAC,IAAK;MACb,OAAOC,kBAAkB,CAACD,CAAC,CAAC,CAAC,CAAC,CAAC,EAAEE,EAAE,CAAA;AACrC,KAAA;AACF,GAAC,CAAC,CAAA;AAEF,EAAA,oBACEX,gBAAA,CAAAY,aAAA,CAACb,YAAY,CAACc,QAAQ,EAAA;AAACC,IAAAA,KAAK,EAAER,OAAAA;AAAQ,GAAA,eACpCN,gBAAA,CAAAY,aAAA,CAACG,2BAAa,EAAA;IACZC,WAAW,EAAEA,MAAMZ,MAAM,CAACa,KAAK,CAACC,gBAAgB,CAACD,KAAK,EAAEE,GAAI;AAC5DC,IAAAA,cAAc,EAAEC,4BAAe;IAC/BC,OAAO,EAAEA,MAAM;AACbC,MAAAA,OAAO,CACL,KAAK,EACJ,CAAA,2EAAA,CACH,CAAC,CAAA;AACH,KAAA;AAAE,GAAA,EAEDjB,OAAO,gBAAGN,gBAAA,CAAAY,aAAA,CAACY,KAAK,EAAA;AAAClB,IA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;;;"}
|
|
1
|
+
{"version":3,"file":"Matches.js","sources":["../../src/Matches.tsx"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport warning from 'tiny-warning'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouter, useRouterState } from './RouterProvider'\nimport { ResolveRelativePath, ToOptions } from './link'\nimport { AnyRoute, ReactNode, rootRouteId } from './route'\nimport {\n FullSearchSchema,\n ParseRoute,\n RouteById,\n RouteByPath,\n RouteIds,\n RoutePaths,\n} from './routeInfo'\nimport { RegisteredRouter, RouterState } from './router'\nimport { NoInfer, StrictOrFrom, pick } from './utils'\n\nexport const matchContext = React.createContext<string | undefined>(undefined)\n\nexport interface RouteMatch<\n TRouteTree extends AnyRoute = AnyRoute,\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n> {\n id: string\n routeId: TRouteId\n pathname: string\n params: RouteById<TRouteTree, TRouteId>['types']['allParams']\n status: 'pending' | 'success' | 'error'\n isFetching: boolean\n showPending: boolean\n error: unknown\n paramsError: unknown\n searchError: unknown\n updatedAt: number\n loadPromise?: Promise<void>\n loaderData?: RouteById<TRouteTree, TRouteId>['types']['loaderData']\n routeContext: RouteById<TRouteTree, TRouteId>['types']['routeContext']\n context: RouteById<TRouteTree, TRouteId>['types']['allContext']\n search: FullSearchSchema<TRouteTree> &\n RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema']\n fetchCount: number\n abortController: AbortController\n cause: 'preload' | 'enter' | 'stay'\n loaderDeps: RouteById<TRouteTree, TRouteId>['types']['loaderDeps']\n invalid: boolean\n}\n\nexport type AnyRouteMatch = RouteMatch<any, any>\n\nexport function Matches() {\n const router = useRouter()\n const matchId = useRouterState({\n select: (s) => {\n return getRenderedMatches(s)[0]?.id\n },\n })\n\n return (\n <matchContext.Provider value={matchId}>\n <CatchBoundary\n getResetKey={() => router.state.resolvedLocation.state?.key}\n errorComponent={ErrorComponent}\n onCatch={() => {\n warning(\n false,\n `Error in router! Consider setting an 'errorComponent' in your RootRoute! 👍`,\n )\n }}\n >\n {matchId ? <Match matchId={matchId} /> : null}\n </CatchBoundary>\n </matchContext.Provider>\n )\n}\n\nfunction SafeFragment(props: any) {\n return <>{props.children}</>\n}\n\nexport function Match({ matchId }: { matchId: string }) {\n const router = useRouter()\n const routeId = useRouterState({\n select: (s) =>\n getRenderedMatches(s).find((d) => d.id === matchId)?.routeId as string,\n })\n\n invariant(\n routeId,\n `Could not find routeId for matchId \"${matchId}\". Please file an issue!`,\n )\n\n const route = router.routesById[routeId]!\n\n const PendingComponent = (route.options.pendingComponent ??\n router.options.defaultPendingComponent) as any\n\n const pendingElement = PendingComponent ? <PendingComponent /> : null\n\n const routeErrorComponent =\n route.options.errorComponent ??\n router.options.defaultErrorComponent ??\n ErrorComponent\n\n const ResolvedSuspenseBoundary =\n route.options.wrapInSuspense ??\n PendingComponent ??\n route.options.component?.preload ??\n route.options.pendingComponent?.preload ??\n (route.options.errorComponent as any)?.preload\n ? React.Suspense\n : SafeFragment\n\n const ResolvedCatchBoundary = routeErrorComponent\n ? CatchBoundary\n : SafeFragment\n\n return (\n <matchContext.Provider value={matchId}>\n <ResolvedSuspenseBoundary fallback={pendingElement}>\n <ResolvedCatchBoundary\n getResetKey={() => router.state.resolvedLocation.state?.key}\n errorComponent={routeErrorComponent}\n onCatch={() => {\n warning(false, `Error in route match: ${matchId}`)\n }}\n >\n <MatchInner matchId={matchId!} pendingElement={pendingElement} />\n </ResolvedCatchBoundary>\n </ResolvedSuspenseBoundary>\n </matchContext.Provider>\n )\n}\n\nfunction MatchInner({\n matchId,\n pendingElement,\n}: {\n matchId: string\n pendingElement: any\n}): any {\n const router = useRouter()\n const routeId = useRouterState({\n select: (s) =>\n getRenderedMatches(s).find((d) => d.id === matchId)?.routeId as string,\n })\n\n const route = router.routesById[routeId]!\n\n const match = useRouterState({\n select: (s) =>\n pick(getRenderedMatches(s).find((d) => d.id === matchId)!, [\n 'status',\n 'error',\n 'showPending',\n 'loadPromise',\n ]),\n })\n\n if (match.status === 'error') {\n throw match.error\n }\n\n if (match.status === 'pending') {\n if (match.showPending) {\n return pendingElement\n }\n throw match.loadPromise\n }\n\n if (match.status === 'success') {\n let Comp = route.options.component ?? router.options.defaultComponent\n\n if (Comp) {\n return <Comp />\n }\n\n return <Outlet />\n }\n\n invariant(\n false,\n 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!',\n )\n}\n\nexport const Outlet = React.memo(function Outlet() {\n const matchId = React.useContext(matchContext)\n\n const childMatchId = useRouterState({\n select: (s) => {\n const matches = getRenderedMatches(s)\n const index = matches.findIndex((d) => d.id === matchId)\n return matches[index + 1]?.id\n },\n })\n\n if (!childMatchId) {\n return null\n }\n\n return <Match matchId={childMatchId} />\n})\n\nexport interface MatchRouteOptions {\n pending?: boolean\n caseSensitive?: boolean\n includeSearch?: boolean\n fuzzy?: boolean\n}\n\nexport type UseMatchRouteOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n> = ToOptions<AnyRoute, TFrom, TTo, TMaskFrom, TMaskTo> & MatchRouteOptions\n\nexport function useMatchRoute<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n>() {\n useRouterState({ select: (s) => [s.location, s.resolvedLocation] })\n const { matchRoute } = useRouter()\n\n return React.useCallback(\n <\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n TResolved extends string = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n >(\n opts: UseMatchRouteOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n ): false | RouteById<TRouteTree, TResolved>['types']['allParams'] => {\n const { pending, caseSensitive, ...rest } = opts\n\n return matchRoute(rest as any, {\n pending,\n caseSensitive,\n })\n },\n [],\n )\n}\n\nexport type MakeMatchRouteOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n> = ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> &\n MatchRouteOptions & {\n // If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns\n children?:\n | ((\n params?: RouteByPath<\n TRouteTree,\n ResolveRelativePath<TFrom, NoInfer<TTo>>\n >['types']['allParams'],\n ) => ReactNode)\n | React.ReactNode\n }\n\nexport function MatchRoute<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n>(\n props: MakeMatchRouteOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n): any {\n const matchRoute = useMatchRoute()\n const params = matchRoute(props as any)\n\n if (typeof props.children === 'function') {\n return (props.children as any)(params)\n }\n\n return !!params ? props.children : null\n}\n\nfunction getRenderedMatches(state: RouterState) {\n return state.pendingMatches?.some((d) => d.showPending)\n ? state.pendingMatches\n : state.matches\n}\n\nexport function useMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TRouteMatchState = RouteMatch<TRouteTree, TFrom>,\n TSelected = TRouteMatchState,\n>(\n opts: StrictOrFrom<TFrom> & {\n select?: (match: TRouteMatchState) => TSelected\n },\n): TStrict extends true ? TSelected : TSelected | undefined {\n const router = useRouter()\n const nearestMatchId = React.useContext(matchContext)\n\n const nearestMatchRouteId = getRenderedMatches(router.state).find(\n (d) => d.id === nearestMatchId,\n )?.routeId\n\n const matchRouteId = (() => {\n const matches = getRenderedMatches(router.state)\n const match = opts?.from\n ? matches.find((d) => d.routeId === opts?.from)\n : matches.find((d) => d.id === nearestMatchId)\n return match!.routeId\n })()\n\n if (opts?.strict ?? true) {\n invariant(\n nearestMatchRouteId == matchRouteId,\n `useMatch(\"${\n matchRouteId as string\n }\") is being called in a component that is meant to render the '${nearestMatchRouteId}' route. Did you mean to 'useMatch(\"${\n matchRouteId as string\n }\", { strict: false })' or 'useRoute(\"${\n matchRouteId as string\n }\")' instead?`,\n )\n }\n\n const matchSelection = useRouterState({\n select: (state) => {\n const match = getRenderedMatches(state).find(\n (d) => d.id === nearestMatchId,\n )\n\n invariant(\n match,\n `Could not find ${\n opts?.from\n ? `an active match from \"${opts.from}\"`\n : 'a nearest match!'\n }`,\n )\n\n return opts?.select ? opts.select(match as any) : match\n },\n })\n\n return matchSelection as any\n}\n\nexport function useMatches<T = RouteMatch[]>(opts?: {\n select?: (matches: RouteMatch[]) => T\n}): T {\n return useRouterState({\n select: (state) => {\n let matches = getRenderedMatches(state)\n return opts?.select ? opts.select(matches) : (matches as T)\n },\n })\n}\n\nexport function useParentMatches<T = RouteMatch[]>(opts?: {\n select?: (matches: RouteMatch[]) => T\n}): T {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches) => {\n matches = matches.slice(matches.findIndex((d) => d.id === contextMatchId))\n return opts?.select ? opts.select(matches) : (matches as T)\n },\n })\n}\n\nexport function useLoaderDeps<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TRouteMatch extends RouteMatch<TRouteTree, TFrom> = RouteMatch<\n TRouteTree,\n TFrom\n >,\n TSelected = Required<TRouteMatch>['loaderDeps'],\n>(\n opts: StrictOrFrom<TFrom> & {\n select?: (match: TRouteMatch) => TSelected\n },\n): TStrict extends true ? TSelected : TSelected | undefined {\n return useMatch({\n ...opts,\n select: (s) => {\n return typeof opts.select === 'function'\n ? opts.select(s?.loaderDeps)\n : s?.loaderDeps\n },\n })!\n}\n\nexport function useLoaderData<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TRouteMatch extends RouteMatch<TRouteTree, TFrom> = RouteMatch<\n TRouteTree,\n TFrom\n >,\n TSelected = Required<TRouteMatch>['loaderData'],\n>(\n opts: StrictOrFrom<TFrom> & {\n select?: (match: TRouteMatch) => TSelected\n },\n): TStrict extends true ? TSelected : TSelected | undefined {\n return useMatch({\n ...opts,\n select: (s) => {\n return typeof opts.select === 'function'\n ? opts.select(s?.loaderData)\n : s?.loaderData\n },\n })!\n}\n"],"names":["matchContext","React","createContext","undefined","Matches","router","useRouter","matchId","useRouterState","select","s","getRenderedMatches","id","createElement","Provider","value","CatchBoundary","getResetKey","state","resolvedLocation","key","errorComponent","ErrorComponent","onCatch","warning","Match","SafeFragment","props","Fragment","children","routeId","find","d","invariant","route","routesById","PendingComponent","options","pendingComponent","defaultPendingComponent","pendingElement","routeErrorComponent","defaultErrorComponent","ResolvedSuspenseBoundary","wrapInSuspense","component","preload","Suspense","ResolvedCatchBoundary","fallback","MatchInner","match","pick","status","error","showPending","loadPromise","Comp","defaultComponent","Outlet","memo","useContext","childMatchId","matches","index","findIndex","useMatchRoute","location","matchRoute","useCallback","opts","pending","caseSensitive","rest","MatchRoute","params","pendingMatches","some","useMatch","nearestMatchId","nearestMatchRouteId","matchRouteId","from","strict","matchSelection","useMatches","useParentMatches","contextMatchId","slice","useLoaderDeps","loaderDeps","useLoaderData","loaderData"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBO,MAAMA,YAAY,gBAAGC,gBAAK,CAACC,aAAa,CAAqBC,SAAS,EAAC;AAgCvE,SAASC,OAAOA,GAAG;AACxB,EAAA,MAAMC,MAAM,GAAGC,wBAAS,EAAE,CAAA;EAC1B,MAAMC,OAAO,GAAGC,6BAAc,CAAC;IAC7BC,MAAM,EAAGC,C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IAAA,GAAGR,IAAI;IACP7D,MAAM,EAAGC,CAAC,IAAK;AACb,MAAA,OAAO,OAAO4D,IAAI,CAAC7D,MAAM,KAAK,UAAU,GACpC6D,IAAI,CAAC7D,MAAM,CAACC,CAAC,EAAEgF,UAAU,CAAC,GAC1BhF,CAAC,EAAEgF,UAAU,CAAA;AACnB,KAAA;AACF,GAAC,CAAC,CAAA;AACJ,CAAA;AAEO,SAASC,aAAaA,CAU3BrB,IAEC,EACyD;AAC1D,EAAA,OAAOQ,QAAQ,CAAC;AACd,IAAA,GAAGR,IAAI;IACP7D,MAAM,EAAGC,CAAC,IAAK;AACb,MAAA,OAAO,OAAO4D,IAAI,CAAC7D,MAAM,KAAK,UAAU,GACpC6D,IAAI,CAAC7D,MAAM,CAACC,CAAC,EAAEkF,UAAU,CAAC,GAC1BlF,CAAC,EAAEkF,UAAU,CAAA;AACnB,KAAA;AACF,GAAC,CAAC,CAAA;AACJ;;;;;;;;;;;;;;"}
|
package/build/cjs/link.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.js","sources":["../../src/link.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useMatch } from './Matches'\nimport { useRouter, useRouterState } from './RouterProvider'\nimport { Trim } from './fileRoute'\nimport { AnyRoute, ReactNode } from './route'\nimport {\n AllParams,\n FullSearchSchema,\n RouteByPath,\n RouteIds,\n RoutePaths,\n} from './routeInfo'\nimport { RegisteredRouter } from './router'\nimport { LinkProps, UseLinkPropsOptions } from './useNavigate'\nimport {\n Expand,\n NoInfer,\n NonNullableUpdater,\n PickRequired,\n UnionToIntersection,\n Updater,\n deepEqual,\n functionalUpdate,\n} from './utils'\nimport { HistoryState } from '@tanstack/history'\n\nexport type CleanPath<T extends string> = T extends `${infer L}//${infer R}`\n ? CleanPath<`${CleanPath<L>}/${CleanPath<R>}`>\n : T extends `${infer L}//`\n ? `${CleanPath<L>}/`\n : T extends `//${infer L}`\n ? `/${CleanPath<L>}`\n : T\n\nexport type Split<S, TIncludeTrailingSlash = true> = S extends unknown\n ? string extends S\n ? string[]\n : S extends string\n ? CleanPath<S> extends ''\n ? []\n : TIncludeTrailingSlash extends true\n ? CleanPath<S> extends `${infer T}/`\n ? [...Split<T>, '/']\n : CleanPath<S> extends `/${infer U}`\n ? Split<U>\n : CleanPath<S> extends `${infer T}/${infer U}`\n ? [...Split<T>, ...Split<U>]\n : [S]\n : CleanPath<S> extends `${infer T}/${infer U}`\n ? [...Split<T>, ...Split<U>]\n : S extends string\n ? [S]\n : never\n : never\n : never\n\nexport type ParsePathParams<T extends string> = keyof {\n [K in Trim<Split<T>[number], '_'> as K extends `$${infer L}` ? L : never]: K\n}\n\nexport type Join<T, Delimiter extends string = '/'> = T extends []\n ? ''\n : T extends [infer L extends string]\n ? L\n : T extends [infer L extends string, ...infer Tail extends [...string[]]]\n ? CleanPath<`${L}${Delimiter}${Join<Tail>}`>\n : never\n\nexport type Last<T extends any[]> = T extends [...infer _, infer L] ? L : never\n\nexport type RelativeToPathAutoComplete<\n AllPaths extends string,\n TFrom extends string,\n TTo extends string,\n SplitPaths extends string[] = Split<AllPaths, false>,\n> = TTo extends `..${infer _}`\n ? SplitPaths extends [\n ...Split<ResolveRelativePath<TFrom, TTo>, false>,\n ...infer TToRest,\n ]\n ? `${CleanPath<\n Join<\n [\n ...Split<TTo, false>,\n ...(\n | TToRest\n | (Split<\n ResolveRelativePath<TFrom, TTo>,\n false\n >['length'] extends 1\n ? never\n : ['../'])\n ),\n ]\n >\n >}`\n : never\n : TTo extends `./${infer RestTTo}`\n ? SplitPaths extends [\n ...Split<TFrom, false>,\n ...Split<RestTTo, false>,\n ...infer RestPath,\n ]\n ? `${TTo}${Join<RestPath>}`\n : never\n :\n | (TFrom extends `/`\n ? never\n : SplitPaths extends [...Split<TFrom, false>, ...infer RestPath]\n ? Join<RestPath> extends { length: 0 }\n ? never\n : './'\n : never)\n | (TFrom extends `/` ? never : '../')\n | AllPaths\n\nexport type NavigateOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = TFrom,\n TMaskTo extends string = '',\n> = ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // `replace` is a boolean that determines whether the navigation should replace the current history entry or push a new one.\n replace?: boolean\n resetScroll?: boolean\n // If set to `true`, the link's underlying navigate() call will be wrapped in a `React.startTransition` call. Defaults to `true`.\n startTransition?: boolean\n}\n\nexport type ToOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n> = ToSubOptions<TRouteTree, TFrom, TTo> & {\n mask?: ToMaskOptions<TRouteTree, TMaskFrom, TMaskTo>\n}\n\nexport type ToMaskOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n> = ToSubOptions<TRouteTree, TMaskFrom, TMaskTo> & {\n unmaskOnReload?: boolean\n}\n\nexport type ToSubOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n> = {\n to?: ToPathOption<TRouteTree, TFrom, TTo>\n // The new has string or a function to update it\n hash?: true | Updater<string>\n // State to pass to the history stack\n state?: true | NonNullableUpdater<HistoryState>\n // The source route path. This is automatically set when using route-level APIs, but for type-safe relative routing on the router itself, this is required\n from?: TFrom\n // // When using relative route paths, this option forces resolution from the current path, instead of the route API's path or `from` path\n} & CheckPath<TRouteTree, NoInfer<TResolved>, {}> &\n SearchParamOptions<TRouteTree, TFrom, TTo, TResolved> &\n PathParamOptions<TRouteTree, TFrom, TResolved>\n\nexport type SearchParamOptions<\n TRouteTree extends AnyRoute,\n TFrom,\n TTo,\n TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n TFromSearchEnsured = '/' extends TFrom\n ? FullSearchSchema<TRouteTree>\n : Expand<\n UnionToIntersection<\n PickRequired<\n RouteByPath<TRouteTree, TFrom>['types']['fullSearchSchema']\n >\n >\n >,\n TFromSearchOptional = Omit<AllParams<TRouteTree>, keyof TFromSearchEnsured>,\n TFromSearch = Expand<TFromSearchEnsured & TFromSearchOptional>,\n TToSearch = '' extends TTo\n ? FullSearchSchema<TRouteTree>\n : Expand<RouteByPath<TRouteTree, TResolved>['types']['fullSearchSchema']>,\n> = keyof PickRequired<TToSearch> extends never\n ? {\n search?: true | SearchReducer<TFromSearch, TToSearch>\n }\n : {\n search: TFromSearchEnsured extends PickRequired<TToSearch>\n ? true | SearchReducer<TFromSearch, TToSearch>\n : SearchReducer<TFromSearch, TToSearch>\n }\n\ntype SearchReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo)\n\nexport type PathParamOptions<\n TRouteTree extends AnyRoute,\n TFrom,\n TTo,\n TFromParamsEnsured = Expand<\n UnionToIntersection<\n PickRequired<RouteByPath<TRouteTree, TFrom>['types']['allParams']>\n >\n >,\n TFromParamsOptional = Omit<AllParams<TRouteTree>, keyof TFromParamsEnsured>,\n TFromParams = Expand<TFromParamsOptional & TFromParamsEnsured>,\n TToParams = Expand<RouteByPath<TRouteTree, TTo>['types']['allParams']>,\n> = keyof PickRequired<TToParams> extends never\n ? {\n params?: true | ParamsReducer<TFromParams, TToParams>\n }\n : {\n params: TFromParamsEnsured extends PickRequired<TToParams>\n ? true | ParamsReducer<TFromParams, TToParams>\n : ParamsReducer<TFromParams, TToParams>\n }\n\ntype ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo)\n\nexport type ToPathOption<\n TRouteTree extends AnyRoute = AnyRoute,\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n> =\n | TTo\n | RelativeToPathAutoComplete<\n RoutePaths<TRouteTree>,\n NoInfer<TFrom> extends string ? NoInfer<TFrom> : '',\n NoInfer<TTo> & string\n >\n\nexport type ToIdOption<\n TRouteTree extends AnyRoute = AnyRoute,\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n> =\n | TTo\n | RelativeToPathAutoComplete<\n RouteIds<TRouteTree>,\n NoInfer<TFrom> extends string ? NoInfer<TFrom> : '',\n NoInfer<TTo> & string\n >\n\nexport interface ActiveOptions {\n exact?: boolean\n includeHash?: boolean\n includeSearch?: boolean\n}\n\nexport type LinkOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = TFrom,\n TMaskTo extends string = '',\n> = NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // The standard anchor tag target attribute\n target?: HTMLAnchorElement['target']\n // Defaults to `{ exact: false, includeHash: false }`\n activeOptions?: ActiveOptions\n // If set, will preload the linked route on hover and cache it for this many milliseconds in hopes that the user will eventually navigate there.\n preload?: false | 'intent'\n // Delay intent preloading by this many milliseconds. If the intent exits before this delay, the preload will be cancelled.\n preloadDelay?: number\n // If true, will render the link without the href attribute\n disabled?: boolean\n}\n\nexport type CheckRelativePath<\n TRouteTree extends AnyRoute,\n TFrom,\n TTo,\n> = TTo extends string\n ? TFrom extends string\n ? ResolveRelativePath<TFrom, TTo> extends RoutePaths<TRouteTree>\n ? {}\n : {\n Error: `${TFrom} + ${TTo} resolves to ${ResolveRelativePath<\n TFrom,\n TTo\n >}, which is not a valid route path.`\n 'Valid Route Paths': RoutePaths<TRouteTree>\n }\n : {}\n : {}\n\nexport type CheckPath<TRouteTree extends AnyRoute, TPath, TPass> = Exclude<\n TPath,\n RoutePaths<TRouteTree>\n> extends never\n ? TPass\n : CheckPathError<TRouteTree, Exclude<TPath, RoutePaths<TRouteTree>>>\n\nexport type CheckPathError<TRouteTree extends AnyRoute, TInvalids> = {\n to: RoutePaths<TRouteTree>\n}\n\nexport type CheckId<TRouteTree extends AnyRoute, TPath, TPass> = Exclude<\n TPath,\n RouteIds<TRouteTree>\n> extends never\n ? TPass\n : CheckIdError<TRouteTree, Exclude<TPath, RouteIds<TRouteTree>>>\n\nexport type CheckIdError<TRouteTree extends AnyRoute, TInvalids> = {\n Error: `${TInvalids extends string\n ? TInvalids\n : never} is not a valid route ID.`\n 'Valid Route IDs': RouteIds<TRouteTree>\n}\n\nexport type ResolveRelativePath<TFrom, TTo = '.'> = TFrom extends string\n ? TTo extends string\n ? TTo extends '.'\n ? TFrom\n : TTo extends `./`\n ? Join<[TFrom, '/']>\n : TTo extends `./${infer TRest}`\n ? ResolveRelativePath<TFrom, TRest>\n : TTo extends `/${infer TRest}`\n ? TTo\n : Split<TTo> extends ['..', ...infer ToRest]\n ? Split<TFrom> extends [...infer FromRest, infer FromTail]\n ? ToRest extends ['/']\n ? Join<[...FromRest, '/']>\n : ResolveRelativePath<Join<FromRest>, Join<ToRest>>\n : never\n : Split<TTo> extends ['.', ...infer ToRest]\n ? ToRest extends ['/']\n ? Join<[TFrom, '/']>\n : ResolveRelativePath<TFrom, Join<ToRest>>\n : CleanPath<Join<['/', ...Split<TFrom>, ...Split<TTo>]>>\n : never\n : never\n\ntype LinkCurrentTargetElement = {\n preloadTimeout?: null | ReturnType<typeof setTimeout>\n}\n\nconst preloadWarning = 'Error preloading route! ☝️'\n\nexport function useLinkProps<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n>(\n options: UseLinkPropsOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n): React.AnchorHTMLAttributes<HTMLAnchorElement> {\n const router = useRouter()\n const matchPathname = useMatch({\n strict: false,\n select: (s) => s.pathname,\n })\n\n const {\n // custom props\n children,\n target,\n activeProps = () => ({ className: 'active' }),\n inactiveProps = () => ({}),\n activeOptions,\n disabled,\n hash,\n search,\n params,\n to,\n state,\n mask,\n preload: userPreload,\n preloadDelay: userPreloadDelay,\n replace,\n startTransition,\n resetScroll,\n // element props\n style,\n className,\n onClick,\n onFocus,\n onMouseEnter,\n onMouseLeave,\n onTouchStart,\n ...rest\n } = options\n\n // If this link simply reloads the current route,\n // make sure it has a new key so it will trigger a data refresh\n\n // If this `to` is a valid external URL, return\n // null for LinkUtils\n\n const dest = {\n from: options.to ? matchPathname : undefined,\n ...options,\n }\n\n let type: 'internal' | 'external' = 'internal'\n\n try {\n new URL(`${to}`)\n type = 'external'\n } catch {}\n\n if (type === 'external') {\n return {\n href: to,\n }\n }\n\n const next = router.buildLocation(dest as any)\n\n const preload = userPreload ?? router.options.defaultPreload\n const preloadDelay =\n userPreloadDelay ?? router.options.defaultPreloadDelay ?? 0\n\n const isActive = useRouterState({\n select: (s) => {\n // Compare path/hash for matches\n const currentPathSplit = s.location.pathname.split('/')\n const nextPathSplit = next.pathname.split('/')\n const pathIsFuzzyEqual = nextPathSplit.every(\n (d, i) => d === currentPathSplit[i],\n )\n // Combine the matches based on user router.options\n const pathTest = activeOptions?.exact\n ? s.location.pathname === next.pathname\n : pathIsFuzzyEqual\n const hashTest = activeOptions?.includeHash\n ? s.location.hash === next.hash\n : true\n const searchTest =\n activeOptions?.includeSearch ?? true\n ? deepEqual(s.location.search, next.search, !activeOptions?.exact)\n : true\n\n // The final \"active\" test\n return pathTest && hashTest && searchTest\n },\n })\n\n // The click handler\n const handleClick = (e: MouseEvent) => {\n if (\n !disabled &&\n !isCtrlEvent(e) &&\n !e.defaultPrevented &&\n (!target || target === '_self') &&\n e.button === 0\n ) {\n e.preventDefault()\n\n // All is well? Navigate!\n router.commitLocation({ ...next, replace, resetScroll, startTransition })\n }\n }\n\n // The click handler\n const handleFocus = (e: MouseEvent) => {\n if (preload) {\n router.preloadRoute(dest as any).catch((err) => {\n console.warn(err)\n console.warn(preloadWarning)\n })\n }\n }\n\n const handleTouchStart = (e: TouchEvent) => {\n if (preload) {\n router.preloadRoute(dest as any).catch((err) => {\n console.warn(err)\n console.warn(preloadWarning)\n })\n }\n }\n\n const handleEnter = (e: MouseEvent) => {\n const target = (e.target || {}) as LinkCurrentTargetElement\n\n if (preload) {\n if (target.preloadTimeout) {\n return\n }\n\n target.preloadTimeout = setTimeout(() => {\n target.preloadTimeout = null\n router.preloadRoute(dest as any).catch((err) => {\n console.warn(err)\n console.warn(preloadWarning)\n })\n }, preloadDelay)\n }\n }\n\n const handleLeave = (e: MouseEvent) => {\n const target = (e.target || {}) as LinkCurrentTargetElement\n\n if (target.preloadTimeout) {\n clearTimeout(target.preloadTimeout)\n target.preloadTimeout = null\n }\n }\n\n const composeHandlers =\n (handlers: (undefined | ((e: any) => void))[]) =>\n (e: React.SyntheticEvent) => {\n if (e.persist) e.persist()\n handlers.filter(Boolean).forEach((handler) => {\n if (e.defaultPrevented) return\n handler!(e)\n })\n }\n\n // Get the active props\n const resolvedActiveProps: React.HTMLAttributes<HTMLAnchorElement> = isActive\n ? functionalUpdate(activeProps as any, {}) ?? {}\n : {}\n\n // Get the inactive props\n const resolvedInactiveProps: React.HTMLAttributes<HTMLAnchorElement> =\n isActive ? {} : functionalUpdate(inactiveProps, {}) ?? {}\n\n return {\n ...resolvedActiveProps,\n ...resolvedInactiveProps,\n ...rest,\n href: disabled\n ? undefined\n : next.maskedLocation\n ? next.maskedLocation.href\n : next.href,\n onClick: composeHandlers([onClick, handleClick]),\n onFocus: composeHandlers([onFocus, handleFocus]),\n onMouseEnter: composeHandlers([onMouseEnter, handleEnter]),\n onMouseLeave: composeHandlers([onMouseLeave, handleLeave]),\n onTouchStart: composeHandlers([onTouchStart, handleTouchStart]),\n target,\n style: {\n ...style,\n ...resolvedActiveProps.style,\n ...resolvedInactiveProps.style,\n },\n className:\n [\n className,\n resolvedActiveProps.className,\n resolvedInactiveProps.className,\n ]\n .filter(Boolean)\n .join(' ') || undefined,\n ...(disabled\n ? {\n role: 'link',\n 'aria-disabled': true,\n }\n : undefined),\n ['data-status']: isActive ? 'active' : undefined,\n }\n}\n\nexport interface LinkComponent<TProps extends Record<string, any> = {}> {\n <\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n >(\n props: LinkProps<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> &\n TProps &\n React.RefAttributes<HTMLAnchorElement>,\n ): ReactNode\n}\n\nexport const Link: LinkComponent = React.forwardRef((props: any, ref) => {\n const linkProps = useLinkProps(props)\n\n return (\n <a\n {...{\n ref: ref as any,\n ...linkProps,\n children:\n typeof props.children === 'function'\n ? props.children({\n isActive: (linkProps as any)['data-status'] === 'active',\n })\n : props.children,\n }}\n />\n )\n}) as any\n\nfunction isCtrlEvent(e: MouseEvent) {\n return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey)\n}\n"],"names":["preloadWarning","useLinkProps","options","router","useRouter","matchPathname","useMatch","strict","select","s","pathname","children","target","activeProps","className","inactiveProps","activeOptions","disabled","hash","search","params","to","state","mask","preload","userPreload","preloadDelay","userPreloadDelay","replace","startTransition","resetScroll","style","onClick","onFocus","onMouseEnter","onMouseLeave","onTouchStart","rest","dest","from","undefined","type","URL","href","next","buildLocation","defaultPreload","defaultPreloadDelay","isActive","useRouterState","currentPathSplit","location","split","nextPathSplit","pathIsFuzzyEqual","every","d","i","pathTest","exact","hashTest","includeHash","searchTest","includeSearch","deepEqual","handleClick","e","isCtrlEvent","defaultPrevented","button","preventDefault","commitLocation","handleFocus","preloadRoute","catch","err","console","warn","handleTouchStart","handleEnter","preloadTimeout","setTimeout","handleLeave","clearTimeout","composeHandlers","handlers","persist","filter","Boolean","forEach","handler","resolvedActiveProps","functionalUpdate","resolvedInactiveProps","maskedLocation","join","role","Link","React","forwardRef","props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,MAAAA,IAAI,EAAE,MAAM;AACZ,MAAA,eAAe,EAAE,IAAA;KAClB,GACDxD,SAAS;AACb,IAAA,CAAC,aAAa,GAAGQ,QAAQ,GAAG,QAAQ,GAAGR,SAAAA;GACxC,CAAA;AACH,CAAA;AAgBO,MAAMyD,IAAmB,gBAAGC,gBAAK,CAACC,UAAU,CAAC,CAACC,KAAU,EAAEC,GAAG,KAAK;AACvE,EAAA,MAAMC,SAAS,GAAGrG,YAAY,CAACmG,KAAK,CAAC,CAAA;AAErC,EAAA,oBACEF,gBAAA,CAAAK,aAAA,CAAA,GAAA,EAAAC,iCAAA,CAAA;AAEIH,IAAAA,GAAG,EAAEA,GAAAA;AAAU,GAAA,EACZC,SAAS,EAAA;IACZ3F,QAAQ,EACN,OAAOyF,KAAK,CAACzF,QAAQ,KAAK,UAAU,GAChCyF,KAAK,CAACzF,QAAQ,CAAC;AACbqC,MAAAA,QAAQ,EAAGsD,SAAS,CAAS,aAAa,CAAC,KAAK,QAAA;KACjD,CAAC,GACFF,KAAK,CAACzF,QAAAA;AAAQ,GAAA,CAEvB,CAAC,CAAA;AAEN,CAAC,EAAQ;AAET,SAASwD,WAAWA,CAACD,CAAa,EAAE;AAClC,EAAA,OAAO,CAAC,EAAEA,CAAC,CAACuC,OAAO,IAAIvC,CAAC,CAACwC,MAAM,IAAIxC,CAAC,CAACyC,OAAO,IAAIzC,CAAC,CAAC0C,QAAQ,CAAC,CAAA;AAC7D;;;;;"}
|
|
1
|
+
{"version":3,"file":"link.js","sources":["../../src/link.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useMatch } from './Matches'\nimport { useRouter, useRouterState } from './RouterProvider'\nimport { Trim } from './fileRoute'\nimport { AnyRoute, ReactNode } from './route'\nimport {\n AllParams,\n FullSearchSchema,\n RouteByPath,\n RouteIds,\n RoutePaths,\n} from './routeInfo'\nimport { RegisteredRouter } from './router'\nimport { LinkProps, UseLinkPropsOptions } from './useNavigate'\nimport {\n Expand,\n NoInfer,\n NonNullableUpdater,\n PickRequired,\n UnionToIntersection,\n Updater,\n deepEqual,\n functionalUpdate,\n} from './utils'\nimport { HistoryState } from '@tanstack/history'\n\nexport type CleanPath<T extends string> = T extends `${infer L}//${infer R}`\n ? CleanPath<`${CleanPath<L>}/${CleanPath<R>}`>\n : T extends `${infer L}//`\n ? `${CleanPath<L>}/`\n : T extends `//${infer L}`\n ? `/${CleanPath<L>}`\n : T\n\nexport type Split<S, TIncludeTrailingSlash = true> = S extends unknown\n ? string extends S\n ? string[]\n : S extends string\n ? CleanPath<S> extends ''\n ? []\n : TIncludeTrailingSlash extends true\n ? CleanPath<S> extends `${infer T}/`\n ? [...Split<T>, '/']\n : CleanPath<S> extends `/${infer U}`\n ? Split<U>\n : CleanPath<S> extends `${infer T}/${infer U}`\n ? [...Split<T>, ...Split<U>]\n : [S]\n : CleanPath<S> extends `${infer T}/${infer U}`\n ? [...Split<T>, ...Split<U>]\n : S extends string\n ? [S]\n : never\n : never\n : never\n\nexport type ParsePathParams<T extends string> = keyof {\n [K in Trim<Split<T>[number], '_'> as K extends `$${infer L}` ? L : never]: K\n}\n\nexport type Join<T, Delimiter extends string = '/'> = T extends []\n ? ''\n : T extends [infer L extends string]\n ? L\n : T extends [infer L extends string, ...infer Tail extends [...string[]]]\n ? CleanPath<`${L}${Delimiter}${Join<Tail>}`>\n : never\n\nexport type Last<T extends any[]> = T extends [...infer _, infer L] ? L : never\n\nexport type RelativeToPathAutoComplete<\n AllPaths extends string,\n TFrom extends string,\n TTo extends string,\n SplitPaths extends string[] = Split<AllPaths, false>,\n> = TTo extends `..${infer _}`\n ? SplitPaths extends [\n ...Split<ResolveRelativePath<TFrom, TTo>, false>,\n ...infer TToRest,\n ]\n ? `${CleanPath<\n Join<\n [\n ...Split<TTo, false>,\n ...(\n | TToRest\n | (Split<\n ResolveRelativePath<TFrom, TTo>,\n false\n >['length'] extends 1\n ? never\n : ['../'])\n ),\n ]\n >\n >}`\n : never\n : TTo extends `./${infer RestTTo}`\n ? SplitPaths extends [\n ...Split<TFrom, false>,\n ...Split<RestTTo, false>,\n ...infer RestPath,\n ]\n ? `${TTo}${Join<RestPath>}`\n : never\n :\n | (TFrom extends `/`\n ? never\n : SplitPaths extends [...Split<TFrom, false>, ...infer RestPath]\n ? Join<RestPath> extends { length: 0 }\n ? never\n : './'\n : never)\n | (TFrom extends `/` ? never : '../')\n | AllPaths\n\nexport type NavigateOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = TFrom,\n TMaskTo extends string = '',\n> = ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // `replace` is a boolean that determines whether the navigation should replace the current history entry or push a new one.\n replace?: boolean\n resetScroll?: boolean\n // If set to `true`, the link's underlying navigate() call will be wrapped in a `React.startTransition` call. Defaults to `true`.\n startTransition?: boolean\n}\n\nexport type ToOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n> = ToSubOptions<TRouteTree, TFrom, TTo> & {\n mask?: ToMaskOptions<TRouteTree, TMaskFrom, TMaskTo>\n}\n\nexport type ToMaskOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n> = ToSubOptions<TRouteTree, TMaskFrom, TMaskTo> & {\n unmaskOnReload?: boolean\n}\n\nexport type ToSubOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n> = {\n to?: ToPathOption<TRouteTree, TFrom, TTo>\n // The new has string or a function to update it\n hash?: true | Updater<string>\n // State to pass to the history stack\n state?: true | NonNullableUpdater<HistoryState>\n // The source route path. This is automatically set when using route-level APIs, but for type-safe relative routing on the router itself, this is required\n from?: TFrom\n // // When using relative route paths, this option forces resolution from the current path, instead of the route API's path or `from` path\n} & CheckPath<TRouteTree, NoInfer<TResolved>, {}> &\n SearchParamOptions<TRouteTree, TFrom, TTo, TResolved> &\n PathParamOptions<TRouteTree, TFrom, TResolved>\n\nexport type SearchParamOptions<\n TRouteTree extends AnyRoute,\n TFrom,\n TTo,\n TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n TFromSearchEnsured = '/' extends TFrom\n ? FullSearchSchema<TRouteTree>\n : Expand<\n UnionToIntersection<\n PickRequired<\n RouteByPath<TRouteTree, TFrom>['types']['fullSearchSchema']\n >\n >\n >,\n TFromSearchOptional = Omit<FullSearchSchema<TRouteTree>, keyof TFromSearchEnsured>,\n TFromSearch = Expand<TFromSearchEnsured & TFromSearchOptional>,\n TToSearch = '' extends TTo\n ? FullSearchSchema<TRouteTree>\n : Expand<RouteByPath<TRouteTree, TResolved>['types']['fullSearchSchema']>,\n> = keyof PickRequired<TToSearch> extends never\n ? {\n search?: true | SearchReducer<TFromSearch, TToSearch>\n }\n : {\n search: TFromSearchEnsured extends PickRequired<TToSearch>\n ? true | SearchReducer<TFromSearch, TToSearch>\n : SearchReducer<TFromSearch, TToSearch>\n }\n\ntype SearchReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo)\n\nexport type PathParamOptions<\n TRouteTree extends AnyRoute,\n TFrom,\n TTo,\n TFromParamsEnsured = Expand<\n UnionToIntersection<\n PickRequired<RouteByPath<TRouteTree, TFrom>['types']['allParams']>\n >\n >,\n TFromParamsOptional = Omit<AllParams<TRouteTree>, keyof TFromParamsEnsured>,\n TFromParams = Expand<TFromParamsOptional & TFromParamsEnsured>,\n TToParams = Expand<RouteByPath<TRouteTree, TTo>['types']['allParams']>,\n> = keyof PickRequired<TToParams> extends never\n ? {\n params?: true | ParamsReducer<TFromParams, TToParams>\n }\n : {\n params: TFromParamsEnsured extends PickRequired<TToParams>\n ? true | ParamsReducer<TFromParams, TToParams>\n : ParamsReducer<TFromParams, TToParams>\n }\n\ntype ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo)\n\nexport type ToPathOption<\n TRouteTree extends AnyRoute = AnyRoute,\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n> =\n | TTo\n | RelativeToPathAutoComplete<\n RoutePaths<TRouteTree>,\n NoInfer<TFrom> extends string ? NoInfer<TFrom> : '',\n NoInfer<TTo> & string\n >\n\nexport type ToIdOption<\n TRouteTree extends AnyRoute = AnyRoute,\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n> =\n | TTo\n | RelativeToPathAutoComplete<\n RouteIds<TRouteTree>,\n NoInfer<TFrom> extends string ? NoInfer<TFrom> : '',\n NoInfer<TTo> & string\n >\n\nexport interface ActiveOptions {\n exact?: boolean\n includeHash?: boolean\n includeSearch?: boolean\n}\n\nexport type LinkOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = TFrom,\n TMaskTo extends string = '',\n> = NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // The standard anchor tag target attribute\n target?: HTMLAnchorElement['target']\n // Defaults to `{ exact: false, includeHash: false }`\n activeOptions?: ActiveOptions\n // If set, will preload the linked route on hover and cache it for this many milliseconds in hopes that the user will eventually navigate there.\n preload?: false | 'intent'\n // Delay intent preloading by this many milliseconds. If the intent exits before this delay, the preload will be cancelled.\n preloadDelay?: number\n // If true, will render the link without the href attribute\n disabled?: boolean\n}\n\nexport type CheckRelativePath<\n TRouteTree extends AnyRoute,\n TFrom,\n TTo,\n> = TTo extends string\n ? TFrom extends string\n ? ResolveRelativePath<TFrom, TTo> extends RoutePaths<TRouteTree>\n ? {}\n : {\n Error: `${TFrom} + ${TTo} resolves to ${ResolveRelativePath<\n TFrom,\n TTo\n >}, which is not a valid route path.`\n 'Valid Route Paths': RoutePaths<TRouteTree>\n }\n : {}\n : {}\n\nexport type CheckPath<TRouteTree extends AnyRoute, TPath, TPass> = Exclude<\n TPath,\n RoutePaths<TRouteTree>\n> extends never\n ? TPass\n : CheckPathError<TRouteTree, Exclude<TPath, RoutePaths<TRouteTree>>>\n\nexport type CheckPathError<TRouteTree extends AnyRoute, TInvalids> = {\n to: RoutePaths<TRouteTree>\n}\n\nexport type CheckId<TRouteTree extends AnyRoute, TPath, TPass> = Exclude<\n TPath,\n RouteIds<TRouteTree>\n> extends never\n ? TPass\n : CheckIdError<TRouteTree, Exclude<TPath, RouteIds<TRouteTree>>>\n\nexport type CheckIdError<TRouteTree extends AnyRoute, TInvalids> = {\n Error: `${TInvalids extends string\n ? TInvalids\n : never} is not a valid route ID.`\n 'Valid Route IDs': RouteIds<TRouteTree>\n}\n\nexport type ResolveRelativePath<TFrom, TTo = '.'> = TFrom extends string\n ? TTo extends string\n ? TTo extends '.'\n ? TFrom\n : TTo extends `./`\n ? Join<[TFrom, '/']>\n : TTo extends `./${infer TRest}`\n ? ResolveRelativePath<TFrom, TRest>\n : TTo extends `/${infer TRest}`\n ? TTo\n : Split<TTo> extends ['..', ...infer ToRest]\n ? Split<TFrom> extends [...infer FromRest, infer FromTail]\n ? ToRest extends ['/']\n ? Join<[...FromRest, '/']>\n : ResolveRelativePath<Join<FromRest>, Join<ToRest>>\n : never\n : Split<TTo> extends ['.', ...infer ToRest]\n ? ToRest extends ['/']\n ? Join<[TFrom, '/']>\n : ResolveRelativePath<TFrom, Join<ToRest>>\n : CleanPath<Join<['/', ...Split<TFrom>, ...Split<TTo>]>>\n : never\n : never\n\ntype LinkCurrentTargetElement = {\n preloadTimeout?: null | ReturnType<typeof setTimeout>\n}\n\nconst preloadWarning = 'Error preloading route! ☝️'\n\nexport function useLinkProps<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n>(\n options: UseLinkPropsOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n): React.AnchorHTMLAttributes<HTMLAnchorElement> {\n const router = useRouter()\n const matchPathname = useMatch({\n strict: false,\n select: (s) => s.pathname,\n })\n\n const {\n // custom props\n children,\n target,\n activeProps = () => ({ className: 'active' }),\n inactiveProps = () => ({}),\n activeOptions,\n disabled,\n hash,\n search,\n params,\n to,\n state,\n mask,\n preload: userPreload,\n preloadDelay: userPreloadDelay,\n replace,\n startTransition,\n resetScroll,\n // element props\n style,\n className,\n onClick,\n onFocus,\n onMouseEnter,\n onMouseLeave,\n onTouchStart,\n ...rest\n } = options\n\n // If this link simply reloads the current route,\n // make sure it has a new key so it will trigger a data refresh\n\n // If this `to` is a valid external URL, return\n // null for LinkUtils\n\n const dest = {\n from: options.to ? matchPathname : undefined,\n ...options,\n }\n\n let type: 'internal' | 'external' = 'internal'\n\n try {\n new URL(`${to}`)\n type = 'external'\n } catch {}\n\n if (type === 'external') {\n return {\n href: to,\n }\n }\n\n const next = router.buildLocation(dest as any)\n\n const preload = userPreload ?? router.options.defaultPreload\n const preloadDelay =\n userPreloadDelay ?? router.options.defaultPreloadDelay ?? 0\n\n const isActive = useRouterState({\n select: (s) => {\n // Compare path/hash for matches\n const currentPathSplit = s.location.pathname.split('/')\n const nextPathSplit = next.pathname.split('/')\n const pathIsFuzzyEqual = nextPathSplit.every(\n (d, i) => d === currentPathSplit[i],\n )\n // Combine the matches based on user router.options\n const pathTest = activeOptions?.exact\n ? s.location.pathname === next.pathname\n : pathIsFuzzyEqual\n const hashTest = activeOptions?.includeHash\n ? s.location.hash === next.hash\n : true\n const searchTest =\n activeOptions?.includeSearch ?? true\n ? deepEqual(s.location.search, next.search, !activeOptions?.exact)\n : true\n\n // The final \"active\" test\n return pathTest && hashTest && searchTest\n },\n })\n\n // The click handler\n const handleClick = (e: MouseEvent) => {\n if (\n !disabled &&\n !isCtrlEvent(e) &&\n !e.defaultPrevented &&\n (!target || target === '_self') &&\n e.button === 0\n ) {\n e.preventDefault()\n\n // All is well? Navigate!\n router.commitLocation({ ...next, replace, resetScroll, startTransition })\n }\n }\n\n // The click handler\n const handleFocus = (e: MouseEvent) => {\n if (preload) {\n router.preloadRoute(dest as any).catch((err) => {\n console.warn(err)\n console.warn(preloadWarning)\n })\n }\n }\n\n const handleTouchStart = (e: TouchEvent) => {\n if (preload) {\n router.preloadRoute(dest as any).catch((err) => {\n console.warn(err)\n console.warn(preloadWarning)\n })\n }\n }\n\n const handleEnter = (e: MouseEvent) => {\n const target = (e.target || {}) as LinkCurrentTargetElement\n\n if (preload) {\n if (target.preloadTimeout) {\n return\n }\n\n target.preloadTimeout = setTimeout(() => {\n target.preloadTimeout = null\n router.preloadRoute(dest as any).catch((err) => {\n console.warn(err)\n console.warn(preloadWarning)\n })\n }, preloadDelay)\n }\n }\n\n const handleLeave = (e: MouseEvent) => {\n const target = (e.target || {}) as LinkCurrentTargetElement\n\n if (target.preloadTimeout) {\n clearTimeout(target.preloadTimeout)\n target.preloadTimeout = null\n }\n }\n\n const composeHandlers =\n (handlers: (undefined | ((e: any) => void))[]) =>\n (e: React.SyntheticEvent) => {\n if (e.persist) e.persist()\n handlers.filter(Boolean).forEach((handler) => {\n if (e.defaultPrevented) return\n handler!(e)\n })\n }\n\n // Get the active props\n const resolvedActiveProps: React.HTMLAttributes<HTMLAnchorElement> = isActive\n ? functionalUpdate(activeProps as any, {}) ?? {}\n : {}\n\n // Get the inactive props\n const resolvedInactiveProps: React.HTMLAttributes<HTMLAnchorElement> =\n isActive ? {} : functionalUpdate(inactiveProps, {}) ?? {}\n\n return {\n ...resolvedActiveProps,\n ...resolvedInactiveProps,\n ...rest,\n href: disabled\n ? undefined\n : next.maskedLocation\n ? next.maskedLocation.href\n : next.href,\n onClick: composeHandlers([onClick, handleClick]),\n onFocus: composeHandlers([onFocus, handleFocus]),\n onMouseEnter: composeHandlers([onMouseEnter, handleEnter]),\n onMouseLeave: composeHandlers([onMouseLeave, handleLeave]),\n onTouchStart: composeHandlers([onTouchStart, handleTouchStart]),\n target,\n style: {\n ...style,\n ...resolvedActiveProps.style,\n ...resolvedInactiveProps.style,\n },\n className:\n [\n className,\n resolvedActiveProps.className,\n resolvedInactiveProps.className,\n ]\n .filter(Boolean)\n .join(' ') || undefined,\n ...(disabled\n ? {\n role: 'link',\n 'aria-disabled': true,\n }\n : undefined),\n ['data-status']: isActive ? 'active' : undefined,\n }\n}\n\nexport interface LinkComponent<TProps extends Record<string, any> = {}> {\n <\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n >(\n props: LinkProps<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> &\n TProps &\n React.RefAttributes<HTMLAnchorElement>,\n ): ReactNode\n}\n\nexport const Link: LinkComponent = React.forwardRef((props: any, ref) => {\n const linkProps = useLinkProps(props)\n\n return (\n <a\n {...{\n ref: ref as any,\n ...linkProps,\n children:\n typeof props.children === 'function'\n ? props.children({\n isActive: (linkProps as any)['data-status'] === 'active',\n })\n : props.children,\n }}\n />\n )\n}) as any\n\nfunction isCtrlEvent(e: MouseEvent) {\n return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey)\n}\n"],"names":["preloadWarning","useLinkProps","options","router","useRouter","matchPathname","useMatch","strict","select","s","pathname","children","target","activeProps","className","inactiveProps","activeOptions","disabled","hash","search","params","to","state","mask","preload","userPreload","preloadDelay","userPreloadDelay","replace","startTransition","resetScroll","style","onClick","onFocus","onMouseEnter","onMouseLeave","onTouchStart","rest","dest","from","undefined","type","URL","href","next","buildLocation","defaultPreload","defaultPreloadDelay","isActive","useRouterState","currentPathSplit","location","split","nextPathSplit","pathIsFuzzyEqual","every","d","i","pathTest","exact","hashTest","includeHash","searchTest","includeSearch","deepEqual","handleClick","e","isCtrlEvent","defaultPrevented","button","preventDefault","commitLocation","handleFocus","preloadRoute","catch","err","console","warn","handleTouchStart","handleEnter","preloadTimeout","setTimeout","handleLeave","clearTimeout","composeHandlers","handlers","persist","filter","Boolean","forEach","handler","resolvedActiveProps","functionalUpdate","resolvedInactiveProps","maskedLocation","join","role","Link","React","forwardRef","props","ref","linkProps","createElement","_extends","metaKey","altKey","ctrlKey","shiftKey"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqVA,MAAMA,cAAc,GAAG,4BAA4B,CAAA;AAE5C,SAASC,YAAYA,CAO1BC,OAAwE,EACzB;AAC/C,EAAA,MAAMC,MAAM,GAAGC,wBAAS,EAAE,CAAA;EAC1B,MAAMC,aAAa,GAAGC,gBAAQ,CAAC;AAC7BC,IAAAA,MAAM,EAAE,KAAK;AACbC,IAAAA,MAAM,EAAGC,CAAC,IAAKA,CAAC,CAACC,QAAAA;AACnB,GAAC,CAAC,CAAA;EAEF,MAAM;AACJ;IACAC,QAAQ;IACRC,MAAM;IACNC,WAAW,GAAGA,OAAO;AAAEC,MAAAA,SAAS,EAAE,QAAA;AAAS,KAAC,CAAC;AAC7CC,IAAAA,aAAa,GAAGA,OAAO,EAAE,CAAC;IAC1BC,aAAa;IACbC,QAAQ;IACRC,IAAI;IACJC,MAAM;IACNC,MAAM;IACNC,EAAE;IACFC,KAAK;IACLC,IAAI;AACJC,IAAAA,OAAO,EAAEC,WAAW;AACpBC,IAAAA,YAAY,EAAEC,gBAAgB;IAC9BC,OAAO;IACPC,eAAe;IACfC,WAAW;AACX;IACAC,KAAK;IACLjB,SAAS;IACTkB,OAAO;IACPC,OAAO;IACPC,YAAY;IACZC,YAAY;IACZC,YAAY;IACZ,GAAGC,IAAAA;AACL,GAAC,GAAGnC,OAAO,CAAA;;AAEX;AACA;;AAEA;AACA;;AAEA,EAAA,MAAMoC,IAAI,GAAG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{"version":3,"file":"route.js","sources":["../../src/route.ts"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport { useLoaderData, useLoaderDeps, useMatch } from './Matches'\nimport { AnyRouteMatch } from './Matches'\nimport { NavigateOptions, ParsePathParams, ToSubOptions } from './link'\nimport { ParsedLocation } from './location'\nimport { joinPaths, trimPath } from './path'\nimport { RouteById, RouteIds, RoutePaths } from './routeInfo'\nimport { AnyRouter, RegisteredRouter } from './router'\nimport { useParams } from './useParams'\nimport { useSearch } from './useSearch'\nimport {\n Assign,\n Expand,\n IsAny,\n NoInfer,\n PickRequired,\n UnionToIntersection,\n} from './utils'\nimport { BuildLocationFn, NavigateFn } from './RouterProvider'\n\nexport const rootRouteId = '__root__' as const\nexport type RootRouteId = typeof rootRouteId\nexport type AnyPathParams = {}\n\nexport type AnySearchSchema = {}\n\nexport type AnyContext = {}\n\nexport interface RouteContext {}\n\nexport interface RouteMeta {}\n\nexport type PreloadableObj = { preload?: () => Promise<void> }\n\nexport type RoutePathOptions<TCustomId, TPath> =\n | {\n path: TPath\n }\n | {\n id: TCustomId\n }\n\nexport type RoutePathOptionsIntersection<TCustomId, TPath> =\n UnionToIntersection<RoutePathOptions<TCustomId, TPath>>\n\nexport type MetaOptions = keyof PickRequired<RouteMeta> extends never\n ? {\n meta?: RouteMeta\n }\n : {\n meta: RouteMeta\n }\n\nexport type RouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TCustomId extends string = string,\n TPath extends string = string,\n TSearchSchema extends Record<string, any> = {},\n TFullSearchSchema extends Record<string, any> = TSearchSchema,\n TParams extends AnyPathParams = AnyPathParams,\n TAllParams extends AnyPathParams = TParams,\n TRouteContext extends RouteContext = RouteContext,\n TAllContext extends Record<string, any> = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderData extends any = unknown,\n> = BaseRouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext,\n TLoaderDeps,\n TLoaderData\n> &\n UpdatableRouteOptions<NoInfer<TFullSearchSchema>>\n\nexport type ParamsFallback<\n TPath extends string,\n TParams,\n> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams\n\nexport type BaseRouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TCustomId extends string = string,\n TPath extends string = string,\n TSearchSchema extends Record<string, any> = {},\n TFullSearchSchema extends Record<string, any> = TSearchSchema,\n TParams extends AnyPathParams = {},\n TAllParams = ParamsFallback<TPath, TParams>,\n TRouteContext extends RouteContext = RouteContext,\n TAllContext extends Record<string, any> = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderData extends any = unknown,\n> = RoutePathOptions<TCustomId, TPath> & {\n getParentRoute: () => TParentRoute\n validateSearch?: SearchSchemaValidator<TSearchSchema>\n} & (keyof PickRequired<RouteContext> extends never\n ? // This async function is called before a route is loaded.\n // If an error is thrown here, the route's loader will not be called.\n // If thrown during a navigation, the navigation will be cancelled and the error will be passed to the `onError` function.\n // If thrown during a preload event, the error will be logged to the console.\n {\n beforeLoad?: BeforeLoadFn<\n TFullSearchSchema,\n TParentRoute,\n TAllParams,\n TRouteContext\n >\n }\n : {\n beforeLoad: BeforeLoadFn<\n TFullSearchSchema,\n TParentRoute,\n TAllParams,\n TRouteContext\n >\n }) & {\n loaderDeps?: (opts: { search: TFullSearchSchema }) => TLoaderDeps\n loader?: RouteLoaderFn<\n TAllParams,\n NoInfer<TLoaderDeps>,\n NoInfer<TAllContext>,\n NoInfer<TRouteContext>,\n TLoaderData\n >\n } & (\n | {\n // Both or none\n parseParams?: (\n rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,\n ) => TParams extends Record<ParsePathParams<TPath>, any>\n ? TParams\n : 'parseParams must return an object'\n stringifyParams?: (\n params: NoInfer<ParamsFallback<TPath, TParams>>,\n ) => Record<ParsePathParams<TPath>, string>\n }\n | {\n stringifyParams?: never\n parseParams?: never\n }\n )\n\ntype BeforeLoadFn<\n TFullSearchSchema extends Record<string, any>,\n TParentRoute extends AnyRoute,\n TAllParams,\n TRouteContext,\n> = (opts: {\n search: TFullSearchSchema\n abortController: AbortController\n preload: boolean\n params: TAllParams\n context: TParentRoute['types']['allContext']\n location: ParsedLocation\n navigate: NavigateFn<AnyRoute>\n buildLocation: BuildLocationFn<TParentRoute>\n cause: 'preload' | 'enter' | 'stay'\n}) => Promise<TRouteContext> | TRouteContext | void\n\nexport type UpdatableRouteOptions<\n TFullSearchSchema extends Record<string, any>,\n> = MetaOptions & {\n // test?: (args: TAllContext) => void\n // If true, this route will be matched as case-sensitive\n caseSensitive?: boolean\n // If true, this route will be forcefully wrapped in a suspense boundary\n wrapInSuspense?: boolean\n // The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`\n component?: RouteComponent\n errorComponent?: false | null | ErrorRouteComponent\n pendingComponent?: RouteComponent\n pendingMs?: number\n pendingMinMs?: number\n staleTime?: number\n gcTime?: number\n preloadStaleTime?: number\n preloadGcTime?: number\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 onError?: (err: any) => void\n // These functions are called as route matches are loaded, stick around and leave the active\n // matches\n onEnter?: (match: AnyRouteMatch) => void\n onStay?: (match: AnyRouteMatch) => void\n onLeave?: (match: AnyRouteMatch) => void\n}\n\nexport type ParseParamsOption<TPath extends string, TParams> = ParseParamsFn<\n TPath,\n TParams\n>\n\nexport type ParseParamsFn<TPath extends string, TParams> = (\n rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,\n) => TParams extends Record<ParsePathParams<TPath>, any>\n ? TParams\n : 'parseParams must return an object'\n\nexport type ParseParamsObj<TPath extends string, TParams> = {\n parse?: ParseParamsFn<TPath, TParams>\n}\n\n// The parse type here allows a zod schema to be passed directly to the validator\nexport type SearchSchemaValidator<TReturn> =\n | SearchSchemaValidatorObj<TReturn>\n | SearchSchemaValidatorFn<TReturn>\n\nexport type SearchSchemaValidatorObj<TReturn> = {\n parse?: SearchSchemaValidatorFn<TReturn>\n}\n\nexport type SearchSchemaValidatorFn<TReturn> = (\n searchObj: Record<string, unknown>,\n) => TReturn\n\nexport type DefinedPathParamWarning =\n 'Path params cannot be redefined by child routes!'\n\nexport type ParentParams<TParentParams> = AnyPathParams extends TParentParams\n ? {}\n : {\n [Key in keyof TParentParams]?: DefinedPathParamWarning\n }\n\nexport type RouteLoaderFn<\n TAllParams = {},\n TLoaderDeps extends Record<string, any> = {},\n TAllContext extends Record<string, any> = AnyContext,\n TRouteContext extends Record<string, any> = AnyContext,\n TLoaderData extends any = unknown,\n> = (\n match: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext, TRouteContext>,\n) => Promise<TLoaderData> | TLoaderData\n\nexport interface LoaderFnContext<\n TAllParams = {},\n TLoaderDeps extends Record<string, any> = {},\n TAllContext extends Record<string, any> = AnyContext,\n TRouteContext extends Record<string, any> = AnyContext,\n> {\n abortController: AbortController\n preload: boolean\n params: TAllParams\n deps: TLoaderDeps\n context: Expand<Assign<TAllContext, TRouteContext>>\n location: ParsedLocation // Do not supply search schema here so as to demotivate people from trying to shortcut loaderDeps\n navigate: (opts: NavigateOptions<AnyRoute>) => Promise<void>\n parentMatchPromise?: Promise<void>\n cause: 'preload' | 'enter' | 'stay'\n}\n\nexport type SearchFilter<T, U = T> = (prev: T) => U\n\nexport type ResolveId<\n TParentRoute,\n TCustomId extends string,\n TPath extends string,\n> = TParentRoute extends { id: infer TParentId extends string }\n ? RoutePrefix<TParentId, string extends TCustomId ? TPath : TCustomId>\n : RootRouteId\n\nexport type InferFullSearchSchema<TRoute> = TRoute extends {\n types: {\n fullSearchSchema: infer TFullSearchSchema\n }\n}\n ? TFullSearchSchema\n : {}\n\nexport type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = Expand<\n Assign<InferFullSearchSchema<TParentRoute>, TSearchSchema>\n>\n\nexport interface AnyRoute\n extends Route<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > {}\n\nexport type MergeFromFromParent<T, U> = IsAny<T, U, T & U>\n\nexport type ResolveAllParams<\n TParentRoute extends AnyRoute,\n TParams extends AnyPathParams,\n> = Record<never, string> extends TParentRoute['types']['allParams']\n ? TParams\n : Expand<\n UnionToIntersection<TParentRoute['types']['allParams'] & TParams> & {}\n >\n\nexport type RouteConstraints = {\n TParentRoute: AnyRoute\n TPath: string\n TFullPath: string\n TCustomId: string\n TId: string\n TSearchSchema: AnySearchSchema\n TFullSearchSchema: AnySearchSchema\n TParams: Record<string, any>\n TAllParams: Record<string, any>\n TParentContext: AnyContext\n TRouteContext: RouteContext\n TAllContext: AnyContext\n TRouterContext: AnyContext\n TChildren: unknown\n TRouteTree: AnyRoute\n}\n\nexport class RouteApi<\n TId extends RouteIds<RegisteredRouter['routeTree']>,\n TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,\n TFullSearchSchema extends Record<\n string,\n any\n > = TRoute['types']['fullSearchSchema'],\n TAllParams extends AnyPathParams = TRoute['types']['allParams'],\n TAllContext extends Record<string, any> = TRoute['types']['allContext'],\n TLoaderDeps extends Record<string, any> = TRoute['types']['loaderDeps'],\n TLoaderData extends any = TRoute['types']['loaderData'],\n> {\n id: TId\n\n constructor({ id }: { id: TId }) {\n this.id = id as any\n }\n\n useMatch = <TSelected = TAllContext>(opts?: {\n select?: (s: TAllContext) => TSelected\n }): TSelected => {\n return useMatch({ ...opts, from: this.id }) as any\n }\n\n useRouteContext = <TSelected = TAllContext>(opts?: {\n select?: (s: TAllContext) => TSelected\n }): TSelected => {\n return useMatch({\n ...opts,\n from: this.id,\n select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),\n } as any)\n }\n\n useSearch = <TSelected = TFullSearchSchema>(opts?: {\n select?: (s: TFullSearchSchema) => TSelected\n }): TSelected => {\n return useSearch({ ...opts, from: this.id } as any)\n }\n\n useParams = <TSelected = TAllParams>(opts?: {\n select?: (s: TAllParams) => TSelected\n }): TSelected => {\n return useParams({ ...opts, from: this.id } as any)\n }\n\n useLoaderDeps = <TSelected = TLoaderDeps>(opts?: {\n select?: (s: TLoaderDeps) => TSelected\n }): TSelected => {\n return useLoaderDeps({ ...opts, from: this.id } as any) as any\n }\n\n useLoaderData = <TSelected = TLoaderData>(opts?: {\n select?: (s: TLoaderData) => TSelected\n }): TSelected => {\n return useLoaderData({ ...opts, from: this.id } as any) as any\n }\n}\n\nexport class Route<\n TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,\n TPath extends RouteConstraints['TPath'] = '/',\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n TPath\n >,\n TCustomId extends RouteConstraints['TCustomId'] = string,\n TId extends RouteConstraints['TId'] = ResolveId<\n TParentRoute,\n TCustomId,\n TPath\n >,\n TSearchSchema extends RouteConstraints['TSearchSchema'] = {},\n TFullSearchSchema extends\n RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<\n TParentRoute,\n TSearchSchema\n >,\n TParams extends RouteConstraints['TParams'] = Expand<\n Record<ParsePathParams<TPath>, string>\n >,\n TAllParams extends RouteConstraints['TAllParams'] = ResolveAllParams<\n TParentRoute,\n TParams\n >,\n TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,\n TAllContext extends Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n > = Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n >,\n TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderData extends any = unknown,\n TChildren extends RouteConstraints['TChildren'] = unknown,\n TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,\n> {\n isRoot: TParentRoute extends Route<any> ? true : false\n options: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext,\n TLoaderDeps,\n TLoaderData\n >\n\n test!: Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n >\n\n // Set up in this.init()\n parentRoute!: TParentRoute\n id!: TId\n // customId!: TCustomId\n path!: TPath\n fullPath!: TFullPath\n to!: TrimPathRight<TFullPath>\n\n // Optional\n children?: TChildren\n originalIndex?: number\n router?: AnyRouter\n rank!: number\n\n constructor(\n options: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext,\n TLoaderDeps,\n TLoaderData\n >,\n ) {\n this.options = (options as any) || {}\n this.isRoot = !options?.getParentRoute as any\n invariant(\n !((options as any)?.id && (options as any)?.path),\n `Route cannot have both an 'id' and a 'path' option.`,\n )\n ;(this as any).$$typeof = Symbol.for('react.memo')\n }\n\n types!: {\n parentRoute: TParentRoute\n path: TPath\n to: TrimPathRight<TFullPath>\n fullPath: TFullPath\n customId: TCustomId\n id: TId\n searchSchema: TSearchSchema\n fullSearchSchema: TFullSearchSchema\n params: TParams\n allParams: TAllParams\n routeContext: TRouteContext\n allContext: TAllContext\n children: TChildren\n routeTree: TRouteTree\n routerContext: TRouterContext\n loaderData: TLoaderData\n loaderDeps: TLoaderDeps\n }\n\n init = (opts: { originalIndex: number }) => {\n this.originalIndex = opts.originalIndex\n\n const options = this.options as RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext,\n TLoaderDeps,\n TLoaderData\n > &\n RoutePathOptionsIntersection<TCustomId, TPath>\n\n const isRoot = !options?.path && !options?.id\n\n this.parentRoute = this.options?.getParentRoute?.()\n\n if (isRoot) {\n this.path = rootRouteId as TPath\n } else {\n invariant(\n this.parentRoute,\n `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`,\n )\n }\n\n let path: undefined | string = isRoot ? rootRouteId : options.path\n\n // If the path is anything other than an index path, trim it up\n if (path && path !== '/') {\n path = trimPath(path)\n }\n\n const customId = options?.id || path\n\n // Strip the parentId prefix from the first level of children\n let id = isRoot\n ? rootRouteId\n : joinPaths([\n (this.parentRoute.id as any) === rootRouteId\n ? ''\n : this.parentRoute.id,\n customId,\n ])\n\n if (path === rootRouteId) {\n path = '/'\n }\n\n if (id !== rootRouteId) {\n id = joinPaths(['/', id])\n }\n\n const fullPath =\n id === rootRouteId ? '/' : joinPaths([this.parentRoute.fullPath, path])\n\n this.path = path as TPath\n this.id = id as TId\n // this.customId = customId as TCustomId\n this.fullPath = fullPath as TFullPath\n this.to = fullPath as TrimPathRight<TFullPath>\n }\n\n addChildren = <TNewChildren extends AnyRoute[]>(\n children: TNewChildren,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext,\n TRouterContext,\n TLoaderDeps,\n TLoaderData,\n TNewChildren,\n TRouteTree\n > => {\n this.children = children as any\n return this as any\n }\n\n update = (options: UpdatableRouteOptions<TFullSearchSchema>) => {\n Object.assign(this.options, options)\n return this\n }\n\n useMatch = <TSelected = TAllContext>(opts?: {\n select?: (search: TAllContext) => TSelected\n }): TSelected => {\n return useMatch({ ...opts, from: this.id }) as any\n }\n\n useRouteContext = <TSelected = TAllContext>(opts?: {\n select?: (search: TAllContext) => TSelected\n }): TSelected => {\n return useMatch({\n ...opts,\n from: this.id,\n select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),\n } as any)\n }\n\n useSearch = <TSelected = TFullSearchSchema>(opts?: {\n select?: (search: TFullSearchSchema) => TSelected\n }): TSelected => {\n return useSearch({ ...opts, from: this.id } as any)\n }\n\n useParams = <TSelected = TAllParams>(opts?: {\n select?: (search: TAllParams) => TSelected\n }): TSelected => {\n return useParams({ ...opts, from: this.id } as any)\n }\n\n useLoaderDeps = <TSelected = TLoaderDeps>(opts?: {\n select?: (s: TLoaderDeps) => TSelected\n }): TSelected => {\n return useLoaderDeps({ ...opts, from: this.id } as any) as any\n }\n\n useLoaderData = <TSelected = TLoaderData>(opts?: {\n select?: (search: TLoaderData) => TSelected\n }): TSelected => {\n return useLoaderData({ ...opts, from: this.id } as any) as any\n }\n}\n\nexport type AnyRootRoute = RootRoute<any, any, any, any>\n\nexport function rootRouteWithContext<TRouterContext extends {}>() {\n return <\n TSearchSchema extends Record<string, any> = {},\n TRouteContext extends RouteContext = RouteContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderData extends any = unknown,\n >(\n options?: Omit<\n RouteOptions<\n AnyRoute, // TParentRoute\n RootRouteId, // TCustomId\n '', // TPath\n TSearchSchema, // TSearchSchema\n TSearchSchema, // TFullSearchSchema\n {}, // TParams\n {}, // TAllParams\n TRouteContext, // TRouteContext\n Assign<TRouterContext, TRouteContext>, // TAllContext\n TLoaderDeps,\n TLoaderData // TLoaderData,\n >,\n | 'path'\n | 'id'\n | 'getParentRoute'\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n >,\n ): RootRoute<TSearchSchema, TRouteContext, TRouterContext> => {\n return new RootRoute(options) as any\n }\n}\n\nexport class RootRoute<\n TSearchSchema extends Record<string, any> = {},\n TRouteContext extends RouteContext = RouteContext,\n TRouterContext extends {} = {},\n TLoaderDeps extends Record<string, any> = {},\n TLoaderData extends any = unknown,\n> extends Route<\n any, // TParentRoute\n '/', // TPath\n '/', // TFullPath\n string, // TCustomId\n RootRouteId, // TId\n TSearchSchema, // TSearchSchema\n TSearchSchema, // TFullSearchSchema\n {}, // TParams\n {}, // TAllParams\n TRouteContext, // TRouteContext\n Expand<Assign<TRouterContext, TRouteContext>>, // TAllContext\n TRouterContext, // TRouterContext\n TLoaderDeps,\n TLoaderData,\n any, // TChildren\n any // TRouteTree\n> {\n constructor(\n options?: Omit<\n RouteOptions<\n AnyRoute, // TParentRoute\n RootRouteId, // TCustomId\n '', // TPath\n TSearchSchema, // TSearchSchema\n TSearchSchema, // TFullSearchSchema\n {}, // TParams\n {}, // TAllParams\n TRouteContext, // TRouteContext\n Assign<TRouterContext, TRouteContext>, // TAllContext\n TLoaderDeps,\n TLoaderData\n >,\n | 'path'\n | 'id'\n | 'getParentRoute'\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n >,\n ) {\n super(options as any)\n }\n}\n\nexport type ResolveFullPath<\n TParentRoute extends AnyRoute,\n TPath extends string,\n TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>,\n> = TPrefixed extends RootRouteId ? '/' : TPrefixed\n\ntype RoutePrefix<\n TPrefix extends string,\n TPath extends string,\n> = string extends TPath\n ? RootRouteId\n : TPath extends string\n ? TPrefix extends RootRouteId\n ? TPath extends '/'\n ? '/'\n : `/${TrimPath<TPath>}`\n : `${TPrefix}/${TPath}` extends '/'\n ? '/'\n : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}`\n : never\n\nexport type TrimPath<T extends string> = '' extends T\n ? ''\n : TrimPathRight<TrimPathLeft<T>>\n\nexport type TrimPathLeft<T extends string> =\n T extends `${RootRouteId}/${infer U}`\n ? TrimPathLeft<U>\n : T extends `/${infer U}`\n ? TrimPathLeft<U>\n : T\nexport type TrimPathRight<T extends string> = T extends '/'\n ? '/'\n : T extends `${infer U}/`\n ? TrimPathRight<U>\n : T\n\nexport type RouteMask<TRouteTree extends AnyRoute> = {\n routeTree: TRouteTree\n from: RoutePaths<TRouteTree>\n to?: any\n params?: any\n search?: any\n hash?: any\n state?: any\n unmaskOnReload?: boolean\n}\n\nexport function createRouteMask<\n TRouteTree extends AnyRoute,\n TFrom extends RoutePaths<TRouteTree>,\n TTo extends string,\n>(\n opts: {\n routeTree: TRouteTree\n } & ToSubOptions<TRouteTree, TFrom, TTo>,\n): RouteMask<TRouteTree> {\n return opts as any\n}\n\nexport type ErrorRouteProps = {\n error: unknown\n info: { componentStack: string }\n}\n//\n\nexport type ReactNode = any\n\nexport type SyncRouteComponent<TProps> =\n | ((props: TProps) => ReactNode)\n | React.LazyExoticComponent<(props: TProps) => ReactNode>\n\nexport type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {\n preload?: () => Promise<void>\n}\n\nexport type RouteComponent<TProps = any> = SyncRouteComponent<TProps> &\n AsyncRouteComponent<TProps>\n\nexport type ErrorRouteComponent = RouteComponent<ErrorRouteProps>\n\nexport class NotFoundRoute<\n TParentRoute extends AnyRootRoute,\n TSearchSchema extends RouteConstraints['TSearchSchema'] = {},\n TFullSearchSchema extends\n RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<\n TParentRoute,\n TSearchSchema\n >,\n TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,\n TAllContext extends Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n > = Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n >,\n TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderData extends any = unknown,\n TChildren extends RouteConstraints['TChildren'] = unknown,\n TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,\n> extends Route<\n TParentRoute,\n '/404',\n '/404',\n '404',\n '404',\n TSearchSchema,\n TFullSearchSchema,\n {},\n {},\n TRouteContext,\n TAllContext,\n TRouterContext,\n TLoaderDeps,\n TLoaderData,\n TChildren,\n TRouteTree\n> {\n constructor(\n options: Omit<\n RouteOptions<\n TParentRoute,\n string,\n string,\n TSearchSchema,\n TFullSearchSchema,\n {},\n {},\n TRouteContext,\n TAllContext,\n TLoaderDeps,\n TLoaderData\n >,\n 'caseSensitive' | 'parseParams' | 'stringifyParams' | 'path' | 'id'\n >,\n ) {\n super({\n ...(options as any),\n id: '404',\n })\n }\n}\n"],"names":["rootRouteId","RouteApi","constructor","id","useMatch","opts","from","useRouteContext","select","d","context","useSearch","useParams","useLoaderDeps","useLoaderData","Route","options","isRoot","getParentRoute","invariant","path","$$typeof","Symbol","for","init","originalIndex","parentRoute","trimPath","customId","joinPaths","fullPath","to","addChildren","children","update","Object","assign","rootRouteWithContext","RootRoute","createRouteMask","NotFoundRoute"],"mappings":";;;;;;;;;;;;;;;;;;AAqBO,MAAMA,WAAW,GAAG,WAAmB;;AA+L9C;;AAwHO,MAAMC,QAAQ,CAWnB;AAGAC,EAAAA,WAAWA,CAAC;AAAEC,IAAAA,EAAAA;AAAgB,GAAC,EAAE;IAC/B,IAAI,CAACA,EAAE,GAAGA,EAAS,CAAA;AACrB,GAAA;EAEAC,QAAQ,GAA6BC,IAEpC,IAAgB;AACf,IAAA,OAAOD,gBAAQ,CAAC;AAAE,MAAA,GAAGC,IAAI;MAAEC,IAAI,EAAE,IAAI,CAACH,EAAAA;AAAG,KAAC,CAAC,CAAA;GAC5C,CAAA;EAEDI,eAAe,GAA6BF,IAE3C,IAAgB;AACf,IAAA,OAAOD,gBAAQ,CAAC;AACd,MAAA,GAAGC,IAAI;MACPC,IAAI,EAAE,IAAI,CAACH,EAAE;AACbK,MAAAA,MAAM,EAAGC,CAAM,IAAMJ,IAAI,EAAEG,MAAM,GAAGH,IAAI,CAACG,MAAM,CAACC,CAAC,CAACC,OAAO,CAAC,GAAGD,CAAC,CAACC,OAAAA;AACjE,KAAQ,CAAC,CAAA;GACV,CAAA;EAEDC,SAAS,GAAmCN,IAE3C,IAAgB;AACf,IAAA,OAAOM,mBAAS,CAAC;AAAE,MAAA,GAAGN,IAAI;MAAEC,IAAI,EAAE,IAAI,CAACH,EAAAA;AAAG,KAAQ,CAAC,CAAA;GACpD,CAAA;EAEDS,SAAS,GAA4BP,IAEpC,IAAgB;AACf,IAAA,OAAOO,mBAAS,CAAC;AAAE,MAAA,GAAGP,IAAI;MAAEC,IAAI,EAAE,IAAI,CAACH,EAAAA;AAAG,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AAE,MAAA,GAAGT,IAAI;MAAEC,IAAI,EAAE,IAAI,CAACH,EAAAA;AAAG,KAAQ,CAAC,CAAA;GACxD,CAAA;AACH,CAAA;AAIO,SAASkC,oBAAoBA,GAA8B;AAChE,EAAA,OAMErB,OAoBC,IAC2D;AAC5D,IAAA,OAAO,IAAIsB,SAAS,CAACtB,OAAO,CAAC,CAAA;GAC9B,CAAA;AACH,CAAA;AAEO,MAAMsB,SAAS,SAMZvB,KAAK,CAiBb;EACAb,WAAWA,CACTc,OAoBC,EACD;IACA,KAAK,CAACA,OAAc,CAAC,CAAA;AACvB,GAAA;AACF,CAAA;AAkDO,SAASuB,eAAeA,CAK7BlC,IAEwC,EACjB;AACvB,EAAA,OAAOA,IAAI,CAAA;AACb,CAAA;;AAMA;;AAiBO,MAAMmC,aAAa,SAmBhBzB,KAAK,CAiBb;EACAb,WAAWA,CACTc,OAeC,EACD;AACA,IAAA,KAAK,CAAC;AACJ,MAAA,GAAIA,OAAe;AACnBb,MAAAA,EAAE,EAAE,KAAA;AACN,KAAC,CAAC,CAAA;AACJ,GAAA;AACF;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"route.js","sources":["../../src/route.ts"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport { useLoaderData, useLoaderDeps, useMatch } from './Matches'\nimport { AnyRouteMatch } from './Matches'\nimport { NavigateOptions, ParsePathParams, ToSubOptions } from './link'\nimport { ParsedLocation } from './location'\nimport { joinPaths, trimPath } from './path'\nimport { RouteById, RouteIds, RoutePaths } from './routeInfo'\nimport { AnyRouter, RegisteredRouter } from './router'\nimport { useParams } from './useParams'\nimport { useSearch } from './useSearch'\nimport {\n Assign,\n Expand,\n IsAny,\n NoInfer,\n PickRequired,\n UnionToIntersection,\n} from './utils'\nimport { BuildLocationFn, NavigateFn } from './RouterProvider'\n\nexport const rootRouteId = '__root__' as const\nexport type RootRouteId = typeof rootRouteId\nexport type AnyPathParams = {}\n\nexport type AnySearchSchema = {}\n\nexport type AnyContext = {}\n\nexport interface RouteContext {}\n\nexport interface RouteMeta {}\n\nexport type PreloadableObj = { preload?: () => Promise<void> }\n\nexport type RoutePathOptions<TCustomId, TPath> =\n | {\n path: TPath\n }\n | {\n id: TCustomId\n }\n\nexport type RoutePathOptionsIntersection<TCustomId, TPath> =\n UnionToIntersection<RoutePathOptions<TCustomId, TPath>>\n\nexport type MetaOptions = keyof PickRequired<RouteMeta> extends never\n ? {\n meta?: RouteMeta\n }\n : {\n meta: RouteMeta\n }\n\nexport type RouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TCustomId extends string = string,\n TPath extends string = string,\n TSearchSchema extends Record<string, any> = {},\n TFullSearchSchema extends Record<string, any> = TSearchSchema,\n TParams extends AnyPathParams = AnyPathParams,\n TAllParams extends AnyPathParams = TParams,\n TRouteContext extends RouteContext = RouteContext,\n TAllContext extends Record<string, any> = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderData extends any = unknown,\n> = BaseRouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext,\n TLoaderDeps,\n TLoaderData\n> &\n UpdatableRouteOptions<NoInfer<TFullSearchSchema>>\n\nexport type ParamsFallback<\n TPath extends string,\n TParams,\n> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams\n\nexport type BaseRouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TCustomId extends string = string,\n TPath extends string = string,\n TSearchSchema extends Record<string, any> = {},\n TFullSearchSchema extends Record<string, any> = TSearchSchema,\n TParams extends AnyPathParams = {},\n TAllParams = ParamsFallback<TPath, TParams>,\n TRouteContext extends RouteContext = RouteContext,\n TAllContext extends Record<string, any> = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderData extends any = unknown,\n> = RoutePathOptions<TCustomId, TPath> & {\n getParentRoute: () => TParentRoute\n validateSearch?: SearchSchemaValidator<TSearchSchema>\n shouldReload?:\n | boolean\n | ((\n match: LoaderFnContext<\n TAllParams,\n TFullSearchSchema,\n TAllContext,\n TRouteContext\n >,\n ) => any)\n} & (keyof PickRequired<RouteContext> extends never\n ? // This async function is called before a route is loaded.\n // If an error is thrown here, the route's loader will not be called.\n // If thrown during a navigation, the navigation will be cancelled and the error will be passed to the `onError` function.\n // If thrown during a preload event, the error will be logged to the console.\n {\n beforeLoad?: BeforeLoadFn<\n TFullSearchSchema,\n TParentRoute,\n TAllParams,\n TRouteContext\n >\n }\n : {\n beforeLoad: BeforeLoadFn<\n TFullSearchSchema,\n TParentRoute,\n TAllParams,\n TRouteContext\n >\n }) & {\n loaderDeps?: (opts: { search: TFullSearchSchema }) => TLoaderDeps\n loader?: RouteLoaderFn<\n TAllParams,\n NoInfer<TLoaderDeps>,\n NoInfer<TAllContext>,\n NoInfer<TRouteContext>,\n TLoaderData\n >\n } & (\n | {\n // Both or none\n parseParams?: (\n rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,\n ) => TParams extends Record<ParsePathParams<TPath>, any>\n ? TParams\n : 'parseParams must return an object'\n stringifyParams?: (\n params: NoInfer<ParamsFallback<TPath, TParams>>,\n ) => Record<ParsePathParams<TPath>, string>\n }\n | {\n stringifyParams?: never\n parseParams?: never\n }\n )\n\ntype BeforeLoadFn<\n TFullSearchSchema extends Record<string, any>,\n TParentRoute extends AnyRoute,\n TAllParams,\n TRouteContext,\n> = (opts: {\n search: TFullSearchSchema\n abortController: AbortController\n preload: boolean\n params: TAllParams\n context: TParentRoute['types']['allContext']\n location: ParsedLocation\n navigate: NavigateFn<AnyRoute>\n buildLocation: BuildLocationFn<TParentRoute>\n cause: 'preload' | 'enter' | 'stay'\n}) => Promise<TRouteContext> | TRouteContext | void\n\nexport type UpdatableRouteOptions<\n TFullSearchSchema extends Record<string, any>,\n> = MetaOptions & {\n // test?: (args: TAllContext) => void\n // If true, this route will be matched as case-sensitive\n caseSensitive?: boolean\n // If true, this route will be forcefully wrapped in a suspense boundary\n wrapInSuspense?: boolean\n // The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`\n component?: RouteComponent\n errorComponent?: false | null | ErrorRouteComponent\n pendingComponent?: RouteComponent\n pendingMs?: number\n pendingMinMs?: number\n staleTime?: number\n gcTime?: number\n preloadStaleTime?: number\n preloadGcTime?: number\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 onError?: (err: any) => void\n // These functions are called as route matches are loaded, stick around and leave the active\n // matches\n onEnter?: (match: AnyRouteMatch) => void\n onStay?: (match: AnyRouteMatch) => void\n onLeave?: (match: AnyRouteMatch) => void\n}\n\nexport type ParseParamsOption<TPath extends string, TParams> = ParseParamsFn<\n TPath,\n TParams\n>\n\nexport type ParseParamsFn<TPath extends string, TParams> = (\n rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,\n) => TParams extends Record<ParsePathParams<TPath>, any>\n ? TParams\n : 'parseParams must return an object'\n\nexport type ParseParamsObj<TPath extends string, TParams> = {\n parse?: ParseParamsFn<TPath, TParams>\n}\n\n// The parse type here allows a zod schema to be passed directly to the validator\nexport type SearchSchemaValidator<TReturn> =\n | SearchSchemaValidatorObj<TReturn>\n | SearchSchemaValidatorFn<TReturn>\n\nexport type SearchSchemaValidatorObj<TReturn> = {\n parse?: SearchSchemaValidatorFn<TReturn>\n}\n\nexport type SearchSchemaValidatorFn<TReturn> = (\n searchObj: Record<string, unknown>,\n) => TReturn\n\nexport type DefinedPathParamWarning =\n 'Path params cannot be redefined by child routes!'\n\nexport type ParentParams<TParentParams> = AnyPathParams extends TParentParams\n ? {}\n : {\n [Key in keyof TParentParams]?: DefinedPathParamWarning\n }\n\nexport type RouteLoaderFn<\n TAllParams = {},\n TLoaderDeps extends Record<string, any> = {},\n TAllContext extends Record<string, any> = AnyContext,\n TRouteContext extends Record<string, any> = AnyContext,\n TLoaderData extends any = unknown,\n> = (\n match: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext, TRouteContext>,\n) => Promise<TLoaderData> | TLoaderData\n\nexport interface LoaderFnContext<\n TAllParams = {},\n TLoaderDeps extends Record<string, any> = {},\n TAllContext extends Record<string, any> = AnyContext,\n TRouteContext extends Record<string, any> = AnyContext,\n> {\n abortController: AbortController\n preload: boolean\n params: TAllParams\n deps: TLoaderDeps\n context: Expand<Assign<TAllContext, TRouteContext>>\n location: ParsedLocation // Do not supply search schema here so as to demotivate people from trying to shortcut loaderDeps\n navigate: (opts: NavigateOptions<AnyRoute>) => Promise<void>\n parentMatchPromise?: Promise<void>\n cause: 'preload' | 'enter' | 'stay'\n}\n\nexport type SearchFilter<T, U = T> = (prev: T) => U\n\nexport type ResolveId<\n TParentRoute,\n TCustomId extends string,\n TPath extends string,\n> = TParentRoute extends { id: infer TParentId extends string }\n ? RoutePrefix<TParentId, string extends TCustomId ? TPath : TCustomId>\n : RootRouteId\n\nexport type InferFullSearchSchema<TRoute> = TRoute extends {\n types: {\n fullSearchSchema: infer TFullSearchSchema\n }\n}\n ? TFullSearchSchema\n : {}\n\nexport type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = Expand<\n Assign<InferFullSearchSchema<TParentRoute>, TSearchSchema>\n>\n\nexport interface AnyRoute\n extends Route<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > {}\n\nexport type MergeFromFromParent<T, U> = IsAny<T, U, T & U>\n\nexport type ResolveAllParams<\n TParentRoute extends AnyRoute,\n TParams extends AnyPathParams,\n> = Record<never, string> extends TParentRoute['types']['allParams']\n ? TParams\n : Expand<\n UnionToIntersection<TParentRoute['types']['allParams'] & TParams> & {}\n >\n\nexport type RouteConstraints = {\n TParentRoute: AnyRoute\n TPath: string\n TFullPath: string\n TCustomId: string\n TId: string\n TSearchSchema: AnySearchSchema\n TFullSearchSchema: AnySearchSchema\n TParams: Record<string, any>\n TAllParams: Record<string, any>\n TParentContext: AnyContext\n TRouteContext: RouteContext\n TAllContext: AnyContext\n TRouterContext: AnyContext\n TChildren: unknown\n TRouteTree: AnyRoute\n}\n\nexport class RouteApi<\n TId extends RouteIds<RegisteredRouter['routeTree']>,\n TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,\n TFullSearchSchema extends Record<\n string,\n any\n > = TRoute['types']['fullSearchSchema'],\n TAllParams extends AnyPathParams = TRoute['types']['allParams'],\n TAllContext extends Record<string, any> = TRoute['types']['allContext'],\n TLoaderDeps extends Record<string, any> = TRoute['types']['loaderDeps'],\n TLoaderData extends any = TRoute['types']['loaderData'],\n> {\n id: TId\n\n constructor({ id }: { id: TId }) {\n this.id = id as any\n }\n\n useMatch = <TSelected = TAllContext>(opts?: {\n select?: (s: TAllContext) => TSelected\n }): TSelected => {\n return useMatch({ ...opts, from: this.id }) as any\n }\n\n useRouteContext = <TSelected = TAllContext>(opts?: {\n select?: (s: TAllContext) => TSelected\n }): TSelected => {\n return useMatch({\n ...opts,\n from: this.id,\n select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),\n } as any)\n }\n\n useSearch = <TSelected = TFullSearchSchema>(opts?: {\n select?: (s: TFullSearchSchema) => TSelected\n }): TSelected => {\n return useSearch({ ...opts, from: this.id } as any)\n }\n\n useParams = <TSelected = TAllParams>(opts?: {\n select?: (s: TAllParams) => TSelected\n }): TSelected => {\n return useParams({ ...opts, from: this.id } as any)\n }\n\n useLoaderDeps = <TSelected = TLoaderDeps>(opts?: {\n select?: (s: TLoaderDeps) => TSelected\n }): TSelected => {\n return useLoaderDeps({ ...opts, from: this.id } as any) as any\n }\n\n useLoaderData = <TSelected = TLoaderData>(opts?: {\n select?: (s: TLoaderData) => TSelected\n }): TSelected => {\n return useLoaderData({ ...opts, from: this.id } as any) as any\n }\n}\n\nexport class Route<\n TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,\n TPath extends RouteConstraints['TPath'] = '/',\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n TPath\n >,\n TCustomId extends RouteConstraints['TCustomId'] = string,\n TId extends RouteConstraints['TId'] = ResolveId<\n TParentRoute,\n TCustomId,\n TPath\n >,\n TSearchSchema extends RouteConstraints['TSearchSchema'] = {},\n TFullSearchSchema extends\n RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<\n TParentRoute,\n TSearchSchema\n >,\n TParams extends RouteConstraints['TParams'] = Expand<\n Record<ParsePathParams<TPath>, string>\n >,\n TAllParams extends RouteConstraints['TAllParams'] = ResolveAllParams<\n TParentRoute,\n TParams\n >,\n TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,\n TAllContext extends Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n > = Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n >,\n TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderData extends any = unknown,\n TChildren extends RouteConstraints['TChildren'] = unknown,\n TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,\n> {\n isRoot: TParentRoute extends Route<any> ? true : false\n options: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext,\n TLoaderDeps,\n TLoaderData\n >\n\n test!: Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n >\n\n // Set up in this.init()\n parentRoute!: TParentRoute\n id!: TId\n // customId!: TCustomId\n path!: TPath\n fullPath!: TFullPath\n to!: TrimPathRight<TFullPath>\n\n // Optional\n children?: TChildren\n originalIndex?: number\n router?: AnyRouter\n rank!: number\n\n constructor(\n options: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext,\n TLoaderDeps,\n TLoaderData\n >,\n ) {\n this.options = (options as any) || {}\n this.isRoot = !options?.getParentRoute as any\n invariant(\n !((options as any)?.id && (options as any)?.path),\n `Route cannot have both an 'id' and a 'path' option.`,\n )\n ;(this as any).$$typeof = Symbol.for('react.memo')\n }\n\n types!: {\n parentRoute: TParentRoute\n path: TPath\n to: TrimPathRight<TFullPath>\n fullPath: TFullPath\n customId: TCustomId\n id: TId\n searchSchema: TSearchSchema\n fullSearchSchema: TFullSearchSchema\n params: TParams\n allParams: TAllParams\n routeContext: TRouteContext\n allContext: TAllContext\n children: TChildren\n routeTree: TRouteTree\n routerContext: TRouterContext\n loaderData: TLoaderData\n loaderDeps: TLoaderDeps\n }\n\n init = (opts: { originalIndex: number }) => {\n this.originalIndex = opts.originalIndex\n\n const options = this.options as RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext,\n TLoaderDeps,\n TLoaderData\n > &\n RoutePathOptionsIntersection<TCustomId, TPath>\n\n const isRoot = !options?.path && !options?.id\n\n this.parentRoute = this.options?.getParentRoute?.()\n\n if (isRoot) {\n this.path = rootRouteId as TPath\n } else {\n invariant(\n this.parentRoute,\n `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`,\n )\n }\n\n let path: undefined | string = isRoot ? rootRouteId : options.path\n\n // If the path is anything other than an index path, trim it up\n if (path && path !== '/') {\n path = trimPath(path)\n }\n\n const customId = options?.id || path\n\n // Strip the parentId prefix from the first level of children\n let id = isRoot\n ? rootRouteId\n : joinPaths([\n (this.parentRoute.id as any) === rootRouteId\n ? ''\n : this.parentRoute.id,\n customId,\n ])\n\n if (path === rootRouteId) {\n path = '/'\n }\n\n if (id !== rootRouteId) {\n id = joinPaths(['/', id])\n }\n\n const fullPath =\n id === rootRouteId ? '/' : joinPaths([this.parentRoute.fullPath, path])\n\n this.path = path as TPath\n this.id = id as TId\n // this.customId = customId as TCustomId\n this.fullPath = fullPath as TFullPath\n this.to = fullPath as TrimPathRight<TFullPath>\n }\n\n addChildren = <TNewChildren extends AnyRoute[]>(\n children: TNewChildren,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext,\n TRouterContext,\n TLoaderDeps,\n TLoaderData,\n TNewChildren,\n TRouteTree\n > => {\n this.children = children as any\n return this as any\n }\n\n update = (options: UpdatableRouteOptions<TFullSearchSchema>) => {\n Object.assign(this.options, options)\n return this\n }\n\n useMatch = <TSelected = TAllContext>(opts?: {\n select?: (search: TAllContext) => TSelected\n }): TSelected => {\n return useMatch({ ...opts, from: this.id }) as any\n }\n\n useRouteContext = <TSelected = TAllContext>(opts?: {\n select?: (search: TAllContext) => TSelected\n }): TSelected => {\n return useMatch({\n ...opts,\n from: this.id,\n select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),\n } as any)\n }\n\n useSearch = <TSelected = TFullSearchSchema>(opts?: {\n select?: (search: TFullSearchSchema) => TSelected\n }): TSelected => {\n return useSearch({ ...opts, from: this.id } as any)\n }\n\n useParams = <TSelected = TAllParams>(opts?: {\n select?: (search: TAllParams) => TSelected\n }): TSelected => {\n return useParams({ ...opts, from: this.id } as any)\n }\n\n useLoaderDeps = <TSelected = TLoaderDeps>(opts?: {\n select?: (s: TLoaderDeps) => TSelected\n }): TSelected => {\n return useLoaderDeps({ ...opts, from: this.id } as any) as any\n }\n\n useLoaderData = <TSelected = TLoaderData>(opts?: {\n select?: (search: TLoaderData) => TSelected\n }): TSelected => {\n return useLoaderData({ ...opts, from: this.id } as any) as any\n }\n}\n\nexport type AnyRootRoute = RootRoute<any, any, any, any>\n\nexport function rootRouteWithContext<TRouterContext extends {}>() {\n return <\n TSearchSchema extends Record<string, any> = {},\n TRouteContext extends RouteContext = RouteContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderData extends any = unknown,\n >(\n options?: Omit<\n RouteOptions<\n AnyRoute, // TParentRoute\n RootRouteId, // TCustomId\n '', // TPath\n TSearchSchema, // TSearchSchema\n TSearchSchema, // TFullSearchSchema\n {}, // TParams\n {}, // TAllParams\n TRouteContext, // TRouteContext\n Assign<TRouterContext, TRouteContext>, // TAllContext\n TLoaderDeps,\n TLoaderData // TLoaderData,\n >,\n | 'path'\n | 'id'\n | 'getParentRoute'\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n >,\n ): RootRoute<TSearchSchema, TRouteContext, TRouterContext> => {\n return new RootRoute(options) as any\n }\n}\n\nexport class RootRoute<\n TSearchSchema extends Record<string, any> = {},\n TRouteContext extends RouteContext = RouteContext,\n TRouterContext extends {} = {},\n TLoaderDeps extends Record<string, any> = {},\n TLoaderData extends any = unknown,\n> extends Route<\n any, // TParentRoute\n '/', // TPath\n '/', // TFullPath\n string, // TCustomId\n RootRouteId, // TId\n TSearchSchema, // TSearchSchema\n TSearchSchema, // TFullSearchSchema\n {}, // TParams\n {}, // TAllParams\n TRouteContext, // TRouteContext\n Expand<Assign<TRouterContext, TRouteContext>>, // TAllContext\n TRouterContext, // TRouterContext\n TLoaderDeps,\n TLoaderData,\n any, // TChildren\n any // TRouteTree\n> {\n constructor(\n options?: Omit<\n RouteOptions<\n AnyRoute, // TParentRoute\n RootRouteId, // TCustomId\n '', // TPath\n TSearchSchema, // TSearchSchema\n TSearchSchema, // TFullSearchSchema\n {}, // TParams\n {}, // TAllParams\n TRouteContext, // TRouteContext\n Assign<TRouterContext, TRouteContext>, // TAllContext\n TLoaderDeps,\n TLoaderData\n >,\n | 'path'\n | 'id'\n | 'getParentRoute'\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n >,\n ) {\n super(options as any)\n }\n}\n\nexport type ResolveFullPath<\n TParentRoute extends AnyRoute,\n TPath extends string,\n TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>,\n> = TPrefixed extends RootRouteId ? '/' : TPrefixed\n\ntype RoutePrefix<\n TPrefix extends string,\n TPath extends string,\n> = string extends TPath\n ? RootRouteId\n : TPath extends string\n ? TPrefix extends RootRouteId\n ? TPath extends '/'\n ? '/'\n : `/${TrimPath<TPath>}`\n : `${TPrefix}/${TPath}` extends '/'\n ? '/'\n : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}`\n : never\n\nexport type TrimPath<T extends string> = '' extends T\n ? ''\n : TrimPathRight<TrimPathLeft<T>>\n\nexport type TrimPathLeft<T extends string> =\n T extends `${RootRouteId}/${infer U}`\n ? TrimPathLeft<U>\n : T extends `/${infer U}`\n ? TrimPathLeft<U>\n : T\nexport type TrimPathRight<T extends string> = T extends '/'\n ? '/'\n : T extends `${infer U}/`\n ? TrimPathRight<U>\n : T\n\nexport type RouteMask<TRouteTree extends AnyRoute> = {\n routeTree: TRouteTree\n from: RoutePaths<TRouteTree>\n to?: any\n params?: any\n search?: any\n hash?: any\n state?: any\n unmaskOnReload?: boolean\n}\n\nexport function createRouteMask<\n TRouteTree extends AnyRoute,\n TFrom extends RoutePaths<TRouteTree>,\n TTo extends string,\n>(\n opts: {\n routeTree: TRouteTree\n } & ToSubOptions<TRouteTree, TFrom, TTo>,\n): RouteMask<TRouteTree> {\n return opts as any\n}\n\nexport type ErrorRouteProps = {\n error: unknown\n info: { componentStack: string }\n}\n//\n\nexport type ReactNode = any\n\nexport type SyncRouteComponent<TProps> =\n | ((props: TProps) => ReactNode)\n | React.LazyExoticComponent<(props: TProps) => ReactNode>\n\nexport type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {\n preload?: () => Promise<void>\n}\n\nexport type RouteComponent<TProps = any> = SyncRouteComponent<TProps> &\n AsyncRouteComponent<TProps>\n\nexport type ErrorRouteComponent = RouteComponent<ErrorRouteProps>\n\nexport class NotFoundRoute<\n TParentRoute extends AnyRootRoute,\n TSearchSchema extends RouteConstraints['TSearchSchema'] = {},\n TFullSearchSchema extends\n RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<\n TParentRoute,\n TSearchSchema\n >,\n TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,\n TAllContext extends Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n > = Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n >,\n TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderData extends any = unknown,\n TChildren extends RouteConstraints['TChildren'] = unknown,\n TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,\n> extends Route<\n TParentRoute,\n '/404',\n '/404',\n '404',\n '404',\n TSearchSchema,\n TFullSearchSchema,\n {},\n {},\n TRouteContext,\n TAllContext,\n TRouterContext,\n TLoaderDeps,\n TLoaderData,\n TChildren,\n TRouteTree\n> {\n constructor(\n options: Omit<\n RouteOptions<\n TParentRoute,\n string,\n string,\n TSearchSchema,\n TFullSearchSchema,\n {},\n {},\n TRouteContext,\n TAllContext,\n TLoaderDeps,\n TLoaderData\n >,\n 'caseSensitive' | 'parseParams' | 'stringifyParams' | 'path' | 'id'\n >,\n ) {\n super({\n ...(options as any),\n id: '404',\n })\n }\n}\n"],"names":["rootRouteId","RouteApi","constructor","id","useMatch","opts","from","useRouteContext","select","d","context","useSearch","useParams","useLoaderDeps","useLoaderData","Route","options","isRoot","getParentRoute","invariant","path","$$typeof","Symbol","for","init","originalIndex","parentRoute","trimPath","customId","joinPaths","fullPath","to","addChildren","children","update","Object","assign","rootRouteWithContext","RootRoute","createRouteMask","NotFoundRoute"],"mappings":";;;;;;;;;;;;;;;;;;AAqBO,MAAMA,WAAW,GAAG,WAAmB;;AAyM9C;;AAwHO,MAAMC,QAAQ,CAWnB;AAGAC,EAAAA,WAAWA,CAAC;AAAEC,IAAAA,EAAAA;AAAgB,GAAC,EAAE;IAC/B,IAAI,CAACA,EAAE,GAAGA,EAAS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jB;AACvB,EAAA,OAAOA,IAAI,CAAA;AACb,CAAA;;AAMA;;AAiBO,MAAMmC,aAAa,SAmBhBzB,KAAK,CAiBb;EACAb,WAAWA,CACTc,OAeC,EACD;AACA,IAAA,KAAK,CAAC;AACJ,MAAA,GAAIA,OAAe;AACnBb,MAAAA,EAAE,EAAE,KAAA;AACN,KAAC,CAAC,CAAA;AACJ,GAAA;AACF;;;;;;;;;;"}
|
package/build/cjs/router.js
CHANGED
|
@@ -356,7 +356,8 @@ class Router {
|
|
|
356
356
|
abortController: new AbortController(),
|
|
357
357
|
fetchCount: 0,
|
|
358
358
|
cause,
|
|
359
|
-
loaderDeps
|
|
359
|
+
loaderDeps,
|
|
360
|
+
invalid: false
|
|
360
361
|
};
|
|
361
362
|
|
|
362
363
|
// Regardless of whether we're reusing an existing match or creating
|
|
@@ -559,8 +560,7 @@ class Router {
|
|
|
559
560
|
loadMatches = async ({
|
|
560
561
|
checkLatest,
|
|
561
562
|
matches,
|
|
562
|
-
preload
|
|
563
|
-
invalidate
|
|
563
|
+
preload
|
|
564
564
|
}) => {
|
|
565
565
|
let latestPromise;
|
|
566
566
|
let firstBadMatchIndex;
|
|
@@ -675,24 +675,27 @@ class Router {
|
|
|
675
675
|
const pendingMs = route.options.pendingMs ?? this.options.defaultPendingMs;
|
|
676
676
|
const pendingMinMs = route.options.pendingMinMs ?? this.options.defaultPendingMinMs;
|
|
677
677
|
const shouldPending = !preload && pendingMs && (route.options.pendingComponent ?? this.options.defaultPendingComponent);
|
|
678
|
+
const loaderContext = {
|
|
679
|
+
params: match.params,
|
|
680
|
+
deps: match.loaderDeps,
|
|
681
|
+
preload: !!preload,
|
|
682
|
+
parentMatchPromise,
|
|
683
|
+
abortController: match.abortController,
|
|
684
|
+
context: match.context,
|
|
685
|
+
location: this.state.location,
|
|
686
|
+
navigate: opts => this.navigate({
|
|
687
|
+
...opts,
|
|
688
|
+
from: match.pathname
|
|
689
|
+
}),
|
|
690
|
+
cause: preload ? 'preload' : match.cause
|
|
691
|
+
};
|
|
678
692
|
const fetch = async () => {
|
|
679
693
|
if (match.isFetching) {
|
|
680
694
|
loadPromise = RouterProvider.getRouteMatch(this.state, match.id)?.loadPromise;
|
|
681
695
|
} else {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
preload: !!preload,
|
|
686
|
-
parentMatchPromise,
|
|
687
|
-
abortController: match.abortController,
|
|
688
|
-
context: match.context,
|
|
689
|
-
location: this.state.location,
|
|
690
|
-
navigate: opts => this.navigate({
|
|
691
|
-
...opts,
|
|
692
|
-
from: match.pathname
|
|
693
|
-
}),
|
|
694
|
-
cause: preload ? 'preload' : match.cause
|
|
695
|
-
};
|
|
696
|
+
// If the user doesn't want the route to reload, just
|
|
697
|
+
// resolve with the existing loader data
|
|
698
|
+
|
|
696
699
|
if (match.fetchCount && match.status === 'success') {
|
|
697
700
|
resolve();
|
|
698
701
|
}
|
|
@@ -759,14 +762,15 @@ class Router {
|
|
|
759
762
|
const age = Date.now() - match.updatedAt;
|
|
760
763
|
let staleAge = preload ? route.options.preloadStaleTime ?? this.options.defaultPreloadStaleTime ?? 30_000 // 30 seconds for preloads by default
|
|
761
764
|
: route.options.staleTime ?? this.options.defaultStaleTime ?? 0;
|
|
762
|
-
if (match.status === 'success') {
|
|
763
|
-
// Background Fetching, no need to wait
|
|
764
|
-
if (age > staleAge) {
|
|
765
|
-
fetch();
|
|
766
|
-
}
|
|
767
|
-
} else {
|
|
768
|
-
// Critical Fetching, we need to await
|
|
769
765
|
|
|
766
|
+
// Default to reloading the route all the time
|
|
767
|
+
let shouldReload;
|
|
768
|
+
const shouldReloadOption = route.options.shouldReload;
|
|
769
|
+
|
|
770
|
+
// Allow shouldReload to get the last say,
|
|
771
|
+
// if provided.
|
|
772
|
+
shouldReload = typeof shouldReloadOption === 'function' ? shouldReloadOption(loaderContext) : shouldReloadOption;
|
|
773
|
+
if (match.status !== 'success') {
|
|
770
774
|
// If we need to potentially show the pending component,
|
|
771
775
|
// start a timer to show it after the pendingMs
|
|
772
776
|
if (shouldPending) {
|
|
@@ -781,7 +785,12 @@ class Router {
|
|
|
781
785
|
resolve();
|
|
782
786
|
});
|
|
783
787
|
}
|
|
788
|
+
|
|
789
|
+
// Critical Fetching, we need to await
|
|
784
790
|
await fetch();
|
|
791
|
+
} else if (match.invalid || (shouldReload ?? age > staleAge)) {
|
|
792
|
+
// Background Fetching, no need to wait
|
|
793
|
+
fetch();
|
|
785
794
|
}
|
|
786
795
|
resolve();
|
|
787
796
|
}));
|
|
@@ -789,10 +798,20 @@ class Router {
|
|
|
789
798
|
await Promise.all(matchPromises);
|
|
790
799
|
return matches;
|
|
791
800
|
};
|
|
792
|
-
invalidate = () =>
|
|
793
|
-
invalidate
|
|
794
|
-
|
|
795
|
-
|
|
801
|
+
invalidate = () => {
|
|
802
|
+
const invalidate = d => ({
|
|
803
|
+
...d,
|
|
804
|
+
invalid: true
|
|
805
|
+
});
|
|
806
|
+
this.__store.setState(s => ({
|
|
807
|
+
...s,
|
|
808
|
+
matches: s.matches.map(invalidate),
|
|
809
|
+
cachedMatches: s.cachedMatches.map(invalidate),
|
|
810
|
+
pendingMatches: s.pendingMatches?.map(invalidate)
|
|
811
|
+
}));
|
|
812
|
+
this.load();
|
|
813
|
+
};
|
|
814
|
+
load = async () => {
|
|
796
815
|
const promise = new Promise(async (resolve, reject) => {
|
|
797
816
|
const next = this.latestLocation;
|
|
798
817
|
const prevLocation = this.state.resolvedLocation;
|
|
@@ -843,8 +862,7 @@ class Router {
|
|
|
843
862
|
// Load the matches
|
|
844
863
|
await this.loadMatches({
|
|
845
864
|
matches: pendingMatches,
|
|
846
|
-
checkLatest: () => this.checkLatest(promise)
|
|
847
|
-
invalidate: opts?.invalidate
|
|
865
|
+
checkLatest: () => this.checkLatest(promise)
|
|
848
866
|
});
|
|
849
867
|
} catch (err) {
|
|
850
868
|
// swallow this error, since we'll display the
|