@tanstack/react-router 0.0.1-beta.163 → 0.0.1-beta.165
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/index.js +1 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/scroll-restoration.js +8 -116
- package/build/cjs/scroll-restoration.js.map +1 -1
- package/build/esm/index.js +8 -118
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +80 -74
- package/build/types/index.d.ts +4 -3
- package/build/umd/index.development.js +103 -91
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +3 -3
- package/src/scroll-restoration.tsx +12 -148
package/build/stats-react.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"name": "index.production.js",
|
|
8
8
|
"children": [
|
|
9
9
|
{
|
|
10
|
-
"uid": "
|
|
10
|
+
"uid": "06a4-173",
|
|
11
11
|
"name": "\u0000rollupPluginBabelHelpers.js"
|
|
12
12
|
},
|
|
13
13
|
{
|
|
@@ -15,25 +15,25 @@
|
|
|
15
15
|
"children": [
|
|
16
16
|
{
|
|
17
17
|
"name": "store/build/esm/index.js",
|
|
18
|
-
"uid": "
|
|
18
|
+
"uid": "06a4-175"
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
21
|
"name": "react-store/build/esm/index.js",
|
|
22
|
-
"uid": "
|
|
22
|
+
"uid": "06a4-177"
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
25
|
"name": "router-core/build/esm/index.js",
|
|
26
|
-
"uid": "
|
|
26
|
+
"uid": "06a4-183"
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
29
|
"name": "react-router/src",
|
|
30
30
|
"children": [
|
|
31
31
|
{
|
|
32
|
-
"uid": "
|
|
32
|
+
"uid": "06a4-185",
|
|
33
33
|
"name": "scroll-restoration.tsx"
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
|
-
"uid": "
|
|
36
|
+
"uid": "06a4-187",
|
|
37
37
|
"name": "index.tsx"
|
|
38
38
|
}
|
|
39
39
|
]
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"children": [
|
|
46
46
|
{
|
|
47
47
|
"name": "tiny-invariant@1.3.1/node_modules/tiny-invariant/dist/esm/tiny-invariant.js",
|
|
48
|
-
"uid": "
|
|
48
|
+
"uid": "06a4-179"
|
|
49
49
|
},
|
|
50
50
|
{
|
|
51
51
|
"name": "tiny-warning@1.0.3/node_modules/tiny-warning/dist/tiny-warning.esm.js",
|
|
52
|
-
"uid": "
|
|
52
|
+
"uid": "06a4-181"
|
|
53
53
|
}
|
|
54
54
|
]
|
|
55
55
|
}
|
|
@@ -59,229 +59,235 @@
|
|
|
59
59
|
"isRoot": true
|
|
60
60
|
},
|
|
61
61
|
"nodeParts": {
|
|
62
|
-
"
|
|
62
|
+
"06a4-173": {
|
|
63
63
|
"renderedLength": 429,
|
|
64
64
|
"gzipLength": 238,
|
|
65
65
|
"brotliLength": 0,
|
|
66
|
-
"mainUid": "
|
|
66
|
+
"mainUid": "06a4-172"
|
|
67
67
|
},
|
|
68
|
-
"
|
|
68
|
+
"06a4-175": {
|
|
69
69
|
"renderedLength": 1843,
|
|
70
70
|
"gzipLength": 644,
|
|
71
71
|
"brotliLength": 0,
|
|
72
|
-
"mainUid": "
|
|
72
|
+
"mainUid": "06a4-174"
|
|
73
73
|
},
|
|
74
|
-
"
|
|
74
|
+
"06a4-177": {
|
|
75
75
|
"renderedLength": 1006,
|
|
76
76
|
"gzipLength": 479,
|
|
77
77
|
"brotliLength": 0,
|
|
78
|
-
"mainUid": "
|
|
78
|
+
"mainUid": "06a4-176"
|
|
79
79
|
},
|
|
80
|
-
"
|
|
80
|
+
"06a4-179": {
|
|
81
81
|
"renderedLength": 181,
|
|
82
82
|
"gzipLength": 129,
|
|
83
83
|
"brotliLength": 0,
|
|
84
|
-
"mainUid": "
|
|
84
|
+
"mainUid": "06a4-178"
|
|
85
85
|
},
|
|
86
|
-
"
|
|
86
|
+
"06a4-181": {
|
|
87
87
|
"renderedLength": 44,
|
|
88
88
|
"gzipLength": 62,
|
|
89
89
|
"brotliLength": 0,
|
|
90
|
-
"mainUid": "
|
|
90
|
+
"mainUid": "06a4-180"
|
|
91
91
|
},
|
|
92
|
-
"
|
|
93
|
-
"renderedLength":
|
|
94
|
-
"gzipLength":
|
|
92
|
+
"06a4-183": {
|
|
93
|
+
"renderedLength": 61314,
|
|
94
|
+
"gzipLength": 14436,
|
|
95
95
|
"brotliLength": 0,
|
|
96
|
-
"mainUid": "
|
|
96
|
+
"mainUid": "06a4-182"
|
|
97
97
|
},
|
|
98
|
-
"
|
|
99
|
-
"renderedLength":
|
|
100
|
-
"gzipLength":
|
|
98
|
+
"06a4-185": {
|
|
99
|
+
"renderedLength": 466,
|
|
100
|
+
"gzipLength": 228,
|
|
101
101
|
"brotliLength": 0,
|
|
102
|
-
"mainUid": "
|
|
102
|
+
"mainUid": "06a4-184"
|
|
103
103
|
},
|
|
104
|
-
"
|
|
104
|
+
"06a4-187": {
|
|
105
105
|
"renderedLength": 17058,
|
|
106
106
|
"gzipLength": 3802,
|
|
107
107
|
"brotliLength": 0,
|
|
108
|
-
"mainUid": "
|
|
108
|
+
"mainUid": "06a4-186"
|
|
109
109
|
}
|
|
110
110
|
},
|
|
111
111
|
"nodeMetas": {
|
|
112
|
-
"
|
|
112
|
+
"06a4-172": {
|
|
113
113
|
"id": "\u0000rollupPluginBabelHelpers.js",
|
|
114
114
|
"moduleParts": {
|
|
115
|
-
"index.production.js": "
|
|
115
|
+
"index.production.js": "06a4-173"
|
|
116
116
|
},
|
|
117
117
|
"imported": [],
|
|
118
118
|
"importedBy": [
|
|
119
119
|
{
|
|
120
|
-
"uid": "
|
|
120
|
+
"uid": "06a4-186"
|
|
121
121
|
}
|
|
122
122
|
]
|
|
123
123
|
},
|
|
124
|
-
"
|
|
124
|
+
"06a4-174": {
|
|
125
125
|
"id": "/packages/store/build/esm/index.js",
|
|
126
126
|
"moduleParts": {
|
|
127
|
-
"index.production.js": "
|
|
127
|
+
"index.production.js": "06a4-175"
|
|
128
128
|
},
|
|
129
129
|
"imported": [],
|
|
130
130
|
"importedBy": [
|
|
131
131
|
{
|
|
132
|
-
"uid": "
|
|
132
|
+
"uid": "06a4-176"
|
|
133
133
|
}
|
|
134
134
|
]
|
|
135
135
|
},
|
|
136
|
-
"
|
|
136
|
+
"06a4-176": {
|
|
137
137
|
"id": "/packages/react-store/build/esm/index.js",
|
|
138
138
|
"moduleParts": {
|
|
139
|
-
"index.production.js": "
|
|
139
|
+
"index.production.js": "06a4-177"
|
|
140
140
|
},
|
|
141
141
|
"imported": [
|
|
142
142
|
{
|
|
143
|
-
"uid": "
|
|
143
|
+
"uid": "06a4-189"
|
|
144
144
|
},
|
|
145
145
|
{
|
|
146
|
-
"uid": "
|
|
146
|
+
"uid": "06a4-174"
|
|
147
147
|
}
|
|
148
148
|
],
|
|
149
149
|
"importedBy": [
|
|
150
150
|
{
|
|
151
|
-
"uid": "
|
|
151
|
+
"uid": "06a4-186"
|
|
152
152
|
},
|
|
153
153
|
{
|
|
154
|
-
"uid": "
|
|
154
|
+
"uid": "06a4-182"
|
|
155
155
|
}
|
|
156
156
|
]
|
|
157
157
|
},
|
|
158
|
-
"
|
|
158
|
+
"06a4-178": {
|
|
159
159
|
"id": "/node_modules/.pnpm/tiny-invariant@1.3.1/node_modules/tiny-invariant/dist/esm/tiny-invariant.js",
|
|
160
160
|
"moduleParts": {
|
|
161
|
-
"index.production.js": "
|
|
161
|
+
"index.production.js": "06a4-179"
|
|
162
162
|
},
|
|
163
163
|
"imported": [],
|
|
164
164
|
"importedBy": [
|
|
165
165
|
{
|
|
166
|
-
"uid": "
|
|
166
|
+
"uid": "06a4-186"
|
|
167
167
|
},
|
|
168
168
|
{
|
|
169
|
-
"uid": "
|
|
169
|
+
"uid": "06a4-182"
|
|
170
170
|
}
|
|
171
171
|
]
|
|
172
172
|
},
|
|
173
|
-
"
|
|
173
|
+
"06a4-180": {
|
|
174
174
|
"id": "/node_modules/.pnpm/tiny-warning@1.0.3/node_modules/tiny-warning/dist/tiny-warning.esm.js",
|
|
175
175
|
"moduleParts": {
|
|
176
|
-
"index.production.js": "
|
|
176
|
+
"index.production.js": "06a4-181"
|
|
177
177
|
},
|
|
178
178
|
"imported": [],
|
|
179
179
|
"importedBy": [
|
|
180
180
|
{
|
|
181
|
-
"uid": "
|
|
181
|
+
"uid": "06a4-186"
|
|
182
182
|
},
|
|
183
183
|
{
|
|
184
|
-
"uid": "
|
|
184
|
+
"uid": "06a4-182"
|
|
185
185
|
}
|
|
186
186
|
]
|
|
187
187
|
},
|
|
188
|
-
"
|
|
188
|
+
"06a4-182": {
|
|
189
189
|
"id": "/packages/router-core/build/esm/index.js",
|
|
190
190
|
"moduleParts": {
|
|
191
|
-
"index.production.js": "
|
|
191
|
+
"index.production.js": "06a4-183"
|
|
192
192
|
},
|
|
193
193
|
"imported": [
|
|
194
194
|
{
|
|
195
|
-
"uid": "
|
|
195
|
+
"uid": "06a4-178"
|
|
196
196
|
},
|
|
197
197
|
{
|
|
198
|
-
"uid": "
|
|
198
|
+
"uid": "06a4-180"
|
|
199
199
|
},
|
|
200
200
|
{
|
|
201
|
-
"uid": "
|
|
201
|
+
"uid": "06a4-176"
|
|
202
202
|
}
|
|
203
203
|
],
|
|
204
204
|
"importedBy": [
|
|
205
205
|
{
|
|
206
|
-
"uid": "
|
|
206
|
+
"uid": "06a4-186"
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"uid": "06a4-184"
|
|
207
210
|
}
|
|
208
211
|
]
|
|
209
212
|
},
|
|
210
|
-
"
|
|
213
|
+
"06a4-184": {
|
|
211
214
|
"id": "/packages/react-router/src/scroll-restoration.tsx",
|
|
212
215
|
"moduleParts": {
|
|
213
|
-
"index.production.js": "
|
|
216
|
+
"index.production.js": "06a4-185"
|
|
214
217
|
},
|
|
215
218
|
"imported": [
|
|
216
219
|
{
|
|
217
|
-
"uid": "
|
|
220
|
+
"uid": "06a4-188"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
"uid": "06a4-182"
|
|
218
224
|
},
|
|
219
225
|
{
|
|
220
|
-
"uid": "
|
|
226
|
+
"uid": "06a4-186"
|
|
221
227
|
}
|
|
222
228
|
],
|
|
223
229
|
"importedBy": [
|
|
224
230
|
{
|
|
225
|
-
"uid": "
|
|
231
|
+
"uid": "06a4-186"
|
|
226
232
|
}
|
|
227
233
|
]
|
|
228
234
|
},
|
|
229
|
-
"
|
|
235
|
+
"06a4-186": {
|
|
230
236
|
"id": "/packages/react-router/src/index.tsx",
|
|
231
237
|
"moduleParts": {
|
|
232
|
-
"index.production.js": "
|
|
238
|
+
"index.production.js": "06a4-187"
|
|
233
239
|
},
|
|
234
240
|
"imported": [
|
|
235
241
|
{
|
|
236
|
-
"uid": "
|
|
242
|
+
"uid": "06a4-172"
|
|
237
243
|
},
|
|
238
244
|
{
|
|
239
|
-
"uid": "
|
|
245
|
+
"uid": "06a4-188"
|
|
240
246
|
},
|
|
241
247
|
{
|
|
242
|
-
"uid": "
|
|
248
|
+
"uid": "06a4-176"
|
|
243
249
|
},
|
|
244
250
|
{
|
|
245
|
-
"uid": "
|
|
251
|
+
"uid": "06a4-178"
|
|
246
252
|
},
|
|
247
253
|
{
|
|
248
|
-
"uid": "
|
|
254
|
+
"uid": "06a4-180"
|
|
249
255
|
},
|
|
250
256
|
{
|
|
251
|
-
"uid": "
|
|
257
|
+
"uid": "06a4-182"
|
|
252
258
|
},
|
|
253
259
|
{
|
|
254
|
-
"uid": "
|
|
260
|
+
"uid": "06a4-184"
|
|
255
261
|
}
|
|
256
262
|
],
|
|
257
263
|
"importedBy": [
|
|
258
264
|
{
|
|
259
|
-
"uid": "
|
|
265
|
+
"uid": "06a4-184"
|
|
260
266
|
}
|
|
261
267
|
],
|
|
262
268
|
"isEntry": true
|
|
263
269
|
},
|
|
264
|
-
"
|
|
270
|
+
"06a4-188": {
|
|
265
271
|
"id": "react",
|
|
266
272
|
"moduleParts": {},
|
|
267
273
|
"imported": [],
|
|
268
274
|
"importedBy": [
|
|
269
275
|
{
|
|
270
|
-
"uid": "
|
|
276
|
+
"uid": "06a4-186"
|
|
271
277
|
},
|
|
272
278
|
{
|
|
273
|
-
"uid": "
|
|
279
|
+
"uid": "06a4-184"
|
|
274
280
|
}
|
|
275
281
|
],
|
|
276
282
|
"isExternal": true
|
|
277
283
|
},
|
|
278
|
-
"
|
|
284
|
+
"06a4-189": {
|
|
279
285
|
"id": "use-sync-external-store/shim/with-selector",
|
|
280
286
|
"moduleParts": {},
|
|
281
287
|
"imported": [],
|
|
282
288
|
"importedBy": [
|
|
283
289
|
{
|
|
284
|
-
"uid": "
|
|
290
|
+
"uid": "06a4-176"
|
|
285
291
|
}
|
|
286
292
|
],
|
|
287
293
|
"isExternal": true
|
package/build/types/index.d.ts
CHANGED
|
@@ -9,13 +9,14 @@
|
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
11
|
import * as _tanstack_router_core from '@tanstack/router-core';
|
|
12
|
-
import { RouteConstraints, AnyRoute, ResolveFullPath, ResolveId, ResolveFullSearchSchema, ParsePathParams, MergeParamsFromParent, RouteContext, AnyContext, UseLoaderResult, AnyRouteProps, RoutePaths, RegisteredRouter, LinkOptions, ToOptions, MatchRouteOptions, RouteByPath, ResolveRelativePath, NavigateOptions, RouterOptions, Router, RouteMatch, RouteIds, RouteById, ParseRoute, RoutesById, AllParams } from '@tanstack/router-core';
|
|
12
|
+
import { ScrollRestorationOptions, RouteConstraints, AnyRoute, ResolveFullPath, ResolveId, ResolveFullSearchSchema, ParsePathParams, MergeParamsFromParent, RouteContext, AnyContext, UseLoaderResult, AnyRouteProps, RoutePaths, RegisteredRouter, LinkOptions, ToOptions, MatchRouteOptions, RouteByPath, ResolveRelativePath, NavigateOptions, RouterOptions, Router, RouteMatch, RouteIds, RouteById, ParseRoute, RoutesById, AllParams } from '@tanstack/router-core';
|
|
13
13
|
export * from '@tanstack/router-core';
|
|
14
14
|
import * as React from 'react';
|
|
15
15
|
import { NoInfer } from '@tanstack/react-store';
|
|
16
16
|
export { useStore } from '@tanstack/react-store';
|
|
17
17
|
|
|
18
|
-
declare function
|
|
18
|
+
declare function useScrollRestoration(options?: ScrollRestorationOptions): void;
|
|
19
|
+
declare function ScrollRestoration(props: ScrollRestorationOptions): null;
|
|
19
20
|
|
|
20
21
|
declare module '@tanstack/router-core' {
|
|
21
22
|
interface RegisterRouteComponent<TProps extends Record<string, any>> {
|
|
@@ -152,4 +153,4 @@ declare function useBlocker(message: string, condition?: boolean | any): void;
|
|
|
152
153
|
declare function Block({ message, condition, children }: PromptProps): any;
|
|
153
154
|
declare function shallow<T>(objA: T, objB: T): boolean;
|
|
154
155
|
|
|
155
|
-
export { AnyRouteComponent, AsyncRouteComponent, Block, ErrorComponent, Link, LinkComponent, LinkPropsOptions, MakeLinkOptions, MakeLinkPropsOptions, MakeMatchRouteOptions, MakeUseMatchRouteOptions, MatchRoute, Navigate, Outlet, PromptProps, RouteComponent, RouteErrorComponent, RouteErrorComponentProps, RouteFromIdOrRoute, RouterProps, RouterProvider, ScrollRestoration, SyncRouteComponent, lazyRouteComponent, matchIdsContext, routerContext, shallow, useBlocker, useDehydrate, useHydrate, useInjectHtml, useLinkProps, useLoader, useMatch, useMatchRoute, useMatches, useNavigate, useParams, useRouteContext, useRouter, useRouterContext, useRouterState, useSearch };
|
|
156
|
+
export { AnyRouteComponent, AsyncRouteComponent, Block, ErrorComponent, Link, LinkComponent, LinkPropsOptions, MakeLinkOptions, MakeLinkPropsOptions, MakeMatchRouteOptions, MakeUseMatchRouteOptions, MatchRoute, Navigate, Outlet, PromptProps, RouteComponent, RouteErrorComponent, RouteErrorComponentProps, RouteFromIdOrRoute, RouterProps, RouterProvider, ScrollRestoration, SyncRouteComponent, lazyRouteComponent, matchIdsContext, routerContext, shallow, useBlocker, useDehydrate, useHydrate, useInjectHtml, useLinkProps, useLoader, useMatch, useMatchRoute, useMatches, useNavigate, useParams, useRouteContext, useRouter, useRouterContext, useRouterState, useScrollRestoration, useSearch };
|
|
@@ -1991,32 +1991,101 @@
|
|
|
1991
1991
|
};
|
|
1992
1992
|
}
|
|
1993
1993
|
|
|
1994
|
-
const useLayoutEffect = typeof window !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
1995
1994
|
const windowKey = 'window';
|
|
1996
1995
|
const delimiter = '___';
|
|
1997
1996
|
let weakScrolledElementsByRestoreKey = {};
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
1997
|
+
let cache;
|
|
1998
|
+
let pathDidChange = false;
|
|
1999
|
+
const sessionsStorage = typeof window !== 'undefined' && window.sessionStorage;
|
|
2000
|
+
const defaultGetKey = location => location.key;
|
|
2001
|
+
function watchScrollPositions(router, opts) {
|
|
2002
|
+
const getKey = opts?.getKey || defaultGetKey;
|
|
2003
|
+
if (sessionsStorage) {
|
|
2004
|
+
if (!cache) {
|
|
2005
|
+
cache = (() => {
|
|
2006
|
+
const storageKey = 'tsr-scroll-restoration-v1';
|
|
2007
|
+
const current = JSON.parse(window.sessionStorage.getItem(storageKey) || '{}');
|
|
2008
|
+
return {
|
|
2009
|
+
current,
|
|
2010
|
+
set: (key, value) => {
|
|
2011
|
+
current[key] = value;
|
|
2012
|
+
window.sessionStorage.setItem(storageKey, JSON.stringify(cache));
|
|
2013
|
+
}
|
|
2014
|
+
};
|
|
2015
|
+
})();
|
|
2016
|
+
}
|
|
2004
2017
|
}
|
|
2005
|
-
const
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2018
|
+
const {
|
|
2019
|
+
history
|
|
2020
|
+
} = window;
|
|
2021
|
+
if (history.scrollRestoration) {
|
|
2022
|
+
history.scrollRestoration = 'manual';
|
|
2023
|
+
}
|
|
2024
|
+
const onScroll = event => {
|
|
2025
|
+
const restoreKey = getKey(router.state.resolvedLocation);
|
|
2026
|
+
if (!weakScrolledElementsByRestoreKey[restoreKey]) {
|
|
2027
|
+
weakScrolledElementsByRestoreKey[restoreKey] = new WeakSet();
|
|
2028
|
+
}
|
|
2029
|
+
const set = weakScrolledElementsByRestoreKey[restoreKey];
|
|
2030
|
+
if (set.has(event.target)) return;
|
|
2031
|
+
set.add(event.target);
|
|
2032
|
+
const cacheKey = [restoreKey, event.target === document || event.target === window ? windowKey : getCssSelector(event.target)].join(delimiter);
|
|
2033
|
+
if (!cache.current[cacheKey]) {
|
|
2034
|
+
cache.set(cacheKey, {
|
|
2035
|
+
scrollX: NaN,
|
|
2036
|
+
scrollY: NaN
|
|
2037
|
+
});
|
|
2012
2038
|
}
|
|
2013
2039
|
};
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2040
|
+
const getCssSelector = el => {
|
|
2041
|
+
let path = [],
|
|
2042
|
+
parent;
|
|
2043
|
+
while (parent = el.parentNode) {
|
|
2044
|
+
path.unshift(`${el.tagName}:nth-child(${[].indexOf.call(parent.children, el) + 1})`);
|
|
2045
|
+
el = parent;
|
|
2046
|
+
}
|
|
2047
|
+
return `${path.join(' > ')}`.toLowerCase();
|
|
2048
|
+
};
|
|
2049
|
+
const onPathWillChange = from => {
|
|
2050
|
+
const restoreKey = getKey(from);
|
|
2051
|
+
for (const cacheKey in cache.current) {
|
|
2052
|
+
const entry = cache.current[cacheKey];
|
|
2053
|
+
const [key, elementSelector] = cacheKey.split(delimiter);
|
|
2054
|
+
if (restoreKey === key) {
|
|
2055
|
+
if (elementSelector === windowKey) {
|
|
2056
|
+
entry.scrollX = window.scrollX || 0;
|
|
2057
|
+
entry.scrollY = window.scrollY || 0;
|
|
2058
|
+
} else if (elementSelector) {
|
|
2059
|
+
const element = document.querySelector(elementSelector);
|
|
2060
|
+
entry.scrollX = element?.scrollLeft || 0;
|
|
2061
|
+
entry.scrollY = element?.scrollTop || 0;
|
|
2062
|
+
}
|
|
2063
|
+
cache.set(cacheKey, entry);
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
};
|
|
2067
|
+
const onPathChange = () => {
|
|
2068
|
+
pathDidChange = true;
|
|
2069
|
+
};
|
|
2070
|
+
if (typeof document !== 'undefined') {
|
|
2071
|
+
document.addEventListener('scroll', onScroll, true);
|
|
2072
|
+
}
|
|
2073
|
+
const unsubOnBeforeLoad = router.subscribe('onBeforeLoad', event => {
|
|
2074
|
+
if (event.pathChanged) onPathWillChange(event.from);
|
|
2075
|
+
});
|
|
2076
|
+
const unsubOnLoad = router.subscribe('onLoad', event => {
|
|
2077
|
+
if (event.pathChanged) onPathChange();
|
|
2078
|
+
});
|
|
2079
|
+
return () => {
|
|
2080
|
+
document.removeEventListener('scroll', onScroll);
|
|
2081
|
+
unsubOnBeforeLoad();
|
|
2082
|
+
unsubOnLoad();
|
|
2083
|
+
};
|
|
2084
|
+
}
|
|
2085
|
+
function restoreScrollPositions(router, opts) {
|
|
2086
|
+
if (pathDidChange) {
|
|
2087
|
+
const getKey = opts?.getKey || defaultGetKey;
|
|
2088
|
+
pathDidChange = false;
|
|
2020
2089
|
const restoreKey = getKey(router.state.location);
|
|
2021
2090
|
let windowRestored = false;
|
|
2022
2091
|
for (const cacheKey in cache.current) {
|
|
@@ -2038,81 +2107,21 @@
|
|
|
2038
2107
|
if (!windowRestored) {
|
|
2039
2108
|
window.scrollTo(0, 0);
|
|
2040
2109
|
}
|
|
2041
|
-
}
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
|
|
2113
|
+
const useLayoutEffect = typeof window !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
2114
|
+
function useScrollRestoration(options) {
|
|
2115
|
+
const router = useRouter();
|
|
2042
2116
|
useLayoutEffect(() => {
|
|
2043
|
-
|
|
2044
|
-
history
|
|
2045
|
-
} = window;
|
|
2046
|
-
if (history.scrollRestoration) {
|
|
2047
|
-
history.scrollRestoration = 'manual';
|
|
2048
|
-
}
|
|
2049
|
-
const onScroll = event => {
|
|
2050
|
-
const restoreKey = getKey(router.state.resolvedLocation);
|
|
2051
|
-
if (!weakScrolledElementsByRestoreKey[restoreKey]) {
|
|
2052
|
-
weakScrolledElementsByRestoreKey[restoreKey] = new WeakSet();
|
|
2053
|
-
}
|
|
2054
|
-
const set = weakScrolledElementsByRestoreKey[restoreKey];
|
|
2055
|
-
if (set.has(event.target)) return;
|
|
2056
|
-
set.add(event.target);
|
|
2057
|
-
const cacheKey = [restoreKey, event.target === document || event.target === window ? windowKey : getCssSelector(event.target)].join(delimiter);
|
|
2058
|
-
if (!cache.current[cacheKey]) {
|
|
2059
|
-
cache.set(cacheKey, {
|
|
2060
|
-
scrollX: NaN,
|
|
2061
|
-
scrollY: NaN
|
|
2062
|
-
});
|
|
2063
|
-
}
|
|
2064
|
-
};
|
|
2065
|
-
const getCssSelector = el => {
|
|
2066
|
-
let path = [],
|
|
2067
|
-
parent;
|
|
2068
|
-
while (parent = el.parentNode) {
|
|
2069
|
-
path.unshift(`${el.tagName}:nth-child(${[].indexOf.call(parent.children, el) + 1})`);
|
|
2070
|
-
el = parent;
|
|
2071
|
-
}
|
|
2072
|
-
return `${path.join(' > ')}`.toLowerCase();
|
|
2073
|
-
};
|
|
2074
|
-
const onPathWillChange = from => {
|
|
2075
|
-
const restoreKey = getKey(from);
|
|
2076
|
-
for (const cacheKey in cache.current) {
|
|
2077
|
-
const entry = cache.current[cacheKey];
|
|
2078
|
-
const [key, elementSelector] = cacheKey.split(delimiter);
|
|
2079
|
-
if (restoreKey === key) {
|
|
2080
|
-
if (elementSelector === windowKey) {
|
|
2081
|
-
entry.scrollX = window.scrollX || 0;
|
|
2082
|
-
entry.scrollY = window.scrollY || 0;
|
|
2083
|
-
} else if (elementSelector) {
|
|
2084
|
-
const element = document.querySelector(elementSelector);
|
|
2085
|
-
entry.scrollX = element?.scrollLeft || 0;
|
|
2086
|
-
entry.scrollY = element?.scrollTop || 0;
|
|
2087
|
-
}
|
|
2088
|
-
cache.set(cacheKey, entry);
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2091
|
-
};
|
|
2092
|
-
const onPathChange = () => {
|
|
2093
|
-
pathDidChangeRef.current = true;
|
|
2094
|
-
};
|
|
2095
|
-
if (typeof document !== 'undefined') {
|
|
2096
|
-
document.addEventListener('scroll', onScroll, true);
|
|
2097
|
-
}
|
|
2098
|
-
const unsubOnBeforeLoad = router.subscribe('onBeforeLoad', event => {
|
|
2099
|
-
if (event.pathChanged) onPathWillChange(event.from);
|
|
2100
|
-
});
|
|
2101
|
-
const unsubOnLoad = router.subscribe('onLoad', event => {
|
|
2102
|
-
if (event.pathChanged) onPathChange();
|
|
2103
|
-
});
|
|
2104
|
-
return () => {
|
|
2105
|
-
document.removeEventListener('scroll', onScroll);
|
|
2106
|
-
unsubOnBeforeLoad();
|
|
2107
|
-
unsubOnLoad();
|
|
2108
|
-
};
|
|
2117
|
+
return watchScrollPositions(router, options);
|
|
2109
2118
|
}, []);
|
|
2110
2119
|
useLayoutEffect(() => {
|
|
2111
|
-
|
|
2112
|
-
pathDidChangeRef.current = false;
|
|
2113
|
-
restoreScrollPositions();
|
|
2114
|
-
}
|
|
2120
|
+
restoreScrollPositions(router, options);
|
|
2115
2121
|
});
|
|
2122
|
+
}
|
|
2123
|
+
function ScrollRestoration(props) {
|
|
2124
|
+
useScrollRestoration(props);
|
|
2116
2125
|
return null;
|
|
2117
2126
|
}
|
|
2118
2127
|
|
|
@@ -2724,6 +2733,7 @@
|
|
|
2724
2733
|
exports.redirect = redirect;
|
|
2725
2734
|
exports.replaceEqualDeep = replaceEqualDeep;
|
|
2726
2735
|
exports.resolvePath = resolvePath;
|
|
2736
|
+
exports.restoreScrollPositions = restoreScrollPositions;
|
|
2727
2737
|
exports.rootRouteId = rootRouteId;
|
|
2728
2738
|
exports.routerContext = routerContext;
|
|
2729
2739
|
exports.shallow = shallow;
|
|
@@ -2746,9 +2756,11 @@
|
|
|
2746
2756
|
exports.useRouter = useRouter;
|
|
2747
2757
|
exports.useRouterContext = useRouterContext;
|
|
2748
2758
|
exports.useRouterState = useRouterState;
|
|
2759
|
+
exports.useScrollRestoration = useScrollRestoration;
|
|
2749
2760
|
exports.useSearch = useSearch;
|
|
2750
2761
|
exports.useStore = useStore;
|
|
2751
2762
|
exports.warning = warning;
|
|
2763
|
+
exports.watchScrollPositions = watchScrollPositions;
|
|
2752
2764
|
|
|
2753
2765
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2754
2766
|
|