@tanstack/react-router 1.114.14 → 1.114.16

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,28 +1 @@
1
- import { AnyRouter, NonNullableUpdater, ParsedLocation } from '@tanstack/router-core';
2
- export type ScrollRestorationEntry = {
3
- scrollX: number;
4
- scrollY: number;
5
- };
6
- export type ScrollRestorationByElement = Record<string, ScrollRestorationEntry>;
7
- export type ScrollRestorationByKey = Record<string, ScrollRestorationByElement>;
8
- export type ScrollRestorationCache = {
9
- state: ScrollRestorationByKey;
10
- set: (updater: NonNullableUpdater<ScrollRestorationByKey>) => void;
11
- };
12
- export type ScrollRestorationOptions = {
13
- getKey?: (location: ParsedLocation) => string;
14
- scrollBehavior?: ScrollToOptions['behavior'];
15
- };
16
- export declare const storageKey = "tsr-scroll-restoration-v1_3";
17
- export declare const scrollRestorationCache: ScrollRestorationCache;
18
- /**
19
- * The default `getKey` function for `useScrollRestoration`.
20
- * It returns the `key` from the location state or the `href` of the location.
21
- *
22
- * The `location.href` is used as a fallback to support the use case where the location state is not available like the initial render.
23
- */
24
- export declare const defaultGetScrollRestorationKey: (location: ParsedLocation) => string;
25
- export declare function getCssSelector(el: any): string;
26
- export declare function restoreScroll(storageKey: string, key: string | undefined, behavior: ScrollToOptions['behavior'] | undefined, shouldScrollRestoration: boolean | undefined, scrollToTopSelectors: Array<string> | undefined): void;
27
- export declare function setupScrollRestoration(router: AnyRouter, force?: boolean): void;
28
1
  export declare function ScrollRestoration(): import("react/jsx-runtime").JSX.Element | null;
@@ -1,182 +1,7 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { functionalUpdate } from "@tanstack/router-core";
2
+ import { defaultGetScrollRestorationKey, restoreScroll, storageKey } from "@tanstack/router-core";
3
3
  import { useRouter } from "./useRouter.js";
4
4
  import { ScriptOnce } from "./ScriptOnce.js";
5
- const storageKey = "tsr-scroll-restoration-v1_3";
6
- let sessionsStorage = false;
7
- try {
8
- sessionsStorage = typeof window !== "undefined" && typeof window.sessionStorage === "object";
9
- } catch {
10
- }
11
- const throttle = (fn, wait) => {
12
- let timeout;
13
- return (...args) => {
14
- if (!timeout) {
15
- timeout = setTimeout(() => {
16
- fn(...args);
17
- timeout = null;
18
- }, wait);
19
- }
20
- };
21
- };
22
- const scrollRestorationCache = sessionsStorage ? (() => {
23
- const state = JSON.parse(window.sessionStorage.getItem(storageKey) || "null") || {};
24
- return {
25
- state,
26
- // This setter is simply to make sure that we set the sessionStorage right
27
- // after the state is updated. It doesn't necessarily need to be a functional
28
- // update.
29
- set: (updater) => (scrollRestorationCache.state = // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
30
- functionalUpdate(updater, scrollRestorationCache.state) || scrollRestorationCache.state, window.sessionStorage.setItem(
31
- storageKey,
32
- JSON.stringify(scrollRestorationCache.state)
33
- ))
34
- };
35
- })() : void 0;
36
- const defaultGetScrollRestorationKey = (location) => {
37
- return location.state.key || location.href;
38
- };
39
- function getCssSelector(el) {
40
- const path = [];
41
- let parent;
42
- while (parent = el.parentNode) {
43
- path.unshift(
44
- `${el.tagName}:nth-child(${[].indexOf.call(parent.children, el) + 1})`
45
- );
46
- el = parent;
47
- }
48
- return `${path.join(" > ")}`.toLowerCase();
49
- }
50
- let ignoreScroll = false;
51
- function restoreScroll(storageKey2, key, behavior, shouldScrollRestoration, scrollToTopSelectors) {
52
- var _a;
53
- let byKey;
54
- try {
55
- byKey = JSON.parse(sessionStorage.getItem(storageKey2) || "{}");
56
- } catch (error) {
57
- console.error(error);
58
- return;
59
- }
60
- const resolvedKey = key || ((_a = window.history.state) == null ? void 0 : _a.key);
61
- const elementEntries = byKey[resolvedKey];
62
- ignoreScroll = true;
63
- (() => {
64
- if (shouldScrollRestoration && elementEntries) {
65
- for (const elementSelector in elementEntries) {
66
- const entry = elementEntries[elementSelector];
67
- if (elementSelector === "window") {
68
- window.scrollTo({
69
- top: entry.scrollY,
70
- left: entry.scrollX,
71
- behavior
72
- });
73
- } else if (elementSelector) {
74
- const element = document.querySelector(elementSelector);
75
- if (element) {
76
- element.scrollLeft = entry.scrollX;
77
- element.scrollTop = entry.scrollY;
78
- }
79
- }
80
- }
81
- return;
82
- }
83
- const hash = window.location.hash.split("#")[1];
84
- if (hash) {
85
- const hashScrollIntoViewOptions = (window.history.state || {}).__hashScrollIntoViewOptions ?? true;
86
- if (hashScrollIntoViewOptions) {
87
- const el = document.getElementById(hash);
88
- if (el) {
89
- el.scrollIntoView(hashScrollIntoViewOptions);
90
- }
91
- }
92
- return;
93
- }
94
- [
95
- "window",
96
- ...(scrollToTopSelectors == null ? void 0 : scrollToTopSelectors.filter((d) => d !== "window")) ?? []
97
- ].forEach((selector) => {
98
- const element = selector === "window" ? window : document.querySelector(selector);
99
- if (element) {
100
- element.scrollTo({
101
- top: 0,
102
- left: 0,
103
- behavior
104
- });
105
- }
106
- });
107
- })();
108
- ignoreScroll = false;
109
- }
110
- function setupScrollRestoration(router, force) {
111
- const shouldScrollRestoration = force ?? router.options.scrollRestoration ?? false;
112
- if (shouldScrollRestoration) {
113
- router.isScrollRestoring = true;
114
- }
115
- if (typeof document === "undefined" || router.isScrollRestorationSetup) {
116
- return;
117
- }
118
- router.isScrollRestorationSetup = true;
119
- ignoreScroll = false;
120
- const getKey = router.options.getScrollRestorationKey || defaultGetScrollRestorationKey;
121
- window.history.scrollRestoration = "manual";
122
- const onScroll = (event) => {
123
- if (ignoreScroll || !router.isScrollRestoring) {
124
- return;
125
- }
126
- let elementSelector = "";
127
- if (event.target === document || event.target === window) {
128
- elementSelector = "window";
129
- } else {
130
- const attrId = event.target.getAttribute(
131
- "data-scroll-restoration-id"
132
- );
133
- if (attrId) {
134
- elementSelector = `[data-scroll-restoration-id="${attrId}"]`;
135
- } else {
136
- elementSelector = getCssSelector(event.target);
137
- }
138
- }
139
- const restoreKey = getKey(router.state.location);
140
- scrollRestorationCache.set((state) => {
141
- const keyEntry = state[restoreKey] = state[restoreKey] || {};
142
- const elementEntry = keyEntry[elementSelector] = keyEntry[elementSelector] || {};
143
- if (elementSelector === "window") {
144
- elementEntry.scrollX = window.scrollX || 0;
145
- elementEntry.scrollY = window.scrollY || 0;
146
- } else if (elementSelector) {
147
- const element = document.querySelector(elementSelector);
148
- if (element) {
149
- elementEntry.scrollX = element.scrollLeft || 0;
150
- elementEntry.scrollY = element.scrollTop || 0;
151
- }
152
- }
153
- return state;
154
- });
155
- };
156
- if (typeof document !== "undefined") {
157
- document.addEventListener("scroll", throttle(onScroll, 100), true);
158
- }
159
- router.subscribe("onRendered", (event) => {
160
- const cacheKey = getKey(event.toLocation);
161
- if (!router.resetNextScroll) {
162
- router.resetNextScroll = true;
163
- return;
164
- }
165
- restoreScroll(
166
- storageKey,
167
- cacheKey,
168
- router.options.scrollRestorationBehavior || void 0,
169
- router.isScrollRestoring || void 0,
170
- router.options.scrollToTopSelectors || void 0
171
- );
172
- if (router.isScrollRestoring) {
173
- scrollRestorationCache.set((state) => {
174
- state[cacheKey] = state[cacheKey] || {};
175
- return state;
176
- });
177
- }
178
- });
179
- }
180
5
  function ScrollRestoration() {
181
6
  const router = useRouter();
182
7
  const getKey = router.options.getScrollRestorationKey || defaultGetScrollRestorationKey;
@@ -194,12 +19,6 @@ function ScrollRestoration() {
194
19
  );
195
20
  }
196
21
  export {
197
- ScrollRestoration,
198
- defaultGetScrollRestorationKey,
199
- getCssSelector,
200
- restoreScroll,
201
- scrollRestorationCache,
202
- setupScrollRestoration,
203
- storageKey
22
+ ScrollRestoration
204
23
  };
205
24
  //# sourceMappingURL=scroll-restoration.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"scroll-restoration.js","sources":["../../src/scroll-restoration.tsx"],"sourcesContent":["import { functionalUpdate } from '@tanstack/router-core'\nimport { useRouter } from './useRouter'\nimport { ScriptOnce } from './ScriptOnce'\nimport type {\n AnyRouter,\n NonNullableUpdater,\n ParsedLocation,\n} from '@tanstack/router-core'\n\nexport type ScrollRestorationEntry = { scrollX: number; scrollY: number }\n\nexport type ScrollRestorationByElement = Record<string, ScrollRestorationEntry>\n\nexport type ScrollRestorationByKey = Record<string, ScrollRestorationByElement>\n\nexport type ScrollRestorationCache = {\n state: ScrollRestorationByKey\n set: (updater: NonNullableUpdater<ScrollRestorationByKey>) => void\n}\nexport type ScrollRestorationOptions = {\n getKey?: (location: ParsedLocation) => string\n scrollBehavior?: ScrollToOptions['behavior']\n}\n\nexport const storageKey = 'tsr-scroll-restoration-v1_3'\nlet sessionsStorage = false\ntry {\n sessionsStorage =\n typeof window !== 'undefined' && typeof window.sessionStorage === 'object'\n} catch {}\nconst throttle = (fn: (...args: Array<any>) => void, wait: number) => {\n let timeout: any\n return (...args: Array<any>) => {\n if (!timeout) {\n timeout = setTimeout(() => {\n fn(...args)\n timeout = null\n }, wait)\n }\n }\n}\nexport const scrollRestorationCache: ScrollRestorationCache = sessionsStorage\n ? (() => {\n const state: ScrollRestorationByKey =\n JSON.parse(window.sessionStorage.getItem(storageKey) || 'null') || {}\n\n return {\n state,\n // This setter is simply to make sure that we set the sessionStorage right\n // after the state is updated. It doesn't necessarily need to be a functional\n // update.\n set: (updater) => (\n (scrollRestorationCache.state =\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n functionalUpdate(updater, scrollRestorationCache.state) ||\n scrollRestorationCache.state),\n window.sessionStorage.setItem(\n storageKey,\n JSON.stringify(scrollRestorationCache.state),\n )\n ),\n }\n })()\n : (undefined as any)\n/**\n * The default `getKey` function for `useScrollRestoration`.\n * It returns the `key` from the location state or the `href` of the location.\n *\n * The `location.href` is used as a fallback to support the use case where the location state is not available like the initial render.\n */\n\nexport const defaultGetScrollRestorationKey = (location: ParsedLocation) => {\n return location.state.key! || location.href\n}\n\nexport function getCssSelector(el: any): string {\n const path = []\n let parent\n while ((parent = el.parentNode)) {\n path.unshift(\n `${el.tagName}:nth-child(${([].indexOf as any).call(parent.children, el) + 1})`,\n )\n el = parent\n }\n return `${path.join(' > ')}`.toLowerCase()\n}\n\nlet ignoreScroll = false\n\n// NOTE: This function must remain pure and not use any outside variables\n// unless they are passed in as arguments. Why? Because we need to be able to\n// toString() it into a script tag to execute as early as possible in the browser\n// during SSR. Additionally, we also call it from within the router lifecycle\nexport function restoreScroll(\n storageKey: string,\n key: string | undefined,\n behavior: ScrollToOptions['behavior'] | undefined,\n shouldScrollRestoration: boolean | undefined,\n scrollToTopSelectors: Array<string> | undefined,\n) {\n let byKey: ScrollRestorationByKey\n\n try {\n byKey = JSON.parse(sessionStorage.getItem(storageKey) || '{}')\n } catch (error: any) {\n console.error(error)\n return\n }\n\n const resolvedKey = key || window.history.state?.key\n const elementEntries = byKey[resolvedKey]\n\n //\n ignoreScroll = true\n\n //\n ;(() => {\n // If we have a cached entry for this location state,\n // we always need to prefer that over the hash scroll.\n if (shouldScrollRestoration && elementEntries) {\n for (const elementSelector in elementEntries) {\n const entry = elementEntries[elementSelector]!\n if (elementSelector === 'window') {\n window.scrollTo({\n top: entry.scrollY,\n left: entry.scrollX,\n behavior,\n })\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 return\n }\n\n // If we don't have a cached entry for the hash,\n // Which means we've never seen this location before,\n // we need to check if there is a hash in the URL.\n // If there is, we need to scroll it's ID into view.\n const hash = window.location.hash.split('#')[1]\n\n if (hash) {\n const hashScrollIntoViewOptions =\n (window.history.state || {}).__hashScrollIntoViewOptions ?? true\n\n if (hashScrollIntoViewOptions) {\n const el = document.getElementById(hash)\n if (el) {\n el.scrollIntoView(hashScrollIntoViewOptions)\n }\n }\n\n return\n }\n\n // If there is no cached entry for the hash and there is no hash in the URL,\n // we need to scroll to the top of the page for every scrollToTop element\n ;[\n 'window',\n ...(scrollToTopSelectors?.filter((d) => d !== 'window') ?? []),\n ].forEach((selector) => {\n const element =\n selector === 'window' ? window : document.querySelector(selector)\n if (element) {\n element.scrollTo({\n top: 0,\n left: 0,\n behavior,\n })\n }\n })\n })()\n\n //\n ignoreScroll = false\n}\n\nexport function setupScrollRestoration(router: AnyRouter, force?: boolean) {\n const shouldScrollRestoration =\n force ?? router.options.scrollRestoration ?? false\n\n if (shouldScrollRestoration) {\n router.isScrollRestoring = true\n }\n\n if (typeof document === 'undefined' || router.isScrollRestorationSetup) {\n return\n }\n\n router.isScrollRestorationSetup = true\n\n //\n ignoreScroll = false\n\n const getKey =\n router.options.getScrollRestorationKey || defaultGetScrollRestorationKey\n\n window.history.scrollRestoration = 'manual'\n\n // // Create a MutationObserver to monitor DOM changes\n // const mutationObserver = new MutationObserver(() => {\n // ;ignoreScroll = true\n // requestAnimationFrame(() => {\n // ;ignoreScroll = false\n\n // // Attempt to restore scroll position on each dom\n // // mutation until the user scrolls. We do this\n // // because dynamic content may come in at different\n // // ticks after the initial render and we want to\n // // keep up with that content as much as possible.\n // // As soon as the user scrolls, we no longer need\n // // to attempt router.\n // // console.log('mutation observer restoreScroll')\n // restoreScroll(\n // storageKey,\n // getKey(router.state.location),\n // router.options.scrollRestorationBehavior,\n // )\n // })\n // })\n\n // const observeDom = () => {\n // // Observe changes to the entire document\n // mutationObserver.observe(document, {\n // childList: true, // Detect added or removed child nodes\n // subtree: true, // Monitor all descendants\n // characterData: true, // Detect text content changes\n // })\n // }\n\n // const unobserveDom = () => {\n // mutationObserver.disconnect()\n // }\n\n // observeDom()\n\n const onScroll = (event: Event) => {\n // unobserveDom()\n\n if (ignoreScroll || !router.isScrollRestoring) {\n return\n }\n\n let elementSelector = ''\n\n if (event.target === document || event.target === window) {\n elementSelector = 'window'\n } else {\n const attrId = (event.target as Element).getAttribute(\n 'data-scroll-restoration-id',\n )\n\n if (attrId) {\n elementSelector = `[data-scroll-restoration-id=\"${attrId}\"]`\n } else {\n elementSelector = getCssSelector(event.target)\n }\n }\n\n const restoreKey = getKey(router.state.location)\n\n scrollRestorationCache.set((state) => {\n const keyEntry = (state[restoreKey] =\n state[restoreKey] || ({} as ScrollRestorationByElement))\n\n const elementEntry = (keyEntry[elementSelector] =\n keyEntry[elementSelector] || ({} as ScrollRestorationEntry))\n\n if (elementSelector === 'window') {\n elementEntry.scrollX = window.scrollX || 0\n elementEntry.scrollY = window.scrollY || 0\n } else if (elementSelector) {\n const element = document.querySelector(elementSelector)\n if (element) {\n elementEntry.scrollX = element.scrollLeft || 0\n elementEntry.scrollY = element.scrollTop || 0\n }\n }\n\n return state\n })\n }\n\n // Throttle the scroll event to avoid excessive updates\n if (typeof document !== 'undefined') {\n document.addEventListener('scroll', throttle(onScroll, 100), true)\n }\n\n router.subscribe('onRendered', (event) => {\n // unobserveDom()\n\n const cacheKey = getKey(event.toLocation)\n\n // If the user doesn't want to restore the scroll position,\n // we don't need to do anything.\n if (!router.resetNextScroll) {\n router.resetNextScroll = true\n return\n }\n\n restoreScroll(\n storageKey,\n cacheKey,\n router.options.scrollRestorationBehavior || undefined,\n router.isScrollRestoring || undefined,\n router.options.scrollToTopSelectors || undefined,\n )\n\n if (router.isScrollRestoring) {\n // Mark the location as having been seen\n scrollRestorationCache.set((state) => {\n state[cacheKey] = state[cacheKey] || ({} as ScrollRestorationByElement)\n\n return state\n })\n }\n })\n}\n\nexport function ScrollRestoration() {\n const router = useRouter()\n const getKey =\n router.options.getScrollRestorationKey || defaultGetScrollRestorationKey\n const userKey = getKey(router.latestLocation)\n const resolvedKey =\n userKey !== defaultGetScrollRestorationKey(router.latestLocation)\n ? userKey\n : null\n\n if (!router.isScrollRestoring || !router.isServer) {\n return null\n }\n\n return (\n <ScriptOnce\n children={`(${restoreScroll.toString()})(${JSON.stringify(storageKey)},${JSON.stringify(resolvedKey)}, undefined, true)`}\n log={false}\n />\n )\n}\n"],"names":["storageKey"],"mappings":";;;;AAwBO,MAAM,aAAa;AAC1B,IAAI,kBAAkB;AACtB,IAAI;AACF,oBACE,OAAO,WAAW,eAAe,OAAO,OAAO,mBAAmB;AACtE,QAAQ;AAAC;AACT,MAAM,WAAW,CAAC,IAAmC,SAAiB;AAChE,MAAA;AACJ,SA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,qBAAqB;AAAA,MAC5B,OAAO,QAAQ,wBAAwB;AAAA,IACzC;AAEA,QAAI,OAAO,mBAAmB;AAEL,6BAAA,IAAI,CAAC,UAAU;AACpC,cAAM,QAAQ,IAAI,MAAM,QAAQ,KAAM,CAAC;AAEhC,eAAA;AAAA,MAAA,CACR;AAAA,IAAA;AAAA,EACH,CACD;AACH;AAEO,SAAS,oBAAoB;AAClC,QAAM,SAAS,UAAU;AACnB,QAAA,SACJ,OAAO,QAAQ,2BAA2B;AACtC,QAAA,UAAU,OAAO,OAAO,cAAc;AAC5C,QAAM,cACJ,YAAY,+BAA+B,OAAO,cAAc,IAC5D,UACA;AAEN,MAAI,CAAC,OAAO,qBAAqB,CAAC,OAAO,UAAU;AAC1C,WAAA;AAAA,EAAA;AAIP,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,UAAU,IAAI,cAAc,SAAU,CAAA,KAAK,KAAK,UAAU,UAAU,CAAC,IAAI,KAAK,UAAU,WAAW,CAAC;AAAA,MACpG,KAAK;AAAA,IAAA;AAAA,EACP;AAEJ;"}
1
+ {"version":3,"file":"scroll-restoration.js","sources":["../../src/scroll-restoration.tsx"],"sourcesContent":["import {\n defaultGetScrollRestorationKey,\n restoreScroll,\n storageKey,\n} from '@tanstack/router-core'\nimport { useRouter } from './useRouter'\nimport { ScriptOnce } from './ScriptOnce'\n\nexport function ScrollRestoration() {\n const router = useRouter()\n const getKey =\n router.options.getScrollRestorationKey || defaultGetScrollRestorationKey\n const userKey = getKey(router.latestLocation)\n const resolvedKey =\n userKey !== defaultGetScrollRestorationKey(router.latestLocation)\n ? userKey\n : null\n\n if (!router.isScrollRestoring || !router.isServer) {\n return null\n }\n\n return (\n <ScriptOnce\n children={`(${restoreScroll.toString()})(${JSON.stringify(storageKey)},${JSON.stringify(resolvedKey)}, undefined, true)`}\n log={false}\n />\n )\n}\n"],"names":[],"mappings":";;;;AAQO,SAAS,oBAAoB;AAClC,QAAM,SAAS,UAAU;AACnB,QAAA,SACJ,OAAO,QAAQ,2BAA2B;AACtC,QAAA,UAAU,OAAO,OAAO,cAAc;AAC5C,QAAM,cACJ,YAAY,+BAA+B,OAAO,cAAc,IAC5D,UACA;AAEN,MAAI,CAAC,OAAO,qBAAqB,CAAC,OAAO,UAAU;AAC1C,WAAA;AAAA,EAAA;AAIP,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,UAAU,IAAI,cAAc,SAAU,CAAA,KAAK,KAAK,UAAU,UAAU,CAAC,IAAI,KAAK,UAAU,WAAW,CAAC;AAAA,MACpG,KAAK;AAAA,IAAA;AAAA,EACP;AAEJ;"}
@@ -1,67 +1,8 @@
1
- import { AnyRouter, Constrain, ConstrainLiteral, FromPathOption, NavigateOptions, PathParamOptions, Redirect, RegisteredRouter, RouteIds, SearchParamOptions, ToPathOption, UseParamsResult, UseSearchResult } from '@tanstack/router-core';
1
+ import { AnyRouter, Constrain, InferFrom, InferMaskFrom, InferMaskTo, InferSelected, InferShouldThrow, InferStrict, InferTo, RegisteredRouter } from '@tanstack/router-core';
2
2
  import { LinkComponentProps } from './link.js';
3
3
  import { UseParamsOptions } from './useParams.js';
4
4
  import { UseSearchOptions } from './useSearch.js';
5
- export type ValidateFromPath<TRouter extends AnyRouter = RegisteredRouter, TFrom = string> = FromPathOption<TRouter, TFrom>;
6
- export type ValidateToPath<TRouter extends AnyRouter = RegisteredRouter, TTo extends string | undefined = undefined, TFrom extends string = string> = ToPathOption<TRouter, TFrom, TTo>;
7
- export type ValidateSearch<TRouter extends AnyRouter = RegisteredRouter, TTo extends string | undefined = undefined, TFrom extends string = string> = SearchParamOptions<TRouter, TFrom, TTo>;
8
- export type ValidateParams<TRouter extends AnyRouter = RegisteredRouter, TTo extends string | undefined = undefined, TFrom extends string = string> = PathParamOptions<TRouter, TFrom, TTo>;
9
- /**
10
- * @internal
11
- */
12
- export type InferFrom<TOptions, TDefaultFrom extends string = string> = TOptions extends {
13
- from: infer TFrom extends string;
14
- } ? TFrom : TDefaultFrom;
15
- /**
16
- * @internal
17
- */
18
- export type InferTo<TOptions> = TOptions extends {
19
- to: infer TTo extends string;
20
- } ? TTo : undefined;
21
- /**
22
- * @internal
23
- */
24
- export type InferMaskTo<TOptions> = TOptions extends {
25
- mask: {
26
- to: infer TTo extends string;
27
- };
28
- } ? TTo : '';
29
- export type InferMaskFrom<TOptions> = TOptions extends {
30
- mask: {
31
- from: infer TFrom extends string;
32
- };
33
- } ? TFrom : string;
34
- export type ValidateNavigateOptions<TRouter extends AnyRouter = RegisteredRouter, TOptions = unknown, TDefaultFrom extends string = string> = Constrain<TOptions, NavigateOptions<TRouter, InferFrom<TOptions, TDefaultFrom>, InferTo<TOptions>, InferMaskFrom<TOptions>, InferMaskTo<TOptions>>>;
35
- export type ValidateNavigateOptionsArray<TRouter extends AnyRouter = RegisteredRouter, TOptions extends ReadonlyArray<any> = ReadonlyArray<unknown>, TDefaultFrom extends string = string> = {
36
- [K in keyof TOptions]: ValidateNavigateOptions<TRouter, TOptions[K], TDefaultFrom>;
37
- };
38
- export type ValidateRedirectOptions<TRouter extends AnyRouter = RegisteredRouter, TOptions = unknown, TDefaultFrom extends string = string> = Constrain<TOptions, Redirect<TRouter, InferFrom<TOptions, TDefaultFrom>, InferTo<TOptions>, InferMaskFrom<TOptions>, InferMaskTo<TOptions>>>;
39
- export type ValidateRedirectOptionsArray<TRouter extends AnyRouter = RegisteredRouter, TOptions extends ReadonlyArray<any> = ReadonlyArray<unknown>, TDefaultFrom extends string = string> = {
40
- [K in keyof TOptions]: ValidateRedirectOptions<TRouter, TOptions[K], TDefaultFrom>;
41
- };
42
5
  export type ValidateLinkOptions<TRouter extends AnyRouter = RegisteredRouter, TOptions = unknown, TDefaultFrom extends string = string, TComp = 'a'> = Constrain<TOptions, LinkComponentProps<TComp, TRouter, InferFrom<TOptions, TDefaultFrom>, InferTo<TOptions>, InferMaskFrom<TOptions>, InferMaskTo<TOptions>>>;
43
- export type ValidateLinkOptionsArray<TRouter extends AnyRouter = RegisteredRouter, TOptions extends ReadonlyArray<any> = ReadonlyArray<unknown>, TDefaultFrom extends string = string, TComp = 'a'> = {
44
- [K in keyof TOptions]: ValidateLinkOptions<TRouter, TOptions[K], TDefaultFrom, TComp>;
45
- };
46
- export type ValidateId<TRouter extends AnyRouter = RegisteredRouter, TId extends string = string> = ConstrainLiteral<TId, RouteIds<TRouter['routeTree']>>;
47
- /**
48
- * @internal
49
- */
50
- export type InferStrict<TOptions> = TOptions extends {
51
- strict: infer TStrict extends boolean;
52
- } ? TStrict : true;
53
- /**
54
- * @internal
55
- */
56
- export type InferShouldThrow<TOptions> = TOptions extends {
57
- shouldThrow: infer TShouldThrow extends boolean;
58
- } ? TShouldThrow : true;
59
- /**
60
- * @internal
61
- */
62
- export type InferSelected<TOptions> = TOptions extends {
63
- select: (...args: Array<any>) => infer TSelected;
64
- } ? TSelected : unknown;
65
6
  /**
66
7
  * @internal
67
8
  */
@@ -69,6 +10,7 @@ export type InferStructuralSharing<TOptions> = TOptions extends {
69
10
  structuralSharing: infer TStructuralSharing;
70
11
  } ? TStructuralSharing : unknown;
71
12
  export type ValidateUseSearchOptions<TOptions, TRouter extends AnyRouter = RegisteredRouter> = Constrain<TOptions, UseSearchOptions<TRouter, InferFrom<TOptions>, InferStrict<TOptions>, InferShouldThrow<TOptions>, InferSelected<TOptions>, InferStructuralSharing<TOptions>>>;
72
- export type ValidateUseSearchResult<TOptions, TRouter extends AnyRouter = RegisteredRouter> = UseSearchResult<TRouter, InferFrom<TOptions>, InferStrict<TOptions>, InferSelected<TOptions>>;
73
13
  export type ValidateUseParamsOptions<TOptions, TRouter extends AnyRouter = RegisteredRouter> = Constrain<TOptions, UseParamsOptions<TRouter, InferFrom<TOptions>, InferStrict<TOptions>, InferShouldThrow<TOptions>, InferSelected<TOptions>, InferSelected<TOptions>>>;
74
- export type ValidateUseParamsResult<TOptions, TRouter extends AnyRouter = RegisteredRouter> = Constrain<TOptions, UseParamsResult<TRouter, InferFrom<TOptions>, InferStrict<TOptions>, InferSelected<TOptions>>>;
14
+ export type ValidateLinkOptionsArray<TRouter extends AnyRouter = RegisteredRouter, TOptions extends ReadonlyArray<any> = ReadonlyArray<unknown>, TDefaultFrom extends string = string, TComp = 'a'> = {
15
+ [K in keyof TOptions]: ValidateLinkOptions<TRouter, TOptions[K], TDefaultFrom, TComp>;
16
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
- "version": "1.114.14",
3
+ "version": "1.114.16",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -54,7 +54,7 @@
54
54
  "tiny-invariant": "^1.3.3",
55
55
  "tiny-warning": "^1.0.3",
56
56
  "@tanstack/history": "1.114.12",
57
- "@tanstack/router-core": "1.114.12"
57
+ "@tanstack/router-core": "1.114.16"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@testing-library/jest-dom": "^6.6.3",
@@ -1,12 +1,15 @@
1
- import { useRouter } from './useRouter'
2
1
  import {
3
2
  defaultGetScrollRestorationKey,
4
3
  getCssSelector,
5
4
  scrollRestorationCache,
6
5
  setupScrollRestoration,
7
- } from './scroll-restoration'
8
- import type { ScrollRestorationOptions } from './scroll-restoration'
9
- import type { ParsedLocation } from '@tanstack/router-core'
6
+ } from '@tanstack/router-core'
7
+ import { useRouter } from './useRouter'
8
+ import type {
9
+ ParsedLocation,
10
+ ScrollRestorationEntry,
11
+ ScrollRestorationOptions,
12
+ } from '@tanstack/router-core'
10
13
 
11
14
  function useScrollRestoration() {
12
15
  const router = useRouter()
@@ -41,7 +44,7 @@ export function useElementScrollRestoration(
41
44
  ) & {
42
45
  getKey?: (location: ParsedLocation) => string
43
46
  },
44
- ) {
47
+ ): ScrollRestorationEntry | undefined {
45
48
  useScrollRestoration()
46
49
 
47
50
  const router = useRouter()
package/src/index.tsx CHANGED
@@ -330,7 +330,34 @@ export { CatchNotFound, DefaultGlobalNotFound } from './not-found'
330
330
  export { notFound, isNotFound } from '@tanstack/router-core'
331
331
  export type { NotFoundError } from '@tanstack/router-core'
332
332
 
333
- export * from './typePrimitives'
333
+ export type {
334
+ ValidateLinkOptions,
335
+ InferStructuralSharing,
336
+ ValidateUseSearchOptions,
337
+ ValidateUseParamsOptions,
338
+ ValidateLinkOptionsArray,
339
+ } from './typePrimitives'
340
+
341
+ export type {
342
+ ValidateFromPath,
343
+ ValidateToPath,
344
+ ValidateSearch,
345
+ ValidateParams,
346
+ InferFrom,
347
+ InferTo,
348
+ InferMaskTo,
349
+ InferMaskFrom,
350
+ ValidateNavigateOptions,
351
+ ValidateNavigateOptionsArray,
352
+ ValidateRedirectOptions,
353
+ ValidateRedirectOptionsArray,
354
+ ValidateId,
355
+ InferStrict,
356
+ InferShouldThrow,
357
+ InferSelected,
358
+ ValidateUseSearchResult,
359
+ ValidateUseParamsResult,
360
+ } from '@tanstack/router-core'
334
361
 
335
362
  export { ScriptOnce } from './ScriptOnce'
336
363
  export { Asset } from './Asset'
package/src/router.ts CHANGED
@@ -25,12 +25,12 @@ import {
25
25
  replaceEqualDeep,
26
26
  resolvePath,
27
27
  rootRouteId,
28
+ setupScrollRestoration,
28
29
  trimPath,
29
30
  trimPathLeft,
30
31
  trimPathRight,
31
32
  } from '@tanstack/router-core'
32
33
 
33
- import { setupScrollRestoration } from './scroll-restoration'
34
34
  import type * as React from 'react'
35
35
  import type { HistoryLocation, RouterHistory } from '@tanstack/history'
36
36