@availity/mui-file-selector 1.0.0-alpha.0 → 1.1.0
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 +48 -0
- package/README.md +107 -15
- package/dist/index.d.mts +208 -22
- package/dist/index.d.ts +208 -22
- package/dist/index.js +234 -97
- package/dist/index.mjs +226 -97
- package/introduction.mdx +3 -0
- package/package.json +11 -11
- package/src/index.ts +7 -0
- package/src/lib/Dropzone.test.tsx +2 -2
- package/src/lib/Dropzone.tsx +92 -32
- package/src/lib/FileList.test.tsx +25 -1
- package/src/lib/FileList.tsx +66 -28
- package/src/lib/FilePickerBtn.test.tsx +3 -1
- package/src/lib/FilePickerBtn.tsx +23 -21
- package/src/lib/FileSelector.stories.tsx +66 -4
- package/src/lib/FileSelector.test.tsx +11 -1
- package/src/lib/FileSelector.tsx +109 -90
- package/src/lib/FileTypesMessage.test.tsx +2 -2
- package/src/lib/FileTypesMessage.tsx +11 -6
- package/src/lib/HeaderMessage.tsx +1 -1
- package/src/lib/useFileDelivery.tsx +3 -1
- package/src/lib/useUploadCore.tsx +10 -3
package/dist/index.js
CHANGED
|
@@ -79,21 +79,22 @@ var __async = (__this, __arguments, generator) => {
|
|
|
79
79
|
// src/index.ts
|
|
80
80
|
var index_exports = {};
|
|
81
81
|
__export(index_exports, {
|
|
82
|
+
Dropzone: () => Dropzone,
|
|
83
|
+
ErrorAlert: () => ErrorAlert,
|
|
84
|
+
FileList: () => FileList,
|
|
85
|
+
FilePickerBtn: () => FilePickerBtn,
|
|
86
|
+
FileRow: () => FileRow,
|
|
82
87
|
FileSelector: () => FileSelector,
|
|
83
|
-
|
|
88
|
+
FileTypesMessage: () => FileTypesMessage,
|
|
89
|
+
HeaderMessage: () => HeaderMessage,
|
|
90
|
+
UploadProgressBar: () => UploadProgressBar,
|
|
91
|
+
useUploadCore: () => useUploadCore
|
|
84
92
|
});
|
|
85
93
|
module.exports = __toCommonJS(index_exports);
|
|
86
94
|
|
|
87
|
-
// src/lib/FileSelector.tsx
|
|
88
|
-
var import_react3 = require("react");
|
|
89
|
-
var import_react_hook_form3 = require("react-hook-form");
|
|
90
|
-
var import_react_query2 = require("@tanstack/react-query");
|
|
91
|
-
var import_mui_button3 = require("@availity/mui-button");
|
|
92
|
-
var import_mui_layout3 = require("@availity/mui-layout");
|
|
93
|
-
var import_mui_typography3 = require("@availity/mui-typography");
|
|
94
|
-
|
|
95
95
|
// src/lib/Dropzone.tsx
|
|
96
96
|
var import_react = require("react");
|
|
97
|
+
var import_styles = require("@mui/material/styles");
|
|
97
98
|
var import_react_dropzone = require("react-dropzone");
|
|
98
99
|
var import_react_hook_form2 = require("react-hook-form");
|
|
99
100
|
var import_mui_divider = require("@availity/mui-divider");
|
|
@@ -109,7 +110,7 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
|
109
110
|
var FilePickerBtn = (_a) => {
|
|
110
111
|
var _b = _a, {
|
|
111
112
|
name,
|
|
112
|
-
children
|
|
113
|
+
children,
|
|
113
114
|
color,
|
|
114
115
|
inputId,
|
|
115
116
|
inputProps = {},
|
|
@@ -126,25 +127,30 @@ var FilePickerBtn = (_a) => {
|
|
|
126
127
|
"onChange",
|
|
127
128
|
"onClick"
|
|
128
129
|
]);
|
|
129
|
-
const { register } = (0, import_react_hook_form.useFormContext)();
|
|
130
130
|
const { accept, multiple, ref, style, type: inputType } = inputProps;
|
|
131
|
-
const field = register(name);
|
|
132
131
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
133
132
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
133
|
+
import_react_hook_form.Controller,
|
|
134
|
+
{
|
|
135
|
+
name,
|
|
136
|
+
defaultValue: [],
|
|
137
|
+
render: ({ field }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
138
|
+
import_mui_form_utils.Input,
|
|
139
|
+
__spreadProps(__spreadValues({}, field), {
|
|
140
|
+
onChange,
|
|
141
|
+
value: [],
|
|
142
|
+
inputRef: ref,
|
|
143
|
+
type: inputType,
|
|
144
|
+
sx: style,
|
|
145
|
+
inputProps: {
|
|
146
|
+
accept,
|
|
147
|
+
size: maxSize != null ? maxSize : void 0,
|
|
148
|
+
multiple
|
|
149
|
+
},
|
|
150
|
+
id: inputId
|
|
151
|
+
})
|
|
152
|
+
)
|
|
153
|
+
}
|
|
148
154
|
),
|
|
149
155
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_mui_button.Button, __spreadProps(__spreadValues({ color }, rest), { onClick, fullWidth: false, children }))
|
|
150
156
|
] });
|
|
@@ -176,43 +182,64 @@ var createCounter = () => {
|
|
|
176
182
|
};
|
|
177
183
|
};
|
|
178
184
|
var counter = createCounter();
|
|
185
|
+
var DropzoneContainer = (0, import_styles.styled)(import_mui_layout.Box, { name: "AvDropzoneContainer", slot: "root" })({
|
|
186
|
+
".MuiDivider-root": {
|
|
187
|
+
width: "196px",
|
|
188
|
+
marginLeft: "auto",
|
|
189
|
+
marginRight: "auto"
|
|
190
|
+
}
|
|
191
|
+
});
|
|
179
192
|
var Dropzone = ({
|
|
180
193
|
allowedFileTypes = [],
|
|
181
194
|
disabled,
|
|
195
|
+
enableDropArea = true,
|
|
182
196
|
maxFiles,
|
|
183
197
|
maxSize,
|
|
184
198
|
multiple,
|
|
185
199
|
name,
|
|
186
200
|
onChange,
|
|
187
201
|
onClick,
|
|
202
|
+
onDrop,
|
|
188
203
|
setFileRejections,
|
|
189
|
-
setTotalSize
|
|
204
|
+
setTotalSize,
|
|
205
|
+
validator
|
|
190
206
|
}) => {
|
|
191
|
-
const { setValue, watch } = (0, import_react_hook_form2.useFormContext)();
|
|
192
|
-
const
|
|
207
|
+
const { getValues, setValue, watch } = (0, import_react_hook_form2.useFormContext)();
|
|
208
|
+
const handleValidation = (0, import_react.useCallback)(
|
|
193
209
|
(file) => {
|
|
194
210
|
var _a2;
|
|
195
211
|
const previous = (_a2 = watch(name)) != null ? _a2 : [];
|
|
212
|
+
const errors = [];
|
|
196
213
|
const isDuplicate = previous.some((prev) => prev.name === file.name);
|
|
197
214
|
if (isDuplicate) {
|
|
198
|
-
|
|
215
|
+
errors.push({
|
|
199
216
|
code: "duplicate-name",
|
|
200
217
|
message: "A file with this name already exists"
|
|
201
|
-
};
|
|
218
|
+
});
|
|
202
219
|
}
|
|
203
220
|
const hasMaxFiles = maxFiles && previous.length >= maxFiles;
|
|
204
221
|
if (hasMaxFiles) {
|
|
205
|
-
|
|
222
|
+
errors.push({
|
|
206
223
|
code: "too-many-files",
|
|
207
224
|
message: `Too many files. You may only upload ${maxFiles} file(s).`
|
|
208
|
-
};
|
|
225
|
+
});
|
|
209
226
|
}
|
|
210
|
-
|
|
227
|
+
if (validator) {
|
|
228
|
+
const validatorErrors = validator(file);
|
|
229
|
+
if (validatorErrors) {
|
|
230
|
+
if (Array.isArray(validatorErrors)) {
|
|
231
|
+
errors.push(...validatorErrors);
|
|
232
|
+
} else {
|
|
233
|
+
errors.push(validatorErrors);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return errors.length > 0 ? errors : null;
|
|
211
238
|
},
|
|
212
|
-
[maxFiles]
|
|
239
|
+
[maxFiles, validator]
|
|
213
240
|
);
|
|
214
|
-
const
|
|
215
|
-
(acceptedFiles, fileRejections) => {
|
|
241
|
+
const handleOnDrop = (0, import_react.useCallback)(
|
|
242
|
+
(acceptedFiles, fileRejections, event) => {
|
|
216
243
|
var _a2;
|
|
217
244
|
let newSize = 0;
|
|
218
245
|
for (const file of acceptedFiles) {
|
|
@@ -227,34 +254,44 @@ var Dropzone = ({
|
|
|
227
254
|
}
|
|
228
255
|
}
|
|
229
256
|
if (setFileRejections) setFileRejections(fileRejections);
|
|
257
|
+
if (onDrop) onDrop(acceptedFiles, fileRejections, event);
|
|
230
258
|
},
|
|
231
259
|
[setFileRejections]
|
|
232
260
|
);
|
|
233
261
|
const accept = allowedFileTypes.join(",");
|
|
234
262
|
const { getRootProps, getInputProps } = (0, import_react_dropzone.useDropzone)({
|
|
235
|
-
onDrop,
|
|
263
|
+
onDrop: handleOnDrop,
|
|
236
264
|
maxSize,
|
|
237
265
|
maxFiles,
|
|
238
266
|
disabled,
|
|
239
267
|
multiple,
|
|
240
268
|
accept,
|
|
241
|
-
validator
|
|
269
|
+
validator: handleValidation
|
|
242
270
|
});
|
|
243
271
|
const inputProps = getInputProps({
|
|
244
272
|
multiple,
|
|
245
273
|
accept,
|
|
246
274
|
onChange
|
|
247
275
|
});
|
|
276
|
+
const _a = getRootProps(), { role, tabIndex } = _a, rootProps = __objRest(_a, ["role", "tabIndex"]);
|
|
248
277
|
const handleOnChange = (event) => {
|
|
249
278
|
if (inputProps.onChange) {
|
|
250
279
|
inputProps.onChange(event);
|
|
251
280
|
}
|
|
252
281
|
};
|
|
253
|
-
const
|
|
254
|
-
|
|
282
|
+
const handleOnClick = (event) => {
|
|
283
|
+
if (!enableDropArea && rootProps.onClick) rootProps.onClick(event);
|
|
284
|
+
if (onClick) onClick;
|
|
285
|
+
};
|
|
286
|
+
const getFieldValue = () => {
|
|
287
|
+
const field = getValues();
|
|
288
|
+
return field[name] || [];
|
|
289
|
+
};
|
|
290
|
+
const hasFiles = getFieldValue().length > 0;
|
|
291
|
+
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: [
|
|
255
292
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_icon.CloudUploadIcon, { fontSize: "xlarge", color: "secondary" }),
|
|
256
293
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_typography.Typography, { variant: "subtitle2", fontWeight: "700", children: "Drag and Drop Files Here" }),
|
|
257
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_divider.Divider, { children: "OR" }),
|
|
294
|
+
/* @__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" }) }),
|
|
258
295
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
259
296
|
FilePickerBtn,
|
|
260
297
|
{
|
|
@@ -264,10 +301,24 @@ var Dropzone = ({
|
|
|
264
301
|
maxSize,
|
|
265
302
|
onClick,
|
|
266
303
|
inputProps,
|
|
267
|
-
onChange: handleOnChange
|
|
304
|
+
onChange: handleOnChange,
|
|
305
|
+
children: "Browse Files"
|
|
268
306
|
}
|
|
269
307
|
)
|
|
270
|
-
] }) }) }) }))
|
|
308
|
+
] }) }) }) })) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
309
|
+
FilePickerBtn,
|
|
310
|
+
{
|
|
311
|
+
name,
|
|
312
|
+
color: "tertiary",
|
|
313
|
+
disabled,
|
|
314
|
+
maxSize,
|
|
315
|
+
onClick: handleOnClick,
|
|
316
|
+
inputProps,
|
|
317
|
+
onChange: handleOnChange,
|
|
318
|
+
startIcon: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_icon.PlusIcon, {}),
|
|
319
|
+
children: hasFiles ? "Add More Files" : "Add File(s)"
|
|
320
|
+
}
|
|
321
|
+
);
|
|
271
322
|
};
|
|
272
323
|
|
|
273
324
|
// src/lib/ErrorAlert.tsx
|
|
@@ -386,25 +437,36 @@ function startUpload(file, options) {
|
|
|
386
437
|
return upload;
|
|
387
438
|
});
|
|
388
439
|
}
|
|
389
|
-
function useUploadCore(file, options) {
|
|
440
|
+
function useUploadCore(file, options, queryOptions) {
|
|
390
441
|
const isQueryEnabled = !!file;
|
|
391
|
-
return (0, import_react_query.useQuery)(
|
|
442
|
+
return (0, import_react_query.useQuery)(__spreadValues({
|
|
443
|
+
queryKey: ["upload", file.name, options],
|
|
444
|
+
queryFn: () => startUpload(file, options),
|
|
392
445
|
enabled: isQueryEnabled,
|
|
393
446
|
retry: false,
|
|
394
447
|
refetchOnWindowFocus: false
|
|
395
|
-
});
|
|
448
|
+
}, queryOptions));
|
|
396
449
|
}
|
|
397
450
|
|
|
398
451
|
// src/lib/FileList.tsx
|
|
399
452
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
400
|
-
var FileRow = ({
|
|
453
|
+
var FileRow = ({
|
|
454
|
+
file,
|
|
455
|
+
options,
|
|
456
|
+
onRemoveFile,
|
|
457
|
+
queryOptions,
|
|
458
|
+
customFileRow: CustomRow,
|
|
459
|
+
disableRemove = false
|
|
460
|
+
}) => {
|
|
401
461
|
const Icon = getFileExtIcon(file.name);
|
|
402
|
-
const { data: upload } = useUploadCore(file, options);
|
|
462
|
+
const { data: upload } = useUploadCore(file, options, queryOptions);
|
|
463
|
+
if (CustomRow) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CustomRow, { upload, options, onRemoveFile });
|
|
403
464
|
if (!upload) return null;
|
|
404
465
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
405
466
|
import_mui_list2.ListItem,
|
|
406
467
|
{
|
|
407
|
-
|
|
468
|
+
disableGutters: true,
|
|
469
|
+
secondaryAction: !disableRemove && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
408
470
|
import_mui_button2.IconButton,
|
|
409
471
|
{
|
|
410
472
|
title: "remove file",
|
|
@@ -427,27 +489,68 @@ var FileRow = ({ file, options, onRemoveFile }) => {
|
|
|
427
489
|
}
|
|
428
490
|
);
|
|
429
491
|
};
|
|
430
|
-
var FileList = ({
|
|
492
|
+
var FileList = ({
|
|
493
|
+
files,
|
|
494
|
+
options,
|
|
495
|
+
onRemoveFile,
|
|
496
|
+
queryOptions,
|
|
497
|
+
customFileRow,
|
|
498
|
+
disableRemove
|
|
499
|
+
}) => {
|
|
431
500
|
if (files.length === 0) return null;
|
|
432
501
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mui_list2.List, { children: files.map((file) => {
|
|
433
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
502
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
503
|
+
FileRow,
|
|
504
|
+
{
|
|
505
|
+
file,
|
|
506
|
+
options,
|
|
507
|
+
onRemoveFile,
|
|
508
|
+
queryOptions,
|
|
509
|
+
customFileRow,
|
|
510
|
+
disableRemove
|
|
511
|
+
},
|
|
512
|
+
file.name
|
|
513
|
+
);
|
|
434
514
|
}) });
|
|
435
515
|
};
|
|
436
516
|
|
|
517
|
+
// src/lib/FileSelector.tsx
|
|
518
|
+
var import_react3 = require("react");
|
|
519
|
+
var import_react_hook_form3 = require("react-hook-form");
|
|
520
|
+
var import_react_query2 = require("@tanstack/react-query");
|
|
521
|
+
var import_mui_layout3 = require("@availity/mui-layout");
|
|
522
|
+
var import_mui_typography4 = require("@availity/mui-typography");
|
|
523
|
+
|
|
437
524
|
// src/lib/FileTypesMessage.tsx
|
|
438
525
|
var import_mui_typography2 = require("@availity/mui-typography");
|
|
439
526
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
440
|
-
var FileTypesMessage = ({
|
|
527
|
+
var FileTypesMessage = ({
|
|
528
|
+
allowedFileTypes = [],
|
|
529
|
+
maxFileSize,
|
|
530
|
+
variant = "caption"
|
|
531
|
+
}) => {
|
|
441
532
|
const fileSizeMsg = typeof maxFileSize === "number" ? `Maximum file size is ${formatBytes(maxFileSize)}. ` : null;
|
|
442
|
-
const fileTypesMsg = allowedFileTypes.length > 0 ? `Supported file types include: ${allowedFileTypes.join(", ")}
|
|
443
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_mui_typography2.Typography, { variant
|
|
533
|
+
const fileTypesMsg = allowedFileTypes.length > 0 ? `Supported file types include: ${allowedFileTypes.join(", ")}` : "All file types allowed.";
|
|
534
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_mui_typography2.Typography, { variant, children: [
|
|
444
535
|
fileSizeMsg,
|
|
445
536
|
fileTypesMsg
|
|
446
537
|
] });
|
|
447
538
|
};
|
|
448
539
|
|
|
449
|
-
// src/lib/
|
|
540
|
+
// src/lib/HeaderMessage.tsx
|
|
541
|
+
var import_mui_typography3 = require("@availity/mui-typography");
|
|
450
542
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
543
|
+
var HeaderMessage = ({ maxFiles, maxSize }) => {
|
|
544
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_mui_typography3.Typography, { variant: "h6", children: [
|
|
545
|
+
"Attach up to ",
|
|
546
|
+
maxFiles,
|
|
547
|
+
" file(s), with a maximum individual size of ",
|
|
548
|
+
formatBytes(maxSize)
|
|
549
|
+
] });
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
// src/lib/FileSelector.tsx
|
|
553
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
451
554
|
var CLOUD_URL = "/cloud/web/appl/vault/upload/v1/resumable";
|
|
452
555
|
var FileSelector = ({
|
|
453
556
|
name,
|
|
@@ -457,7 +560,9 @@ var FileSelector = ({
|
|
|
457
560
|
clientId,
|
|
458
561
|
children,
|
|
459
562
|
customerId,
|
|
563
|
+
customFileRow,
|
|
460
564
|
disabled = false,
|
|
565
|
+
enableDropArea = true,
|
|
461
566
|
endpoint,
|
|
462
567
|
isCloud,
|
|
463
568
|
label = "Upload file",
|
|
@@ -465,80 +570,95 @@ var FileSelector = ({
|
|
|
465
570
|
maxSize,
|
|
466
571
|
multiple = true,
|
|
467
572
|
onChange,
|
|
468
|
-
|
|
469
|
-
onSuccess,
|
|
470
|
-
onError,
|
|
471
|
-
onFilePreUpload = [],
|
|
573
|
+
onDrop,
|
|
472
574
|
onUploadRemove,
|
|
473
|
-
|
|
575
|
+
queryOptions,
|
|
576
|
+
uploadOptions,
|
|
577
|
+
validator,
|
|
578
|
+
disableRemove
|
|
474
579
|
}) => {
|
|
475
580
|
const [totalSize, setTotalSize] = (0, import_react3.useState)(0);
|
|
476
581
|
const [fileRejections, setFileRejections] = (0, import_react3.useState)([]);
|
|
477
582
|
const client = (0, import_react_query2.useQueryClient)();
|
|
478
|
-
const
|
|
479
|
-
|
|
480
|
-
[name]: []
|
|
481
|
-
}
|
|
482
|
-
});
|
|
483
|
-
const options = {
|
|
583
|
+
const formMethods = (0, import_react_hook_form3.useFormContext)();
|
|
584
|
+
const options = __spreadProps(__spreadValues({}, uploadOptions), {
|
|
484
585
|
bucketId,
|
|
485
586
|
customerId,
|
|
486
587
|
clientId,
|
|
487
588
|
fileTypes: allowedFileTypes,
|
|
488
589
|
maxSize,
|
|
489
|
-
allowedFileNameCharacters
|
|
490
|
-
|
|
491
|
-
onSuccess,
|
|
492
|
-
retryDelays
|
|
493
|
-
};
|
|
494
|
-
if (onFilePreUpload) options.onPreStart = onFilePreUpload;
|
|
590
|
+
allowedFileNameCharacters
|
|
591
|
+
});
|
|
495
592
|
if (endpoint) options.endpoint = endpoint;
|
|
496
593
|
if (isCloud) options.endpoint = CLOUD_URL;
|
|
497
594
|
const handleOnRemoveFile = (uploadId, upload) => {
|
|
498
|
-
const prevFiles =
|
|
595
|
+
const prevFiles = formMethods.getValues(name);
|
|
499
596
|
const newFiles = prevFiles.filter((file) => file.name !== upload.file.name);
|
|
500
597
|
if (newFiles.length !== prevFiles.length) {
|
|
501
598
|
const removedFile = prevFiles.find((file) => file.name === upload.file.name);
|
|
502
|
-
|
|
599
|
+
try {
|
|
600
|
+
upload.abort();
|
|
601
|
+
} catch (e) {
|
|
602
|
+
console.error("Encountered an issue stopping the file upload");
|
|
603
|
+
}
|
|
604
|
+
formMethods.setValue(name, newFiles);
|
|
605
|
+
client.removeQueries(["upload", upload.file.name]);
|
|
503
606
|
if (removedFile == null ? void 0 : removedFile.size) setTotalSize(totalSize - removedFile.size);
|
|
504
607
|
if (onUploadRemove) onUploadRemove(newFiles, uploadId);
|
|
505
608
|
}
|
|
506
609
|
};
|
|
507
|
-
const files =
|
|
508
|
-
const handleOnSubmit = (values) => {
|
|
509
|
-
if (values[name].length === 0) return;
|
|
510
|
-
const queries = client.getQueriesData(["upload"]);
|
|
511
|
-
const uploads = [];
|
|
512
|
-
for (const [, data] of queries) {
|
|
513
|
-
if (data) uploads.push(data);
|
|
514
|
-
}
|
|
515
|
-
if (onSubmit) onSubmit(uploads, values);
|
|
516
|
-
};
|
|
610
|
+
const files = formMethods.watch(name);
|
|
517
611
|
const handleRemoveRejection = (id) => {
|
|
518
612
|
const rejections = fileRejections.filter((value) => value.id !== id);
|
|
519
613
|
setFileRejections(rejections);
|
|
520
614
|
};
|
|
521
|
-
return /* @__PURE__ */ (0,
|
|
522
|
-
/* @__PURE__ */ (0,
|
|
523
|
-
/* @__PURE__ */ (0,
|
|
524
|
-
/* @__PURE__ */ (0,
|
|
615
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
616
|
+
enableDropArea ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
617
|
+
label ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_mui_typography4.Typography, { marginBottom: "4px", children: label }) : null,
|
|
618
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
525
619
|
Dropzone,
|
|
526
620
|
{
|
|
527
621
|
name,
|
|
528
622
|
allowedFileTypes,
|
|
529
623
|
disabled,
|
|
624
|
+
enableDropArea,
|
|
530
625
|
maxFiles,
|
|
531
626
|
maxSize,
|
|
532
627
|
multiple,
|
|
533
628
|
onChange,
|
|
629
|
+
onDrop,
|
|
534
630
|
setFileRejections,
|
|
535
|
-
setTotalSize
|
|
631
|
+
setTotalSize,
|
|
632
|
+
validator
|
|
536
633
|
}
|
|
537
634
|
),
|
|
538
|
-
/* @__PURE__ */ (0,
|
|
635
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(FileTypesMessage, { allowedFileTypes, maxFileSize: maxSize, variant: "caption" }),
|
|
636
|
+
children
|
|
637
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_mui_layout3.Grid, { container: true, rowSpacing: 3, flexDirection: "column", children: [
|
|
638
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_mui_layout3.Grid, { children: [
|
|
639
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(HeaderMessage, { maxFiles, maxSize }),
|
|
640
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(FileTypesMessage, { allowedFileTypes, variant: "body2" })
|
|
641
|
+
] }),
|
|
642
|
+
children ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_mui_layout3.Grid, { children }) : null,
|
|
643
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_mui_layout3.Grid, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
644
|
+
Dropzone,
|
|
645
|
+
{
|
|
646
|
+
name,
|
|
647
|
+
allowedFileTypes,
|
|
648
|
+
disabled,
|
|
649
|
+
enableDropArea,
|
|
650
|
+
maxFiles,
|
|
651
|
+
maxSize,
|
|
652
|
+
multiple,
|
|
653
|
+
onChange,
|
|
654
|
+
onDrop,
|
|
655
|
+
setFileRejections,
|
|
656
|
+
setTotalSize,
|
|
657
|
+
validator
|
|
658
|
+
}
|
|
659
|
+
) })
|
|
539
660
|
] }),
|
|
540
|
-
|
|
541
|
-
fileRejections.length > 0 ? fileRejections.map((rejection) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
661
|
+
fileRejections.length > 0 ? fileRejections.map((rejection) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
542
662
|
ErrorAlert,
|
|
543
663
|
{
|
|
544
664
|
errors: rejection.errors,
|
|
@@ -548,12 +668,29 @@ var FileSelector = ({
|
|
|
548
668
|
},
|
|
549
669
|
rejection.id
|
|
550
670
|
)) : null,
|
|
551
|
-
/* @__PURE__ */ (0,
|
|
552
|
-
|
|
553
|
-
|
|
671
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
672
|
+
FileList,
|
|
673
|
+
{
|
|
674
|
+
files: files || [],
|
|
675
|
+
options,
|
|
676
|
+
onRemoveFile: handleOnRemoveFile,
|
|
677
|
+
queryOptions,
|
|
678
|
+
customFileRow,
|
|
679
|
+
disableRemove
|
|
680
|
+
}
|
|
681
|
+
)
|
|
682
|
+
] });
|
|
554
683
|
};
|
|
555
684
|
// Annotate the CommonJS export names for ESM import in node:
|
|
556
685
|
0 && (module.exports = {
|
|
686
|
+
Dropzone,
|
|
687
|
+
ErrorAlert,
|
|
688
|
+
FileList,
|
|
689
|
+
FilePickerBtn,
|
|
690
|
+
FileRow,
|
|
557
691
|
FileSelector,
|
|
558
|
-
|
|
692
|
+
FileTypesMessage,
|
|
693
|
+
HeaderMessage,
|
|
694
|
+
UploadProgressBar,
|
|
695
|
+
useUploadCore
|
|
559
696
|
});
|