zh-web-sdk 2.9.0 → 2.10.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/jest.config.js ADDED
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ testEnvironment: "jsdom",
3
+ transform: {
4
+ "^.+.tsx?$": ["ts-jest",{}],
5
+ },
6
+ modulePathIgnorePatterns: ["<rootDir>/dist/"],
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zh-web-sdk",
3
- "version": "2.9.0",
3
+ "version": "2.10.4",
4
4
  "private": false,
5
5
  "description": "ZeroHash Web SDK",
6
6
  "homepage": "https://github.com/seedcx/zh-web-sdk",
@@ -17,9 +17,14 @@
17
17
  "build:zip": "npm run build && npm run zip",
18
18
  "zip": "rimraf build/* && node scripts/zip.js",
19
19
  "lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
20
- "test": "echo \"Error: no test specified\" && exit 1"
20
+ "test": "jest"
21
21
  },
22
22
  "devDependencies": {
23
+ "@testing-library/dom": "^10.4.0",
24
+ "@testing-library/react": "^16.0.1",
25
+ "@types/jest": "^29.5.14",
26
+ "@types/react": "^18.3.12",
27
+ "@types/react-dom": "^18.3.1",
23
28
  "@typescript-eslint/eslint-plugin": "^6.4.0",
24
29
  "archiver": "^5.3.1",
25
30
  "esbuild": "0.18.3",
@@ -32,12 +37,14 @@
32
37
  "eslint-plugin-promise": "^6.1.1",
33
38
  "eslint-plugin-react-hooks": "^4.6.0",
34
39
  "eslint-plugin-react-refresh": "^0.3.4",
40
+ "jest": "^29.7.0",
41
+ "jest-environment-jsdom": "^29.7.0",
35
42
  "rimraf": "^5.0.1",
43
+ "ts-jest": "^29.2.5",
44
+ "ts-node": "^10.9.2",
36
45
  "typescript": "^4.9.5"
37
46
  },
38
47
  "dependencies": {
39
- "@types/react": "^18.2.12",
40
- "@types/react-dom": "^18.2.5",
41
48
  "react": "^18.2.0",
42
49
  "react-dom": "^18.2.0",
43
50
  "react-redux": "^8.1.1",
@@ -0,0 +1,26 @@
1
+ import {useWindowSize} from "../use-window-size";
2
+ import {act, renderHook, waitFor} from "@testing-library/react";
3
+
4
+ describe("useWindowSize", () => {
5
+ it("Should work", async () => {
6
+ const { result } = renderHook(() => useWindowSize());
7
+
8
+ // Asset initial values.
9
+ expect(result.current.height).toBe(768);
10
+ expect(result.current.width).toBe(1024);
11
+
12
+
13
+ // Change the viewport to 500px.
14
+ global.innerWidth = 500;
15
+ global.innerHeight = 500;
16
+
17
+ act(() => {
18
+ global.dispatchEvent(new Event('resize'));
19
+ })
20
+
21
+ await waitFor(() => {
22
+ expect(result.current.width).toBe(500);
23
+ expect(result.current.height).toBe(500);
24
+ })
25
+ })
26
+ })
@@ -0,0 +1,19 @@
1
+ import {useLayoutEffect, useState} from "react";
2
+
3
+ export const useWindowSize = () => {
4
+ const [height, setHeight] = useState(0);
5
+ const [width, setWidth] = useState(0);
6
+ useLayoutEffect(() => {
7
+ function updateSize() {
8
+ setWidth(window.innerWidth);
9
+ setHeight(window.innerHeight);
10
+ }
11
+ window.addEventListener('resize', updateSize);
12
+ updateSize();
13
+ return () => window.removeEventListener('resize', updateSize);
14
+ }, []);
15
+ return {
16
+ height,
17
+ width
18
+ };
19
+ }
@@ -20,6 +20,7 @@ import {
20
20
  Page,
21
21
  appIdentifierToActionPrefixMap,
22
22
  } from "../types";
23
+ import { useWindowSize } from "../hooks/use-window-size";
23
24
 
24
25
  interface AppContainerProps {
25
26
  isAppActive?: boolean;
@@ -129,6 +130,7 @@ const AppContainer = ({
129
130
  const hasJwt = !!jwt;
130
131
  const [container, setContainerStyle] = useState(containerStyle);
131
132
  const allAppsState = useSelector((state) => state as AppContainerMappedProps);
133
+ const { height }= useWindowSize();
132
134
 
133
135
  /**
134
136
  * setContainer sets the CSS styles based on the current matching media queries
@@ -231,6 +233,8 @@ const AppContainer = ({
231
233
  isAppActive
232
234
  ? {
233
235
  ...appWrapperStyle,
236
+ maxHeight: CSS.supports("height: 100dvh") ? "100dvh" : `${height}px`,
237
+ height: CSS.supports("height: 100dvh") ? "100dvh" : `${height}px`
234
238
  }
235
239
  : appWrapperHiddenStyle
236
240
  }
package/src/styles.ts CHANGED
@@ -49,7 +49,7 @@ export const appWrapperStyle: CSSProperties = {
49
49
  flexDirection: "column",
50
50
  width: "100vw",
51
51
  height: CSS.supports("height: 100dvh") ? "100dvh" : window.innerHeight + "px",
52
- maxHeight: window.innerHeight + "px",
52
+ maxHeight: CSS.supports("height: 100dvh") ? "100dvh" : window.innerHeight + "px",
53
53
  background: "rgba(0,0,0,0.5)",
54
54
  cursor: "pointer",
55
55
  }
@@ -1,57 +0,0 @@
1
- name: "Release"
2
-
3
- on:
4
- push:
5
- tags:
6
- - "*"
7
-
8
- jobs:
9
- release:
10
- name: Release
11
- env:
12
- NODE_VERSION: '16.13.0'
13
- runs-on: ["builder","x64","linux","self-hosted"]
14
- steps:
15
- - uses: actions/checkout@v3
16
-
17
- - uses: actions/setup-node@v3
18
- with:
19
- node-version: ${{ env.NODE_VERSION }}
20
- cache: 'npm'
21
-
22
- - name: NPM CI
23
- run: npm ci
24
-
25
- - name: NPM Build
26
- run: echo "BUILD=$(npm run build:zip | grep Zipping | awk '{print $3}') " >> $GITHUB_OUTPUT
27
- id: build
28
-
29
- - name: Create a GitHub release
30
- uses: ncipollo/release-action@v1
31
- with:
32
- tag: ${{ github.ref_name }}
33
- name: Release ${{ github.ref_name }}
34
- body: |
35
- ${{ github.ref.outputs.changelog }}
36
- generateReleaseNotes: true
37
- token: ${{ secrets.GITHUB_TOKEN }}
38
- artifacts: |
39
- ${{ steps.build.outputs.BUILD }}
40
-
41
- publish:
42
- name: Publish
43
- env:
44
- NODE_VERSION: '16.13.0'
45
- runs-on: ["builder","x64","linux","self-hosted"]
46
- steps:
47
- - uses: actions/checkout@v3
48
- - uses: actions/setup-node@v3
49
- with:
50
- node-version: ${{ env.NODE_VERSION }}
51
- cache: 'npm'
52
- registry-url: 'https://registry.npmjs.org'
53
- - name: NPM CI
54
- run: npm ci
55
- - run: npm publish
56
- env:
57
- NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}