@tanstack/router-core 1.120.4-alpha.19 → 1.120.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/fileRoute.d.cts +2 -6
- package/dist/cjs/index.cjs +0 -3
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +6 -6
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +1 -18
- package/dist/cjs/path.cjs +16 -130
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/path.d.cts +0 -17
- package/dist/cjs/redirect.cjs +14 -17
- package/dist/cjs/redirect.cjs.map +1 -1
- package/dist/cjs/redirect.d.cts +7 -13
- package/dist/cjs/route.cjs +1 -12
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +14 -15
- package/dist/cjs/router.cjs +155 -231
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +3 -46
- package/dist/cjs/scroll-restoration.cjs +23 -12
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/scroll-restoration.d.cts +1 -1
- package/dist/cjs/typePrimitives.d.cts +2 -2
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +0 -2
- package/dist/esm/fileRoute.d.ts +2 -6
- package/dist/esm/index.d.ts +6 -6
- package/dist/esm/index.js +2 -5
- package/dist/esm/link.d.ts +1 -18
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/path.d.ts +0 -17
- package/dist/esm/path.js +16 -130
- package/dist/esm/path.js.map +1 -1
- package/dist/esm/redirect.d.ts +7 -13
- package/dist/esm/redirect.js +14 -17
- package/dist/esm/redirect.js.map +1 -1
- package/dist/esm/route.d.ts +14 -15
- package/dist/esm/route.js +1 -12
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.d.ts +3 -46
- package/dist/esm/router.js +158 -234
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/scroll-restoration.d.ts +1 -1
- package/dist/esm/scroll-restoration.js +23 -12
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/dist/esm/typePrimitives.d.ts +2 -2
- package/dist/esm/utils.d.ts +0 -2
- package/dist/esm/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/fileRoute.ts +1 -90
- package/src/index.ts +6 -14
- package/src/link.ts +11 -97
- package/src/path.ts +16 -181
- package/src/redirect.ts +22 -37
- package/src/route.ts +35 -104
- package/src/router.ts +209 -332
- package/src/scroll-restoration.ts +44 -27
- package/src/typePrimitives.ts +2 -2
- package/src/utils.ts +0 -14
|
@@ -18,12 +18,22 @@ export type ScrollRestorationOptions = {
|
|
|
18
18
|
scrollBehavior?: ScrollToOptions['behavior']
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
function getSafeSessionStorage() {
|
|
22
|
+
try {
|
|
23
|
+
if (
|
|
24
|
+
typeof window !== 'undefined' &&
|
|
25
|
+
typeof window.sessionStorage === 'object'
|
|
26
|
+
) {
|
|
27
|
+
return window.sessionStorage
|
|
28
|
+
}
|
|
29
|
+
} catch {
|
|
30
|
+
return undefined
|
|
31
|
+
}
|
|
32
|
+
return undefined
|
|
33
|
+
}
|
|
34
|
+
|
|
21
35
|
export const storageKey = 'tsr-scroll-restoration-v1_3'
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
sessionsStorage =
|
|
25
|
-
typeof window !== 'undefined' && typeof window.sessionStorage === 'object'
|
|
26
|
-
} catch {}
|
|
36
|
+
|
|
27
37
|
const throttle = (fn: (...args: Array<any>) => void, wait: number) => {
|
|
28
38
|
let timeout: any
|
|
29
39
|
return (...args: Array<any>) => {
|
|
@@ -35,28 +45,32 @@ const throttle = (fn: (...args: Array<any>) => void, wait: number) => {
|
|
|
35
45
|
}
|
|
36
46
|
}
|
|
37
47
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
48
|
+
|
|
49
|
+
function createScrollRestorationCache(): ScrollRestorationCache | undefined {
|
|
50
|
+
const safeSessionStorage = getSafeSessionStorage()
|
|
51
|
+
if (!safeSessionStorage) {
|
|
52
|
+
return undefined
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const persistedState = safeSessionStorage.getItem(storageKey)
|
|
56
|
+
let state: ScrollRestorationByKey = persistedState
|
|
57
|
+
? JSON.parse(persistedState)
|
|
58
|
+
: {}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
state,
|
|
62
|
+
// This setter is simply to make sure that we set the sessionStorage right
|
|
63
|
+
// after the state is updated. It doesn't necessarily need to be a functional
|
|
64
|
+
// update.
|
|
65
|
+
set: (updater) => (
|
|
66
|
+
(state = functionalUpdate(updater, state) || state),
|
|
67
|
+
safeSessionStorage.setItem(storageKey, JSON.stringify(state))
|
|
68
|
+
),
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const scrollRestorationCache = createScrollRestorationCache()
|
|
73
|
+
|
|
60
74
|
/**
|
|
61
75
|
* The default `getKey` function for `useScrollRestoration`.
|
|
62
76
|
* It returns the `key` from the location state or the `href` of the location.
|
|
@@ -176,6 +190,9 @@ export function restoreScroll(
|
|
|
176
190
|
}
|
|
177
191
|
|
|
178
192
|
export function setupScrollRestoration(router: AnyRouter, force?: boolean) {
|
|
193
|
+
if (scrollRestorationCache === undefined) {
|
|
194
|
+
return
|
|
195
|
+
}
|
|
179
196
|
const shouldScrollRestoration =
|
|
180
197
|
force ?? router.options.scrollRestoration ?? false
|
|
181
198
|
|
package/src/typePrimitives.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
SearchParamOptions,
|
|
6
6
|
ToPathOption,
|
|
7
7
|
} from './link'
|
|
8
|
-
import type {
|
|
8
|
+
import type { Redirect } from './redirect'
|
|
9
9
|
import type { RouteIds } from './routeInfo'
|
|
10
10
|
import type { AnyRouter, RegisteredRouter } from './router'
|
|
11
11
|
import type { UseParamsResult } from './useParams'
|
|
@@ -104,7 +104,7 @@ export type ValidateRedirectOptions<
|
|
|
104
104
|
TDefaultFrom extends string = string,
|
|
105
105
|
> = Constrain<
|
|
106
106
|
TOptions,
|
|
107
|
-
|
|
107
|
+
Redirect<
|
|
108
108
|
TRouter,
|
|
109
109
|
InferFrom<TOptions, TDefaultFrom>,
|
|
110
110
|
InferTo<TOptions>,
|
package/src/utils.ts
CHANGED
|
@@ -169,20 +169,6 @@ export type ValidateJSON<T> = ((...args: Array<any>) => any) extends T
|
|
|
169
169
|
: 'Function is not serializable'
|
|
170
170
|
: { [K in keyof T]: ValidateJSON<T[K]> }
|
|
171
171
|
|
|
172
|
-
export type LooseReturnType<T> = T extends (
|
|
173
|
-
...args: Array<any>
|
|
174
|
-
) => infer TReturn
|
|
175
|
-
? TReturn
|
|
176
|
-
: never
|
|
177
|
-
|
|
178
|
-
export type LooseAsyncReturnType<T> = T extends (
|
|
179
|
-
...args: Array<any>
|
|
180
|
-
) => infer TReturn
|
|
181
|
-
? TReturn extends Promise<infer TReturn>
|
|
182
|
-
? TReturn
|
|
183
|
-
: TReturn
|
|
184
|
-
: never
|
|
185
|
-
|
|
186
172
|
export function last<T>(arr: Array<T>) {
|
|
187
173
|
return arr[arr.length - 1]
|
|
188
174
|
}
|