@tanstack/react-router 1.109.2 → 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/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +1 -3
- package/dist/cjs/RouterProvider.cjs.map +1 -1
- package/dist/cjs/RouterProvider.d.cts +0 -25
- package/dist/cjs/fileRoute.cjs +4 -1
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +5 -17
- package/dist/cjs/index.d.cts +7 -9
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +1 -73
- package/dist/cjs/not-found.cjs.map +1 -1
- package/dist/cjs/not-found.d.cts +1 -1
- package/dist/cjs/redirects.cjs.map +1 -1
- package/dist/cjs/redirects.d.cts +2 -18
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +10 -57
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +2 -9
- package/dist/cjs/typePrimitives.d.cts +4 -6
- package/dist/cjs/useBlocker.cjs.map +1 -1
- package/dist/cjs/useBlocker.d.cts +1 -1
- package/dist/cjs/useLoaderData.cjs.map +1 -1
- package/dist/cjs/useLoaderData.d.cts +2 -6
- package/dist/cjs/useLoaderDeps.cjs.map +1 -1
- package/dist/cjs/useLoaderDeps.d.cts +2 -6
- 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 -6
- package/dist/cjs/useRouteContext.cjs.map +1 -1
- package/dist/cjs/useRouteContext.d.cts +1 -9
- package/dist/cjs/useSearch.cjs.map +1 -1
- package/dist/cjs/useSearch.d.cts +2 -6
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +1 -11
- package/dist/esm/Matches.d.ts +1 -3
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/RouterProvider.d.ts +0 -25
- package/dist/esm/RouterProvider.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +5 -17
- package/dist/esm/fileRoute.js +4 -1
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/index.d.ts +7 -9
- package/dist/esm/link.d.ts +1 -73
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/not-found.d.ts +1 -1
- package/dist/esm/not-found.js.map +1 -1
- package/dist/esm/redirects.d.ts +2 -18
- package/dist/esm/redirects.js.map +1 -1
- package/dist/esm/route.d.ts +10 -57
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.d.ts +2 -9
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/typePrimitives.d.ts +4 -6
- package/dist/esm/useBlocker.d.ts +1 -1
- package/dist/esm/useBlocker.js.map +1 -1
- package/dist/esm/useLoaderData.d.ts +2 -6
- package/dist/esm/useLoaderData.js.map +1 -1
- package/dist/esm/useLoaderDeps.d.ts +2 -6
- 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 -6
- package/dist/esm/useParams.js.map +1 -1
- package/dist/esm/useRouteContext.d.ts +1 -9
- package/dist/esm/useRouteContext.js.map +1 -1
- package/dist/esm/useSearch.d.ts +2 -6
- package/dist/esm/useSearch.js.map +1 -1
- package/dist/esm/utils.d.ts +1 -11
- package/dist/esm/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/Matches.tsx +11 -15
- package/src/RouterProvider.tsx +0 -48
- package/src/fileRoute.ts +22 -43
- package/src/index.tsx +30 -43
- package/src/link.tsx +4 -427
- package/src/not-found.tsx +1 -1
- package/src/redirects.ts +6 -36
- package/src/route.ts +103 -167
- package/src/router.ts +13 -25
- package/src/typePrimitives.ts +11 -7
- package/src/useBlocker.tsx +1 -1
- package/src/useLoaderData.tsx +6 -21
- package/src/useLoaderDeps.tsx +6 -14
- package/src/useMatch.tsx +1 -2
- package/src/useNavigate.tsx +5 -12
- package/src/useParams.tsx +7 -21
- package/src/useRouteContext.ts +5 -37
- package/src/useSearch.tsx +7 -21
- package/src/utils.ts +0 -17
- package/dist/cjs/routeInfo.d.cts +0 -53
- package/dist/esm/routeInfo.d.ts +0 -53
- package/src/routeInfo.ts +0 -239
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { RouteIds } from './routeInfo.js';
|
|
1
|
+
import { Constrain, ConstrainLiteral, FromPathOption, NavigateOptions, PathParamOptions, Redirect, RouteIds, SearchParamOptions, ToPathOption, UseParamsResult, UseSearchResult } from '@tanstack/router-core';
|
|
2
|
+
import { LinkComponentProps } from './link.js';
|
|
4
3
|
import { AnyRouter, RegisteredRouter } from './router.js';
|
|
5
|
-
import { UseParamsOptions
|
|
6
|
-
import { UseSearchOptions
|
|
7
|
-
import { Constrain, ConstrainLiteral } from '@tanstack/router-core';
|
|
4
|
+
import { UseParamsOptions } from './useParams.js';
|
|
5
|
+
import { UseSearchOptions } from './useSearch.js';
|
|
8
6
|
export type ValidateFromPath<TRouter extends AnyRouter = RegisteredRouter, TFrom = string> = FromPathOption<TRouter, TFrom>;
|
|
9
7
|
export type ValidateToPath<TRouter extends AnyRouter = RegisteredRouter, TTo extends string | undefined = undefined, TFrom extends string = string> = ToPathOption<TRouter, TFrom, TTo>;
|
|
10
8
|
export type ValidateSearch<TRouter extends AnyRouter = RegisteredRouter, TTo extends string | undefined = undefined, TFrom extends string = string> = SearchParamOptions<TRouter, TFrom, TTo>;
|
package/dist/esm/useBlocker.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HistoryAction } from '@tanstack/history';
|
|
2
2
|
import { AnyRoute } from './route.js';
|
|
3
|
-
import { ParseRoute } from '
|
|
3
|
+
import { ParseRoute } from '@tanstack/router-core';
|
|
4
4
|
import { AnyRouter, RegisteredRouter } from './router.js';
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
interface ShouldBlockFnLocation<out TRouteId, out TFullPath, out TAllParams, out TFullSearchSchema> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBlocker.js","sources":["../../src/useBlocker.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useRouter } from './useRouter'\nimport type {\n BlockerFnArgs,\n HistoryAction,\n HistoryLocation,\n} from '@tanstack/history'\nimport type { AnyRoute } from './route'\nimport type { ParseRoute } from './routeInfo'\nimport type { AnyRouter, RegisteredRouter } from './router'\n\ninterface ShouldBlockFnLocation<\n out TRouteId,\n out TFullPath,\n out TAllParams,\n out TFullSearchSchema,\n> {\n routeId: TRouteId\n fullPath: TFullPath\n pathname: string\n params: TAllParams\n search: TFullSearchSchema\n}\n\ntype AnyShouldBlockFnLocation = ShouldBlockFnLocation<any, any, any, any>\ntype MakeShouldBlockFnLocationUnion<\n TRouter extends AnyRouter = RegisteredRouter,\n TRoute extends AnyRoute = ParseRoute<TRouter['routeTree']>,\n> = TRoute extends any\n ? ShouldBlockFnLocation<\n TRoute['id'],\n TRoute['fullPath'],\n TRoute['types']['allParams'],\n TRoute['types']['fullSearchSchema']\n >\n : never\n\ntype BlockerResolver<TRouter extends AnyRouter = RegisteredRouter> =\n | {\n status: 'blocked'\n current: MakeShouldBlockFnLocationUnion<TRouter>\n next: MakeShouldBlockFnLocationUnion<TRouter>\n action: HistoryAction\n proceed: () => void\n reset: () => void\n }\n | {\n status: 'idle'\n current: undefined\n next: undefined\n action: undefined\n proceed: undefined\n reset: undefined\n }\n\ntype ShouldBlockFnArgs<TRouter extends AnyRouter = RegisteredRouter> = {\n current: MakeShouldBlockFnLocationUnion<TRouter>\n next: MakeShouldBlockFnLocationUnion<TRouter>\n action: HistoryAction\n}\n\nexport type ShouldBlockFn<TRouter extends AnyRouter = RegisteredRouter> = (\n args: ShouldBlockFnArgs<TRouter>,\n) => boolean | Promise<boolean>\nexport type UseBlockerOpts<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = boolean,\n> = {\n shouldBlockFn: ShouldBlockFn<TRouter>\n enableBeforeUnload?: boolean | (() => boolean)\n disabled?: boolean\n withResolver?: TWithResolver\n}\n\ntype LegacyBlockerFn = () => Promise<any> | any\ntype LegacyBlockerOpts = {\n blockerFn?: LegacyBlockerFn\n condition?: boolean | any\n}\n\nfunction _resolveBlockerOpts(\n opts?: UseBlockerOpts | LegacyBlockerOpts | LegacyBlockerFn,\n condition?: boolean | any,\n): UseBlockerOpts {\n if (opts === undefined) {\n return {\n shouldBlockFn: () => true,\n withResolver: false,\n }\n }\n\n if ('shouldBlockFn' in opts) {\n return opts\n }\n\n if (typeof opts === 'function') {\n const shouldBlock = Boolean(condition ?? true)\n\n const _customBlockerFn = async () => {\n if (shouldBlock) return await opts()\n return false\n }\n\n return {\n shouldBlockFn: _customBlockerFn,\n enableBeforeUnload: shouldBlock,\n withResolver: false,\n }\n }\n\n const shouldBlock = Boolean(opts.condition ?? true)\n const fn = opts.blockerFn\n\n const _customBlockerFn = async () => {\n if (shouldBlock && fn !== undefined) {\n return await fn()\n }\n return shouldBlock\n }\n\n return {\n shouldBlockFn: _customBlockerFn,\n enableBeforeUnload: shouldBlock,\n withResolver: fn === undefined,\n }\n}\n\nexport function useBlocker<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = false,\n>(\n opts: UseBlockerOpts<TRouter, TWithResolver>,\n): TWithResolver extends true ? BlockerResolver<TRouter> : void\n\n/**\n * @deprecated Use the shouldBlockFn property instead\n */\nexport function useBlocker(blockerFnOrOpts?: LegacyBlockerOpts): BlockerResolver\n\n/**\n * @deprecated Use the UseBlockerOpts object syntax instead\n */\nexport function useBlocker(\n blockerFn?: LegacyBlockerFn,\n condition?: boolean | any,\n): BlockerResolver\n\nexport function useBlocker(\n opts?: UseBlockerOpts | LegacyBlockerOpts | LegacyBlockerFn,\n condition?: boolean | any,\n): BlockerResolver | void {\n const {\n shouldBlockFn,\n enableBeforeUnload = true,\n disabled = false,\n withResolver = false,\n } = _resolveBlockerOpts(opts, condition)\n\n const router = useRouter()\n const { history } = router\n\n const [resolver, setResolver] = React.useState<BlockerResolver>({\n status: 'idle',\n current: undefined,\n next: undefined,\n action: undefined,\n proceed: undefined,\n reset: undefined,\n })\n\n React.useEffect(() => {\n const blockerFnComposed = async (blockerFnArgs: BlockerFnArgs) => {\n function getLocation(\n location: HistoryLocation,\n ): AnyShouldBlockFnLocation {\n const parsedLocation = router.parseLocation(undefined, location)\n const matchedRoutes = router.getMatchedRoutes(parsedLocation)\n if (matchedRoutes.foundRoute === undefined) {\n throw new Error(`No route found for location ${location.href}`)\n }\n return {\n routeId: matchedRoutes.foundRoute.id,\n fullPath: matchedRoutes.foundRoute.fullPath,\n pathname: parsedLocation.pathname,\n params: matchedRoutes.routeParams,\n search: parsedLocation.search,\n }\n }\n\n const current = getLocation(blockerFnArgs.currentLocation)\n const next = getLocation(blockerFnArgs.nextLocation)\n\n const shouldBlock = await shouldBlockFn({\n action: blockerFnArgs.action,\n current,\n next,\n })\n if (!withResolver) {\n return shouldBlock\n }\n\n if (!shouldBlock) {\n return false\n }\n\n const promise = new Promise<boolean>((resolve) => {\n setResolver({\n status: 'blocked',\n current,\n next,\n action: blockerFnArgs.action,\n proceed: () => resolve(false),\n reset: () => resolve(true),\n })\n })\n\n const canNavigateAsync = await promise\n setResolver({\n status: 'idle',\n current: undefined,\n next: undefined,\n action: undefined,\n proceed: undefined,\n reset: undefined,\n })\n\n return canNavigateAsync\n }\n\n return disabled\n ? undefined\n : history.block({ blockerFn: blockerFnComposed, enableBeforeUnload })\n }, [\n shouldBlockFn,\n enableBeforeUnload,\n disabled,\n withResolver,\n history,\n router,\n ])\n\n return resolver\n}\n\nconst _resolvePromptBlockerArgs = (\n props: PromptProps | LegacyPromptProps,\n): UseBlockerOpts => {\n if ('shouldBlockFn' in props) {\n return { ...props }\n }\n\n const shouldBlock = Boolean(props.condition ?? true)\n const fn = props.blockerFn\n\n const _customBlockerFn = async () => {\n if (shouldBlock && fn !== undefined) {\n return await fn()\n }\n return shouldBlock\n }\n\n return {\n shouldBlockFn: _customBlockerFn,\n enableBeforeUnload: shouldBlock,\n withResolver: fn === undefined,\n }\n}\n\nexport function Block<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = boolean,\n>(opts: PromptProps<TRouter, TWithResolver>): React.ReactNode\n\n/**\n * @deprecated Use the UseBlockerOpts property instead\n */\nexport function Block(opts: LegacyPromptProps): React.ReactNode\n\nexport function Block(opts: PromptProps | LegacyPromptProps): React.ReactNode {\n const { children, ...rest } = opts\n const args = _resolvePromptBlockerArgs(rest)\n\n const resolver = useBlocker(args)\n return children\n ? typeof children === 'function'\n ? children(resolver as any)\n : children\n : null\n}\n\ntype LegacyPromptProps = {\n blockerFn?: LegacyBlockerFn\n condition?: boolean | any\n children?: React.ReactNode | ((params: BlockerResolver) => React.ReactNode)\n}\n\ntype PromptProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = boolean,\n TParams = TWithResolver extends true ? BlockerResolver<TRouter> : void,\n> = UseBlockerOpts<TRouter, TWithResolver> & {\n children?: React.ReactNode | ((params: TParams) => React.ReactNode)\n}\n"],"names":["shouldBlock","_customBlockerFn"],"mappings":";;AAgFA,SAAS,oBACP,MACA,WACgB;AAChB,MAAI,SAAS,QAAW;AACf,WAAA;AAAA,MACL,eAAe,MAAM;AAAA,MACrB,cAAc;AAAA,IAChB;AAAA,EAAA;AAGF,MAAI,mBAAmB,MAAM;AACpB,WAAA;AAAA,EAAA;AAGL,MAAA,OAAO,SAAS,YAAY;AACxBA,UAAAA,eAAc,QAAQ,aAAa,IAAI;AAE7C,UAAMC,oBAAmB,YAAY;AAC/BD,UAAAA,aAAoB,QAAA,MAAM,KAAK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AM,EAAE,UAAU,GAAG,KAAA,IAAS;AACxB,QAAA,OAAO,0BAA0B,IAAI;AAErC,QAAA,WAAW,WAAW,IAAI;AAChC,SAAO,WACH,OAAO,aAAa,aAClB,SAAS,QAAe,IACxB,WACF;AACN;"}
|
|
1
|
+
{"version":3,"file":"useBlocker.js","sources":["../../src/useBlocker.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useRouter } from './useRouter'\nimport type {\n BlockerFnArgs,\n HistoryAction,\n HistoryLocation,\n} from '@tanstack/history'\nimport type { AnyRoute } from './route'\nimport type { ParseRoute } from '@tanstack/router-core'\nimport type { AnyRouter, RegisteredRouter } from './router'\n\ninterface ShouldBlockFnLocation<\n out TRouteId,\n out TFullPath,\n out TAllParams,\n out TFullSearchSchema,\n> {\n routeId: TRouteId\n fullPath: TFullPath\n pathname: string\n params: TAllParams\n search: TFullSearchSchema\n}\n\ntype AnyShouldBlockFnLocation = ShouldBlockFnLocation<any, any, any, any>\ntype MakeShouldBlockFnLocationUnion<\n TRouter extends AnyRouter = RegisteredRouter,\n TRoute extends AnyRoute = ParseRoute<TRouter['routeTree']>,\n> = TRoute extends any\n ? ShouldBlockFnLocation<\n TRoute['id'],\n TRoute['fullPath'],\n TRoute['types']['allParams'],\n TRoute['types']['fullSearchSchema']\n >\n : never\n\ntype BlockerResolver<TRouter extends AnyRouter = RegisteredRouter> =\n | {\n status: 'blocked'\n current: MakeShouldBlockFnLocationUnion<TRouter>\n next: MakeShouldBlockFnLocationUnion<TRouter>\n action: HistoryAction\n proceed: () => void\n reset: () => void\n }\n | {\n status: 'idle'\n current: undefined\n next: undefined\n action: undefined\n proceed: undefined\n reset: undefined\n }\n\ntype ShouldBlockFnArgs<TRouter extends AnyRouter = RegisteredRouter> = {\n current: MakeShouldBlockFnLocationUnion<TRouter>\n next: MakeShouldBlockFnLocationUnion<TRouter>\n action: HistoryAction\n}\n\nexport type ShouldBlockFn<TRouter extends AnyRouter = RegisteredRouter> = (\n args: ShouldBlockFnArgs<TRouter>,\n) => boolean | Promise<boolean>\nexport type UseBlockerOpts<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = boolean,\n> = {\n shouldBlockFn: ShouldBlockFn<TRouter>\n enableBeforeUnload?: boolean | (() => boolean)\n disabled?: boolean\n withResolver?: TWithResolver\n}\n\ntype LegacyBlockerFn = () => Promise<any> | any\ntype LegacyBlockerOpts = {\n blockerFn?: LegacyBlockerFn\n condition?: boolean | any\n}\n\nfunction _resolveBlockerOpts(\n opts?: UseBlockerOpts | LegacyBlockerOpts | LegacyBlockerFn,\n condition?: boolean | any,\n): UseBlockerOpts {\n if (opts === undefined) {\n return {\n shouldBlockFn: () => true,\n withResolver: false,\n }\n }\n\n if ('shouldBlockFn' in opts) {\n return opts\n }\n\n if (typeof opts === 'function') {\n const shouldBlock = Boolean(condition ?? true)\n\n const _customBlockerFn = async () => {\n if (shouldBlock) return await opts()\n return false\n }\n\n return {\n shouldBlockFn: _customBlockerFn,\n enableBeforeUnload: shouldBlock,\n withResolver: false,\n }\n }\n\n const shouldBlock = Boolean(opts.condition ?? true)\n const fn = opts.blockerFn\n\n const _customBlockerFn = async () => {\n if (shouldBlock && fn !== undefined) {\n return await fn()\n }\n return shouldBlock\n }\n\n return {\n shouldBlockFn: _customBlockerFn,\n enableBeforeUnload: shouldBlock,\n withResolver: fn === undefined,\n }\n}\n\nexport function useBlocker<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = false,\n>(\n opts: UseBlockerOpts<TRouter, TWithResolver>,\n): TWithResolver extends true ? BlockerResolver<TRouter> : void\n\n/**\n * @deprecated Use the shouldBlockFn property instead\n */\nexport function useBlocker(blockerFnOrOpts?: LegacyBlockerOpts): BlockerResolver\n\n/**\n * @deprecated Use the UseBlockerOpts object syntax instead\n */\nexport function useBlocker(\n blockerFn?: LegacyBlockerFn,\n condition?: boolean | any,\n): BlockerResolver\n\nexport function useBlocker(\n opts?: UseBlockerOpts | LegacyBlockerOpts | LegacyBlockerFn,\n condition?: boolean | any,\n): BlockerResolver | void {\n const {\n shouldBlockFn,\n enableBeforeUnload = true,\n disabled = false,\n withResolver = false,\n } = _resolveBlockerOpts(opts, condition)\n\n const router = useRouter()\n const { history } = router\n\n const [resolver, setResolver] = React.useState<BlockerResolver>({\n status: 'idle',\n current: undefined,\n next: undefined,\n action: undefined,\n proceed: undefined,\n reset: undefined,\n })\n\n React.useEffect(() => {\n const blockerFnComposed = async (blockerFnArgs: BlockerFnArgs) => {\n function getLocation(\n location: HistoryLocation,\n ): AnyShouldBlockFnLocation {\n const parsedLocation = router.parseLocation(undefined, location)\n const matchedRoutes = router.getMatchedRoutes(parsedLocation)\n if (matchedRoutes.foundRoute === undefined) {\n throw new Error(`No route found for location ${location.href}`)\n }\n return {\n routeId: matchedRoutes.foundRoute.id,\n fullPath: matchedRoutes.foundRoute.fullPath,\n pathname: parsedLocation.pathname,\n params: matchedRoutes.routeParams,\n search: parsedLocation.search,\n }\n }\n\n const current = getLocation(blockerFnArgs.currentLocation)\n const next = getLocation(blockerFnArgs.nextLocation)\n\n const shouldBlock = await shouldBlockFn({\n action: blockerFnArgs.action,\n current,\n next,\n })\n if (!withResolver) {\n return shouldBlock\n }\n\n if (!shouldBlock) {\n return false\n }\n\n const promise = new Promise<boolean>((resolve) => {\n setResolver({\n status: 'blocked',\n current,\n next,\n action: blockerFnArgs.action,\n proceed: () => resolve(false),\n reset: () => resolve(true),\n })\n })\n\n const canNavigateAsync = await promise\n setResolver({\n status: 'idle',\n current: undefined,\n next: undefined,\n action: undefined,\n proceed: undefined,\n reset: undefined,\n })\n\n return canNavigateAsync\n }\n\n return disabled\n ? undefined\n : history.block({ blockerFn: blockerFnComposed, enableBeforeUnload })\n }, [\n shouldBlockFn,\n enableBeforeUnload,\n disabled,\n withResolver,\n history,\n router,\n ])\n\n return resolver\n}\n\nconst _resolvePromptBlockerArgs = (\n props: PromptProps | LegacyPromptProps,\n): UseBlockerOpts => {\n if ('shouldBlockFn' in props) {\n return { ...props }\n }\n\n const shouldBlock = Boolean(props.condition ?? true)\n const fn = props.blockerFn\n\n const _customBlockerFn = async () => {\n if (shouldBlock && fn !== undefined) {\n return await fn()\n }\n return shouldBlock\n }\n\n return {\n shouldBlockFn: _customBlockerFn,\n enableBeforeUnload: shouldBlock,\n withResolver: fn === undefined,\n }\n}\n\nexport function Block<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = boolean,\n>(opts: PromptProps<TRouter, TWithResolver>): React.ReactNode\n\n/**\n * @deprecated Use the UseBlockerOpts property instead\n */\nexport function Block(opts: LegacyPromptProps): React.ReactNode\n\nexport function Block(opts: PromptProps | LegacyPromptProps): React.ReactNode {\n const { children, ...rest } = opts\n const args = _resolvePromptBlockerArgs(rest)\n\n const resolver = useBlocker(args)\n return children\n ? typeof children === 'function'\n ? children(resolver as any)\n : children\n : null\n}\n\ntype LegacyPromptProps = {\n blockerFn?: LegacyBlockerFn\n condition?: boolean | any\n children?: React.ReactNode | ((params: BlockerResolver) => React.ReactNode)\n}\n\ntype PromptProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = boolean,\n TParams = TWithResolver extends true ? BlockerResolver<TRouter> : void,\n> = UseBlockerOpts<TRouter, TWithResolver> & {\n children?: React.ReactNode | ((params: TParams) => React.ReactNode)\n}\n"],"names":["shouldBlock","_customBlockerFn"],"mappings":";;AAgFA,SAAS,oBACP,MACA,WACgB;AAChB,MAAI,SAAS,QAAW;AACf,WAAA;AAAA,MACL,eAAe,MAAM;AAAA,MACrB,cAAc;AAAA,IAChB;AAAA,EAAA;AAGF,MAAI,mBAAmB,MAAM;AACpB,WAAA;AAAA,EAAA;AAGL,MAAA,OAAO,SAAS,YAAY;AACxBA,UAAAA,eAAc,QAAQ,aAAa,IAAI;AAE7C,UAAMC,oBAAmB,YAAY;AAC/BD,UAAAA,aAAoB,QAAA,MAAM,KAAK;AAC5B,aAAA;AAAA,IACT;AAEO,WAAA;AAAA,MACL,eAAeC;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A0B,IAAI;AAErC,QAAA,WAAW,WAAW,IAAI;AAChC,SAAO,WACH,OAAO,aAAa,aAClB,SAAS,QAAe,IACxB,WACF;AACN;"}
|
|
@@ -1,13 +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';
|
|
5
|
-
import { Expand } from '@tanstack/router-core';
|
|
3
|
+
import { ResolveUseLoaderData, StrictOrFrom, UseLoaderDataResult } from '@tanstack/router-core';
|
|
6
4
|
export interface UseLoaderDataBaseOptions<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TSelected, TStructuralSharing> {
|
|
7
|
-
select?: (match:
|
|
5
|
+
select?: (match: ResolveUseLoaderData<TRouter, TFrom, TStrict>) => ValidateSelected<TRouter, TSelected, TStructuralSharing>;
|
|
8
6
|
}
|
|
9
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>;
|
|
10
|
-
export type ResolveLoaderData<TRouter extends AnyRouter, TFrom, TStrict extends boolean> = TStrict extends false ? AllLoaderData<TRouter['routeTree']> : Expand<RouteById<TRouter['routeTree'], TFrom>['types']['loaderData']>;
|
|
11
|
-
export type UseLoaderDataResult<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TSelected> = unknown extends TSelected ? ResolveLoaderData<TRouter, TFrom, TStrict> : TSelected;
|
|
12
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>;
|
|
13
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,13 +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';
|
|
5
|
-
import { Expand } from '@tanstack/router-core';
|
|
3
|
+
import { ResolveUseLoaderDeps, StrictOrFrom, UseLoaderDepsResult } from '@tanstack/router-core';
|
|
6
4
|
export interface UseLoaderDepsBaseOptions<TRouter extends AnyRouter, TFrom, TSelected, TStructuralSharing> {
|
|
7
|
-
select?: (deps:
|
|
5
|
+
select?: (deps: ResolveUseLoaderDeps<TRouter, TFrom>) => ValidateSelected<TRouter, TSelected, TStructuralSharing>;
|
|
8
6
|
}
|
|
9
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>;
|
|
10
|
-
export type ResolveLoaderDeps<TRouter extends AnyRouter, TFrom> = Expand<RouteById<TRouter['routeTree'], TFrom>['types']['loaderDeps']>;
|
|
11
|
-
export type UseLoaderDepsResult<TRouter extends AnyRouter, TFrom, TSelected> = unknown extends TSelected ? ResolveLoaderDeps<TRouter, TFrom> : TSelected;
|
|
12
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>;
|
|
13
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 '
|
|
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,15 +1,11 @@
|
|
|
1
1
|
import { ThrowConstraint } from './useMatch.js';
|
|
2
2
|
import { StructuralSharingOption, ValidateSelected } from './structuralSharing.js';
|
|
3
|
-
import { AllParams, RouteById } from './routeInfo.js';
|
|
4
3
|
import { AnyRouter, RegisteredRouter } from './router.js';
|
|
5
|
-
import { StrictOrFrom } from '
|
|
6
|
-
import { Expand, ThrowOrOptional } from '@tanstack/router-core';
|
|
4
|
+
import { ResolveUseParams, StrictOrFrom, ThrowOrOptional, UseParamsResult } from '@tanstack/router-core';
|
|
7
5
|
export interface UseParamsBaseOptions<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TThrow extends boolean, TSelected, TStructuralSharing> {
|
|
8
|
-
select?: (params:
|
|
6
|
+
select?: (params: ResolveUseParams<TRouter, TFrom, TStrict>) => ValidateSelected<TRouter, TSelected, TStructuralSharing>;
|
|
9
7
|
shouldThrow?: TThrow;
|
|
10
8
|
}
|
|
11
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>;
|
|
12
|
-
export type ResolveParams<TRouter extends AnyRouter, TFrom, TStrict extends boolean> = TStrict extends false ? AllParams<TRouter['routeTree']> : Expand<RouteById<TRouter['routeTree'], TFrom>['types']['allParams']>;
|
|
13
|
-
export type UseParamsResult<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TSelected> = unknown extends TSelected ? ResolveParams<TRouter, TFrom, TStrict> : TSelected;
|
|
14
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>;
|
|
15
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 {
|
|
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,12 +1,4 @@
|
|
|
1
|
-
import { AllContext, RouteById } from './routeInfo.js';
|
|
2
1
|
import { AnyRouter, RegisteredRouter } from './router.js';
|
|
3
|
-
import {
|
|
4
|
-
import { Expand } from '@tanstack/router-core';
|
|
5
|
-
export interface UseRouteContextBaseOptions<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TSelected> {
|
|
6
|
-
select?: (search: ResolveRouteContext<TRouter, TFrom, TStrict>) => TSelected;
|
|
7
|
-
}
|
|
8
|
-
export type UseRouteContextOptions<TRouter extends AnyRouter, TFrom extends string | undefined, TStrict extends boolean, TSelected> = StrictOrFrom<TRouter, TFrom, TStrict> & UseRouteContextBaseOptions<TRouter, TFrom, TStrict, TSelected>;
|
|
9
|
-
export type ResolveRouteContext<TRouter extends AnyRouter, TFrom, TStrict extends boolean> = TStrict extends false ? AllContext<TRouter['routeTree']> : Expand<RouteById<TRouter['routeTree'], TFrom>['types']['allContext']>;
|
|
10
|
-
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';
|
|
11
3
|
export type UseRouteContextRoute<out TFrom> = <TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown>(opts?: UseRouteContextBaseOptions<TRouter, TFrom, true, TSelected>) => UseRouteContextResult<TRouter, TFrom, true, TSelected>;
|
|
12
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 {
|
|
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,15 +1,11 @@
|
|
|
1
1
|
import { ThrowConstraint } from './useMatch.js';
|
|
2
2
|
import { StructuralSharingOption, ValidateSelected } from './structuralSharing.js';
|
|
3
|
-
import { FullSearchSchema, RouteById } from './routeInfo.js';
|
|
4
3
|
import { AnyRouter, RegisteredRouter } from './router.js';
|
|
5
|
-
import { StrictOrFrom } from '
|
|
6
|
-
import { Expand, ThrowOrOptional } from '@tanstack/router-core';
|
|
4
|
+
import { ResolveUseSearch, StrictOrFrom, ThrowOrOptional, UseSearchResult } from '@tanstack/router-core';
|
|
7
5
|
export interface UseSearchBaseOptions<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TThrow extends boolean, TSelected, TStructuralSharing> {
|
|
8
|
-
select?: (state:
|
|
6
|
+
select?: (state: ResolveUseSearch<TRouter, TFrom, TStrict>) => ValidateSelected<TRouter, TSelected, TStructuralSharing>;
|
|
9
7
|
shouldThrow?: TThrow;
|
|
10
8
|
}
|
|
11
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>;
|
|
12
|
-
export type UseSearchResult<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TSelected> = unknown extends TSelected ? ResolveSearch<TRouter, TFrom, TStrict> : TSelected;
|
|
13
|
-
export type ResolveSearch<TRouter extends AnyRouter, TFrom, TStrict extends boolean> = TStrict extends false ? FullSearchSchema<TRouter['routeTree']> : Expand<RouteById<TRouter['routeTree'], TFrom>['types']['fullSearchSchema']>;
|
|
14
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>;
|
|
15
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 {
|
|
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,16 +1,6 @@
|
|
|
1
|
-
import { RouteIds } from './routeInfo.js';
|
|
2
|
-
import { AnyRouter } from './router.js';
|
|
3
|
-
import { ConstrainLiteral } from '@tanstack/router-core';
|
|
4
1
|
import * as React from 'react';
|
|
5
2
|
export declare function useStableCallback<T extends (...args: Array<any>) => any>(fn: T): T;
|
|
6
|
-
export
|
|
7
|
-
from?: never;
|
|
8
|
-
strict: TStrict;
|
|
9
|
-
} : {
|
|
10
|
-
from: ConstrainLiteral<TFrom, RouteIds<TRouter['routeTree']>>;
|
|
11
|
-
strict?: TStrict;
|
|
12
|
-
};
|
|
13
|
-
export declare const useLayoutEffect: typeof React.useEffect;
|
|
3
|
+
export declare const useLayoutEffect: typeof React.useLayoutEffect;
|
|
14
4
|
/**
|
|
15
5
|
* Taken from https://www.developerway.com/posts/implementing-advanced-use-previous-hook#part3
|
|
16
6
|
*/
|
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":[],"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|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
|
-
"version": "1.
|
|
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.
|
|
57
|
+
"@tanstack/router-core": "^1.111.6"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@testing-library/jest-dom": "^6.6.3",
|
package/src/Matches.tsx
CHANGED
|
@@ -13,30 +13,26 @@ import type {
|
|
|
13
13
|
} from './structuralSharing'
|
|
14
14
|
import type { AnyRoute, ReactNode } from './route'
|
|
15
15
|
import type {
|
|
16
|
+
AllContext,
|
|
17
|
+
AllLoaderData,
|
|
18
|
+
AllParams,
|
|
16
19
|
ControlledPromise,
|
|
17
20
|
DeepPartial,
|
|
18
|
-
|
|
19
|
-
ResolveRelativePath,
|
|
20
|
-
StaticDataRouteOption,
|
|
21
|
-
} from '@tanstack/router-core'
|
|
22
|
-
import type { AnyRouter, RegisteredRouter, RouterState } from './router'
|
|
23
|
-
import type {
|
|
21
|
+
FullSearchSchema,
|
|
24
22
|
MakeOptionalPathParams,
|
|
25
23
|
MakeOptionalSearchParams,
|
|
26
24
|
MaskOptions,
|
|
27
|
-
|
|
28
|
-
ToSubOptionsProps,
|
|
29
|
-
} from './link'
|
|
30
|
-
import type {
|
|
31
|
-
AllContext,
|
|
32
|
-
AllLoaderData,
|
|
33
|
-
AllParams,
|
|
34
|
-
FullSearchSchema,
|
|
25
|
+
NoInfer,
|
|
35
26
|
ParseRoute,
|
|
27
|
+
ResolveRelativePath,
|
|
28
|
+
ResolveRoute,
|
|
36
29
|
RouteById,
|
|
37
30
|
RouteByPath,
|
|
38
31
|
RouteIds,
|
|
39
|
-
|
|
32
|
+
StaticDataRouteOption,
|
|
33
|
+
ToSubOptionsProps,
|
|
34
|
+
} from '@tanstack/router-core'
|
|
35
|
+
import type { AnyRouter, RegisteredRouter, RouterState } from './router'
|
|
40
36
|
|
|
41
37
|
export type MakeRouteMatchFromRoute<TRoute extends AnyRoute> = RouteMatch<
|
|
42
38
|
TRoute['types']['id'],
|
package/src/RouterProvider.tsx
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import { Matches } from './Matches'
|
|
3
3
|
import { getRouterContext } from './routerContext'
|
|
4
|
-
import type { NavigateOptions, ToOptions } from './link'
|
|
5
|
-
import type {
|
|
6
|
-
ParsedLocation,
|
|
7
|
-
ViewTransitionOptions,
|
|
8
|
-
} from '@tanstack/router-core'
|
|
9
|
-
import type { RoutePaths } from './routeInfo'
|
|
10
4
|
import type {
|
|
11
5
|
AnyRouter,
|
|
12
6
|
RegisteredRouter,
|
|
@@ -14,48 +8,6 @@ import type {
|
|
|
14
8
|
RouterOptions,
|
|
15
9
|
} from './router'
|
|
16
10
|
|
|
17
|
-
export interface CommitLocationOptions {
|
|
18
|
-
replace?: boolean
|
|
19
|
-
resetScroll?: boolean
|
|
20
|
-
hashScrollIntoView?: boolean | ScrollIntoViewOptions
|
|
21
|
-
viewTransition?: boolean | ViewTransitionOptions
|
|
22
|
-
/**
|
|
23
|
-
* @deprecated All navigations use React transitions under the hood now
|
|
24
|
-
**/
|
|
25
|
-
startTransition?: boolean
|
|
26
|
-
ignoreBlocker?: boolean
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface MatchLocation {
|
|
30
|
-
to?: string | number | null
|
|
31
|
-
fuzzy?: boolean
|
|
32
|
-
caseSensitive?: boolean
|
|
33
|
-
from?: string
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export type NavigateFn = <
|
|
37
|
-
TRouter extends RegisteredRouter,
|
|
38
|
-
TTo extends string | undefined,
|
|
39
|
-
TFrom extends RoutePaths<TRouter['routeTree']> | string = string,
|
|
40
|
-
TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,
|
|
41
|
-
TMaskTo extends string = '',
|
|
42
|
-
>(
|
|
43
|
-
opts: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,
|
|
44
|
-
) => Promise<void> | void
|
|
45
|
-
|
|
46
|
-
export type BuildLocationFn = <
|
|
47
|
-
TRouter extends RegisteredRouter,
|
|
48
|
-
TTo extends string | undefined,
|
|
49
|
-
TFrom extends RoutePaths<TRouter['routeTree']> | string = string,
|
|
50
|
-
TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,
|
|
51
|
-
TMaskTo extends string = '',
|
|
52
|
-
>(
|
|
53
|
-
opts: ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
|
54
|
-
leaveParams?: boolean
|
|
55
|
-
_includeValidateSearch?: boolean
|
|
56
|
-
},
|
|
57
|
-
) => ParsedLocation
|
|
58
|
-
|
|
59
11
|
export function RouterContextProvider<
|
|
60
12
|
TRouter extends AnyRouter = RegisteredRouter,
|
|
61
13
|
TDehydrated extends Record<string, any> = Record<string, any>,
|
package/src/fileRoute.ts
CHANGED
|
@@ -10,58 +10,33 @@ import { useNavigate } from './useNavigate'
|
|
|
10
10
|
import type { UseParamsRoute } from './useParams'
|
|
11
11
|
import type { UseMatchRoute } from './useMatch'
|
|
12
12
|
import type { UseSearchRoute } from './useSearch'
|
|
13
|
-
import type {
|
|
14
|
-
AnyContext,
|
|
15
|
-
AnyPathParams,
|
|
16
|
-
AnyValidator,
|
|
17
|
-
Constrain,
|
|
18
|
-
ResolveParams,
|
|
19
|
-
} from '@tanstack/router-core'
|
|
20
13
|
|
|
21
14
|
import type {
|
|
22
15
|
AnyRoute,
|
|
23
16
|
FileBaseRouteOptions,
|
|
24
|
-
RootRoute,
|
|
25
17
|
Route,
|
|
26
18
|
RouteConstraints,
|
|
27
19
|
RouteLoaderFn,
|
|
28
20
|
UpdatableRouteOptions,
|
|
29
21
|
} from './route'
|
|
30
22
|
import type { RegisteredRouter } from './router'
|
|
31
|
-
import type {
|
|
23
|
+
import type {
|
|
24
|
+
AnyContext,
|
|
25
|
+
AnyRoute as AnyCoreRoute,
|
|
26
|
+
AnyPathParams,
|
|
27
|
+
AnyRouter,
|
|
28
|
+
AnyValidator,
|
|
29
|
+
Constrain,
|
|
30
|
+
ConstrainLiteral,
|
|
31
|
+
FileRoutesByPath,
|
|
32
|
+
ResolveParams,
|
|
33
|
+
RouteById,
|
|
34
|
+
RouteIds,
|
|
35
|
+
} from '@tanstack/router-core'
|
|
32
36
|
import type { UseLoaderDepsRoute } from './useLoaderDeps'
|
|
33
37
|
import type { UseLoaderDataRoute } from './useLoaderData'
|
|
34
38
|
import type { UseRouteContextRoute } from './useRouteContext'
|
|
35
39
|
|
|
36
|
-
export interface FileRoutesByPath {
|
|
37
|
-
// '/': {
|
|
38
|
-
// parentRoute: typeof rootRoute
|
|
39
|
-
// }
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface FileRouteTypes {
|
|
43
|
-
fileRoutesByFullPath: any
|
|
44
|
-
fullPaths: any
|
|
45
|
-
to: any
|
|
46
|
-
fileRoutesByTo: any
|
|
47
|
-
id: any
|
|
48
|
-
fileRoutesById: any
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export type InferFileRouteTypes<TRouteTree extends AnyRoute> =
|
|
52
|
-
TRouteTree extends RootRoute<
|
|
53
|
-
any,
|
|
54
|
-
any,
|
|
55
|
-
any,
|
|
56
|
-
any,
|
|
57
|
-
any,
|
|
58
|
-
any,
|
|
59
|
-
any,
|
|
60
|
-
infer TFileRouteTypes extends FileRouteTypes
|
|
61
|
-
>
|
|
62
|
-
? TFileRouteTypes
|
|
63
|
-
: never
|
|
64
|
-
|
|
65
40
|
export function createFileRoute<
|
|
66
41
|
TFilePath extends keyof FileRoutesByPath,
|
|
67
42
|
TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],
|
|
@@ -203,7 +178,7 @@ export type LazyRouteOptions = Pick<
|
|
|
203
178
|
'component' | 'errorComponent' | 'pendingComponent' | 'notFoundComponent'
|
|
204
179
|
>
|
|
205
180
|
|
|
206
|
-
export class LazyRoute<TRoute extends
|
|
181
|
+
export class LazyRoute<TRoute extends AnyCoreRoute> {
|
|
207
182
|
options: {
|
|
208
183
|
id: string
|
|
209
184
|
} & LazyRouteOptions
|
|
@@ -264,11 +239,15 @@ export class LazyRoute<TRoute extends AnyRoute> {
|
|
|
264
239
|
}
|
|
265
240
|
|
|
266
241
|
export function createLazyRoute<
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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']>>) {
|
|
270
246
|
return (opts: LazyRouteOptions) => {
|
|
271
|
-
return new LazyRoute<TRoute>({
|
|
247
|
+
return new LazyRoute<TRoute>({
|
|
248
|
+
id: id,
|
|
249
|
+
...opts,
|
|
250
|
+
})
|
|
272
251
|
}
|
|
273
252
|
}
|
|
274
253
|
|