@dreamcommerce/aurora 2.8.1-34 → 2.8.1-36
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/build/cjs/packages/aurora/src/components/file_picker/use_file_picker.js +19 -2
- package/build/cjs/packages/aurora/src/components/file_picker/use_file_picker.js.map +1 -1
- package/build/esm/packages/aurora/src/components/file_picker/types.d.ts +5 -1
- package/build/esm/packages/aurora/src/components/file_picker/types.js +1 -1
- package/build/esm/packages/aurora/src/components/file_picker/types.js.map +1 -1
- package/build/esm/packages/aurora/src/components/file_picker/use_file_picker.js +19 -2
- package/build/esm/packages/aurora/src/components/file_picker/use_file_picker.js.map +1 -1
- package/package.json +1 -1
|
@@ -11,13 +11,28 @@ const useFilePicker = ({ onChange, initialFile, allowedExtensions, inputRef, ini
|
|
|
11
11
|
const [errors, setErrors] = React.useState([]);
|
|
12
12
|
const [isDragOver, setDragOver] = React.useState(false);
|
|
13
13
|
const [isPreview, setPreview] = React.useState(true);
|
|
14
|
+
const [imageSize, setImageSize] = React.useState(undefined);
|
|
14
15
|
React.useEffect(() => {
|
|
15
|
-
console.log('initialFile', initialFile);
|
|
16
16
|
setFile(initialFile);
|
|
17
|
+
initialFile && setImageSizeBasedOnUrl(initialFile === null || initialFile === void 0 ? void 0 : initialFile.fileUrl);
|
|
17
18
|
}, [initialFile]);
|
|
19
|
+
React.useEffect(() => {
|
|
20
|
+
console.log('imageSize', imageSize);
|
|
21
|
+
}, [imageSize]);
|
|
18
22
|
React.useEffect(() => {
|
|
19
23
|
initialErrors && setErrors(initialErrors);
|
|
20
24
|
}, [initialErrors]);
|
|
25
|
+
const setImageSizeBasedOnUrl = (fileUrl) => {
|
|
26
|
+
createImageFromUrl(fileUrl).then((image) => {
|
|
27
|
+
setImageSize({ width: image.naturalWidth, height: image.naturalHeight });
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
const createImageFromUrl = async (url) => {
|
|
31
|
+
const img = new Image();
|
|
32
|
+
img.src = url;
|
|
33
|
+
await img.decode();
|
|
34
|
+
return img;
|
|
35
|
+
};
|
|
21
36
|
const onDropFile = (event) => {
|
|
22
37
|
setErrors([]);
|
|
23
38
|
event.stopPropagation();
|
|
@@ -49,10 +64,12 @@ const useFilePicker = ({ onChange, initialFile, allowedExtensions, inputRef, ini
|
|
|
49
64
|
};
|
|
50
65
|
const updateFile = (files) => {
|
|
51
66
|
if (files === null || files === void 0 ? void 0 : files.length) {
|
|
67
|
+
const fileUrl = URL.createObjectURL(files === null || files === void 0 ? void 0 : files[0]);
|
|
52
68
|
setFile({
|
|
53
69
|
fileName: files === null || files === void 0 ? void 0 : files[0].name,
|
|
54
|
-
fileUrl:
|
|
70
|
+
fileUrl: fileUrl
|
|
55
71
|
});
|
|
72
|
+
setImageSizeBasedOnUrl(fileUrl);
|
|
56
73
|
const isValid = validateFileExtension(allowedExtensions, files[0].type);
|
|
57
74
|
if (isValid)
|
|
58
75
|
onChange === null || onChange === void 0 ? void 0 : onChange(files);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
|
|
1
|
+
{"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import React, { ChangeEvent } from 'react';
|
|
2
1
|
import { FILES_EXTENSIONS, MIME_FILE_EXTENSIONS } from "./constants";
|
|
2
|
+
import React, { ChangeEvent } from 'react';
|
|
3
3
|
import { TControlErrors } from "../controls/types";
|
|
4
4
|
export declare type TFilePickerFile = {
|
|
5
5
|
fileUrl: string;
|
|
6
6
|
fileName: string;
|
|
7
7
|
};
|
|
8
|
+
export declare type TFilePickerImageSize = {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
};
|
|
8
12
|
export interface IFilePicker {
|
|
9
13
|
id: string;
|
|
10
14
|
name?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../src/components/file_picker/types.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../src/components/file_picker/types.ts"],"names":[],"mappings":"AAAA,OAAuD,yCAAyC,CAAC;AACjG,OAAmC,OAAO,CAAC;AAE3C,OAA+B,kCAAkC,CAAC"}
|
|
@@ -7,13 +7,28 @@ const useFilePicker = ({ onChange, initialFile, allowedExtensions, inputRef, ini
|
|
|
7
7
|
const [errors, setErrors] = useState([]);
|
|
8
8
|
const [isDragOver, setDragOver] = useState(false);
|
|
9
9
|
const [isPreview, setPreview] = useState(true);
|
|
10
|
+
const [imageSize, setImageSize] = useState(undefined);
|
|
10
11
|
useEffect(() => {
|
|
11
|
-
console.log('initialFile', initialFile);
|
|
12
12
|
setFile(initialFile);
|
|
13
|
+
initialFile && setImageSizeBasedOnUrl(initialFile === null || initialFile === void 0 ? void 0 : initialFile.fileUrl);
|
|
13
14
|
}, [initialFile]);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
console.log('imageSize', imageSize);
|
|
17
|
+
}, [imageSize]);
|
|
14
18
|
useEffect(() => {
|
|
15
19
|
initialErrors && setErrors(initialErrors);
|
|
16
20
|
}, [initialErrors]);
|
|
21
|
+
const setImageSizeBasedOnUrl = (fileUrl) => {
|
|
22
|
+
createImageFromUrl(fileUrl).then((image) => {
|
|
23
|
+
setImageSize({ width: image.naturalWidth, height: image.naturalHeight });
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
const createImageFromUrl = async (url) => {
|
|
27
|
+
const img = new Image();
|
|
28
|
+
img.src = url;
|
|
29
|
+
await img.decode();
|
|
30
|
+
return img;
|
|
31
|
+
};
|
|
17
32
|
const onDropFile = (event) => {
|
|
18
33
|
setErrors([]);
|
|
19
34
|
event.stopPropagation();
|
|
@@ -45,10 +60,12 @@ const useFilePicker = ({ onChange, initialFile, allowedExtensions, inputRef, ini
|
|
|
45
60
|
};
|
|
46
61
|
const updateFile = (files) => {
|
|
47
62
|
if (files === null || files === void 0 ? void 0 : files.length) {
|
|
63
|
+
const fileUrl = URL.createObjectURL(files === null || files === void 0 ? void 0 : files[0]);
|
|
48
64
|
setFile({
|
|
49
65
|
fileName: files === null || files === void 0 ? void 0 : files[0].name,
|
|
50
|
-
fileUrl:
|
|
66
|
+
fileUrl: fileUrl
|
|
51
67
|
});
|
|
68
|
+
setImageSizeBasedOnUrl(fileUrl);
|
|
52
69
|
const isValid = validateFileExtension(allowedExtensions, files[0].type);
|
|
53
70
|
if (isValid)
|
|
54
71
|
onChange === null || onChange === void 0 ? void 0 : onChange(files);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
|
|
1
|
+
{"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
|