@etsoo/react 1.6.71 → 1.6.73
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/lib/components/ScrollRestoration.d.ts +5 -0
- package/lib/components/ScrollRestoration.js +30 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/uses/useWindowScroll.d.ts +4 -2
- package/lib/uses/useWindowScroll.js +1 -1
- package/package.json +6 -6
- package/src/components/ScrollRestoration.tsx +37 -0
- package/src/index.ts +1 -0
- package/src/uses/useWindowScroll.ts +5 -2
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useLocation } from 'react-router-dom';
|
|
3
|
+
import { useWindowScroll } from '../uses/useWindowScroll';
|
|
4
|
+
const urls = {};
|
|
5
|
+
/**
|
|
6
|
+
* Scroll restoration
|
|
7
|
+
*/
|
|
8
|
+
export function ScrollRestoration() {
|
|
9
|
+
// Location key
|
|
10
|
+
const { key } = useLocation();
|
|
11
|
+
// Mounted
|
|
12
|
+
const mounted = React.useRef(false);
|
|
13
|
+
// Detect scroll
|
|
14
|
+
const data = useWindowScroll();
|
|
15
|
+
if (mounted.current) {
|
|
16
|
+
urls[key] = data;
|
|
17
|
+
}
|
|
18
|
+
// Setup
|
|
19
|
+
React.useEffect(() => {
|
|
20
|
+
const pos = urls[key];
|
|
21
|
+
if (pos) {
|
|
22
|
+
window.scrollTo(pos.x, pos.y);
|
|
23
|
+
}
|
|
24
|
+
mounted.current = true;
|
|
25
|
+
return () => {
|
|
26
|
+
mounted.current = false;
|
|
27
|
+
};
|
|
28
|
+
}, [key]);
|
|
29
|
+
return React.createElement(React.Fragment, null);
|
|
30
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './components/GridMethodRef';
|
|
|
10
10
|
export * from './components/ListItemReact';
|
|
11
11
|
export * from './components/ScrollerGrid';
|
|
12
12
|
export * from './components/ScrollerList';
|
|
13
|
+
export * from './components/ScrollRestoration';
|
|
13
14
|
export * from './notifier/Notifier';
|
|
14
15
|
export * from '@etsoo/notificationbase';
|
|
15
16
|
export * from './states/CultureState';
|
package/lib/index.js
CHANGED
|
@@ -12,6 +12,7 @@ export * from './components/GridMethodRef';
|
|
|
12
12
|
export * from './components/ListItemReact';
|
|
13
13
|
export * from './components/ScrollerGrid';
|
|
14
14
|
export * from './components/ScrollerList';
|
|
15
|
+
export * from './components/ScrollRestoration';
|
|
15
16
|
// notifier
|
|
16
17
|
export * from './notifier/Notifier';
|
|
17
18
|
export * from '@etsoo/notificationbase';
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Window scroll position
|
|
3
|
+
*/
|
|
4
|
+
export interface IScrollPos {
|
|
2
5
|
x: number;
|
|
3
6
|
y: number;
|
|
4
7
|
}
|
|
@@ -7,4 +10,3 @@ interface IScrollPos {
|
|
|
7
10
|
* @returns Scroll location
|
|
8
11
|
*/
|
|
9
12
|
export declare const useWindowScroll: () => IScrollPos;
|
|
10
|
-
export {};
|
|
@@ -22,7 +22,7 @@ export const useWindowScroll = () => {
|
|
|
22
22
|
requestAnimationFrameSeed = window.requestAnimationFrame(() => {
|
|
23
23
|
ticking = false;
|
|
24
24
|
requestAnimationFrameSeed = 0;
|
|
25
|
-
if (lastPos.x !=
|
|
25
|
+
if (lastPos.x != pos.x || lastPos.y != pos.y) {
|
|
26
26
|
setPos(lastPos);
|
|
27
27
|
}
|
|
28
28
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/react",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.73",
|
|
4
4
|
"description": "TypeScript ReactJs UI Independent Framework",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -50,20 +50,20 @@
|
|
|
50
50
|
"@emotion/css": "^11.10.8",
|
|
51
51
|
"@emotion/react": "^11.10.8",
|
|
52
52
|
"@emotion/styled": "^11.10.8",
|
|
53
|
-
"@etsoo/appscript": "^1.3.
|
|
53
|
+
"@etsoo/appscript": "^1.3.99",
|
|
54
54
|
"@etsoo/notificationbase": "^1.1.24",
|
|
55
55
|
"@etsoo/shared": "^1.2.1",
|
|
56
|
-
"@types/react": "^18.2.
|
|
57
|
-
"@types/react-dom": "^18.2.
|
|
56
|
+
"@types/react": "^18.2.2",
|
|
57
|
+
"@types/react-dom": "^18.2.3",
|
|
58
58
|
"@types/react-window": "^1.8.5",
|
|
59
59
|
"react": "^18.2.0",
|
|
60
60
|
"react-dom": "^18.2.0",
|
|
61
|
-
"react-router-dom": "^6.11.
|
|
61
|
+
"react-router-dom": "^6.11.1",
|
|
62
62
|
"react-window": "^1.8.9"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@babel/cli": "^7.21.5",
|
|
66
|
-
"@babel/core": "^7.21.
|
|
66
|
+
"@babel/core": "^7.21.8",
|
|
67
67
|
"@babel/plugin-transform-runtime": "^7.21.4",
|
|
68
68
|
"@babel/preset-env": "^7.21.5",
|
|
69
69
|
"@babel/runtime-corejs3": "^7.21.5",
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useLocation } from 'react-router-dom';
|
|
3
|
+
import { IScrollPos, useWindowScroll } from '../uses/useWindowScroll';
|
|
4
|
+
|
|
5
|
+
const urls: Record<string, IScrollPos | undefined> = {};
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Scroll restoration
|
|
9
|
+
*/
|
|
10
|
+
export function ScrollRestoration() {
|
|
11
|
+
// Location key
|
|
12
|
+
const { key } = useLocation();
|
|
13
|
+
|
|
14
|
+
// Mounted
|
|
15
|
+
const mounted = React.useRef(false);
|
|
16
|
+
|
|
17
|
+
// Detect scroll
|
|
18
|
+
const data = useWindowScroll();
|
|
19
|
+
if (mounted.current) {
|
|
20
|
+
urls[key] = data;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Setup
|
|
24
|
+
React.useEffect(() => {
|
|
25
|
+
const pos = urls[key];
|
|
26
|
+
if (pos) {
|
|
27
|
+
window.scrollTo(pos.x, pos.y);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
mounted.current = true;
|
|
31
|
+
return () => {
|
|
32
|
+
mounted.current = false;
|
|
33
|
+
};
|
|
34
|
+
}, [key]);
|
|
35
|
+
|
|
36
|
+
return <React.Fragment />;
|
|
37
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from './components/GridMethodRef';
|
|
|
13
13
|
export * from './components/ListItemReact';
|
|
14
14
|
export * from './components/ScrollerGrid';
|
|
15
15
|
export * from './components/ScrollerList';
|
|
16
|
+
export * from './components/ScrollRestoration';
|
|
16
17
|
|
|
17
18
|
// notifier
|
|
18
19
|
export * from './notifier/Notifier';
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Window scroll position
|
|
5
|
+
*/
|
|
6
|
+
export interface IScrollPos {
|
|
4
7
|
x: number;
|
|
5
8
|
y: number;
|
|
6
9
|
}
|
|
@@ -32,7 +35,7 @@ export const useWindowScroll = () => {
|
|
|
32
35
|
ticking = false;
|
|
33
36
|
requestAnimationFrameSeed = 0;
|
|
34
37
|
|
|
35
|
-
if (lastPos.x !=
|
|
38
|
+
if (lastPos.x != pos.x || lastPos.y != pos.y) {
|
|
36
39
|
setPos(lastPos);
|
|
37
40
|
}
|
|
38
41
|
});
|