@etsoo/materialui 1.4.28 → 1.4.30
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/UserAvatarEditor.d.ts +1 -1
- package/lib/UserAvatarEditor.js +14 -5
- package/package.json +4 -4
- package/src/UserAvatarEditor.tsx +20 -9
|
@@ -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): Promise<void | false | undefined>;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* User avatar editor props
|
package/lib/UserAvatarEditor.js
CHANGED
|
@@ -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;
|
|
@@ -130,16 +134,21 @@ export function UserAvatarEditor(props) {
|
|
|
130
134
|
to.height = heightCalculated;
|
|
131
135
|
// Large photo, resize it
|
|
132
136
|
// https://github.com/nodeca/pica
|
|
133
|
-
picaInstance
|
|
134
|
-
.resize(data, to, {
|
|
137
|
+
const canvas = await picaInstance.resize(data, to, {
|
|
135
138
|
unsharpAmount: 160,
|
|
136
139
|
unsharpRadius: 0.6,
|
|
137
140
|
unsharpThreshold: 1
|
|
138
|
-
})
|
|
139
|
-
|
|
141
|
+
});
|
|
142
|
+
const result = await onDone(canvas, toBlob, type.current);
|
|
143
|
+
if (result === false) {
|
|
144
|
+
resetUI();
|
|
145
|
+
}
|
|
140
146
|
}
|
|
141
147
|
else {
|
|
142
|
-
onDone(data, toBlob, type.current);
|
|
148
|
+
const result = await onDone(data, toBlob, type.current);
|
|
149
|
+
if (result === false) {
|
|
150
|
+
resetUI();
|
|
151
|
+
}
|
|
143
152
|
}
|
|
144
153
|
};
|
|
145
154
|
// Load the component
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/materialui",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.30",
|
|
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.
|
|
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.
|
|
43
|
-
"@mui/material": "^6.1.
|
|
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",
|
package/src/UserAvatarEditor.tsx
CHANGED
|
@@ -40,7 +40,7 @@ export interface UserAvatarEditorOnDoneHandler {
|
|
|
40
40
|
canvas: HTMLCanvasElement,
|
|
41
41
|
toBlob: UserAvatarEditorToBlob,
|
|
42
42
|
type: string
|
|
43
|
-
): void
|
|
43
|
+
): Promise<void | false | undefined>;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
@@ -224,6 +224,11 @@ export function UserAvatarEditor(props: UserAvatarEditorProps) {
|
|
|
224
224
|
setEditorState({ ...defaultState });
|
|
225
225
|
};
|
|
226
226
|
|
|
227
|
+
const resetUI = () => {
|
|
228
|
+
setPreviewImage(undefined);
|
|
229
|
+
handleReset();
|
|
230
|
+
};
|
|
231
|
+
|
|
227
232
|
// Handle rotate
|
|
228
233
|
const handleRotate = (r: number) => {
|
|
229
234
|
let rotate = editorState.rotate + r;
|
|
@@ -266,15 +271,21 @@ export function UserAvatarEditor(props: UserAvatarEditorProps) {
|
|
|
266
271
|
|
|
267
272
|
// Large photo, resize it
|
|
268
273
|
// https://github.com/nodeca/pica
|
|
269
|
-
picaInstance
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
274
|
+
const canvas = await picaInstance.resize(data, to, {
|
|
275
|
+
unsharpAmount: 160,
|
|
276
|
+
unsharpRadius: 0.6,
|
|
277
|
+
unsharpThreshold: 1
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
const result = await onDone(canvas, toBlob, type.current);
|
|
281
|
+
if (result === false) {
|
|
282
|
+
resetUI();
|
|
283
|
+
}
|
|
276
284
|
} else {
|
|
277
|
-
onDone(data, toBlob, type.current);
|
|
285
|
+
const result = await onDone(data, toBlob, type.current);
|
|
286
|
+
if (result === false) {
|
|
287
|
+
resetUI();
|
|
288
|
+
}
|
|
278
289
|
}
|
|
279
290
|
};
|
|
280
291
|
|