allaw-ui 3.1.1 → 3.1.3
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.
|
@@ -41,7 +41,7 @@ import ImageCropperModal from "./ImageCropperModal";
|
|
|
41
41
|
import IconButton from "../../atoms/buttons/IconButton";
|
|
42
42
|
import TertiaryButton from "../../atoms/buttons/TertiaryButton";
|
|
43
43
|
var FileUploader = function (_a) {
|
|
44
|
-
var acceptedExtensions = _a.acceptedExtensions, maxFileSizeMB = _a.maxFileSizeMB, _b = _a.enableDragAndDrop, enableDragAndDrop = _b === void 0 ? true : _b, _c = _a.enableCropping, enableCropping = _c === void 0 ? false : _c, _d = _a.cropShape, cropShape = _d === void 0 ? "square" : _d, iconUrl = _a.iconUrl, descriptionParts = _a.descriptionParts, onFileRead = _a.onFileRead, onFileRemove = _a.onFileRemove, _e = _a.uploadProgress, uploadProgress = _e === void 0 ? 0 : _e, _f = _a.isLoading, isLoading = _f === void 0 ? false : _f, _g = _a.autoManageProgress, autoManageProgress = _g === void 0 ? false : _g, _h = _a.progressSteps, progressSteps = _h === void 0 ? 10 : _h, _j = _a.progressInterval, progressInterval = _j === void 0 ? 500 : _j, _k = _a.errorMessage, errorMessage = _k === void 0 ? null : _k, _l = _a.buttonLabel, buttonLabel = _l === void 0 ? "Choisir un fichier" : _l, _m = _a.acceptedLabel, acceptedLabel = _m === void 0 ? "Format accepté :" : _m, _o = _a.maxSizeLabel, maxSizeLabel = _o === void 0 ? "Taille maximale :" : _o, fileName = _a.fileName, fileSize = _a.fileSize, _p = _a.filePresentationLabel, filePresentationLabel = _p === void 0 ? "Voici votre fichier." : _p, initialFile = _a.initialFile, initialPreviewUrl = _a.initialPreviewUrl, initialCropMetadata = _a.initialCropMetadata;
|
|
44
|
+
var acceptedExtensions = _a.acceptedExtensions, maxFileSizeMB = _a.maxFileSizeMB, _b = _a.enableDragAndDrop, enableDragAndDrop = _b === void 0 ? true : _b, _c = _a.enableCropping, enableCropping = _c === void 0 ? false : _c, _d = _a.cropShape, cropShape = _d === void 0 ? "square" : _d, iconUrl = _a.iconUrl, descriptionParts = _a.descriptionParts, onFileRead = _a.onFileRead, onFileRemove = _a.onFileRemove, _e = _a.uploadProgress, uploadProgress = _e === void 0 ? 0 : _e, _f = _a.isLoading, isLoading = _f === void 0 ? false : _f, _g = _a.autoManageProgress, autoManageProgress = _g === void 0 ? false : _g, _h = _a.progressSteps, progressSteps = _h === void 0 ? 10 : _h, _j = _a.progressInterval, progressInterval = _j === void 0 ? 500 : _j, _k = _a.errorMessage, errorMessage = _k === void 0 ? null : _k, _l = _a.buttonLabel, buttonLabel = _l === void 0 ? "Choisir un fichier" : _l, _m = _a.acceptedLabel, acceptedLabel = _m === void 0 ? "Format accepté :" : _m, _o = _a.maxSizeLabel, maxSizeLabel = _o === void 0 ? "Taille maximale :" : _o, fileName = _a.fileName, fileSize = _a.fileSize, _p = _a.filePresentationLabel, filePresentationLabel = _p === void 0 ? "Voici votre fichier." : _p, initialFile = _a.initialFile, initialPreviewUrl = _a.initialPreviewUrl, initialCropMetadata = _a.initialCropMetadata, originalFileName = _a.originalFileName;
|
|
45
45
|
var _q = useState(initialFile || null), selectedFile = _q[0], setSelectedFile = _q[1];
|
|
46
46
|
var _r = useState(null), fileContent = _r[0], setFileContent = _r[1];
|
|
47
47
|
var _s = useState(false), isHovering = _s[0], setIsHovering = _s[1];
|
|
@@ -51,11 +51,10 @@ var FileUploader = function (_a) {
|
|
|
51
51
|
var _w = useState(0), internalProgress = _w[0], setInternalProgress = _w[1];
|
|
52
52
|
var progressIntervalRef = useRef(null);
|
|
53
53
|
var fileInputRef = useRef(null);
|
|
54
|
+
var _x = useState(originalFileName), currentFileName = _x[0], setCurrentFileName = _x[1];
|
|
54
55
|
useEffect(function () {
|
|
55
56
|
if (initialFile) {
|
|
56
57
|
setSelectedFile(initialFile);
|
|
57
|
-
var url = URL.createObjectURL(initialFile);
|
|
58
|
-
setPreviewUrl(url);
|
|
59
58
|
initialFile.arrayBuffer().then(function (content) {
|
|
60
59
|
setFileContent(content);
|
|
61
60
|
});
|
|
@@ -66,14 +65,17 @@ var FileUploader = function (_a) {
|
|
|
66
65
|
if (initialCropMetadata) {
|
|
67
66
|
setCropMetadata(initialCropMetadata);
|
|
68
67
|
}
|
|
69
|
-
|
|
68
|
+
if (originalFileName) {
|
|
69
|
+
setCurrentFileName(originalFileName);
|
|
70
|
+
}
|
|
71
|
+
}, [initialFile, initialPreviewUrl, initialCropMetadata, originalFileName]);
|
|
70
72
|
useEffect(function () {
|
|
71
73
|
return function () {
|
|
72
|
-
if (previewUrl) {
|
|
74
|
+
if (previewUrl && !initialPreviewUrl) {
|
|
73
75
|
URL.revokeObjectURL(previewUrl);
|
|
74
76
|
}
|
|
75
77
|
};
|
|
76
|
-
}, [previewUrl]);
|
|
78
|
+
}, [previewUrl, initialPreviewUrl]);
|
|
77
79
|
var startProgressSimulation = function () {
|
|
78
80
|
stopProgressSimulation();
|
|
79
81
|
setInternalProgress(1);
|
|
@@ -149,6 +151,7 @@ var FileUploader = function (_a) {
|
|
|
149
151
|
setSelectedFile(null);
|
|
150
152
|
setPreviewUrl(null);
|
|
151
153
|
setCropMetadata(null);
|
|
154
|
+
setCurrentFileName(undefined);
|
|
152
155
|
return [2 /*return*/];
|
|
153
156
|
}
|
|
154
157
|
_a.label = 1;
|
|
@@ -158,6 +161,7 @@ var FileUploader = function (_a) {
|
|
|
158
161
|
case 2:
|
|
159
162
|
content = _a.sent();
|
|
160
163
|
setFileContent(content);
|
|
164
|
+
setCurrentFileName(file.name);
|
|
161
165
|
if (isImageFile(file)) {
|
|
162
166
|
url = URL.createObjectURL(file);
|
|
163
167
|
setPreviewUrl(url);
|
|
@@ -192,6 +196,7 @@ var FileUploader = function (_a) {
|
|
|
192
196
|
setSelectedFile(null);
|
|
193
197
|
setPreviewUrl(null);
|
|
194
198
|
setCropMetadata(null);
|
|
199
|
+
setCurrentFileName(undefined);
|
|
195
200
|
return [3 /*break*/, 4];
|
|
196
201
|
case 4: return [2 /*return*/];
|
|
197
202
|
}
|
|
@@ -216,7 +221,7 @@ var FileUploader = function (_a) {
|
|
|
216
221
|
}
|
|
217
222
|
};
|
|
218
223
|
var handleFileDelete = function () {
|
|
219
|
-
if (previewUrl) {
|
|
224
|
+
if (previewUrl && !initialPreviewUrl) {
|
|
220
225
|
URL.revokeObjectURL(previewUrl);
|
|
221
226
|
}
|
|
222
227
|
if (autoManageProgress) {
|
|
@@ -227,6 +232,7 @@ var FileUploader = function (_a) {
|
|
|
227
232
|
setFileContent(null);
|
|
228
233
|
setPreviewUrl(null);
|
|
229
234
|
setCropMetadata(null);
|
|
235
|
+
setCurrentFileName(undefined);
|
|
230
236
|
resetFileInput();
|
|
231
237
|
onFileRemove === null || onFileRemove === void 0 ? void 0 : onFileRemove();
|
|
232
238
|
};
|
|
@@ -319,10 +325,14 @@ var FileUploader = function (_a) {
|
|
|
319
325
|
React.createElement("div", { className: styles.uploaded_file_icon }, iconUrl ? (React.createElement(Image, { src: iconUrl, alt: "File icon", className: styles.file_icon, width: 20, height: 20 })) : (React.createElement("i", { className: "allaw-icon-file" }))),
|
|
320
326
|
React.createElement("div", { className: styles.uploaded_file_name_size },
|
|
321
327
|
React.createElement("div", { className: styles.uploaded_file_name },
|
|
322
|
-
React.createElement("span", { className: styles.file_name }, displayFileName || "Analyse en cours..."),
|
|
328
|
+
React.createElement("span", { className: styles.file_name }, displayFileName || currentFileName || "Analyse en cours..."),
|
|
323
329
|
selectedFile && (React.createElement("i", { className: "allaw-icon-check ".concat(styles.success_icon) }))),
|
|
324
330
|
React.createElement("div", { className: styles.uploaded_file_size },
|
|
325
|
-
React.createElement("span", { className: styles.file_size }, displayFileSize > 0
|
|
331
|
+
React.createElement("span", { className: styles.file_size }, displayFileSize > 0
|
|
332
|
+
? formatFileSize(displayFileSize)
|
|
333
|
+
: (selectedFile === null || selectedFile === void 0 ? void 0 : selectedFile.size)
|
|
334
|
+
? formatFileSize(selectedFile.size)
|
|
335
|
+
: ""))),
|
|
326
336
|
selectedFile && (React.createElement("div", { className: styles.uploaded_file_delete_container },
|
|
327
337
|
React.createElement("div", { className: styles.uploaded_file_delete, onClick: handleFileDelete },
|
|
328
338
|
React.createElement("i", { className: "allaw-icon-close" }))))),
|