@etsoo/react 1.6.70 → 1.6.72

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.
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ /**
3
+ * Scroll restoration
4
+ */
5
+ export declare function ScrollRestoration(): JSX.Element;
@@ -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
- interface IScrollPos {
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 != lastPos.x || lastPos.y != lastPos.y) {
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.70",
3
+ "version": "1.6.72",
4
4
  "description": "TypeScript ReactJs UI Independent Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -47,10 +47,10 @@
47
47
  "dependencies": {
48
48
  "@dnd-kit/core": "^6.0.8",
49
49
  "@dnd-kit/sortable": "^7.0.2",
50
- "@emotion/css": "^11.10.6",
51
- "@emotion/react": "^11.10.6",
52
- "@emotion/styled": "^11.10.6",
53
- "@etsoo/appscript": "^1.3.95",
50
+ "@emotion/css": "^11.10.8",
51
+ "@emotion/react": "^11.10.8",
52
+ "@emotion/styled": "^11.10.8",
53
+ "@etsoo/appscript": "^1.3.98",
54
54
  "@etsoo/notificationbase": "^1.1.24",
55
55
  "@etsoo/shared": "^1.2.1",
56
56
  "@types/react": "^18.2.0",
@@ -58,15 +58,15 @@
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.10.0",
61
+ "react-router-dom": "^6.11.0",
62
62
  "react-window": "^1.8.9"
63
63
  },
64
64
  "devDependencies": {
65
- "@babel/cli": "^7.21.0",
66
- "@babel/core": "^7.21.4",
65
+ "@babel/cli": "^7.21.5",
66
+ "@babel/core": "^7.21.5",
67
67
  "@babel/plugin-transform-runtime": "^7.21.4",
68
- "@babel/preset-env": "^7.21.4",
69
- "@babel/runtime-corejs3": "^7.21.0",
68
+ "@babel/preset-env": "^7.21.5",
69
+ "@babel/runtime-corejs3": "^7.21.5",
70
70
  "@testing-library/jest-dom": "^5.16.5",
71
71
  "@testing-library/react": "^14.0.0",
72
72
  "@types/jest": "^29.5.1",
@@ -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
- interface IScrollPos {
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 != lastPos.x || lastPos.y != lastPos.y) {
38
+ if (lastPos.x != pos.x || lastPos.y != pos.y) {
36
39
  setPos(lastPos);
37
40
  }
38
41
  });