idea-react 2.0.0-rc.1 → 2.0.0-rc.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "idea-react",
3
- "version": "2.0.0-rc.1",
3
+ "version": "2.0.0-rc.2",
4
4
  "license": "LGPL-3.0-or-later",
5
5
  "author": "shiy2008@gmail.com",
6
6
  "description": "A React advanced components library based on TypeScript & Bootstrap, built by idea2app remote developers team.",
@@ -28,6 +28,7 @@
28
28
  "@swc/helpers": "^0.5.3",
29
29
  "classnames": "^2.5.1",
30
30
  "editorjs-html": "^3.4.3",
31
+ "html2canvas": "^1.4.1",
31
32
  "iterable-observer": "^1.0.1",
32
33
  "lodash": "^4.17.21",
33
34
  "mobx": ">=6.12.0",
@@ -52,18 +53,18 @@
52
53
  "@parcel/transformer-typescript-tsc": "~2.11.0",
53
54
  "@parcel/transformer-typescript-types": "~2.11.0",
54
55
  "@storybook/addon-console": "^3.0.0",
55
- "@storybook/addon-essentials": "^7.6.10",
56
- "@storybook/addon-interactions": "^7.6.10",
57
- "@storybook/addon-links": "^7.6.10",
58
- "@storybook/addon-storysource": "^7.6.10",
59
- "@storybook/blocks": "^7.6.10",
60
- "@storybook/react": "^7.6.10",
61
- "@storybook/react-vite": "^7.6.10",
56
+ "@storybook/addon-essentials": "^7.6.12",
57
+ "@storybook/addon-interactions": "^7.6.12",
58
+ "@storybook/addon-links": "^7.6.12",
59
+ "@storybook/addon-storysource": "^7.6.12",
60
+ "@storybook/blocks": "^7.6.12",
61
+ "@storybook/react": "^7.6.12",
62
+ "@storybook/react-vite": "^7.6.12",
62
63
  "@storybook/testing-library": "^0.2.2",
63
64
  "@types/lodash": "^4.14.202",
64
- "@types/node": "^18.19.10",
65
+ "@types/node": "^18.19.14",
65
66
  "@types/prismjs": "^1.26.3",
66
- "@types/react": "^18.2.48",
67
+ "@types/react": "^18.2.52",
67
68
  "@types/react-dom": "^18.2.18",
68
69
  "@typescript-eslint/eslint-plugin": "^6.20.0",
69
70
  "@typescript-eslint/parser": "^6.20.0",
@@ -72,10 +73,10 @@
72
73
  "eslint-config-prettier": "^9.1.0",
73
74
  "eslint-plugin-import": "^2.29.1",
74
75
  "eslint-plugin-simple-import-sort": "^10.0.0",
75
- "husky": "^9.0.7",
76
+ "husky": "^9.0.10",
76
77
  "koapache": "^2.2.2",
77
78
  "less": "^4.2.0",
78
- "lint-staged": "^15.2.0",
79
+ "lint-staged": "^15.2.1",
79
80
  "parcel": "~2.11.0",
80
81
  "postcss-preset-env": "^9.3.0",
81
82
  "prettier": "^3.2.4",
@@ -84,7 +85,7 @@
84
85
  "react": "^18.2.0",
85
86
  "react-dom": "^18.2.0",
86
87
  "rimraf": "^5.0.5",
87
- "storybook": "^7.6.10",
88
+ "storybook": "^7.6.12",
88
89
  "typedoc": "^0.25.7",
89
90
  "typedoc-plugin-mdn-links": "^3.1.14",
90
91
  "typescript": "~5.3.3",
@@ -0,0 +1,98 @@
1
+ import html2canvas from 'html2canvas';
2
+ import { observable } from 'mobx';
3
+ import { observer } from 'mobx-react';
4
+ import { createRef, MouseEvent, PropsWithChildren, PureComponent } from 'react';
5
+ import { Image } from 'react-bootstrap';
6
+ import { blobOf } from 'web-utility';
7
+
8
+ import { Loading } from './Loading';
9
+
10
+ export async function elementToImage(
11
+ element: HTMLElement,
12
+ type?: string,
13
+ quality?: number
14
+ ) {
15
+ const canvas = await html2canvas(element, { useCORS: true });
16
+
17
+ return new Promise<string>((resolve, reject) =>
18
+ canvas.toBlob(
19
+ blob => (blob ? resolve(URL.createObjectURL(blob)) : reject()),
20
+ type,
21
+ quality
22
+ )
23
+ );
24
+ }
25
+
26
+ export type ShareBoxProps = PropsWithChildren<ShareData>;
27
+
28
+ @observer
29
+ export class ShareBox extends PureComponent<ShareBoxProps> {
30
+ static displayName = 'ShareBox';
31
+
32
+ root = createRef<HTMLDivElement>();
33
+
34
+ @observable
35
+ accessor loading = false;
36
+
37
+ @observable
38
+ accessor imageURI = '';
39
+
40
+ componentDidMount() {
41
+ globalThis.addEventListener?.('resize', this.generateImage);
42
+ }
43
+
44
+ componentWillUnmount() {
45
+ globalThis.removeEventListener?.('resize', this.generateImage);
46
+ }
47
+
48
+ generateImage = async () => {
49
+ if (this.imageURI) {
50
+ URL.revokeObjectURL(this.imageURI);
51
+ this.imageURI = '';
52
+ }
53
+ this.loading = true;
54
+ this.imageURI = await elementToImage(this.root.current!);
55
+ this.loading = false;
56
+ };
57
+
58
+ share = async (event: MouseEvent<HTMLImageElement>) => {
59
+ event.stopPropagation();
60
+
61
+ const image = await blobOf(this.imageURI);
62
+
63
+ const file = new File([image], `${this.props.title}.png`, {
64
+ type: image.type
65
+ });
66
+ await navigator.share?.({ files: [file], ...this.props });
67
+ };
68
+
69
+ render() {
70
+ const { children } = this.props,
71
+ { loading, imageURI } = this;
72
+
73
+ return (
74
+ <>
75
+ {loading && <Loading />}
76
+
77
+ <div
78
+ ref={this.root}
79
+ className="position-relative"
80
+ onMouseEnter={imageURI ? undefined : this.generateImage}
81
+ onTouchStart={imageURI ? undefined : this.generateImage}
82
+ >
83
+ {children}
84
+
85
+ {imageURI && (
86
+ <Image
87
+ className="position-absolute start-0 top-0 w-100 h-100"
88
+ fluid
89
+ src={imageURI}
90
+ alt="Share Image"
91
+ onClick={this.share}
92
+ />
93
+ )}
94
+ </div>
95
+ </>
96
+ );
97
+ }
98
+ }
package/source/index.ts CHANGED
@@ -13,6 +13,7 @@ export * from './Nameplate';
13
13
  export * from './OverlayBox';
14
14
  export * from './PageNav';
15
15
  export * from './Select';
16
+ export * from './ShareBox';
16
17
  export * from './SpinnerButton';
17
18
  export * from './TableSpinner';
18
19
  export * from './TimeDistance';