@tanstack/react-router 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/cjs/link.js +1 -4
- package/build/cjs/link.js.map +1 -1
- package/build/cjs/useNavigate.js.map +1 -1
- package/build/cjs/utils.js +2 -0
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +3 -4
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +355 -355
- package/build/types/RouterProvider.d.ts +1 -1
- package/build/types/link.d.ts +21 -24
- package/build/types/useNavigate.d.ts +6 -6
- package/build/types/utils.d.ts +1 -0
- package/build/umd/index.development.js +3 -4
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/RouterProvider.tsx +4 -4
- package/src/link.tsx +67 -89
- package/src/useNavigate.tsx +21 -22
- package/src/utils.ts +3 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouterProvider.js","sources":["../../src/RouterProvider.tsx"],"sourcesContent":["import * as React from 'react'\nimport warning from 'tiny-warning'\nimport { useStore } from '@tanstack/react-store'\nimport { Matches } from './Matches'\nimport { NavigateOptions, ResolveRelativePath, ToOptions } from './link'\nimport { ParsedLocation } from './location'\nimport { AnyRoute } from './route'\nimport { RouteById, RoutePaths } from './routeInfo'\nimport {\n BuildNextOptions,\n RegisteredRouter,\n Router,\n RouterOptions,\n RouterState,\n} from './router'\nimport { NoInfer, pick, useLayoutEffect } from './utils'\nimport { MatchRouteOptions } from './Matches'\nimport { RouteMatch } from './Matches'\n\nconst useTransition =\n React.useTransition ||\n (() => [\n false,\n (cb) => {\n cb()\n },\n ])\n\nexport interface CommitLocationOptions {\n replace?: boolean\n resetScroll?: boolean\n startTransition?: boolean\n}\n\nexport interface MatchLocation {\n to?: string | number | null\n fuzzy?: boolean\n caseSensitive?: boolean\n from?: string\n}\n\nexport type NavigateFn<TRouteTree extends AnyRoute> = <\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = TFrom,\n TMaskTo extends string = '',\n>(\n opts: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n) => Promise<void>\n\nexport type MatchRouteFn<TRouteTree extends AnyRoute> = <\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n>(\n location: ToOptions<TRouteTree, TFrom, TTo>,\n opts?: MatchRouteOptions,\n) => false | RouteById<TRouteTree, TResolved>['types']['allParams']\n\nexport type BuildLocationFn<TRouteTree extends AnyRoute> = (\n opts: ToOptions<TRouteTree>,\n) => ParsedLocation\n\nexport type InjectedHtmlEntry = string | (() => Promise<string> | string)\n\nexport let routerContext = React.createContext<Router<any>>(null!)\n\nif (typeof document !== 'undefined') {\n if (window.__TSR_ROUTER_CONTEXT__) {\n routerContext = window.__TSR_ROUTER_CONTEXT__\n } else {\n window.__TSR_ROUTER_CONTEXT__ = routerContext as any\n }\n}\n\nexport function RouterProvider<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TDehydrated extends Record<string, any> = Record<string, any>,\n>({ router, ...rest }: RouterProps<TRouteTree, TDehydrated>) {\n // Allow the router to update options on the router instance\n router.update({\n ...router.options,\n ...rest,\n context: {\n ...router.options.context,\n ...rest?.context,\n },\n } as any)\n\n const matches = router.options.InnerWrap ? (\n <router.options.InnerWrap>\n <Matches />\n </router.options.InnerWrap>\n ) : (\n <Matches />\n )\n\n const provider = (\n <routerContext.Provider value={router}>\n {matches}\n <Transitioner />\n </routerContext.Provider>\n )\n\n if (router.options.Wrap) {\n return <router.options.Wrap>{provider}</router.options.Wrap>\n }\n\n return provider\n}\n\nfunction Transitioner() {\n const mountLoadCount = React.useRef(0)\n const router = useRouter()\n const routerState = useRouterState({\n select: (s) =>\n pick(s, ['isLoading', 'location', 'resolvedLocation', 'isTransitioning']),\n })\n\n const [isTransitioning, startReactTransition] = useTransition()\n\n router.startReactTransition = startReactTransition\n\n React.useEffect(() => {\n if (isTransitioning) {\n router.__store.setState((s) => ({\n ...s,\n isTransitioning,\n }))\n }\n }, [isTransitioning])\n\n const tryLoad = () => {\n const apply = (cb: () => void) => {\n if (!routerState.isTransitioning) {\n startReactTransition(() => cb())\n } else {\n cb()\n }\n }\n\n apply(() => {\n try {\n router.load()\n } catch (err) {\n console.error(err)\n }\n })\n }\n\n useLayoutEffect(() => {\n const unsub = router.history.subscribe(() => {\n router.latestLocation = router.parseLocation(router.latestLocation)\n if (routerState.location !== router.latestLocation) {\n tryLoad()\n }\n })\n\n const nextLocation = router.buildLocation({\n search: true,\n params: true,\n hash: true,\n state: true,\n })\n\n if (routerState.location.href !== nextLocation.href) {\n router.commitLocation({ ...nextLocation, replace: true })\n }\n\n return () => {\n unsub()\n }\n }, [router.history])\n\n useLayoutEffect(() => {\n if (\n (React.useTransition as any)\n ? routerState.isTransitioning && !isTransitioning\n : true &&\n !routerState.isLoading &&\n routerState.resolvedLocation !== routerState.location\n ) {\n router.emit({\n type: 'onResolved',\n fromLocation: routerState.resolvedLocation,\n toLocation: routerState.location,\n pathChanged:\n routerState.location!.href !== routerState.resolvedLocation?.href,\n })\n\n if ((document as any).querySelector) {\n if (routerState.location.hash !== '') {\n const el = document.getElementById(\n routerState.location.hash,\n ) as HTMLElement | null\n if (el) {\n el.scrollIntoView()\n }\n }\n }\n\n router.__store.setState((s) => ({\n ...s,\n isTransitioning: false,\n resolvedLocation: s.location,\n }))\n }\n }, [\n routerState.isTransitioning,\n isTransitioning,\n routerState.isLoading,\n routerState.resolvedLocation,\n routerState.location,\n ])\n\n useLayoutEffect(() => {\n if (!window.__TSR_DEHYDRATED__ && !mountLoadCount.current) {\n mountLoadCount.current++\n tryLoad()\n }\n }, [])\n\n return null\n}\n\nexport function getRouteMatch<TRouteTree extends AnyRoute>(\n state: RouterState<TRouteTree>,\n id: string,\n): undefined | RouteMatch<TRouteTree> {\n return [\n ...state.cachedMatches,\n ...(state.pendingMatches ?? []),\n ...state.matches,\n ].find((d) => d.id === id)\n}\n\nexport function useRouterState<\n TSelected = RouterState<RegisteredRouter['routeTree']>,\n>(opts?: {\n select: (state: RouterState<RegisteredRouter['routeTree']>) => TSelected\n}): TSelected {\n const router = useRouter()\n return useStore(router.__store, opts?.select as any)\n}\n\nexport type RouterProps<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TDehydrated extends Record<string, any> = Record<string, any>,\n> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> & {\n router: Router<TRouteTree>\n context?: Partial<RouterOptions<TRouteTree, TDehydrated>['context']>\n}\n\nexport function useRouter<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n>(): 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(value, 'useRouter must be used inside a <RouterProvider> component!')\n return value as any\n}\n"],"names":["useTransition","React","cb","routerContext","createContext","document","window","__TSR_ROUTER_CONTEXT__","RouterProvider","router","rest","update","options","context","matches","InnerWrap","createElement","Matches","provider","Provider","value","Transitioner","Wrap","mountLoadCount","useRef","useRouter","routerState","useRouterState","select","s","pick","isTransitioning","startReactTransition","useEffect","__store","setState","tryLoad","apply","load","err","console","error","useLayoutEffect","unsub","history","subscribe","latestLocation","parseLocation","location","nextLocation","buildLocation","search","params","hash","state","href","commitLocation","replace","isLoading","resolvedLocation","emit","type","fromLocation","toLocation","pathChanged","querySelector","el","getElementById","scrollIntoView","__TSR_DEHYDRATED__","current","getRouteMatch","id","cachedMatches","pendingMatches","find","d","opts","useStore","resolvedContext","useContext","warning"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,MAAMA,aAAa,GAC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EAAA,OAAO,IAAI,CAAA;AACb,CAAA;AAEO,SAASmC,aAAaA,CAC3BjB,KAA8B,EAC9BkB,EAAU,EAC0B;AACpC,EAAA,OAAO,CACL,GAAGlB,KAAK,CAACmB,aAAa,EACtB,IAAInB,KAAK,CAACoB,cAAc,IAAI,EAAE,GAC9B,GAAGpB,KAAK,CAACxC,OAAO,CACjB,CAAC6D,IAAI,CAAEC,CAAC,IAAKA,CAAC,CAACJ,EAAE,KAAKA,EAAE,CAAC,CAAA;AAC5B,CAAA;AAEO,SAAS7C,cAAcA,CAE5BkD,IAED,EAAa;AACZ,EAAA,MAAMpE,MAAM,GAAGgB,SAAS,EAAE,CAAA;EAC1B,OAAOqD,mBAAQ,CAACrE,MAAM,CAACyB,OAAO,EAAE2C,IAAI,EAAEjD,MAAa,CAAC,CAAA;AACtD,CAAA;AAUO,SAASH,SAASA,GAED;AACtB,EAAA,MAAMsD,eAAe,GACnB,OAAO1E,QAAQ,KAAK,WAAW,GAC3BC,MAAM,CAACC,sBAAsB,IAAIJ,qBAAa,GAC9CA,qBAAa,CAAA;AACnB,EAAA,MAAMiB,KAAK,GAAGnB,gBAAK,CAAC+E,UAAU,CAACD,eAAe,CAAC,CAAA;AAC/CE,EAAAA,OAAO,CAAC7D,KAAK,EAAE,6DAA6D,CAAC,CAAA;AAC7E,EAAA,OAAOA,KAAK,CAAA;AACd;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"RouterProvider.js","sources":["../../src/RouterProvider.tsx"],"sourcesContent":["import * as React from 'react'\nimport warning from 'tiny-warning'\nimport { useStore } from '@tanstack/react-store'\nimport { Matches } from './Matches'\nimport { NavigateOptions, ResolveRelativePath, ToOptions } from './link'\nimport { ParsedLocation } from './location'\nimport { AnyRoute } from './route'\nimport { RouteById, RoutePaths } from './routeInfo'\nimport {\n BuildNextOptions,\n RegisteredRouter,\n Router,\n RouterOptions,\n RouterState,\n} from './router'\nimport { NoInfer, pick, useLayoutEffect } from './utils'\nimport { MatchRouteOptions } from './Matches'\nimport { RouteMatch } from './Matches'\n\nconst useTransition =\n React.useTransition ||\n (() => [\n false,\n (cb) => {\n cb()\n },\n ])\n\nexport interface CommitLocationOptions {\n replace?: boolean\n resetScroll?: boolean\n startTransition?: boolean\n}\n\nexport interface MatchLocation {\n to?: string | number | null\n fuzzy?: boolean\n caseSensitive?: boolean\n from?: string\n}\n\nexport type NavigateFn<TRouteTree extends AnyRoute> = <\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string | undefined = undefined,\n>(\n opts: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n) => Promise<void>\n\nexport type MatchRouteFn<TRouteTree extends AnyRoute> = <\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n>(\n location: ToOptions<TRouteTree, TFrom, TTo>,\n opts?: MatchRouteOptions,\n) => false | RouteById<TRouteTree, TResolved>['types']['allParams']\n\nexport type BuildLocationFn<TRouteTree extends AnyRoute> = (\n opts: ToOptions<TRouteTree>,\n) => ParsedLocation\n\nexport type InjectedHtmlEntry = string | (() => Promise<string> | string)\n\nexport let routerContext = React.createContext<Router<any>>(null!)\n\nif (typeof document !== 'undefined') {\n if (window.__TSR_ROUTER_CONTEXT__) {\n routerContext = window.__TSR_ROUTER_CONTEXT__\n } else {\n window.__TSR_ROUTER_CONTEXT__ = routerContext as any\n }\n}\n\nexport function RouterProvider<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TDehydrated extends Record<string, any> = Record<string, any>,\n>({ router, ...rest }: RouterProps<TRouteTree, TDehydrated>) {\n // Allow the router to update options on the router instance\n router.update({\n ...router.options,\n ...rest,\n context: {\n ...router.options.context,\n ...rest?.context,\n },\n } as any)\n\n const matches = router.options.InnerWrap ? (\n <router.options.InnerWrap>\n <Matches />\n </router.options.InnerWrap>\n ) : (\n <Matches />\n )\n\n const provider = (\n <routerContext.Provider value={router}>\n {matches}\n <Transitioner />\n </routerContext.Provider>\n )\n\n if (router.options.Wrap) {\n return <router.options.Wrap>{provider}</router.options.Wrap>\n }\n\n return provider\n}\n\nfunction Transitioner() {\n const mountLoadCount = React.useRef(0)\n const router = useRouter()\n const routerState = useRouterState({\n select: (s) =>\n pick(s, ['isLoading', 'location', 'resolvedLocation', 'isTransitioning']),\n })\n\n const [isTransitioning, startReactTransition] = useTransition()\n\n router.startReactTransition = startReactTransition\n\n React.useEffect(() => {\n if (isTransitioning) {\n router.__store.setState((s) => ({\n ...s,\n isTransitioning,\n }))\n }\n }, [isTransitioning])\n\n const tryLoad = () => {\n const apply = (cb: () => void) => {\n if (!routerState.isTransitioning) {\n startReactTransition(() => cb())\n } else {\n cb()\n }\n }\n\n apply(() => {\n try {\n router.load()\n } catch (err) {\n console.error(err)\n }\n })\n }\n\n useLayoutEffect(() => {\n const unsub = router.history.subscribe(() => {\n router.latestLocation = router.parseLocation(router.latestLocation)\n if (routerState.location !== router.latestLocation) {\n tryLoad()\n }\n })\n\n const nextLocation = router.buildLocation({\n search: true,\n params: true,\n hash: true,\n state: true,\n })\n\n if (routerState.location.href !== nextLocation.href) {\n router.commitLocation({ ...nextLocation, replace: true })\n }\n\n return () => {\n unsub()\n }\n }, [router.history])\n\n useLayoutEffect(() => {\n if (\n (React.useTransition as any)\n ? routerState.isTransitioning && !isTransitioning\n : true &&\n !routerState.isLoading &&\n routerState.resolvedLocation !== routerState.location\n ) {\n router.emit({\n type: 'onResolved',\n fromLocation: routerState.resolvedLocation,\n toLocation: routerState.location,\n pathChanged:\n routerState.location!.href !== routerState.resolvedLocation?.href,\n })\n\n if ((document as any).querySelector) {\n if (routerState.location.hash !== '') {\n const el = document.getElementById(\n routerState.location.hash,\n ) as HTMLElement | null\n if (el) {\n el.scrollIntoView()\n }\n }\n }\n\n router.__store.setState((s) => ({\n ...s,\n isTransitioning: false,\n resolvedLocation: s.location,\n }))\n }\n }, [\n routerState.isTransitioning,\n isTransitioning,\n routerState.isLoading,\n routerState.resolvedLocation,\n routerState.location,\n ])\n\n useLayoutEffect(() => {\n if (!window.__TSR_DEHYDRATED__ && !mountLoadCount.current) {\n mountLoadCount.current++\n tryLoad()\n }\n }, [])\n\n return null\n}\n\nexport function getRouteMatch<TRouteTree extends AnyRoute>(\n state: RouterState<TRouteTree>,\n id: string,\n): undefined | RouteMatch<TRouteTree> {\n return [\n ...state.cachedMatches,\n ...(state.pendingMatches ?? []),\n ...state.matches,\n ].find((d) => d.id === id)\n}\n\nexport function useRouterState<\n TSelected = RouterState<RegisteredRouter['routeTree']>,\n>(opts?: {\n select: (state: RouterState<RegisteredRouter['routeTree']>) => TSelected\n}): TSelected {\n const router = useRouter()\n return useStore(router.__store, opts?.select as any)\n}\n\nexport type RouterProps<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TDehydrated extends Record<string, any> = Record<string, any>,\n> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> & {\n router: Router<TRouteTree>\n context?: Partial<RouterOptions<TRouteTree, TDehydrated>['context']>\n}\n\nexport function useRouter<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n>(): 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(value, 'useRouter must be used inside a <RouterProvider> component!')\n return value as any\n}\n"],"names":["useTransition","React","cb","routerContext","createContext","document","window","__TSR_ROUTER_CONTEXT__","RouterProvider","router","rest","update","options","context","matches","InnerWrap","createElement","Matches","provider","Provider","value","Transitioner","Wrap","mountLoadCount","useRef","useRouter","routerState","useRouterState","select","s","pick","isTransitioning","startReactTransition","useEffect","__store","setState","tryLoad","apply","load","err","console","error","useLayoutEffect","unsub","history","subscribe","latestLocation","parseLocation","location","nextLocation","buildLocation","search","params","hash","state","href","commitLocation","replace","isLoading","resolvedLocation","emit","type","fromLocation","toLocation","pathChanged","querySelector","el","getElementById","scrollIntoView","__TSR_DEHYDRATED__","current","getRouteMatch","id","cachedMatches","pendingMatches","find","d","opts","useStore","resolvedContext","useContext","warning"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,MAAMA,aAAa,GACjBC,gBAAK,CAACD,aAAa,KAClB,MAAM,CACL,KAAK,EACJE,EAAE,IAAK;AACNA,EAAAA,EAAE,EAAE,CAAA;AACN,CAAC,CACF,CAAC,CAAA;AAuCOC,qBAAa,gBAAGF,gBAAK,CAACG,aAAa,CAAc,IAAK,EAAC;AAElE,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;EACnC,IAAIC,MAAM,CAACC,sBAAsB,EAAE;IACjCJ,qBAAa,GAAGG,MAAM,CAACC,sBAAsB,CAAA;AAC/C,GAAC,MAAM;IACLD,MAAM,CAACC,sBAAsB,GAAGJ,qBAAoB,CAAA;AACtD,GAAA;AACF,CAAA;AAEO,SAASK,cAAcA,CAG5B;EAAEC,MAAM;EAAE,GAAGC,IAAAA;AAA2C,CAAC,EAAE;AAC3D;EACAD,MAAM,CAACE,MAAM,CAAC;IACZ,GAAGF,MAAM,CAACG,OAAO;AACjB,IAAA,GAAGF,IAAI;AACPG,IAAAA,OAAO,EAAE;AACP,MAAA,GAAGJ,MAAM,CAACG,OAAO,CAACC,OAAO;AACzB,MAAA,GAAGH,IAAI,EAAEG,OAAAA;AACX,KAAA;AACF,GAAQ,CAAC,CAAA;AAET,EAAA,MAAMC,OAAO,GAAGL,MAAM,CAACG,OAAO,CAACG,SAAS,gBACtCd,gBAAA,CAAAe,aAAA,CAACP,MAAM,CAACG,OAAO,CAACG,SAAS,EAAA,IAAA,eACvBd,gBAAA,CAAAe,aAAA,CAACC,eAAO,EAAE,IAAA,CACc,CAAC,gBAE3BhB,gBAAA,CAAAe,aAAA,CAACC,eAAO,MAAE,CACX,CAAA;EAED,MAAMC,QAAQ,gBACZjB,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,MAAM;IACpB,IAAI,CAACpC,MAAM,CAAC+D,kBAAkB,IAAI,CAAC9C,cAAc,CAAC+C,OAAO,EAAE;MACzD/C,cAAc,CAAC+C,OAAO,EAAE,CAAA;AACxBlC,MAAAA,OAAO,EAAE,CAAA;AACX,KAAA;GACD,EAAE,EAAE,CAAC,CAAA;AAEN,EAAA,OAAO,IAAI,CAAA;AACb,CAAA;AAEO,SAASmC,aAAaA,CAC3BjB,KAA8B,EAC9BkB,EAAU,EAC0B;AACpC,EAAA,OAAO,CACL,GAAGlB,KAAK,CAACmB,aAAa,EACtB,IAAInB,KAAK,CAACoB,cAAc,IAAI,EAAE,GAC9B,GAAGpB,KAAK,CAACxC,OAAO,CACjB,CAAC6D,IAAI,CAAEC,CAAC,IAAKA,CAAC,CAACJ,EAAE,KAAKA,EAAE,CAAC,CAAA;AAC5B,CAAA;AAEO,SAAS7C,cAAcA,CAE5BkD,IAED,EAAa;AACZ,EAAA,MAAMpE,MAAM,GAAGgB,SAAS,EAAE,CAAA;EAC1B,OAAOqD,mBAAQ,CAACrE,MAAM,CAACyB,OAAO,EAAE2C,IAAI,EAAEjD,MAAa,CAAC,CAAA;AACtD,CAAA;AAUO,SAASH,SAASA,GAED;AACtB,EAAA,MAAMsD,eAAe,GACnB,OAAO1E,QAAQ,KAAK,WAAW,GAC3BC,MAAM,CAACC,sBAAsB,IAAIJ,qBAAa,GAC9CA,qBAAa,CAAA;AACnB,EAAA,MAAMiB,KAAK,GAAGnB,gBAAK,CAAC+E,UAAU,CAACD,eAAe,CAAC,CAAA;AAC/CE,EAAAA,OAAO,CAAC7D,KAAK,EAAE,6DAA6D,CAAC,CAAA;AAC7E,EAAA,OAAOA,KAAK,CAAA;AACd;;;;;;;"}
|
package/build/cjs/link.js
CHANGED
|
@@ -36,10 +36,7 @@ function _interopNamespaceDefault(e) {
|
|
|
36
36
|
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
37
37
|
|
|
38
38
|
const preloadWarning = 'Error preloading route! ☝️';
|
|
39
|
-
function useLinkProps({
|
|
40
|
-
from,
|
|
41
|
-
...options
|
|
42
|
-
}) {
|
|
39
|
+
function useLinkProps(options) {
|
|
43
40
|
const router = RouterProvider.useRouter();
|
|
44
41
|
const matchPathname = Matches.useMatch({
|
|
45
42
|
strict: false,
|
package/build/cjs/link.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.js","sources":["../../src/link.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useMatch } from './Matches'\nimport { useRouter, useRouterState } from './RouterProvider'\nimport { Trim } from './fileRoute'\nimport { AnyRoute, ReactNode } from './route'\nimport {\n AllParams,\n FullSearchSchema,\n RouteByPath,\n RouteIds,\n RoutePaths,\n} from './routeInfo'\nimport { RegisteredRouter } from './router'\nimport { LinkProps, UseLinkPropsOptions } from './useNavigate'\nimport {\n Expand,\n NoInfer,\n NonNullableUpdater,\n PickRequired,\n UnionToIntersection,\n Updater,\n deepEqual,\n functionalUpdate,\n} from './utils'\nimport { HistoryState } from '@tanstack/history'\n\nexport type CleanPath<T extends string> = T extends `${infer L}//${infer R}`\n ? CleanPath<`${CleanPath<L>}/${CleanPath<R>}`>\n : T extends `${infer L}//`\n ? `${CleanPath<L>}/`\n : T extends `//${infer L}`\n ? `/${CleanPath<L>}`\n : T\n\nexport type Split<S, TIncludeTrailingSlash = true> = S extends unknown\n ? string extends S\n ? string[]\n : S extends string\n ? CleanPath<S> extends ''\n ? []\n : TIncludeTrailingSlash extends true\n ? CleanPath<S> extends `${infer T}/`\n ? [...Split<T>, '/']\n : CleanPath<S> extends `/${infer U}`\n ? Split<U>\n : CleanPath<S> extends `${infer T}/${infer U}`\n ? [...Split<T>, ...Split<U>]\n : [S]\n : CleanPath<S> extends `${infer T}/${infer U}`\n ? [...Split<T>, ...Split<U>]\n : S extends string\n ? [S]\n : never\n : never\n : never\n\nexport type ParsePathParams<T extends string> = keyof {\n [K in Trim<Split<T>[number], '_'> as K extends `$${infer L}` ? L : never]: K\n}\n\nexport type Join<T, Delimiter extends string = '/'> = T extends []\n ? ''\n : T extends [infer L extends string]\n ? L\n : T extends [infer L extends string, ...infer Tail extends [...string[]]]\n ? CleanPath<`${L}${Delimiter}${Join<Tail>}`>\n : never\n\nexport type Last<T extends any[]> = T extends [...infer _, infer L] ? L : never\n\nexport type RelativeToPathAutoComplete<\n AllPaths extends string,\n TFrom extends string,\n TTo extends string,\n SplitPaths extends string[] = Split<AllPaths, false>,\n> = TTo extends `..${infer _}`\n ? SplitPaths extends [\n ...Split<ResolveRelativePath<TFrom, TTo>, false>,\n ...infer TToRest,\n ]\n ? `${CleanPath<\n Join<\n [\n ...Split<TTo, false>,\n ...(\n | TToRest\n | (Split<\n ResolveRelativePath<TFrom, TTo>,\n false\n >['length'] extends 1\n ? never\n : ['../'])\n ),\n ]\n >\n >}`\n : never\n : TTo extends `./${infer RestTTo}`\n ? SplitPaths extends [\n ...Split<TFrom, false>,\n ...Split<RestTTo, false>,\n ...infer RestPath,\n ]\n ? `${TTo}${Join<RestPath>}`\n : never\n :\n | (TFrom extends `/`\n ? never\n : SplitPaths extends [...Split<TFrom, false>, ...infer RestPath]\n ? Join<RestPath> extends { length: 0 }\n ? never\n : './'\n : never)\n | (TFrom extends `/` ? never : '../')\n | AllPaths\n\nexport type NavigateOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = TFrom,\n TMaskTo extends string = '',\n> = ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // `replace` is a boolean that determines whether the navigation should replace the current history entry or push a new one.\n replace?: boolean\n resetScroll?: boolean\n // If set to `true`, the link's underlying navigate() call will be wrapped in a `React.startTransition` call. Defaults to `true`.\n startTransition?: boolean\n}\n\nexport type ToOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n> = ToSubOptions<TRouteTree, TFrom, TTo> & {\n mask?: ToMaskOptions<TRouteTree, TMaskFrom, TMaskTo>\n}\n\nexport type ToMaskOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n> = ToSubOptions<TRouteTree, TMaskFrom, TMaskTo> & {\n unmaskOnReload?: boolean\n}\n\nexport type ToSubOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n> = {\n to?: ToPathOption<TRouteTree, TFrom, TTo>\n // The new has string or a function to update it\n hash?: true | Updater<string>\n // State to pass to the history stack\n state?: true | NonNullableUpdater<HistoryState>\n // The source route path. This is automatically set when using route-level APIs, but for type-safe relative routing on the router itself, this is required\n from?: TFrom\n // // When using relative route paths, this option forces resolution from the current path, instead of the route API's path or `from` path\n} & CheckPath<TRouteTree, NoInfer<TResolved>, {}> &\n SearchParamOptions<TRouteTree, TFrom, TTo, TResolved> &\n PathParamOptions<TRouteTree, TFrom, TResolved>\n\nexport type SearchParamOptions<\n TRouteTree extends AnyRoute,\n TFrom,\n TTo,\n TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n TFromSearchEnsured = '/' extends TFrom\n ? FullSearchSchema<TRouteTree>\n : Expand<\n PickRequired<\n RouteByPath<TRouteTree, TFrom>['types']['fullSearchSchema']\n >\n >,\n TFromSearchOptional = Omit<\n FullSearchSchema<TRouteTree>,\n keyof TFromSearchEnsured\n >,\n TFromSearch = Expand<TFromSearchEnsured & TFromSearchOptional>,\n TToSearch = '' extends TTo\n ? FullSearchSchema<TRouteTree>\n : Expand<RouteByPath<TRouteTree, TResolved>['types']['fullSearchSchema']>,\n> = keyof PickRequired<TToSearch> extends never\n ? {\n search?: true | SearchReducer<TFromSearch, TToSearch>\n }\n : {\n search: TFromSearchEnsured extends PickRequired<TToSearch>\n ? true | SearchReducer<TFromSearch, TToSearch>\n : SearchReducer<TFromSearch, TToSearch>\n }\n\ntype SearchReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo)\n\nexport type PathParamOptions<\n TRouteTree extends AnyRoute,\n TFrom,\n TTo,\n TFromParamsEnsured = Expand<\n UnionToIntersection<\n PickRequired<RouteByPath<TRouteTree, TFrom>['types']['allParams']>\n >\n >,\n TFromParamsOptional = Omit<AllParams<TRouteTree>, keyof TFromParamsEnsured>,\n TFromParams = Expand<TFromParamsOptional & TFromParamsEnsured>,\n TToParams = Expand<RouteByPath<TRouteTree, TTo>['types']['allParams']>,\n> = never extends TToParams\n ? {\n params?: true | ParamsReducer<Partial<TFromParams>, Partial<TFromParams>>\n }\n : keyof PickRequired<TToParams> extends never\n ? {\n params?: true | ParamsReducer<TFromParams, TToParams>\n }\n : {\n params: TFromParamsEnsured extends PickRequired<TToParams>\n ? true | ParamsReducer<TFromParams, TToParams>\n : ParamsReducer<TFromParams, TToParams>\n }\n\ntype ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo)\n\nexport type ToPathOption<\n TRouteTree extends AnyRoute = AnyRoute,\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n> =\n | TTo\n | RelativeToPathAutoComplete<\n RoutePaths<TRouteTree>,\n NoInfer<TFrom> extends string ? NoInfer<TFrom> : '',\n NoInfer<TTo> & string\n >\n\nexport type ToIdOption<\n TRouteTree extends AnyRoute = AnyRoute,\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n> =\n | TTo\n | RelativeToPathAutoComplete<\n RouteIds<TRouteTree>,\n NoInfer<TFrom> extends string ? NoInfer<TFrom> : '',\n NoInfer<TTo> & string\n >\n\nexport interface ActiveOptions {\n exact?: boolean\n includeHash?: boolean\n includeSearch?: boolean\n}\n\nexport type LinkOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = TFrom,\n TMaskTo extends string = '',\n> = NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // The standard anchor tag target attribute\n target?: HTMLAnchorElement['target']\n // Defaults to `{ exact: false, includeHash: false }`\n activeOptions?: ActiveOptions\n // If set, will preload the linked route on hover and cache it for this many milliseconds in hopes that the user will eventually navigate there.\n preload?: false | 'intent'\n // Delay intent preloading by this many milliseconds. If the intent exits before this delay, the preload will be cancelled.\n preloadDelay?: number\n // If true, will render the link without the href attribute\n disabled?: boolean\n}\n\nexport type CheckRelativePath<\n TRouteTree extends AnyRoute,\n TFrom,\n TTo,\n> = TTo extends string\n ? TFrom extends string\n ? ResolveRelativePath<TFrom, TTo> extends RoutePaths<TRouteTree>\n ? {}\n : {\n Error: `${TFrom} + ${TTo} resolves to ${ResolveRelativePath<\n TFrom,\n TTo\n >}, which is not a valid route path.`\n 'Valid Route Paths': RoutePaths<TRouteTree>\n }\n : {}\n : {}\n\nexport type CheckPath<TRouteTree extends AnyRoute, TPath, TPass> = Exclude<\n TPath,\n RoutePaths<TRouteTree>\n> extends never\n ? TPass\n : CheckPathError<TRouteTree, Exclude<TPath, RoutePaths<TRouteTree>>>\n\nexport type CheckPathError<TRouteTree extends AnyRoute, TInvalids> = {\n to: RoutePaths<TRouteTree>\n}\n\nexport type CheckId<TRouteTree extends AnyRoute, TPath, TPass> = Exclude<\n TPath,\n RouteIds<TRouteTree>\n> extends never\n ? TPass\n : CheckIdError<TRouteTree, Exclude<TPath, RouteIds<TRouteTree>>>\n\nexport type CheckIdError<TRouteTree extends AnyRoute, TInvalids> = {\n Error: `${TInvalids extends string\n ? TInvalids\n : never} is not a valid route ID.`\n 'Valid Route IDs': RouteIds<TRouteTree>\n}\n\nexport type ResolveRelativePath<TFrom, TTo = '.'> = TFrom extends string\n ? TTo extends string\n ? TTo extends '.'\n ? TFrom\n : TTo extends `./`\n ? Join<[TFrom, '/']>\n : TTo extends `./${infer TRest}`\n ? ResolveRelativePath<TFrom, TRest>\n : TTo extends `/${infer TRest}`\n ? TTo\n : Split<TTo> extends ['..', ...infer ToRest]\n ? Split<TFrom> extends [...infer FromRest, infer FromTail]\n ? ToRest extends ['/']\n ? Join<[...FromRest, '/']>\n : ResolveRelativePath<Join<FromRest>, Join<ToRest>>\n : never\n : Split<TTo> extends ['.', ...infer ToRest]\n ? ToRest extends ['/']\n ? Join<[TFrom, '/']>\n : ResolveRelativePath<TFrom, Join<ToRest>>\n : CleanPath<Join<['/', ...Split<TFrom>, ...Split<TTo>]>>\n : never\n : never\n\ntype LinkCurrentTargetElement = {\n preloadTimeout?: null | ReturnType<typeof setTimeout>\n}\n\nconst preloadWarning = 'Error preloading route! ☝️'\n\nexport function useLinkProps<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n>({\n from,\n ...options\n}: UseLinkPropsOptions<\n TRouteTree,\n TFrom,\n TTo,\n TMaskFrom,\n TMaskTo\n>): React.AnchorHTMLAttributes<HTMLAnchorElement> {\n const router = useRouter()\n const matchPathname = useMatch({\n strict: false,\n select: (s) => s.pathname,\n })\n\n const {\n // custom props\n children,\n target,\n activeProps = () => ({ className: 'active' }),\n inactiveProps = () => ({}),\n activeOptions,\n disabled,\n hash,\n search,\n params,\n to,\n state,\n mask,\n preload: userPreload,\n preloadDelay: userPreloadDelay,\n replace,\n startTransition,\n resetScroll,\n // element props\n style,\n className,\n onClick,\n onFocus,\n onMouseEnter,\n onMouseLeave,\n onTouchStart,\n ...rest\n } = options\n\n // If this link simply reloads the current route,\n // make sure it has a new key so it will trigger a data refresh\n\n // If this `to` is a valid external URL, return\n // null for LinkUtils\n\n const dest = {\n from: options.to ? matchPathname : undefined,\n ...options,\n }\n\n let type: 'internal' | 'external' = 'internal'\n\n try {\n new URL(`${to}`)\n type = 'external'\n } catch {}\n\n if (type === 'external') {\n return {\n href: to,\n }\n }\n\n const next = router.buildLocation(dest as any)\n const preload = userPreload ?? router.options.defaultPreload\n const preloadDelay =\n userPreloadDelay ?? router.options.defaultPreloadDelay ?? 0\n\n const isActive = useRouterState({\n select: (s) => {\n // Compare path/hash for matches\n const currentPathSplit = s.location.pathname.split('/')\n const nextPathSplit = next.pathname.split('/')\n const pathIsFuzzyEqual = nextPathSplit.every(\n (d, i) => d === currentPathSplit[i],\n )\n // Combine the matches based on user router.options\n const pathTest = activeOptions?.exact\n ? s.location.pathname === next.pathname\n : pathIsFuzzyEqual\n const hashTest = activeOptions?.includeHash\n ? s.location.hash === next.hash\n : true\n const searchTest =\n activeOptions?.includeSearch ?? true\n ? deepEqual(s.location.search, next.search, !activeOptions?.exact)\n : true\n\n // The final \"active\" test\n return pathTest && hashTest && searchTest\n },\n })\n\n // The click handler\n const handleClick = (e: MouseEvent) => {\n if (\n !disabled &&\n !isCtrlEvent(e) &&\n !e.defaultPrevented &&\n (!target || target === '_self') &&\n e.button === 0\n ) {\n e.preventDefault()\n\n // All is well? Navigate!\n router.commitLocation({ ...next, replace, resetScroll, startTransition })\n }\n }\n\n // The click handler\n const handleFocus = (e: MouseEvent) => {\n if (preload) {\n router.preloadRoute(dest as any).catch((err) => {\n console.warn(err)\n console.warn(preloadWarning)\n })\n }\n }\n\n const handleTouchStart = (e: TouchEvent) => {\n if (preload) {\n router.preloadRoute(dest as any).catch((err) => {\n console.warn(err)\n console.warn(preloadWarning)\n })\n }\n }\n\n const handleEnter = (e: MouseEvent) => {\n const target = (e.target || {}) as LinkCurrentTargetElement\n\n if (preload) {\n if (target.preloadTimeout) {\n return\n }\n\n target.preloadTimeout = setTimeout(() => {\n target.preloadTimeout = null\n router.preloadRoute(dest as any).catch((err) => {\n console.warn(err)\n console.warn(preloadWarning)\n })\n }, preloadDelay)\n }\n }\n\n const handleLeave = (e: MouseEvent) => {\n const target = (e.target || {}) as LinkCurrentTargetElement\n\n if (target.preloadTimeout) {\n clearTimeout(target.preloadTimeout)\n target.preloadTimeout = null\n }\n }\n\n const composeHandlers =\n (handlers: (undefined | ((e: any) => void))[]) =>\n (e: React.SyntheticEvent) => {\n if (e.persist) e.persist()\n handlers.filter(Boolean).forEach((handler) => {\n if (e.defaultPrevented) return\n handler!(e)\n })\n }\n\n // Get the active props\n const resolvedActiveProps: React.HTMLAttributes<HTMLAnchorElement> = isActive\n ? functionalUpdate(activeProps as any, {}) ?? {}\n : {}\n\n // Get the inactive props\n const resolvedInactiveProps: React.HTMLAttributes<HTMLAnchorElement> =\n isActive ? {} : functionalUpdate(inactiveProps, {}) ?? {}\n\n return {\n ...resolvedActiveProps,\n ...resolvedInactiveProps,\n ...rest,\n href: disabled\n ? undefined\n : next.maskedLocation\n ? next.maskedLocation.href\n : next.href,\n onClick: composeHandlers([onClick, handleClick]),\n onFocus: composeHandlers([onFocus, handleFocus]),\n onMouseEnter: composeHandlers([onMouseEnter, handleEnter]),\n onMouseLeave: composeHandlers([onMouseLeave, handleLeave]),\n onTouchStart: composeHandlers([onTouchStart, handleTouchStart]),\n target,\n style: {\n ...style,\n ...resolvedActiveProps.style,\n ...resolvedInactiveProps.style,\n },\n className:\n [\n className,\n resolvedActiveProps.className,\n resolvedInactiveProps.className,\n ]\n .filter(Boolean)\n .join(' ') || undefined,\n ...(disabled\n ? {\n role: 'link',\n 'aria-disabled': true,\n }\n : undefined),\n ['data-status']: isActive ? 'active' : undefined,\n }\n}\n\nexport interface LinkComponent<TProps extends Record<string, any> = {}> {\n <\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = '/',\n TMaskTo extends string = '',\n >(\n props: LinkProps<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> &\n TProps &\n React.RefAttributes<HTMLAnchorElement>,\n ): ReactNode\n}\n\nexport const Link: LinkComponent = React.forwardRef((props: any, ref) => {\n const linkProps = useLinkProps(props)\n\n return (\n <a\n {...{\n ref: ref as any,\n ...linkProps,\n children:\n typeof props.children === 'function'\n ? props.children({\n isActive: (linkProps as any)['data-status'] === 'active',\n })\n : props.children,\n }}\n />\n )\n}) as any\n\nfunction isCtrlEvent(e: MouseEvent) {\n return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey)\n}\n"],"names":["preloadWarning","useLinkProps","from","options","router","useRouter","matchPathname","useMatch","strict","select","s","pathname","children","target","activeProps","className","inactiveProps","activeOptions","disabled","hash","search","params","to","state","mask","preload","userPreload","preloadDelay","userPreloadDelay","replace","startTransition","resetScroll","style","onClick","onFocus","onMouseEnter","onMouseLeave","onTouchStart","rest","dest","undefined","type","URL","href","next","buildLocation","defaultPreload","defaultPreloadDelay","isActive","useRouterState","currentPathSplit","location","split","nextPathSplit","pathIsFuzzyEqual","every","d","i","pathTest","exact","hashTest","includeHash","searchTest","includeSearch","deepEqual","handleClick","e","isCtrlEvent","defaultPrevented","button","preventDefault","commitLocation","handleFocus","preloadRoute","catch","err","console","warn","handleTouchStart","handleEnter","preloadTimeout","setTimeout","handleLeave","clearTimeout","composeHandlers","handlers","persist","filter","Boolean","forEach","handler","resolvedActiveProps","functionalUpdate","resolvedInactiveProps","maskedLocation","join","role","Link","React","forwardRef","props","ref","linkProps","createElement","_extends","metaKey","altKey","ctrlKey","shiftKey"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0VA,MAAMA,cAAc,GAAG,4BAA4B,CAAA;AAE5C,SAASC,YAAYA,CAM1B;EACAC,IAAI;EACJ,GAAGC,OAAAA;AAOL,CAAC,EAAiD;AAChD,EAAA,MAAMC,MAAM,GAAGC,wBAAS,EAAE,CAAA;EAC1B,MAAMC,aAAa,GAAGC,gBAAQ,CAAC;AAC7BC,IAAAA,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,KAAK,CAAC,CAAA;AAErC,EAAA,oBACEF,gBAAA,CAAAK,aAAA,CAAA,GAAA,EAAAC,iCAAA,CAAA;AAEIH,IAAAA,GAAG,EAAEA,GAAAA;AAAU,GAAA,EACZC,SAAS,EAAA;IACZ1F,QAAQ,EACN,OAAOwF,KAAK,CAACxF,QAAQ,KAAK,UAAU,GAChCwF,KAAK,CAACxF,QAAQ,CAAC;AACboC,MAAAA,QAAQ,EAAGsD,SAAS,CAAS,aAAa,CAAC,KAAK,QAAA;KACjD,CAAC,GACFF,KAAK,CAACxF,QAAAA;AAAQ,GAAA,CAEvB,CAAC,CAAA;AAEN,CAAC,EAAQ;AAET,SAASuD,WAAWA,CAACD,CAAa,EAAE;AAClC,EAAA,OAAO,CAAC,EAAEA,CAAC,CAACuC,OAAO,IAAIvC,CAAC,CAACwC,MAAM,IAAIxC,CAAC,CAACyC,OAAO,IAAIzC,CAAC,CAAC0C,QAAQ,CAAC,CAAA;AAC7D;;;;;"}
|
|
1
|
+
{"version":3,"file":"link.js","sources":["../../src/link.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useMatch } from './Matches'\nimport { useRouter, useRouterState } from './RouterProvider'\nimport { Trim } from './fileRoute'\nimport { AnyRoute, ReactNode } from './route'\nimport {\n AllParams,\n FullSearchSchema,\n RouteByPath,\n RouteIds,\n RoutePaths,\n} from './routeInfo'\nimport { RegisteredRouter } from './router'\nimport { LinkProps, UseLinkPropsOptions } from './useNavigate'\nimport {\n Expand,\n NoInfer,\n NonNullableUpdater,\n PickRequired,\n UnionToIntersection,\n Updater,\n WithoutEmpty,\n deepEqual,\n functionalUpdate,\n} from './utils'\nimport { HistoryState } from '@tanstack/history'\n\nexport type CleanPath<T extends string> = T extends `${infer L}//${infer R}`\n ? CleanPath<`${CleanPath<L>}/${CleanPath<R>}`>\n : T extends `${infer L}//`\n ? `${CleanPath<L>}/`\n : T extends `//${infer L}`\n ? `/${CleanPath<L>}`\n : T\n\nexport type Split<S, TIncludeTrailingSlash = true> = S extends unknown\n ? string extends S\n ? string[]\n : S extends string\n ? CleanPath<S> extends ''\n ? []\n : TIncludeTrailingSlash extends true\n ? CleanPath<S> extends `${infer T}/`\n ? [...Split<T>, '/']\n : CleanPath<S> extends `/${infer U}`\n ? Split<U>\n : CleanPath<S> extends `${infer T}/${infer U}`\n ? [...Split<T>, ...Split<U>]\n : [S]\n : CleanPath<S> extends `${infer T}/${infer U}`\n ? [...Split<T>, ...Split<U>]\n : S extends string\n ? [S]\n : never\n : never\n : never\n\nexport type ParsePathParams<T extends string> = keyof {\n [K in Trim<Split<T>[number], '_'> as K extends `$${infer L}` ? L : never]: K\n}\n\nexport type Join<T, Delimiter extends string = '/'> = T extends []\n ? ''\n : T extends [infer L extends string]\n ? L\n : T extends [infer L extends string, ...infer Tail extends [...string[]]]\n ? CleanPath<`${L}${Delimiter}${Join<Tail>}`>\n : never\n\nexport type Last<T extends any[]> = T extends [...infer _, infer L] ? L : never\n\nexport type RelativeToPathAutoComplete<\n AllPaths extends string,\n TFrom extends string,\n TTo extends string,\n SplitPaths extends string[] = Split<AllPaths, false>,\n> = TTo extends `..${infer _}`\n ? SplitPaths extends [\n ...Split<ResolveRelativePath<TFrom, TTo>, false>,\n ...infer TToRest,\n ]\n ? `${CleanPath<\n Join<\n [\n ...Split<TTo, false>,\n ...(\n | TToRest\n | (Split<\n ResolveRelativePath<TFrom, TTo>,\n false\n >['length'] extends 1\n ? never\n : ['../'])\n ),\n ]\n >\n >}`\n : never\n : TTo extends `./${infer RestTTo}`\n ? SplitPaths extends [\n ...Split<TFrom, false>,\n ...Split<RestTTo, false>,\n ...infer RestPath,\n ]\n ? `${TTo}${Join<RestPath>}`\n : never\n :\n | (TFrom extends `/`\n ? never\n : SplitPaths extends [...Split<TFrom, false>, ...infer RestPath]\n ? Join<RestPath> extends { length: 0 }\n ? never\n : './'\n : never)\n | (TFrom extends `/` ? never : '../')\n | AllPaths\n\nexport type NavigateOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string | undefined = undefined,\n> = ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // `replace` is a boolean that determines whether the navigation should replace the current history entry or push a new one.\n replace?: boolean\n resetScroll?: boolean\n // If set to `true`, the link's underlying navigate() call will be wrapped in a `React.startTransition` call. Defaults to `true`.\n startTransition?: boolean\n}\n\nexport type ToOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string | undefined = undefined,\n> = ToSubOptions<TRouteTree, TFrom, TTo> & {\n mask?: ToMaskOptions<TRouteTree, TMaskFrom, TMaskTo>\n}\n\nexport type ToMaskOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TMaskFrom extends RoutePaths<TRouteTree> | string = string,\n TMaskTo extends string | undefined = undefined,\n> = ToSubOptions<TRouteTree, TMaskFrom, TMaskTo> & {\n unmaskOnReload?: boolean\n}\n\nexport type ToSubOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string | undefined = undefined,\n TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n> = {\n to?: ToPathOption<TRouteTree, TFrom, TTo>\n // The new has string or a function to update it\n hash?: true | Updater<string>\n // State to pass to the history stack\n state?: true | NonNullableUpdater<HistoryState>\n // The source route path. This is automatically set when using route-level APIs, but for type-safe relative routing on the router itself, this is required\n from?: TFrom\n // // When using relative route paths, this option forces resolution from the current path, instead of the route API's path or `from` path\n} & CheckPath<TRouteTree, NoInfer<TResolved>, {}> &\n SearchParamOptions<TRouteTree, TFrom, TTo, TResolved> &\n PathParamOptions<TRouteTree, TFrom, TTo, TResolved>\n\ntype ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo)\n\nexport type ParamOptions<\n TRouteTree extends AnyRoute,\n TFrom,\n TTo,\n TResolved,\n TParamVariant extends 'allParams' | 'fullSearchSchema',\n TFromParams = Expand<RouteByPath<TRouteTree, TFrom>['types'][TParamVariant]>,\n TToParams = TTo extends undefined\n ? TFromParams\n : never extends TResolved\n ? Expand<RouteByPath<TRouteTree, TTo>['types'][TParamVariant]>\n : Expand<RouteByPath<TRouteTree, TResolved>['types'][TParamVariant]>,\n TReducer = ParamsReducer<TFromParams, TToParams>,\n> = Expand<WithoutEmpty<PickRequired<TToParams>>> extends never\n ? Partial<MakeParamOption<TParamVariant, true | TReducer>>\n : TFromParams extends Expand<WithoutEmpty<PickRequired<TToParams>>>\n ? MakeParamOption<TParamVariant, true | TReducer>\n : MakeParamOption<TParamVariant, TReducer>\n\ntype MakeParamOption<\n TParamVariant extends 'allParams' | 'fullSearchSchema',\n T,\n> = TParamVariant extends 'allParams'\n ? MakePathParamOptions<T>\n : MakeSearchParamOptions<T>\ntype MakeSearchParamOptions<T> = { search: T }\ntype MakePathParamOptions<T> = { params: T }\n\nexport type SearchParamOptions<\n TRouteTree extends AnyRoute,\n TFrom,\n TTo,\n TResolved,\n> = ParamOptions<TRouteTree, TFrom, TTo, TResolved, 'fullSearchSchema'>\n\nexport type PathParamOptions<\n TRouteTree extends AnyRoute,\n TFrom,\n TTo,\n TResolved,\n> = ParamOptions<TRouteTree, TFrom, TTo, TResolved, 'allParams'>\n\nexport type ToPathOption<\n TRouteTree extends AnyRoute = AnyRoute,\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string | undefined = undefined,\n> =\n | TTo\n | RelativeToPathAutoComplete<\n RoutePaths<TRouteTree>,\n NoInfer<TFrom> extends string ? NoInfer<TFrom> : '',\n NoInfer<TTo> & string\n >\n\nexport type ToIdOption<\n TRouteTree extends AnyRoute = AnyRoute,\n TFrom extends RoutePaths<TRouteTree> | undefined = undefined,\n TTo extends string | undefined = undefined,\n> =\n | TTo\n | RelativeToPathAutoComplete<\n RouteIds<TRouteTree>,\n NoInfer<TFrom> extends string ? NoInfer<TFrom> : '',\n NoInfer<TTo> & string\n >\n\nexport interface ActiveOptions {\n exact?: boolean\n includeHash?: boolean\n includeSearch?: boolean\n}\n\nexport type LinkOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string | undefined = undefined,\n> = NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // The standard anchor tag target attribute\n target?: HTMLAnchorElement['target']\n // Defaults to `{ exact: false, includeHash: false }`\n activeOptions?: ActiveOptions\n // If set, will preload the linked route on hover and cache it for this many milliseconds in hopes that the user will eventually navigate there.\n preload?: false | 'intent'\n // Delay intent preloading by this many milliseconds. If the intent exits before this delay, the preload will be cancelled.\n preloadDelay?: number\n // If true, will render the link without the href attribute\n disabled?: boolean\n}\n\nexport type CheckRelativePath<\n TRouteTree extends AnyRoute,\n TFrom,\n TTo,\n> = TTo extends string\n ? TFrom extends string\n ? ResolveRelativePath<TFrom, TTo> extends RoutePaths<TRouteTree>\n ? {}\n : {\n Error: `${TFrom} + ${TTo} resolves to ${ResolveRelativePath<\n TFrom,\n TTo\n >}, which is not a valid route path.`\n 'Valid Route Paths': RoutePaths<TRouteTree>\n }\n : {}\n : {}\n\nexport type CheckPath<TRouteTree extends AnyRoute, TPath, TPass> = Exclude<\n TPath,\n RoutePaths<TRouteTree>\n> extends never\n ? TPass\n : CheckPathError<TRouteTree, Exclude<TPath, RoutePaths<TRouteTree>>>\n\nexport type CheckPathError<TRouteTree extends AnyRoute, TInvalids> = {\n to: RoutePaths<TRouteTree>\n}\n\nexport type CheckId<TRouteTree extends AnyRoute, TPath, TPass> = Exclude<\n TPath,\n RouteIds<TRouteTree>\n> extends never\n ? TPass\n : CheckIdError<TRouteTree, Exclude<TPath, RouteIds<TRouteTree>>>\n\nexport type CheckIdError<TRouteTree extends AnyRoute, TInvalids> = {\n Error: `${TInvalids extends string\n ? TInvalids\n : never} is not a valid route ID.`\n 'Valid Route IDs': RouteIds<TRouteTree>\n}\n\nexport type ResolveRelativePath<TFrom, TTo = '.'> = TFrom extends string\n ? TTo extends string\n ? TTo extends '.'\n ? TFrom\n : TTo extends `./`\n ? Join<[TFrom, '/']>\n : TTo extends `./${infer TRest}`\n ? ResolveRelativePath<TFrom, TRest>\n : TTo extends `/${infer TRest}`\n ? TTo\n : Split<TTo> extends ['..', ...infer ToRest]\n ? Split<TFrom> extends [...infer FromRest, infer FromTail]\n ? ToRest extends ['/']\n ? Join<[...FromRest, '/']>\n : ResolveRelativePath<Join<FromRest>, Join<ToRest>>\n : never\n : Split<TTo> extends ['.', ...infer ToRest]\n ? ToRest extends ['/']\n ? Join<[TFrom, '/']>\n : ResolveRelativePath<TFrom, Join<ToRest>>\n : CleanPath<Join<['/', ...Split<TFrom>, ...Split<TTo>]>>\n : never\n : never\n\ntype LinkCurrentTargetElement = {\n preloadTimeout?: null | ReturnType<typeof setTimeout>\n}\n\nconst preloadWarning = 'Error preloading route! ☝️'\n\nexport function useLinkProps<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string | undefined = undefined,\n>(\n options: UseLinkPropsOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n): React.AnchorHTMLAttributes<HTMLAnchorElement> {\n const router = useRouter()\n const matchPathname = useMatch({\n strict: false,\n select: (s) => s.pathname,\n })\n\n const {\n // custom props\n children,\n target,\n activeProps = () => ({ className: 'active' }),\n inactiveProps = () => ({}),\n activeOptions,\n disabled,\n hash,\n search,\n params,\n to,\n state,\n mask,\n preload: userPreload,\n preloadDelay: userPreloadDelay,\n replace,\n startTransition,\n resetScroll,\n // element props\n style,\n className,\n onClick,\n onFocus,\n onMouseEnter,\n onMouseLeave,\n onTouchStart,\n ...rest\n } = options\n\n // If this link simply reloads the current route,\n // make sure it has a new key so it will trigger a data refresh\n\n // If this `to` is a valid external URL, return\n // null for LinkUtils\n\n const dest = {\n from: options.to ? matchPathname : undefined,\n ...options,\n }\n\n let type: 'internal' | 'external' = 'internal'\n\n try {\n new URL(`${to}`)\n type = 'external'\n } catch {}\n\n if (type === 'external') {\n return {\n href: to,\n }\n }\n\n const next = router.buildLocation(dest as any)\n const preload = userPreload ?? router.options.defaultPreload\n const preloadDelay =\n userPreloadDelay ?? router.options.defaultPreloadDelay ?? 0\n\n const isActive = useRouterState({\n select: (s) => {\n // Compare path/hash for matches\n const currentPathSplit = s.location.pathname.split('/')\n const nextPathSplit = next.pathname.split('/')\n const pathIsFuzzyEqual = nextPathSplit.every(\n (d, i) => d === currentPathSplit[i],\n )\n // Combine the matches based on user router.options\n const pathTest = activeOptions?.exact\n ? s.location.pathname === next.pathname\n : pathIsFuzzyEqual\n const hashTest = activeOptions?.includeHash\n ? s.location.hash === next.hash\n : true\n const searchTest =\n activeOptions?.includeSearch ?? true\n ? deepEqual(s.location.search, next.search, !activeOptions?.exact)\n : true\n\n // The final \"active\" test\n return pathTest && hashTest && searchTest\n },\n })\n\n // The click handler\n const handleClick = (e: MouseEvent) => {\n if (\n !disabled &&\n !isCtrlEvent(e) &&\n !e.defaultPrevented &&\n (!target || target === '_self') &&\n e.button === 0\n ) {\n e.preventDefault()\n\n // All is well? Navigate!\n router.commitLocation({ ...next, replace, resetScroll, startTransition })\n }\n }\n\n // The click handler\n const handleFocus = (e: MouseEvent) => {\n if (preload) {\n router.preloadRoute(dest as any).catch((err) => {\n console.warn(err)\n console.warn(preloadWarning)\n })\n }\n }\n\n const handleTouchStart = (e: TouchEvent) => {\n if (preload) {\n router.preloadRoute(dest as any).catch((err) => {\n console.warn(err)\n console.warn(preloadWarning)\n })\n }\n }\n\n const handleEnter = (e: MouseEvent) => {\n const target = (e.target || {}) as LinkCurrentTargetElement\n\n if (preload) {\n if (target.preloadTimeout) {\n return\n }\n\n target.preloadTimeout = setTimeout(() => {\n target.preloadTimeout = null\n router.preloadRoute(dest as any).catch((err) => {\n console.warn(err)\n console.warn(preloadWarning)\n })\n }, preloadDelay)\n }\n }\n\n const handleLeave = (e: MouseEvent) => {\n const target = (e.target || {}) as LinkCurrentTargetElement\n\n if (target.preloadTimeout) {\n clearTimeout(target.preloadTimeout)\n target.preloadTimeout = null\n }\n }\n\n const composeHandlers =\n (handlers: (undefined | ((e: any) => void))[]) =>\n (e: React.SyntheticEvent) => {\n if (e.persist) e.persist()\n handlers.filter(Boolean).forEach((handler) => {\n if (e.defaultPrevented) return\n handler!(e)\n })\n }\n\n // Get the active props\n const resolvedActiveProps: React.HTMLAttributes<HTMLAnchorElement> = isActive\n ? functionalUpdate(activeProps as any, {}) ?? {}\n : {}\n\n // Get the inactive props\n const resolvedInactiveProps: React.HTMLAttributes<HTMLAnchorElement> =\n isActive ? {} : functionalUpdate(inactiveProps, {}) ?? {}\n\n return {\n ...resolvedActiveProps,\n ...resolvedInactiveProps,\n ...rest,\n href: disabled\n ? undefined\n : next.maskedLocation\n ? next.maskedLocation.href\n : next.href,\n onClick: composeHandlers([onClick, handleClick]),\n onFocus: composeHandlers([onFocus, handleFocus]),\n onMouseEnter: composeHandlers([onMouseEnter, handleEnter]),\n onMouseLeave: composeHandlers([onMouseLeave, handleLeave]),\n onTouchStart: composeHandlers([onTouchStart, handleTouchStart]),\n target,\n style: {\n ...style,\n ...resolvedActiveProps.style,\n ...resolvedInactiveProps.style,\n },\n className:\n [\n className,\n resolvedActiveProps.className,\n resolvedInactiveProps.className,\n ]\n .filter(Boolean)\n .join(' ') || undefined,\n ...(disabled\n ? {\n role: 'link',\n 'aria-disabled': true,\n }\n : undefined),\n ['data-status']: isActive ? 'active' : undefined,\n }\n}\n\nexport interface LinkComponent<TProps extends Record<string, any> = {}> {\n <\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string | undefined = undefined,\n >(\n props: LinkProps<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> &\n TProps &\n React.RefAttributes<HTMLAnchorElement>,\n ): ReactNode\n}\n\nexport const Link: LinkComponent = React.forwardRef((props: any, ref) => {\n const linkProps = useLinkProps(props)\n\n return (\n <a\n {...{\n ref: ref as any,\n ...linkProps,\n children:\n typeof props.children === 'function'\n ? props.children({\n isActive: (linkProps as any)['data-status'] === 'active',\n })\n : props.children,\n }}\n />\n )\n}) as any\n\nfunction isCtrlEvent(e: MouseEvent) {\n return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey)\n}\n"],"names":["preloadWarning","useLinkProps","options","router","useRouter","matchPathname","useMatch","strict","select","s","pathname","children","target","activeProps","className","inactiveProps","activeOptions","disabled","hash","search","params","to","state","mask","preload","userPreload","preloadDelay","userPreloadDelay","replace","startTransition","resetScroll","style","onClick","onFocus","onMouseEnter","onMouseLeave","onTouchStart","rest","dest","from","undefined","type","URL","href","next","buildLocation","defaultPreload","defaultPreloadDelay","isActive","useRouterState","currentPathSplit","location","split","nextPathSplit","pathIsFuzzyEqual","every","d","i","pathTest","exact","hashTest","includeHash","searchTest","includeSearch","deepEqual","handleClick","e","isCtrlEvent","defaultPrevented","button","preventDefault","commitLocation","handleFocus","preloadRoute","catch","err","console","warn","handleTouchStart","handleEnter","preloadTimeout","setTimeout","handleLeave","clearTimeout","composeHandlers","handlers","persist","filter","Boolean","forEach","handler","resolvedActiveProps","functionalUpdate","resolvedInactiveProps","maskedLocation","join","role","Link","React","forwardRef","props","ref","linkProps","createElement","_extends","metaKey","altKey","ctrlKey","shiftKey"],"mappings":";;;;;;;;;;;;;;;;;;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AACb,IAAA,CAAC,aAAa,GAAGQ,QAAQ,GAAG,QAAQ,GAAGR,SAAAA;GACxC,CAAA;AACH,CAAA;AAgBO,MAAMyD,IAAmB,gBAAGC,gBAAK,CAACC,UAAU,CAAC,CAACC,KAAU,EAAEC,GAAG,KAAK;AACvE,EAAA,MAAMC,SAAS,GAAGrG,YAAY,CAACmG,KAAK,CAAC,CAAA;AAErC,EAAA,oBACEF,gBAAA,CAAAK,aAAA,CAAA,GAAA,EAAAC,iCAAA,CAAA;AAEIH,IAAAA,GAAG,EAAEA,GAAAA;AAAU,GAAA,EACZC,SAAS,EAAA;IACZ3F,QAAQ,EACN,OAAOyF,KAAK,CAACzF,QAAQ,KAAK,UAAU,GAChCyF,KAAK,CAACzF,QAAQ,CAAC;AACbqC,MAAAA,QAAQ,EAAGsD,SAAS,CAAS,aAAa,CAAC,KAAK,QAAA;KACjD,CAAC,GACFF,KAAK,CAACzF,QAAAA;AAAQ,GAAA,CAEvB,CAAC,CAAA;AAEN,CAAC,EAAQ;AAET,SAASwD,WAAWA,CAACD,CAAa,EAAE;AAClC,EAAA,OAAO,CAAC,EAAEA,CAAC,CAACuC,OAAO,IAAIvC,CAAC,CAACwC,MAAM,IAAIxC,CAAC,CAACyC,OAAO,IAAIzC,CAAC,CAAC0C,QAAQ,CAAC,CAAA;AAC7D;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNavigate.js","sources":["../../src/useNavigate.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useMatch } from './Matches'\nimport { useRouter } from './RouterProvider'\nimport { LinkOptions, NavigateOptions } from './link'\nimport { AnyRoute } from './route'\nimport { RoutePaths } from './routeInfo'\nimport { RegisteredRouter } from './router'\
|
|
1
|
+
{"version":3,"file":"useNavigate.js","sources":["../../src/useNavigate.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useMatch } from './Matches'\nimport { useRouter } from './RouterProvider'\nimport { LinkOptions, NavigateOptions } from './link'\nimport { AnyRoute } from './route'\nimport { RoutePaths } from './routeInfo'\nimport { RegisteredRouter } from './router'\n\nexport function useNavigate<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TDefaultFrom extends RoutePaths<TRouteTree> | string = string,\n>(_defaultOpts?: { from?: TDefaultFrom }) {\n const { navigate, buildLocation } = 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 | undefined = undefined,\n TMaskFrom extends RoutePaths<TRouteTree>| string = TFrom,\n TMaskTo extends string | undefined = undefined,\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 | undefined = undefined,\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string | undefined = undefined,\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 | undefined= undefined,\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string | undefined = undefined,\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| undefined = undefined,\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string | undefined = undefined,\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 | undefined = undefined,\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string | undefined = undefined,\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":["useNavigate","_defaultOpts","navigate","buildLocation","useRouter","matchPathname","useMatch","strict","select","s","pathname","React","useCallback","from","rest","to","undefined","Navigate","props","match","useEffect"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQO,SAASA,WAAWA,CAGzBC,YAAsC,EAAE;EACxC,MAAM;IAAEC,QAAQ;AAAEC,IAAAA,aAAAA;GAAe,GAAGC,wBAAS,EAAE,CAAA;EAE/C,MAAMC,aAAa,GAAGC,gBAAQ,CAAC;AAC7BC,IAAAA,MAAM,EAAE,KAAK;AACbC,IAAAA,MAAM,EAAGC,CAAC,IAAKA,CAAC,CAACC,QAAAA;AACnB,GAAC,CAAC,CAAA;AAEF,EAAA,OAAOC,gBAAK,CAACC,WAAW,CACtB,CAKE;IACAC,IAAI;IACJ,GAAGC,IAAAA;AACwD,GAAC,KAAK;AACjE,IAAA,OAAOZ,QAAQ,CAAC;AACdW,MAAAA,IAAI,EAAEC,IAAI,EAAEC,EAAE,GAAGV,aAAa,GAAGW,SAAS;MAC1C,GAAIF,IAAAA;AACN,KAAC,CAAC,CAAA;GACH,EACD,EACF,CAAC,CAAA;AACH,CAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,SAASG,QAAQA,CAMtBC,KAAkE,EAAQ;EAC1E,MAAM;AAAEhB,IAAAA,QAAAA;GAAU,GAAGE,wBAAS,EAAE,CAAA;EAChC,MAAMe,KAAK,GAAGb,gBAAQ,CAAC;AAAEC,IAAAA,MAAM,EAAE,KAAA;AAAM,GAAC,CAAC,CAAA;EAEzCI,gBAAK,CAACS,SAAS,CAAC,MAAM;AACpBlB,IAAAA,QAAQ,CAAC;MACPW,IAAI,EAAEK,KAAK,CAACH,EAAE,GAAGI,KAAK,CAACT,QAAQ,GAAGM,SAAS;MAC3C,GAAGE,KAAAA;AACL,KAAQ,CAAC,CAAA;GACV,EAAE,EAAE,CAAC,CAAA;AAEN,EAAA,OAAO,IAAI,CAAA;AACb;;;;;"}
|
package/build/cjs/utils.js
CHANGED
package/build/cjs/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as React from 'react'\nimport { useMatch } from './Matches'\nimport { RouteMatch } from './Matches'\nimport { AnyRoute } from './route'\nimport { ParseRoute, RouteIds, RoutesById, RouteById } from './routeInfo'\nimport { RegisteredRouter } from './router'\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 IsAnyBoolean<T> = 1 extends 0 & T ? true : false\nexport type IsKnown<T, Y, N> = unknown extends T ? N : Y\nexport type PickAsRequired<T, K extends keyof T> = Omit<T, K> &\n Required<Pick<T, K>>\nexport type PickAsPartial<T, K extends keyof T> = Omit<T, K> &\n Partial<Pick<T, K>>\nexport type PickUnsafe<T, K> = K extends keyof T ? Pick<T, K> : never\nexport type PickExtra<T, K> = {\n [TKey in keyof K as string extends TKey\n ? never\n : TKey extends keyof T\n ? never\n : TKey]: K[TKey]\n}\n\nexport type PickRequired<T> = {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K]\n}\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\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 Values<O> = O[ValueKeys<O>]\nexport type ValueKeys<O> = Extract<keyof O, PropertyKey>\n\nexport type DeepAwaited<T> = T extends Promise<infer A>\n ? DeepAwaited<A>\n : T extends Record<infer A, Promise<infer B>>\n ? { [K in A]: DeepAwaited<B> }\n : T\n\nexport type PathParamMask<TRoutePath extends string> =\n TRoutePath extends `${infer L}/$${infer C}/${infer R}`\n ? PathParamMask<`${L}/${string}/${R}`>\n : TRoutePath extends `${infer L}/$${infer C}`\n ? PathParamMask<`${L}/${string}`>\n : TRoutePath\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\nexport type PickExtract<T, U> = {\n [K in keyof T as T[K] extends U ? K : never]: T[K]\n}\n\nexport type PickExclude<T, U> = {\n [K in keyof T as T[K] extends U ? never : K]: T[K]\n}\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 `a` if `b` 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 = Array.isArray(prev) && Array.isArray(next)\n\n if (array || (isPlainObject(prev) && isPlainObject(next))) {\n const prevSize = array ? prev.length : Object.keys(prev).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 copy[key] = replaceEqualDeep(prev[key], next[key])\n if (copy[key] === prev[key]) {\n equalItems++\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 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 StrictOrFrom<TFrom> =\n | {\n from: TFrom\n strict?: true\n }\n | {\n from?: never\n strict: false\n }\n\nexport type RouteFromIdOrRoute<\n T,\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n> = T extends ParseRoute<TRouteTree>\n ? T\n : T extends RouteIds<TRouteTree>\n ? RoutesById<TRouteTree>[T]\n : T extends string\n ? RouteIds<TRouteTree>\n : never\n\nexport function useRouteContext<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TRouteContext = RouteById<TRouteTree, TFrom>['types']['allContext'],\n TSelected = TRouteContext,\n>(\n opts: StrictOrFrom<TFrom> & {\n select?: (search: TRouteContext) => TSelected\n },\n): TStrict extends true ? TSelected : TSelected | undefined {\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\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":["isServer","document","last","arr","length","isFunction","d","functionalUpdate","updater","previous","pick","parent","keys","reduce","obj","key","replaceEqualDeep","prev","_next","next","array","Array","isArray","isPlainObject","prevSize","Object","nextItems","nextSize","copy","equalItems","i","o","hasObjectPrototype","ctor","constructor","prot","prototype","hasOwnProperty","toString","call","deepEqual","a","b","partial","aKeys","bKeys","some","item","index","useStableCallback","fn","fnRef","React","useRef","current","ref","args","shallow","objA","objB","is","keysA","useRouteContext","opts","useMatch","select","match","context","useLayoutEffect","window","useEffect","escapeJSON","jsonString","replace"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA;;AAaA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAoCA;;AAUA;;MAEaA,QAAQ,GAAG,OAAOC,QAAQ,KAAK,YAAW;AAEhD,SAASC,IAAIA,CAAIC,GAAQ,EAAE;AAChC,EAAA,OAAOA,GAAG,CAACA,GAAG,CAACC,MAAM,GAAG,CAAC,CAAC,CAAA;AAC5B,CAAA;AAEA,SAASC,UAAUA,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SAAS,CAACC,cAAc,CAACE,IAAI,CAACoB,IAAI,EAAEE,KAAK,CAAC/B,CAAC,CAAW,CAAC,IAC/D,CAACL,MAAM,CAACmC,EAAE,CAACF,IAAI,CAACG,KAAK,CAAC/B,CAAC,CAAC,CAAY,EAAE6B,IAAI,CAACE,KAAK,CAAC/B,CAAC,CAAC,CAAY,CAAC,EAChE;AACA,MAAA,OAAO,KAAK,CAAA;AACd,KAAA;AACF,GAAA;AACA,EAAA,OAAO,IAAI,CAAA;AACb,CAAA;AAuBO,SAASgC,eAAeA,CAO7BC,IAEC,EACyD;AAC1D,EAAA,OAAOC,gBAAQ,CAAC;AACd,IAAA,GAAID,IAAY;AAChBE,IAAAA,MAAM,EAAGC,KAAiB,IACxBH,IAAI,EAAEE,MAAM,GACRF,IAAI,CAACE,MAAM,CAACC,KAAK,CAACC,OAAwB,CAAC,GAC3CD,KAAK,CAACC,OAAAA;AACd,GAAC,CAAC,CAAA;AACJ,CAAA;AAEaC,MAAAA,eAAe,GAC1B,OAAOC,MAAM,KAAK,WAAW,GAAGjB,gBAAK,CAACgB,eAAe,GAAGhB,gBAAK,CAACkB,UAAS;AAElE,SAASC,UAAUA,CAACC,UAAkB,EAAE;EAC7C,OAAOA,UAAU,CACdC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;AAAC,GACvBA,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;AAAC,GACrBA,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC1B;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as React from 'react'\nimport { useMatch } from './Matches'\nimport { RouteMatch } from './Matches'\nimport { AnyRoute } from './route'\nimport { ParseRoute, RouteIds, RoutesById, RouteById } from './routeInfo'\nimport { RegisteredRouter } from './router'\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 IsAnyBoolean<T> = 1 extends 0 & T ? true : false\nexport type IsKnown<T, Y, N> = unknown extends T ? N : Y\nexport type PickAsRequired<T, K extends keyof T> = Omit<T, K> &\n Required<Pick<T, K>>\nexport type PickAsPartial<T, K extends keyof T> = Omit<T, K> &\n Partial<Pick<T, K>>\nexport type PickUnsafe<T, K> = K extends keyof T ? Pick<T, K> : never\nexport type PickExtra<T, K> = {\n [TKey in keyof K as string extends TKey\n ? never\n : TKey extends keyof T\n ? never\n : TKey]: K[TKey]\n}\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\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 Values<O> = O[ValueKeys<O>]\nexport type ValueKeys<O> = Extract<keyof O, PropertyKey>\n\nexport type DeepAwaited<T> = T extends Promise<infer A>\n ? DeepAwaited<A>\n : T extends Record<infer A, Promise<infer B>>\n ? { [K in A]: DeepAwaited<B> }\n : T\n\nexport type PathParamMask<TRoutePath extends string> =\n TRoutePath extends `${infer L}/$${infer C}/${infer R}`\n ? PathParamMask<`${L}/${string}/${R}`>\n : TRoutePath extends `${infer L}/$${infer C}`\n ? PathParamMask<`${L}/${string}`>\n : TRoutePath\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\nexport type PickExtract<T, U> = {\n [K in keyof T as T[K] extends U ? K : never]: T[K]\n}\n\nexport type PickExclude<T, U> = {\n [K in keyof T as T[K] extends U ? never : K]: T[K]\n}\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 `a` if `b` 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 = Array.isArray(prev) && Array.isArray(next)\n\n if (array || (isPlainObject(prev) && isPlainObject(next))) {\n const prevSize = array ? prev.length : Object.keys(prev).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 copy[key] = replaceEqualDeep(prev[key], next[key])\n if (copy[key] === prev[key]) {\n equalItems++\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 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 StrictOrFrom<TFrom> =\n | {\n from: TFrom\n strict?: true\n }\n | {\n from?: never\n strict: false\n }\n\nexport type RouteFromIdOrRoute<\n T,\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n> = T extends ParseRoute<TRouteTree>\n ? T\n : T extends RouteIds<TRouteTree>\n ? RoutesById<TRouteTree>[T]\n : T extends string\n ? RouteIds<TRouteTree>\n : never\n\nexport function useRouteContext<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TRouteContext = RouteById<TRouteTree, TFrom>['types']['allContext'],\n TSelected = TRouteContext,\n>(\n opts: StrictOrFrom<TFrom> & {\n select?: (search: TRouteContext) => TSelected\n },\n): TStrict extends true ? TSelected : TSelected | undefined {\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\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":["isServer","document","last","arr","length","isFunction","d","functionalUpdate","updater","previous","pick","parent","keys","reduce","obj","key","replaceEqualDeep","prev","_next","next","array","Array","isArray","isPlainObject","prevSize","Object","nextItems","nextSize","copy","equalItems","i","o","hasObjectPrototype","ctor","constructor","prot","prototype","hasOwnProperty","toString","call","deepEqual","a","b","partial","aKeys","bKeys","some","item","index","useStableCallback","fn","fnRef","React","useRef","current","ref","args","shallow","objA","objB","is","keysA","useRouteContext","opts","useMatch","select","match","context","useLayoutEffect","window","useEffect","escapeJSON","jsonString","replace"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA;;AAGA;;AAaA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAoCA;;AAUA;;MAEaA,QAAQ,GAAG,OAAOC,QAAQ,KAAK,YAAW;AAEhD,SAASC,IAAIA,CAAIC,GAAQ,EAAE;AAChC,EAAA,OAAOA,GAAG,CAACA,GAAG,CAACC,MAAM,GAAG,CAAC,CAAC,CAAA;AAC5B,CAAA;AAEA,SAASC,UAAUA,CAACC,CAAM,EAAiB;EACzC,OAAO,OAAOA,CAAC,KAAK,UAAU,CAAA;AAChC,CAAA;AAEO,SAASC,gBAAgBA,CAC9BC,OAAuD,EACvDC,QAAiB,EACR;AACT,EAAA,IAAIJ,UAAU,CAACG,OAAO,CAAC,EAAE;IACvB,OAAOA,OAAO,CAACC,QAAmB,CAAC,CAAA;AACrC,GAAA;AAEA,EAAA,OAAOD,OAAO,CAAA;AAChB,CAAA;AA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ACA,EAAA,OAAO,IAAI,CAAA;AACb,CAAA;AAuBO,SAASgC,eAAeA,CAO7BC,IAEC,EACyD;AAC1D,EAAA,OAAOC,gBAAQ,CAAC;AACd,IAAA,GAAID,IAAY;AAChBE,IAAAA,MAAM,EAAGC,KAAiB,IACxBH,IAAI,EAAEE,MAAM,GACRF,IAAI,CAACE,MAAM,CAACC,KAAK,CAACC,OAAwB,CAAC,GAC3CD,KAAK,CAACC,OAAAA;AACd,GAAC,CAAC,CAAA;AACJ,CAAA;AAEaC,MAAAA,eAAe,GAC1B,OAAOC,MAAM,KAAK,WAAW,GAAGjB,gBAAK,CAACgB,eAAe,GAAGhB,gBAAK,CAACkB,UAAS;AAElE,SAASC,UAAUA,CAACC,UAAkB,EAAE;EAC7C,OAAOA,UAAU,CACdC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;AAAC,GACvBA,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;AAAC,GACrBA,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC1B;;;;;;;;;;;;;;;"}
|
package/build/esm/index.js
CHANGED
|
@@ -109,6 +109,8 @@ function ErrorComponent({
|
|
|
109
109
|
}, error.message ? /*#__PURE__*/React.createElement("code", null, error.message) : null)) : null);
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
// from https://stackoverflow.com/a/76458160
|
|
113
|
+
|
|
112
114
|
// export type Expand<T> = T
|
|
113
115
|
|
|
114
116
|
// type Compute<T> = { [K in keyof T]: T[K] } | never
|
|
@@ -1083,10 +1085,7 @@ function _extends() {
|
|
|
1083
1085
|
}
|
|
1084
1086
|
|
|
1085
1087
|
const preloadWarning = 'Error preloading route! ☝️';
|
|
1086
|
-
function useLinkProps({
|
|
1087
|
-
from,
|
|
1088
|
-
...options
|
|
1089
|
-
}) {
|
|
1088
|
+
function useLinkProps(options) {
|
|
1090
1089
|
const router = useRouter();
|
|
1091
1090
|
const matchPathname = useMatch({
|
|
1092
1091
|
strict: false,
|