@tanstack/react-router 0.0.1-beta.211 → 0.0.1-beta.212

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.
@@ -1 +1 @@
1
- {"version":3,"file":"link.js","sources":["../../src/link.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useMatch } from './Matches'\nimport { useRouter } from './RouterProvider'\nimport { Trim } from './fileRoute'\nimport { LocationState, ParsedLocation } from './location'\nimport { AnyRoute, ReactNode } from './route'\nimport {\n AllParams,\n FullSearchSchema,\n RouteByPath,\n RouteIds,\n RoutePaths,\n} from './routeInfo'\nimport { RegisteredRouter } from './router'\nimport { MakeLinkOptions, MakeLinkPropsOptions } from './useNavigate'\nimport {\n Expand,\n NoInfer,\n NonNullableUpdater,\n PickRequired,\n UnionToIntersection,\n Updater,\n functionalUpdate,\n} from './utils'\n\nexport type LinkInfo =\n | {\n type: 'external'\n href: string\n }\n | {\n type: 'internal'\n next: ParsedLocation\n handleFocus: (e: any) => void\n handleClick: (e: any) => void\n handleEnter: (e: any) => void\n handleLeave: (e: any) => void\n handleTouchStart: (e: any) => void\n isActive: boolean\n disabled?: boolean\n }\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<LocationState>\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 // fromCurrent?: boolean\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 UnionToIntersection<\n PickRequired<\n RouteByPath<TRouteTree, TFrom>['types']['fullSearchSchema']\n >\n >\n >,\n TFromSearchOptional = Omit<AllParams<TRouteTree>, keyof TFromSearchEnsured>,\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> = 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\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 options: MakeLinkPropsOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n): React.AnchorHTMLAttributes<HTMLAnchorElement> {\n const { buildLink } = useRouter()\n const match = useMatch({\n strict: false,\n })\n\n const {\n // custom props\n type,\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,\n preloadDelay,\n replace,\n startTransition,\n // element props\n style,\n className,\n onClick,\n onFocus,\n onMouseEnter,\n onMouseLeave,\n onTouchStart,\n ...rest\n } = options\n\n const linkInfo = buildLink({\n from: options.to ? match.pathname : undefined,\n ...options,\n } as any)\n\n if (linkInfo.type === 'external') {\n const { href } = linkInfo\n return { href }\n }\n\n const {\n handleClick,\n handleFocus,\n handleEnter,\n handleLeave,\n handleTouchStart,\n isActive,\n next,\n } = linkInfo\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: MakeLinkOptions<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"],"names":["useLinkProps","options","buildLink","useRouter","match","useMatch","strict","type","children","target","activeProps","className","inactiveProps","activeOptions","disabled","hash","search","params","to","state","mask","preload","preloadDelay","replace","startTransition","style","onClick","onFocus","onMouseEnter","onMouseLeave","onTouchStart","rest","linkInfo","from","pathname","undefined","href","handleClick","handleFocus","handleEnter","handleLeave","handleTouchStart","isActive","next","composeHandlers","handlers","e","persist","filter","Boolean","forEach","handler","defaultPrevented","resolvedActiveProps","functionalUpdate","resolvedInactiveProps","maskedLocation","join","role","Link","React","forwardRef","props","ref","linkProps","createElement","_extends"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkWO,SAASA,YAAYA,CAO1BC,OAAyE,EAC1B;EAC/C,MAAM;AAAEC,IAAAA,SAAAA;GAAW,GAAGC,wBAAS,EAAE,CAAA;EACjC,MAAMC,KAAK,GAAGC,gBAAQ,CAAC;AACrBC,IAAAA,MAAM,EAAE,KAAA;AACV,GAAC,CAAC,CAAA;EAEF,MAAM;AACJ;IACAC,IAAI;IACJC,QAAQ;IACRC,MAAM;IACNC,WAAW,GAAGA,OAAO;AAAEC,MAAAA,SAAS,EAAE,QAAA;AAAS,KAAC,CAAC;AAC7CC,IAAAA,aAAa,GAAGA,OAAO,EAAE,CAAC;IAC1BC,aAAa;IACbC,QAAQ;IACRC,IAAI;IACJC,MAAM;IACNC,MAAM;IACNC,EAAE;IACFC,KAAK;IACLC,IAAI;IACJC,OAAO;IACPC,YAAY;IACZC,OAAO;IACPC,eAAe;AACf;IACAC,KAAK;IACLd,SAAS;IACTe,OAAO;IACPC,OAAO;IACPC,YAAY;IACZC,YAAY;IACZC,YAAY;IACZ,GAAGC,IAAAA;AACL,GAAC,GAAG9B,OAAO,CAAA;EAEX,MAAM+B,QAAQ,GAAG9B,SAAS,CAAC;IACzB+B,IAAI,EAAEhC,OAAO,CAACiB,E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AAQ,KAAK,UAAU,GAChCsD,KAAK,CAACtD,QAAQ,CAAC;AACbkC,MAAAA,QAAQ,EAAGsB,SAAS,CAAS,aAAa,CAAC,KAAK,QAAA;KACjD,CAAC,GACFF,KAAK,CAACtD,QAAAA;AAAQ,GAAA,CAEvB,CAAC,CAAA;AAEN,CAAC;;;;;"}
1
+ {"version":3,"file":"link.js","sources":["../../src/link.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useMatch } from './Matches'\nimport { useRouter } from './RouterProvider'\nimport { Trim } from './fileRoute'\nimport { LocationState, ParsedLocation } from './location'\nimport { AnyRoute, ReactNode } from './route'\nimport {\n AllParams,\n FullSearchSchema,\n RouteByPath,\n RouteIds,\n RoutePaths,\n} from './routeInfo'\nimport { RegisteredRouter } from './router'\nimport { MakeLinkOptions, MakeLinkPropsOptions } from './useNavigate'\nimport {\n Expand,\n NoInfer,\n NonNullableUpdater,\n PickRequired,\n UnionToIntersection,\n Updater,\n functionalUpdate,\n} from './utils'\n\nexport type LinkInfo =\n | {\n type: 'external'\n href: string\n }\n | {\n type: 'internal'\n next: ParsedLocation\n handleFocus: (e: any) => void\n handleClick: (e: any) => void\n handleEnter: (e: any) => void\n handleLeave: (e: any) => void\n handleTouchStart: (e: any) => void\n isActive: boolean\n disabled?: boolean\n }\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<LocationState>\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 // fromCurrent?: boolean\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 UnionToIntersection<\n PickRequired<\n RouteByPath<TRouteTree, TFrom>['types']['fullSearchSchema']\n >\n >\n >,\n TFromSearchOptional = Omit<AllParams<TRouteTree>, keyof TFromSearchEnsured>,\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> = 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\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 options: MakeLinkPropsOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n): React.AnchorHTMLAttributes<HTMLAnchorElement> {\n const { buildLink } = useRouter()\n const match = useMatch({\n strict: false,\n })\n\n const {\n // custom props\n type,\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,\n preloadDelay,\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 const linkInfo = buildLink({\n from: options.to ? match.pathname : undefined,\n ...options,\n } as any)\n\n if (linkInfo.type === 'external') {\n const { href } = linkInfo\n return { href }\n }\n\n const {\n handleClick,\n handleFocus,\n handleEnter,\n handleLeave,\n handleTouchStart,\n isActive,\n next,\n } = linkInfo\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: MakeLinkOptions<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"],"names":["useLinkProps","options","buildLink","useRouter","match","useMatch","strict","type","children","target","activeProps","className","inactiveProps","activeOptions","disabled","hash","search","params","to","state","mask","preload","preloadDelay","replace","startTransition","resetScroll","style","onClick","onFocus","onMouseEnter","onMouseLeave","onTouchStart","rest","linkInfo","from","pathname","undefined","href","handleClick","handleFocus","handleEnter","handleLeave","handleTouchStart","isActive","next","composeHandlers","handlers","e","persist","filter","Boolean","forEach","handler","defaultPrevented","resolvedActiveProps","functionalUpdate","resolvedInactiveProps","maskedLocation","join","role","Link","React","forwardRef","props","ref","linkProps","createElement","_extends"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkWO,SAASA,YAAYA,CAO1BC,OAAyE,EAC1B;EAC/C,MAAM;AAAEC,IAAAA,SAAAA;GAAW,GAAGC,wBAAS,EAAE,CAAA;EACjC,MAAMC,KAAK,GAAGC,gBAAQ,CAAC;AACrBC,IAAAA,MAAM,EAAE,KAAA;AACV,GAAC,CAAC,CAAA;EAEF,MAAM;AACJ;IACAC,IAAI;IACJC,QAAQ;IACRC,MAAM;IACNC,WAAW,GAAGA,OAAO;AAAEC,MAAAA,SAAS,EAAE,QAAA;AAAS,KAAC,CAAC;AAC7CC,IAAAA,aAAa,GAAGA,OAAO,EAAE,CAAC;IAC1BC,aAAa;IACbC,QAAQ;IACRC,IAAI;IACJC,MAAM;IACNC,MAAM;IACNC,EAAE;IACFC,KAAK;IACLC,IAAI;IACJC,OAAO;IACPC,YAAY;IACZC,OAAO;IACPC,eAAe;IACfC,WAAW;AACX;IACAC,KAAK;IACLf,SAAS;IACTgB,OAAO;IACPC,OAAO;IACPC,YAAY;IACZC,YAAY;IACZC,YAAY;IACZ,GAAGC,IAAAA;AACL,GA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IH,IAAAA,GAAG,EAAEA,GAAAA;AAAU,GAAA,EACZC,SAAS,EAAA;IACZzD,QAAQ,EACN,OAAOuD,KAAK,CAACvD,QAAQ,KAAK,UAAU,GAChCuD,KAAK,CAACvD,QAAQ,CAAC;AACbmC,MAAAA,QAAQ,EAAGsB,SAAS,CAAS,aAAa,CAAC,KAAK,QAAA;KACjD,CAAC,GACFF,KAAK,CAACvD,QAAAA;AAAQ,GAAA,CAEvB,CAAC,CAAA;AAEN,CAAC;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"router.js","sources":["../../src/router.ts"],"sourcesContent":["import { RouterHistory } from '@tanstack/history'\n\n//\n\nimport {\n AnySearchSchema,\n AnyRoute,\n AnyContext,\n AnyPathParams,\n RouteMask,\n} from './route'\nimport { FullSearchSchema } from './routeInfo'\nimport { defaultParseSearch, defaultStringifySearch } from './searchParams'\nimport { PickAsRequired, Updater, NonNullableUpdater } from './utils'\nimport {\n ErrorRouteComponent,\n PendingRouteComponent,\n RouteComponent,\n} from './route'\nimport { RouteMatch } from './RouterProvider'\nimport { ParsedLocation } from './location'\nimport { LocationState } from './location'\nimport { SearchSerializer, SearchParser } from './searchParams'\nimport { RouterContext } from './RouterProvider'\n\n//\n\ndeclare global {\n interface Window {\n __TSR_DEHYDRATED__?: HydrationCtx\n __TSR_ROUTER_CONTEXT__?: React.Context<RouterContext<any>>\n }\n}\n\nexport interface Register {\n // router: Router\n}\n\nexport type AnyRouter = Router<any, any>\n\nexport type RegisteredRouter = Register extends {\n router: infer TRouter extends AnyRouter\n}\n ? TRouter\n : AnyRouter\n\nexport type HydrationCtx = {\n router: DehydratedRouter\n payload: Record<string, any>\n}\n\nexport type RouterContextOptions<TRouteTree extends AnyRoute> =\n AnyContext extends TRouteTree['types']['routerContext']\n ? {\n context?: TRouteTree['types']['routerContext']\n }\n : {\n context: TRouteTree['types']['routerContext']\n }\n\nexport interface RouterOptions<\n TRouteTree extends AnyRoute,\n TDehydrated extends Record<string, any> = Record<string, any>,\n> {\n history?: RouterHistory\n stringifySearch?: SearchSerializer\n parseSearch?: SearchParser\n defaultPreload?: false | 'intent'\n defaultPreloadDelay?: number\n defaultComponent?: RouteComponent<AnySearchSchema, AnyPathParams, AnyContext>\n defaultErrorComponent?: ErrorRouteComponent<\n AnySearchSchema,\n AnyPathParams,\n AnyContext\n >\n defaultPendingComponent?: PendingRouteComponent<\n AnySearchSchema,\n AnyPathParams,\n AnyContext\n >\n defaultMaxAge?: number\n defaultGcMaxAge?: number\n defaultPreloadMaxAge?: number\n caseSensitive?: boolean\n routeTree?: TRouteTree\n basepath?: string\n createRoute?: (opts: { route: AnyRoute; router: AnyRouter }) => void\n context?: TRouteTree['types']['routerContext']\n // dehydrate?: () => TDehydrated\n // hydrate?: (dehydrated: TDehydrated) => void\n routeMasks?: RouteMask<TRouteTree>[]\n unmaskOnReload?: boolean\n}\n\nexport interface RouterState<TRouteTree extends AnyRoute = AnyRoute> {\n status: 'pending' | 'idle'\n matches: RouteMatch<TRouteTree>[]\n pendingMatches: RouteMatch<TRouteTree>[]\n location: ParsedLocation<FullSearchSchema<TRouteTree>>\n resolvedLocation: undefined | ParsedLocation<FullSearchSchema<TRouteTree>>\n lastUpdated: number\n}\n\nexport type ListenerFn<TEvent extends RouterEvent> = (event: TEvent) => void\n\nexport interface BuildNextOptions {\n to?: string | number | null\n params?: true | Updater<unknown>\n search?: true | Updater<unknown>\n hash?: true | Updater<string>\n state?: true | NonNullableUpdater<LocationState>\n mask?: {\n to?: string | number | null\n params?: true | Updater<unknown>\n search?: true | Updater<unknown>\n hash?: true | Updater<string>\n state?: true | NonNullableUpdater<LocationState>\n unmaskOnReload?: boolean\n }\n from?: string\n}\n\nexport interface DehydratedRouterState {\n dehydratedMatches: DehydratedRouteMatch[]\n}\n\nexport type DehydratedRouteMatch = Pick<\n RouteMatch,\n 'fetchedAt' | 'invalid' | 'id' | 'status' | 'updatedAt'\n>\n\nexport interface DehydratedRouter {\n state: DehydratedRouterState\n}\n\nexport type RouterConstructorOptions<\n TRouteTree extends AnyRoute,\n TDehydrated extends Record<string, any>,\n> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> &\n RouterContextOptions<TRouteTree>\n\nexport const componentTypes = [\n 'component',\n 'errorComponent',\n 'pendingComponent',\n] as const\n\nexport type RouterEvents = {\n onBeforeLoad: {\n type: 'onBeforeLoad'\n from: undefined | ParsedLocation\n to: ParsedLocation\n pathChanged: boolean\n }\n onLoad: {\n type: 'onLoad'\n from: undefined | ParsedLocation\n to: ParsedLocation\n pathChanged: boolean\n }\n}\n\nexport type RouterEvent = RouterEvents[keyof RouterEvents]\n\nexport type RouterListener<TRouterEvent extends RouterEvent> = {\n eventType: TRouterEvent['type']\n fn: ListenerFn<TRouterEvent>\n}\n\nexport class Router<\n TRouteTree extends AnyRoute = AnyRoute,\n TDehydrated extends Record<string, any> = Record<string, any>,\n> {\n options: PickAsRequired<\n RouterOptions<TRouteTree, TDehydrated>,\n 'stringifySearch' | 'parseSearch' | 'context'\n >\n routeTree: TRouteTree\n // dehydratedData?: TDehydrated\n // resetNextScroll = false\n // tempLocationKey = `${Math.round(Math.random() * 10000000)}`\n\n constructor(options: RouterConstructorOptions<TRouteTree, TDehydrated>) {\n this.options = {\n defaultPreloadDelay: 50,\n context: undefined!,\n ...options,\n stringifySearch: options?.stringifySearch ?? defaultStringifySearch,\n parseSearch: options?.parseSearch ?? defaultParseSearch,\n }\n\n this.routeTree = this.options.routeTree as TRouteTree\n }\n\n subscribers = new Set<RouterListener<RouterEvent>>()\n\n subscribe = <TType extends keyof RouterEvents>(\n eventType: TType,\n fn: ListenerFn<RouterEvents[TType]>,\n ) => {\n const listener: RouterListener<any> = {\n eventType,\n fn,\n }\n\n this.subscribers.add(listener)\n\n return () => {\n this.subscribers.delete(listener)\n }\n }\n\n emit = (routerEvent: RouterEvent) => {\n this.subscribers.forEach((listener) => {\n if (listener.eventType === routerEvent.type) {\n listener.fn(routerEvent)\n }\n })\n }\n\n // dehydrate = (): DehydratedRouter => {\n // return {\n // state: {\n // dehydratedMatches: state.matches.map((d) =>\n // pick(d, ['fetchedAt', 'invalid', 'id', 'status', 'updatedAt']),\n // ),\n // },\n // }\n // }\n\n // hydrate = async (__do_not_use_server_ctx?: HydrationCtx) => {\n // let _ctx = __do_not_use_server_ctx\n // // Client hydrates from window\n // if (typeof document !== 'undefined') {\n // _ctx = window.__TSR_DEHYDRATED__\n // }\n\n // invariant(\n // _ctx,\n // 'Expected to find a __TSR_DEHYDRATED__ property on window... but we did not. Did you forget to render <DehydrateRouter /> in your app?',\n // )\n\n // const ctx = _ctx\n // this.dehydratedData = ctx.payload as any\n // this.options.hydrate?.(ctx.payload as any)\n // const dehydratedState = ctx.router.state\n\n // let matches = this.matchRoutes(\n // state.location.pathname,\n // state.location.search,\n // ).map((match) => {\n // const dehydratedMatch = dehydratedState.dehydratedMatches.find(\n // (d) => d.id === match.id,\n // )\n\n // invariant(\n // dehydratedMatch,\n // `Could not find a client-side match for dehydrated match with id: ${match.id}!`,\n // )\n\n // if (dehydratedMatch) {\n // return {\n // ...match,\n // ...dehydratedMatch,\n // }\n // }\n // return match\n // })\n\n // this.setState((s) => {\n // return {\n // ...s,\n // matches: dehydratedState.dehydratedMatches as any,\n // }\n // })\n // }\n\n // TODO:\n // injectedHtml: (string | (() => Promise<string> | string))[] = []\n\n // TODO:\n // injectHtml = async (html: string | (() => Promise<string> | string)) => {\n // this.injectedHtml.push(html)\n // }\n\n // TODO:\n // dehydrateData = <T>(key: any, getData: T | (() => Promise<T> | T)) => {\n // if (typeof document === 'undefined') {\n // const strKey = typeof key === 'string' ? key : JSON.stringify(key)\n\n // this.injectHtml(async () => {\n // const id = `__TSR_DEHYDRATED__${strKey}`\n // const data =\n // typeof getData === 'function' ? await (getData as any)() : getData\n // return `<script id='${id}' suppressHydrationWarning>window[\"__TSR_DEHYDRATED__${escapeJSON(\n // strKey,\n // )}\"] = ${JSON.stringify(data)}\n // ;(() => {\n // var el = document.getElementById('${id}')\n // el.parentElement.removeChild(el)\n // })()\n // </script>`\n // })\n\n // return () => this.hydrateData<T>(key)\n // }\n\n // return () => undefined\n // }\n\n // hydrateData = <T = unknown>(key: any) => {\n // if (typeof document !== 'undefined') {\n // const strKey = typeof key === 'string' ? key : JSON.stringify(key)\n\n // return window[`__TSR_DEHYDRATED__${strKey}` as any] as T\n // }\n\n // return undefined\n // }\n\n // resolveMatchPromise = (matchId: string, key: string, value: any) => {\n // state.matches\n // .find((d) => d.id === matchId)\n // ?.__promisesByKey[key]?.resolve(value)\n // }\n\n // setRouteMatch = (\n // id: string,\n // pending: boolean,\n // updater: NonNullableUpdater<RouteMatch<TRouteTree>>,\n // ) => {\n // const key = pending ? 'pendingMatches' : 'matches'\n\n // this.setState((prev) => {\n // return {\n // ...prev,\n // [key]: prev[key].map((d) => {\n // if (d.id === id) {\n // return functionalUpdate(updater, d)\n // }\n\n // return d\n // }),\n // }\n // })\n // }\n\n // setPendingRouteMatch = (\n // id: string,\n // updater: NonNullableUpdater<RouteMatch<TRouteTree>>,\n // ) => {\n // this.setRouteMatch(id, true, updater)\n // }\n}\n\nfunction 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\n// A function that takes an import() argument which is a function and returns a new function that will\n// proxy arguments from the caller to the imported function, retaining all type\n// information along the way\nexport function lazyFn<\n T extends Record<string, (...args: any[]) => any>,\n TKey extends keyof T = 'default',\n>(fn: () => Promise<T>, key?: TKey) {\n return async (...args: Parameters<T[TKey]>): Promise<ReturnType<T[TKey]>> => {\n const imported = await fn()\n return imported[key || 'default'](...args)\n }\n}\n"],"names":["componentTypes","Router","constructor","options","defaultPreloadDelay","context","undefined","stringifySearch","defaultStringifySearch","parseSearch","defaultParseSearch","routeTree","subscribers","Set","subscribe","eventType","fn","listener","add","delete","emit","routerEvent","forEach","type","lazyFn","key","args","imported"],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AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACF,CAAA;;AASA;AACA;AACA;AACO,SAASG,MAAMA,CAGpBR,EAAoB,EAAES,GAAU,EAAE;EAClC,OAAO,OAAO,GAAGC,IAAyB,KAAmC;AAC3E,IAAA,MAAMC,QAAQ,GAAG,MAAMX,EAAE,EAAE,CAAA;IAC3B,OAAOW,QAAQ,CAACF,GAAG,IAAI,SAAS,CAAC,CAAC,GAAGC,IAAI,CAAC,CAAA;GAC3C,CAAA;AACH;;;;;;"}
1
+ {"version":3,"file":"router.js","sources":["../../src/router.ts"],"sourcesContent":["import { RouterHistory } from '@tanstack/history'\n\n//\n\nimport {\n AnySearchSchema,\n AnyRoute,\n AnyContext,\n AnyPathParams,\n RouteMask,\n} from './route'\nimport { FullSearchSchema } from './routeInfo'\nimport { defaultParseSearch, defaultStringifySearch } from './searchParams'\nimport { PickAsRequired, Updater, NonNullableUpdater } from './utils'\nimport {\n ErrorRouteComponent,\n PendingRouteComponent,\n RouteComponent,\n} from './route'\nimport { RouteMatch } from './RouterProvider'\nimport { ParsedLocation } from './location'\nimport { LocationState } from './location'\nimport { SearchSerializer, SearchParser } from './searchParams'\nimport { RouterContext } from './RouterProvider'\n\n//\n\ndeclare global {\n interface Window {\n __TSR_DEHYDRATED__?: HydrationCtx\n __TSR_ROUTER_CONTEXT__?: React.Context<RouterContext<any>>\n }\n}\n\nexport interface Register {\n // router: Router\n}\n\nexport type AnyRouter = Router<any, any>\n\nexport type RegisteredRouter = Register extends {\n router: infer TRouter extends AnyRouter\n}\n ? TRouter\n : AnyRouter\n\nexport type HydrationCtx = {\n router: DehydratedRouter\n payload: Record<string, any>\n}\n\nexport type RouterContextOptions<TRouteTree extends AnyRoute> =\n AnyContext extends TRouteTree['types']['routerContext']\n ? {\n context?: TRouteTree['types']['routerContext']\n }\n : {\n context: TRouteTree['types']['routerContext']\n }\n\nexport interface RouterOptions<\n TRouteTree extends AnyRoute,\n TDehydrated extends Record<string, any> = Record<string, any>,\n> {\n history?: RouterHistory\n stringifySearch?: SearchSerializer\n parseSearch?: SearchParser\n defaultPreload?: false | 'intent'\n defaultPreloadDelay?: number\n defaultComponent?: RouteComponent<AnySearchSchema, AnyPathParams, AnyContext>\n defaultErrorComponent?: ErrorRouteComponent<\n AnySearchSchema,\n AnyPathParams,\n AnyContext\n >\n defaultPendingComponent?: PendingRouteComponent<\n AnySearchSchema,\n AnyPathParams,\n AnyContext\n >\n defaultMaxAge?: number\n defaultGcMaxAge?: number\n defaultPreloadMaxAge?: number\n caseSensitive?: boolean\n routeTree?: TRouteTree\n basepath?: string\n createRoute?: (opts: { route: AnyRoute; router: AnyRouter }) => void\n context?: TRouteTree['types']['routerContext']\n // dehydrate?: () => TDehydrated\n // hydrate?: (dehydrated: TDehydrated) => void\n routeMasks?: RouteMask<TRouteTree>[]\n unmaskOnReload?: boolean\n}\n\nexport interface RouterState<TRouteTree extends AnyRoute = AnyRoute> {\n status: 'pending' | 'idle'\n matches: RouteMatch<TRouteTree>[]\n pendingMatches: RouteMatch<TRouteTree>[]\n location: ParsedLocation<FullSearchSchema<TRouteTree>>\n resolvedLocation: ParsedLocation<FullSearchSchema<TRouteTree>>\n lastUpdated: number\n}\n\nexport type ListenerFn<TEvent extends RouterEvent> = (event: TEvent) => void\n\nexport interface BuildNextOptions {\n to?: string | number | null\n params?: true | Updater<unknown>\n search?: true | Updater<unknown>\n hash?: true | Updater<string>\n state?: true | NonNullableUpdater<LocationState>\n mask?: {\n to?: string | number | null\n params?: true | Updater<unknown>\n search?: true | Updater<unknown>\n hash?: true | Updater<string>\n state?: true | NonNullableUpdater<LocationState>\n unmaskOnReload?: boolean\n }\n from?: string\n}\n\nexport interface DehydratedRouterState {\n dehydratedMatches: DehydratedRouteMatch[]\n}\n\nexport type DehydratedRouteMatch = Pick<\n RouteMatch,\n 'fetchedAt' | 'invalid' | 'id' | 'status' | 'updatedAt'\n>\n\nexport interface DehydratedRouter {\n state: DehydratedRouterState\n}\n\nexport type RouterConstructorOptions<\n TRouteTree extends AnyRoute,\n TDehydrated extends Record<string, any>,\n> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> &\n RouterContextOptions<TRouteTree>\n\nexport const componentTypes = [\n 'component',\n 'errorComponent',\n 'pendingComponent',\n] as const\n\nexport type RouterEvents = {\n onBeforeLoad: {\n type: 'onBeforeLoad'\n fromLocation: ParsedLocation\n toLocation: ParsedLocation\n pathChanged: boolean\n }\n onLoad: {\n type: 'onLoad'\n fromLocation: ParsedLocation\n toLocation: ParsedLocation\n pathChanged: boolean\n }\n onResolved: {\n type: 'onResolved'\n fromLocation: ParsedLocation\n toLocation: ParsedLocation\n pathChanged: boolean\n }\n}\n\nexport type RouterEvent = RouterEvents[keyof RouterEvents]\n\nexport type RouterListener<TRouterEvent extends RouterEvent> = {\n eventType: TRouterEvent['type']\n fn: ListenerFn<TRouterEvent>\n}\n\nexport class Router<\n TRouteTree extends AnyRoute = AnyRoute,\n TDehydrated extends Record<string, any> = Record<string, any>,\n> {\n options: PickAsRequired<\n RouterOptions<TRouteTree, TDehydrated>,\n 'stringifySearch' | 'parseSearch' | 'context'\n >\n routeTree: TRouteTree\n // dehydratedData?: TDehydrated\n // resetNextScroll = false\n // tempLocationKey = `${Math.round(Math.random() * 10000000)}`\n\n constructor(options: RouterConstructorOptions<TRouteTree, TDehydrated>) {\n this.options = {\n defaultPreloadDelay: 50,\n context: undefined!,\n ...options,\n stringifySearch: options?.stringifySearch ?? defaultStringifySearch,\n parseSearch: options?.parseSearch ?? defaultParseSearch,\n }\n\n this.routeTree = this.options.routeTree as TRouteTree\n }\n\n subscribers = new Set<RouterListener<RouterEvent>>()\n\n subscribe = <TType extends keyof RouterEvents>(\n eventType: TType,\n fn: ListenerFn<RouterEvents[TType]>,\n ) => {\n const listener: RouterListener<any> = {\n eventType,\n fn,\n }\n\n this.subscribers.add(listener)\n\n return () => {\n this.subscribers.delete(listener)\n }\n }\n\n emit = (routerEvent: RouterEvent) => {\n this.subscribers.forEach((listener) => {\n if (listener.eventType === routerEvent.type) {\n listener.fn(routerEvent)\n }\n })\n }\n\n // dehydrate = (): DehydratedRouter => {\n // return {\n // state: {\n // dehydratedMatches: state.matches.map((d) =>\n // pick(d, ['fetchedAt', 'invalid', 'id', 'status', 'updatedAt']),\n // ),\n // },\n // }\n // }\n\n // hydrate = async (__do_not_use_server_ctx?: HydrationCtx) => {\n // let _ctx = __do_not_use_server_ctx\n // // Client hydrates from window\n // if (typeof document !== 'undefined') {\n // _ctx = window.__TSR_DEHYDRATED__\n // }\n\n // invariant(\n // _ctx,\n // 'Expected to find a __TSR_DEHYDRATED__ property on window... but we did not. Did you forget to render <DehydrateRouter /> in your app?',\n // )\n\n // const ctx = _ctx\n // this.dehydratedData = ctx.payload as any\n // this.options.hydrate?.(ctx.payload as any)\n // const dehydratedState = ctx.router.state\n\n // let matches = this.matchRoutes(\n // state.location.pathname,\n // state.location.search,\n // ).map((match) => {\n // const dehydratedMatch = dehydratedState.dehydratedMatches.find(\n // (d) => d.id === match.id,\n // )\n\n // invariant(\n // dehydratedMatch,\n // `Could not find a client-side match for dehydrated match with id: ${match.id}!`,\n // )\n\n // if (dehydratedMatch) {\n // return {\n // ...match,\n // ...dehydratedMatch,\n // }\n // }\n // return match\n // })\n\n // this.setState((s) => {\n // return {\n // ...s,\n // matches: dehydratedState.dehydratedMatches as any,\n // }\n // })\n // }\n\n // TODO:\n // injectedHtml: (string | (() => Promise<string> | string))[] = []\n\n // TODO:\n // injectHtml = async (html: string | (() => Promise<string> | string)) => {\n // this.injectedHtml.push(html)\n // }\n\n // TODO:\n // dehydrateData = <T>(key: any, getData: T | (() => Promise<T> | T)) => {\n // if (typeof document === 'undefined') {\n // const strKey = typeof key === 'string' ? key : JSON.stringify(key)\n\n // this.injectHtml(async () => {\n // const id = `__TSR_DEHYDRATED__${strKey}`\n // const data =\n // typeof getData === 'function' ? await (getData as any)() : getData\n // return `<script id='${id}' suppressHydrationWarning>window[\"__TSR_DEHYDRATED__${escapeJSON(\n // strKey,\n // )}\"] = ${JSON.stringify(data)}\n // ;(() => {\n // var el = document.getElementById('${id}')\n // el.parentElement.removeChild(el)\n // })()\n // </script>`\n // })\n\n // return () => this.hydrateData<T>(key)\n // }\n\n // return () => undefined\n // }\n\n // hydrateData = <T = unknown>(key: any) => {\n // if (typeof document !== 'undefined') {\n // const strKey = typeof key === 'string' ? key : JSON.stringify(key)\n\n // return window[`__TSR_DEHYDRATED__${strKey}` as any] as T\n // }\n\n // return undefined\n // }\n\n // resolveMatchPromise = (matchId: string, key: string, value: any) => {\n // state.matches\n // .find((d) => d.id === matchId)\n // ?.__promisesByKey[key]?.resolve(value)\n // }\n\n // setRouteMatch = (\n // id: string,\n // pending: boolean,\n // updater: NonNullableUpdater<RouteMatch<TRouteTree>>,\n // ) => {\n // const key = pending ? 'pendingMatches' : 'matches'\n\n // this.setState((prev) => {\n // return {\n // ...prev,\n // [key]: prev[key].map((d) => {\n // if (d.id === id) {\n // return functionalUpdate(updater, d)\n // }\n\n // return d\n // }),\n // }\n // })\n // }\n\n // setPendingRouteMatch = (\n // id: string,\n // updater: NonNullableUpdater<RouteMatch<TRouteTree>>,\n // ) => {\n // this.setRouteMatch(id, true, updater)\n // }\n}\n\nfunction 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\n// A function that takes an import() argument which is a function and returns a new function that will\n// proxy arguments from the caller to the imported function, retaining all type\n// information along the way\nexport function lazyFn<\n T extends Record<string, (...args: any[]) => any>,\n TKey extends keyof T = 'default',\n>(fn: () => Promise<T>, key?: TKey) {\n return async (...args: Parameters<T[TKey]>): Promise<ReturnType<T[TKey]>> => {\n const imported = await fn()\n return imported[key || 'default'](...args)\n }\n}\n"],"names":["componentTypes","Router","constructor","options","defaultPreloadDelay","context","undefined","stringifySearch","defaultStringifySearch","parseSearch","defaultParseSearch","routeTree","subscribers","Set","subscribe","eventType","fn","listener","add","delete","emit","routerEvent","forEach","type","lazyFn","key","args","imported"],"mappings":";;;;;;;;;;;;;;;;AAEA;;AAuBA;;AAoHO,MAAMA,cAAc,GAAG,CAC5B,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EACV;AA8BH,MAAMC,MAAM,CAGjB;AAMA;AACA;AACA;EAEAC,WAAWA,CAACC,OAA0D,EAAE;IACtE,IAAI,CAACA,OAAO,GAAG;AACbC,MAAAA,mBAAmB,EAAE,EAAE;AACvBC,MAAAA,OAAO,EAAEC,SAAU;AACnB,MAAA,GAAGH,OAAO;AACVI,MAAAA,eAAe,EAAEJ,OAAO,EAAEI,eAAe,IAAIC,mCAAsB;AACnEC,MAAAA,WAAW,EAAEN,OAAO,EAAEM,WAAW,IAAIC,+BAAAA;KACtC,CAAA;AAED,IAAA,IAAI,CAACC,SAAS,GAAG,IAAI,CAACR,OAAO,CAACQ,SAAuB,CAAA;AACvD,GAAA;AAEAC,EAAAA,WAAW,GAAG,IAAIC,GAAG,EAA+B,CAAA;AAEpDC,EAAAA,SAAS,GAAGA,CACVC,SAAgB,EAChBC,EAAmC,KAChC;AACH,IAAA,MAAMC,QAA6B,GAAG;MACpCF,SAAS;AACTC,MAAAA,EAAAA;KACD,CAAA;AAED,IAAA,IAAI,CAACJ,WAAW,CAACM,GAAG,CAACD,QAAQ,CAAC,CAAA;AAE9B,IAAA,OAAO,MAAM;AACX,MAAA,IAAI,CAACL,WAAW,CAACO,MAAM,CAACF,QAAQ,CAAC,CAAA;KAClC,CAAA;GACF,CAAA;EAEDG,IAAI,GAAIC,WAAwB,IAAK;AACnC,IAAA,IAAI,CAACT,WAAW,CAACU,OAAO,CAAEL,QAAQ,IAAK;AACrC,MAAA,IAAIA,QAAQ,CAACF,SAAS,KAAKM,WAAW,CAACE,IAAI,EAAE;AAC3CN,QAAAA,QAAQ,CAACD,EAAE,CAACK,WAAW,CAAC,CAAA;AAC1B,OAAA;AACF,KAAC,CAAC,CAAA;GACH,CAAA;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACF,CAAA;;AASA;AACA;AACA;AACO,SAASG,MAAMA,CAGpBR,EAAoB,EAAES,GAAU,EAAE;EAClC,OAAO,OAAO,GAAGC,IAAyB,KAAmC;AAC3E,IAAA,MAAMC,QAAQ,GAAG,MAAMX,EAAE,EAAE,CAAA;IAC3B,OAAOW,QAAQ,CAACF,GAAG,IAAI,SAAS,CAAC,CAAC,GAAGC,IAAI,CAAC,CAAA;GAC3C,CAAA;AACH;;;;;;"}
@@ -0,0 +1,186 @@
1
+ /**
2
+ * @tanstack/react-router/src/index.tsx
3
+ *
4
+ * Copyright (c) TanStack
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ 'use strict';
12
+
13
+ Object.defineProperty(exports, '__esModule', { value: true });
14
+
15
+ var React = require('react');
16
+ var RouterProvider = require('./RouterProvider.js');
17
+ var utils = require('./utils.js');
18
+
19
+ function _interopNamespace(e) {
20
+ if (e && e.__esModule) return e;
21
+ var n = Object.create(null);
22
+ if (e) {
23
+ Object.keys(e).forEach(function (k) {
24
+ if (k !== 'default') {
25
+ var d = Object.getOwnPropertyDescriptor(e, k);
26
+ Object.defineProperty(n, k, d.get ? d : {
27
+ enumerable: true,
28
+ get: function () { return e[k]; }
29
+ });
30
+ }
31
+ });
32
+ }
33
+ n["default"] = e;
34
+ return Object.freeze(n);
35
+ }
36
+
37
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
38
+
39
+ const useLayoutEffect = typeof window !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
40
+ const windowKey = 'window';
41
+ const delimiter = '___';
42
+ let weakScrolledElements = new WeakSet();
43
+ let cache;
44
+ const sessionsStorage = typeof window !== 'undefined' && window.sessionStorage;
45
+ const defaultGetKey = location => location.state.key;
46
+ function useScrollRestoration(options) {
47
+ const {
48
+ state,
49
+ subscribe,
50
+ resetNextScrollRef
51
+ } = RouterProvider.useRouter();
52
+ useLayoutEffect(() => {
53
+ const getKey = options?.getKey || defaultGetKey;
54
+ if (sessionsStorage) {
55
+ if (!cache) {
56
+ cache = (() => {
57
+ const storageKey = 'tsr-scroll-restoration-v2';
58
+ const state = JSON.parse(window.sessionStorage.getItem(storageKey) || 'null') || {
59
+ cached: {},
60
+ next: {}
61
+ };
62
+ return {
63
+ state,
64
+ set: updater => {
65
+ cache.state = utils.functionalUpdate(updater, cache.state);
66
+ window.sessionStorage.setItem(storageKey, JSON.stringify(cache.state));
67
+ }
68
+ };
69
+ })();
70
+ }
71
+ }
72
+ const {
73
+ history
74
+ } = window;
75
+ if (history.scrollRestoration) {
76
+ history.scrollRestoration = 'manual';
77
+ }
78
+ const onScroll = event => {
79
+ if (weakScrolledElements.has(event.target)) return;
80
+ weakScrolledElements.add(event.target);
81
+ const elementSelector = event.target === document || event.target === window ? windowKey : getCssSelector(event.target);
82
+ if (!cache.state.next[elementSelector]) {
83
+ cache.set(c => ({
84
+ ...c,
85
+ next: {
86
+ ...c.next,
87
+ [elementSelector]: {
88
+ scrollX: NaN,
89
+ scrollY: NaN
90
+ }
91
+ }
92
+ }));
93
+ }
94
+ };
95
+ const getCssSelector = el => {
96
+ let path = [],
97
+ parent;
98
+ while (parent = el.parentNode) {
99
+ path.unshift(`${el.tagName}:nth-child(${[].indexOf.call(parent.children, el) + 1})`);
100
+ el = parent;
101
+ }
102
+ return `${path.join(' > ')}`.toLowerCase();
103
+ };
104
+ if (typeof document !== 'undefined') {
105
+ document.addEventListener('scroll', onScroll, true);
106
+ }
107
+ const unsubOnBeforeLoad = subscribe('onBeforeLoad', event => {
108
+ if (event.pathChanged) {
109
+ const restoreKey = getKey(event.fromLocation);
110
+ for (const elementSelector in cache.state.next) {
111
+ const entry = cache.state.next[elementSelector];
112
+ if (elementSelector === windowKey) {
113
+ entry.scrollX = window.scrollX || 0;
114
+ entry.scrollY = window.scrollY || 0;
115
+ } else if (elementSelector) {
116
+ const element = document.querySelector(elementSelector);
117
+ entry.scrollX = element?.scrollLeft || 0;
118
+ entry.scrollY = element?.scrollTop || 0;
119
+ }
120
+ cache.set(c => {
121
+ const next = {
122
+ ...c.next
123
+ };
124
+ delete next[elementSelector];
125
+ return {
126
+ ...c,
127
+ next,
128
+ cached: {
129
+ ...c.cached,
130
+ [[restoreKey, elementSelector].join(delimiter)]: entry
131
+ }
132
+ };
133
+ });
134
+ }
135
+ }
136
+ });
137
+ const unsubOnResolved = subscribe('onResolved', event => {
138
+ if (event.pathChanged) {
139
+ if (!resetNextScrollRef.current) {
140
+ return;
141
+ }
142
+ resetNextScrollRef.current = true;
143
+ const getKey = options?.getKey || defaultGetKey;
144
+ const restoreKey = getKey(event.toLocation);
145
+ let windowRestored = false;
146
+ for (const cacheKey in cache.state.cached) {
147
+ const entry = cache.state.cached[cacheKey];
148
+ const [key, elementSelector] = cacheKey.split(delimiter);
149
+ if (key === restoreKey) {
150
+ if (elementSelector === windowKey) {
151
+ windowRestored = true;
152
+ window.scrollTo(entry.scrollX, entry.scrollY);
153
+ } else if (elementSelector) {
154
+ const element = document.querySelector(elementSelector);
155
+ if (element) {
156
+ element.scrollLeft = entry.scrollX;
157
+ element.scrollTop = entry.scrollY;
158
+ }
159
+ }
160
+ }
161
+ }
162
+ if (!windowRestored) {
163
+ window.scrollTo(0, 0);
164
+ }
165
+ cache.set(c => ({
166
+ ...c,
167
+ next: {}
168
+ }));
169
+ weakScrolledElements = new WeakSet();
170
+ }
171
+ });
172
+ return () => {
173
+ document.removeEventListener('scroll', onScroll);
174
+ unsubOnBeforeLoad();
175
+ unsubOnResolved();
176
+ };
177
+ }, []);
178
+ }
179
+ function ScrollRestoration(props) {
180
+ useScrollRestoration(props);
181
+ return null;
182
+ }
183
+
184
+ exports.ScrollRestoration = ScrollRestoration;
185
+ exports.useScrollRestoration = useScrollRestoration;
186
+ //# sourceMappingURL=scroll-restoration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scroll-restoration.js","sources":["../../src/scroll-restoration.tsx"],"sourcesContent":["import * as React from 'react'\n\nconst useLayoutEffect =\n typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\nimport { ParsedLocation } from './location'\nimport { useRouter } from './RouterProvider'\nimport { NonNullableUpdater, functionalUpdate } from './utils'\n\nconst windowKey = 'window'\nconst delimiter = '___'\n\nlet weakScrolledElements = new WeakSet<any>()\n\ntype CacheValue = Record<string, { scrollX: number; scrollY: number }>\ntype CacheState = {\n cached: CacheValue\n next: CacheValue\n}\n\ntype Cache = {\n state: CacheState\n set: (updater: NonNullableUpdater<CacheState>) => void\n}\n\nlet cache: Cache\n\nconst sessionsStorage = typeof window !== 'undefined' && window.sessionStorage\n\nexport type ScrollRestorationOptions = {\n getKey?: (location: ParsedLocation) => string\n}\n\nconst defaultGetKey = (location: ParsedLocation) => location.state.key!\n\nexport function useScrollRestoration(options?: ScrollRestorationOptions) {\n const { state, subscribe, resetNextScrollRef } = useRouter()\n\n useLayoutEffect(() => {\n const getKey = options?.getKey || defaultGetKey\n\n if (sessionsStorage) {\n if (!cache) {\n cache = (() => {\n const storageKey = 'tsr-scroll-restoration-v2'\n\n const state: CacheState = JSON.parse(\n window.sessionStorage.getItem(storageKey) || 'null',\n ) || { cached: {}, next: {} }\n\n return {\n state,\n set: (updater) => {\n cache.state = functionalUpdate(updater, cache.state)\n window.sessionStorage.setItem(\n storageKey,\n JSON.stringify(cache.state),\n )\n },\n }\n })()\n }\n }\n\n const { history } = window\n if (history.scrollRestoration) {\n history.scrollRestoration = 'manual'\n }\n\n const onScroll = (event: Event) => {\n if (weakScrolledElements.has(event.target)) return\n weakScrolledElements.add(event.target)\n\n const elementSelector =\n event.target === document || event.target === window\n ? windowKey\n : getCssSelector(event.target)\n\n if (!cache.state.next[elementSelector]) {\n cache.set((c) => ({\n ...c,\n next: {\n ...c.next,\n [elementSelector]: {\n scrollX: NaN,\n scrollY: NaN,\n },\n },\n }))\n }\n }\n\n const getCssSelector = (el: any): string => {\n let path = [],\n parent\n while ((parent = el.parentNode)) {\n path.unshift(\n `${el.tagName}:nth-child(${\n ([].indexOf as any).call(parent.children, el) + 1\n })`,\n )\n el = parent\n }\n return `${path.join(' > ')}`.toLowerCase()\n }\n\n if (typeof document !== 'undefined') {\n document.addEventListener('scroll', onScroll, true)\n }\n\n const unsubOnBeforeLoad = subscribe('onBeforeLoad', (event) => {\n if (event.pathChanged) {\n const restoreKey = getKey(event.fromLocation)\n for (const elementSelector in cache.state.next) {\n const entry = cache.state.next[elementSelector]!\n if (elementSelector === windowKey) {\n entry.scrollX = window.scrollX || 0\n entry.scrollY = window.scrollY || 0\n } else if (elementSelector) {\n const element = document.querySelector(elementSelector)\n entry.scrollX = element?.scrollLeft || 0\n entry.scrollY = element?.scrollTop || 0\n }\n\n cache.set((c) => {\n const next = { ...c.next }\n delete next[elementSelector]\n\n return {\n ...c,\n next,\n cached: {\n ...c.cached,\n [[restoreKey, elementSelector].join(delimiter)]: entry,\n },\n }\n })\n }\n }\n })\n\n const unsubOnResolved = subscribe('onResolved', (event) => {\n if (event.pathChanged) {\n if (!resetNextScrollRef.current) {\n return\n }\n\n resetNextScrollRef.current = true\n\n const getKey = options?.getKey || defaultGetKey\n\n const restoreKey = getKey(event.toLocation)\n let windowRestored = false\n\n for (const cacheKey in cache.state.cached) {\n const entry = cache.state.cached[cacheKey]!\n const [key, elementSelector] = cacheKey.split(delimiter)\n if (key === restoreKey) {\n if (elementSelector === windowKey) {\n windowRestored = true\n window.scrollTo(entry.scrollX, entry.scrollY)\n } else if (elementSelector) {\n const element = document.querySelector(elementSelector)\n if (element) {\n element.scrollLeft = entry.scrollX\n element.scrollTop = entry.scrollY\n }\n }\n }\n }\n\n if (!windowRestored) {\n window.scrollTo(0, 0)\n }\n\n cache.set((c) => ({ ...c, next: {} }))\n weakScrolledElements = new WeakSet<any>()\n }\n })\n\n return () => {\n document.removeEventListener('scroll', onScroll)\n unsubOnBeforeLoad()\n unsubOnResolved()\n }\n }, [])\n}\n\nexport function ScrollRestoration(props: ScrollRestorationOptions) {\n useScrollRestoration(props)\n return null\n}\n"],"names":["useLayoutEffect","window","React","useEffect","windowKey","delimiter","weakScrolledElements","WeakSet","cache","sessionsStorage","sessionStorage","defaultGetKey","location","state","key","useScrollRestoration","options","subscribe","resetNextScrollRef","useRouter","getKey","storageKey","JSON","parse","getItem","cached","next","set","updater","functionalUpdate","setItem","stringify","history","scrollRestoration","onScroll","event","has","target","add","elementSelector","document","getCssSelector","c","scrollX","NaN","scrollY","el","path","parent","parentNode","unshift","tagName","indexOf","call","children","join","toLowerCase","addEventListener","unsubOnBeforeLoad","pathChanged","restoreKey","fromLocation","entry","element","querySelector","scrollLeft","scrollTop","unsubOnResolved","current","toLocation","windowRestored","cacheKey","split","scrollTo","removeEventListener","ScrollRestoration","props"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,MAAMA,eAAe,GACnB,OAAOC,MAAM,KAAK,WAAW,GAAGC,gBAAK,CAACF,eAAe,GAAGE,gBAAK,CAACC,SAAS,CAAA;AAMzE,MAAMC,SAAS,GAAG,QAAQ,CAAA;AAC1B,MAAMC,SAAS,GAAG,KAAK,CAAA;AAEvB,IAAIC,oBAAoB,GAAG,IAAIC,OAAO,EAAO,CAAA;AAa7C,IAAIC,KAAY,CAAA;AAEhB,MAAMC,eAAe,GAAG,OAAOR,MAAM,KAAK,WAAW,IAAIA,MAAM,CAACS,cAAc,CAAA;AAM9E,MAAMC,aAAa,GAAIC,QAAwB,IAAKA,QAAQ,CAACC,KAAK,CAACC,GAAI,CAAA;AAEhE,SAASC,oBAAoBA,CAACC,OAAkC,EAAE;EACvE,MAAM;IAAEH,KAAK;IAAEI,SAAS;AAAEC,IAAAA,kBAAAA;GAAoB,GAAGC,wBAAS,EAAE,CAAA;AAE5DnB,EAAAA,eAAe,CAAC,MAAM;AACpB,IAAA,MAAMoB,MAAM,GAAGJ,OAAO,EAAEI,MAAM,IAAIT,aAAa,CAAA;AAE/C,IAAA,IAAIF,eAAe,EAAE;MACnB,IAAI,CAACD,KAAK,EAAE;QACVA,KAAK,GAAG,CAAC,MAAM;UACb,MAAMa,UAAU,GAAG,2BAA2B,CAAA;AAE9C,UAAA,MAAMR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