@tanstack/router-core 1.131.26 → 1.131.28
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/load-matches.cjs +8 -23
- package/dist/cjs/load-matches.cjs.map +1 -1
- package/dist/cjs/qss.cjs +19 -19
- package/dist/cjs/qss.cjs.map +1 -1
- package/dist/cjs/qss.d.cts +6 -4
- package/dist/cjs/router.cjs +15 -22
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/scroll-restoration.cjs +21 -26
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/searchParams.cjs +7 -15
- package/dist/cjs/searchParams.cjs.map +1 -1
- package/dist/esm/load-matches.js +8 -23
- package/dist/esm/load-matches.js.map +1 -1
- package/dist/esm/qss.d.ts +6 -4
- package/dist/esm/qss.js +19 -19
- package/dist/esm/qss.js.map +1 -1
- package/dist/esm/router.js +15 -22
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/scroll-restoration.js +21 -26
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/dist/esm/searchParams.js +7 -15
- package/dist/esm/searchParams.js.map +1 -1
- package/package.json +1 -1
- package/src/load-matches.ts +12 -29
- package/src/qss.ts +27 -24
- package/src/router.ts +31 -36
- package/src/scroll-restoration.ts +25 -32
- package/src/searchParams.ts +8 -19
|
@@ -28,7 +28,7 @@ function getSafeSessionStorage() {
|
|
|
28
28
|
return window.sessionStorage
|
|
29
29
|
}
|
|
30
30
|
} catch {
|
|
31
|
-
|
|
31
|
+
// silent
|
|
32
32
|
}
|
|
33
33
|
return undefined
|
|
34
34
|
}
|
|
@@ -85,14 +85,14 @@ export const defaultGetScrollRestorationKey = (location: ParsedLocation) => {
|
|
|
85
85
|
|
|
86
86
|
export function getCssSelector(el: any): string {
|
|
87
87
|
const path = []
|
|
88
|
-
let parent
|
|
88
|
+
let parent: HTMLElement
|
|
89
89
|
while ((parent = el.parentNode)) {
|
|
90
|
-
path.
|
|
91
|
-
`${el.tagName}:nth-child(${
|
|
90
|
+
path.push(
|
|
91
|
+
`${el.tagName}:nth-child(${Array.prototype.indexOf.call(parent.children, el) + 1})`,
|
|
92
92
|
)
|
|
93
93
|
el = parent
|
|
94
94
|
}
|
|
95
|
-
return `${path.join(' > ')}`.toLowerCase()
|
|
95
|
+
return `${path.reverse().join(' > ')}`.toLowerCase()
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
let ignoreScroll = false
|
|
@@ -120,7 +120,7 @@ export function restoreScroll({
|
|
|
120
120
|
|
|
121
121
|
try {
|
|
122
122
|
byKey = JSON.parse(sessionStorage.getItem(storageKey) || '{}')
|
|
123
|
-
} catch (error
|
|
123
|
+
} catch (error) {
|
|
124
124
|
console.error(error)
|
|
125
125
|
return
|
|
126
126
|
}
|
|
@@ -132,7 +132,7 @@ export function restoreScroll({
|
|
|
132
132
|
ignoreScroll = true
|
|
133
133
|
|
|
134
134
|
//
|
|
135
|
-
|
|
135
|
+
scroll: {
|
|
136
136
|
// If we have a cached entry for this location state,
|
|
137
137
|
// we always need to prefer that over the hash scroll.
|
|
138
138
|
if (
|
|
@@ -157,18 +157,18 @@ export function restoreScroll({
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
break scroll
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
// If we don't have a cached entry for the hash,
|
|
164
164
|
// Which means we've never seen this location before,
|
|
165
165
|
// we need to check if there is a hash in the URL.
|
|
166
166
|
// If there is, we need to scroll it's ID into view.
|
|
167
|
-
const hash = (location ?? window.location).hash.split('#')[1]
|
|
167
|
+
const hash = (location ?? window.location).hash.split('#', 2)[1]
|
|
168
168
|
|
|
169
169
|
if (hash) {
|
|
170
170
|
const hashScrollIntoViewOptions =
|
|
171
|
-
|
|
171
|
+
window.history.state?.__hashScrollIntoViewOptions ?? true
|
|
172
172
|
|
|
173
173
|
if (hashScrollIntoViewOptions) {
|
|
174
174
|
const el = document.getElementById(hash)
|
|
@@ -177,30 +177,24 @@ export function restoreScroll({
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
|
|
180
|
+
break scroll
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
// If there is no cached entry for the hash and there is no hash in the URL,
|
|
184
184
|
// we need to scroll to the top of the page for every scrollToTop element
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
: typeof selector === 'function'
|
|
185
|
+
const scrollOptions = { top: 0, left: 0, behavior }
|
|
186
|
+
window.scrollTo(scrollOptions)
|
|
187
|
+
if (scrollToTopSelectors) {
|
|
188
|
+
for (const selector of scrollToTopSelectors) {
|
|
189
|
+
if (selector === 'window') continue
|
|
190
|
+
const element =
|
|
191
|
+
typeof selector === 'function'
|
|
193
192
|
? selector()
|
|
194
193
|
: document.querySelector(selector)
|
|
195
|
-
|
|
196
|
-
element.scrollTo({
|
|
197
|
-
top: 0,
|
|
198
|
-
left: 0,
|
|
199
|
-
behavior,
|
|
200
|
-
})
|
|
194
|
+
if (element) element.scrollTo(scrollOptions)
|
|
201
195
|
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
204
198
|
|
|
205
199
|
//
|
|
206
200
|
ignoreScroll = false
|
|
@@ -294,11 +288,10 @@ export function setupScrollRestoration(router: AnyRouter, force?: boolean) {
|
|
|
294
288
|
const restoreKey = getKey(router.state.location)
|
|
295
289
|
|
|
296
290
|
scrollRestorationCache.set((state) => {
|
|
297
|
-
const keyEntry = (state[restoreKey]
|
|
298
|
-
state[restoreKey] || ({} as ScrollRestorationByElement))
|
|
291
|
+
const keyEntry = (state[restoreKey] ||= {} as ScrollRestorationByElement)
|
|
299
292
|
|
|
300
|
-
const elementEntry = (keyEntry[elementSelector]
|
|
301
|
-
|
|
293
|
+
const elementEntry = (keyEntry[elementSelector] ||=
|
|
294
|
+
{} as ScrollRestorationEntry)
|
|
302
295
|
|
|
303
296
|
if (elementSelector === 'window') {
|
|
304
297
|
elementEntry.scrollX = window.scrollX || 0
|
|
@@ -344,7 +337,7 @@ export function setupScrollRestoration(router: AnyRouter, force?: boolean) {
|
|
|
344
337
|
if (router.isScrollRestoring) {
|
|
345
338
|
// Mark the location as having been seen
|
|
346
339
|
scrollRestorationCache.set((state) => {
|
|
347
|
-
state[cacheKey]
|
|
340
|
+
state[cacheKey] ||= {} as ScrollRestorationByElement
|
|
348
341
|
|
|
349
342
|
return state
|
|
350
343
|
})
|
package/src/searchParams.ts
CHANGED
|
@@ -9,7 +9,7 @@ export const defaultStringifySearch = stringifySearchWith(
|
|
|
9
9
|
|
|
10
10
|
export function parseSearchWith(parser: (str: string) => any) {
|
|
11
11
|
return (searchStr: string): AnySchema => {
|
|
12
|
-
if (searchStr
|
|
12
|
+
if (searchStr[0] === '?') {
|
|
13
13
|
searchStr = searchStr.substring(1)
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -21,8 +21,8 @@ export function parseSearchWith(parser: (str: string) => any) {
|
|
|
21
21
|
if (typeof value === 'string') {
|
|
22
22
|
try {
|
|
23
23
|
query[key] = parser(value)
|
|
24
|
-
} catch (
|
|
25
|
-
//
|
|
24
|
+
} catch (_err) {
|
|
25
|
+
// silent
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -35,20 +35,21 @@ export function stringifySearchWith(
|
|
|
35
35
|
stringify: (search: any) => string,
|
|
36
36
|
parser?: (str: string) => any,
|
|
37
37
|
) {
|
|
38
|
+
const hasParser = typeof parser === 'function'
|
|
38
39
|
function stringifyValue(val: any) {
|
|
39
40
|
if (typeof val === 'object' && val !== null) {
|
|
40
41
|
try {
|
|
41
42
|
return stringify(val)
|
|
42
|
-
} catch (
|
|
43
|
+
} catch (_err) {
|
|
43
44
|
// silent
|
|
44
45
|
}
|
|
45
|
-
} else if (
|
|
46
|
+
} else if (hasParser && typeof val === 'string') {
|
|
46
47
|
try {
|
|
47
48
|
// Check if it's a valid parseable string.
|
|
48
49
|
// If it is, then stringify it again.
|
|
49
50
|
parser(val)
|
|
50
51
|
return stringify(val)
|
|
51
|
-
} catch (
|
|
52
|
+
} catch (_err) {
|
|
52
53
|
// silent
|
|
53
54
|
}
|
|
54
55
|
}
|
|
@@ -56,19 +57,7 @@ export function stringifySearchWith(
|
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
return (search: Record<string, any>) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
Object.keys(search).forEach((key) => {
|
|
62
|
-
const val = search[key]
|
|
63
|
-
if (typeof val === 'undefined' || val === undefined) {
|
|
64
|
-
delete search[key]
|
|
65
|
-
} else {
|
|
66
|
-
search[key] = stringifyValue(val)
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
const searchStr = encode(search as Record<string, string>).toString()
|
|
71
|
-
|
|
60
|
+
const searchStr = encode(search, stringifyValue)
|
|
72
61
|
return searchStr ? `?${searchStr}` : ''
|
|
73
62
|
}
|
|
74
63
|
}
|