@etsoo/materialui 1.4.28 → 1.4.29

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.
@@ -8,7 +8,7 @@ export interface UserAvatarEditorToBlob {
8
8
  * User avatar editor on done handler
9
9
  */
10
10
  export interface UserAvatarEditorOnDoneHandler {
11
- (canvas: HTMLCanvasElement, toBlob: UserAvatarEditorToBlob, type: string): void;
11
+ (canvas: HTMLCanvasElement, toBlob: UserAvatarEditorToBlob, type: string): void | false;
12
12
  }
13
13
  /**
14
14
  * User avatar editor props
@@ -97,6 +97,10 @@ export function UserAvatarEditor(props) {
97
97
  const handleReset = () => {
98
98
  setEditorState({ ...defaultState });
99
99
  };
100
+ const resetUI = () => {
101
+ setPreviewImage(undefined);
102
+ handleReset();
103
+ };
100
104
  // Handle rotate
101
105
  const handleRotate = (r) => {
102
106
  let rotate = editorState.rotate + r;
@@ -136,10 +140,14 @@ export function UserAvatarEditor(props) {
136
140
  unsharpRadius: 0.6,
137
141
  unsharpThreshold: 1
138
142
  })
139
- .then((result) => onDone(result, toBlob, type.current));
143
+ .then((result) => {
144
+ if (onDone(result, toBlob, type.current) === false) {
145
+ resetUI();
146
+ }
147
+ });
140
148
  }
141
- else {
142
- onDone(data, toBlob, type.current);
149
+ else if (onDone(data, toBlob, type.current) === false) {
150
+ resetUI();
143
151
  }
144
152
  };
145
153
  // Load the component
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.4.28",
3
+ "version": "1.4.29",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -35,12 +35,12 @@
35
35
  "@emotion/css": "^11.13.5",
36
36
  "@emotion/react": "^11.13.5",
37
37
  "@emotion/styled": "^11.13.5",
38
- "@etsoo/appscript": "^1.5.70",
38
+ "@etsoo/appscript": "^1.5.71",
39
39
  "@etsoo/notificationbase": "^1.1.54",
40
40
  "@etsoo/react": "^1.8.3",
41
41
  "@etsoo/shared": "^1.2.55",
42
- "@mui/icons-material": "^6.1.8",
43
- "@mui/material": "^6.1.8",
42
+ "@mui/icons-material": "^6.1.9",
43
+ "@mui/material": "^6.1.9",
44
44
  "@mui/x-data-grid": "^7.22.3",
45
45
  "chart.js": "^4.4.6",
46
46
  "chartjs-plugin-datalabels": "^2.2.0",
@@ -36,11 +36,9 @@ export interface UserAvatarEditorToBlob {
36
36
  * User avatar editor on done handler
37
37
  */
38
38
  export interface UserAvatarEditorOnDoneHandler {
39
- (
40
- canvas: HTMLCanvasElement,
41
- toBlob: UserAvatarEditorToBlob,
42
- type: string
43
- ): void;
39
+ (canvas: HTMLCanvasElement, toBlob: UserAvatarEditorToBlob, type: string):
40
+ | void
41
+ | false;
44
42
  }
45
43
 
46
44
  /**
@@ -224,6 +222,11 @@ export function UserAvatarEditor(props: UserAvatarEditorProps) {
224
222
  setEditorState({ ...defaultState });
225
223
  };
226
224
 
225
+ const resetUI = () => {
226
+ setPreviewImage(undefined);
227
+ handleReset();
228
+ };
229
+
227
230
  // Handle rotate
228
231
  const handleRotate = (r: number) => {
229
232
  let rotate = editorState.rotate + r;
@@ -272,9 +275,13 @@ export function UserAvatarEditor(props: UserAvatarEditorProps) {
272
275
  unsharpRadius: 0.6,
273
276
  unsharpThreshold: 1
274
277
  })
275
- .then((result) => onDone(result, toBlob, type.current));
276
- } else {
277
- onDone(data, toBlob, type.current);
278
+ .then((result) => {
279
+ if (onDone(result, toBlob, type.current) === false) {
280
+ resetUI();
281
+ }
282
+ });
283
+ } else if (onDone(data, toBlob, type.current) === false) {
284
+ resetUI();
278
285
  }
279
286
  };
280
287