@veeqo/ui 12.4.0-beta-2 → 12.4.0-beta-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/dist/components/SelectDropdown/SelectDropdown.cjs +7 -8
- package/dist/components/SelectDropdown/SelectDropdown.cjs.map +1 -1
- package/dist/components/SelectDropdown/SelectDropdown.d.ts +1 -1
- package/dist/components/SelectDropdown/SelectDropdown.js +7 -8
- package/dist/components/SelectDropdown/SelectDropdown.js.map +1 -1
- package/dist/components/SelectDropdown/SelectDropdown.module.scss.cjs +2 -2
- package/dist/components/SelectDropdown/SelectDropdown.module.scss.cjs.map +1 -1
- package/dist/components/SelectDropdown/SelectDropdown.module.scss.js +2 -2
- package/dist/components/SelectDropdown/SelectDropdown.module.scss.js.map +1 -1
- package/dist/components/SelectDropdown/components/ListItem/ListItem.js +2 -2
- package/dist/components/SelectDropdown/components/ListItem/ListItem.js.map +1 -1
- package/dist/components/SelectDropdown/components/item.module.scss.cjs +2 -2
- package/dist/components/SelectDropdown/components/item.module.scss.cjs.map +1 -1
- package/dist/components/SelectDropdown/components/item.module.scss.js +2 -2
- package/dist/components/SelectDropdown/components/item.module.scss.js.map +1 -1
- package/dist/components/SelectDropdown/types.d.ts +1 -3
- package/dist/components/UploadFile/UploadFile.cjs +63 -82
- package/dist/components/UploadFile/UploadFile.cjs.map +1 -1
- package/dist/components/UploadFile/UploadFile.js +66 -85
- package/dist/components/UploadFile/UploadFile.js.map +1 -1
- package/dist/components/UploadFile/components/DropCopy/DropCopy.cjs +28 -0
- package/dist/components/UploadFile/components/DropCopy/DropCopy.cjs.map +1 -0
- package/dist/components/UploadFile/components/DropCopy/DropCopy.d.ts +2 -0
- package/dist/components/UploadFile/components/DropCopy/DropCopy.js +22 -0
- package/dist/components/UploadFile/components/DropCopy/DropCopy.js.map +1 -0
- package/dist/components/UploadFile/components/UploadCopy/UploadCopy.cjs +6 -6
- package/dist/components/UploadFile/components/UploadCopy/UploadCopy.cjs.map +1 -1
- package/dist/components/UploadFile/components/UploadCopy/UploadCopy.js +6 -6
- package/dist/components/UploadFile/components/UploadCopy/UploadCopy.js.map +1 -1
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.cjs +52 -5
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.cjs.map +1 -1
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.d.ts +7 -3
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.js +52 -5
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.js.map +1 -1
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.module.scss.cjs +9 -0
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.module.scss.cjs.map +1 -0
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.module.scss.js +7 -0
- package/dist/components/UploadFile/components/UploadedFile/UploadedFile.module.scss.js.map +1 -0
- package/dist/components/UploadFile/constants.cjs +64 -8
- package/dist/components/UploadFile/constants.cjs.map +1 -1
- package/dist/components/UploadFile/constants.d.ts +52 -5
- package/dist/components/UploadFile/constants.js +63 -9
- package/dist/components/UploadFile/constants.js.map +1 -1
- package/dist/components/UploadFile/hooks/useFileErrorMessages/index.d.ts +1 -0
- package/dist/components/UploadFile/hooks/useFileErrorMessages/useFileErrorMessages.cjs +39 -0
- package/dist/components/UploadFile/hooks/useFileErrorMessages/useFileErrorMessages.cjs.map +1 -0
- package/dist/components/UploadFile/hooks/useFileErrorMessages/useFileErrorMessages.d.ts +13 -0
- package/dist/components/UploadFile/hooks/useFileErrorMessages/useFileErrorMessages.js +37 -0
- package/dist/components/UploadFile/hooks/useFileErrorMessages/useFileErrorMessages.js.map +1 -0
- package/dist/components/UploadFile/hooks/usePreviewImage/index.d.ts +1 -0
- package/dist/components/UploadFile/hooks/usePreviewImage/usePreviewImage.cjs +36 -0
- package/dist/components/UploadFile/hooks/usePreviewImage/usePreviewImage.cjs.map +1 -0
- package/dist/components/UploadFile/hooks/usePreviewImage/usePreviewImage.d.ts +8 -0
- package/dist/components/UploadFile/hooks/usePreviewImage/usePreviewImage.js +34 -0
- package/dist/components/UploadFile/hooks/usePreviewImage/usePreviewImage.js.map +1 -0
- package/dist/components/UploadFile/hooks/useUploadFile/index.d.ts +1 -0
- package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.cjs +65 -0
- package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.cjs.map +1 -0
- package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.d.ts +9 -0
- package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.js +63 -0
- package/dist/components/UploadFile/hooks/useUploadFile/useUploadFile.js.map +1 -0
- package/dist/components/UploadFile/hooks/useValidateInput/index.d.ts +1 -0
- package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.cjs +69 -0
- package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.cjs.map +1 -0
- package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.d.ts +10 -0
- package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.js +67 -0
- package/dist/components/UploadFile/hooks/useValidateInput/useValidateInput.js.map +1 -0
- package/dist/components/UploadFile/mocks/files.d.ts +2 -0
- package/dist/components/UploadFile/mocks/mockUseUploadFile.d.ts +14 -0
- package/dist/components/UploadFile/mocks/utils.d.ts +1 -2
- package/dist/components/UploadFile/styled.cjs +41 -1
- package/dist/components/UploadFile/styled.cjs.map +1 -1
- package/dist/components/UploadFile/styled.d.ts +5 -1
- package/dist/components/UploadFile/styled.js +41 -1
- package/dist/components/UploadFile/styled.js.map +1 -1
- package/dist/components/UploadFile/types.d.ts +15 -1
- package/dist/components/UploadFile/utils/convertFileTypeToAcceptedFileExtension/convertFileTypeToAcceptedFileExtension.d.ts +1 -0
- package/dist/components/UploadFile/utils/convertFileTypeToAcceptedFileExtension/convertFileTypeToAcceptedFileType.cjs +17 -0
- package/dist/components/UploadFile/utils/convertFileTypeToAcceptedFileExtension/convertFileTypeToAcceptedFileType.cjs.map +1 -0
- package/dist/components/UploadFile/utils/convertFileTypeToAcceptedFileExtension/convertFileTypeToAcceptedFileType.d.ts +1 -0
- package/dist/components/UploadFile/utils/convertFileTypeToAcceptedFileExtension/convertFileTypeToAcceptedFileType.js +15 -0
- package/dist/components/UploadFile/utils/convertFileTypeToAcceptedFileExtension/convertFileTypeToAcceptedFileType.js.map +1 -0
- package/dist/components/UploadFile/utils/convertFileTypeToAcceptedFileExtension/index.d.ts +1 -0
- package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.cjs +14 -11
- package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.cjs.map +1 -1
- package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.d.ts +10 -7
- package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.js +14 -11
- package/dist/components/UploadFile/utils/getFileSizeString/getFileSizeString.js.map +1 -1
- package/dist/components/UploadFile/utils/getValidTypesString/getValidTypesString.cjs +16 -30
- package/dist/components/UploadFile/utils/getValidTypesString/getValidTypesString.cjs.map +1 -1
- package/dist/components/UploadFile/utils/getValidTypesString/getValidTypesString.js +16 -30
- package/dist/components/UploadFile/utils/getValidTypesString/getValidTypesString.js.map +1 -1
- package/dist/components/UploadFile/utils/index.d.ts +0 -1
- package/dist/components/UploadFile/utils/isImageType/index.d.ts +1 -0
- package/dist/components/UploadFile/utils/isImageType/isImageType.cjs +14 -0
- package/dist/components/UploadFile/utils/isImageType/isImageType.cjs.map +1 -0
- package/dist/components/UploadFile/utils/isImageType/isImageType.d.ts +1 -0
- package/dist/components/UploadFile/utils/isImageType/isImageType.js +12 -0
- package/dist/components/UploadFile/utils/isImageType/isImageType.js.map +1 -0
- package/package.json +1 -1
- package/dist/components/SelectDropdown/components/GridItem/GridItem.cjs +0 -37
- package/dist/components/SelectDropdown/components/GridItem/GridItem.cjs.map +0 -1
- package/dist/components/SelectDropdown/components/GridItem/GridItem.js +0 -31
- package/dist/components/SelectDropdown/components/GridItem/GridItem.js.map +0 -1
- package/dist/components/SelectDropdown/components/OptionsContainers/GridList.cjs +0 -18
- package/dist/components/SelectDropdown/components/OptionsContainers/GridList.cjs.map +0 -1
- package/dist/components/SelectDropdown/components/OptionsContainers/GridList.d.ts +0 -3
- package/dist/components/SelectDropdown/components/OptionsContainers/GridList.js +0 -12
- package/dist/components/SelectDropdown/components/OptionsContainers/GridList.js.map +0 -1
- package/dist/components/SelectDropdown/components/OptionsContainers/ListBox.cjs +0 -19
- package/dist/components/SelectDropdown/components/OptionsContainers/ListBox.cjs.map +0 -1
- package/dist/components/SelectDropdown/components/OptionsContainers/ListBox.d.ts +0 -3
- package/dist/components/SelectDropdown/components/OptionsContainers/ListBox.js +0 -13
- package/dist/components/SelectDropdown/components/OptionsContainers/ListBox.js.map +0 -1
- package/dist/components/SelectDropdown/components/OptionsContainers/OptionsContainer.module.scss.cjs +0 -9
- package/dist/components/SelectDropdown/components/OptionsContainers/OptionsContainer.module.scss.cjs.map +0 -1
- package/dist/components/SelectDropdown/components/OptionsContainers/OptionsContainer.module.scss.js +0 -7
- package/dist/components/SelectDropdown/components/OptionsContainers/OptionsContainer.module.scss.js.map +0 -1
- package/dist/components/SelectDropdown/components/OptionsContainers/types.d.ts +0 -25
- package/dist/components/UploadFile/UploadGraphic.cjs +0 -14
- package/dist/components/UploadFile/UploadGraphic.cjs.map +0 -1
- package/dist/components/UploadFile/UploadGraphic.d.ts +0 -2
- package/dist/components/UploadFile/UploadGraphic.js +0 -8
- package/dist/components/UploadFile/UploadGraphic.js.map +0 -1
- package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.cjs +0 -31
- package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.cjs.map +0 -1
- package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.d.ts +0 -7
- package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.js +0 -25
- package/dist/components/UploadFile/components/UploadFileErrors/UploadFileErrors.js.map +0 -1
- package/dist/components/UploadFile/components/UploadedFile/styled.cjs +0 -20
- package/dist/components/UploadFile/components/UploadedFile/styled.cjs.map +0 -1
- package/dist/components/UploadFile/components/UploadedFile/styled.d.ts +0 -2
- package/dist/components/UploadFile/components/UploadedFile/styled.js +0 -13
- package/dist/components/UploadFile/components/UploadedFile/styled.js.map +0 -1
- package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.cjs +0 -18
- package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.cjs.map +0 -1
- package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.d.ts +0 -13
- package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.js +0 -16
- package/dist/components/UploadFile/utils/setInputElFile/setInputElFile.js.map +0 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { isImageType } from '../../utils/isImageType/isImageType.js';
|
|
3
|
+
|
|
4
|
+
const usePreviewImage = ({ file }) => {
|
|
5
|
+
const [previewSrc, setPreviewSrc] = useState('');
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (!file) {
|
|
8
|
+
setPreviewSrc('');
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
if (!isImageType(file)) {
|
|
12
|
+
setPreviewSrc('');
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const fileReader = new FileReader();
|
|
16
|
+
fileReader.onload = (event) => {
|
|
17
|
+
var _a;
|
|
18
|
+
const imageUrl = (_a = event.target) === null || _a === undefined ? undefined : _a.result;
|
|
19
|
+
setPreviewSrc(String(imageUrl));
|
|
20
|
+
};
|
|
21
|
+
fileReader.readAsDataURL(file);
|
|
22
|
+
return () => {
|
|
23
|
+
fileReader.abort();
|
|
24
|
+
};
|
|
25
|
+
}, [file]);
|
|
26
|
+
const shouldShowPreview = file ? isImageType(file) : false;
|
|
27
|
+
return {
|
|
28
|
+
previewSrc,
|
|
29
|
+
shouldShowPreview,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { usePreviewImage };
|
|
34
|
+
//# sourceMappingURL=usePreviewImage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePreviewImage.js","sources":["../../../../../src/components/UploadFile/hooks/usePreviewImage/usePreviewImage.ts"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport { isImageType } from '../../utils/isImageType';\n\ntype UsePreviewImageProps = {\n file?: File | null;\n};\n\nexport const usePreviewImage = ({ file }: UsePreviewImageProps) => {\n const [previewSrc, setPreviewSrc] = useState('');\n\n useEffect(() => {\n if (!file) {\n setPreviewSrc('');\n return undefined;\n }\n\n if (!isImageType(file)) {\n setPreviewSrc('');\n return undefined;\n }\n\n const fileReader = new FileReader();\n\n fileReader.onload = (event) => {\n const imageUrl = event.target?.result;\n setPreviewSrc(String(imageUrl));\n };\n\n fileReader.readAsDataURL(file);\n\n return () => {\n fileReader.abort();\n };\n }, [file]);\n\n const shouldShowPreview = file ? isImageType(file) : false;\n\n return {\n previewSrc,\n shouldShowPreview,\n };\n};\n"],"names":[],"mappings":";;;MAOa,eAAe,GAAG,CAAC,EAAE,IAAI,EAAwB,KAAI;IAChE,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC;IAEhD,SAAS,CAAC,MAAK;QACb,IAAI,CAAC,IAAI,EAAE;YACT,aAAa,CAAC,EAAE,CAAC;AACjB,YAAA,OAAO,SAAS;AACjB;AAED,QAAA,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE;YACtB,aAAa,CAAC,EAAE,CAAC;AACjB,YAAA,OAAO,SAAS;AACjB;AAED,QAAA,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE;AAEnC,QAAA,UAAU,CAAC,MAAM,GAAG,CAAC,KAAK,KAAI;;YAC5B,MAAM,QAAQ,GAAG,CAAA,EAAA,GAAA,KAAK,CAAC,MAAM,MAAA,IAAA,IAAA,EAAA,KAAA,SAAA,GAAA,SAAA,GAAA,EAAA,CAAE,MAAM;AACrC,YAAA,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACjC,SAAC;AAED,QAAA,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC;AAE9B,QAAA,OAAO,MAAK;YACV,UAAU,CAAC,KAAK,EAAE;AACpB,SAAC;AACH,KAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AAEV,IAAA,MAAM,iBAAiB,GAAG,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,KAAK;IAE1D,OAAO;QACL,UAAU;QACV,iBAAiB;KAClB;AACH;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useUploadFile } from './useUploadFile';
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
|
|
5
|
+
const useUploadFile = () => {
|
|
6
|
+
const inputRef = React.useRef(null);
|
|
7
|
+
const [fileList, setFileList] = React.useState();
|
|
8
|
+
// Keep inputRef.current.files in sync with fileList
|
|
9
|
+
React.useEffect(() => {
|
|
10
|
+
if (inputRef.current && fileList) {
|
|
11
|
+
// Only update if not already the same (avoid unnecessary assignment)
|
|
12
|
+
if (inputRef.current.files !== fileList) {
|
|
13
|
+
const dt = new DataTransfer();
|
|
14
|
+
Array.from(fileList).forEach((file) => dt.items.add(file));
|
|
15
|
+
inputRef.current.files = dt.files;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
// If fileList is undefined, clear the input
|
|
19
|
+
if (inputRef.current && !fileList) {
|
|
20
|
+
inputRef.current.value = '';
|
|
21
|
+
}
|
|
22
|
+
}, [fileList, inputRef]);
|
|
23
|
+
// Restores the previous file selection when user cancels the file dialog
|
|
24
|
+
const onCancel = React.useCallback(() => {
|
|
25
|
+
// If there are no existing files to restore, just return
|
|
26
|
+
if (!fileList || fileList.length === 0)
|
|
27
|
+
return;
|
|
28
|
+
const newFileList = new DataTransfer();
|
|
29
|
+
Array.from(fileList).forEach((file) => newFileList.items.add(file));
|
|
30
|
+
if (inputRef === null || inputRef === undefined ? undefined : inputRef.current) {
|
|
31
|
+
inputRef.current.files = newFileList.files;
|
|
32
|
+
}
|
|
33
|
+
}, [fileList]);
|
|
34
|
+
const removeFileFromList = (fileToRemove) => {
|
|
35
|
+
if (!fileList)
|
|
36
|
+
return;
|
|
37
|
+
const newFileList = new DataTransfer();
|
|
38
|
+
Array.from(fileList).forEach((file) => {
|
|
39
|
+
if (file.name === fileToRemove.name)
|
|
40
|
+
return; // Skip this file (remove it)
|
|
41
|
+
newFileList.items.add(file);
|
|
42
|
+
});
|
|
43
|
+
if (inputRef === null || inputRef === undefined ? undefined : inputRef.current) {
|
|
44
|
+
inputRef.current.files = newFileList.files;
|
|
45
|
+
}
|
|
46
|
+
setFileList(newFileList.files);
|
|
47
|
+
};
|
|
48
|
+
const clearFileSelection = () => {
|
|
49
|
+
var _a;
|
|
50
|
+
if ((_a = inputRef.current) === null || _a === undefined ? undefined : _a.value)
|
|
51
|
+
inputRef.current.value = '';
|
|
52
|
+
setFileList(undefined);
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
clearFileSelection,
|
|
56
|
+
inputRef,
|
|
57
|
+
onCancel,
|
|
58
|
+
removeFileFromList,
|
|
59
|
+
setFileList,
|
|
60
|
+
fileList,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
exports.useUploadFile = useUploadFile;
|
|
65
|
+
//# sourceMappingURL=useUploadFile.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUploadFile.cjs","sources":["../../../../../src/components/UploadFile/hooks/useUploadFile/useUploadFile.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nexport const useUploadFile = () => {\n const inputRef = useRef<HTMLInputElement | null>(null);\n\n const [fileList, setFileList] = useState<FileList>();\n\n // Keep inputRef.current.files in sync with fileList\n useEffect(() => {\n if (inputRef.current && fileList) {\n // Only update if not already the same (avoid unnecessary assignment)\n if (inputRef.current.files !== fileList) {\n const dt = new DataTransfer();\n Array.from(fileList).forEach((file) => dt.items.add(file));\n inputRef.current.files = dt.files;\n }\n }\n // If fileList is undefined, clear the input\n if (inputRef.current && !fileList) {\n inputRef.current.value = '';\n }\n }, [fileList, inputRef]);\n\n // Restores the previous file selection when user cancels the file dialog\n const onCancel = useCallback(() => {\n // If there are no existing files to restore, just return\n if (!fileList || fileList.length === 0) return;\n\n const newFileList = new DataTransfer();\n Array.from(fileList).forEach((file) => newFileList.items.add(file));\n\n if (inputRef?.current) {\n inputRef.current.files = newFileList.files;\n }\n }, [fileList]);\n\n const removeFileFromList = (fileToRemove: File) => {\n if (!fileList) return;\n\n const newFileList = new DataTransfer();\n Array.from(fileList).forEach((file) => {\n if (file.name === fileToRemove.name) return; // Skip this file (remove it)\n newFileList.items.add(file);\n });\n\n if (inputRef?.current) {\n inputRef.current.files = newFileList.files;\n }\n setFileList(newFileList.files);\n };\n\n const clearFileSelection = () => {\n if (inputRef.current?.value) inputRef.current.value = '';\n setFileList(undefined);\n };\n\n return {\n clearFileSelection,\n inputRef,\n onCancel,\n removeFileFromList,\n setFileList,\n fileList,\n };\n};\n"],"names":["useRef","useState","useEffect","useCallback"],"mappings":";;;;AAEO,MAAM,aAAa,GAAG,MAAK;AAChC,IAAA,MAAM,QAAQ,GAAGA,YAAM,CAA0B,IAAI,CAAC;IAEtD,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAGC,cAAQ,EAAY;;IAGpDC,eAAS,CAAC,MAAK;AACb,QAAA,IAAI,QAAQ,CAAC,OAAO,IAAI,QAAQ,EAAE;;AAEhC,YAAA,IAAI,QAAQ,CAAC,OAAO,CAAC,KAAK,KAAK,QAAQ,EAAE;AACvC,gBAAA,MAAM,EAAE,GAAG,IAAI,YAAY,EAAE;gBAC7B,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,KA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A,IAAA,QAAQ,6BAAR,QAAQ,CAAE,OAAO,EAAE;YACrB,QAAQ,CAAC,OAAO,CAAC,KAAK,GAAG,WAAW,CAAC,KAAK;AAC3C;AACD,QAAA,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC;AAChC,KAAC;IAED,MAAM,kBAAkB,GAAG,MAAK;;AAC9B,QAAA,IAAI,CAAA,EAAA,GAAA,QAAQ,CAAC,OAAO,gDAAE,KAAK;AAAE,YAAA,QAAQ,CAAC,OAAO,CAAC,KAAK,GAAG,EAAE;QACxD,WAAW,CAAC,SAAS,CAAC;AACxB,KAAC;IAED,OAAO;QACL,kBAAkB;QAClB,QAAQ;QACR,QAAQ;QACR,kBAAkB;QAClB,WAAW;QACX,QAAQ;KACT;AACH;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const useUploadFile: () => {
|
|
3
|
+
clearFileSelection: () => void;
|
|
4
|
+
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
5
|
+
onCancel: () => void;
|
|
6
|
+
removeFileFromList: (fileToRemove: File) => void;
|
|
7
|
+
setFileList: import("react").Dispatch<import("react").SetStateAction<FileList | undefined>>;
|
|
8
|
+
fileList: FileList | undefined;
|
|
9
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useRef, useState, useEffect, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
const useUploadFile = () => {
|
|
4
|
+
const inputRef = useRef(null);
|
|
5
|
+
const [fileList, setFileList] = useState();
|
|
6
|
+
// Keep inputRef.current.files in sync with fileList
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (inputRef.current && fileList) {
|
|
9
|
+
// Only update if not already the same (avoid unnecessary assignment)
|
|
10
|
+
if (inputRef.current.files !== fileList) {
|
|
11
|
+
const dt = new DataTransfer();
|
|
12
|
+
Array.from(fileList).forEach((file) => dt.items.add(file));
|
|
13
|
+
inputRef.current.files = dt.files;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// If fileList is undefined, clear the input
|
|
17
|
+
if (inputRef.current && !fileList) {
|
|
18
|
+
inputRef.current.value = '';
|
|
19
|
+
}
|
|
20
|
+
}, [fileList, inputRef]);
|
|
21
|
+
// Restores the previous file selection when user cancels the file dialog
|
|
22
|
+
const onCancel = useCallback(() => {
|
|
23
|
+
// If there are no existing files to restore, just return
|
|
24
|
+
if (!fileList || fileList.length === 0)
|
|
25
|
+
return;
|
|
26
|
+
const newFileList = new DataTransfer();
|
|
27
|
+
Array.from(fileList).forEach((file) => newFileList.items.add(file));
|
|
28
|
+
if (inputRef === null || inputRef === undefined ? undefined : inputRef.current) {
|
|
29
|
+
inputRef.current.files = newFileList.files;
|
|
30
|
+
}
|
|
31
|
+
}, [fileList]);
|
|
32
|
+
const removeFileFromList = (fileToRemove) => {
|
|
33
|
+
if (!fileList)
|
|
34
|
+
return;
|
|
35
|
+
const newFileList = new DataTransfer();
|
|
36
|
+
Array.from(fileList).forEach((file) => {
|
|
37
|
+
if (file.name === fileToRemove.name)
|
|
38
|
+
return; // Skip this file (remove it)
|
|
39
|
+
newFileList.items.add(file);
|
|
40
|
+
});
|
|
41
|
+
if (inputRef === null || inputRef === undefined ? undefined : inputRef.current) {
|
|
42
|
+
inputRef.current.files = newFileList.files;
|
|
43
|
+
}
|
|
44
|
+
setFileList(newFileList.files);
|
|
45
|
+
};
|
|
46
|
+
const clearFileSelection = () => {
|
|
47
|
+
var _a;
|
|
48
|
+
if ((_a = inputRef.current) === null || _a === undefined ? undefined : _a.value)
|
|
49
|
+
inputRef.current.value = '';
|
|
50
|
+
setFileList(undefined);
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
clearFileSelection,
|
|
54
|
+
inputRef,
|
|
55
|
+
onCancel,
|
|
56
|
+
removeFileFromList,
|
|
57
|
+
setFileList,
|
|
58
|
+
fileList,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export { useUploadFile };
|
|
63
|
+
//# sourceMappingURL=useUploadFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUploadFile.js","sources":["../../../../../src/components/UploadFile/hooks/useUploadFile/useUploadFile.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nexport const useUploadFile = () => {\n const inputRef = useRef<HTMLInputElement | null>(null);\n\n const [fileList, setFileList] = useState<FileList>();\n\n // Keep inputRef.current.files in sync with fileList\n useEffect(() => {\n if (inputRef.current && fileList) {\n // Only update if not already the same (avoid unnecessary assignment)\n if (inputRef.current.files !== fileList) {\n const dt = new DataTransfer();\n Array.from(fileList).forEach((file) => dt.items.add(file));\n inputRef.current.files = dt.files;\n }\n }\n // If fileList is undefined, clear the input\n if (inputRef.current && !fileList) {\n inputRef.current.value = '';\n }\n }, [fileList, inputRef]);\n\n // Restores the previous file selection when user cancels the file dialog\n const onCancel = useCallback(() => {\n // If there are no existing files to restore, just return\n if (!fileList || fileList.length === 0) return;\n\n const newFileList = new DataTransfer();\n Array.from(fileList).forEach((file) => newFileList.items.add(file));\n\n if (inputRef?.current) {\n inputRef.current.files = newFileList.files;\n }\n }, [fileList]);\n\n const removeFileFromList = (fileToRemove: File) => {\n if (!fileList) return;\n\n const newFileList = new DataTransfer();\n Array.from(fileList).forEach((file) => {\n if (file.name === fileToRemove.name) return; // Skip this file (remove it)\n newFileList.items.add(file);\n });\n\n if (inputRef?.current) {\n inputRef.current.files = newFileList.files;\n }\n setFileList(newFileList.files);\n };\n\n const clearFileSelection = () => {\n if (inputRef.current?.value) inputRef.current.value = '';\n setFileList(undefined);\n };\n\n return {\n clearFileSelection,\n inputRef,\n onCancel,\n removeFileFromList,\n setFileList,\n fileList,\n };\n};\n"],"names":[],"mappings":";;AAEO,MAAM,aAAa,GAAG,MAAK;AAChC,IAAA,MAAM,QAAQ,GAAG,MAAM,CAA0B,IAAI,CAAC;IAEtD,MAAM,CAAC,QAAQ,EAAE,WAAW,C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AW,GAAG,IAAI,YAAY,EAAE;QACtC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,KAAI;AACpC,YAAA,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC,IAAI;AAAE,gBAAA,OAAO;AAC5C,YAAA,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;AAC7B,SAAC,CAAC;AAEF,QAAA,IAAI,QAAQ,KAAR,IAAA,IAAA,QAAQ,6BAAR,QAAQ,CAAE,OAAO,EAAE;YACrB,QAAQ,CAAC,OAAO,CAAC,KAAK,GAAG,WAAW,CAAC,KAAK;AAC3C;AACD,QAAA,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC;AAChC,KAAC;IAED,MAAM,kBAAkB,GAAG,MAAK;;AAC9B,QAAA,IAAI,CAAA,EAAA,GAAA,QAAQ,CAAC,OAAO,gDAAE,KAAK;AAAE,YAAA,QAAQ,CAAC,OAAO,CAAC,KAAK,GAAG,EAAE;QACxD,WAAW,CAAC,SAAS,CAAC;AACxB,KAAC;IAED,OAAO;QACL,kBAAkB;QAClB,QAAQ;QACR,QAAQ;QACR,kBAAkB;QAClB,WAAW;QACX,QAAQ;KACT;AACH;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useValidateInput } from './useValidateInput';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var constants = require('../../constants.cjs');
|
|
5
|
+
|
|
6
|
+
const useValidateInput = ({ fileList, fileTypes, inputRef, maxBytes, }) => {
|
|
7
|
+
// Tracks error states within the input element itself, using preset
|
|
8
|
+
// error messages and assigns these to the input component based on the file
|
|
9
|
+
const setInputValidation = React.useCallback(() => {
|
|
10
|
+
var _a, _b, _c, _d;
|
|
11
|
+
let errorMessage = constants.InputErrorStateMessages.VALID;
|
|
12
|
+
if (!((_b = (_a = inputRef.current) === null || _a === undefined ? undefined : _a.files) === null || _b === undefined ? undefined : _b.length)) {
|
|
13
|
+
(_c = inputRef.current) === null || _c === undefined ? undefined : _c.setCustomValidity(errorMessage);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const results = {
|
|
17
|
+
numberOfInvalidFormatFiles: 0,
|
|
18
|
+
numberOfInvalidSizeFiles: 0,
|
|
19
|
+
totalFiles: inputRef.current.files.length,
|
|
20
|
+
};
|
|
21
|
+
Array.from(inputRef.current.files).forEach((file) => {
|
|
22
|
+
// Check file size
|
|
23
|
+
if (file.size > maxBytes) {
|
|
24
|
+
results.numberOfInvalidSizeFiles += 1;
|
|
25
|
+
}
|
|
26
|
+
// Check file type/format
|
|
27
|
+
const [, extension] = file.type.split('/');
|
|
28
|
+
const isTypeValid = fileTypes.find((validType) => validType.substring(1) === extension);
|
|
29
|
+
if (!isTypeValid) {
|
|
30
|
+
results.numberOfInvalidFormatFiles += 1;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
// Determine appropriate error message based on validation results
|
|
34
|
+
const hasFormatErrors = results.numberOfInvalidFormatFiles > 0;
|
|
35
|
+
const hasSizeErrors = results.numberOfInvalidSizeFiles > 0;
|
|
36
|
+
const isSingleFile = results.totalFiles === 1;
|
|
37
|
+
if (hasFormatErrors && hasSizeErrors) {
|
|
38
|
+
// Both format and size errors exist
|
|
39
|
+
errorMessage = constants.InputErrorStateMessages.INVALID_FORMAT_AND_SIZE;
|
|
40
|
+
}
|
|
41
|
+
else if (hasFormatErrors && !hasSizeErrors) {
|
|
42
|
+
// Only format errors
|
|
43
|
+
if (isSingleFile) {
|
|
44
|
+
errorMessage = constants.InputErrorStateMessages.INVALID_FORMAT;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
errorMessage = constants.InputErrorStateMessages.INVALID_FORMATS;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else if (!hasFormatErrors && hasSizeErrors) {
|
|
51
|
+
// Only size errors
|
|
52
|
+
if (isSingleFile) {
|
|
53
|
+
errorMessage = constants.InputErrorStateMessages.INVALID_SIZE;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
errorMessage = constants.InputErrorStateMessages.INVALID_SIZES;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// If no errors, errorMessage remains VALID
|
|
60
|
+
(_d = inputRef.current) === null || _d === undefined ? undefined : _d.setCustomValidity(errorMessage);
|
|
61
|
+
}, [inputRef, maxBytes, fileTypes]);
|
|
62
|
+
// Validate input whenever fileList changes
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
setInputValidation();
|
|
65
|
+
}, [fileList, setInputValidation]);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
exports.useValidateInput = useValidateInput;
|
|
69
|
+
//# sourceMappingURL=useValidateInput.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useValidateInput.cjs","sources":["../../../../../src/components/UploadFile/hooks/useValidateInput/useValidateInput.ts"],"sourcesContent":["import { useEffect, useCallback } from 'react';\nimport { AcceptedFileTypes, InputErrorStateMessages } from '../../constants';\n\ntype UseValidateInputProps = {\n fileTypes: Array<AcceptedFileTypes>;\n maxBytes: number;\n fileList: FileList | undefined;\n inputRef: React.MutableRefObject<HTMLInputElement | null>;\n};\n\nexport const useValidateInput = ({\n fileList,\n fileTypes,\n inputRef,\n maxBytes,\n}: UseValidateInputProps) => {\n // Tracks error states within the input element itself, using preset\n // error messages and assigns these to the input component based on the file\n const setInputValidation = useCallback(() => {\n let errorMessage = InputErrorStateMessages.VALID;\n\n if (!inputRef.current?.files?.length) {\n inputRef.current?.setCustomValidity(errorMessage);\n return;\n }\n\n const results = {\n numberOfInvalidFormatFiles: 0,\n numberOfInvalidSizeFiles: 0,\n totalFiles: inputRef.current.files.length,\n };\n\n Array.from(inputRef.current.files).forEach((file) => {\n // Check file size\n if (file.size > maxBytes) {\n results.numberOfInvalidSizeFiles += 1;\n }\n\n // Check file type/format\n const [, extension] = file.type.split('/');\n const isTypeValid = fileTypes.find((validType) => validType.substring(1) === extension);\n if (!isTypeValid) {\n results.numberOfInvalidFormatFiles += 1;\n }\n });\n\n // Determine appropriate error message based on validation results\n const hasFormatErrors = results.numberOfInvalidFormatFiles > 0;\n const hasSizeErrors = results.numberOfInvalidSizeFiles > 0;\n const isSingleFile = results.totalFiles === 1;\n\n if (hasFormatErrors && hasSizeErrors) {\n // Both format and size errors exist\n errorMessage = InputErrorStateMessages.INVALID_FORMAT_AND_SIZE;\n } else if (hasFormatErrors && !hasSizeErrors) {\n // Only format errors\n if (isSingleFile) {\n errorMessage = InputErrorStateMessages.INVALID_FORMAT;\n } else {\n errorMessage = InputErrorStateMessages.INVALID_FORMATS;\n }\n } else if (!hasFormatErrors && hasSizeErrors) {\n // Only size errors\n if (isSingleFile) {\n errorMessage = InputErrorStateMessages.INVALID_SIZE;\n } else {\n errorMessage = InputErrorStateMessages.INVALID_SIZES;\n }\n }\n // If no errors, errorMessage remains VALID\n\n inputRef.current?.setCustomValidity(errorMessage);\n }, [inputRef, maxBytes, fileTypes]);\n\n // Validate input whenever fileList changes\n useEffect(() => {\n setInputValidation();\n }, [fileList, setInputValidation]);\n};\n"],"names":["useCallback","InputErrorStateMessages","useEffect"],"mappings":";;;;;AAUO,MAAM,gBAAgB,GAAG,CAAC,EAC/B,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAQ,GACc,KAAI;;;AAG1B,IAAA,MAAM,kBAAkB,GAAGA,iBAAW,CAAC,MAAK;;AAC1C,QAAA,IAAI,YAAY,GAAGC,iCAAuB,CAAC,KAAK;AAEhD,QAAA,IAAI,EAAC,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,QAAQ,CAAC,OAAO,MAAA,IAAA,IAAA,EAAA,KAAA,SAAA,GAAA,SAAA,GAAA,EAAA,CAAE,KAAK,MAAA,IAAA,IAAA,EAAA,KAAA,SAAA,GAAA,SAAA,GAAA,EAAA,CAAE,MAAM,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A,YAAY,GAAGA,iCAAuB,CAAC,cAAc;AACtD;AAAM,iBAAA;AACL,gBAAA,YAAY,GAAGA,iCAAuB,CAAC,eAAe;AACvD;AACF;AAAM,aAAA,IAAI,CAAC,eAAe,IAAI,aAAa,EAAE;;AAE5C,YAAA,IAAI,YAAY,EAAE;AAChB,gBAAA,YAAY,GAAGA,iCAAuB,CAAC,YAAY;AACpD;AAAM,iBAAA;AACL,gBAAA,YAAY,GAAGA,iCAAuB,CAAC,aAAa;AACrD;AACF;;QAGD,CAAA,EAAA,GAAA,QAAQ,CAAC,OAAO,MAAA,IAAA,IAAA,EAAA,KAAA,SAAA,GAAA,SAAA,GAAA,EAAA,CAAE,iBAAiB,CAAC,YAAY,CAAC;KAClD,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;;IAGnCC,eAAS,CAAC,MAAK;AACb,QAAA,kBAAkB,EAAE;AACtB,KAAC,EAAE,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;AACpC;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { AcceptedFileTypes } from '../../constants';
|
|
3
|
+
type UseValidateInputProps = {
|
|
4
|
+
fileTypes: Array<AcceptedFileTypes>;
|
|
5
|
+
maxBytes: number;
|
|
6
|
+
fileList: FileList | undefined;
|
|
7
|
+
inputRef: React.MutableRefObject<HTMLInputElement | null>;
|
|
8
|
+
};
|
|
9
|
+
export declare const useValidateInput: ({ fileList, fileTypes, inputRef, maxBytes, }: UseValidateInputProps) => void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useCallback, useEffect } from 'react';
|
|
2
|
+
import { InputErrorStateMessages } from '../../constants.js';
|
|
3
|
+
|
|
4
|
+
const useValidateInput = ({ fileList, fileTypes, inputRef, maxBytes, }) => {
|
|
5
|
+
// Tracks error states within the input element itself, using preset
|
|
6
|
+
// error messages and assigns these to the input component based on the file
|
|
7
|
+
const setInputValidation = useCallback(() => {
|
|
8
|
+
var _a, _b, _c, _d;
|
|
9
|
+
let errorMessage = InputErrorStateMessages.VALID;
|
|
10
|
+
if (!((_b = (_a = inputRef.current) === null || _a === undefined ? undefined : _a.files) === null || _b === undefined ? undefined : _b.length)) {
|
|
11
|
+
(_c = inputRef.current) === null || _c === undefined ? undefined : _c.setCustomValidity(errorMessage);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const results = {
|
|
15
|
+
numberOfInvalidFormatFiles: 0,
|
|
16
|
+
numberOfInvalidSizeFiles: 0,
|
|
17
|
+
totalFiles: inputRef.current.files.length,
|
|
18
|
+
};
|
|
19
|
+
Array.from(inputRef.current.files).forEach((file) => {
|
|
20
|
+
// Check file size
|
|
21
|
+
if (file.size > maxBytes) {
|
|
22
|
+
results.numberOfInvalidSizeFiles += 1;
|
|
23
|
+
}
|
|
24
|
+
// Check file type/format
|
|
25
|
+
const [, extension] = file.type.split('/');
|
|
26
|
+
const isTypeValid = fileTypes.find((validType) => validType.substring(1) === extension);
|
|
27
|
+
if (!isTypeValid) {
|
|
28
|
+
results.numberOfInvalidFormatFiles += 1;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
// Determine appropriate error message based on validation results
|
|
32
|
+
const hasFormatErrors = results.numberOfInvalidFormatFiles > 0;
|
|
33
|
+
const hasSizeErrors = results.numberOfInvalidSizeFiles > 0;
|
|
34
|
+
const isSingleFile = results.totalFiles === 1;
|
|
35
|
+
if (hasFormatErrors && hasSizeErrors) {
|
|
36
|
+
// Both format and size errors exist
|
|
37
|
+
errorMessage = InputErrorStateMessages.INVALID_FORMAT_AND_SIZE;
|
|
38
|
+
}
|
|
39
|
+
else if (hasFormatErrors && !hasSizeErrors) {
|
|
40
|
+
// Only format errors
|
|
41
|
+
if (isSingleFile) {
|
|
42
|
+
errorMessage = InputErrorStateMessages.INVALID_FORMAT;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
errorMessage = InputErrorStateMessages.INVALID_FORMATS;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else if (!hasFormatErrors && hasSizeErrors) {
|
|
49
|
+
// Only size errors
|
|
50
|
+
if (isSingleFile) {
|
|
51
|
+
errorMessage = InputErrorStateMessages.INVALID_SIZE;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
errorMessage = InputErrorStateMessages.INVALID_SIZES;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// If no errors, errorMessage remains VALID
|
|
58
|
+
(_d = inputRef.current) === null || _d === undefined ? undefined : _d.setCustomValidity(errorMessage);
|
|
59
|
+
}, [inputRef, maxBytes, fileTypes]);
|
|
60
|
+
// Validate input whenever fileList changes
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
setInputValidation();
|
|
63
|
+
}, [fileList, setInputValidation]);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export { useValidateInput };
|
|
67
|
+
//# sourceMappingURL=useValidateInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useValidateInput.js","sources":["../../../../../src/components/UploadFile/hooks/useValidateInput/useValidateInput.ts"],"sourcesContent":["import { useEffect, useCallback } from 'react';\nimport { AcceptedFileTypes, InputErrorStateMessages } from '../../constants';\n\ntype UseValidateInputProps = {\n fileTypes: Array<AcceptedFileTypes>;\n maxBytes: number;\n fileList: FileList | undefined;\n inputRef: React.MutableRefObject<HTMLInputElement | null>;\n};\n\nexport const useValidateInput = ({\n fileList,\n fileTypes,\n inputRef,\n maxBytes,\n}: UseValidateInputProps) => {\n // Tracks error states within the input element itself, using preset\n // error messages and assigns these to the input component based on the file\n const setInputValidation = useCallback(() => {\n let errorMessage = InputErrorStateMessages.VALID;\n\n if (!inputRef.current?.files?.length) {\n inputRef.current?.setCustomValidity(errorMessage);\n return;\n }\n\n const results = {\n numberOfInvalidFormatFiles: 0,\n numberOfInvalidSizeFiles: 0,\n totalFiles: inputRef.current.files.length,\n };\n\n Array.from(inputRef.current.files).forEach((file) => {\n // Check file size\n if (file.size > maxBytes) {\n results.numberOfInvalidSizeFiles += 1;\n }\n\n // Check file type/format\n const [, extension] = file.type.split('/');\n const isTypeValid = fileTypes.find((validType) => validType.substring(1) === extension);\n if (!isTypeValid) {\n results.numberOfInvalidFormatFiles += 1;\n }\n });\n\n // Determine appropriate error message based on validation results\n const hasFormatErrors = results.numberOfInvalidFormatFiles > 0;\n const hasSizeErrors = results.numberOfInvalidSizeFiles > 0;\n const isSingleFile = results.totalFiles === 1;\n\n if (hasFormatErrors && hasSizeErrors) {\n // Both format and size errors exist\n errorMessage = InputErrorStateMessages.INVALID_FORMAT_AND_SIZE;\n } else if (hasFormatErrors && !hasSizeErrors) {\n // Only format errors\n if (isSingleFile) {\n errorMessage = InputErrorStateMessages.INVALID_FORMAT;\n } else {\n errorMessage = InputErrorStateMessages.INVALID_FORMATS;\n }\n } else if (!hasFormatErrors && hasSizeErrors) {\n // Only size errors\n if (isSingleFile) {\n errorMessage = InputErrorStateMessages.INVALID_SIZE;\n } else {\n errorMessage = InputErrorStateMessages.INVALID_SIZES;\n }\n }\n // If no errors, errorMessage remains VALID\n\n inputRef.current?.setCustomValidity(errorMessage);\n }, [inputRef, maxBytes, fileTypes]);\n\n // Validate input whenever fileList changes\n useEffect(() => {\n setInputValidation();\n }, [fileList, setInputValidation]);\n};\n"],"names":[],"mappings":";;;AAUO,MAAM,gBAAgB,GAAG,CAAC,EAC/B,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAQ,GACc,KAAI;;;AAG1B,IAAA,MAAM,kBAAkB,GAAG,WAAW,CAAC,MAAK;;AAC1C,QAAA,IAAI,YAAY,GAAG,uBAAuB,CAAC,KAAK;AAEhD,QAAA,IAAI,EAAC,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,QAAQ,CAAC,OAAO,MAAA,IAAA,IAAA,EAAA,KAAA,SAAA,GAAA,SAAA,GAAA,EAAA,CAAE,KAAK,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Ae,IAAI,CAAC,aAAa,EAAE;;AAE5C,YAAA,IAAI,YAAY,EAAE;AAChB,gBAAA,YAAY,GAAG,uBAAuB,CAAC,cAAc;AACtD;AAAM,iBAAA;AACL,gBAAA,YAAY,GAAG,uBAAuB,CAAC,eAAe;AACvD;AACF;AAAM,aAAA,IAAI,CAAC,eAAe,IAAI,aAAa,EAAE;;AAE5C,YAAA,IAAI,YAAY,EAAE;AAChB,gBAAA,YAAY,GAAG,uBAAuB,CAAC,YAAY;AACpD;AAAM,iBAAA;AACL,gBAAA,YAAY,GAAG,uBAAuB,CAAC,aAAa;AACrD;AACF;;QAGD,CAAA,EAAA,GAAA,QAAQ,CAAC,OAAO,MAAA,IAAA,IAAA,EAAA,KAAA,SAAA,GAAA,SAAA,GAAA,EAAA,CAAE,iBAAiB,CAAC,YAAY,CAAC;KAClD,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;;IAGnC,SAAS,CAAC,MAAK;AACb,QAAA,kBAAkB,EAAE;AACtB,KAAC,EAAE,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;AACpC;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
export declare const mockUseRemoveUploadFile: () => {
|
|
3
|
+
mockRemoveFileFromList: jest.Mock<any, any, any>;
|
|
4
|
+
};
|
|
5
|
+
export declare const mockUseUploadFile: () => {
|
|
6
|
+
mockRemoveFileFromList: jest.Mock<any, any, any>;
|
|
7
|
+
mockClearFileSelection: jest.Mock<any, any, any>;
|
|
8
|
+
mockInputRef: {
|
|
9
|
+
current: null;
|
|
10
|
+
};
|
|
11
|
+
mockOnCancel: jest.Mock<any, any, any>;
|
|
12
|
+
mockSetFileList: jest.Mock<any, any, any>;
|
|
13
|
+
mockFileList: undefined;
|
|
14
|
+
};
|
|
@@ -4,7 +4,6 @@ type MockHelperProps = {
|
|
|
4
4
|
};
|
|
5
5
|
export declare const mockDrop: ({ file, label }: MockHelperProps) => void;
|
|
6
6
|
export declare const mockDragOver: ({ file, label }: MockHelperProps) => void;
|
|
7
|
-
export declare const getDefaultInput: () =>
|
|
7
|
+
export declare const getDefaultInput: () => HTMLInputElement;
|
|
8
8
|
export declare const getStyledDropzoneContainer: () => HTMLElement;
|
|
9
|
-
export declare const getUploadGraphic: () => HTMLElement;
|
|
10
9
|
export {};
|
|
@@ -9,7 +9,47 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
9
9
|
|
|
10
10
|
var styled__default = /*#__PURE__*/_interopDefaultCompat(styled);
|
|
11
11
|
|
|
12
|
-
const DropZoneContainer = styled__default.default.div.withConfig({ displayName: "vui--DropZoneContainer", componentId: "vui--17v0v3c" }) `display:flex;align-items:center;justify-content:center;padding:${sizes.sizes.
|
|
12
|
+
const DropZoneContainer = styled__default.default.div.withConfig({ displayName: "vui--DropZoneContainer", componentId: "vui--17v0v3c" }) `display:flex;align-items:center;justify-content:center;padding:${sizes.sizes.base};border-radius:${radius.radius.base};input[type='file']{position:absolute;opacity:0;width:1px;height:1px;cursor:pointer;}cursor:pointer;border:2px dashed ${colors.colors.neutral.ink.lightest};background-color:${colors.colors.neutral.grey.lightest};:hover{border:2px dashed ${colors.colors.secondary.blue.base};background-color:${colors.colors.secondary.blue.lightest};svg{color:${colors.colors.secondary.blue.base};}}:active,:focus-within{border:2px dashed ${colors.colors.secondary.blue.base};box-shadow:0 0 0 4px ${colors.colors.secondary.blue.light};background-color:${colors.colors.secondary.blue.lightest};svg{color:${colors.colors.secondary.blue.base};}}${({ isDragOver }) => isDragOver &&
|
|
13
|
+
`
|
|
14
|
+
border: 2px dashed ${colors.colors.secondary.blue.base};
|
|
15
|
+
box-shadow: 0 0 0 4px ${colors.colors.secondary.blue.light};
|
|
16
|
+
background-color: ${colors.colors.secondary.blue.lightest};
|
|
17
|
+
|
|
18
|
+
svg {
|
|
19
|
+
color: ${colors.colors.secondary.blue.base};
|
|
20
|
+
}
|
|
21
|
+
`} ${({ hasUserProvidedNoFiles, isDragOver, isDirty }) => hasUserProvidedNoFiles &&
|
|
22
|
+
isDirty &&
|
|
23
|
+
`
|
|
24
|
+
border: 2px dashed ${colors.colors.secondary.red.base};
|
|
25
|
+
|
|
26
|
+
:hover {
|
|
27
|
+
border: 2px dashed ${colors.colors.secondary.red.base};
|
|
28
|
+
background-color: ${colors.colors.secondary.red.lightest};
|
|
29
|
+
|
|
30
|
+
svg {
|
|
31
|
+
color: ${colors.colors.secondary.red.base};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
:active, :focus-within {
|
|
36
|
+
border: 2px dashed ${colors.colors.secondary.red.base};
|
|
37
|
+
box-shadow: 0 0 0 4px ${colors.colors.secondary.red.light};
|
|
38
|
+
background-color: ${colors.colors.secondary.red.lightest};
|
|
39
|
+
|
|
40
|
+
svg {
|
|
41
|
+
color: ${colors.colors.secondary.red.base};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
${isDragOver
|
|
46
|
+
? `
|
|
47
|
+
border: 2px dashed ${colors.colors.secondary.red.base};
|
|
48
|
+
box-shadow: 0 0 0 4px ${colors.colors.secondary.red.light};
|
|
49
|
+
background-color: ${colors.colors.secondary.red.lightest};
|
|
50
|
+
`
|
|
51
|
+
: ''}
|
|
52
|
+
`} &:has(input:disabled){cursor:not-allowed;box-shadow:none;background-color:${colors.colors.neutral.grey.light};border-color:${colors.colors.neutral.ink.lightest};color:${colors.colors.neutral.ink.light};svg{color:${colors.colors.neutral.ink.lightest};}}`;
|
|
13
53
|
|
|
14
54
|
exports.DropZoneContainer = DropZoneContainer;
|
|
15
55
|
//# sourceMappingURL=styled.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styled.cjs","sources":["../../../src/components/UploadFile/styled.tsx"],"sourcesContent":["import styled from 'styled-components';\nimport { colors } from '../../theme/modules/colors';\nimport { radius } from '../../theme/modules/radius';\nimport { sizes } from '../../theme/modules/sizes';\n\nexport const DropZoneContainer = styled.div
|
|
1
|
+
{"version":3,"file":"styled.cjs","sources":["../../../src/components/UploadFile/styled.tsx"],"sourcesContent":["import styled from 'styled-components';\nimport { colors } from '../../theme/modules/colors';\nimport { radius } from '../../theme/modules/radius';\nimport { sizes } from '../../theme/modules/sizes';\n\nexport const DropZoneContainer = styled.div<{\n hasUserProvidedNoFiles: boolean;\n isDirty: boolean;\n isDragOver?: boolean;\n}>`\n display: flex;\n align-items: center;\n justify-content: center;\n\n padding: ${sizes.base};\n border-radius: ${radius.base};\n\n input[type='file'] {\n position: absolute;\n opacity: 0;\n width: 1px;\n height: 1px;\n cursor: pointer;\n }\n\n cursor: pointer;\n\n border: 2px dashed ${colors.neutral.ink.lightest};\n background-color: ${colors.neutral.grey.lightest};\n\n :hover {\n border: 2px dashed ${colors.secondary.blue.base};\n background-color: ${colors.secondary.blue.lightest};\n\n svg {\n color: ${colors.secondary.blue.base};\n }\n }\n :active,\n :focus-within {\n border: 2px dashed ${colors.secondary.blue.base};\n box-shadow: 0 0 0 4px ${colors.secondary.blue.light};\n background-color: ${colors.secondary.blue.lightest};\n\n svg {\n color: ${colors.secondary.blue.base};\n }\n }\n\n ${({ isDragOver }) =>\n isDragOver &&\n `\n border: 2px dashed ${colors.secondary.blue.base};\n box-shadow: 0 0 0 4px ${colors.secondary.blue.light};\n background-color: ${colors.secondary.blue.lightest};\n\n svg {\n color: ${colors.secondary.blue.base};\n }\n `}\n\n ${({ hasUserProvidedNoFiles, isDragOver, isDirty }) =>\n hasUserProvidedNoFiles &&\n isDirty &&\n `\n border: 2px dashed ${colors.secondary.red.base};\n\n :hover {\n border: 2px dashed ${colors.secondary.red.base};\n background-color: ${colors.secondary.red.lightest};\n\n svg {\n color: ${colors.secondary.red.base};\n }\n }\n\n :active, :focus-within {\n border: 2px dashed ${colors.secondary.red.base};\n box-shadow: 0 0 0 4px ${colors.secondary.red.light};\n background-color: ${colors.secondary.red.lightest};\n\n svg {\n color: ${colors.secondary.red.base};\n }\n }\n\n ${\n isDragOver\n ? `\n border: 2px dashed ${colors.secondary.red.base};\n box-shadow: 0 0 0 4px ${colors.secondary.red.light};\n background-color: ${colors.secondary.red.lightest};\n `\n : ''\n }\n `}\n\n\n &:has(input:disabled) {\n cursor: not-allowed;\n box-shadow: none;\n background-color: ${colors.neutral.grey.light};\n border-color: ${colors.neutral.ink.lightest};\n color: ${colors.neutral.ink.light};\n\n svg {\n color: ${colors.neutral.ink.lightest};\n }\n }\n`;\n"],"names":["styled","sizes","radius","colors"],"mappings":";;;;;;;;;;;MAKa,iBAAiB,GAAGA,uBAAM,CAAC,GAAG,sJAS9BC,WAAK,CAAC,IAAI,CACJ,eAAA,EAAAC,aAAM,CAAC,IAAI,CAAA,sHAAA,EAYPC,aAAM,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAC5B,kBAAA,EAAAA,aAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,6BAGzBA,aAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAA,kBAAA,EAC3BA,aAAM,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,cAGvCA,aAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAA,2CAAA,EAKhBA,aAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CACvB,sBAAA,EAAAA,aAAM,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAA,kBAAA,EAC/BA,aAAM,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAGvC,WAAA,EAAAA,aAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,MAIrC,CAAC,EAAE,UAAU,EAAE,KACf,UAAU;AACV,IAAA;AACqB,uBAAA,EAAAA,aAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAA;AACvB,0BAAA,EAAAA,aAAM,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAA;AAC/B,sBAAA,EAAAA,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,OAAO,CAAC,GAAG,CAAC,KAAK,CAGtB,WAAA,EAAAA,aAAM,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ;;;;"}
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
export declare const DropZoneContainer: import("styled-components").StyledComponent<"div", any, {
|
|
1
|
+
export declare const DropZoneContainer: import("styled-components").StyledComponent<"div", any, {
|
|
2
|
+
hasUserProvidedNoFiles: boolean;
|
|
3
|
+
isDirty: boolean;
|
|
4
|
+
isDragOver?: boolean | undefined;
|
|
5
|
+
}, never>;
|
|
@@ -3,7 +3,47 @@ import { colors } from '../../theme/modules/colors.js';
|
|
|
3
3
|
import { radius } from '../../theme/modules/radius.js';
|
|
4
4
|
import { sizes } from '../../theme/modules/sizes.js';
|
|
5
5
|
|
|
6
|
-
const DropZoneContainer = styled.div.withConfig({ displayName: "vui--DropZoneContainer", componentId: "vui--17v0v3c" }) `display:flex;align-items:center;justify-content:center;padding:${sizes.
|
|
6
|
+
const DropZoneContainer = styled.div.withConfig({ displayName: "vui--DropZoneContainer", componentId: "vui--17v0v3c" }) `display:flex;align-items:center;justify-content:center;padding:${sizes.base};border-radius:${radius.base};input[type='file']{position:absolute;opacity:0;width:1px;height:1px;cursor:pointer;}cursor:pointer;border:2px dashed ${colors.neutral.ink.lightest};background-color:${colors.neutral.grey.lightest};:hover{border:2px dashed ${colors.secondary.blue.base};background-color:${colors.secondary.blue.lightest};svg{color:${colors.secondary.blue.base};}}:active,:focus-within{border:2px dashed ${colors.secondary.blue.base};box-shadow:0 0 0 4px ${colors.secondary.blue.light};background-color:${colors.secondary.blue.lightest};svg{color:${colors.secondary.blue.base};}}${({ isDragOver }) => isDragOver &&
|
|
7
|
+
`
|
|
8
|
+
border: 2px dashed ${colors.secondary.blue.base};
|
|
9
|
+
box-shadow: 0 0 0 4px ${colors.secondary.blue.light};
|
|
10
|
+
background-color: ${colors.secondary.blue.lightest};
|
|
11
|
+
|
|
12
|
+
svg {
|
|
13
|
+
color: ${colors.secondary.blue.base};
|
|
14
|
+
}
|
|
15
|
+
`} ${({ hasUserProvidedNoFiles, isDragOver, isDirty }) => hasUserProvidedNoFiles &&
|
|
16
|
+
isDirty &&
|
|
17
|
+
`
|
|
18
|
+
border: 2px dashed ${colors.secondary.red.base};
|
|
19
|
+
|
|
20
|
+
:hover {
|
|
21
|
+
border: 2px dashed ${colors.secondary.red.base};
|
|
22
|
+
background-color: ${colors.secondary.red.lightest};
|
|
23
|
+
|
|
24
|
+
svg {
|
|
25
|
+
color: ${colors.secondary.red.base};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
:active, :focus-within {
|
|
30
|
+
border: 2px dashed ${colors.secondary.red.base};
|
|
31
|
+
box-shadow: 0 0 0 4px ${colors.secondary.red.light};
|
|
32
|
+
background-color: ${colors.secondary.red.lightest};
|
|
33
|
+
|
|
34
|
+
svg {
|
|
35
|
+
color: ${colors.secondary.red.base};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
${isDragOver
|
|
40
|
+
? `
|
|
41
|
+
border: 2px dashed ${colors.secondary.red.base};
|
|
42
|
+
box-shadow: 0 0 0 4px ${colors.secondary.red.light};
|
|
43
|
+
background-color: ${colors.secondary.red.lightest};
|
|
44
|
+
`
|
|
45
|
+
: ''}
|
|
46
|
+
`} &:has(input:disabled){cursor:not-allowed;box-shadow:none;background-color:${colors.neutral.grey.light};border-color:${colors.neutral.ink.lightest};color:${colors.neutral.ink.light};svg{color:${colors.neutral.ink.lightest};}}`;
|
|
7
47
|
|
|
8
48
|
export { DropZoneContainer };
|
|
9
49
|
//# sourceMappingURL=styled.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styled.js","sources":["../../../src/components/UploadFile/styled.tsx"],"sourcesContent":["import styled from 'styled-components';\nimport { colors } from '../../theme/modules/colors';\nimport { radius } from '../../theme/modules/radius';\nimport { sizes } from '../../theme/modules/sizes';\n\nexport const DropZoneContainer = styled.div
|
|
1
|
+
{"version":3,"file":"styled.js","sources":["../../../src/components/UploadFile/styled.tsx"],"sourcesContent":["import styled from 'styled-components';\nimport { colors } from '../../theme/modules/colors';\nimport { radius } from '../../theme/modules/radius';\nimport { sizes } from '../../theme/modules/sizes';\n\nexport const DropZoneContainer = styled.div<{\n hasUserProvidedNoFiles: boolean;\n isDirty: boolean;\n isDragOver?: boolean;\n}>`\n display: flex;\n align-items: center;\n justify-content: center;\n\n padding: ${sizes.base};\n border-radius: ${radius.base};\n\n input[type='file'] {\n position: absolute;\n opacity: 0;\n width: 1px;\n height: 1px;\n cursor: pointer;\n }\n\n cursor: pointer;\n\n border: 2px dashed ${colors.neutral.ink.lightest};\n background-color: ${colors.neutral.grey.lightest};\n\n :hover {\n border: 2px dashed ${colors.secondary.blue.base};\n background-color: ${colors.secondary.blue.lightest};\n\n svg {\n color: ${colors.secondary.blue.base};\n }\n }\n :active,\n :focus-within {\n border: 2px dashed ${colors.secondary.blue.base};\n box-shadow: 0 0 0 4px ${colors.secondary.blue.light};\n background-color: ${colors.secondary.blue.lightest};\n\n svg {\n color: ${colors.secondary.blue.base};\n }\n }\n\n ${({ isDragOver }) =>\n isDragOver &&\n `\n border: 2px dashed ${colors.secondary.blue.base};\n box-shadow: 0 0 0 4px ${colors.secondary.blue.light};\n background-color: ${colors.secondary.blue.lightest};\n\n svg {\n color: ${colors.secondary.blue.base};\n }\n `}\n\n ${({ hasUserProvidedNoFiles, isDragOver, isDirty }) =>\n hasUserProvidedNoFiles &&\n isDirty &&\n `\n border: 2px dashed ${colors.secondary.red.base};\n\n :hover {\n border: 2px dashed ${colors.secondary.red.base};\n background-color: ${colors.secondary.red.lightest};\n\n svg {\n color: ${colors.secondary.red.base};\n }\n }\n\n :active, :focus-within {\n border: 2px dashed ${colors.secondary.red.base};\n box-shadow: 0 0 0 4px ${colors.secondary.red.light};\n background-color: ${colors.secondary.red.lightest};\n\n svg {\n color: ${colors.secondary.red.base};\n }\n }\n\n ${\n isDragOver\n ? `\n border: 2px dashed ${colors.secondary.red.base};\n box-shadow: 0 0 0 4px ${colors.secondary.red.light};\n background-color: ${colors.secondary.red.lightest};\n `\n : ''\n }\n `}\n\n\n &:has(input:disabled) {\n cursor: not-allowed;\n box-shadow: none;\n background-color: ${colors.neutral.grey.light};\n border-color: ${colors.neutral.ink.lightest};\n color: ${colors.neutral.ink.light};\n\n svg {\n color: ${colors.neutral.ink.lightest};\n }\n }\n`;\n"],"names":[],"mappings":";;;;;MAKa,iBAAiB,GAAG,MAAM,CAAC,GAAG,sJAS9B,KAAK,CAAC,IAAI,CACJ,eAAA,EAAA,MAAM,CAAC,IAAI,CAAA,sHAAA,EAYP,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAC5B,kBAAA,EAAA,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,6BAGzB,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAA,kBAAA,EAC3B,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,cAGvC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAA,2CAAA,EAKhB,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CACvB,sBAAA,EAAA,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAA,kBAAA,EAC/B,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAGvC,WAAA,EAAA,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,MAIrC,CAAC,EAAE,UAAU,EAAE,KACf,UAAU;AACV,IAAA;AACqB,uBAAA,EAAA,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAA;AACvB,0BAAA,EAAA,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAA;AAC/B,sBAAA,EAAA,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAA;;;AAGvC,aAAA,EAAA,MAAM,CAAC,S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
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { AcceptedFileTypes, FileSizeUnit } from './constants';
|
|
2
|
+
import { AcceptedFileTypes, ErrorType, FileSizeUnit } from './constants';
|
|
3
3
|
export interface UploadFileProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
4
4
|
id: string;
|
|
5
5
|
fileTypes: Array<AcceptedFileTypes>;
|
|
6
6
|
label?: string;
|
|
7
7
|
format?: FileSizeUnit;
|
|
8
8
|
maxBytes?: number;
|
|
9
|
+
errorMessage?: string;
|
|
10
|
+
hideUploadedFiles?: boolean;
|
|
11
|
+
onMaxFilesExceeded?: () => void;
|
|
12
|
+
maxFiles?: number;
|
|
13
|
+
disabledMessage?: string;
|
|
14
|
+
isDirty?: boolean;
|
|
9
15
|
}
|
|
16
|
+
export type UploadFileErrors = {
|
|
17
|
+
criticalErrors: Array<UploadFileError>;
|
|
18
|
+
};
|
|
19
|
+
type UploadFileError = {
|
|
20
|
+
errorType: ErrorType;
|
|
21
|
+
errorMessage: string;
|
|
22
|
+
};
|
|
23
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const convertFileTypeToAcceptedFileExtension: (fileType: string) => string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const convertFileTypeToAcceptedFileExtension = (fileType) => {
|
|
4
|
+
if (typeof fileType !== 'string' || !fileType.includes('/')) {
|
|
5
|
+
throw new Error('Invalid MIME type');
|
|
6
|
+
}
|
|
7
|
+
// Remove any MIME parameter (e.g., ";charset=UTF-8")
|
|
8
|
+
const [typePart] = fileType.split(';');
|
|
9
|
+
const [group, type] = typePart.trim().split('/');
|
|
10
|
+
if (!group || !type) {
|
|
11
|
+
throw new Error('Invalid MIME type');
|
|
12
|
+
}
|
|
13
|
+
return `.${type}`;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.convertFileTypeToAcceptedFileExtension = convertFileTypeToAcceptedFileExtension;
|
|
17
|
+
//# sourceMappingURL=convertFileTypeToAcceptedFileType.cjs.map
|