@veeqo/ui 12.4.0-beta-3 → 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 +8 -9
- package/dist/components/SelectDropdown/SelectDropdown.cjs.map +1 -1
- package/dist/components/SelectDropdown/SelectDropdown.d.ts +1 -1
- package/dist/components/SelectDropdown/SelectDropdown.js +8 -9
- 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/SelectDropdownState.cjs +3 -11
- package/dist/components/SelectDropdown/components/SelectDropdownState.cjs.map +1 -1
- package/dist/components/SelectDropdown/components/SelectDropdownState.js +3 -11
- package/dist/components/SelectDropdown/components/SelectDropdownState.js.map +1 -1
- package/dist/components/SelectDropdown/components/item.module.scss.cjs +3 -3
- package/dist/components/SelectDropdown/components/item.module.scss.cjs.map +1 -1
- package/dist/components/SelectDropdown/components/item.module.scss.js +3 -3
- 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/GridItem/GridItem.module.scss.cjs +0 -9
- package/dist/components/SelectDropdown/components/GridItem/GridItem.module.scss.cjs.map +0 -1
- package/dist/components/SelectDropdown/components/GridItem/GridItem.module.scss.js +0 -7
- package/dist/components/SelectDropdown/components/GridItem/GridItem.module.scss.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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../../../src/components/UploadFile/constants.ts"],"sourcesContent":["export enum AcceptedFileTypes {\n CSV = '.csv',\n JPEG = '.jpeg',\n JPG = '.jpg',\n GIF = '.gif',\n
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../src/components/UploadFile/constants.ts"],"sourcesContent":["export enum AcceptedFileTypes {\n // DATA FILES\n CSV = '.csv',\n JSON = '.json',\n XML = '.xml',\n TXT = '.txt',\n\n // DOCUMENTS\n PDF = '.pdf',\n DOC = '.doc',\n DOCX = '.docx',\n XLS = '.xls',\n XLSX = '.xlsx',\n PPT = '.ppt',\n PPTX = '.pptx',\n ODT = '.odt',\n ODS = '.ods',\n ODP = '.odp',\n RTF = '.rtf',\n\n // IMAGES\n JPEG = '.jpeg',\n JPG = '.jpg',\n PNG = '.png',\n GIF = '.gif',\n BMP = '.bmp',\n WEBP = '.webp',\n SVG = '.svg',\n ICO = '.ico',\n TIFF = '.tiff',\n TIF = '.tif',\n\n // AUDIO\n MP3 = '.mp3',\n WAV = '.wav',\n OGG = '.ogg',\n AAC = '.aac',\n FLAC = '.flac',\n M4A = '.m4a',\n WMA = '.wma',\n\n // VIDEO\n MP4 = '.mp4',\n AVI = '.avi',\n MOV = '.mov',\n WMV = '.wmv',\n FLV = '.flv',\n WEBM = '.webm',\n MKV = '.mkv',\n M4V = '.m4v',\n\n // ARCHIVES\n ZIP = '.zip',\n RAR = '.rar',\n SEVEN_Z = '.7z',\n TAR = '.tar',\n GZ = '.gz',\n}\n\nexport enum FileSizeUnit {\n KB = 'KB',\n MB = 'MB',\n}\n\nexport enum ErrorType {\n critical = 'CRITICAL',\n warning = 'WARNING',\n}\n\nexport const DEFAULT_MAXIMUM_MULTIPLE_FILES = 10;\n\nexport enum InputErrorStateMessages {\n VALID = '',\n INVALID_FORMAT = 'Please provide a file with a valid format.',\n INVALID_FORMATS = 'Please provide files with a valid format.',\n INVALID_SIZE = 'Please provide file with an acceptable size.',\n INVALID_SIZES = 'Please provide files with an acceptable size.',\n INVALID_FORMAT_AND_SIZE = 'Please provide files with an acceptable size and format.',\n}\n"],"names":[],"mappings":"IAAY;AAAZ,CAAA,UAAY,iBAAiB,EAAA;;AAE3B,IAAA,iBAAA,CAAA,KAAA,CAAA,GAAA,MAAY;AACZ,IAAA,iBAAA,CAAA,MAAA,CAAA,GAAA,OAAc;AACd,IAAA,iBAAA,CAAA,KAAA,CAAA,GAAA,MAAY;AACZ,IAAA,iBAAA,CAAA,KAAA,CAAA,GAAA,MAAY;;AAGZ,IAAA,iBAAA,CAAA,KAAA,CAAA,GAAA,MAAY;AACZ,IAAA,iBAAA,CAAA,KAA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EAAA;AACjC,IAAA,uBAAA,CAAA,OAAA,CAAA,GAAA,EAAU;AACV,IAAA,uBAAA,CAAA,gBAAA,CAAA,GAAA,4CAA6D;AAC7D,IAAA,uBAAA,CAAA,iBAAA,CAAA,GAAA,2CAA6D;AAC7D,IAAA,uBAAA,CAAA,cAAA,CAAA,GAAA,8CAA6D;AAC7D,IAAA,uBAAA,CAAA,eAAA,CAAA,GAAA,+CAA+D;AAC/D,IAAA,uBAAA,CAAA,yBAAA,CAAA,GAAA,0DAAoF;AACtF,CAAC,EAPW,uBAAuB,KAAvB,uBAAuB,GAOlC,EAAA,CAAA,CAAA;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useFileErrorMessages } from './useFileErrorMessages';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var constants = require('../../constants.cjs');
|
|
5
|
+
var convertFileTypeToAcceptedFileType = require('../../utils/convertFileTypeToAcceptedFileExtension/convertFileTypeToAcceptedFileType.cjs');
|
|
6
|
+
|
|
7
|
+
const useFileErrorMessages = ({ format, maxBytes, fileTypes, file, }) => {
|
|
8
|
+
const [errorMessages, setErrorMessages] = React.useState({ criticalErrors: [] });
|
|
9
|
+
React.useEffect(() => {
|
|
10
|
+
if (!file)
|
|
11
|
+
return;
|
|
12
|
+
const extension = convertFileTypeToAcceptedFileType.convertFileTypeToAcceptedFileExtension(file.type);
|
|
13
|
+
const isTypeValid = fileTypes.includes(extension);
|
|
14
|
+
const hasInvalidFormat = !isTypeValid;
|
|
15
|
+
const hasExceededMaxSize = file.size > maxBytes;
|
|
16
|
+
const errors = { criticalErrors: [] };
|
|
17
|
+
if (hasExceededMaxSize) {
|
|
18
|
+
errors.criticalErrors.push({
|
|
19
|
+
errorType: constants.ErrorType.critical,
|
|
20
|
+
errorMessage: 'File is too big',
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (hasInvalidFormat) {
|
|
24
|
+
errors.criticalErrors.push({
|
|
25
|
+
errorType: constants.ErrorType.critical,
|
|
26
|
+
errorMessage: 'Invalid format',
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
setErrorMessages(errors);
|
|
30
|
+
}, [file, fileTypes, format, maxBytes]);
|
|
31
|
+
const hasCriticalErrors = !!errorMessages.criticalErrors.length;
|
|
32
|
+
return {
|
|
33
|
+
hasCriticalErrors,
|
|
34
|
+
errorMessages,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.useFileErrorMessages = useFileErrorMessages;
|
|
39
|
+
//# sourceMappingURL=useFileErrorMessages.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFileErrorMessages.cjs","sources":["../../../../../src/components/UploadFile/hooks/useFileErrorMessages/useFileErrorMessages.ts"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport { AcceptedFileTypes, ErrorType, FileSizeUnit } from '../../constants';\nimport { UploadFileErrors } from '../../types';\nimport { convertFileTypeToAcceptedFileExtension } from '../../utils/convertFileTypeToAcceptedFileExtension';\n\ntype UseFileErrorMessagesProps = {\n file?: File | null;\n format: FileSizeUnit;\n maxBytes: number;\n fileTypes: Array<AcceptedFileTypes>;\n};\n\nexport const useFileErrorMessages = ({\n format,\n maxBytes,\n fileTypes,\n file,\n}: UseFileErrorMessagesProps) => {\n const [errorMessages, setErrorMessages] = useState<UploadFileErrors>({ criticalErrors: [] });\n\n useEffect(() => {\n if (!file) return;\n\n const extension = convertFileTypeToAcceptedFileExtension(file.type);\n const isTypeValid = (fileTypes as string[]).includes(extension);\n const hasInvalidFormat = !isTypeValid;\n\n const hasExceededMaxSize = file.size > maxBytes;\n\n const errors: UploadFileErrors = { criticalErrors: [] };\n if (hasExceededMaxSize) {\n errors.criticalErrors.push({\n errorType: ErrorType.critical,\n errorMessage: 'File is too big',\n });\n }\n if (hasInvalidFormat) {\n errors.criticalErrors.push({\n errorType: ErrorType.critical,\n errorMessage: 'Invalid format',\n });\n }\n setErrorMessages(errors);\n }, [file, fileTypes, format, maxBytes]);\n\n const hasCriticalErrors = !!errorMessages.criticalErrors.length;\n\n return {\n hasCriticalErrors,\n errorMessages,\n };\n};\n"],"names":["useState","useEffect","convertFileTypeToAcceptedFileExtension","ErrorType"],"mappings":";;;;;;AAYO,MAAM,oBAAoB,GAAG,CAAC,EACnC,MAAM,EACN,QAAQ,EACR,SAAS,EACT,IAAI,GACsB,KAAI;AAC9B,IAAA,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAGA,cAAQ,CAAmB,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC;IAE5FC,eAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,IAAI;YAAE;QAEX,MAAM,SAAS,GAAGC,wEAAsC,CAAC,IAAI,CAAC,IAAI,CAAC;QACnE,MAAM,WAAW,GAAI,SAAsB,CAAC,QAAQ,CAAC,SAAS,CAAC;AAC/D,QAAA,MAAM,gBAAgB,GAAG,CAAC,WAAW;AAErC,QAAA,MAAM,kBAAkB,GAAG,IAAI,CAAC,IAAI,GAAG,QAAQ;AAE/C,QAAA,MAAM,MAAM,GAAqB,EAAE,cAAc,EAAE,EAAE,EAAE;AACvD,QAAA,IAAI,kBAAkB,EAAE;AACtB,YAAA,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC;gBACzB,SAAS,EAAEC,mBAAS,CAAC,QAAQ;AAC7B,gBAAA,YAAY,EAAE,iBAAiB;AAChC,aAAA,CAAC;AACH;AACD,QAAA,IAAI,gBAAgB,EAAE;AACpB,YAAA,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC;gBACzB,SAAS,EAAEA,mBAAS,CAAC,QAAQ;AAC7B,gBAAA,YAAY,EAAE,gBAAgB;AAC/B,aAAA,CAAC;AACH;QACD,gBAAgB,CAAC,MAAM,CAAC;KACzB,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAEvC,MAAM,iBAAiB,GAAG,CAAC,CAAC,aAAa,CAAC,cAAc,CAAC,MAAM;IAE/D,OAAO;QACL,iBAAiB;QACjB,aAAa;KACd;AACH;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AcceptedFileTypes, FileSizeUnit } from '../../constants';
|
|
2
|
+
import { UploadFileErrors } from '../../types';
|
|
3
|
+
type UseFileErrorMessagesProps = {
|
|
4
|
+
file?: File | null;
|
|
5
|
+
format: FileSizeUnit;
|
|
6
|
+
maxBytes: number;
|
|
7
|
+
fileTypes: Array<AcceptedFileTypes>;
|
|
8
|
+
};
|
|
9
|
+
export declare const useFileErrorMessages: ({ format, maxBytes, fileTypes, file, }: UseFileErrorMessagesProps) => {
|
|
10
|
+
hasCriticalErrors: boolean;
|
|
11
|
+
errorMessages: UploadFileErrors;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { ErrorType } from '../../constants.js';
|
|
3
|
+
import { convertFileTypeToAcceptedFileExtension } from '../../utils/convertFileTypeToAcceptedFileExtension/convertFileTypeToAcceptedFileType.js';
|
|
4
|
+
|
|
5
|
+
const useFileErrorMessages = ({ format, maxBytes, fileTypes, file, }) => {
|
|
6
|
+
const [errorMessages, setErrorMessages] = useState({ criticalErrors: [] });
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (!file)
|
|
9
|
+
return;
|
|
10
|
+
const extension = convertFileTypeToAcceptedFileExtension(file.type);
|
|
11
|
+
const isTypeValid = fileTypes.includes(extension);
|
|
12
|
+
const hasInvalidFormat = !isTypeValid;
|
|
13
|
+
const hasExceededMaxSize = file.size > maxBytes;
|
|
14
|
+
const errors = { criticalErrors: [] };
|
|
15
|
+
if (hasExceededMaxSize) {
|
|
16
|
+
errors.criticalErrors.push({
|
|
17
|
+
errorType: ErrorType.critical,
|
|
18
|
+
errorMessage: 'File is too big',
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (hasInvalidFormat) {
|
|
22
|
+
errors.criticalErrors.push({
|
|
23
|
+
errorType: ErrorType.critical,
|
|
24
|
+
errorMessage: 'Invalid format',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
setErrorMessages(errors);
|
|
28
|
+
}, [file, fileTypes, format, maxBytes]);
|
|
29
|
+
const hasCriticalErrors = !!errorMessages.criticalErrors.length;
|
|
30
|
+
return {
|
|
31
|
+
hasCriticalErrors,
|
|
32
|
+
errorMessages,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { useFileErrorMessages };
|
|
37
|
+
//# sourceMappingURL=useFileErrorMessages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFileErrorMessages.js","sources":["../../../../../src/components/UploadFile/hooks/useFileErrorMessages/useFileErrorMessages.ts"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport { AcceptedFileTypes, ErrorType, FileSizeUnit } from '../../constants';\nimport { UploadFileErrors } from '../../types';\nimport { convertFileTypeToAcceptedFileExtension } from '../../utils/convertFileTypeToAcceptedFileExtension';\n\ntype UseFileErrorMessagesProps = {\n file?: File | null;\n format: FileSizeUnit;\n maxBytes: number;\n fileTypes: Array<AcceptedFileTypes>;\n};\n\nexport const useFileErrorMessages = ({\n format,\n maxBytes,\n fileTypes,\n file,\n}: UseFileErrorMessagesProps) => {\n const [errorMessages, setErrorMessages] = useState<UploadFileErrors>({ criticalErrors: [] });\n\n useEffect(() => {\n if (!file) return;\n\n const extension = convertFileTypeToAcceptedFileExtension(file.type);\n const isTypeValid = (fileTypes as string[]).includes(extension);\n const hasInvalidFormat = !isTypeValid;\n\n const hasExceededMaxSize = file.size > maxBytes;\n\n const errors: UploadFileErrors = { criticalErrors: [] };\n if (hasExceededMaxSize) {\n errors.criticalErrors.push({\n errorType: ErrorType.critical,\n errorMessage: 'File is too big',\n });\n }\n if (hasInvalidFormat) {\n errors.criticalErrors.push({\n errorType: ErrorType.critical,\n errorMessage: 'Invalid format',\n });\n }\n setErrorMessages(errors);\n }, [file, fileTypes, format, maxBytes]);\n\n const hasCriticalErrors = !!errorMessages.criticalErrors.length;\n\n return {\n hasCriticalErrors,\n errorMessages,\n };\n};\n"],"names":[],"mappings":";;;;AAYO,MAAM,oBAAoB,GAAG,CAAC,EACnC,MAAM,EACN,QAAQ,EACR,SAAS,EACT,IAAI,GACsB,KAAI;AAC9B,IAAA,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAmB,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC;IAE5F,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,IAAI;YAAE;QAEX,MAAM,SAAS,GAAG,sCAAsC,CAAC,IAAI,CAAC,IAAI,CAAC;QACnE,MAAM,WAAW,GAAI,SAAsB,CAAC,QAAQ,CAAC,SAAS,CAAC;AAC/D,QAAA,MAAM,gBAAgB,GAAG,CAAC,WAAW;AAErC,QAAA,MAAM,kBAAkB,GAAG,IAAI,CAAC,IAAI,GAAG,QAAQ;AAE/C,QAAA,MAAM,MAAM,GAAqB,EAAE,cAAc,EAAE,EAAE,EAAE;AACvD,QAAA,IAAI,kBAAkB,EAAE;AACtB,YAAA,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC;gBACzB,SAAS,EAAE,SAAS,CAAC,QAAQ;AAC7B,gBAAA,YAAY,EAAE,iBAAiB;AAChC,aAAA,CAAC;AACH;AACD,QAAA,IAAI,gBAAgB,EAAE;AACpB,YAAA,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC;gBACzB,SAAS,EAAE,SAAS,CAAC,QAAQ;AAC7B,gBAAA,YAAY,EAAE,gBAAgB;AAC/B,aAAA,CAAC;AACH;QACD,gBAAgB,CAAC,MAAM,CAAC;KACzB,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAEvC,MAAM,iBAAiB,GAAG,CAAC,CAAC,aAAa,CAAC,cAAc,CAAC,MAAM;IAE/D,OAAO;QACL,iBAAiB;QACjB,aAAa;KACd;AACH;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { usePreviewImage } from './usePreviewImage';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var isImageType = require('../../utils/isImageType/isImageType.cjs');
|
|
5
|
+
|
|
6
|
+
const usePreviewImage = ({ file }) => {
|
|
7
|
+
const [previewSrc, setPreviewSrc] = React.useState('');
|
|
8
|
+
React.useEffect(() => {
|
|
9
|
+
if (!file) {
|
|
10
|
+
setPreviewSrc('');
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
if (!isImageType.isImageType(file)) {
|
|
14
|
+
setPreviewSrc('');
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
const fileReader = new FileReader();
|
|
18
|
+
fileReader.onload = (event) => {
|
|
19
|
+
var _a;
|
|
20
|
+
const imageUrl = (_a = event.target) === null || _a === undefined ? undefined : _a.result;
|
|
21
|
+
setPreviewSrc(String(imageUrl));
|
|
22
|
+
};
|
|
23
|
+
fileReader.readAsDataURL(file);
|
|
24
|
+
return () => {
|
|
25
|
+
fileReader.abort();
|
|
26
|
+
};
|
|
27
|
+
}, [file]);
|
|
28
|
+
const shouldShowPreview = file ? isImageType.isImageType(file) : false;
|
|
29
|
+
return {
|
|
30
|
+
previewSrc,
|
|
31
|
+
shouldShowPreview,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.usePreviewImage = usePreviewImage;
|
|
36
|
+
//# sourceMappingURL=usePreviewImage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePreviewImage.cjs","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":["useState","useEffect","isImageType"],"mappings":";;;;;MAOa,eAAe,GAAG,CAAC,EAAE,IAAI,EAAwB,KAAI;IAChE,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAGA,cAAQ,CAAC,EAAE,CAAC;IAEhDC,eAAS,CAAC,MAAK;QACb,IAAI,CAAC,IAAI,EAAE;YACT,aAAa,CAAC,EAAE,CAAC;AACjB,YAAA,OAAO,SAAS;AACjB;AAED,QAAA,IAAI,CAACC,uBAAW,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,GAAGA,uBAAW,CAAC,IAAI,CAAC,GAAG,KAAK;IAE1D,OAAO;QACL,UAAU;QACV,iBAAiB;KAClB;AACH;;;;"}
|
|
@@ -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,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAC1D,QAAQ,CAAC,OAAO,CAAC,KAAK,GAAG,EAAE,CAAC,KAAK;AAClC;AACF;;AAED,QAAA,IAAI,QAAQ,CAAC,OAAO,IAAI,CAAC,QAAQ,EAAE;AACjC,YAAA,QAAQ,CAA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AA,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,CAAC,GAAG,QAAQ,EAAY;;IAGpD,SAAS,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,YAA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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,CAAA,EAAE;YACpC,CAAA,EAAA,GAAA,QAAQ,CAAC,OAAO,MAAA,IAAA,IAAA,EAAA,KAAA,SAAA,GAAA,SAAA,GAAA,EAAA,CAAE,iBAAiB,CAAC,YAAY,CAAC;YACjD;AACD;AAED,QAAA,MAAM,OAAO,GAAG;AACd,YAAA,0BAA0B,EAAE,CAAC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,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,MAAA,IAAA,IAAA,EAAA,KAAA,SAAA,GAAA,SAAA,GAAA,EAAA,CAAE,MAAM,CAAA,EAAE;YACpC,CAAA,EAAA,GAAA,QAAQ,CAAC,OAAO,MAAA,IAAA,IAAA,EAAA,KAAA,SAAA,GAAA,SAAA,GAAA,EAAA,CAAE,iBAAiB,CAAC,YAAY,CAA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AAa,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 {};
|