@tanstack/react-router 1.53.1 → 1.56.1
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/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +2 -2
- package/dist/cjs/RouterProvider.cjs.map +1 -1
- package/dist/cjs/RouterProvider.d.cts +2 -2
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +10 -1
- package/dist/cjs/index.d.cts +3 -3
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +22 -21
- package/dist/cjs/redirects.cjs.map +1 -1
- package/dist/cjs/redirects.d.cts +2 -2
- package/dist/cjs/route.cjs +18 -2
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +8 -5
- package/dist/cjs/routeInfo.d.cts +32 -21
- package/dist/cjs/router.cjs +4 -1
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +2 -2
- package/dist/cjs/useLoaderData.cjs.map +1 -1
- package/dist/cjs/useLoaderData.d.cts +3 -3
- package/dist/cjs/useLoaderDeps.cjs.map +1 -1
- package/dist/cjs/useLoaderDeps.d.cts +2 -2
- package/dist/cjs/useMatch.cjs.map +1 -1
- package/dist/cjs/useMatch.d.cts +2 -2
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/cjs/useNavigate.d.cts +2 -2
- package/dist/cjs/useParams.cjs.map +1 -1
- package/dist/cjs/useParams.d.cts +2 -2
- package/dist/cjs/useRouteContext.cjs.map +1 -1
- package/dist/cjs/useRouteContext.d.cts +2 -2
- package/dist/cjs/useSearch.cjs.map +1 -1
- package/dist/cjs/useSearch.d.cts +2 -2
- package/dist/esm/Matches.d.ts +2 -2
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/RouterProvider.d.ts +2 -2
- package/dist/esm/RouterProvider.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +10 -1
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/link.d.ts +22 -21
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/redirects.d.ts +2 -2
- package/dist/esm/redirects.js.map +1 -1
- package/dist/esm/route.d.ts +8 -5
- package/dist/esm/route.js +18 -2
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/routeInfo.d.ts +32 -21
- package/dist/esm/router.d.ts +2 -2
- package/dist/esm/router.js +4 -1
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/useLoaderData.d.ts +3 -3
- package/dist/esm/useLoaderData.js.map +1 -1
- package/dist/esm/useLoaderDeps.d.ts +2 -2
- package/dist/esm/useLoaderDeps.js.map +1 -1
- package/dist/esm/useMatch.d.ts +2 -2
- package/dist/esm/useMatch.js.map +1 -1
- package/dist/esm/useNavigate.d.ts +2 -2
- package/dist/esm/useNavigate.js.map +1 -1
- package/dist/esm/useParams.d.ts +2 -2
- package/dist/esm/useParams.js.map +1 -1
- package/dist/esm/useRouteContext.d.ts +2 -2
- package/dist/esm/useRouteContext.js.map +1 -1
- package/dist/esm/useSearch.d.ts +2 -2
- package/dist/esm/useSearch.js.map +1 -1
- package/package.json +1 -1
- package/src/Matches.tsx +15 -22
- package/src/RouterProvider.tsx +4 -4
- package/src/fileRoute.ts +25 -1
- package/src/index.tsx +10 -1
- package/src/link.tsx +81 -76
- package/src/redirects.ts +8 -8
- package/src/route.ts +98 -9
- package/src/routeInfo.ts +116 -38
- package/src/router.ts +9 -5
- package/src/useLoaderData.tsx +3 -3
- package/src/useLoaderDeps.tsx +3 -3
- package/src/useMatch.tsx +9 -3
- package/src/useNavigate.tsx +5 -5
- package/src/useParams.tsx +10 -3
- package/src/useRouteContext.ts +8 -3
- package/src/useSearch.tsx +11 -4
package/dist/cjs/router.d.cts
CHANGED
|
@@ -502,8 +502,8 @@ export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailing
|
|
|
502
502
|
invalidate: () => Promise<void>;
|
|
503
503
|
resolveRedirect: (err: AnyRedirect) => ResolvedRedirect;
|
|
504
504
|
cleanCache: () => void;
|
|
505
|
-
preloadRoute: <TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string =
|
|
506
|
-
matchRoute: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string =
|
|
505
|
+
preloadRoute: <TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string | undefined = undefined, TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom, TMaskTo extends string = "">(opts: NavigateOptions<Router<TRouteTree, TTrailingSlashOption, TDehydrated, TSerializedError>, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<Array<AnyRouteMatch> | undefined>;
|
|
506
|
+
matchRoute: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string | undefined = undefined, TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<Router<TRouteTree, TTrailingSlashOption, TDehydrated, TSerializedError>, TFrom, TTo>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>["types"]["allParams"];
|
|
507
507
|
dehydrate: () => DehydratedRouter;
|
|
508
508
|
hydrate: () => void;
|
|
509
509
|
injectedHtml: Array<() => string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLoaderData.cjs","sources":["../../src/useLoaderData.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { RegisteredRouter } from './router'\nimport type { AnyRoute } from './route'\nimport type { MakeRouteMatch } from './Matches'\nimport type { RouteIds } from './routeInfo'\nimport type { StrictOrFrom } from './utils'\n\nexport type UseLoaderDataOptions<\n TRouteTree extends AnyRoute,\n TFrom,\n TStrict extends boolean,\n TRouteMatch extends MakeRouteMatch<TRouteTree, TFrom, TStrict>,\n TSelected,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (match: Required<TRouteMatch>['loaderData']) => TSelected\n}\n\nexport function useLoaderData<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends
|
|
1
|
+
{"version":3,"file":"useLoaderData.cjs","sources":["../../src/useLoaderData.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { RegisteredRouter } from './router'\nimport type { AnyRoute } from './route'\nimport type { MakeRouteMatch } from './Matches'\nimport type { RouteIds } from './routeInfo'\nimport type { Constrain, StrictOrFrom } from './utils'\n\nexport type UseLoaderDataOptions<\n TRouteTree extends AnyRoute,\n TFrom,\n TStrict extends boolean,\n TRouteMatch extends MakeRouteMatch<TRouteTree, TFrom, TStrict>,\n TSelected,\n> = StrictOrFrom<Constrain<TFrom, RouteIds<TRouteTree>>, TStrict> & {\n select?: (match: Required<TRouteMatch>['loaderData']) => TSelected\n}\n\nexport function useLoaderData<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends string | undefined = undefined,\n TStrict extends boolean = true,\n TRouteMatch extends MakeRouteMatch<\n TRouteTree,\n TFrom,\n TStrict\n > = MakeRouteMatch<TRouteTree, TFrom, TStrict>,\n TSelected = Required<TRouteMatch>['loaderData'],\n>(\n opts: UseLoaderDataOptions<\n TRouteTree,\n TFrom,\n TStrict,\n TRouteMatch,\n TSelected\n >,\n): TSelected {\n return useMatch<TRouteTree, TFrom, TStrict, TRouteMatch, TSelected>({\n ...opts,\n select: (s) => {\n return typeof opts.select === 'function'\n ? opts.select(s.loaderData)\n : (s.loaderData as TSelected)\n },\n })\n}\n"],"names":["useMatch"],"mappings":";;;AAiBO,SAAS,cAWd,MAOW;AACX,SAAOA,kBAA6D;AAAA,IAClE,GAAG;AAAA,IACH,QAAQ,CAAC,MAAM;AACN,aAAA,OAAO,KAAK,WAAW,aAC1B,KAAK,OAAO,EAAE,UAAU,IACvB,EAAE;AAAA,IACT;AAAA,EAAA,CACD;AACH;;"}
|
|
@@ -2,8 +2,8 @@ import { RegisteredRouter } from './router.cjs';
|
|
|
2
2
|
import { AnyRoute } from './route.cjs';
|
|
3
3
|
import { MakeRouteMatch } from './Matches.cjs';
|
|
4
4
|
import { RouteIds } from './routeInfo.cjs';
|
|
5
|
-
import { StrictOrFrom } from './utils.cjs';
|
|
6
|
-
export type UseLoaderDataOptions<TRouteTree extends AnyRoute, TFrom, TStrict extends boolean, TRouteMatch extends MakeRouteMatch<TRouteTree, TFrom, TStrict>, TSelected> = StrictOrFrom<TFrom, TStrict> & {
|
|
5
|
+
import { Constrain, StrictOrFrom } from './utils.cjs';
|
|
6
|
+
export type UseLoaderDataOptions<TRouteTree extends AnyRoute, TFrom, TStrict extends boolean, TRouteMatch extends MakeRouteMatch<TRouteTree, TFrom, TStrict>, TSelected> = StrictOrFrom<Constrain<TFrom, RouteIds<TRouteTree>>, TStrict> & {
|
|
7
7
|
select?: (match: Required<TRouteMatch>['loaderData']) => TSelected;
|
|
8
8
|
};
|
|
9
|
-
export declare function useLoaderData<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends
|
|
9
|
+
export declare function useLoaderData<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends string | undefined = undefined, TStrict extends boolean = true, TRouteMatch extends MakeRouteMatch<TRouteTree, TFrom, TStrict> = MakeRouteMatch<TRouteTree, TFrom, TStrict>, TSelected = Required<TRouteMatch>['loaderData']>(opts: UseLoaderDataOptions<TRouteTree, TFrom, TStrict, TRouteMatch, TSelected>): TSelected;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLoaderDeps.cjs","sources":["../../src/useLoaderDeps.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { RegisteredRouter } from './router'\nimport type { AnyRoute } from './route'\nimport type { MakeRouteMatch } from './Matches'\nimport type { RouteIds } from './routeInfo'\nimport type { StrictOrFrom } from './utils'\n\nexport function useLoaderDeps<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends
|
|
1
|
+
{"version":3,"file":"useLoaderDeps.cjs","sources":["../../src/useLoaderDeps.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { RegisteredRouter } from './router'\nimport type { AnyRoute } from './route'\nimport type { MakeRouteMatch } from './Matches'\nimport type { RouteIds } from './routeInfo'\nimport type { Constrain, StrictOrFrom } from './utils'\n\nexport function useLoaderDeps<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends string | undefined = undefined,\n TRouteMatch extends MakeRouteMatch<TRouteTree, TFrom> = MakeRouteMatch<\n TRouteTree,\n TFrom\n >,\n TSelected = Required<TRouteMatch>['loaderDeps'],\n>(\n opts: StrictOrFrom<Constrain<TFrom, RouteIds<TRouteTree>>> & {\n select?: (match: TRouteMatch) => TSelected\n },\n): TSelected {\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"],"names":["useMatch"],"mappings":";;;AAOO,SAAS,cASd,MAGW;AACX,SAAOA,kBAAS;AAAA,IACd,GAAG;AAAA,IACH,QAAQ,CAAC,MAAM;AACN,aAAA,OAAO,KAAK,WAAW,aAC1B,KAAK,OAAO,EAAE,UAAU,IACxB,EAAE;AAAA,IACR;AAAA,EAAA,CACD;AACH;;"}
|
|
@@ -2,7 +2,7 @@ import { RegisteredRouter } from './router.cjs';
|
|
|
2
2
|
import { AnyRoute } from './route.cjs';
|
|
3
3
|
import { MakeRouteMatch } from './Matches.cjs';
|
|
4
4
|
import { RouteIds } from './routeInfo.cjs';
|
|
5
|
-
import { StrictOrFrom } from './utils.cjs';
|
|
6
|
-
export declare function useLoaderDeps<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends
|
|
5
|
+
import { Constrain, StrictOrFrom } from './utils.cjs';
|
|
6
|
+
export declare function useLoaderDeps<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends string | undefined = undefined, TRouteMatch extends MakeRouteMatch<TRouteTree, TFrom> = MakeRouteMatch<TRouteTree, TFrom>, TSelected = Required<TRouteMatch>['loaderDeps']>(opts: StrictOrFrom<Constrain<TFrom, RouteIds<TRouteTree>>> & {
|
|
7
7
|
select?: (match: TRouteMatch) => TSelected;
|
|
8
8
|
}): TSelected;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMatch.cjs","sources":["../../src/useMatch.tsx"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport { useRouterState } from './useRouterState'\nimport { matchContext } from './matchContext'\nimport type { RegisteredRouter } from './router'\nimport type { AnyRoute } from './route'\nimport type { MakeRouteMatch } from './Matches'\nimport type { RouteIds } from './routeInfo'\nimport type { StrictOrFrom } from './utils'\n\nexport type UseMatchOptions<\n TFrom,\n TStrict extends boolean,\n TRouteMatch,\n TSelected,\n TThrow extends boolean,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (match: TRouteMatch) => TSelected\n shouldThrow?: TThrow\n}\n\nexport function useMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends
|
|
1
|
+
{"version":3,"file":"useMatch.cjs","sources":["../../src/useMatch.tsx"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport { useRouterState } from './useRouterState'\nimport { matchContext } from './matchContext'\nimport type { RegisteredRouter } from './router'\nimport type { AnyRoute } from './route'\nimport type { MakeRouteMatch } from './Matches'\nimport type { RouteIds } from './routeInfo'\nimport type { Constrain, StrictOrFrom } from './utils'\n\nexport type UseMatchOptions<\n TFrom,\n TStrict extends boolean,\n TRouteMatch,\n TSelected,\n TThrow extends boolean,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (match: TRouteMatch) => TSelected\n shouldThrow?: TThrow\n}\n\nexport function useMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends string | undefined = undefined,\n TStrict extends boolean = true,\n TRouteMatch = MakeRouteMatch<TRouteTree, TFrom, TStrict>,\n TSelected = TRouteMatch,\n TThrow extends boolean = true,\n>(\n opts: UseMatchOptions<\n Constrain<TFrom, RouteIds<TRouteTree>>,\n TStrict,\n TRouteMatch,\n TSelected,\n TThrow\n >,\n): TThrow extends true ? TSelected : TSelected | undefined {\n const nearestMatchId = React.useContext(matchContext)\n\n const matchSelection = useRouterState({\n select: (state) => {\n const match = state.matches.find((d) =>\n opts.from ? opts.from === d.routeId : d.id === nearestMatchId,\n )\n invariant(\n !((opts.shouldThrow ?? true) && !match),\n `Could not find ${opts.from ? `an active match from \"${opts.from}\"` : 'a nearest match!'}`,\n )\n\n if (match === undefined) {\n return undefined\n }\n\n return opts.select ? opts.select(match as any) : match\n },\n })\n\n return matchSelection as TSelected\n}\n"],"names":["React","matchContext","useRouterState"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAqBO,SAAS,SAQd,MAOyD;AACnD,QAAA,iBAAiBA,iBAAM,WAAWC,aAAY,YAAA;AAEpD,QAAM,iBAAiBC,eAAAA,eAAe;AAAA,IACpC,QAAQ,CAAC,UAAU;AACX,YAAA,QAAQ,MAAM,QAAQ;AAAA,QAAK,CAAC,MAChC,KAAK,OAAO,KAAK,SAAS,EAAE,UAAU,EAAE,OAAO;AAAA,MAAA;AAEjD;AAAA,QACE,GAAG,KAAK,eAAe,SAAS,CAAC;AAAA,QACjC,kBAAkB,KAAK,OAAO,yBAAyB,KAAK,IAAI,MAAM,kBAAkB;AAAA,MAAA;AAG1F,UAAI,UAAU,QAAW;AAChB,eAAA;AAAA,MACT;AAEA,aAAO,KAAK,SAAS,KAAK,OAAO,KAAY,IAAI;AAAA,IACnD;AAAA,EAAA,CACD;AAEM,SAAA;AACT;;"}
|
package/dist/cjs/useMatch.d.cts
CHANGED
|
@@ -2,9 +2,9 @@ import { RegisteredRouter } from './router.cjs';
|
|
|
2
2
|
import { AnyRoute } from './route.cjs';
|
|
3
3
|
import { MakeRouteMatch } from './Matches.cjs';
|
|
4
4
|
import { RouteIds } from './routeInfo.cjs';
|
|
5
|
-
import { StrictOrFrom } from './utils.cjs';
|
|
5
|
+
import { Constrain, StrictOrFrom } from './utils.cjs';
|
|
6
6
|
export type UseMatchOptions<TFrom, TStrict extends boolean, TRouteMatch, TSelected, TThrow extends boolean> = StrictOrFrom<TFrom, TStrict> & {
|
|
7
7
|
select?: (match: TRouteMatch) => TSelected;
|
|
8
8
|
shouldThrow?: TThrow;
|
|
9
9
|
};
|
|
10
|
-
export declare function useMatch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends
|
|
10
|
+
export declare function useMatch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends string | undefined = undefined, TStrict extends boolean = true, TRouteMatch = MakeRouteMatch<TRouteTree, TFrom, TStrict>, TSelected = TRouteMatch, TThrow extends boolean = true>(opts: UseMatchOptions<Constrain<TFrom, RouteIds<TRouteTree>>, TStrict, TRouteMatch, TSelected, TThrow>): TThrow extends true ? TSelected : TSelected | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNavigate.cjs","sources":["../../src/useNavigate.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useRouter } from './useRouter'\nimport type { FromPathOption, NavigateOptions } from './link'\nimport type { RoutePaths } from './routeInfo'\nimport type { AnyRouter, RegisteredRouter } from './router'\n\nexport type UseNavigateResult<TDefaultFrom extends string> = <\n
|
|
1
|
+
{"version":3,"file":"useNavigate.cjs","sources":["../../src/useNavigate.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useRouter } from './useRouter'\nimport type { FromPathOption, NavigateOptions } from './link'\nimport type { RoutePaths } from './routeInfo'\nimport type { AnyRouter, RegisteredRouter } from './router'\n\nexport type UseNavigateResult<TDefaultFrom extends string> = <\n TRouter extends RegisteredRouter,\n TTo extends string | undefined,\n TFrom extends string = TDefaultFrom,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '',\n>({\n from,\n ...rest\n}: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<void>\n\nexport function useNavigate<\n TRouter extends AnyRouter = RegisteredRouter,\n TDefaultFrom extends string = string,\n>(_defaultOpts?: {\n from?: FromPathOption<TRouter, TDefaultFrom>\n}): UseNavigateResult<TDefaultFrom> {\n const { navigate } = useRouter()\n\n return React.useCallback(\n (options: NavigateOptions) => {\n return navigate({\n ...options,\n })\n },\n [navigate],\n ) as UseNavigateResult<TDefaultFrom>\n}\n\n// NOTE: I don't know of anyone using this. It's undocumented, so let's wait until someone needs it\n// export function typedNavigate<\n// TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n// TDefaultFrom extends RoutePaths<TRouteTree> = '/',\n// >(navigate: (opts: NavigateOptions<any>) => Promise<void>) {\n// return navigate as <\n// TFrom extends RoutePaths<TRouteTree> = TDefaultFrom,\n// TTo extends string = '',\n// TMaskFrom extends RoutePaths<TRouteTree> = '/',\n// TMaskTo extends string = '',\n// >(\n// opts?: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n// ) => Promise<void>\n// } //\n\nexport function Navigate<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '',\n>(props: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): null {\n const { navigate } = useRouter()\n\n React.useEffect(() => {\n navigate({\n ...props,\n } as any)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n return null\n}\n"],"names":["useRouter","React"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAiBO,SAAS,YAGd,cAEkC;AAC5B,QAAA,EAAE,aAAaA,UAAAA;AAErB,SAAOC,iBAAM;AAAA,IACX,CAAC,YAA6B;AAC5B,aAAO,SAAS;AAAA,QACd,GAAG;AAAA,MAAA,CACJ;AAAA,IACH;AAAA,IACA,CAAC,QAAQ;AAAA,EAAA;AAEb;AAiBO,SAAS,SAMd,OAAuE;AACjE,QAAA,EAAE,aAAaD,UAAAA;AAErBC,mBAAM,UAAU,MAAM;AACX,aAAA;AAAA,MACP,GAAG;AAAA,IAAA,CACG;AAAA,EAEV,GAAG,CAAE,CAAA;AAEE,SAAA;AACT;;;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { FromPathOption, NavigateOptions } from './link.cjs';
|
|
2
2
|
import { RoutePaths } from './routeInfo.cjs';
|
|
3
3
|
import { AnyRouter, RegisteredRouter } from './router.cjs';
|
|
4
|
-
export type UseNavigateResult<TDefaultFrom extends string> = <
|
|
4
|
+
export type UseNavigateResult<TDefaultFrom extends string> = <TRouter extends RegisteredRouter, TTo extends string | undefined, TFrom extends string = TDefaultFrom, TMaskFrom extends string = TFrom, TMaskTo extends string = ''>({ from, ...rest }: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<void>;
|
|
5
5
|
export declare function useNavigate<TRouter extends AnyRouter = RegisteredRouter, TDefaultFrom extends string = string>(_defaultOpts?: {
|
|
6
6
|
from?: FromPathOption<TRouter, TDefaultFrom>;
|
|
7
7
|
}): UseNavigateResult<TDefaultFrom>;
|
|
8
|
-
export declare function Navigate<TRouter extends AnyRouter = RegisteredRouter, TFrom extends RoutePaths<TRouter['routeTree']> | string = string, TTo extends string =
|
|
8
|
+
export declare function Navigate<TRouter extends AnyRouter = RegisteredRouter, TFrom extends RoutePaths<TRouter['routeTree']> | string = string, TTo extends string | undefined = undefined, TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom, TMaskTo extends string = ''>(props: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useParams.cjs","sources":["../../src/useParams.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { AnyRoute } from './route'\nimport type { AllParams, RouteById, RouteIds } from './routeInfo'\nimport type { RegisteredRouter } from './router'\nimport type { StrictOrFrom } from './utils'\n\nexport type UseParamsOptions<\n TFrom,\n TStrict extends boolean,\n TParams,\n TSelected,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (params: TParams) => TSelected\n}\n\nexport function useParams<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends
|
|
1
|
+
{"version":3,"file":"useParams.cjs","sources":["../../src/useParams.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { AnyRoute } from './route'\nimport type { AllParams, RouteById, RouteIds } from './routeInfo'\nimport type { RegisteredRouter } from './router'\nimport type { Constrain, StrictOrFrom } from './utils'\n\nexport type UseParamsOptions<\n TFrom,\n TStrict extends boolean,\n TParams,\n TSelected,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (params: TParams) => TSelected\n}\n\nexport function useParams<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends string | undefined = undefined,\n TStrict extends boolean = true,\n TParams = TStrict extends false\n ? AllParams<TRouteTree>\n : RouteById<TRouteTree, TFrom>['types']['allParams'],\n TSelected = TParams,\n>(\n opts: UseParamsOptions<\n Constrain<TFrom, RouteIds<TRouteTree>>,\n TStrict,\n TParams,\n TSelected\n >,\n): TSelected {\n return useMatch({\n ...opts,\n select: (match) => {\n return opts.select ? opts.select(match.params as TParams) : match.params\n },\n }) as TSelected\n}\n"],"names":["useMatch"],"mappings":";;;AAeO,SAAS,UASd,MAMW;AACX,SAAOA,kBAAS;AAAA,IACd,GAAG;AAAA,IACH,QAAQ,CAAC,UAAU;AACjB,aAAO,KAAK,SAAS,KAAK,OAAO,MAAM,MAAiB,IAAI,MAAM;AAAA,IACpE;AAAA,EAAA,CACD;AACH;;"}
|
package/dist/cjs/useParams.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AnyRoute } from './route.cjs';
|
|
2
2
|
import { AllParams, RouteById, RouteIds } from './routeInfo.cjs';
|
|
3
3
|
import { RegisteredRouter } from './router.cjs';
|
|
4
|
-
import { StrictOrFrom } from './utils.cjs';
|
|
4
|
+
import { Constrain, StrictOrFrom } from './utils.cjs';
|
|
5
5
|
export type UseParamsOptions<TFrom, TStrict extends boolean, TParams, TSelected> = StrictOrFrom<TFrom, TStrict> & {
|
|
6
6
|
select?: (params: TParams) => TSelected;
|
|
7
7
|
};
|
|
8
|
-
export declare function useParams<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends
|
|
8
|
+
export declare function useParams<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends string | undefined = undefined, TStrict extends boolean = true, TParams = TStrict extends false ? AllParams<TRouteTree> : RouteById<TRouteTree, TFrom>['types']['allParams'], TSelected = TParams>(opts: UseParamsOptions<Constrain<TFrom, RouteIds<TRouteTree>>, TStrict, TParams, TSelected>): TSelected;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouteContext.cjs","sources":["../../src/useRouteContext.ts"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { MakeRouteMatch } from './Matches'\nimport type { AnyRoute } from './route'\nimport type { AllContext, RouteById, RouteIds } from './routeInfo'\nimport type { RegisteredRouter } from './router'\nimport type { Expand, StrictOrFrom } from './utils'\n\nexport type UseRouteContextOptions<\n TFrom,\n TStrict extends boolean,\n TRouteContext,\n TSelected,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (search: TRouteContext) => TSelected\n}\n\nexport function useRouteContext<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends
|
|
1
|
+
{"version":3,"file":"useRouteContext.cjs","sources":["../../src/useRouteContext.ts"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { MakeRouteMatch } from './Matches'\nimport type { AnyRoute } from './route'\nimport type { AllContext, RouteById, RouteIds } from './routeInfo'\nimport type { RegisteredRouter } from './router'\nimport type { Constrain, Expand, StrictOrFrom } from './utils'\n\nexport type UseRouteContextOptions<\n TFrom,\n TStrict extends boolean,\n TRouteContext,\n TSelected,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (search: TRouteContext) => TSelected\n}\n\nexport function useRouteContext<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends string | undefined = undefined,\n TStrict extends boolean = true,\n TRouteContext = TStrict extends false\n ? AllContext<TRouteTree>\n : Expand<RouteById<TRouteTree, TFrom>['types']['allContext']>,\n TSelected = TRouteContext,\n>(\n opts: UseRouteContextOptions<\n Constrain<TFrom, RouteIds<TRouteTree>>,\n TStrict,\n TRouteContext,\n TSelected\n >,\n): TSelected {\n return useMatch({\n ...(opts as any),\n select: (match: MakeRouteMatch<TRouteTree, TFrom>) =>\n opts.select ? opts.select(match.context) : match.context,\n })\n}\n"],"names":["useMatch"],"mappings":";;;AAgBO,SAAS,gBASd,MAMW;AACX,SAAOA,kBAAS;AAAA,IACd,GAAI;AAAA,IACJ,QAAQ,CAAC,UACP,KAAK,SAAS,KAAK,OAAO,MAAM,OAAO,IAAI,MAAM;AAAA,EAAA,CACpD;AACH;;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AnyRoute } from './route.cjs';
|
|
2
2
|
import { AllContext, RouteById, RouteIds } from './routeInfo.cjs';
|
|
3
3
|
import { RegisteredRouter } from './router.cjs';
|
|
4
|
-
import { Expand, StrictOrFrom } from './utils.cjs';
|
|
4
|
+
import { Constrain, Expand, StrictOrFrom } from './utils.cjs';
|
|
5
5
|
export type UseRouteContextOptions<TFrom, TStrict extends boolean, TRouteContext, TSelected> = StrictOrFrom<TFrom, TStrict> & {
|
|
6
6
|
select?: (search: TRouteContext) => TSelected;
|
|
7
7
|
};
|
|
8
|
-
export declare function useRouteContext<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends
|
|
8
|
+
export declare function useRouteContext<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends string | undefined = undefined, TStrict extends boolean = true, TRouteContext = TStrict extends false ? AllContext<TRouteTree> : Expand<RouteById<TRouteTree, TFrom>['types']['allContext']>, TSelected = TRouteContext>(opts: UseRouteContextOptions<Constrain<TFrom, RouteIds<TRouteTree>>, TStrict, TRouteContext, TSelected>): TSelected;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSearch.cjs","sources":["../../src/useSearch.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { AnyRoute } from './route'\nimport type { FullSearchSchema, RouteById, RouteIds } from './routeInfo'\nimport type { RegisteredRouter } from './router'\nimport type { MakeRouteMatch } from './Matches'\nimport type { Expand, StrictOrFrom } from './utils'\n\nexport type UseSearchOptions<\n TFrom,\n TStrict extends boolean,\n TSearch,\n TSelected,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (search: TSearch) => TSelected\n}\n\nexport function useSearch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends
|
|
1
|
+
{"version":3,"file":"useSearch.cjs","sources":["../../src/useSearch.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { AnyRoute } from './route'\nimport type { FullSearchSchema, RouteById, RouteIds } from './routeInfo'\nimport type { RegisteredRouter } from './router'\nimport type { MakeRouteMatch } from './Matches'\nimport type { Constrain, Expand, StrictOrFrom } from './utils'\n\nexport type UseSearchOptions<\n TFrom,\n TStrict extends boolean,\n TSearch,\n TSelected,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (search: TSearch) => TSelected\n}\n\nexport function useSearch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends string | undefined = undefined,\n TStrict extends boolean = true,\n TSearch = TStrict extends false\n ? FullSearchSchema<TRouteTree>\n : Expand<RouteById<TRouteTree, TFrom>['types']['fullSearchSchema']>,\n TSelected = TSearch,\n>(\n opts: UseSearchOptions<\n Constrain<TFrom, RouteIds<TRouteTree>>,\n TStrict,\n TSearch,\n TSelected\n >,\n): TSelected {\n return useMatch({\n ...opts,\n select: (match) => {\n return opts.select ? opts.select(match.search) : match.search\n },\n })\n}\n"],"names":["useMatch"],"mappings":";;;AAgBO,SAAS,UASd,MAMW;AACX,SAAOA,kBAAS;AAAA,IACd,GAAG;AAAA,IACH,QAAQ,CAAC,UAAU;AACjB,aAAO,KAAK,SAAS,KAAK,OAAO,MAAM,MAAM,IAAI,MAAM;AAAA,IACzD;AAAA,EAAA,CACD;AACH;;"}
|
package/dist/cjs/useSearch.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AnyRoute } from './route.cjs';
|
|
2
2
|
import { FullSearchSchema, RouteById, RouteIds } from './routeInfo.cjs';
|
|
3
3
|
import { RegisteredRouter } from './router.cjs';
|
|
4
|
-
import { Expand, StrictOrFrom } from './utils.cjs';
|
|
4
|
+
import { Constrain, Expand, StrictOrFrom } from './utils.cjs';
|
|
5
5
|
export type UseSearchOptions<TFrom, TStrict extends boolean, TSearch, TSelected> = StrictOrFrom<TFrom, TStrict> & {
|
|
6
6
|
select?: (search: TSearch) => TSelected;
|
|
7
7
|
};
|
|
8
|
-
export declare function useSearch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends
|
|
8
|
+
export declare function useSearch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends string | undefined = undefined, TStrict extends boolean = true, TSearch = TStrict extends false ? FullSearchSchema<TRouteTree> : Expand<RouteById<TRouteTree, TFrom>['types']['fullSearchSchema']>, TSelected = TSearch>(opts: UseSearchOptions<Constrain<TFrom, RouteIds<TRouteTree>>, TStrict, TSearch, TSelected>): TSelected;
|
package/dist/esm/Matches.d.ts
CHANGED
|
@@ -68,7 +68,7 @@ export interface RouteMatch<TRouteId, TFullPath, TAllParams, TFullSearchSchema,
|
|
|
68
68
|
minPendingPromise?: ControlledPromise<void>;
|
|
69
69
|
pendingTimeout?: ReturnType<typeof setTimeout>;
|
|
70
70
|
}
|
|
71
|
-
export type MakeRouteMatch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TRouteId =
|
|
71
|
+
export type MakeRouteMatch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TRouteId = RouteIds<TRouteTree>, TStrict extends boolean = true> = RouteMatch<TRouteId, RouteById<TRouteTree, TRouteId>['types']['fullPath'], TStrict extends false ? AllParams<TRouteTree> : RouteById<TRouteTree, TRouteId>['types']['allParams'], TStrict extends false ? FullSearchSchema<TRouteTree> : RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema'], TStrict extends false ? AllLoaderData<TRouteTree> : RouteById<TRouteTree, TRouteId>['types']['loaderData'], TStrict extends false ? AllContext<TRouteTree> : RouteById<TRouteTree, TRouteId>['types']['allContext'], RouteById<TRouteTree, TRouteId>['types']['loaderDeps']>;
|
|
72
72
|
export type AnyRouteMatch = RouteMatch<any, any, any, any, any, any, any>;
|
|
73
73
|
export declare function Matches(): import("react/jsx-runtime").JSX.Element;
|
|
74
74
|
export interface MatchRouteOptions {
|
|
@@ -77,7 +77,7 @@ export interface MatchRouteOptions {
|
|
|
77
77
|
includeSearch?: boolean;
|
|
78
78
|
fuzzy?: boolean;
|
|
79
79
|
}
|
|
80
|
-
export type UseMatchRouteOptions<TRouter extends AnyRouter = RegisteredRouter, TFrom extends RoutePaths<TRouter['routeTree']> = RoutePaths<TRouter['routeTree']>, TTo extends string = '', TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom, TMaskTo extends string = '', TOptions extends ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> = ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>, TRelaxedOptions = Omit<TOptions, 'search' | 'params'> & DeepPartial<Pick<TOptions, 'search' | 'params'>>> = TRelaxedOptions & MatchRouteOptions;
|
|
80
|
+
export type UseMatchRouteOptions<TRouter extends AnyRouter = RegisteredRouter, TFrom extends RoutePaths<TRouter['routeTree']> | string = RoutePaths<TRouter['routeTree']>, TTo extends string = '', TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom, TMaskTo extends string = '', TOptions extends ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> = ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>, TRelaxedOptions = Omit<TOptions, 'search' | 'params'> & DeepPartial<Pick<TOptions, 'search' | 'params'>>> = TRelaxedOptions & MatchRouteOptions;
|
|
81
81
|
export declare function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>(): <TFrom extends RoutePaths<TRouter["routeTree"]> | string = string, TTo extends string = "", TMaskFrom extends RoutePaths<TRouter["routeTree"]> | string = TFrom, TMaskTo extends string = "", TResolved extends string = ResolveRelativePath<TFrom, NoInfer<TTo>>>(opts: UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>) => false | RouteByPath<TRouter["routeTree"], TResolved>["types"]["allParams"];
|
|
82
82
|
export type MakeMatchRouteOptions<TRouter extends AnyRouter = RegisteredRouter, TFrom extends RoutePaths<TRouter['routeTree']> = RoutePaths<TRouter['routeTree']>, TTo extends string = '', TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom, TMaskTo extends string = ''> = UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
|
83
83
|
children?: ((params?: RouteByPath<TRouter['routeTree'], ResolveRelativePath<TFrom, NoInfer<TTo>>>['types']['allParams']) => ReactNode) | React.ReactNode;
|
package/dist/esm/Matches.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Matches.js","sources":["../../src/Matches.tsx"],"sourcesContent":["import * as React from 'react'\nimport warning from 'tiny-warning'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouterState } from './useRouterState'\nimport { useRouter } from './useRouter'\nimport { Transitioner } from './Transitioner'\nimport { matchContext } from './matchContext'\nimport { Match } from './Match'\nimport { SafeFragment } from './SafeFragment'\nimport type { AnyRoute, ReactNode, StaticDataRouteOption } from './route'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type { ResolveRelativePath, ToOptions } from './link'\nimport type {\n AllContext,\n AllLoaderData,\n AllParams,\n FullSearchSchema,\n ParseRoute,\n RouteById,\n RouteByPath,\n RouteIds,\n RoutePaths,\n} from './routeInfo'\nimport type {\n Constrain,\n ControlledPromise,\n DeepPartial,\n NoInfer,\n} from './utils'\n\nexport type AnyMatchAndValue = { match: any; value: any }\n\nexport type FindValueByIndex<\n TKey,\n TValue extends ReadonlyArray<any>,\n> = TKey extends `${infer TIndex extends number}` ? TValue[TIndex] : never\n\nexport type FindValueByKey<TKey, TValue> =\n TValue extends ReadonlyArray<any>\n ? FindValueByIndex<TKey, TValue>\n : TValue[TKey & keyof TValue]\n\nexport type CreateMatchAndValue<TMatch, TValue> = TValue extends any\n ? {\n match: TMatch\n value: TValue\n }\n : never\n\nexport type NextMatchAndValue<\n TKey,\n TMatchAndValue extends AnyMatchAndValue,\n> = TMatchAndValue extends any\n ? CreateMatchAndValue<\n TMatchAndValue['match'],\n FindValueByKey<TKey, TMatchAndValue['value']>\n >\n : never\n\nexport type IsMatchKeyOf<TValue> =\n TValue extends ReadonlyArray<any>\n ? number extends TValue['length']\n ? `${number}`\n : keyof TValue & `${number}`\n : TValue extends object\n ? keyof TValue & string\n : never\n\nexport type IsMatchPath<\n TParentPath extends string,\n TMatchAndValue extends AnyMatchAndValue,\n> = `${TParentPath}${IsMatchKeyOf<TMatchAndValue['value']>}`\n\nexport type IsMatchResult<\n TKey,\n TMatchAndValue extends AnyMatchAndValue,\n> = TMatchAndValue extends any\n ? TKey extends keyof TMatchAndValue['value']\n ? TMatchAndValue['match']\n : never\n : never\n\nexport type IsMatchParse<\n TPath,\n TMatchAndValue extends AnyMatchAndValue,\n TParentPath extends string = '',\n> = TPath extends `${string}.${string}`\n ? TPath extends `${infer TFirst}.${infer TRest}`\n ? IsMatchParse<\n TRest,\n NextMatchAndValue<TFirst, TMatchAndValue>,\n `${TParentPath}${TFirst}.`\n >\n : never\n : {\n path: IsMatchPath<TParentPath, TMatchAndValue>\n result: IsMatchResult<TPath, TMatchAndValue>\n }\n\nexport type IsMatch<TMatch, TPath> = IsMatchParse<\n TPath,\n TMatch extends any ? { match: TMatch; value: TMatch } : never\n>\n\n/**\n * Narrows matches based on a path\n * @experimental\n */\nexport const isMatch = <TMatch, TPath extends string>(\n match: TMatch,\n path: Constrain<TPath, IsMatch<TMatch, TPath>['path']>,\n): match is IsMatch<TMatch, TPath>['result'] => {\n const parts = (path as string).split('.')\n let part\n let value: any = match\n\n while ((part = parts.shift()) != null && value != null) {\n value = value[part]\n }\n\n return value != null\n}\n\nexport interface RouteMatch<\n TRouteId,\n TFullPath,\n TAllParams,\n TFullSearchSchema,\n TLoaderData,\n TAllContext,\n TLoaderDeps,\n> {\n id: string\n routeId: TRouteId\n fullPath: TFullPath\n index: number\n pathname: string\n params: TAllParams\n status: 'pending' | 'success' | 'error' | 'redirected' | 'notFound'\n isFetching: false | 'beforeLoad' | 'loader'\n error: unknown\n paramsError: unknown\n searchError: unknown\n updatedAt: number\n componentsPromise?: Promise<Array<void>>\n loadPromise?: ControlledPromise<void>\n beforeLoadPromise?: ControlledPromise<void>\n loaderPromise?: ControlledPromise<void>\n loaderData?: TLoaderData\n __routeContext: Record<string, unknown>\n __beforeLoadContext: Record<string, unknown>\n context: TAllContext\n search: TFullSearchSchema\n fetchCount: number\n abortController: AbortController\n cause: 'preload' | 'enter' | 'stay'\n loaderDeps: TLoaderDeps\n preload: boolean\n invalid: boolean\n meta?: Array<React.JSX.IntrinsicElements['meta']>\n links?: Array<React.JSX.IntrinsicElements['link']>\n scripts?: Array<React.JSX.IntrinsicElements['script']>\n headers?: Record<string, string>\n globalNotFound?: boolean\n staticData: StaticDataRouteOption\n minPendingPromise?: ControlledPromise<void>\n pendingTimeout?: ReturnType<typeof setTimeout>\n}\n\nexport type MakeRouteMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId = ParseRoute<TRouteTree>['id'],\n TStrict extends boolean = true,\n TTypes extends AnyRoute['types'] = RouteById<TRouteTree, TRouteId>['types'],\n TFullPath = TTypes['fullPath'],\n TAllParams = TStrict extends false\n ? AllParams<TRouteTree>\n : TTypes['allParams'],\n TFullSearchSchema = TStrict extends false\n ? FullSearchSchema<TRouteTree>\n : TTypes['fullSearchSchema'],\n TLoaderData = TStrict extends false\n ? AllLoaderData<TRouteTree>\n : TTypes['loaderData'],\n TAllContext = TStrict extends false\n ? AllContext<TRouteTree>\n : TTypes['allContext'],\n TLoaderDeps = TTypes['loaderDeps'],\n> = RouteMatch<\n TRouteId,\n TFullPath,\n TAllParams,\n TFullSearchSchema,\n TLoaderData,\n TAllContext,\n TLoaderDeps\n>\n\nexport type AnyRouteMatch = RouteMatch<any, any, any, any, any, any, any>\n\nexport function Matches() {\n const router = useRouter()\n\n const pendingElement = router.options.defaultPendingComponent ? (\n <router.options.defaultPendingComponent />\n ) : null\n\n // Do not render a root Suspense during SSR or hydrating from SSR\n const ResolvedSuspense =\n router.isServer || (typeof document !== 'undefined' && window.__TSR__)\n ? SafeFragment\n : React.Suspense\n\n const inner = (\n <ResolvedSuspense fallback={pendingElement}>\n <Transitioner />\n <MatchesInner />\n </ResolvedSuspense>\n )\n\n return router.options.InnerWrap ? (\n <router.options.InnerWrap>{inner}</router.options.InnerWrap>\n ) : (\n inner\n )\n}\n\nfunction MatchesInner() {\n const matchId = useRouterState({\n select: (s) => {\n return s.matches[0]?.id\n },\n })\n\n const resetKey = useRouterState({\n select: (s) => s.loadedAt,\n })\n\n return (\n <matchContext.Provider value={matchId}>\n <CatchBoundary\n getResetKey={() => resetKey}\n errorComponent={ErrorComponent}\n onCatch={(error) => {\n warning(\n false,\n `The following error wasn't caught by any route! At the very least, consider setting an 'errorComponent' in your RootRoute!`,\n )\n warning(false, error.message || error.toString())\n }}\n >\n {matchId ? <Match matchId={matchId} /> : null}\n </CatchBoundary>\n </matchContext.Provider>\n )\n}\n\nexport interface MatchRouteOptions {\n pending?: boolean\n caseSensitive?: boolean\n includeSearch?: boolean\n fuzzy?: boolean\n}\n\nexport type UseMatchRouteOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> = RoutePaths<\n TRouter['routeTree']\n >,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom,\n TMaskTo extends string = '',\n TOptions extends ToOptions<\n TRouter,\n TFrom,\n TTo,\n TMaskFrom,\n TMaskTo\n > = ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n TRelaxedOptions = Omit<TOptions, 'search' | 'params'> &\n DeepPartial<Pick<TOptions, 'search' | 'params'>>,\n> = TRelaxedOptions & MatchRouteOptions\n\nexport function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>() {\n const router = useRouter()\n\n useRouterState({\n select: (s) => [s.location.href, s.resolvedLocation.href, s.status],\n })\n\n return React.useCallback(\n <\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '',\n TResolved extends string = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n >(\n opts: UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n ):\n | false\n | RouteByPath<TRouter['routeTree'], TResolved>['types']['allParams'] => {\n const { pending, caseSensitive, fuzzy, includeSearch, ...rest } = opts\n\n return router.matchRoute(rest as any, {\n pending,\n caseSensitive,\n fuzzy,\n includeSearch,\n })\n },\n [router],\n )\n}\n\nexport type MakeMatchRouteOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> = RoutePaths<\n TRouter['routeTree']\n >,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom,\n TMaskTo extends string = '',\n> = UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {\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 TRouter['routeTree'],\n ResolveRelativePath<TFrom, NoInfer<TTo>>\n >['types']['allParams'],\n ) => ReactNode)\n | React.ReactNode\n}\n\nexport function MatchRoute<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> = RoutePaths<\n TRouter['routeTree']\n >,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom,\n TMaskTo extends string = '',\n>(props: MakeMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): 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\nexport type MakeRouteMatchUnion<\n TRouter extends AnyRouter = RegisteredRouter,\n TRoute extends AnyRoute = ParseRoute<TRouter['routeTree']>,\n> = TRoute extends any\n ? RouteMatch<\n TRoute['id'],\n TRoute['fullPath'],\n TRoute['types']['allParams'],\n TRoute['types']['fullSearchSchema'],\n TRoute['types']['loaderData'],\n TRoute['types']['allContext'],\n TRoute['types']['loaderDeps']\n >\n : never\n\nexport function useMatches<\n TRouter extends AnyRouter = RegisteredRouter,\n TRouteMatch = MakeRouteMatchUnion<TRouter>,\n T = Array<TRouteMatch>,\n>(opts?: { select?: (matches: Array<TRouteMatch>) => T }): T {\n return useRouterState({\n select: (state) => {\n const matches = state.matches\n return opts?.select\n ? opts.select(matches as Array<TRouteMatch>)\n : (matches as T)\n },\n })\n}\n\nexport function useParentMatches<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n TRouteMatch = MakeRouteMatch<TRouteTree, TRouteId>,\n T = Array<TRouteMatch>,\n>(opts?: { select?: (matches: Array<TRouteMatch>) => T }): T {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches) => {\n matches = matches.slice(\n 0,\n matches.findIndex((d) => d.id === contextMatchId),\n )\n return opts?.select\n ? opts.select(matches as Array<TRouteMatch>)\n : (matches as T)\n },\n })\n}\n\nexport function useChildMatches<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n TRouteMatch = MakeRouteMatch<TRouteTree, TRouteId>,\n T = Array<TRouteMatch>,\n>(opts?: { select?: (matches: Array<TRouteMatch>) => T }): T {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches) => {\n matches = matches.slice(\n matches.findIndex((d) => d.id === contextMatchId) + 1,\n )\n return opts?.select\n ? opts.select(matches as Array<TRouteMatch>)\n : (matches as T)\n },\n })\n}\n"],"names":[],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"Matches.js","sources":["../../src/Matches.tsx"],"sourcesContent":["import * as React from 'react'\nimport warning from 'tiny-warning'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouterState } from './useRouterState'\nimport { useRouter } from './useRouter'\nimport { Transitioner } from './Transitioner'\nimport { matchContext } from './matchContext'\nimport { Match } from './Match'\nimport { SafeFragment } from './SafeFragment'\nimport type { AnyRoute, ReactNode, StaticDataRouteOption } from './route'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type { ResolveRelativePath, ToOptions } from './link'\nimport type {\n AllContext,\n AllLoaderData,\n AllParams,\n FullSearchSchema,\n ParseRoute,\n RouteById,\n RouteByPath,\n RouteIds,\n RoutePaths,\n} from './routeInfo'\nimport type {\n Constrain,\n ControlledPromise,\n DeepPartial,\n NoInfer,\n} from './utils'\n\nexport type AnyMatchAndValue = { match: any; value: any }\n\nexport type FindValueByIndex<\n TKey,\n TValue extends ReadonlyArray<any>,\n> = TKey extends `${infer TIndex extends number}` ? TValue[TIndex] : never\n\nexport type FindValueByKey<TKey, TValue> =\n TValue extends ReadonlyArray<any>\n ? FindValueByIndex<TKey, TValue>\n : TValue[TKey & keyof TValue]\n\nexport type CreateMatchAndValue<TMatch, TValue> = TValue extends any\n ? {\n match: TMatch\n value: TValue\n }\n : never\n\nexport type NextMatchAndValue<\n TKey,\n TMatchAndValue extends AnyMatchAndValue,\n> = TMatchAndValue extends any\n ? CreateMatchAndValue<\n TMatchAndValue['match'],\n FindValueByKey<TKey, TMatchAndValue['value']>\n >\n : never\n\nexport type IsMatchKeyOf<TValue> =\n TValue extends ReadonlyArray<any>\n ? number extends TValue['length']\n ? `${number}`\n : keyof TValue & `${number}`\n : TValue extends object\n ? keyof TValue & string\n : never\n\nexport type IsMatchPath<\n TParentPath extends string,\n TMatchAndValue extends AnyMatchAndValue,\n> = `${TParentPath}${IsMatchKeyOf<TMatchAndValue['value']>}`\n\nexport type IsMatchResult<\n TKey,\n TMatchAndValue extends AnyMatchAndValue,\n> = TMatchAndValue extends any\n ? TKey extends keyof TMatchAndValue['value']\n ? TMatchAndValue['match']\n : never\n : never\n\nexport type IsMatchParse<\n TPath,\n TMatchAndValue extends AnyMatchAndValue,\n TParentPath extends string = '',\n> = TPath extends `${string}.${string}`\n ? TPath extends `${infer TFirst}.${infer TRest}`\n ? IsMatchParse<\n TRest,\n NextMatchAndValue<TFirst, TMatchAndValue>,\n `${TParentPath}${TFirst}.`\n >\n : never\n : {\n path: IsMatchPath<TParentPath, TMatchAndValue>\n result: IsMatchResult<TPath, TMatchAndValue>\n }\n\nexport type IsMatch<TMatch, TPath> = IsMatchParse<\n TPath,\n TMatch extends any ? { match: TMatch; value: TMatch } : never\n>\n\n/**\n * Narrows matches based on a path\n * @experimental\n */\nexport const isMatch = <TMatch, TPath extends string>(\n match: TMatch,\n path: Constrain<TPath, IsMatch<TMatch, TPath>['path']>,\n): match is IsMatch<TMatch, TPath>['result'] => {\n const parts = (path as string).split('.')\n let part\n let value: any = match\n\n while ((part = parts.shift()) != null && value != null) {\n value = value[part]\n }\n\n return value != null\n}\n\nexport interface RouteMatch<\n TRouteId,\n TFullPath,\n TAllParams,\n TFullSearchSchema,\n TLoaderData,\n TAllContext,\n TLoaderDeps,\n> {\n id: string\n routeId: TRouteId\n fullPath: TFullPath\n index: number\n pathname: string\n params: TAllParams\n status: 'pending' | 'success' | 'error' | 'redirected' | 'notFound'\n isFetching: false | 'beforeLoad' | 'loader'\n error: unknown\n paramsError: unknown\n searchError: unknown\n updatedAt: number\n componentsPromise?: Promise<Array<void>>\n loadPromise?: ControlledPromise<void>\n beforeLoadPromise?: ControlledPromise<void>\n loaderPromise?: ControlledPromise<void>\n loaderData?: TLoaderData\n __routeContext: Record<string, unknown>\n __beforeLoadContext: Record<string, unknown>\n context: TAllContext\n search: TFullSearchSchema\n fetchCount: number\n abortController: AbortController\n cause: 'preload' | 'enter' | 'stay'\n loaderDeps: TLoaderDeps\n preload: boolean\n invalid: boolean\n meta?: Array<React.JSX.IntrinsicElements['meta']>\n links?: Array<React.JSX.IntrinsicElements['link']>\n scripts?: Array<React.JSX.IntrinsicElements['script']>\n headers?: Record<string, string>\n globalNotFound?: boolean\n staticData: StaticDataRouteOption\n minPendingPromise?: ControlledPromise<void>\n pendingTimeout?: ReturnType<typeof setTimeout>\n}\n\nexport type MakeRouteMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n> = RouteMatch<\n TRouteId,\n RouteById<TRouteTree, TRouteId>['types']['fullPath'],\n TStrict extends false\n ? AllParams<TRouteTree>\n : RouteById<TRouteTree, TRouteId>['types']['allParams'],\n TStrict extends false\n ? FullSearchSchema<TRouteTree>\n : RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema'],\n TStrict extends false\n ? AllLoaderData<TRouteTree>\n : RouteById<TRouteTree, TRouteId>['types']['loaderData'],\n TStrict extends false\n ? AllContext<TRouteTree>\n : RouteById<TRouteTree, TRouteId>['types']['allContext'],\n RouteById<TRouteTree, TRouteId>['types']['loaderDeps']\n>\n\nexport type AnyRouteMatch = RouteMatch<any, any, any, any, any, any, any>\n\nexport function Matches() {\n const router = useRouter()\n\n const pendingElement = router.options.defaultPendingComponent ? (\n <router.options.defaultPendingComponent />\n ) : null\n\n // Do not render a root Suspense during SSR or hydrating from SSR\n const ResolvedSuspense =\n router.isServer || (typeof document !== 'undefined' && window.__TSR__)\n ? SafeFragment\n : React.Suspense\n\n const inner = (\n <ResolvedSuspense fallback={pendingElement}>\n <Transitioner />\n <MatchesInner />\n </ResolvedSuspense>\n )\n\n return router.options.InnerWrap ? (\n <router.options.InnerWrap>{inner}</router.options.InnerWrap>\n ) : (\n inner\n )\n}\n\nfunction MatchesInner() {\n const matchId = useRouterState({\n select: (s) => {\n return s.matches[0]?.id\n },\n })\n\n const resetKey = useRouterState({\n select: (s) => s.loadedAt,\n })\n\n return (\n <matchContext.Provider value={matchId}>\n <CatchBoundary\n getResetKey={() => resetKey}\n errorComponent={ErrorComponent}\n onCatch={(error) => {\n warning(\n false,\n `The following error wasn't caught by any route! At the very least, consider setting an 'errorComponent' in your RootRoute!`,\n )\n warning(false, error.message || error.toString())\n }}\n >\n {matchId ? <Match matchId={matchId} /> : null}\n </CatchBoundary>\n </matchContext.Provider>\n )\n}\n\nexport interface MatchRouteOptions {\n pending?: boolean\n caseSensitive?: boolean\n includeSearch?: boolean\n fuzzy?: boolean\n}\n\nexport type UseMatchRouteOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = RoutePaths<\n TRouter['routeTree']\n >,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '',\n TOptions extends ToOptions<\n TRouter,\n TFrom,\n TTo,\n TMaskFrom,\n TMaskTo\n > = ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n TRelaxedOptions = Omit<TOptions, 'search' | 'params'> &\n DeepPartial<Pick<TOptions, 'search' | 'params'>>,\n> = TRelaxedOptions & MatchRouteOptions\n\nexport function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>() {\n const router = useRouter()\n\n useRouterState({\n select: (s) => [s.location.href, s.resolvedLocation.href, s.status],\n })\n\n return React.useCallback(\n <\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '',\n TResolved extends string = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n >(\n opts: UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n ):\n | false\n | RouteByPath<TRouter['routeTree'], TResolved>['types']['allParams'] => {\n const { pending, caseSensitive, fuzzy, includeSearch, ...rest } = opts\n\n return router.matchRoute(rest as any, {\n pending,\n caseSensitive,\n fuzzy,\n includeSearch,\n })\n },\n [router],\n )\n}\n\nexport type MakeMatchRouteOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> = RoutePaths<\n TRouter['routeTree']\n >,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom,\n TMaskTo extends string = '',\n> = UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {\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 TRouter['routeTree'],\n ResolveRelativePath<TFrom, NoInfer<TTo>>\n >['types']['allParams'],\n ) => ReactNode)\n | React.ReactNode\n}\n\nexport function MatchRoute<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> = RoutePaths<\n TRouter['routeTree']\n >,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom,\n TMaskTo extends string = '',\n>(props: MakeMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): 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\nexport type MakeRouteMatchUnion<\n TRouter extends AnyRouter = RegisteredRouter,\n TRoute extends AnyRoute = ParseRoute<TRouter['routeTree']>,\n> = TRoute extends any\n ? RouteMatch<\n TRoute['id'],\n TRoute['fullPath'],\n TRoute['types']['allParams'],\n TRoute['types']['fullSearchSchema'],\n TRoute['types']['loaderData'],\n TRoute['types']['allContext'],\n TRoute['types']['loaderDeps']\n >\n : never\n\nexport function useMatches<\n TRouter extends AnyRouter = RegisteredRouter,\n TRouteMatch = MakeRouteMatchUnion<TRouter>,\n T = Array<TRouteMatch>,\n>(opts?: { select?: (matches: Array<TRouteMatch>) => T }): T {\n return useRouterState({\n select: (state) => {\n const matches = state.matches\n return opts?.select\n ? opts.select(matches as Array<TRouteMatch>)\n : (matches as T)\n },\n })\n}\n\nexport function useParentMatches<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n TRouteMatch = MakeRouteMatch<TRouteTree, TRouteId>,\n T = Array<TRouteMatch>,\n>(opts?: { select?: (matches: Array<TRouteMatch>) => T }): T {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches) => {\n matches = matches.slice(\n 0,\n matches.findIndex((d) => d.id === contextMatchId),\n )\n return opts?.select\n ? opts.select(matches as Array<TRouteMatch>)\n : (matches as T)\n },\n })\n}\n\nexport function useChildMatches<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n TRouteMatch = MakeRouteMatch<TRouteTree, TRouteId>,\n T = Array<TRouteMatch>,\n>(opts?: { select?: (matches: Array<TRouteMatch>) => T }): T {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches) => {\n matches = matches.slice(\n matches.findIndex((d) => d.id === contextMatchId) + 1,\n )\n return opts?.select\n ? opts.select(matches as Array<TRouteMatch>)\n : (matches as T)\n },\n })\n}\n"],"names":[],"mappings":"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"}
|
|
@@ -19,10 +19,10 @@ export interface MatchLocation {
|
|
|
19
19
|
caseSensitive?: boolean;
|
|
20
20
|
from?: string;
|
|
21
21
|
}
|
|
22
|
-
export type NavigateFn = <
|
|
22
|
+
export type NavigateFn = <TRouter extends RegisteredRouter, TTo extends string | undefined, TFrom extends RoutePaths<TRouter['routeTree']> | string = string, TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom, TMaskTo extends string = ''>(opts: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
|
23
23
|
__isRedirect?: boolean;
|
|
24
24
|
}) => Promise<void>;
|
|
25
|
-
export type BuildLocationFn = <
|
|
25
|
+
export type BuildLocationFn = <TRouter extends RegisteredRouter, TTo extends string | undefined, TFrom extends RoutePaths<TRouter['routeTree']> | string = string, TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom, TMaskTo extends string = ''>(opts: ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
|
26
26
|
leaveParams?: boolean;
|
|
27
27
|
}) => ParsedLocation;
|
|
28
28
|
export type InjectedHtmlEntry = string | (() => Promise<string> | string);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouterProvider.js","sources":["../../src/RouterProvider.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Matches } from './Matches'\nimport { getRouterContext } from './routerContext'\nimport type { NavigateOptions, ToOptions } from './link'\nimport type { ParsedLocation } from './location'\nimport type { RoutePaths } from './routeInfo'\nimport type {\n AnyRouter,\n RegisteredRouter,\n Router,\n RouterOptions,\n} from './router'\n\nexport interface CommitLocationOptions {\n replace?: boolean\n resetScroll?: boolean\n viewTransition?: boolean\n /**\n * @deprecated All navigations use React transitions under the hood now\n **/\n startTransition?: boolean\n ignoreBlocker?: boolean\n}\n\nexport interface MatchLocation {\n to?: string | number | null\n fuzzy?: boolean\n caseSensitive?: boolean\n from?: string\n}\n\nexport type NavigateFn = <\n
|
|
1
|
+
{"version":3,"file":"RouterProvider.js","sources":["../../src/RouterProvider.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Matches } from './Matches'\nimport { getRouterContext } from './routerContext'\nimport type { NavigateOptions, ToOptions } from './link'\nimport type { ParsedLocation } from './location'\nimport type { RoutePaths } from './routeInfo'\nimport type {\n AnyRouter,\n RegisteredRouter,\n Router,\n RouterOptions,\n} from './router'\n\nexport interface CommitLocationOptions {\n replace?: boolean\n resetScroll?: boolean\n viewTransition?: boolean\n /**\n * @deprecated All navigations use React transitions under the hood now\n **/\n startTransition?: boolean\n ignoreBlocker?: boolean\n}\n\nexport interface MatchLocation {\n to?: string | number | null\n fuzzy?: boolean\n caseSensitive?: boolean\n from?: string\n}\n\nexport type NavigateFn = <\n TRouter extends RegisteredRouter,\n TTo extends string | undefined,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '',\n>(\n opts: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {\n __isRedirect?: boolean\n },\n) => Promise<void>\n\nexport type BuildLocationFn = <\n TRouter extends RegisteredRouter,\n TTo extends string | undefined,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '',\n>(\n opts: ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {\n leaveParams?: boolean\n },\n) => ParsedLocation\n\nexport type InjectedHtmlEntry = string | (() => Promise<string> | string)\n\nexport function RouterContextProvider<\n TRouter extends AnyRouter = RegisteredRouter,\n TDehydrated extends Record<string, any> = Record<string, any>,\n>({\n router,\n children,\n ...rest\n}: RouterProps<TRouter, TDehydrated> & {\n children: React.ReactNode\n}) {\n // Allow the router to update options on the router instance\n router.update({\n ...router.options,\n ...rest,\n context: {\n ...router.options.context,\n ...rest.context,\n },\n } as any)\n\n const routerContext = getRouterContext()\n\n const provider = (\n <routerContext.Provider value={router}>{children}</routerContext.Provider>\n )\n\n if (router.options.Wrap) {\n return <router.options.Wrap>{provider}</router.options.Wrap>\n }\n\n return provider\n}\n\nexport function RouterProvider<\n TRouter extends AnyRouter = RegisteredRouter,\n TDehydrated extends Record<string, any> = Record<string, any>,\n>({ router, ...rest }: RouterProps<TRouter, TDehydrated>) {\n return (\n <RouterContextProvider router={router} {...rest}>\n <Matches />\n </RouterContextProvider>\n )\n}\n\nexport type RouterProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TDehydrated extends Record<string, any> = Record<string, any>,\n> = Omit<\n RouterOptions<\n TRouter['routeTree'],\n NonNullable<TRouter['options']['trailingSlash']>,\n TDehydrated\n >,\n 'context'\n> & {\n router: Router<\n TRouter['routeTree'],\n NonNullable<TRouter['options']['trailingSlash']>\n >\n context?: Partial<\n RouterOptions<\n TRouter['routeTree'],\n NonNullable<TRouter['options']['trailingSlash']>,\n TDehydrated\n >['context']\n >\n}\n"],"names":[],"mappings":";;;AAyDO,SAAS,sBAGd;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAEG;AAED,SAAO,OAAO;AAAA,IACZ,GAAG,OAAO;AAAA,IACV,GAAG;AAAA,IACH,SAAS;AAAA,MACP,GAAG,OAAO,QAAQ;AAAA,MAClB,GAAG,KAAK;AAAA,IACV;AAAA,EAAA,CACM;AAER,QAAM,gBAAgB;AAEtB,QAAM,WACH,oBAAA,cAAc,UAAd,EAAuB,OAAO,QAAS,SAAS,CAAA;AAG/C,MAAA,OAAO,QAAQ,MAAM;AACvB,WAAQ,oBAAA,OAAO,QAAQ,MAAf,EAAqB,UAAS,SAAA,CAAA;AAAA,EACxC;AAEO,SAAA;AACT;AAEO,SAAS,eAGd,EAAE,QAAQ,GAAG,QAA2C;AACxD,6BACG,uBAAsB,EAAA,QAAiB,GAAG,MACzC,UAAA,oBAAC,UAAQ,CAAA,EACX,CAAA;AAEJ;"}
|
package/dist/esm/fileRoute.d.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { Constrain } from './utils.js';
|
|
2
|
-
import { AnyContext, AnyPathParams, AnyRoute, AnySearchValidator, FileBaseRouteOptions, ResolveParams, Route, RouteConstraints, RouteLoaderFn, UpdatableRouteOptions } from './route.js';
|
|
2
|
+
import { AnyContext, AnyPathParams, AnyRoute, AnySearchValidator, FileBaseRouteOptions, ResolveParams, RootRoute, Route, RouteConstraints, RouteLoaderFn, UpdatableRouteOptions } from './route.js';
|
|
3
3
|
import { MakeRouteMatch } from './Matches.js';
|
|
4
4
|
import { RegisteredRouter } from './router.js';
|
|
5
5
|
import { RouteById, RouteIds } from './routeInfo.js';
|
|
6
6
|
export interface FileRoutesByPath {
|
|
7
7
|
}
|
|
8
|
+
export interface FileRouteTypes {
|
|
9
|
+
fileRoutesByFullPath: any;
|
|
10
|
+
fullPaths: any;
|
|
11
|
+
to: any;
|
|
12
|
+
fileRoutesByTo: any;
|
|
13
|
+
id: any;
|
|
14
|
+
fileRoutesById: any;
|
|
15
|
+
}
|
|
16
|
+
export type InferFileRouteTypes<TRouteTree extends AnyRoute> = TRouteTree extends RootRoute<any, any, any, any, any, any, any, infer TFileRouteTypes extends FileRouteTypes> ? TFileRouteTypes : never;
|
|
8
17
|
export declare function createFileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'], TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'], TFullPath extends RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath']>(path: TFilePath): FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>['createRoute'];
|
|
9
18
|
/**
|
|
10
19
|
@deprecated It's no longer recommended to use the `FileRoute` class directly.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileRoute.js","sources":["../../src/fileRoute.ts"],"sourcesContent":["import warning from 'tiny-warning'\nimport { createRoute } from './route'\nimport { useMatch } from './useMatch'\nimport { useLoaderDeps } from './useLoaderDeps'\nimport { useLoaderData } from './useLoaderData'\nimport { useSearch } from './useSearch'\nimport { useParams } from './useParams'\nimport { useNavigate } from './useNavigate'\nimport type { Constrain } from './utils'\nimport type {\n AnyContext,\n AnyPathParams,\n AnyRoute,\n AnySearchValidator,\n FileBaseRouteOptions,\n ResolveParams,\n Route,\n RouteConstraints,\n RouteLoaderFn,\n UpdatableRouteOptions,\n} from './route'\nimport type { MakeRouteMatch } from './Matches'\nimport type { RegisteredRouter } from './router'\nimport type { RouteById, RouteIds } from './routeInfo'\n\nexport interface FileRoutesByPath {\n // '/': {\n // parentRoute: typeof rootRoute\n // }\n}\n\nexport function createFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'],\n TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'],\n TFullPath extends\n RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath'],\n>(\n path: TFilePath,\n): FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>['createRoute'] {\n return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {\n silent: true,\n }).createRoute\n}\n\n/** \n @deprecated It's no longer recommended to use the `FileRoute` class directly.\n Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.\n*/\nexport class FileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'],\n TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'],\n TFullPath extends\n RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath'],\n> {\n silent?: boolean\n\n constructor(\n public path: TFilePath,\n _opts?: { silent: boolean },\n ) {\n this.silent = _opts?.silent\n }\n\n createRoute = <\n TSearchValidator = undefined,\n TParams = ResolveParams<TPath>,\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TChildren = unknown,\n >(\n options?: FileBaseRouteOptions<\n TParentRoute,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn\n > &\n UpdatableRouteOptions<\n TParentRoute,\n TId,\n TFullPath,\n TParams,\n TSearchValidator,\n TLoaderFn,\n TLoaderDeps,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TFilePath,\n TId,\n TSearchValidator,\n TParams,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren\n > => {\n warning(\n this.silent,\n 'FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.',\n )\n const route = createRoute(options as any)\n ;(route as any).isRoot = false\n return route as any\n }\n}\n\n/** \n @deprecated It's recommended not to split loaders into separate files.\n Instead, place the loader function in the the main route file, inside the\n `createFileRoute('/path/to/file)(options)` options.\n*/\nexport function FileRouteLoader<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(\n _path: TFilePath,\n): <TLoaderFn>(\n loaderFn: Constrain<\n TLoaderFn,\n RouteLoaderFn<\n TRoute['parentRoute'],\n TRoute['types']['params'],\n TRoute['types']['loaderDeps'],\n TRoute['types']['routerContext'],\n TRoute['types']['routeContextFn'],\n TRoute['types']['beforeLoadFn']\n >\n >,\n) => TLoaderFn {\n warning(\n false,\n `FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \\`createFileRoute('/path/to/file')(options)\\` options`,\n )\n return (loaderFn) => loaderFn as any\n}\n\nexport type LazyRouteOptions = Pick<\n UpdatableRouteOptions<\n AnyRoute,\n string,\n string,\n AnyPathParams,\n AnySearchValidator,\n {},\n AnyContext,\n AnyContext,\n AnyContext,\n AnyContext\n >,\n 'component' | 'errorComponent' | 'pendingComponent' | 'notFoundComponent'\n>\n\nexport class LazyRoute<TRoute extends AnyRoute> {\n options: {\n id: string\n } & LazyRouteOptions\n\n constructor(\n opts: {\n id: string\n } & LazyRouteOptions,\n ) {\n this.options = opts\n ;(this as any).$$typeof = Symbol.for('react.memo')\n }\n\n useMatch = <\n TRouteMatch = MakeRouteMatch<\n RegisteredRouter['routeTree'],\n TRoute['types']['id']\n >,\n TSelected = TRouteMatch,\n >(opts?: {\n select?: (match: TRouteMatch) => TSelected\n }): TSelected => {\n return useMatch({ select: opts?.select, from: this.options.id })\n }\n\n useRouteContext = <TSelected = TRoute['types']['allContext']>(opts?: {\n select?: (s: TRoute['types']['allContext']) => TSelected\n }): TSelected => {\n return useMatch({\n from: this.options.id,\n select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),\n })\n }\n\n useSearch = <TSelected = TRoute['types']['fullSearchSchema']>(opts?: {\n select?: (s: TRoute['types']['fullSearchSchema']) => TSelected\n }): TSelected => {\n return useSearch({ ...opts, from: this.options.id })\n }\n\n useParams = <TSelected = TRoute['types']['allParams']>(opts?: {\n select?: (s: TRoute['types']['allParams']) => TSelected\n }): TSelected => {\n return useParams({ ...opts, from: this.options.id })\n }\n\n useLoaderDeps = <TSelected = TRoute['types']['loaderDeps']>(opts?: {\n select?: (s: TRoute['types']['loaderDeps']) => TSelected\n }): TSelected => {\n return useLoaderDeps({ ...opts, from: this.options.id } as any)\n }\n\n useLoaderData = <TSelected = TRoute['types']['loaderData']>(opts?: {\n select?: (s: TRoute['types']['loaderData']) => TSelected\n }): TSelected => {\n return useLoaderData({ ...opts, from: this.options.id } as any)\n }\n\n useNavigate = () => {\n return useNavigate({ from: this.options.id })\n }\n}\n\nexport function createLazyRoute<\n TId extends RouteIds<RegisteredRouter['routeTree']>,\n TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,\n>(id: TId) {\n return (opts: LazyRouteOptions) => {\n return new LazyRoute<TRoute>({ id: id as any, ...opts })\n }\n}\n\nconst routeGroupPatternRegex = /\\(.+\\)/g\n\nfunction removeGroups(s: string) {\n return s.replaceAll(routeGroupPatternRegex, '').replaceAll('//', '/')\n}\n\nexport function createLazyFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(id: TFilePath) {\n return (opts: LazyRouteOptions) =>\n new LazyRoute<TRoute>({ id: removeGroups(id), ...opts })\n}\n"],"names":["opts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"fileRoute.js","sources":["../../src/fileRoute.ts"],"sourcesContent":["import warning from 'tiny-warning'\nimport { createRoute } from './route'\nimport { useMatch } from './useMatch'\nimport { useLoaderDeps } from './useLoaderDeps'\nimport { useLoaderData } from './useLoaderData'\nimport { useSearch } from './useSearch'\nimport { useParams } from './useParams'\nimport { useNavigate } from './useNavigate'\nimport type { Constrain } from './utils'\nimport type {\n AnyContext,\n AnyPathParams,\n AnyRoute,\n AnySearchValidator,\n FileBaseRouteOptions,\n ResolveParams,\n RootRoute,\n Route,\n RouteConstraints,\n RouteLoaderFn,\n UpdatableRouteOptions,\n} from './route'\nimport type { MakeRouteMatch } from './Matches'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type { RouteById, RouteIds } from './routeInfo'\n\nexport interface FileRoutesByPath {\n // '/': {\n // parentRoute: typeof rootRoute\n // }\n}\n\nexport interface FileRouteTypes {\n fileRoutesByFullPath: any\n fullPaths: any\n to: any\n fileRoutesByTo: any\n id: any\n fileRoutesById: any\n}\n\nexport type InferFileRouteTypes<TRouteTree extends AnyRoute> =\n TRouteTree extends RootRoute<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n infer TFileRouteTypes extends FileRouteTypes\n >\n ? TFileRouteTypes\n : never\n\nexport function createFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'],\n TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'],\n TFullPath extends\n RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath'],\n>(\n path: TFilePath,\n): FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>['createRoute'] {\n return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {\n silent: true,\n }).createRoute\n}\n\n/** \n @deprecated It's no longer recommended to use the `FileRoute` class directly.\n Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.\n*/\nexport class FileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'],\n TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'],\n TFullPath extends\n RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath'],\n> {\n silent?: boolean\n\n constructor(\n public path: TFilePath,\n _opts?: { silent: boolean },\n ) {\n this.silent = _opts?.silent\n }\n\n createRoute = <\n TSearchValidator = undefined,\n TParams = ResolveParams<TPath>,\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TChildren = unknown,\n >(\n options?: FileBaseRouteOptions<\n TParentRoute,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn\n > &\n UpdatableRouteOptions<\n TParentRoute,\n TId,\n TFullPath,\n TParams,\n TSearchValidator,\n TLoaderFn,\n TLoaderDeps,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TFilePath,\n TId,\n TSearchValidator,\n TParams,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren\n > => {\n warning(\n this.silent,\n 'FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.',\n )\n const route = createRoute(options as any)\n ;(route as any).isRoot = false\n return route as any\n }\n}\n\n/** \n @deprecated It's recommended not to split loaders into separate files.\n Instead, place the loader function in the the main route file, inside the\n `createFileRoute('/path/to/file)(options)` options.\n*/\nexport function FileRouteLoader<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(\n _path: TFilePath,\n): <TLoaderFn>(\n loaderFn: Constrain<\n TLoaderFn,\n RouteLoaderFn<\n TRoute['parentRoute'],\n TRoute['types']['params'],\n TRoute['types']['loaderDeps'],\n TRoute['types']['routerContext'],\n TRoute['types']['routeContextFn'],\n TRoute['types']['beforeLoadFn']\n >\n >,\n) => TLoaderFn {\n warning(\n false,\n `FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \\`createFileRoute('/path/to/file')(options)\\` options`,\n )\n return (loaderFn) => loaderFn as any\n}\n\nexport type LazyRouteOptions = Pick<\n UpdatableRouteOptions<\n AnyRoute,\n string,\n string,\n AnyPathParams,\n AnySearchValidator,\n {},\n AnyContext,\n AnyContext,\n AnyContext,\n AnyContext\n >,\n 'component' | 'errorComponent' | 'pendingComponent' | 'notFoundComponent'\n>\n\nexport class LazyRoute<TRoute extends AnyRoute> {\n options: {\n id: string\n } & LazyRouteOptions\n\n constructor(\n opts: {\n id: string\n } & LazyRouteOptions,\n ) {\n this.options = opts\n ;(this as any).$$typeof = Symbol.for('react.memo')\n }\n\n useMatch = <\n TRouteMatch = MakeRouteMatch<\n RegisteredRouter['routeTree'],\n TRoute['types']['id']\n >,\n TSelected = TRouteMatch,\n >(opts?: {\n select?: (match: TRouteMatch) => TSelected\n }): TSelected => {\n return useMatch({ select: opts?.select, from: this.options.id })\n }\n\n useRouteContext = <TSelected = TRoute['types']['allContext']>(opts?: {\n select?: (s: TRoute['types']['allContext']) => TSelected\n }): TSelected => {\n return useMatch({\n from: this.options.id,\n select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),\n })\n }\n\n useSearch = <TSelected = TRoute['types']['fullSearchSchema']>(opts?: {\n select?: (s: TRoute['types']['fullSearchSchema']) => TSelected\n }): TSelected => {\n return useSearch({ ...opts, from: this.options.id })\n }\n\n useParams = <TSelected = TRoute['types']['allParams']>(opts?: {\n select?: (s: TRoute['types']['allParams']) => TSelected\n }): TSelected => {\n return useParams({ ...opts, from: this.options.id })\n }\n\n useLoaderDeps = <TSelected = TRoute['types']['loaderDeps']>(opts?: {\n select?: (s: TRoute['types']['loaderDeps']) => TSelected\n }): TSelected => {\n return useLoaderDeps({ ...opts, from: this.options.id } as any)\n }\n\n useLoaderData = <TSelected = TRoute['types']['loaderData']>(opts?: {\n select?: (s: TRoute['types']['loaderData']) => TSelected\n }): TSelected => {\n return useLoaderData({ ...opts, from: this.options.id } as any)\n }\n\n useNavigate = () => {\n return useNavigate({ from: this.options.id })\n }\n}\n\nexport function createLazyRoute<\n TId extends RouteIds<RegisteredRouter['routeTree']>,\n TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,\n>(id: TId) {\n return (opts: LazyRouteOptions) => {\n return new LazyRoute<TRoute>({ id: id as any, ...opts })\n }\n}\n\nconst routeGroupPatternRegex = /\\(.+\\)/g\n\nfunction removeGroups(s: string) {\n return s.replaceAll(routeGroupPatternRegex, '').replaceAll('//', '/')\n}\n\nexport function createLazyFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(id: TFilePath) {\n return (opts: LazyRouteOptions) =>\n new LazyRoute<TRoute>({ id: removeGroups(id), ...opts })\n}\n"],"names":["opts"],"mappings":";;;;;;;;AAuDO,SAAS,gBAQd,MAC0E;AACnE,SAAA,IAAI,UAA0D,MAAM;AAAA,IACzE,QAAQ;AAAA,EACT,CAAA,EAAE;AACL;AAMO,MAAM,UAOX;AAAA,EAGA,YACS,MACP,OACA;AAFO,SAAA,OAAA;AAMT,SAAA,cAAc,CASZ,YAqCG;AACH;AAAA,QACE,KAAK;AAAA,QACL;AAAA,MAAA;AAEI,YAAA,QAAQ,YAAY,OAAc;AACtC,YAAc,SAAS;AAClB,aAAA;AAAA,IAAA;AAxDP,SAAK,SAAS,+BAAO;AAAA,EACvB;AAyDF;AAOO,SAAS,gBAId,OAaa;AACb;AAAA,IACE;AAAA,IACA;AAAA,EAAA;AAEF,SAAO,CAAC,aAAa;AACvB;AAkBO,MAAM,UAAmC;AAAA,EAK9C,YACE,MAGA;AAKF,SAAA,WAAW,CAMTA,UAEe;AACR,aAAA,SAAS,EAAE,QAAQA,SAAA,gBAAAA,MAAM,QAAQ,MAAM,KAAK,QAAQ,GAAA,CAAI;AAAA,IAAA;AAGjE,SAAA,kBAAkB,CAA4CA,UAE7C;AACf,aAAO,SAAS;AAAA,QACd,MAAM,KAAK,QAAQ;AAAA,QACnB,QAAQ,CAAC,OAAYA,SAAA,gBAAAA,MAAM,UAASA,MAAK,OAAO,EAAE,OAAO,IAAI,EAAE;AAAA,MAAA,CAChE;AAAA,IAAA;AAGH,SAAA,YAAY,CAAkDA,UAE7C;AACR,aAAA,UAAU,EAAE,GAAGA,OAAM,MAAM,KAAK,QAAQ,IAAI;AAAA,IAAA;AAGrD,SAAA,YAAY,CAA2CA,UAEtC;AACR,aAAA,UAAU,EAAE,GAAGA,OAAM,MAAM,KAAK,QAAQ,IAAI;AAAA,IAAA;AAGrD,SAAA,gBAAgB,CAA4CA,UAE3C;AACR,aAAA,cAAc,EAAE,GAAGA,OAAM,MAAM,KAAK,QAAQ,IAAW;AAAA,IAAA;AAGhE,SAAA,gBAAgB,CAA4CA,UAE3C;AACR,aAAA,cAAc,EAAE,GAAGA,OAAM,MAAM,KAAK,QAAQ,IAAW;AAAA,IAAA;AAGhE,SAAA,cAAc,MAAM;AAClB,aAAO,YAAY,EAAE,MAAM,KAAK,QAAQ,IAAI;AAAA,IAAA;AAlD5C,SAAK,UAAU;AACb,SAAa,WAAW,OAAO,IAAI,YAAY;AAAA,EACnD;AAkDF;AAEO,SAAS,gBAGd,IAAS;AACT,SAAO,CAAC,SAA2B;AACjC,WAAO,IAAI,UAAkB,EAAE,IAAe,GAAG,KAAM,CAAA;AAAA,EAAA;AAE3D;AAEA,MAAM,yBAAyB;AAE/B,SAAS,aAAa,GAAW;AAC/B,SAAO,EAAE,WAAW,wBAAwB,EAAE,EAAE,WAAW,MAAM,GAAG;AACtE;AAEO,SAAS,oBAGd,IAAe;AACR,SAAA,CAAC,SACN,IAAI,UAAkB,EAAE,IAAI,aAAa,EAAE,GAAG,GAAG,KAAA,CAAM;AAC3D;"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -9,14 +9,14 @@ export { defer } from './defer.js';
|
|
|
9
9
|
export type { DeferredPromiseState, DeferredPromise } from './defer.js';
|
|
10
10
|
export { CatchBoundary, ErrorComponent } from './CatchBoundary.js';
|
|
11
11
|
export { FileRoute, createFileRoute, FileRouteLoader, LazyRoute, createLazyRoute, createLazyFileRoute, } from './fileRoute.js';
|
|
12
|
-
export type { FileRoutesByPath, LazyRouteOptions } from './fileRoute.js';
|
|
12
|
+
export type { FileRoutesByPath, FileRouteTypes, LazyRouteOptions, } from './fileRoute.js';
|
|
13
13
|
export * from './history.js';
|
|
14
14
|
export { lazyRouteComponent } from './lazyRouteComponent.js';
|
|
15
15
|
export { useLinkProps, createLink, Link } from './link.js';
|
|
16
16
|
export type { CleanPath, Split, ParsePathParams, Join, Last, RemoveTrailingSlashes, RemoveLeadingSlashes, SearchPaths, SearchRelativePathAutoComplete, RelativeToParentPathAutoComplete, RelativeToCurrentPathAutoComplete, AbsolutePathAutoComplete, RelativeToPathAutoComplete, NavigateOptions, ToOptions, ToMaskOptions, ToSubOptions, ResolveRoute, SearchParamOptions, PathParamOptions, ToPathOption, ActiveOptions, LinkOptions, CheckPath, ResolveRelativePath, UseLinkPropsOptions, ActiveLinkOptions, LinkProps, LinkComponent, } from './link.js';
|
|
17
17
|
export type { ParsedLocation } from './location.js';
|
|
18
18
|
export { Matches, useMatchRoute, MatchRoute, useMatches, useParentMatches, useChildMatches, isMatch, } from './Matches.js';
|
|
19
|
-
export type { RouteMatch, AnyRouteMatch, MatchRouteOptions, UseMatchRouteOptions, MakeMatchRouteOptions, } from './Matches.js';
|
|
19
|
+
export type { RouteMatch, AnyRouteMatch, MatchRouteOptions, UseMatchRouteOptions, MakeMatchRouteOptions, MakeRouteMatch, MakeRouteMatchUnion, } from './Matches.js';
|
|
20
20
|
export { matchContext } from './matchContext.js';
|
|
21
21
|
export { Match, Outlet } from './Match.js';
|
|
22
22
|
export { isServerSideError, defaultDeserializeError } from './isServerSideError.js';
|
|
@@ -32,7 +32,7 @@ export { rootRouteId } from './root.js';
|
|
|
32
32
|
export type { RootRouteId } from './root.js';
|
|
33
33
|
export { RouteApi, getRouteApi, Route, createRoute, RootRoute, rootRouteWithContext, createRootRoute, createRootRouteWithContext, createRouteMask, NotFoundRoute, } from './route.js';
|
|
34
34
|
export type { AnyPathParams, ResolveParams, SearchSchemaInput, SearchValidatorAdapter, AnySearchSchema, AnyContext, RouteContext, PreloadableObj, RoutePathOptions, StaticDataRouteOption, RoutePathOptionsIntersection, RouteOptions, FileBaseRouteOptions, BaseRouteOptions, UpdatableRouteOptions, UpdatableStaticRouteOption, MetaDescriptor, RouteLinkEntry, ParseParamsFn, RouteLoaderFn, LoaderFnContext, SearchFilter, ResolveId, InferFullSearchSchema, InferFullSearchSchemaInput, ResolveFullSearchSchema, ResolveFullSearchSchemaInput, AnyRoute, RouteConstraints, AnyRootRoute, ResolveFullPath, RouteMask, ErrorRouteProps, ErrorComponentProps, NotFoundRouteProps, ReactNode, SyncRouteComponent, AsyncRouteComponent, RouteComponent, ErrorRouteComponent, NotFoundRouteComponent, TrimPath, TrimPathLeft, TrimPathRight, RootRouteOptions, AnyRouteWithContext, ParseSplatParams, SplatParams, StringifyParamsFn, ParamsOptions, FullSearchSchemaOption, RouteContextFn, RouteContextOptions, BeforeLoadFn, BeforeLoadContextOptions, AnySearchValidator, DefaultSearchValidator, ContextOptions, SearchValidatorObj, AnySearchValidatorObj, AnySearchValidatorAdapter, AnySearchValidatorFn, SearchValidatorFn, SearchValidator, InferAllParams, InferAllContext, ResolveSearchSchemaFnInput, ResolveSearchSchemaInput, ResolveSearchSchema, LooseReturnType, LooseAsyncReturnType, ContextReturnType, ContextAsyncReturnType, RouteContextParameter, BeforeLoadContextParameter, ResolveAllContext, ResolveLoaderData, ResolveAllParamsFromParent, ResolveRouteContext, ResolveSearchSchemaFn, } from './route.js';
|
|
35
|
-
export type { ParseRoute, RoutesById, RouteById, RouteIds, RoutesByPath, RouteByPath, RoutePaths, FullSearchSchema, AllParams, } from './routeInfo.js';
|
|
35
|
+
export type { ParseRoute, RoutesById, RouteById, RouteIds, RoutesByPath, RouteByPath, RoutePaths, FullSearchSchema, AllParams, AllLoaderData, FullSearchSchemaInput, AllContext, } from './routeInfo.js';
|
|
36
36
|
export { componentTypes, createRouter, Router, lazyFn, SearchParamError, PathParamError, getInitialRouterState, defaultSerializeError, } from './router.js';
|
|
37
37
|
export type { Register, AnyRouter, RegisteredRouter, HydrationCtx, RouterContextOptions, TrailingSlashOption, RouterOptions, RouterErrorSerializer, RouterState, ListenerFn, BuildNextOptions, DehydratedRouterState, DehydratedRouteMatch, DehydratedRouter, RouterConstructorOptions, RouterEvents, RouterEvent, RouterListener, AnyRouterWithContext, ExtractedEntry, StreamState, } from './router.js';
|
|
38
38
|
export { RouterProvider, RouterContextProvider } from './RouterProvider.js';
|