allaw-ui 3.1.2 → 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,6 +51,7 @@ 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);
|
|
@@ -64,7 +65,10 @@ var FileUploader = function (_a) {
|
|
|
64
65
|
if (initialCropMetadata) {
|
|
65
66
|
setCropMetadata(initialCropMetadata);
|
|
66
67
|
}
|
|
67
|
-
|
|
68
|
+
if (originalFileName) {
|
|
69
|
+
setCurrentFileName(originalFileName);
|
|
70
|
+
}
|
|
71
|
+
}, [initialFile, initialPreviewUrl, initialCropMetadata, originalFileName]);
|
|
68
72
|
useEffect(function () {
|
|
69
73
|
return function () {
|
|
70
74
|
if (previewUrl && !initialPreviewUrl) {
|
|
@@ -147,6 +151,7 @@ var FileUploader = function (_a) {
|
|
|
147
151
|
setSelectedFile(null);
|
|
148
152
|
setPreviewUrl(null);
|
|
149
153
|
setCropMetadata(null);
|
|
154
|
+
setCurrentFileName(undefined);
|
|
150
155
|
return [2 /*return*/];
|
|
151
156
|
}
|
|
152
157
|
_a.label = 1;
|
|
@@ -156,6 +161,7 @@ var FileUploader = function (_a) {
|
|
|
156
161
|
case 2:
|
|
157
162
|
content = _a.sent();
|
|
158
163
|
setFileContent(content);
|
|
164
|
+
setCurrentFileName(file.name);
|
|
159
165
|
if (isImageFile(file)) {
|
|
160
166
|
url = URL.createObjectURL(file);
|
|
161
167
|
setPreviewUrl(url);
|
|
@@ -190,6 +196,7 @@ var FileUploader = function (_a) {
|
|
|
190
196
|
setSelectedFile(null);
|
|
191
197
|
setPreviewUrl(null);
|
|
192
198
|
setCropMetadata(null);
|
|
199
|
+
setCurrentFileName(undefined);
|
|
193
200
|
return [3 /*break*/, 4];
|
|
194
201
|
case 4: return [2 /*return*/];
|
|
195
202
|
}
|
|
@@ -214,7 +221,7 @@ var FileUploader = function (_a) {
|
|
|
214
221
|
}
|
|
215
222
|
};
|
|
216
223
|
var handleFileDelete = function () {
|
|
217
|
-
if (previewUrl) {
|
|
224
|
+
if (previewUrl && !initialPreviewUrl) {
|
|
218
225
|
URL.revokeObjectURL(previewUrl);
|
|
219
226
|
}
|
|
220
227
|
if (autoManageProgress) {
|
|
@@ -225,6 +232,7 @@ var FileUploader = function (_a) {
|
|
|
225
232
|
setFileContent(null);
|
|
226
233
|
setPreviewUrl(null);
|
|
227
234
|
setCropMetadata(null);
|
|
235
|
+
setCurrentFileName(undefined);
|
|
228
236
|
resetFileInput();
|
|
229
237
|
onFileRemove === null || onFileRemove === void 0 ? void 0 : onFileRemove();
|
|
230
238
|
};
|
|
@@ -317,9 +325,7 @@ var FileUploader = function (_a) {
|
|
|
317
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" }))),
|
|
318
326
|
React.createElement("div", { className: styles.uploaded_file_name_size },
|
|
319
327
|
React.createElement("div", { className: styles.uploaded_file_name },
|
|
320
|
-
React.createElement("span", { className: styles.file_name }, displayFileName ||
|
|
321
|
-
(selectedFile === null || selectedFile === void 0 ? void 0 : selectedFile.name) ||
|
|
322
|
-
"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
331
|
React.createElement("span", { className: styles.file_size }, displayFileSize > 0
|