@tanstack/react-router 1.111.3 → 1.111.6
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/fileRoute.cjs +4 -1
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +4 -4
- package/dist/cjs/index.d.cts +1 -3
- package/dist/cjs/redirects.cjs.map +1 -1
- package/dist/cjs/redirects.d.cts +2 -16
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +1 -2
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +1 -2
- package/dist/cjs/typePrimitives.d.cts +3 -4
- package/dist/cjs/useLoaderData.cjs.map +1 -1
- package/dist/cjs/useLoaderData.d.cts +2 -5
- package/dist/cjs/useLoaderDeps.cjs.map +1 -1
- package/dist/cjs/useLoaderDeps.d.cts +2 -5
- package/dist/cjs/useMatch.cjs.map +1 -1
- package/dist/cjs/useMatch.d.cts +1 -2
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/cjs/useNavigate.d.cts +1 -2
- package/dist/cjs/useParams.cjs.map +1 -1
- package/dist/cjs/useParams.d.cts +2 -5
- package/dist/cjs/useRouteContext.cjs.map +1 -1
- package/dist/cjs/useRouteContext.d.cts +1 -8
- package/dist/cjs/useSearch.cjs.map +1 -1
- package/dist/cjs/useSearch.d.cts +2 -5
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +0 -8
- package/dist/esm/fileRoute.d.ts +4 -4
- package/dist/esm/fileRoute.js +4 -1
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/index.d.ts +1 -3
- package/dist/esm/redirects.d.ts +2 -16
- package/dist/esm/redirects.js.map +1 -1
- package/dist/esm/route.d.ts +1 -2
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.d.ts +1 -2
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/typePrimitives.d.ts +3 -4
- package/dist/esm/useLoaderData.d.ts +2 -5
- package/dist/esm/useLoaderData.js.map +1 -1
- package/dist/esm/useLoaderDeps.d.ts +2 -5
- package/dist/esm/useLoaderDeps.js.map +1 -1
- package/dist/esm/useMatch.d.ts +1 -2
- package/dist/esm/useMatch.js.map +1 -1
- package/dist/esm/useNavigate.d.ts +1 -2
- package/dist/esm/useNavigate.js.map +1 -1
- package/dist/esm/useParams.d.ts +2 -5
- package/dist/esm/useParams.js.map +1 -1
- package/dist/esm/useRouteContext.d.ts +1 -8
- package/dist/esm/useRouteContext.js.map +1 -1
- package/dist/esm/useSearch.d.ts +2 -5
- package/dist/esm/useSearch.js.map +1 -1
- package/dist/esm/utils.d.ts +0 -8
- package/dist/esm/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/fileRoute.ts +12 -5
- package/src/index.tsx +4 -2
- package/src/redirects.ts +4 -36
- package/src/route.ts +1 -2
- package/src/router.ts +2 -1
- package/src/typePrimitives.ts +6 -3
- package/src/useLoaderData.tsx +6 -20
- package/src/useLoaderDeps.tsx +6 -13
- package/src/useMatch.tsx +1 -2
- package/src/useNavigate.tsx +5 -12
- package/src/useParams.tsx +4 -22
- package/src/useRouteContext.ts +5 -36
- package/src/useSearch.tsx +4 -22
- package/src/utils.ts +0 -19
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { Constrain, ConstrainLiteral, FromPathOption, NavigateOptions, PathParamOptions, RouteIds, SearchParamOptions, ToPathOption } from '@tanstack/router-core';
|
|
1
|
+
import { Constrain, ConstrainLiteral, FromPathOption, NavigateOptions, PathParamOptions, Redirect, RouteIds, SearchParamOptions, ToPathOption, UseParamsResult, UseSearchResult } from '@tanstack/router-core';
|
|
2
2
|
import { LinkComponentProps } from './link.js';
|
|
3
|
-
import { Redirect } from './redirects.js';
|
|
4
3
|
import { AnyRouter, RegisteredRouter } from './router.js';
|
|
5
|
-
import { UseParamsOptions
|
|
6
|
-
import { UseSearchOptions
|
|
4
|
+
import { UseParamsOptions } from './useParams.js';
|
|
5
|
+
import { UseSearchOptions } from './useSearch.js';
|
|
7
6
|
export type ValidateFromPath<TRouter extends AnyRouter = RegisteredRouter, TFrom = string> = FromPathOption<TRouter, TFrom>;
|
|
8
7
|
export type ValidateToPath<TRouter extends AnyRouter = RegisteredRouter, TTo extends string | undefined = undefined, TFrom extends string = string> = ToPathOption<TRouter, TFrom, TTo>;
|
|
9
8
|
export type ValidateSearch<TRouter extends AnyRouter = RegisteredRouter, TTo extends string | undefined = undefined, TFrom extends string = string> = SearchParamOptions<TRouter, TFrom, TTo>;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { StructuralSharingOption, ValidateSelected } from './structuralSharing.js';
|
|
2
2
|
import { AnyRouter, RegisteredRouter } from './router.js';
|
|
3
|
-
import {
|
|
4
|
-
import { StrictOrFrom } from './utils.js';
|
|
3
|
+
import { ResolveUseLoaderData, StrictOrFrom, UseLoaderDataResult } from '@tanstack/router-core';
|
|
5
4
|
export interface UseLoaderDataBaseOptions<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TSelected, TStructuralSharing> {
|
|
6
|
-
select?: (match:
|
|
5
|
+
select?: (match: ResolveUseLoaderData<TRouter, TFrom, TStrict>) => ValidateSelected<TRouter, TSelected, TStructuralSharing>;
|
|
7
6
|
}
|
|
8
7
|
export type UseLoaderDataOptions<TRouter extends AnyRouter, TFrom extends string | undefined, TStrict extends boolean, TSelected, TStructuralSharing> = StrictOrFrom<TRouter, TFrom, TStrict> & UseLoaderDataBaseOptions<TRouter, TFrom, TStrict, TSelected, TStructuralSharing> & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>;
|
|
9
|
-
export type ResolveLoaderData<TRouter extends AnyRouter, TFrom, TStrict extends boolean> = TStrict extends false ? AllLoaderData<TRouter['routeTree']> : Expand<RouteById<TRouter['routeTree'], TFrom>['types']['loaderData']>;
|
|
10
|
-
export type UseLoaderDataResult<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TSelected> = unknown extends TSelected ? ResolveLoaderData<TRouter, TFrom, TStrict> : TSelected;
|
|
11
8
|
export type UseLoaderDataRoute<out TId> = <TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown, TStructuralSharing extends boolean = boolean>(opts?: UseLoaderDataBaseOptions<TRouter, TId, true, TSelected, TStructuralSharing> & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>) => UseLoaderDataResult<TRouter, TId, true, TSelected>;
|
|
12
9
|
export declare function useLoaderData<TRouter extends AnyRouter = RegisteredRouter, const TFrom extends string | undefined = undefined, TStrict extends boolean = true, TSelected = unknown, TStructuralSharing extends boolean = boolean>(opts: UseLoaderDataOptions<TRouter, TFrom, TStrict, TSelected, TStructuralSharing>): UseLoaderDataResult<TRouter, TFrom, TStrict, TSelected>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLoaderData.js","sources":["../../src/useLoaderData.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type {
|
|
1
|
+
{"version":3,"file":"useLoaderData.js","sources":["../../src/useLoaderData.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type {\n ResolveUseLoaderData,\n StrictOrFrom,\n UseLoaderDataResult,\n} from '@tanstack/router-core'\n\nexport interface UseLoaderDataBaseOptions<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TSelected,\n TStructuralSharing,\n> {\n select?: (\n match: ResolveUseLoaderData<TRouter, TFrom, TStrict>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n}\n\nexport type UseLoaderDataOptions<\n TRouter extends AnyRouter,\n TFrom extends string | undefined,\n TStrict extends boolean,\n TSelected,\n TStructuralSharing,\n> = StrictOrFrom<TRouter, TFrom, TStrict> &\n UseLoaderDataBaseOptions<\n TRouter,\n TFrom,\n TStrict,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>\n\nexport type UseLoaderDataRoute<out TId> = <\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseLoaderDataBaseOptions<\n TRouter,\n TId,\n true,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n) => UseLoaderDataResult<TRouter, TId, true, TSelected>\n\nexport function useLoaderData<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string | undefined = undefined,\n TStrict extends boolean = true,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts: UseLoaderDataOptions<\n TRouter,\n TFrom,\n TStrict,\n TSelected,\n TStructuralSharing\n >,\n): UseLoaderDataResult<TRouter, TFrom, TStrict, TSelected> {\n return useMatch({\n from: opts.from!,\n strict: opts.strict,\n structuralSharing: opts.structuralSharing,\n select: (s: any) => {\n return opts.select ? opts.select(s.loaderData) : s.loaderData\n },\n } as any) as UseLoaderDataResult<TRouter, TFrom, TStrict, TSelected>\n}\n"],"names":[],"mappings":";AAuDO,SAAS,cAOd,MAOyD;AACzD,SAAO,SAAS;AAAA,IACd,MAAM,KAAK;AAAA,IACX,QAAQ,KAAK;AAAA,IACb,mBAAmB,KAAK;AAAA,IACxB,QAAQ,CAAC,MAAW;AAClB,aAAO,KAAK,SAAS,KAAK,OAAO,EAAE,UAAU,IAAI,EAAE;AAAA,IAAA;AAAA,EACrD,CACM;AACV;"}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { StructuralSharingOption, ValidateSelected } from './structuralSharing.js';
|
|
2
2
|
import { AnyRouter, RegisteredRouter } from './router.js';
|
|
3
|
-
import { StrictOrFrom } from '
|
|
4
|
-
import { Expand, RouteById } from '@tanstack/router-core';
|
|
3
|
+
import { ResolveUseLoaderDeps, StrictOrFrom, UseLoaderDepsResult } from '@tanstack/router-core';
|
|
5
4
|
export interface UseLoaderDepsBaseOptions<TRouter extends AnyRouter, TFrom, TSelected, TStructuralSharing> {
|
|
6
|
-
select?: (deps:
|
|
5
|
+
select?: (deps: ResolveUseLoaderDeps<TRouter, TFrom>) => ValidateSelected<TRouter, TSelected, TStructuralSharing>;
|
|
7
6
|
}
|
|
8
7
|
export type UseLoaderDepsOptions<TRouter extends AnyRouter, TFrom extends string | undefined, TSelected, TStructuralSharing> = StrictOrFrom<TRouter, TFrom> & UseLoaderDepsBaseOptions<TRouter, TFrom, TSelected, TStructuralSharing> & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>;
|
|
9
|
-
export type ResolveLoaderDeps<TRouter extends AnyRouter, TFrom> = Expand<RouteById<TRouter['routeTree'], TFrom>['types']['loaderDeps']>;
|
|
10
|
-
export type UseLoaderDepsResult<TRouter extends AnyRouter, TFrom, TSelected> = unknown extends TSelected ? ResolveLoaderDeps<TRouter, TFrom> : TSelected;
|
|
11
8
|
export type UseLoaderDepsRoute<out TId> = <TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown, TStructuralSharing extends boolean = boolean>(opts?: UseLoaderDepsBaseOptions<TRouter, TId, TSelected, TStructuralSharing> & StructuralSharingOption<TRouter, TSelected, false>) => UseLoaderDepsResult<TRouter, TId, TSelected>;
|
|
12
9
|
export declare function useLoaderDeps<TRouter extends AnyRouter = RegisteredRouter, const TFrom extends string | undefined = undefined, TSelected = unknown, TStructuralSharing extends boolean = boolean>(opts: UseLoaderDepsOptions<TRouter, TFrom, TSelected, TStructuralSharing>): UseLoaderDepsResult<TRouter, TFrom, TSelected>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLoaderDeps.js","sources":["../../src/useLoaderDeps.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type {
|
|
1
|
+
{"version":3,"file":"useLoaderDeps.js","sources":["../../src/useLoaderDeps.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type {\n ResolveUseLoaderDeps,\n StrictOrFrom,\n UseLoaderDepsResult,\n} from '@tanstack/router-core'\n\nexport interface UseLoaderDepsBaseOptions<\n TRouter extends AnyRouter,\n TFrom,\n TSelected,\n TStructuralSharing,\n> {\n select?: (\n deps: ResolveUseLoaderDeps<TRouter, TFrom>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n}\n\nexport type UseLoaderDepsOptions<\n TRouter extends AnyRouter,\n TFrom extends string | undefined,\n TSelected,\n TStructuralSharing,\n> = StrictOrFrom<TRouter, TFrom> &\n UseLoaderDepsBaseOptions<TRouter, TFrom, TSelected, TStructuralSharing> &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>\n\nexport type UseLoaderDepsRoute<out TId> = <\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseLoaderDepsBaseOptions<TRouter, TId, TSelected, TStructuralSharing> &\n StructuralSharingOption<TRouter, TSelected, false>,\n) => UseLoaderDepsResult<TRouter, TId, TSelected>\n\nexport function useLoaderDeps<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string | undefined = undefined,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts: UseLoaderDepsOptions<TRouter, TFrom, TSelected, TStructuralSharing>,\n): UseLoaderDepsResult<TRouter, TFrom, TSelected> {\n const { select, ...rest } = opts\n return useMatch({\n ...rest,\n select: (s) => {\n return select ? select(s.loaderDeps) : s.loaderDeps\n },\n }) as UseLoaderDepsResult<TRouter, TFrom, TSelected>\n}\n"],"names":[],"mappings":";AAyCO,SAAS,cAMd,MACgD;AAChD,QAAM,EAAE,QAAQ,GAAG,KAAA,IAAS;AAC5B,SAAO,SAAS;AAAA,IACd,GAAG;AAAA,IACH,QAAQ,CAAC,MAAM;AACb,aAAO,SAAS,OAAO,EAAE,UAAU,IAAI,EAAE;AAAA,IAAA;AAAA,EAC3C,CACD;AACH;"}
|
package/dist/esm/useMatch.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { StructuralSharingOption, ValidateSelected } from './structuralSharing.js';
|
|
2
2
|
import { AnyRouter, RegisteredRouter } from './router.js';
|
|
3
3
|
import { MakeRouteMatch, MakeRouteMatchUnion } from './Matches.js';
|
|
4
|
-
import { StrictOrFrom } from '
|
|
5
|
-
import { ThrowOrOptional } from '@tanstack/router-core';
|
|
4
|
+
import { StrictOrFrom, ThrowOrOptional } from '@tanstack/router-core';
|
|
6
5
|
export interface UseMatchBaseOptions<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TThrow extends boolean, TSelected, TStructuralSharing extends boolean> {
|
|
7
6
|
select?: (match: MakeRouteMatch<TRouter['routeTree'], TFrom, TStrict>) => ValidateSelected<TRouter, TSelected, TStructuralSharing>;
|
|
8
7
|
shouldThrow?: TThrow;
|
package/dist/esm/useMatch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMatch.js","sources":["../../src/useMatch.tsx"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport { useRouterState } from './useRouterState'\nimport { dummyMatchContext, matchContext } from './matchContext'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type { MakeRouteMatch, MakeRouteMatchUnion } from './Matches'\nimport type { StrictOrFrom
|
|
1
|
+
{"version":3,"file":"useMatch.js","sources":["../../src/useMatch.tsx"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport { useRouterState } from './useRouterState'\nimport { dummyMatchContext, matchContext } from './matchContext'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type { MakeRouteMatch, MakeRouteMatchUnion } from './Matches'\nimport type { StrictOrFrom, ThrowOrOptional } from '@tanstack/router-core'\n\nexport interface UseMatchBaseOptions<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing extends boolean,\n> {\n select?: (\n match: MakeRouteMatch<TRouter['routeTree'], TFrom, TStrict>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n shouldThrow?: TThrow\n}\n\nexport type UseMatchRoute<out TFrom> = <\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseMatchBaseOptions<\n TRouter,\n TFrom,\n true,\n true,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n) => UseMatchResult<TRouter, TFrom, true, TSelected>\n\nexport type UseMatchOptions<\n TRouter extends AnyRouter,\n TFrom extends string | undefined,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing extends boolean,\n> = StrictOrFrom<TRouter, TFrom, TStrict> &\n UseMatchBaseOptions<\n TRouter,\n TFrom,\n TStrict,\n TThrow,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>\n\nexport type UseMatchResult<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TSelected,\n> = unknown extends TSelected\n ? TStrict extends true\n ? MakeRouteMatch<TRouter['routeTree'], TFrom, TStrict>\n : MakeRouteMatchUnion<TRouter>\n : TSelected\n\nexport type ThrowConstraint<\n TStrict extends boolean,\n TThrow extends boolean,\n> = TStrict extends false ? (TThrow extends true ? never : TThrow) : TThrow\n\nexport function useMatch<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string | undefined = undefined,\n TStrict extends boolean = true,\n TThrow extends boolean = true,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts: UseMatchOptions<\n TRouter,\n TFrom,\n TStrict,\n ThrowConstraint<TStrict, TThrow>,\n TSelected,\n TStructuralSharing\n >,\n): ThrowOrOptional<UseMatchResult<TRouter, TFrom, TStrict, TSelected>, TThrow> {\n const nearestMatchId = React.useContext(\n opts.from ? dummyMatchContext : matchContext,\n )\n\n const matchSelection = useRouterState({\n select: (state: any) => {\n const match = state.matches.find((d: any) =>\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) : match\n },\n structuralSharing: opts.structuralSharing,\n } as any)\n\n return matchSelection as any\n}\n"],"names":[],"mappings":";;;;AA4EO,SAAS,SAQd,MAQ6E;AAC7E,QAAM,iBAAiB,MAAM;AAAA,IAC3B,KAAK,OAAO,oBAAoB;AAAA,EAClC;AAEA,QAAM,iBAAiB,eAAe;AAAA,IACpC,QAAQ,CAAC,UAAe;AAChB,YAAA,QAAQ,MAAM,QAAQ;AAAA,QAAK,CAAC,MAChC,KAAK,OAAO,KAAK,SAAS,EAAE,UAAU,EAAE,OAAO;AAAA,MACjD;AACA;AAAA,QACE,GAAG,KAAK,eAAe,SAAS,CAAC;AAAA,QACjC,kBAAkB,KAAK,OAAO,yBAAyB,KAAK,IAAI,MAAM,kBAAkB;AAAA,MAC1F;AAEA,UAAI,UAAU,QAAW;AAChB,eAAA;AAAA,MAAA;AAGT,aAAO,KAAK,SAAS,KAAK,OAAO,KAAK,IAAI;AAAA,IAC5C;AAAA,IACA,mBAAmB,KAAK;AAAA,EAAA,CAClB;AAED,SAAA;AACT;"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { FromPathOption, NavigateOptions } from '@tanstack/router-core';
|
|
1
|
+
import { FromPathOption, NavigateOptions, UseNavigateResult } from '@tanstack/router-core';
|
|
2
2
|
import { AnyRouter, RegisteredRouter } from './router.js';
|
|
3
|
-
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>;
|
|
4
3
|
export declare function useNavigate<TRouter extends AnyRouter = RegisteredRouter, TDefaultFrom extends string = string>(_defaultOpts?: {
|
|
5
4
|
from?: FromPathOption<TRouter, TDefaultFrom>;
|
|
6
5
|
}): UseNavigateResult<TDefaultFrom>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNavigate.js","sources":["../../src/useNavigate.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useRouter } from './useRouter'\nimport type {
|
|
1
|
+
{"version":3,"file":"useNavigate.js","sources":["../../src/useNavigate.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useRouter } from './useRouter'\nimport type {\n FromPathOption,\n NavigateOptions,\n UseNavigateResult,\n} from '@tanstack/router-core'\nimport type { AnyRouter, RegisteredRouter } from './router'\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 const TFrom extends string = string,\n const TTo extends string | undefined = undefined,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(props: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): null {\n const router = useRouter()\n\n const previousPropsRef = React.useRef<NavigateOptions<\n TRouter,\n TFrom,\n TTo,\n TMaskFrom,\n TMaskTo\n > | null>(null)\n React.useEffect(() => {\n if (previousPropsRef.current !== props) {\n router.navigate({\n ...props,\n })\n previousPropsRef.current = props\n }\n }, [router, props])\n return null\n}\n"],"names":[],"mappings":";;AASO,SAAS,YAGd,cAEkC;AAC5B,QAAA,EAAE,SAAS,IAAI,UAAU;AAE/B,SAAO,MAAM;AAAA,IACX,CAAC,YAA6B;AAC5B,aAAO,SAAS;AAAA,QACd,GAAG;AAAA,MAAA,CACJ;AAAA,IACH;AAAA,IACA,CAAC,QAAQ;AAAA,EACX;AACF;AAiBO,SAAS,SAMd,OAAuE;AACvE,QAAM,SAAS,UAAU;AAEnB,QAAA,mBAAmB,MAAM,OAMrB,IAAI;AACd,QAAM,UAAU,MAAM;AAChB,QAAA,iBAAiB,YAAY,OAAO;AACtC,aAAO,SAAS;AAAA,QACd,GAAG;AAAA,MAAA,CACJ;AACD,uBAAiB,UAAU;AAAA,IAAA;AAAA,EAC7B,GACC,CAAC,QAAQ,KAAK,CAAC;AACX,SAAA;AACT;"}
|
package/dist/esm/useParams.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { ThrowConstraint } from './useMatch.js';
|
|
2
2
|
import { StructuralSharingOption, ValidateSelected } from './structuralSharing.js';
|
|
3
3
|
import { AnyRouter, RegisteredRouter } from './router.js';
|
|
4
|
-
import { StrictOrFrom } from '
|
|
5
|
-
import { AllParams, Expand, RouteById, ThrowOrOptional } from '@tanstack/router-core';
|
|
4
|
+
import { ResolveUseParams, StrictOrFrom, ThrowOrOptional, UseParamsResult } from '@tanstack/router-core';
|
|
6
5
|
export interface UseParamsBaseOptions<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TThrow extends boolean, TSelected, TStructuralSharing> {
|
|
7
|
-
select?: (params:
|
|
6
|
+
select?: (params: ResolveUseParams<TRouter, TFrom, TStrict>) => ValidateSelected<TRouter, TSelected, TStructuralSharing>;
|
|
8
7
|
shouldThrow?: TThrow;
|
|
9
8
|
}
|
|
10
9
|
export type UseParamsOptions<TRouter extends AnyRouter, TFrom extends string | undefined, TStrict extends boolean, TThrow extends boolean, TSelected, TStructuralSharing> = StrictOrFrom<TRouter, TFrom, TStrict> & UseParamsBaseOptions<TRouter, TFrom, TStrict, TThrow, TSelected, TStructuralSharing> & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>;
|
|
11
|
-
export type ResolveParams<TRouter extends AnyRouter, TFrom, TStrict extends boolean> = TStrict extends false ? AllParams<TRouter['routeTree']> : Expand<RouteById<TRouter['routeTree'], TFrom>['types']['allParams']>;
|
|
12
|
-
export type UseParamsResult<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TSelected> = unknown extends TSelected ? ResolveParams<TRouter, TFrom, TStrict> : TSelected;
|
|
13
10
|
export type UseParamsRoute<out TFrom> = <TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown, TStructuralSharing extends boolean = boolean>(opts?: UseParamsBaseOptions<TRouter, TFrom, true, true, TSelected, TStructuralSharing> & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>) => UseParamsResult<TRouter, TFrom, true, TSelected>;
|
|
14
11
|
export declare function useParams<TRouter extends AnyRouter = RegisteredRouter, const TFrom extends string | undefined = undefined, TStrict extends boolean = true, TThrow extends boolean = true, TSelected = unknown, TStructuralSharing extends boolean = boolean>(opts: UseParamsOptions<TRouter, TFrom, TStrict, ThrowConstraint<TStrict, TThrow>, TSelected, TStructuralSharing>): ThrowOrOptional<UseParamsResult<TRouter, TFrom, TStrict, TSelected>, TThrow>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useParams.js","sources":["../../src/useParams.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { ThrowConstraint } from './useMatch'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type {
|
|
1
|
+
{"version":3,"file":"useParams.js","sources":["../../src/useParams.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { ThrowConstraint } from './useMatch'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type {\n ResolveUseParams,\n StrictOrFrom,\n ThrowOrOptional,\n UseParamsResult,\n} from '@tanstack/router-core'\n\nexport interface UseParamsBaseOptions<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing,\n> {\n select?: (\n params: ResolveUseParams<TRouter, TFrom, TStrict>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n shouldThrow?: TThrow\n}\n\nexport type UseParamsOptions<\n TRouter extends AnyRouter,\n TFrom extends string | undefined,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing,\n> = StrictOrFrom<TRouter, TFrom, TStrict> &\n UseParamsBaseOptions<\n TRouter,\n TFrom,\n TStrict,\n TThrow,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>\n\nexport type UseParamsRoute<out TFrom> = <\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseParamsBaseOptions<\n TRouter,\n TFrom,\n /* TStrict */ true,\n /* TThrow */ true,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n) => UseParamsResult<TRouter, TFrom, true, TSelected>\n\nexport function useParams<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string | undefined = undefined,\n TStrict extends boolean = true,\n TThrow extends boolean = true,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts: UseParamsOptions<\n TRouter,\n TFrom,\n TStrict,\n ThrowConstraint<TStrict, TThrow>,\n TSelected,\n TStructuralSharing\n >,\n): ThrowOrOptional<\n UseParamsResult<TRouter, TFrom, TStrict, TSelected>,\n TThrow\n> {\n return useMatch({\n from: opts.from!,\n strict: opts.strict,\n shouldThrow: opts.shouldThrow,\n structuralSharing: opts.structuralSharing,\n select: (match: any) => {\n return opts.select ? opts.select(match.params) : match.params\n },\n }) as any\n}\n"],"names":[],"mappings":";AA8DO,SAAS,UAQd,MAWA;AACA,SAAO,SAAS;AAAA,IACd,MAAM,KAAK;AAAA,IACX,QAAQ,KAAK;AAAA,IACb,aAAa,KAAK;AAAA,IAClB,mBAAmB,KAAK;AAAA,IACxB,QAAQ,CAAC,UAAe;AACtB,aAAO,KAAK,SAAS,KAAK,OAAO,MAAM,MAAM,IAAI,MAAM;AAAA,IAAA;AAAA,EACzD,CACD;AACH;"}
|
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import { AnyRouter, RegisteredRouter } from './router.js';
|
|
2
|
-
import {
|
|
3
|
-
import { AllContext, Expand, RouteById } from '@tanstack/router-core';
|
|
4
|
-
export interface UseRouteContextBaseOptions<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TSelected> {
|
|
5
|
-
select?: (search: ResolveRouteContext<TRouter, TFrom, TStrict>) => TSelected;
|
|
6
|
-
}
|
|
7
|
-
export type UseRouteContextOptions<TRouter extends AnyRouter, TFrom extends string | undefined, TStrict extends boolean, TSelected> = StrictOrFrom<TRouter, TFrom, TStrict> & UseRouteContextBaseOptions<TRouter, TFrom, TStrict, TSelected>;
|
|
8
|
-
export type ResolveRouteContext<TRouter extends AnyRouter, TFrom, TStrict extends boolean> = TStrict extends false ? AllContext<TRouter['routeTree']> : Expand<RouteById<TRouter['routeTree'], TFrom>['types']['allContext']>;
|
|
9
|
-
export type UseRouteContextResult<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TSelected> = unknown extends TSelected ? ResolveRouteContext<TRouter, TFrom, TStrict> : TSelected;
|
|
2
|
+
import { UseRouteContextBaseOptions, UseRouteContextOptions, UseRouteContextResult } from '@tanstack/router-core';
|
|
10
3
|
export type UseRouteContextRoute<out TFrom> = <TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown>(opts?: UseRouteContextBaseOptions<TRouter, TFrom, true, TSelected>) => UseRouteContextResult<TRouter, TFrom, true, TSelected>;
|
|
11
4
|
export declare function useRouteContext<TRouter extends AnyRouter = RegisteredRouter, const TFrom extends string | undefined = undefined, TStrict extends boolean = true, TSelected = unknown>(opts: UseRouteContextOptions<TRouter, TFrom, TStrict, TSelected>): UseRouteContextResult<TRouter, TFrom, TStrict, TSelected>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouteContext.js","sources":["../../src/useRouteContext.ts"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type {
|
|
1
|
+
{"version":3,"file":"useRouteContext.js","sources":["../../src/useRouteContext.ts"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type {\n UseRouteContextBaseOptions,\n UseRouteContextOptions,\n UseRouteContextResult,\n} from '@tanstack/router-core'\n\nexport type UseRouteContextRoute<out TFrom> = <\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n>(\n opts?: UseRouteContextBaseOptions<TRouter, TFrom, true, TSelected>,\n) => UseRouteContextResult<TRouter, TFrom, true, TSelected>\n\nexport function useRouteContext<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string | undefined = undefined,\n TStrict extends boolean = true,\n TSelected = unknown,\n>(\n opts: UseRouteContextOptions<TRouter, TFrom, TStrict, TSelected>,\n): UseRouteContextResult<TRouter, TFrom, TStrict, TSelected> {\n return useMatch({\n ...(opts as any),\n select: (match) =>\n opts.select ? opts.select(match.context) : match.context,\n }) as UseRouteContextResult<TRouter, TFrom, TStrict, TSelected>\n}\n"],"names":[],"mappings":";AAeO,SAAS,gBAMd,MAC2D;AAC3D,SAAO,SAAS;AAAA,IACd,GAAI;AAAA,IACJ,QAAQ,CAAC,UACP,KAAK,SAAS,KAAK,OAAO,MAAM,OAAO,IAAI,MAAM;AAAA,EAAA,CACpD;AACH;"}
|
package/dist/esm/useSearch.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { ThrowConstraint } from './useMatch.js';
|
|
2
2
|
import { StructuralSharingOption, ValidateSelected } from './structuralSharing.js';
|
|
3
3
|
import { AnyRouter, RegisteredRouter } from './router.js';
|
|
4
|
-
import { StrictOrFrom } from '
|
|
5
|
-
import { Expand, FullSearchSchema, RouteById, ThrowOrOptional } from '@tanstack/router-core';
|
|
4
|
+
import { ResolveUseSearch, StrictOrFrom, ThrowOrOptional, UseSearchResult } from '@tanstack/router-core';
|
|
6
5
|
export interface UseSearchBaseOptions<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TThrow extends boolean, TSelected, TStructuralSharing> {
|
|
7
|
-
select?: (state:
|
|
6
|
+
select?: (state: ResolveUseSearch<TRouter, TFrom, TStrict>) => ValidateSelected<TRouter, TSelected, TStructuralSharing>;
|
|
8
7
|
shouldThrow?: TThrow;
|
|
9
8
|
}
|
|
10
9
|
export type UseSearchOptions<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TThrow extends boolean, TSelected, TStructuralSharing> = StrictOrFrom<TRouter, TFrom, TStrict> & UseSearchBaseOptions<TRouter, TFrom, TStrict, TThrow, TSelected, TStructuralSharing> & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>;
|
|
11
|
-
export type UseSearchResult<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TSelected> = unknown extends TSelected ? ResolveSearch<TRouter, TFrom, TStrict> : TSelected;
|
|
12
|
-
export type ResolveSearch<TRouter extends AnyRouter, TFrom, TStrict extends boolean> = TStrict extends false ? FullSearchSchema<TRouter['routeTree']> : Expand<RouteById<TRouter['routeTree'], TFrom>['types']['fullSearchSchema']>;
|
|
13
10
|
export type UseSearchRoute<out TFrom> = <TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown, TStructuralSharing extends boolean = boolean>(opts?: UseSearchBaseOptions<TRouter, TFrom, true, true, TSelected, TStructuralSharing> & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>) => UseSearchResult<TRouter, TFrom, true, TSelected>;
|
|
14
11
|
export declare function useSearch<TRouter extends AnyRouter = RegisteredRouter, const TFrom extends string | undefined = undefined, TStrict extends boolean = true, TThrow extends boolean = true, TSelected = unknown, TStructuralSharing extends boolean = boolean>(opts: UseSearchOptions<TRouter, TFrom, TStrict, ThrowConstraint<TStrict, TThrow>, TSelected, TStructuralSharing>): ThrowOrOptional<UseSearchResult<TRouter, TFrom, TStrict, TSelected>, TThrow>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSearch.js","sources":["../../src/useSearch.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { ThrowConstraint } from './useMatch'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type {
|
|
1
|
+
{"version":3,"file":"useSearch.js","sources":["../../src/useSearch.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { ThrowConstraint } from './useMatch'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type {\n ResolveUseSearch,\n StrictOrFrom,\n ThrowOrOptional,\n UseSearchResult,\n} from '@tanstack/router-core'\n\nexport interface UseSearchBaseOptions<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing,\n> {\n select?: (\n state: ResolveUseSearch<TRouter, TFrom, TStrict>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n shouldThrow?: TThrow\n}\n\nexport type UseSearchOptions<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing,\n> = StrictOrFrom<TRouter, TFrom, TStrict> &\n UseSearchBaseOptions<\n TRouter,\n TFrom,\n TStrict,\n TThrow,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>\n\nexport type UseSearchRoute<out TFrom> = <\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseSearchBaseOptions<\n TRouter,\n TFrom,\n /* TStrict */ true,\n /* TThrow */ true,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n) => UseSearchResult<TRouter, TFrom, true, TSelected>\n\nexport function useSearch<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string | undefined = undefined,\n TStrict extends boolean = true,\n TThrow extends boolean = true,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts: UseSearchOptions<\n TRouter,\n TFrom,\n TStrict,\n ThrowConstraint<TStrict, TThrow>,\n TSelected,\n TStructuralSharing\n >,\n): ThrowOrOptional<\n UseSearchResult<TRouter, TFrom, TStrict, TSelected>,\n TThrow\n> {\n return useMatch({\n from: opts.from!,\n strict: opts.strict,\n shouldThrow: opts.shouldThrow,\n structuralSharing: opts.structuralSharing,\n select: (match: any) => {\n return opts.select ? opts.select(match.search) : match.search\n },\n }) as any\n}\n"],"names":[],"mappings":";AA8DO,SAAS,UAQd,MAWA;AACA,SAAO,SAAS;AAAA,IACd,MAAM,KAAK;AAAA,IACX,QAAQ,KAAK;AAAA,IACb,aAAa,KAAK;AAAA,IAClB,mBAAmB,KAAK;AAAA,IACxB,QAAQ,CAAC,UAAe;AACtB,aAAO,KAAK,SAAS,KAAK,OAAO,MAAM,MAAM,IAAI,MAAM;AAAA,IAAA;AAAA,EACzD,CACD;AACH;"}
|
package/dist/esm/utils.d.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
import { AnyRouter, ConstrainLiteral, RouteIds } from '@tanstack/router-core';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
export declare function useStableCallback<T extends (...args: Array<any>) => any>(fn: T): T;
|
|
4
|
-
export type StrictOrFrom<TRouter extends AnyRouter, TFrom, TStrict extends boolean = true> = TStrict extends false ? {
|
|
5
|
-
from?: never;
|
|
6
|
-
strict: TStrict;
|
|
7
|
-
} : {
|
|
8
|
-
from: ConstrainLiteral<TFrom, RouteIds<TRouter['routeTree']>>;
|
|
9
|
-
strict?: TStrict;
|
|
10
|
-
};
|
|
11
3
|
export declare const useLayoutEffect: typeof React.useLayoutEffect;
|
|
12
4
|
/**
|
|
13
5
|
* Taken from https://www.developerway.com/posts/implementing-advanced-use-previous-hook#part3
|
package/dist/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as React from 'react'\
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as React from 'react'\n\nexport function useStableCallback<T extends (...args: Array<any>) => any>(\n fn: T,\n): T {\n const fnRef = React.useRef(fn)\n fnRef.current = fn\n\n const ref = React.useRef((...args: Array<any>) => fnRef.current(...args))\n return ref.current as T\n}\n\nexport const useLayoutEffect =\n typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\n/**\n * Taken from https://www.developerway.com/posts/implementing-advanced-use-previous-hook#part3\n */\nexport function usePrevious<T>(value: T): T | null {\n // initialise the ref with previous and current values\n const ref = React.useRef<{ value: T; prev: T | null }>({\n value: value,\n prev: null,\n })\n\n const current = ref.current.value\n\n // if the value passed into hook doesn't match what we store as \"current\"\n // move the \"current\" to the \"previous\"\n // and store the passed value as \"current\"\n if (value !== current) {\n ref.current = {\n value: value,\n prev: current,\n }\n }\n\n // return the previous value only\n return ref.current.prev\n}\n\n/**\n * React hook to wrap `IntersectionObserver`.\n *\n * This hook will create an `IntersectionObserver` and observe the ref passed to it.\n *\n * When the intersection changes, the callback will be called with the `IntersectionObserverEntry`.\n *\n * @param ref - The ref to observe\n * @param intersectionObserverOptions - The options to pass to the IntersectionObserver\n * @param options - The options to pass to the hook\n * @param callback - The callback to call when the intersection changes\n * @returns The IntersectionObserver instance\n * @example\n * ```tsx\n * const MyComponent = () => {\n * const ref = React.useRef<HTMLDivElement>(null)\n * useIntersectionObserver(\n * ref,\n * (entry) => { doSomething(entry) },\n * { rootMargin: '10px' },\n * { disabled: false }\n * )\n * return <div ref={ref} />\n * ```\n */\nexport function useIntersectionObserver<T extends Element>(\n ref: React.RefObject<T | null>,\n callback: (entry: IntersectionObserverEntry | undefined) => void,\n intersectionObserverOptions: IntersectionObserverInit = {},\n options: { disabled?: boolean } = {},\n): IntersectionObserver | null {\n const isIntersectionObserverAvailable = React.useRef(\n typeof IntersectionObserver === 'function',\n )\n\n const observerRef = React.useRef<IntersectionObserver | null>(null)\n\n React.useEffect(() => {\n if (\n !ref.current ||\n !isIntersectionObserverAvailable.current ||\n options.disabled\n ) {\n return\n }\n\n observerRef.current = new IntersectionObserver(([entry]) => {\n callback(entry)\n }, intersectionObserverOptions)\n\n observerRef.current.observe(ref.current)\n\n return () => {\n observerRef.current?.disconnect()\n }\n }, [callback, intersectionObserverOptions, options.disabled, ref])\n\n return observerRef.current\n}\n\n/**\n * React hook to take a `React.ForwardedRef` and returns a `ref` that can be used on a DOM element.\n *\n * @param ref - The forwarded ref\n * @returns The inner ref returned by `useRef`\n * @example\n * ```tsx\n * const MyComponent = React.forwardRef((props, ref) => {\n * const innerRef = useForwardedRef(ref)\n * return <div ref={innerRef} />\n * })\n * ```\n */\nexport function useForwardedRef<T>(ref?: React.ForwardedRef<T>) {\n const innerRef = React.useRef<T>(null)\n React.useImperativeHandle(ref, () => innerRef.current!, [])\n return innerRef\n}\n"],"names":[],"mappings":";AAEO,SAAS,kBACd,IACG;AACG,QAAA,QAAQ,MAAM,OAAO,EAAE;AAC7B,QAAM,UAAU;AAEV,QAAA,MAAM,MAAM,OAAO,IAAI,SAAqB,MAAM,QAAQ,GAAG,IAAI,CAAC;AACxE,SAAO,IAAI;AACb;AAEO,MAAM,kBACX,OAAO,WAAW,cAAc,MAAM,kBAAkB,MAAM;AAKzD,SAAS,YAAe,OAAoB;AAE3C,QAAA,MAAM,MAAM,OAAqC;AAAA,IACrD;AAAA,IACA,MAAM;AAAA,EAAA,CACP;AAEK,QAAA,UAAU,IAAI,QAAQ;AAK5B,MAAI,UAAU,SAAS;AACrB,QAAI,UAAU;AAAA,MACZ;AAAA,MACA,MAAM;AAAA,IACR;AAAA,EAAA;AAIF,SAAO,IAAI,QAAQ;AACrB;AA2BgB,SAAA,wBACd,KACA,UACA,8BAAwD,CACxD,GAAA,UAAkC,IACL;AAC7B,QAAM,kCAAkC,MAAM;AAAA,IAC5C,OAAO,yBAAyB;AAAA,EAClC;AAEM,QAAA,cAAc,MAAM,OAAoC,IAAI;AAElE,QAAM,UAAU,MAAM;AACpB,QACE,CAAC,IAAI,WACL,CAAC,gCAAgC,WACjC,QAAQ,UACR;AACA;AAAA,IAAA;AAGF,gBAAY,UAAU,IAAI,qBAAqB,CAAC,CAAC,KAAK,MAAM;AAC1D,eAAS,KAAK;AAAA,OACb,2BAA2B;AAElB,gBAAA,QAAQ,QAAQ,IAAI,OAAO;AAEvC,WAAO,MAAM;;AACX,wBAAY,YAAZ,mBAAqB;AAAA,IACvB;AAAA,EAAA,GACC,CAAC,UAAU,6BAA6B,QAAQ,UAAU,GAAG,CAAC;AAEjE,SAAO,YAAY;AACrB;AAeO,SAAS,gBAAmB,KAA6B;AACxD,QAAA,WAAW,MAAM,OAAU,IAAI;AACrC,QAAM,oBAAoB,KAAK,MAAM,SAAS,SAAU,CAAA,CAAE;AACnD,SAAA;AACT;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
|
-
"version": "1.111.
|
|
3
|
+
"version": "1.111.6",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"tiny-invariant": "^1.3.3",
|
|
55
55
|
"tiny-warning": "^1.0.3",
|
|
56
56
|
"@tanstack/history": "1.99.13",
|
|
57
|
-
"@tanstack/router-core": "^1.111.
|
|
57
|
+
"@tanstack/router-core": "^1.111.6"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@testing-library/jest-dom": "^6.6.3",
|
package/src/fileRoute.ts
CHANGED
|
@@ -22,9 +22,12 @@ import type {
|
|
|
22
22
|
import type { RegisteredRouter } from './router'
|
|
23
23
|
import type {
|
|
24
24
|
AnyContext,
|
|
25
|
+
AnyRoute as AnyCoreRoute,
|
|
25
26
|
AnyPathParams,
|
|
27
|
+
AnyRouter,
|
|
26
28
|
AnyValidator,
|
|
27
29
|
Constrain,
|
|
30
|
+
ConstrainLiteral,
|
|
28
31
|
FileRoutesByPath,
|
|
29
32
|
ResolveParams,
|
|
30
33
|
RouteById,
|
|
@@ -175,7 +178,7 @@ export type LazyRouteOptions = Pick<
|
|
|
175
178
|
'component' | 'errorComponent' | 'pendingComponent' | 'notFoundComponent'
|
|
176
179
|
>
|
|
177
180
|
|
|
178
|
-
export class LazyRoute<TRoute extends
|
|
181
|
+
export class LazyRoute<TRoute extends AnyCoreRoute> {
|
|
179
182
|
options: {
|
|
180
183
|
id: string
|
|
181
184
|
} & LazyRouteOptions
|
|
@@ -236,11 +239,15 @@ export class LazyRoute<TRoute extends AnyRoute> {
|
|
|
236
239
|
}
|
|
237
240
|
|
|
238
241
|
export function createLazyRoute<
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
243
|
+
TId extends string = string,
|
|
244
|
+
TRoute extends AnyCoreRoute = RouteById<TRouter['routeTree'], TId>,
|
|
245
|
+
>(id: ConstrainLiteral<TId, RouteIds<TRouter['routeTree']>>) {
|
|
242
246
|
return (opts: LazyRouteOptions) => {
|
|
243
|
-
return new LazyRoute<TRoute>({
|
|
247
|
+
return new LazyRoute<TRoute>({
|
|
248
|
+
id: id,
|
|
249
|
+
...opts,
|
|
250
|
+
})
|
|
244
251
|
}
|
|
245
252
|
}
|
|
246
253
|
|
package/src/index.tsx
CHANGED
|
@@ -195,6 +195,10 @@ export type {
|
|
|
195
195
|
AnyRouterWithContext,
|
|
196
196
|
CommitLocationOptions,
|
|
197
197
|
MatchLocation,
|
|
198
|
+
UseNavigateResult,
|
|
199
|
+
AnyRedirect,
|
|
200
|
+
Redirect,
|
|
201
|
+
ResolvedRedirect,
|
|
198
202
|
} from '@tanstack/router-core'
|
|
199
203
|
export type {
|
|
200
204
|
UseLinkPropsOptions,
|
|
@@ -232,7 +236,6 @@ export { useLoaderDeps } from './useLoaderDeps'
|
|
|
232
236
|
export { useLoaderData } from './useLoaderData'
|
|
233
237
|
|
|
234
238
|
export { redirect, isRedirect } from './redirects'
|
|
235
|
-
export type { AnyRedirect, Redirect, ResolvedRedirect } from './redirects'
|
|
236
239
|
|
|
237
240
|
export {
|
|
238
241
|
RouteApi,
|
|
@@ -310,7 +313,6 @@ export type { UseBlockerOpts, ShouldBlockFn } from './useBlocker'
|
|
|
310
313
|
export { useBlocker, Block } from './useBlocker'
|
|
311
314
|
|
|
312
315
|
export { useNavigate, Navigate } from './useNavigate'
|
|
313
|
-
export type { UseNavigateResult } from './useNavigate'
|
|
314
316
|
|
|
315
317
|
export { useParams } from './useParams'
|
|
316
318
|
export { useSearch } from './useSearch'
|
package/src/redirects.ts
CHANGED
|
@@ -1,41 +1,9 @@
|
|
|
1
|
-
import type { AnyRouter, RegisteredRouter } from './router'
|
|
2
1
|
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
AnyRedirect,
|
|
3
|
+
Redirect,
|
|
4
|
+
ResolvedRedirect,
|
|
6
5
|
} from '@tanstack/router-core'
|
|
7
|
-
|
|
8
|
-
export type AnyRedirect = Redirect<any, any, any, any, any>
|
|
9
|
-
|
|
10
|
-
export type Redirect<
|
|
11
|
-
TRouter extends AnyRouter = RegisteredRouter,
|
|
12
|
-
TFrom extends RoutePaths<TRouter['routeTree']> | string = '/',
|
|
13
|
-
TTo extends string | undefined = '.',
|
|
14
|
-
TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,
|
|
15
|
-
TMaskTo extends string = '.',
|
|
16
|
-
> = {
|
|
17
|
-
href?: string
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated Use `statusCode` instead
|
|
20
|
-
**/
|
|
21
|
-
code?: number
|
|
22
|
-
statusCode?: number
|
|
23
|
-
throw?: any
|
|
24
|
-
headers?: HeadersInit
|
|
25
|
-
} & NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>
|
|
26
|
-
|
|
27
|
-
export type ResolvedRedirect<
|
|
28
|
-
TRouter extends AnyRouter = RegisteredRouter,
|
|
29
|
-
TFrom extends RoutePaths<TRouter['routeTree']> = '/',
|
|
30
|
-
TTo extends string = '',
|
|
31
|
-
TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom,
|
|
32
|
-
TMaskTo extends string = '',
|
|
33
|
-
> = PickAsRequired<
|
|
34
|
-
Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,
|
|
35
|
-
'code' | 'statusCode' | 'headers'
|
|
36
|
-
> & {
|
|
37
|
-
href: string
|
|
38
|
-
}
|
|
6
|
+
import type { RegisteredRouter } from './router'
|
|
39
7
|
|
|
40
8
|
export function redirect<
|
|
41
9
|
TRouter extends RegisteredRouter,
|
package/src/route.ts
CHANGED
|
@@ -51,6 +51,7 @@ import type {
|
|
|
51
51
|
ToMaskOptions,
|
|
52
52
|
TrimPathRight,
|
|
53
53
|
UpdatableStaticRouteOption,
|
|
54
|
+
UseNavigateResult,
|
|
54
55
|
} from '@tanstack/router-core'
|
|
55
56
|
import type { UseLoaderDataRoute } from './useLoaderData'
|
|
56
57
|
import type { UseMatchRoute } from './useMatch'
|
|
@@ -58,7 +59,6 @@ import type { UseLoaderDepsRoute } from './useLoaderDeps'
|
|
|
58
59
|
import type { UseParamsRoute } from './useParams'
|
|
59
60
|
import type { UseSearchRoute } from './useSearch'
|
|
60
61
|
import type * as React from 'react'
|
|
61
|
-
import type { UseNavigateResult } from './useNavigate'
|
|
62
62
|
import type {
|
|
63
63
|
AnyRouteMatch,
|
|
64
64
|
MakeRouteMatchFromRoute,
|
|
@@ -68,7 +68,6 @@ import type {
|
|
|
68
68
|
import type { AnyRouter, RegisteredRouter, Router } from './router'
|
|
69
69
|
import type { NotFoundError } from './not-found'
|
|
70
70
|
import type { LazyRoute } from './fileRoute'
|
|
71
|
-
|
|
72
71
|
import type { UseRouteContextRoute } from './useRouteContext'
|
|
73
72
|
|
|
74
73
|
export type RouteOptions<
|
package/src/router.ts
CHANGED
|
@@ -41,6 +41,7 @@ import type { NoInfer } from '@tanstack/react-store'
|
|
|
41
41
|
|
|
42
42
|
import type {
|
|
43
43
|
AnyContext,
|
|
44
|
+
AnyRedirect,
|
|
44
45
|
AnySchema,
|
|
45
46
|
AnyValidator,
|
|
46
47
|
BuildLocationFn,
|
|
@@ -56,6 +57,7 @@ import type {
|
|
|
56
57
|
PickAsRequired,
|
|
57
58
|
Register,
|
|
58
59
|
ResolveRelativePath,
|
|
60
|
+
ResolvedRedirect,
|
|
59
61
|
RouteById,
|
|
60
62
|
RoutePaths,
|
|
61
63
|
RoutesById,
|
|
@@ -88,7 +90,6 @@ import type {
|
|
|
88
90
|
MatchRouteOptions,
|
|
89
91
|
} from './Matches'
|
|
90
92
|
|
|
91
|
-
import type { AnyRedirect, ResolvedRedirect } from './redirects'
|
|
92
93
|
import type { NotFoundError } from './not-found'
|
|
93
94
|
|
|
94
95
|
declare global {
|
package/src/typePrimitives.ts
CHANGED
|
@@ -4,15 +4,18 @@ import type {
|
|
|
4
4
|
FromPathOption,
|
|
5
5
|
NavigateOptions,
|
|
6
6
|
PathParamOptions,
|
|
7
|
+
Redirect,
|
|
7
8
|
RouteIds,
|
|
8
9
|
SearchParamOptions,
|
|
9
10
|
ToPathOption,
|
|
11
|
+
UseParamsResult,
|
|
12
|
+
UseSearchResult,
|
|
10
13
|
} from '@tanstack/router-core'
|
|
11
14
|
import type { LinkComponentProps } from './link'
|
|
12
|
-
import type { Redirect } from './redirects'
|
|
13
15
|
import type { AnyRouter, RegisteredRouter } from './router'
|
|
14
|
-
|
|
15
|
-
import type {
|
|
16
|
+
|
|
17
|
+
import type { UseParamsOptions } from './useParams'
|
|
18
|
+
import type { UseSearchOptions } from './useSearch'
|
|
16
19
|
|
|
17
20
|
export type ValidateFromPath<
|
|
18
21
|
TRouter extends AnyRouter = RegisteredRouter,
|
package/src/useLoaderData.tsx
CHANGED
|
@@ -4,8 +4,11 @@ import type {
|
|
|
4
4
|
ValidateSelected,
|
|
5
5
|
} from './structuralSharing'
|
|
6
6
|
import type { AnyRouter, RegisteredRouter } from './router'
|
|
7
|
-
import type {
|
|
8
|
-
|
|
7
|
+
import type {
|
|
8
|
+
ResolveUseLoaderData,
|
|
9
|
+
StrictOrFrom,
|
|
10
|
+
UseLoaderDataResult,
|
|
11
|
+
} from '@tanstack/router-core'
|
|
9
12
|
|
|
10
13
|
export interface UseLoaderDataBaseOptions<
|
|
11
14
|
TRouter extends AnyRouter,
|
|
@@ -15,7 +18,7 @@ export interface UseLoaderDataBaseOptions<
|
|
|
15
18
|
TStructuralSharing,
|
|
16
19
|
> {
|
|
17
20
|
select?: (
|
|
18
|
-
match:
|
|
21
|
+
match: ResolveUseLoaderData<TRouter, TFrom, TStrict>,
|
|
19
22
|
) => ValidateSelected<TRouter, TSelected, TStructuralSharing>
|
|
20
23
|
}
|
|
21
24
|
|
|
@@ -35,23 +38,6 @@ export type UseLoaderDataOptions<
|
|
|
35
38
|
> &
|
|
36
39
|
StructuralSharingOption<TRouter, TSelected, TStructuralSharing>
|
|
37
40
|
|
|
38
|
-
export type ResolveLoaderData<
|
|
39
|
-
TRouter extends AnyRouter,
|
|
40
|
-
TFrom,
|
|
41
|
-
TStrict extends boolean,
|
|
42
|
-
> = TStrict extends false
|
|
43
|
-
? AllLoaderData<TRouter['routeTree']>
|
|
44
|
-
: Expand<RouteById<TRouter['routeTree'], TFrom>['types']['loaderData']>
|
|
45
|
-
|
|
46
|
-
export type UseLoaderDataResult<
|
|
47
|
-
TRouter extends AnyRouter,
|
|
48
|
-
TFrom,
|
|
49
|
-
TStrict extends boolean,
|
|
50
|
-
TSelected,
|
|
51
|
-
> = unknown extends TSelected
|
|
52
|
-
? ResolveLoaderData<TRouter, TFrom, TStrict>
|
|
53
|
-
: TSelected
|
|
54
|
-
|
|
55
41
|
export type UseLoaderDataRoute<out TId> = <
|
|
56
42
|
TRouter extends AnyRouter = RegisteredRouter,
|
|
57
43
|
TSelected = unknown,
|
package/src/useLoaderDeps.tsx
CHANGED
|
@@ -4,8 +4,11 @@ import type {
|
|
|
4
4
|
ValidateSelected,
|
|
5
5
|
} from './structuralSharing'
|
|
6
6
|
import type { AnyRouter, RegisteredRouter } from './router'
|
|
7
|
-
import type {
|
|
8
|
-
|
|
7
|
+
import type {
|
|
8
|
+
ResolveUseLoaderDeps,
|
|
9
|
+
StrictOrFrom,
|
|
10
|
+
UseLoaderDepsResult,
|
|
11
|
+
} from '@tanstack/router-core'
|
|
9
12
|
|
|
10
13
|
export interface UseLoaderDepsBaseOptions<
|
|
11
14
|
TRouter extends AnyRouter,
|
|
@@ -14,7 +17,7 @@ export interface UseLoaderDepsBaseOptions<
|
|
|
14
17
|
TStructuralSharing,
|
|
15
18
|
> {
|
|
16
19
|
select?: (
|
|
17
|
-
deps:
|
|
20
|
+
deps: ResolveUseLoaderDeps<TRouter, TFrom>,
|
|
18
21
|
) => ValidateSelected<TRouter, TSelected, TStructuralSharing>
|
|
19
22
|
}
|
|
20
23
|
|
|
@@ -27,16 +30,6 @@ export type UseLoaderDepsOptions<
|
|
|
27
30
|
UseLoaderDepsBaseOptions<TRouter, TFrom, TSelected, TStructuralSharing> &
|
|
28
31
|
StructuralSharingOption<TRouter, TSelected, TStructuralSharing>
|
|
29
32
|
|
|
30
|
-
export type ResolveLoaderDeps<TRouter extends AnyRouter, TFrom> = Expand<
|
|
31
|
-
RouteById<TRouter['routeTree'], TFrom>['types']['loaderDeps']
|
|
32
|
-
>
|
|
33
|
-
|
|
34
|
-
export type UseLoaderDepsResult<
|
|
35
|
-
TRouter extends AnyRouter,
|
|
36
|
-
TFrom,
|
|
37
|
-
TSelected,
|
|
38
|
-
> = unknown extends TSelected ? ResolveLoaderDeps<TRouter, TFrom> : TSelected
|
|
39
|
-
|
|
40
33
|
export type UseLoaderDepsRoute<out TId> = <
|
|
41
34
|
TRouter extends AnyRouter = RegisteredRouter,
|
|
42
35
|
TSelected = unknown,
|
package/src/useMatch.tsx
CHANGED
|
@@ -8,8 +8,7 @@ import type {
|
|
|
8
8
|
} from './structuralSharing'
|
|
9
9
|
import type { AnyRouter, RegisteredRouter } from './router'
|
|
10
10
|
import type { MakeRouteMatch, MakeRouteMatchUnion } from './Matches'
|
|
11
|
-
import type { StrictOrFrom } from '
|
|
12
|
-
import type { ThrowOrOptional } from '@tanstack/router-core'
|
|
11
|
+
import type { StrictOrFrom, ThrowOrOptional } from '@tanstack/router-core'
|
|
13
12
|
|
|
14
13
|
export interface UseMatchBaseOptions<
|
|
15
14
|
TRouter extends AnyRouter,
|
package/src/useNavigate.tsx
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import { useRouter } from './useRouter'
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
FromPathOption,
|
|
5
|
+
NavigateOptions,
|
|
6
|
+
UseNavigateResult,
|
|
7
|
+
} from '@tanstack/router-core'
|
|
4
8
|
import type { AnyRouter, RegisteredRouter } from './router'
|
|
5
9
|
|
|
6
|
-
export type UseNavigateResult<TDefaultFrom extends string> = <
|
|
7
|
-
TRouter extends RegisteredRouter,
|
|
8
|
-
TTo extends string | undefined,
|
|
9
|
-
TFrom extends string = TDefaultFrom,
|
|
10
|
-
TMaskFrom extends string = TFrom,
|
|
11
|
-
TMaskTo extends string = '',
|
|
12
|
-
>({
|
|
13
|
-
from,
|
|
14
|
-
...rest
|
|
15
|
-
}: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<void>
|
|
16
|
-
|
|
17
10
|
export function useNavigate<
|
|
18
11
|
TRouter extends AnyRouter = RegisteredRouter,
|
|
19
12
|
TDefaultFrom extends string = string,
|