@tanstack/react-router 1.7.1 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/CatchBoundary.cjs +106 -0
- package/dist/cjs/CatchBoundary.cjs.map +1 -0
- package/dist/cjs/Matches.cjs +278 -0
- package/dist/cjs/Matches.cjs.map +1 -0
- package/dist/cjs/Matches.d.cts +71 -0
- package/{build/cjs/RouterProvider.js → dist/cjs/RouterProvider.cjs} +55 -58
- package/dist/cjs/RouterProvider.cjs.map +1 -0
- package/dist/cjs/RouterProvider.d.cts +29 -0
- package/dist/cjs/awaited.cjs +51 -0
- package/dist/cjs/awaited.cjs.map +1 -0
- package/dist/cjs/defer.cjs +30 -0
- package/dist/cjs/defer.cjs.map +1 -0
- package/dist/cjs/fileRoute.cjs +19 -0
- package/dist/cjs/fileRoute.cjs.map +1 -0
- package/dist/cjs/history.d.cts +7 -0
- package/{build/cjs/index.js → dist/cjs/index.cjs} +39 -51
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/lazyRouteComponent.cjs +40 -0
- package/dist/cjs/lazyRouteComponent.cjs.map +1 -0
- package/dist/cjs/link.cjs +196 -0
- package/dist/cjs/link.cjs.map +1 -0
- package/dist/cjs/link.d.cts +85 -0
- package/{build/cjs/path.js → dist/cjs/path.cjs} +87 -95
- package/dist/cjs/path.cjs.map +1 -0
- package/dist/cjs/path.d.cts +24 -0
- package/dist/cjs/qss.cjs +45 -0
- package/dist/cjs/qss.cjs.map +1 -0
- package/dist/cjs/redirects.cjs +15 -0
- package/dist/cjs/redirects.cjs.map +1 -0
- package/dist/cjs/route.cjs +143 -0
- package/dist/cjs/route.cjs.map +1 -0
- package/dist/cjs/router.cjs +1089 -0
- package/dist/cjs/router.cjs.map +1 -0
- package/dist/cjs/routerContext.cjs +29 -0
- package/dist/cjs/routerContext.cjs.map +1 -0
- package/{build/cjs/scroll-restoration.js → dist/cjs/scroll-restoration.cjs} +58 -75
- package/dist/cjs/scroll-restoration.cjs.map +1 -0
- package/{build/cjs/searchParams.js → dist/cjs/searchParams.cjs} +18 -36
- package/dist/cjs/searchParams.cjs.map +1 -0
- package/dist/cjs/useBlocker.cjs +36 -0
- package/dist/cjs/useBlocker.cjs.map +1 -0
- package/dist/cjs/useNavigate.cjs +55 -0
- package/dist/cjs/useNavigate.cjs.map +1 -0
- package/dist/cjs/useParams.cjs +16 -0
- package/dist/cjs/useParams.cjs.map +1 -0
- package/dist/cjs/useRouteContext.cjs +11 -0
- package/dist/cjs/useRouteContext.cjs.map +1 -0
- package/dist/cjs/useRouter.cjs +33 -0
- package/dist/cjs/useRouter.cjs.map +1 -0
- package/dist/cjs/useRouterState.cjs +12 -0
- package/dist/cjs/useRouterState.cjs.map +1 -0
- package/dist/cjs/useSearch.cjs +13 -0
- package/dist/cjs/useSearch.cjs.map +1 -0
- package/{build/cjs/utils.js → dist/cjs/utils.cjs} +25 -116
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/cjs/utils.d.cts +50 -0
- package/dist/esm/CatchBoundary.d.ts +36 -0
- package/dist/esm/CatchBoundary.js +89 -0
- package/dist/esm/CatchBoundary.js.map +1 -0
- package/{build/types → dist/esm}/Matches.d.ts +3 -3
- package/dist/esm/Matches.js +261 -0
- package/dist/esm/Matches.js.map +1 -0
- package/{build/types → dist/esm}/RouterProvider.d.ts +3 -1
- package/dist/esm/RouterProvider.js +136 -0
- package/dist/esm/RouterProvider.js.map +1 -0
- package/dist/esm/awaited.d.ts +9 -0
- package/dist/esm/awaited.js +51 -0
- package/dist/esm/awaited.js.map +1 -0
- package/dist/esm/defer.d.ts +22 -0
- package/dist/esm/defer.js +30 -0
- package/{build/cjs → dist/esm}/defer.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +21 -0
- package/dist/esm/fileRoute.js +19 -0
- package/dist/esm/fileRoute.js.map +1 -0
- package/{build/types → dist/esm}/history.d.ts +1 -1
- package/dist/esm/index.d.ts +30 -0
- package/dist/esm/index.js +118 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lazyRouteComponent.d.ts +2 -0
- package/dist/esm/lazyRouteComponent.js +23 -0
- package/{build/cjs → dist/esm}/lazyRouteComponent.js.map +1 -1
- package/{build/types → dist/esm}/link.d.ts +3 -1
- package/dist/esm/link.js +179 -0
- package/dist/esm/link.js.map +1 -0
- package/dist/esm/location.d.ts +12 -0
- package/{build/types → dist/esm}/path.d.ts +8 -1
- package/dist/esm/path.js +209 -0
- package/dist/esm/path.js.map +1 -0
- package/dist/esm/qss.d.ts +2 -0
- package/dist/esm/qss.js +45 -0
- package/dist/esm/qss.js.map +1 -0
- package/dist/esm/redirects.d.ts +11 -0
- package/dist/esm/redirects.js +15 -0
- package/{build/cjs → dist/esm}/redirects.js.map +1 -1
- package/dist/esm/route.d.ts +300 -0
- package/dist/esm/route.js +143 -0
- package/dist/esm/route.js.map +1 -0
- package/dist/esm/routeInfo.d.ts +31 -0
- package/dist/esm/router.d.ts +201 -0
- package/dist/esm/router.js +1089 -0
- package/dist/esm/router.js.map +1 -0
- package/dist/esm/routerContext.d.ts +3 -0
- package/dist/esm/routerContext.js +13 -0
- package/{build/cjs → dist/esm}/routerContext.js.map +1 -1
- package/dist/esm/scroll-restoration.d.ts +18 -0
- package/dist/esm/scroll-restoration.js +168 -0
- package/dist/esm/scroll-restoration.js.map +1 -0
- package/dist/esm/searchParams.d.ts +7 -0
- package/dist/esm/searchParams.js +63 -0
- package/{build/cjs → dist/esm}/searchParams.js.map +1 -1
- package/dist/esm/useBlocker.d.ts +9 -0
- package/dist/esm/useBlocker.js +19 -0
- package/{build/cjs → dist/esm}/useBlocker.js.map +1 -1
- package/dist/esm/useNavigate.d.ts +20 -0
- package/dist/esm/useNavigate.js +38 -0
- package/{build/cjs → dist/esm}/useNavigate.js.map +1 -1
- package/dist/esm/useParams.d.ts +7 -0
- package/dist/esm/useParams.js +16 -0
- package/{build/cjs → dist/esm}/useParams.js.map +1 -1
- package/dist/esm/useRouteContext.d.ts +7 -0
- package/dist/esm/useRouteContext.js +11 -0
- package/{build/cjs → dist/esm}/useRouteContext.js.map +1 -1
- package/dist/esm/useRouter.d.ts +5 -0
- package/dist/esm/useRouter.js +16 -0
- package/{build/cjs → dist/esm}/useRouter.js.map +1 -1
- package/dist/esm/useRouterState.d.ts +6 -0
- package/dist/esm/useRouterState.js +12 -0
- package/{build/cjs → dist/esm}/useRouterState.js.map +1 -1
- package/dist/esm/useSearch.d.ts +7 -0
- package/dist/esm/useSearch.js +13 -0
- package/dist/esm/useSearch.js.map +1 -0
- package/{build/types → dist/esm}/utils.d.ts +4 -0
- package/dist/esm/utils.js +137 -0
- package/dist/esm/utils.js.map +1 -0
- package/package.json +43 -22
- package/src/Matches.tsx +10 -6
- package/src/RouterProvider.tsx +3 -1
- package/src/fileRoute.ts +4 -5
- package/src/link.tsx +5 -4
- package/src/path.ts +16 -5
- package/src/route.ts +5 -6
- package/src/router.ts +25 -8
- package/src/useSearch.tsx +5 -2
- package/src/utils.ts +9 -0
- package/build/cjs/CatchBoundary.js +0 -128
- package/build/cjs/CatchBoundary.js.map +0 -1
- package/build/cjs/Matches.js +0 -260
- package/build/cjs/Matches.js.map +0 -1
- package/build/cjs/RouterProvider.js.map +0 -1
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -29
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/awaited.js +0 -60
- package/build/cjs/awaited.js.map +0 -1
- package/build/cjs/defer.js +0 -42
- package/build/cjs/fileRoute.js +0 -31
- package/build/cjs/fileRoute.js.map +0 -1
- package/build/cjs/index.js.map +0 -1
- package/build/cjs/lazyRouteComponent.js +0 -54
- package/build/cjs/link.js +0 -224
- package/build/cjs/link.js.map +0 -1
- package/build/cjs/path.js.map +0 -1
- package/build/cjs/qss.js +0 -63
- package/build/cjs/qss.js.map +0 -1
- package/build/cjs/redirects.js +0 -28
- package/build/cjs/route.js +0 -292
- package/build/cjs/route.js.map +0 -1
- package/build/cjs/router.js +0 -1116
- package/build/cjs/router.js.map +0 -1
- package/build/cjs/routerContext.js +0 -42
- package/build/cjs/scroll-restoration.js.map +0 -1
- package/build/cjs/useBlocker.js +0 -55
- package/build/cjs/useNavigate.js +0 -88
- package/build/cjs/useParams.js +0 -27
- package/build/cjs/useRouteContext.js +0 -23
- package/build/cjs/useRouter.js +0 -44
- package/build/cjs/useRouterState.js +0 -24
- package/build/cjs/useSearch.js +0 -25
- package/build/cjs/useSearch.js.map +0 -1
- package/build/cjs/utils.js.map +0 -1
- package/build/esm/index.js +0 -2874
- package/build/esm/index.js.map +0 -1
- package/build/stats-html.html +0 -4838
- package/build/stats-react.json +0 -1471
- package/build/umd/index.development.js +0 -3573
- package/build/umd/index.development.js.map +0 -1
- package/build/umd/index.production.js +0 -22
- package/build/umd/index.production.js.map +0 -1
- /package/{build/types/CatchBoundary.d.ts → dist/cjs/CatchBoundary.d.cts} +0 -0
- /package/{build/types/awaited.d.ts → dist/cjs/awaited.d.cts} +0 -0
- /package/{build/types/defer.d.ts → dist/cjs/defer.d.cts} +0 -0
- /package/{build/types/fileRoute.d.ts → dist/cjs/fileRoute.d.cts} +0 -0
- /package/{build/types/index.d.ts → dist/cjs/index.d.cts} +0 -0
- /package/{build/types/lazyRouteComponent.d.ts → dist/cjs/lazyRouteComponent.d.cts} +0 -0
- /package/{build/types/location.d.ts → dist/cjs/location.d.cts} +0 -0
- /package/{build/types/qss.d.ts → dist/cjs/qss.d.cts} +0 -0
- /package/{build/types/redirects.d.ts → dist/cjs/redirects.d.cts} +0 -0
- /package/{build/types/route.d.ts → dist/cjs/route.d.cts} +0 -0
- /package/{build/types/routeInfo.d.ts → dist/cjs/routeInfo.d.cts} +0 -0
- /package/{build/types/router.d.ts → dist/cjs/router.d.cts} +0 -0
- /package/{build/types/routerContext.d.ts → dist/cjs/routerContext.d.cts} +0 -0
- /package/{build/types/scroll-restoration.d.ts → dist/cjs/scroll-restoration.d.cts} +0 -0
- /package/{build/types/searchParams.d.ts → dist/cjs/searchParams.d.cts} +0 -0
- /package/{build/types/useBlocker.d.ts → dist/cjs/useBlocker.d.cts} +0 -0
- /package/{build/types/useNavigate.d.ts → dist/cjs/useNavigate.d.cts} +0 -0
- /package/{build/types/useParams.d.ts → dist/cjs/useParams.d.cts} +0 -0
- /package/{build/types/useRouteContext.d.ts → dist/cjs/useRouteContext.d.cts} +0 -0
- /package/{build/types/useRouter.d.ts → dist/cjs/useRouter.d.cts} +0 -0
- /package/{build/types/useRouterState.d.ts → dist/cjs/useRouterState.d.cts} +0 -0
- /package/{build/types/useSearch.d.ts → dist/cjs/useSearch.d.cts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNavigate.js","sources":["../../src/useNavigate.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useMatch } from './Matches'\nimport { useRouter } from './useRouter'\nimport { LinkOptions, NavigateOptions } from './link'\nimport { AnyRoute } from './route'\nimport { RoutePaths } from './routeInfo'\nimport { RegisteredRouter } from './router'\nimport { StringLiteral } from './utils'\n\nexport function useNavigate<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TDefaultFrom extends RoutePaths<TRouteTree> | string = RoutePaths<TRouteTree>,\n>(_defaultOpts?: { from?: StringLiteral<TDefaultFrom> }) {\n const { navigate } = useRouter()\n\n const matchPathname = useMatch({\n strict: false,\n select: (s) => s.pathname,\n })\n\n return React.useCallback(\n <\n TFrom extends RoutePaths<TRouteTree> | string = TDefaultFrom,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n >({\n from,\n ...rest\n }: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>) => {\n return navigate({\n from: rest?.to ? matchPathname : undefined,\n ...(rest as any),\n })\n },\n [],\n )\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 TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n>(props: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>): null {\n const { navigate } = useRouter()\n const match = useMatch({ strict: false })\n\n React.useEffect(() => {\n navigate({\n from: props.to ? match.pathname : undefined,\n ...props,\n } as any)\n }, [])\n\n return null\n}\n\nexport type UseLinkPropsOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n> = ActiveLinkOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> &\n React.AnchorHTMLAttributes<HTMLAnchorElement>\n\nexport type LinkProps<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n> = ActiveLinkOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> &\n Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'children'> & {\n // If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns\n children?:\n | React.ReactNode\n | ((state: { isActive: boolean }) => React.ReactNode)\n }\n\nexport type ActiveLinkOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n> = LinkOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // A function that returns additional props for the `active` state of this link. These props override other props passed to the link (`style`'s are merged, `className`'s are concatenated)\n activeProps?:\n | React.AnchorHTMLAttributes<HTMLAnchorElement>\n | (() => React.AnchorHTMLAttributes<HTMLAnchorElement>)\n // A function that returns additional props for the `inactive` state of this link. These props override other props passed to the link (`style`'s are merged, `className`'s are concatenated)\n inactiveProps?:\n | React.AnchorHTMLAttributes<HTMLAnchorElement>\n | (() => React.AnchorHTMLAttributes<HTMLAnchorElement>)\n}\n"],"names":[
|
|
1
|
+
{"version":3,"file":"useNavigate.js","sources":["../../src/useNavigate.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useMatch } from './Matches'\nimport { useRouter } from './useRouter'\nimport { LinkOptions, NavigateOptions } from './link'\nimport { AnyRoute } from './route'\nimport { RoutePaths } from './routeInfo'\nimport { RegisteredRouter } from './router'\nimport { StringLiteral } from './utils'\n\nexport function useNavigate<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TDefaultFrom extends RoutePaths<TRouteTree> | string = RoutePaths<TRouteTree>,\n>(_defaultOpts?: { from?: StringLiteral<TDefaultFrom> }) {\n const { navigate } = useRouter()\n\n const matchPathname = useMatch({\n strict: false,\n select: (s) => s.pathname,\n })\n\n return React.useCallback(\n <\n TFrom extends RoutePaths<TRouteTree> | string = TDefaultFrom,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n >({\n from,\n ...rest\n }: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>) => {\n return navigate({\n from: rest?.to ? matchPathname : undefined,\n ...(rest as any),\n })\n },\n [],\n )\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 TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n>(props: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>): null {\n const { navigate } = useRouter()\n const match = useMatch({ strict: false })\n\n React.useEffect(() => {\n navigate({\n from: props.to ? match.pathname : undefined,\n ...props,\n } as any)\n }, [])\n\n return null\n}\n\nexport type UseLinkPropsOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n> = ActiveLinkOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> &\n React.AnchorHTMLAttributes<HTMLAnchorElement>\n\nexport type LinkProps<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n> = ActiveLinkOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> &\n Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'children'> & {\n // If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns\n children?:\n | React.ReactNode\n | ((state: { isActive: boolean }) => React.ReactNode)\n }\n\nexport type ActiveLinkOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n> = LinkOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // A function that returns additional props for the `active` state of this link. These props override other props passed to the link (`style`'s are merged, `className`'s are concatenated)\n activeProps?:\n | React.AnchorHTMLAttributes<HTMLAnchorElement>\n | (() => React.AnchorHTMLAttributes<HTMLAnchorElement>)\n // A function that returns additional props for the `inactive` state of this link. These props override other props passed to the link (`style`'s are merged, `className`'s are concatenated)\n inactiveProps?:\n | React.AnchorHTMLAttributes<HTMLAnchorElement>\n | (() => React.AnchorHTMLAttributes<HTMLAnchorElement>)\n}\n"],"names":[],"mappings":";;;AASO,SAAS,YAGd,cAAuD;AACjD,QAAA,EAAE,aAAa;AAErB,QAAM,gBAAgB,SAAS;AAAA,IAC7B,QAAQ;AAAA,IACR,QAAQ,CAAC,MAAM,EAAE;AAAA,EAAA,CAClB;AAED,SAAO,MAAM;AAAA,IACX,CAKE;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IAAA,MAC8D;AACjE,aAAO,SAAS;AAAA,QACd,OAAM,6BAAM,MAAK,gBAAgB;AAAA,QACjC,GAAI;AAAA,MAAA,CACL;AAAA,IACH;AAAA,IACA,CAAC;AAAA,EAAA;AAEL;AAiBO,SAAS,SAMd,OAA0E;AACpE,QAAA,EAAE,aAAa;AACrB,QAAM,QAAQ,SAAS,EAAE,QAAQ,MAAO,CAAA;AAExC,QAAM,UAAU,MAAM;AACX,aAAA;AAAA,MACP,MAAM,MAAM,KAAK,MAAM,WAAW;AAAA,MAClC,GAAG;AAAA,IAAA,CACG;AAAA,EACV,GAAG,CAAE,CAAA;AAEE,SAAA;AACT;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AnyRoute } from './route';
|
|
2
|
+
import { RouteIds, RouteById } from './routeInfo';
|
|
3
|
+
import { RegisteredRouter } from './router';
|
|
4
|
+
import { StrictOrFrom } from './utils';
|
|
5
|
+
export declare function useParams<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TParams = RouteById<TRouteTree, TFrom>['types']['allParams'], TSelected = TParams>(opts: StrictOrFrom<TFrom> & {
|
|
6
|
+
select?: (params: TParams) => TSelected;
|
|
7
|
+
}): TSelected;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { last } from "./utils.js";
|
|
2
|
+
import { useRouterState } from "./useRouterState.js";
|
|
3
|
+
import { getRenderedMatches } from "./Matches.js";
|
|
4
|
+
function useParams(opts) {
|
|
5
|
+
return useRouterState({
|
|
6
|
+
select: (state) => {
|
|
7
|
+
var _a;
|
|
8
|
+
const params = (_a = last(getRenderedMatches(state))) == null ? void 0 : _a.params;
|
|
9
|
+
return (opts == null ? void 0 : opts.select) ? opts.select(params) : params;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
useParams
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=useParams.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useParams.js","sources":["../../src/useParams.tsx"],"sourcesContent":["import { AnyRoute } from './route'\nimport { RouteIds, RouteById } from './routeInfo'\nimport { RegisteredRouter } from './router'\nimport { last } from './utils'\nimport { useRouterState } from './useRouterState'\nimport { StrictOrFrom } from './utils'\nimport { getRenderedMatches } from './Matches'\n\nexport function useParams<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TParams = RouteById<TRouteTree, TFrom>['types']['allParams'],\n TSelected = TParams,\n>(\n opts: StrictOrFrom<TFrom> & {\n select?: (params: TParams) => TSelected\n },\n): TSelected {\n return useRouterState({\n select: (state: any) => {\n const params = (last(getRenderedMatches(state)) as any)?.params\n return opts?.select ? opts.select(params) : params\n },\n })\n}\n"],"names":[
|
|
1
|
+
{"version":3,"file":"useParams.js","sources":["../../src/useParams.tsx"],"sourcesContent":["import { AnyRoute } from './route'\nimport { RouteIds, RouteById } from './routeInfo'\nimport { RegisteredRouter } from './router'\nimport { last } from './utils'\nimport { useRouterState } from './useRouterState'\nimport { StrictOrFrom } from './utils'\nimport { getRenderedMatches } from './Matches'\n\nexport function useParams<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TParams = RouteById<TRouteTree, TFrom>['types']['allParams'],\n TSelected = TParams,\n>(\n opts: StrictOrFrom<TFrom> & {\n select?: (params: TParams) => TSelected\n },\n): TSelected {\n return useRouterState({\n select: (state: any) => {\n const params = (last(getRenderedMatches(state)) as any)?.params\n return opts?.select ? opts.select(params) : params\n },\n })\n}\n"],"names":[],"mappings":";;;AAQO,SAAS,UAMd,MAGW;AACX,SAAO,eAAe;AAAA,IACpB,QAAQ,CAAC,UAAe;;AACtB,YAAM,UAAU,UAAK,mBAAmB,KAAK,CAAC,MAA9B,mBAAyC;AACzD,cAAO,6BAAM,UAAS,KAAK,OAAO,MAAM,IAAI;AAAA,IAC9C;AAAA,EAAA,CACD;AACH;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AnyRoute } from './route';
|
|
2
|
+
import { RouteIds, RouteById } from './routeInfo';
|
|
3
|
+
import { RegisteredRouter } from './router';
|
|
4
|
+
import { StrictOrFrom } from './utils';
|
|
5
|
+
export declare function useRouteContext<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TRouteContext = RouteById<TRouteTree, TFrom>['types']['allContext'], TSelected = TRouteContext>(opts: StrictOrFrom<TFrom> & {
|
|
6
|
+
select?: (search: TRouteContext) => TSelected;
|
|
7
|
+
}): TSelected;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useMatch } from "./Matches.js";
|
|
2
|
+
function useRouteContext(opts) {
|
|
3
|
+
return useMatch({
|
|
4
|
+
...opts,
|
|
5
|
+
select: (match) => (opts == null ? void 0 : opts.select) ? opts.select(match.context) : match.context
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
useRouteContext
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=useRouteContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouteContext.js","sources":["../../src/useRouteContext.ts"],"sourcesContent":["import { useMatch, RouteMatch } from './Matches'\nimport { AnyRoute } from './route'\nimport { RouteIds, RouteById } from './routeInfo'\nimport { RegisteredRouter } from './router'\nimport { StrictOrFrom } from './utils'\n\nexport function useRouteContext<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TRouteContext = RouteById<TRouteTree, TFrom>['types']['allContext'],\n TSelected = TRouteContext,\n>(\n opts: StrictOrFrom<TFrom> & {\n select?: (search: TRouteContext) => TSelected\n },\n): TSelected {\n return useMatch({\n ...(opts as any),\n select: (match: RouteMatch) =>\n opts?.select\n ? opts.select(match.context as TRouteContext)\n : match.context,\n })\n}\n"],"names":[
|
|
1
|
+
{"version":3,"file":"useRouteContext.js","sources":["../../src/useRouteContext.ts"],"sourcesContent":["import { useMatch, RouteMatch } from './Matches'\nimport { AnyRoute } from './route'\nimport { RouteIds, RouteById } from './routeInfo'\nimport { RegisteredRouter } from './router'\nimport { StrictOrFrom } from './utils'\n\nexport function useRouteContext<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TRouteContext = RouteById<TRouteTree, TFrom>['types']['allContext'],\n TSelected = TRouteContext,\n>(\n opts: StrictOrFrom<TFrom> & {\n select?: (search: TRouteContext) => TSelected\n },\n): TSelected {\n return useMatch({\n ...(opts as any),\n select: (match: RouteMatch) =>\n opts?.select\n ? opts.select(match.context as TRouteContext)\n : match.context,\n })\n}\n"],"names":[],"mappings":";AAMO,SAAS,gBAMd,MAGW;AACX,SAAO,SAAS;AAAA,IACd,GAAI;AAAA,IACJ,QAAQ,CAAC,WACP,6BAAM,UACF,KAAK,OAAO,MAAM,OAAwB,IAC1C,MAAM;AAAA,EAAA,CACb;AACH;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import warning from "tiny-warning";
|
|
3
|
+
import { routerContext } from "./routerContext.js";
|
|
4
|
+
function useRouter(opts) {
|
|
5
|
+
const resolvedContext = typeof document !== "undefined" ? window.__TSR_ROUTER_CONTEXT__ || routerContext : routerContext;
|
|
6
|
+
const value = React.useContext(resolvedContext);
|
|
7
|
+
warning(
|
|
8
|
+
!(((opts == null ? void 0 : opts.warn) ?? true) && !value),
|
|
9
|
+
"useRouter must be used inside a <RouterProvider> component!"
|
|
10
|
+
);
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
useRouter
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=useRouter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouter.js","sources":["../../src/useRouter.tsx"],"sourcesContent":["import * as React from 'react'\nimport warning from 'tiny-warning'\nimport { AnyRoute } from './route'\nimport { RegisteredRouter, Router } from './router'\nimport { routerContext } from './routerContext'\n\nexport function useRouter<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n>(opts?: { warn?: boolean }): Router<TRouteTree> {\n const resolvedContext =\n typeof document !== 'undefined'\n ? window.__TSR_ROUTER_CONTEXT__ || routerContext\n : routerContext\n const value = React.useContext(resolvedContext)\n warning(\n !((opts?.warn ?? true) && !value),\n 'useRouter must be used inside a <RouterProvider> component!',\n )\n return value as any\n}\n"],"names":[
|
|
1
|
+
{"version":3,"file":"useRouter.js","sources":["../../src/useRouter.tsx"],"sourcesContent":["import * as React from 'react'\nimport warning from 'tiny-warning'\nimport { AnyRoute } from './route'\nimport { RegisteredRouter, Router } from './router'\nimport { routerContext } from './routerContext'\n\nexport function useRouter<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n>(opts?: { warn?: boolean }): Router<TRouteTree> {\n const resolvedContext =\n typeof document !== 'undefined'\n ? window.__TSR_ROUTER_CONTEXT__ || routerContext\n : routerContext\n const value = React.useContext(resolvedContext)\n warning(\n !((opts?.warn ?? true) && !value),\n 'useRouter must be used inside a <RouterProvider> component!',\n )\n return value as any\n}\n"],"names":[],"mappings":";;;AAMO,SAAS,UAEd,MAA+C;AAC/C,QAAM,kBACJ,OAAO,aAAa,cAChB,OAAO,0BAA0B,gBACjC;AACA,QAAA,QAAQ,MAAM,WAAW,eAAe;AAC9C;AAAA,IACE,IAAG,6BAAM,SAAQ,SAAS,CAAC;AAAA,IAC3B;AAAA,EAAA;AAEK,SAAA;AACT;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AnyRoute } from './route';
|
|
2
|
+
import { RegisteredRouter, Router, RouterState } from './router';
|
|
3
|
+
export declare function useRouterState<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TSelected = RouterState<TRouteTree>>(opts?: {
|
|
4
|
+
router?: Router<TRouteTree>;
|
|
5
|
+
select: (state: RouterState<RegisteredRouter['routeTree']>) => TSelected;
|
|
6
|
+
}): TSelected;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useStore } from "@tanstack/react-store";
|
|
2
|
+
import { useRouter } from "./useRouter.js";
|
|
3
|
+
function useRouterState(opts) {
|
|
4
|
+
const contextRouter = useRouter({
|
|
5
|
+
warn: (opts == null ? void 0 : opts.router) === void 0
|
|
6
|
+
});
|
|
7
|
+
return useStore(((opts == null ? void 0 : opts.router) || contextRouter).__store, opts == null ? void 0 : opts.select);
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
useRouterState
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=useRouterState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouterState.js","sources":["../../src/useRouterState.tsx"],"sourcesContent":["import { useStore } from '@tanstack/react-store'\nimport { AnyRoute } from './route'\nimport { RegisteredRouter, Router, RouterState } from './router'\nimport { useRouter } from './useRouter'\n\nexport function useRouterState<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TSelected = RouterState<TRouteTree>,\n>(opts?: {\n router?: Router<TRouteTree>\n select: (state: RouterState<RegisteredRouter['routeTree']>) => TSelected\n}): TSelected {\n const contextRouter = useRouter<TRouteTree>({\n warn: opts?.router === undefined,\n })\n return useStore((opts?.router || contextRouter).__store, opts?.select as any)\n}\n"],"names":[
|
|
1
|
+
{"version":3,"file":"useRouterState.js","sources":["../../src/useRouterState.tsx"],"sourcesContent":["import { useStore } from '@tanstack/react-store'\nimport { AnyRoute } from './route'\nimport { RegisteredRouter, Router, RouterState } from './router'\nimport { useRouter } from './useRouter'\n\nexport function useRouterState<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TSelected = RouterState<TRouteTree>,\n>(opts?: {\n router?: Router<TRouteTree>\n select: (state: RouterState<RegisteredRouter['routeTree']>) => TSelected\n}): TSelected {\n const contextRouter = useRouter<TRouteTree>({\n warn: opts?.router === undefined,\n })\n return useStore((opts?.router || contextRouter).__store, opts?.select as any)\n}\n"],"names":[],"mappings":";;AAKO,SAAS,eAGd,MAGY;AACZ,QAAM,gBAAgB,UAAsB;AAAA,IAC1C,OAAM,6BAAM,YAAW;AAAA,EAAA,CACxB;AACD,SAAO,WAAU,6BAAM,WAAU,eAAe,SAAS,6BAAM,MAAa;AAC9E;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AnyRoute, RootSearchSchema } from './route';
|
|
2
|
+
import { RouteIds, RouteById } from './routeInfo';
|
|
3
|
+
import { RegisteredRouter } from './router';
|
|
4
|
+
import { StrictOrFrom } from './utils';
|
|
5
|
+
export declare function useSearch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TSearch = Exclude<RouteById<TRouteTree, TFrom>['types']['fullSearchSchema'], RootSearchSchema>, TSelected = TSearch>(opts: StrictOrFrom<TFrom> & {
|
|
6
|
+
select?: (search: TSearch) => TSelected;
|
|
7
|
+
}): TSelected;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useMatch } from "./Matches.js";
|
|
2
|
+
function useSearch(opts) {
|
|
3
|
+
return useMatch({
|
|
4
|
+
...opts,
|
|
5
|
+
select: (match) => {
|
|
6
|
+
return (opts == null ? void 0 : opts.select) ? opts.select(match.search) : match.search;
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
useSearch
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=useSearch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSearch.js","sources":["../../src/useSearch.tsx"],"sourcesContent":["import { AnyRoute, RootSearchSchema } from './route'\nimport { RouteIds, RouteById } from './routeInfo'\nimport { RegisteredRouter } from './router'\nimport { RouteMatch } from './Matches'\nimport { useMatch } from './Matches'\nimport { StrictOrFrom } from './utils'\n\nexport function useSearch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TSearch = Exclude<\n RouteById<TRouteTree, TFrom>['types']['fullSearchSchema'],\n RootSearchSchema\n >,\n TSelected = TSearch,\n>(\n opts: StrictOrFrom<TFrom> & {\n select?: (search: TSearch) => TSelected\n },\n): TSelected {\n return useMatch({\n ...opts,\n select: (match: RouteMatch) => {\n return opts?.select ? opts.select(match.search as TSearch) : match.search\n },\n })\n}\n"],"names":[],"mappings":";AAOO,SAAS,UASd,MAGW;AACX,SAAO,SAAS;AAAA,IACd,GAAG;AAAA,IACH,QAAQ,CAAC,UAAsB;AAC7B,cAAO,6BAAM,UAAS,KAAK,OAAO,MAAM,MAAiB,IAAI,MAAM;AAAA,IACrE;AAAA,EAAA,CACD;AACH;"}
|
|
@@ -10,6 +10,10 @@ export type Expand<T> = T extends object ? T extends infer O ? {
|
|
|
10
10
|
[K in keyof O]: O[K];
|
|
11
11
|
} : never : T;
|
|
12
12
|
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => any ? I : never;
|
|
13
|
+
export type DeepOptional<T, K extends keyof T> = Pick<DeepPartial<T>, K> & Omit<T, K>;
|
|
14
|
+
export type DeepPartial<T> = T extends object ? {
|
|
15
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
16
|
+
} : T;
|
|
13
17
|
export type Assign<Left, Right> = Omit<Left, keyof Right> & Right;
|
|
14
18
|
export type AssignAll<T extends any[]> = T extends [infer Left, ...infer Right] ? Right extends any[] ? Assign<Left, AssignAll<Right>> : Left : {};
|
|
15
19
|
export type Timeout = ReturnType<typeof setTimeout>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
const isServer = typeof document === "undefined";
|
|
3
|
+
function last(arr) {
|
|
4
|
+
return arr[arr.length - 1];
|
|
5
|
+
}
|
|
6
|
+
function isFunction(d) {
|
|
7
|
+
return typeof d === "function";
|
|
8
|
+
}
|
|
9
|
+
function functionalUpdate(updater, previous) {
|
|
10
|
+
if (isFunction(updater)) {
|
|
11
|
+
return updater(previous);
|
|
12
|
+
}
|
|
13
|
+
return updater;
|
|
14
|
+
}
|
|
15
|
+
function pick(parent, keys) {
|
|
16
|
+
return keys.reduce((obj, key) => {
|
|
17
|
+
obj[key] = parent[key];
|
|
18
|
+
return obj;
|
|
19
|
+
}, {});
|
|
20
|
+
}
|
|
21
|
+
function replaceEqualDeep(prev, _next) {
|
|
22
|
+
if (prev === _next) {
|
|
23
|
+
return prev;
|
|
24
|
+
}
|
|
25
|
+
const next = _next;
|
|
26
|
+
const array = isPlainArray(prev) && isPlainArray(next);
|
|
27
|
+
if (array || isPlainObject(prev) && isPlainObject(next)) {
|
|
28
|
+
const prevItems = array ? prev : Object.keys(prev);
|
|
29
|
+
const prevSize = prevItems.length;
|
|
30
|
+
const nextItems = array ? next : Object.keys(next);
|
|
31
|
+
const nextSize = nextItems.length;
|
|
32
|
+
const copy = array ? [] : {};
|
|
33
|
+
let equalItems = 0;
|
|
34
|
+
for (let i = 0; i < nextSize; i++) {
|
|
35
|
+
const key = array ? i : nextItems[i];
|
|
36
|
+
if (!array && prev[key] === void 0 && next[key] === void 0 && prevItems.includes(key)) {
|
|
37
|
+
copy[key] = void 0;
|
|
38
|
+
equalItems++;
|
|
39
|
+
} else {
|
|
40
|
+
copy[key] = replaceEqualDeep(prev[key], next[key]);
|
|
41
|
+
if (copy[key] === prev[key] && prev[key] !== void 0) {
|
|
42
|
+
equalItems++;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return prevSize === nextSize && equalItems === prevSize ? prev : copy;
|
|
47
|
+
}
|
|
48
|
+
return next;
|
|
49
|
+
}
|
|
50
|
+
function isPlainObject(o) {
|
|
51
|
+
if (!hasObjectPrototype(o)) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
const ctor = o.constructor;
|
|
55
|
+
if (typeof ctor === "undefined") {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
const prot = ctor.prototype;
|
|
59
|
+
if (!hasObjectPrototype(prot)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (!prot.hasOwnProperty("isPrototypeOf")) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
function hasObjectPrototype(o) {
|
|
68
|
+
return Object.prototype.toString.call(o) === "[object Object]";
|
|
69
|
+
}
|
|
70
|
+
function isPlainArray(value) {
|
|
71
|
+
return Array.isArray(value) && value.length === Object.keys(value).length;
|
|
72
|
+
}
|
|
73
|
+
function deepEqual(a, b, partial = false) {
|
|
74
|
+
if (a === b) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
if (typeof a !== typeof b) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
81
|
+
const aKeys = Object.keys(a);
|
|
82
|
+
const bKeys = Object.keys(b);
|
|
83
|
+
if (!partial && aKeys.length !== bKeys.length) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
return !bKeys.some(
|
|
87
|
+
(key) => !(key in a) || !deepEqual(a[key], b[key], partial)
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
91
|
+
return !a.some((item, index) => !deepEqual(item, b[index], partial));
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
function useStableCallback(fn) {
|
|
96
|
+
const fnRef = React.useRef(fn);
|
|
97
|
+
fnRef.current = fn;
|
|
98
|
+
const ref = React.useRef((...args) => fnRef.current(...args));
|
|
99
|
+
return ref.current;
|
|
100
|
+
}
|
|
101
|
+
function shallow(objA, objB) {
|
|
102
|
+
if (Object.is(objA, objB)) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
const keysA = Object.keys(objA);
|
|
109
|
+
if (keysA.length !== Object.keys(objB).length) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
for (let i = 0; i < keysA.length; i++) {
|
|
113
|
+
if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
const useLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
|
|
120
|
+
function escapeJSON(jsonString) {
|
|
121
|
+
return jsonString.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/"/g, '\\"');
|
|
122
|
+
}
|
|
123
|
+
export {
|
|
124
|
+
deepEqual,
|
|
125
|
+
escapeJSON,
|
|
126
|
+
functionalUpdate,
|
|
127
|
+
isPlainArray,
|
|
128
|
+
isPlainObject,
|
|
129
|
+
isServer,
|
|
130
|
+
last,
|
|
131
|
+
pick,
|
|
132
|
+
replaceEqualDeep,
|
|
133
|
+
shallow,
|
|
134
|
+
useLayoutEffect,
|
|
135
|
+
useStableCallback
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as React from 'react'\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\nexport type IsAny<T, Y, N = T> = 1 extends 0 & T ? Y : N\nexport type PickAsRequired<T, K extends keyof T> = Omit<T, K> &\n Required<Pick<T, K>>\n\nexport type PickRequired<T> = {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K]\n}\n\n// from https://stackoverflow.com/a/76458160\nexport type WithoutEmpty<T> = T extends T ? ({} extends T ? never : T) : never\n\n// export type Expand<T> = T\nexport type Expand<T> = T extends object\n ? T extends infer O\n ? { [K in keyof O]: O[K] }\n : never\n : T\n\nexport type UnionToIntersection<U> = (\n U extends any ? (k: U) => void : never\n) extends (k: infer I) => any\n ? I\n : never\n\nexport type DeepOptional<T, K extends keyof T> = Pick<DeepPartial<T>, K> &\n Omit<T, K>\n\nexport type DeepPartial<T> = T extends object\n ? {\n [P in keyof T]?: DeepPartial<T[P]>\n }\n : T\n\n// type Compute<T> = { [K in keyof T]: T[K] } | never\n\n// type AllKeys<T> = T extends any ? keyof T : never\n\n// export type MergeUnion<T, Keys extends keyof T = keyof T> = Compute<\n// {\n// [K in Keys]: T[Keys]\n// } & {\n// [K in AllKeys<T>]?: T extends any\n// ? K extends keyof T\n// ? T[K]\n// : never\n// : never\n// }\n// >\n\nexport type Assign<Left, Right> = Omit<Left, keyof Right> & Right\n\nexport type AssignAll<T extends any[]> = T extends [infer Left, ...infer Right]\n ? Right extends any[]\n ? Assign<Left, AssignAll<Right>>\n : Left\n : {}\n\n// // Sample types to merge\n// type TypeA = {\n// shared: string\n// onlyInA: string\n// nested: {\n// shared: string\n// aProp: string\n// }\n// array: string[]\n// }\n\n// type TypeB = {\n// shared: number\n// onlyInB: number\n// nested: {\n// shared: number\n// bProp: number\n// }\n// array: number[]\n// }\n\n// type TypeC = {\n// shared: boolean\n// onlyInC: boolean\n// nested: {\n// shared: boolean\n// cProp: boolean\n// }\n// array: boolean[]\n// }\n\n// type Test = Expand<Assign<TypeA, TypeB>>\n\n// // Using DeepMerge to merge TypeA and TypeB\n// type MergedType = Expand<AssignAll<[TypeA, TypeB, TypeC]>>\n\nexport type Timeout = ReturnType<typeof setTimeout>\n\nexport type Updater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev?: TPrevious) => TResult)\n\nexport type NonNullableUpdater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev: TPrevious) => TResult)\n\n// from https://github.com/type-challenges/type-challenges/issues/737\ntype LastInUnion<U> = UnionToIntersection<\n U extends unknown ? (x: U) => 0 : never\n> extends (x: infer L) => 0\n ? L\n : never\nexport type UnionToTuple<U, Last = LastInUnion<U>> = [U] extends [never]\n ? []\n : [...UnionToTuple<Exclude<U, Last>>, Last]\n\n//\n\nexport const isServer = typeof document === 'undefined'\n\nexport function last<T>(arr: T[]) {\n return arr[arr.length - 1]\n}\n\nfunction isFunction(d: any): d is Function {\n return typeof d === 'function'\n}\n\nexport function functionalUpdate<TResult>(\n updater: Updater<TResult> | NonNullableUpdater<TResult>,\n previous: TResult,\n): TResult {\n if (isFunction(updater)) {\n return updater(previous as TResult)\n }\n\n return updater\n}\n\nexport function pick<T, K extends keyof T>(parent: T, keys: K[]): Pick<T, K> {\n return keys.reduce((obj: any, key: K) => {\n obj[key] = parent[key]\n return obj\n }, {} as any)\n}\n\n/**\n * This function returns `prev` if `_next` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between immutable JSON values for example.\n * Do not use this with signals\n */\nexport function replaceEqualDeep<T>(prev: any, _next: T): T {\n if (prev === _next) {\n return prev\n }\n\n const next = _next as any\n\n const array = isPlainArray(prev) && isPlainArray(next)\n\n if (array || (isPlainObject(prev) && isPlainObject(next))) {\n const prevItems = array ? prev : Object.keys(prev)\n const prevSize = prevItems.length\n const nextItems = array ? next : Object.keys(next)\n const nextSize = nextItems.length\n const copy: any = array ? [] : {}\n\n let equalItems = 0\n\n for (let i = 0; i < nextSize; i++) {\n const key = array ? i : nextItems[i]\n if (\n !array &&\n prev[key] === undefined &&\n next[key] === undefined &&\n prevItems.includes(key)\n ) {\n copy[key] = undefined\n equalItems++\n } else {\n copy[key] = replaceEqualDeep(prev[key], next[key])\n if (copy[key] === prev[key] && prev[key] !== undefined) {\n equalItems++\n }\n }\n }\n\n return prevSize === nextSize && equalItems === prevSize ? prev : copy\n }\n\n return next\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function isPlainObject(o: any) {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has modified constructor\n const ctor = o.constructor\n if (typeof ctor === 'undefined') {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any) {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n\nexport function isPlainArray(value: unknown) {\n return Array.isArray(value) && value.length === Object.keys(value).length\n}\n\nexport function deepEqual(a: any, b: any, partial: boolean = false): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (isPlainObject(a) && isPlainObject(b)) {\n const aKeys = Object.keys(a)\n const bKeys = Object.keys(b)\n\n if (!partial && aKeys.length !== bKeys.length) {\n return false\n }\n\n return !bKeys.some(\n (key) => !(key in a) || !deepEqual(a[key], b[key], partial),\n )\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n return !a.some((item, index) => !deepEqual(item, b[index], partial))\n }\n\n return false\n}\n\nexport function useStableCallback<T extends (...args: any[]) => any>(fn: T): T {\n const fnRef = React.useRef(fn)\n fnRef.current = fn\n\n const ref = React.useRef((...args: any[]) => fnRef.current(...args))\n return ref.current as T\n}\n\nexport function shallow<T>(objA: T, objB: T) {\n if (Object.is(objA, objB)) {\n return true\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false\n }\n\n const keysA = Object.keys(objA)\n if (keysA.length !== Object.keys(objB).length) {\n return false\n }\n\n for (let i = 0; i < keysA.length; i++) {\n if (\n !Object.prototype.hasOwnProperty.call(objB, keysA[i] as string) ||\n !Object.is(objA[keysA[i] as keyof T], objB[keysA[i] as keyof T])\n ) {\n return false\n }\n }\n return true\n}\n\nexport type StringLiteral<T> = T extends string\n ? string extends T\n ? string\n : T\n : never\n\nexport type StrictOrFrom<TFrom> =\n | {\n from: StringLiteral<TFrom> | TFrom\n strict?: true\n }\n | {\n from?: never\n strict: false\n }\n\nexport const useLayoutEffect =\n typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\nexport function escapeJSON(jsonString: string) {\n return jsonString\n .replace(/\\\\/g, '\\\\\\\\') // Escape backslashes\n .replace(/'/g, \"\\\\'\") // Escape single quotes\n .replace(/\"/g, '\\\\\"') // Escape double quotes\n}\n"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
|
+
"version": "1.8.1",
|
|
4
|
+
"description": "",
|
|
3
5
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "1.7.1",
|
|
5
6
|
"license": "MIT",
|
|
6
|
-
"repository":
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/TanStack/router.git",
|
|
10
|
+
"directory": "packages/react-router"
|
|
11
|
+
},
|
|
7
12
|
"homepage": "https://tanstack.com/router",
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
"
|
|
13
|
+
"funding": {
|
|
14
|
+
"type": "github",
|
|
15
|
+
"url": "https://github.com/sponsors/tannerlinsley"
|
|
11
16
|
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"types": "dist/esm/index.d.ts",
|
|
19
|
+
"main": "dist/cjs/index.cjs",
|
|
20
|
+
"module": "dist/esm/index.js",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": {
|
|
24
|
+
"types": "./dist/esm/index.d.ts",
|
|
25
|
+
"default": "./dist/esm/index.js"
|
|
26
|
+
},
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./dist/cjs/index.d.cts",
|
|
29
|
+
"default": "./dist/cjs/index.cjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"sideEffects": false,
|
|
12
35
|
"keywords": [
|
|
13
36
|
"react",
|
|
14
37
|
"location",
|
|
@@ -18,35 +41,33 @@
|
|
|
18
41
|
"async router",
|
|
19
42
|
"typescript"
|
|
20
43
|
],
|
|
21
|
-
"funding": {
|
|
22
|
-
"type": "github",
|
|
23
|
-
"url": "https://github.com/sponsors/tannerlinsley"
|
|
24
|
-
},
|
|
25
|
-
"module": "build/esm/index.js",
|
|
26
|
-
"main": "build/cjs/index.js",
|
|
27
|
-
"browser": "build/umd/index.production.js",
|
|
28
|
-
"types": "build/types/index.d.ts",
|
|
29
44
|
"engines": {
|
|
30
45
|
"node": ">=12"
|
|
31
46
|
},
|
|
32
47
|
"files": [
|
|
33
|
-
"
|
|
48
|
+
"dist",
|
|
34
49
|
"src"
|
|
35
50
|
],
|
|
36
|
-
"sideEffects": false,
|
|
37
|
-
"peerDependencies": {
|
|
38
|
-
"react": ">=16",
|
|
39
|
-
"react-dom": ">=16"
|
|
40
|
-
},
|
|
41
51
|
"dependencies": {
|
|
42
|
-
"@babel/runtime": "^7.16.7",
|
|
43
52
|
"@tanstack/react-store": "^0.2.1",
|
|
44
53
|
"@tanstack/store": "^0.1.3",
|
|
45
54
|
"tiny-invariant": "^1.3.1",
|
|
46
55
|
"tiny-warning": "^1.0.3",
|
|
47
|
-
"@tanstack/history": "1.
|
|
56
|
+
"@tanstack/history": "1.8.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@vitejs/plugin-react": "^4.2.1"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"react": ">=16",
|
|
63
|
+
"react-dom": ">=16"
|
|
48
64
|
},
|
|
49
65
|
"scripts": {
|
|
50
|
-
"
|
|
66
|
+
"clean": "rimraf ./dist && rimraf ./coverage",
|
|
67
|
+
"test:types": "tsc",
|
|
68
|
+
"test:lib": "vitest",
|
|
69
|
+
"test:lib:dev": "pnpm run test:lib --watch",
|
|
70
|
+
"test:build": "publint --strict",
|
|
71
|
+
"build": "vite build"
|
|
51
72
|
}
|
|
52
73
|
}
|
package/src/Matches.tsx
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
RoutePaths,
|
|
15
15
|
} from './routeInfo'
|
|
16
16
|
import { RegisteredRouter, RouterState } from './router'
|
|
17
|
-
import { NoInfer, StrictOrFrom, pick } from './utils'
|
|
17
|
+
import { DeepOptional, NoInfer, StrictOrFrom, pick } from './utils'
|
|
18
18
|
|
|
19
19
|
export const matchContext = React.createContext<string | undefined>(undefined)
|
|
20
20
|
|
|
@@ -221,11 +221,15 @@ export interface MatchRouteOptions {
|
|
|
221
221
|
|
|
222
222
|
export type UseMatchRouteOptions<
|
|
223
223
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
224
|
-
TFrom extends RoutePaths<TRouteTree> =
|
|
224
|
+
TFrom extends RoutePaths<TRouteTree> = RoutePaths<TRouteTree>,
|
|
225
225
|
TTo extends string = '',
|
|
226
|
-
TMaskFrom extends RoutePaths<TRouteTree> =
|
|
226
|
+
TMaskFrom extends RoutePaths<TRouteTree> = TFrom,
|
|
227
227
|
TMaskTo extends string = '',
|
|
228
|
-
> =
|
|
228
|
+
> = DeepOptional<
|
|
229
|
+
ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,
|
|
230
|
+
'search' | 'params'
|
|
231
|
+
> &
|
|
232
|
+
MatchRouteOptions
|
|
229
233
|
|
|
230
234
|
export function useMatchRoute<
|
|
231
235
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
@@ -235,9 +239,9 @@ export function useMatchRoute<
|
|
|
235
239
|
|
|
236
240
|
return React.useCallback(
|
|
237
241
|
<
|
|
238
|
-
TFrom extends RoutePaths<TRouteTree> =
|
|
242
|
+
TFrom extends RoutePaths<TRouteTree> = RoutePaths<TRouteTree>,
|
|
239
243
|
TTo extends string = '',
|
|
240
|
-
TMaskFrom extends RoutePaths<TRouteTree> =
|
|
244
|
+
TMaskFrom extends RoutePaths<TRouteTree> = TFrom,
|
|
241
245
|
TMaskTo extends string = '',
|
|
242
246
|
TResolved extends string = ResolveRelativePath<TFrom, NoInfer<TTo>>,
|
|
243
247
|
>(
|
package/src/RouterProvider.tsx
CHANGED
|
@@ -44,7 +44,9 @@ export type NavigateFn<TRouteTree extends AnyRoute> = <
|
|
|
44
44
|
) => Promise<void>
|
|
45
45
|
|
|
46
46
|
export type BuildLocationFn<TRouteTree extends AnyRoute> = (
|
|
47
|
-
opts: ToOptions<TRouteTree
|
|
47
|
+
opts: ToOptions<TRouteTree> & {
|
|
48
|
+
leaveParams?: boolean
|
|
49
|
+
},
|
|
48
50
|
) => ParsedLocation
|
|
49
51
|
|
|
50
52
|
export type InjectedHtmlEntry = string | (() => Promise<string> | string)
|
package/src/fileRoute.ts
CHANGED
|
@@ -77,12 +77,11 @@ export type ResolveFilePath<
|
|
|
77
77
|
export type FileRoutePath<
|
|
78
78
|
TParentRoute extends AnyRoute,
|
|
79
79
|
TFilePath extends string,
|
|
80
|
-
> =
|
|
81
|
-
|
|
80
|
+
> = ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}`
|
|
81
|
+
? ''
|
|
82
|
+
: ResolveFilePath<TParentRoute, TFilePath> extends `/_${infer _}`
|
|
82
83
|
? ''
|
|
83
|
-
: ResolveFilePath<TParentRoute, TFilePath>
|
|
84
|
-
? ''
|
|
85
|
-
: ResolveFilePath<TParentRoute, TFilePath>
|
|
84
|
+
: ResolveFilePath<TParentRoute, TFilePath>
|
|
86
85
|
|
|
87
86
|
export class FileRoute<
|
|
88
87
|
TFilePath extends keyof FileRoutesByPath,
|
package/src/link.tsx
CHANGED
|
@@ -167,10 +167,11 @@ export type ToSubOptions<
|
|
|
167
167
|
type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo)
|
|
168
168
|
|
|
169
169
|
type ParamVariant = 'PATH' | 'SEARCH'
|
|
170
|
-
type ExcludeRootSearchSchema<
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
170
|
+
type ExcludeRootSearchSchema<T, Excluded = Exclude<T, RootSearchSchema>> = [
|
|
171
|
+
Excluded,
|
|
172
|
+
] extends [never]
|
|
173
|
+
? {}
|
|
174
|
+
: Excluded
|
|
174
175
|
|
|
175
176
|
type PostProcessParams<
|
|
176
177
|
T,
|
package/src/path.ts
CHANGED
|
@@ -122,11 +122,18 @@ export function parsePathname(pathname?: string): Segment[] {
|
|
|
122
122
|
return segments
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
path
|
|
127
|
-
params: any
|
|
128
|
-
leaveWildcards
|
|
129
|
-
|
|
125
|
+
interface InterpolatePathOptions {
|
|
126
|
+
path?: string
|
|
127
|
+
params: any
|
|
128
|
+
leaveWildcards?: boolean
|
|
129
|
+
leaveParams?: boolean
|
|
130
|
+
}
|
|
131
|
+
export function interpolatePath({
|
|
132
|
+
path,
|
|
133
|
+
params,
|
|
134
|
+
leaveWildcards,
|
|
135
|
+
leaveParams,
|
|
136
|
+
}: InterpolatePathOptions) {
|
|
130
137
|
const interpolatedPathSegments = parsePathname(path)
|
|
131
138
|
|
|
132
139
|
return joinPaths(
|
|
@@ -138,6 +145,10 @@ export function interpolatePath(
|
|
|
138
145
|
}
|
|
139
146
|
|
|
140
147
|
if (segment.type === 'param') {
|
|
148
|
+
if (leaveParams) {
|
|
149
|
+
const value = params[segment.value]
|
|
150
|
+
return `${segment.value}${value ?? ''}`
|
|
151
|
+
}
|
|
141
152
|
return params![segment.value.substring(1)] ?? 'undefined'
|
|
142
153
|
}
|
|
143
154
|
|
package/src/route.ts
CHANGED
|
@@ -342,12 +342,11 @@ export type MergeFromFromParent<T, U> = IsAny<T, U, T & U>
|
|
|
342
342
|
export type ResolveAllParams<
|
|
343
343
|
TParentRoute extends AnyRoute,
|
|
344
344
|
TParams extends AnyPathParams,
|
|
345
|
-
> =
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
>
|
|
345
|
+
> = Record<never, string> extends TParentRoute['types']['allParams']
|
|
346
|
+
? TParams
|
|
347
|
+
: Expand<
|
|
348
|
+
UnionToIntersection<TParentRoute['types']['allParams'] & TParams> & {}
|
|
349
|
+
>
|
|
351
350
|
|
|
352
351
|
export type RouteConstraints = {
|
|
353
352
|
TParentRoute: AnyRoute
|