@availity/mui-file-selector 1.7.1 → 1.8.1
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/CHANGELOG.md +21 -0
- package/dist/index.d.mts +37 -7
- package/dist/index.d.ts +37 -7
- package/dist/index.js +214 -66
- package/dist/index.mjs +222 -74
- package/package.json +1 -1
- package/src/lib/Dropzone.tsx +101 -4
- package/src/lib/Dropzone2.tsx +91 -5
- package/src/lib/ErrorAlert.tsx +1 -0
- package/src/lib/FileSelector.tsx +21 -1
- package/src/lib/FileSelector2.tsx +8 -1
- package/src/lib/FileTypesMessage.tsx +14 -0
- package/src/lib/HeaderMessage.tsx +8 -3
package/dist/index.js
CHANGED
|
@@ -108,7 +108,7 @@ var import_styles = require("@mui/material/styles");
|
|
|
108
108
|
var import_react_dropzone = require("react-dropzone");
|
|
109
109
|
var import_react_hook_form2 = require("react-hook-form");
|
|
110
110
|
var import_mui_divider = require("@availity/mui-divider");
|
|
111
|
-
var
|
|
111
|
+
var import_mui_icon2 = require("@availity/mui-icon");
|
|
112
112
|
var import_mui_layout = require("@availity/mui-layout");
|
|
113
113
|
var import_mui_typography = require("@availity/mui-typography");
|
|
114
114
|
|
|
@@ -166,6 +166,55 @@ var FilePickerBtn = (_a) => {
|
|
|
166
166
|
] });
|
|
167
167
|
};
|
|
168
168
|
|
|
169
|
+
// src/lib/util.ts
|
|
170
|
+
var import_mui_icon = require("@availity/mui-icon");
|
|
171
|
+
function formatBytes(bytes, decimals = 2) {
|
|
172
|
+
if (!+bytes) return "0 Bytes";
|
|
173
|
+
const k = 1024;
|
|
174
|
+
const dm = decimals < 0 ? 0 : decimals;
|
|
175
|
+
const sizes = ["Bytes", "KB", "MB", "GB"];
|
|
176
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
177
|
+
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
178
|
+
}
|
|
179
|
+
var FILE_EXT_ICONS = {
|
|
180
|
+
png: import_mui_icon.FileImageIcon,
|
|
181
|
+
jpg: import_mui_icon.FileImageIcon,
|
|
182
|
+
jpeg: import_mui_icon.FileImageIcon,
|
|
183
|
+
gif: import_mui_icon.FileImageIcon,
|
|
184
|
+
csv: import_mui_icon.FileCsvIcon,
|
|
185
|
+
ppt: import_mui_icon.FilePowerpointIcon,
|
|
186
|
+
pptx: import_mui_icon.FilePowerpointIcon,
|
|
187
|
+
xls: import_mui_icon.FileExcelIcon,
|
|
188
|
+
xlsx: import_mui_icon.FileExcelIcon,
|
|
189
|
+
doc: import_mui_icon.FileWordIcon,
|
|
190
|
+
docx: import_mui_icon.FileWordIcon,
|
|
191
|
+
txt: import_mui_icon.FileLinesIcon,
|
|
192
|
+
text: import_mui_icon.FileLinesIcon,
|
|
193
|
+
zip: import_mui_icon.FileArchiveIcon,
|
|
194
|
+
"7zip": import_mui_icon.FileArchiveIcon,
|
|
195
|
+
xml: import_mui_icon.FileCodeIcon,
|
|
196
|
+
html: import_mui_icon.FileCodeIcon,
|
|
197
|
+
pdf: import_mui_icon.FilePdfIcon
|
|
198
|
+
};
|
|
199
|
+
var isValidKey = (key) => key ? key in FILE_EXT_ICONS : false;
|
|
200
|
+
var getFileExtension = (fileName) => {
|
|
201
|
+
var _a;
|
|
202
|
+
return ((_a = fileName.split(".").pop()) == null ? void 0 : _a.toLowerCase()) || "";
|
|
203
|
+
};
|
|
204
|
+
var getFileExtIcon = (fileName) => {
|
|
205
|
+
const ext = getFileExtension(fileName);
|
|
206
|
+
return isValidKey(ext) ? FILE_EXT_ICONS[ext] : import_mui_icon.FileIcon;
|
|
207
|
+
};
|
|
208
|
+
var dedupeErrors = (errors) => {
|
|
209
|
+
const dedupedErrors = errors.reduce((acc, error) => {
|
|
210
|
+
if (!acc.find((err) => err.code === error.code)) {
|
|
211
|
+
acc.push(error);
|
|
212
|
+
}
|
|
213
|
+
return acc;
|
|
214
|
+
}, []);
|
|
215
|
+
return dedupedErrors;
|
|
216
|
+
};
|
|
217
|
+
|
|
169
218
|
// src/lib/Dropzone.tsx
|
|
170
219
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
171
220
|
var outerBoxStyles = {
|
|
@@ -201,10 +250,12 @@ var DropzoneContainer = (0, import_styles.styled)(import_mui_layout.Box, { name:
|
|
|
201
250
|
});
|
|
202
251
|
var Dropzone = ({
|
|
203
252
|
allowedFileTypes = [],
|
|
253
|
+
allowedFileNameCharacters,
|
|
204
254
|
disabled,
|
|
205
255
|
enableDropArea = true,
|
|
206
256
|
maxFiles,
|
|
207
257
|
maxSize,
|
|
258
|
+
maxTotalSize,
|
|
208
259
|
multiple,
|
|
209
260
|
name,
|
|
210
261
|
onChange,
|
|
@@ -234,6 +285,27 @@ var Dropzone = ({
|
|
|
234
285
|
message: `Too many files. You may only upload ${maxFiles} file(s).`
|
|
235
286
|
});
|
|
236
287
|
}
|
|
288
|
+
if (allowedFileNameCharacters) {
|
|
289
|
+
const fileName = file.name.substring(0, file.name.lastIndexOf("."));
|
|
290
|
+
const regExp = new RegExp(`([^${allowedFileNameCharacters}])`, "g");
|
|
291
|
+
if (fileName.match(regExp) !== null) {
|
|
292
|
+
errors.push({
|
|
293
|
+
code: "invalid-file-name-characters",
|
|
294
|
+
message: "File name contains characters not allowed"
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if (allowedFileTypes.length > 0) {
|
|
299
|
+
const fileName = file.name;
|
|
300
|
+
const fileExt = fileName.substring(fileName.lastIndexOf(".")).toLowerCase();
|
|
301
|
+
const lowerCaseAllowedTypes = allowedFileTypes.map((type) => type.toLowerCase());
|
|
302
|
+
if (!lowerCaseAllowedTypes.includes(fileExt)) {
|
|
303
|
+
errors.push({
|
|
304
|
+
code: "file-invalid-type",
|
|
305
|
+
message: `File type ${fileExt} is not allowed`
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
}
|
|
237
309
|
if (validator) {
|
|
238
310
|
const validatorErrors = validator(file);
|
|
239
311
|
if (validatorErrors) {
|
|
@@ -246,7 +318,7 @@ var Dropzone = ({
|
|
|
246
318
|
}
|
|
247
319
|
return errors.length > 0 ? errors : null;
|
|
248
320
|
},
|
|
249
|
-
[maxFiles, validator]
|
|
321
|
+
[maxFiles, validator, allowedFileNameCharacters, watch, name, allowedFileTypes]
|
|
250
322
|
);
|
|
251
323
|
const handleOnDrop = (0, import_react.useCallback)(
|
|
252
324
|
(acceptedFiles, fileRejections, event) => {
|
|
@@ -257,7 +329,48 @@ var Dropzone = ({
|
|
|
257
329
|
}
|
|
258
330
|
setTotalSize((prev) => prev + newSize);
|
|
259
331
|
const previous = (_a2 = watch(name)) != null ? _a2 : [];
|
|
260
|
-
|
|
332
|
+
if (maxTotalSize) {
|
|
333
|
+
const currentTotalSize = previous.reduce((sum, file) => sum + file.size, 0);
|
|
334
|
+
let newSize2 = 0;
|
|
335
|
+
const availableSize = Math.max(0, maxTotalSize - currentTotalSize);
|
|
336
|
+
let sizeCounter = 0;
|
|
337
|
+
const cutoffIndex = acceptedFiles.findIndex((file) => {
|
|
338
|
+
sizeCounter += file.size;
|
|
339
|
+
return sizeCounter > availableSize;
|
|
340
|
+
});
|
|
341
|
+
if (cutoffIndex !== -1) {
|
|
342
|
+
const filesToAdd2 = acceptedFiles.slice(0, cutoffIndex === 0 ? 0 : cutoffIndex);
|
|
343
|
+
fileRejections.push({
|
|
344
|
+
file: acceptedFiles[cutoffIndex],
|
|
345
|
+
errors: [
|
|
346
|
+
{
|
|
347
|
+
code: "upload-too-large",
|
|
348
|
+
message: `Total upload size exceeds the limit of ${formatBytes(maxTotalSize)}.`
|
|
349
|
+
}
|
|
350
|
+
],
|
|
351
|
+
id: counter.increment()
|
|
352
|
+
});
|
|
353
|
+
acceptedFiles = filesToAdd2;
|
|
354
|
+
}
|
|
355
|
+
newSize2 = acceptedFiles.reduce((sum, file) => sum + file.size, 0);
|
|
356
|
+
setTotalSize((prev) => prev + newSize2);
|
|
357
|
+
}
|
|
358
|
+
const remainingSlots = maxFiles ? Math.max(0, maxFiles - previous.length) : acceptedFiles.length;
|
|
359
|
+
const filesToAdd = acceptedFiles.slice(0, remainingSlots);
|
|
360
|
+
setValue(name, previous.concat(filesToAdd));
|
|
361
|
+
if (maxFiles && acceptedFiles.length > remainingSlots) {
|
|
362
|
+
fileRejections.push({
|
|
363
|
+
file: acceptedFiles[remainingSlots],
|
|
364
|
+
// Use the first excess file
|
|
365
|
+
errors: [
|
|
366
|
+
{
|
|
367
|
+
code: "too-many-files",
|
|
368
|
+
message: `Too many files. You may only upload ${maxFiles} file(s).`
|
|
369
|
+
}
|
|
370
|
+
],
|
|
371
|
+
id: counter.increment()
|
|
372
|
+
});
|
|
373
|
+
}
|
|
261
374
|
if (fileRejections.length > 0) {
|
|
262
375
|
const TOO_MANY_FILES_CODE = "too-many-files";
|
|
263
376
|
let hasTooManyFiles = false;
|
|
@@ -284,7 +397,7 @@ var Dropzone = ({
|
|
|
284
397
|
if (setFileRejections) setFileRejections(fileRejections);
|
|
285
398
|
if (onDrop) onDrop(acceptedFiles, fileRejections, event);
|
|
286
399
|
},
|
|
287
|
-
[setFileRejections]
|
|
400
|
+
[setFileRejections, setTotalSize, watch, name, maxTotalSize, maxFiles, setValue, onDrop]
|
|
288
401
|
);
|
|
289
402
|
const accept = allowedFileTypes.join(",");
|
|
290
403
|
const { getRootProps, getInputProps } = (0, import_react_dropzone.useDropzone)({
|
|
@@ -309,7 +422,7 @@ var Dropzone = ({
|
|
|
309
422
|
};
|
|
310
423
|
const handleOnClick = (event) => {
|
|
311
424
|
if (!enableDropArea && rootProps.onClick) rootProps.onClick(event);
|
|
312
|
-
if (onClick) onClick;
|
|
425
|
+
if (onClick) onClick(event);
|
|
313
426
|
};
|
|
314
427
|
const getFieldValue = () => {
|
|
315
428
|
const field = getValues();
|
|
@@ -317,7 +430,7 @@ var Dropzone = ({
|
|
|
317
430
|
};
|
|
318
431
|
const hasFiles = getFieldValue().length > 0;
|
|
319
432
|
return enableDropArea ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(DropzoneContainer, __spreadProps(__spreadValues({ sx: outerBoxStyles }, rootProps), { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_layout.Box, { sx: innerBoxStyles, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_layout.Stack, { spacing: 2, alignItems: "center", justifyContent: "center", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
320
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
433
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_icon2.CloudUploadIcon, { fontSize: "xlarge", color: "secondary" }),
|
|
321
434
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_typography.Typography, { variant: "subtitle2", fontWeight: "700", children: "Drag and Drop Files Here" }),
|
|
322
435
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_divider.Divider, { flexItem: true, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_typography.Typography, { variant: "subtitle2", children: "OR" }) }),
|
|
323
436
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
@@ -343,7 +456,7 @@ var Dropzone = ({
|
|
|
343
456
|
onClick: handleOnClick,
|
|
344
457
|
inputProps,
|
|
345
458
|
onChange: handleOnChange,
|
|
346
|
-
startIcon: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
459
|
+
startIcon: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_icon2.PlusIcon, {}),
|
|
347
460
|
children: hasFiles ? "Add More Files" : "Add File(s)"
|
|
348
461
|
}
|
|
349
462
|
);
|
|
@@ -358,57 +471,6 @@ var import_mui_icon3 = require("@availity/mui-icon");
|
|
|
358
471
|
var import_mui_layout2 = require("@availity/mui-layout");
|
|
359
472
|
var import_mui_typography2 = require("@availity/mui-typography");
|
|
360
473
|
var import_upload_core = __toESM(require("@availity/upload-core"));
|
|
361
|
-
|
|
362
|
-
// src/lib/util.ts
|
|
363
|
-
var import_mui_icon2 = require("@availity/mui-icon");
|
|
364
|
-
function formatBytes(bytes, decimals = 2) {
|
|
365
|
-
if (!+bytes) return "0 Bytes";
|
|
366
|
-
const k = 1024;
|
|
367
|
-
const dm = decimals < 0 ? 0 : decimals;
|
|
368
|
-
const sizes = ["Bytes", "KB", "MB", "GB"];
|
|
369
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
370
|
-
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
371
|
-
}
|
|
372
|
-
var FILE_EXT_ICONS = {
|
|
373
|
-
png: import_mui_icon2.FileImageIcon,
|
|
374
|
-
jpg: import_mui_icon2.FileImageIcon,
|
|
375
|
-
jpeg: import_mui_icon2.FileImageIcon,
|
|
376
|
-
gif: import_mui_icon2.FileImageIcon,
|
|
377
|
-
csv: import_mui_icon2.FileCsvIcon,
|
|
378
|
-
ppt: import_mui_icon2.FilePowerpointIcon,
|
|
379
|
-
pptx: import_mui_icon2.FilePowerpointIcon,
|
|
380
|
-
xls: import_mui_icon2.FileExcelIcon,
|
|
381
|
-
xlsx: import_mui_icon2.FileExcelIcon,
|
|
382
|
-
doc: import_mui_icon2.FileWordIcon,
|
|
383
|
-
docx: import_mui_icon2.FileWordIcon,
|
|
384
|
-
txt: import_mui_icon2.FileLinesIcon,
|
|
385
|
-
text: import_mui_icon2.FileLinesIcon,
|
|
386
|
-
zip: import_mui_icon2.FileArchiveIcon,
|
|
387
|
-
"7zip": import_mui_icon2.FileArchiveIcon,
|
|
388
|
-
xml: import_mui_icon2.FileCodeIcon,
|
|
389
|
-
html: import_mui_icon2.FileCodeIcon,
|
|
390
|
-
pdf: import_mui_icon2.FilePdfIcon
|
|
391
|
-
};
|
|
392
|
-
var isValidKey = (key) => key ? key in FILE_EXT_ICONS : false;
|
|
393
|
-
var getFileExtension = (fileName) => {
|
|
394
|
-
var _a;
|
|
395
|
-
return ((_a = fileName.split(".").pop()) == null ? void 0 : _a.toLowerCase()) || "";
|
|
396
|
-
};
|
|
397
|
-
var getFileExtIcon = (fileName) => {
|
|
398
|
-
const ext = getFileExtension(fileName);
|
|
399
|
-
return isValidKey(ext) ? FILE_EXT_ICONS[ext] : import_mui_icon2.FileIcon;
|
|
400
|
-
};
|
|
401
|
-
var dedupeErrors = (errors) => {
|
|
402
|
-
const dedupedErrors = errors.reduce((acc, error) => {
|
|
403
|
-
if (!acc.find((err) => err.code === error.code)) {
|
|
404
|
-
acc.push(error);
|
|
405
|
-
}
|
|
406
|
-
return acc;
|
|
407
|
-
}, []);
|
|
408
|
-
return dedupedErrors;
|
|
409
|
-
};
|
|
410
|
-
|
|
411
|
-
// src/lib/Dropzone2.tsx
|
|
412
474
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
413
475
|
var counter2 = createCounter();
|
|
414
476
|
function startUpload(file, options) {
|
|
@@ -430,6 +492,7 @@ var Dropzone2 = ({
|
|
|
430
492
|
enableDropArea = true,
|
|
431
493
|
maxFiles,
|
|
432
494
|
maxSize,
|
|
495
|
+
maxTotalSize,
|
|
433
496
|
multiple,
|
|
434
497
|
name,
|
|
435
498
|
onChange,
|
|
@@ -461,6 +524,27 @@ var Dropzone2 = ({
|
|
|
461
524
|
message: `Too many files. You may only upload ${maxFiles} file(s).`
|
|
462
525
|
});
|
|
463
526
|
}
|
|
527
|
+
if (uploadOptions.allowedFileNameCharacters) {
|
|
528
|
+
const fileName = file.name.substring(0, file.name.lastIndexOf("."));
|
|
529
|
+
const regExp = new RegExp(`([^${uploadOptions.allowedFileNameCharacters}])`, "g");
|
|
530
|
+
if (fileName.match(regExp) !== null) {
|
|
531
|
+
errors.push({
|
|
532
|
+
code: "invalid-file-name-characters",
|
|
533
|
+
message: "File name contains characters not allowed"
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
if (allowedFileTypes.length > 0) {
|
|
538
|
+
const fileName = file.name;
|
|
539
|
+
const fileExt = fileName.substring(fileName.lastIndexOf(".")).toLowerCase();
|
|
540
|
+
const lowerCaseAllowedTypes = allowedFileTypes.map((type) => type.toLowerCase());
|
|
541
|
+
if (!lowerCaseAllowedTypes.includes(fileExt)) {
|
|
542
|
+
errors.push({
|
|
543
|
+
code: "file-invalid-type",
|
|
544
|
+
message: `File type ${fileExt} is not allowed`
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
}
|
|
464
548
|
if (validator) {
|
|
465
549
|
const validatorErrors = validator(file);
|
|
466
550
|
if (validatorErrors) {
|
|
@@ -473,7 +557,7 @@ var Dropzone2 = ({
|
|
|
473
557
|
}
|
|
474
558
|
return errors.length > 0 ? dedupeErrors(errors) : null;
|
|
475
559
|
},
|
|
476
|
-
[maxFiles, validator]
|
|
560
|
+
[maxFiles, validator, uploadOptions.allowedFileNameCharacters, allowedFileTypes, watch, name]
|
|
477
561
|
);
|
|
478
562
|
const handleOnDrop = (0, import_react2.useCallback)(
|
|
479
563
|
(acceptedFiles, fileRejections, event) => __async(void 0, null, function* () {
|
|
@@ -484,8 +568,49 @@ var Dropzone2 = ({
|
|
|
484
568
|
}
|
|
485
569
|
setTotalSize((prev) => prev + newSize);
|
|
486
570
|
const previous = (_a2 = watch(name)) != null ? _a2 : [];
|
|
487
|
-
|
|
571
|
+
if (maxTotalSize) {
|
|
572
|
+
const currentTotalSize = previous.reduce((sum, upload) => sum + upload.file.size, 0);
|
|
573
|
+
let newSize2 = 0;
|
|
574
|
+
const availableSize = Math.max(0, maxTotalSize - currentTotalSize);
|
|
575
|
+
let sizeCounter = 0;
|
|
576
|
+
const cutoffIndex = acceptedFiles.findIndex((file) => {
|
|
577
|
+
sizeCounter += file.size;
|
|
578
|
+
return sizeCounter > availableSize;
|
|
579
|
+
});
|
|
580
|
+
if (cutoffIndex !== -1) {
|
|
581
|
+
const filesToAdd2 = acceptedFiles.slice(0, cutoffIndex === 0 ? 0 : cutoffIndex);
|
|
582
|
+
fileRejections.push({
|
|
583
|
+
file: acceptedFiles[cutoffIndex],
|
|
584
|
+
errors: [
|
|
585
|
+
{
|
|
586
|
+
code: "upload-too-large",
|
|
587
|
+
message: `Total upload size exceeds the limit of ${formatBytes(maxTotalSize)}.`
|
|
588
|
+
}
|
|
589
|
+
],
|
|
590
|
+
id: counter2.increment()
|
|
591
|
+
});
|
|
592
|
+
acceptedFiles = filesToAdd2;
|
|
593
|
+
}
|
|
594
|
+
newSize2 = acceptedFiles.reduce((sum, file) => sum + file.size, 0);
|
|
595
|
+
setTotalSize((prev) => prev + newSize2);
|
|
596
|
+
}
|
|
597
|
+
const remainingSlots = maxFiles ? Math.max(0, maxFiles - previous.length) : acceptedFiles.length;
|
|
598
|
+
const filesToAdd = acceptedFiles.slice(0, remainingSlots);
|
|
599
|
+
const uploads = filesToAdd.map((file) => startUpload(file, uploadOptions));
|
|
488
600
|
setValue(name, previous.concat(yield Promise.all(uploads)));
|
|
601
|
+
if (maxFiles && acceptedFiles.length > remainingSlots) {
|
|
602
|
+
fileRejections.push({
|
|
603
|
+
file: acceptedFiles[remainingSlots],
|
|
604
|
+
// Use the first excess file
|
|
605
|
+
errors: [
|
|
606
|
+
{
|
|
607
|
+
code: "too-many-files",
|
|
608
|
+
message: `Too many files. You may only upload ${maxFiles} file(s).`
|
|
609
|
+
}
|
|
610
|
+
],
|
|
611
|
+
id: counter2.increment()
|
|
612
|
+
});
|
|
613
|
+
}
|
|
489
614
|
if (fileRejections.length > 0) {
|
|
490
615
|
const TOO_MANY_FILES_CODE = "too-many-files";
|
|
491
616
|
let hasTooManyFiles = false;
|
|
@@ -512,7 +637,7 @@ var Dropzone2 = ({
|
|
|
512
637
|
if (setFileRejections) setFileRejections(fileRejections);
|
|
513
638
|
if (onDrop) onDrop(acceptedFiles, fileRejections, event);
|
|
514
639
|
}),
|
|
515
|
-
[setFileRejections]
|
|
640
|
+
[setFileRejections, setTotalSize, watch, name, maxTotalSize, maxFiles, uploadOptions, setValue, onDrop]
|
|
516
641
|
);
|
|
517
642
|
const { getRootProps, getInputProps } = (0, import_react_dropzone2.useDropzone)({
|
|
518
643
|
onDrop: handleOnDrop,
|
|
@@ -536,7 +661,7 @@ var Dropzone2 = ({
|
|
|
536
661
|
};
|
|
537
662
|
const handleOnClick = (event) => {
|
|
538
663
|
if (!enableDropArea && rootProps.onClick) rootProps.onClick(event);
|
|
539
|
-
if (onClick) onClick;
|
|
664
|
+
if (onClick) onClick(event);
|
|
540
665
|
};
|
|
541
666
|
const getFieldValue = () => {
|
|
542
667
|
const field = getValues();
|
|
@@ -582,6 +707,7 @@ var import_mui_list = require("@availity/mui-list");
|
|
|
582
707
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
583
708
|
var codes = {
|
|
584
709
|
"file-too-large": "File exceeds maximum size",
|
|
710
|
+
"upload-too-large": "File causes maximum total upload size to be exceeded",
|
|
585
711
|
"file-invalid-type": "File has an invalid type",
|
|
586
712
|
"file-too-small": "File is smaller than minimum size",
|
|
587
713
|
"too-many-file": "Too many files",
|
|
@@ -1087,14 +1213,18 @@ var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
|
1087
1213
|
var FileTypesMessage = ({
|
|
1088
1214
|
allowedFileTypes = [],
|
|
1089
1215
|
customSizeMessage,
|
|
1216
|
+
customTotalSizeMessage,
|
|
1090
1217
|
customTypesMessage,
|
|
1091
1218
|
maxFileSize,
|
|
1219
|
+
maxTotalSize,
|
|
1092
1220
|
variant = "caption"
|
|
1093
1221
|
}) => {
|
|
1094
1222
|
const fileSizeMsg = customSizeMessage || (typeof maxFileSize === "number" ? `Maximum file size is ${formatBytes(maxFileSize)}. ` : null);
|
|
1223
|
+
const totalFileSizeMsg = customTotalSizeMessage || (typeof maxTotalSize === "number" ? `Maximum total upload size is ${formatBytes(maxTotalSize)}. ` : null);
|
|
1095
1224
|
const fileTypesMsg = customTypesMessage || (allowedFileTypes.length > 0 ? `Supported file types include: ${allowedFileTypes.join(", ")}` : "All file types allowed.");
|
|
1096
1225
|
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_mui_typography4.Typography, { variant, children: [
|
|
1097
1226
|
fileSizeMsg,
|
|
1227
|
+
totalFileSizeMsg,
|
|
1098
1228
|
fileTypesMsg
|
|
1099
1229
|
] });
|
|
1100
1230
|
};
|
|
@@ -1102,12 +1232,14 @@ var FileTypesMessage = ({
|
|
|
1102
1232
|
// src/lib/HeaderMessage.tsx
|
|
1103
1233
|
var import_mui_typography5 = require("@availity/mui-typography");
|
|
1104
1234
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
1105
|
-
var HeaderMessage = ({ maxFiles, maxSize }) => {
|
|
1235
|
+
var HeaderMessage = ({ maxFiles, maxSize, maxTotalSize }) => {
|
|
1106
1236
|
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_mui_typography5.Typography, { variant: "h6", children: [
|
|
1107
1237
|
"Attach up to ",
|
|
1108
1238
|
maxFiles,
|
|
1109
1239
|
" file(s), with a maximum individual size of ",
|
|
1110
|
-
formatBytes(maxSize)
|
|
1240
|
+
formatBytes(maxSize),
|
|
1241
|
+
" ",
|
|
1242
|
+
maxTotalSize && `and a maximum total size of ${formatBytes(maxTotalSize)}`
|
|
1111
1243
|
] });
|
|
1112
1244
|
};
|
|
1113
1245
|
|
|
@@ -1122,6 +1254,7 @@ var FileSelector = ({
|
|
|
1122
1254
|
clientId,
|
|
1123
1255
|
children,
|
|
1124
1256
|
customSizeMessage,
|
|
1257
|
+
customTotalSizeMessage,
|
|
1125
1258
|
customTypesMessage,
|
|
1126
1259
|
customerId,
|
|
1127
1260
|
customFileRow,
|
|
@@ -1132,6 +1265,7 @@ var FileSelector = ({
|
|
|
1132
1265
|
label = "Upload file",
|
|
1133
1266
|
maxFiles,
|
|
1134
1267
|
maxSize,
|
|
1268
|
+
maxTotalSize,
|
|
1135
1269
|
multiple = true,
|
|
1136
1270
|
onChange,
|
|
1137
1271
|
onDrop,
|
|
@@ -1191,10 +1325,12 @@ var FileSelector = ({
|
|
|
1191
1325
|
{
|
|
1192
1326
|
name,
|
|
1193
1327
|
allowedFileTypes,
|
|
1328
|
+
allowedFileNameCharacters,
|
|
1194
1329
|
disabled,
|
|
1195
1330
|
enableDropArea,
|
|
1196
1331
|
maxFiles,
|
|
1197
1332
|
maxSize,
|
|
1333
|
+
maxTotalSize,
|
|
1198
1334
|
multiple,
|
|
1199
1335
|
onChange,
|
|
1200
1336
|
onDrop,
|
|
@@ -1208,7 +1344,9 @@ var FileSelector = ({
|
|
|
1208
1344
|
{
|
|
1209
1345
|
allowedFileTypes,
|
|
1210
1346
|
maxFileSize: maxSize,
|
|
1347
|
+
maxTotalSize,
|
|
1211
1348
|
customSizeMessage,
|
|
1349
|
+
customTotalSizeMessage,
|
|
1212
1350
|
customTypesMessage,
|
|
1213
1351
|
variant: "caption"
|
|
1214
1352
|
}
|
|
@@ -1216,11 +1354,12 @@ var FileSelector = ({
|
|
|
1216
1354
|
children
|
|
1217
1355
|
] }) : /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_mui_layout7.Grid, { container: true, rowSpacing: 3, flexDirection: "column", children: [
|
|
1218
1356
|
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_mui_layout7.Grid, { children: [
|
|
1219
|
-
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(HeaderMessage, { maxFiles, maxSize }),
|
|
1357
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(HeaderMessage, { maxFiles, maxSize, maxTotalSize }),
|
|
1220
1358
|
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1221
1359
|
FileTypesMessage,
|
|
1222
1360
|
{
|
|
1223
1361
|
allowedFileTypes,
|
|
1362
|
+
customTotalSizeMessage,
|
|
1224
1363
|
customSizeMessage,
|
|
1225
1364
|
customTypesMessage,
|
|
1226
1365
|
variant: "body2"
|
|
@@ -1233,10 +1372,12 @@ var FileSelector = ({
|
|
|
1233
1372
|
{
|
|
1234
1373
|
name,
|
|
1235
1374
|
allowedFileTypes,
|
|
1375
|
+
allowedFileNameCharacters,
|
|
1236
1376
|
disabled,
|
|
1237
1377
|
enableDropArea,
|
|
1238
1378
|
maxFiles,
|
|
1239
1379
|
maxSize,
|
|
1380
|
+
maxTotalSize,
|
|
1240
1381
|
multiple,
|
|
1241
1382
|
onChange,
|
|
1242
1383
|
onDrop,
|
|
@@ -1298,6 +1439,7 @@ var FileSelector2 = ({
|
|
|
1298
1439
|
clientId,
|
|
1299
1440
|
children,
|
|
1300
1441
|
customSizeMessage,
|
|
1442
|
+
customTotalSizeMessage,
|
|
1301
1443
|
customTypesMessage,
|
|
1302
1444
|
customerId,
|
|
1303
1445
|
customFileRow,
|
|
@@ -1308,6 +1450,7 @@ var FileSelector2 = ({
|
|
|
1308
1450
|
label = "Upload file",
|
|
1309
1451
|
maxFiles,
|
|
1310
1452
|
maxSize,
|
|
1453
|
+
maxTotalSize,
|
|
1311
1454
|
multiple = true,
|
|
1312
1455
|
onChange,
|
|
1313
1456
|
onDrop,
|
|
@@ -1368,6 +1511,7 @@ var FileSelector2 = ({
|
|
|
1368
1511
|
enableDropArea,
|
|
1369
1512
|
maxFiles,
|
|
1370
1513
|
maxSize,
|
|
1514
|
+
maxTotalSize,
|
|
1371
1515
|
multiple,
|
|
1372
1516
|
onChange,
|
|
1373
1517
|
onDrop,
|
|
@@ -1382,7 +1526,9 @@ var FileSelector2 = ({
|
|
|
1382
1526
|
{
|
|
1383
1527
|
allowedFileTypes,
|
|
1384
1528
|
maxFileSize: maxSize,
|
|
1529
|
+
maxTotalSize,
|
|
1385
1530
|
customSizeMessage,
|
|
1531
|
+
customTotalSizeMessage,
|
|
1386
1532
|
customTypesMessage,
|
|
1387
1533
|
variant: "caption"
|
|
1388
1534
|
}
|
|
@@ -1390,12 +1536,13 @@ var FileSelector2 = ({
|
|
|
1390
1536
|
children
|
|
1391
1537
|
] }) : /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_mui_layout8.Grid, { container: true, rowSpacing: 3, flexDirection: "column", children: [
|
|
1392
1538
|
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_mui_layout8.Grid, { children: [
|
|
1393
|
-
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(HeaderMessage, { maxFiles, maxSize }),
|
|
1539
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(HeaderMessage, { maxFiles, maxSize, maxTotalSize }),
|
|
1394
1540
|
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1395
1541
|
FileTypesMessage,
|
|
1396
1542
|
{
|
|
1397
1543
|
allowedFileTypes,
|
|
1398
1544
|
customSizeMessage,
|
|
1545
|
+
customTotalSizeMessage,
|
|
1399
1546
|
customTypesMessage,
|
|
1400
1547
|
variant: "body2"
|
|
1401
1548
|
}
|
|
@@ -1411,6 +1558,7 @@ var FileSelector2 = ({
|
|
|
1411
1558
|
enableDropArea,
|
|
1412
1559
|
maxFiles,
|
|
1413
1560
|
maxSize,
|
|
1561
|
+
maxTotalSize,
|
|
1414
1562
|
multiple,
|
|
1415
1563
|
onChange,
|
|
1416
1564
|
onDrop,
|