@availity/mui-file-selector 2.0.6 → 3.0.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 +38 -0
- package/dist/index.d.ts +13 -13
- package/dist/index.js +424 -541
- package/package.json +28 -28
- package/project.json +5 -6
- package/src/lib/Dropzone.test.tsx +1 -1
- package/src/lib/Dropzone.tsx +3 -3
- package/src/lib/Dropzone2.test.tsx +1 -1
- package/src/lib/Dropzone2.tsx +3 -3
- package/src/lib/ErrorAlert.test.tsx +1 -1
- package/src/lib/FileList.test.tsx +2 -2
- package/src/lib/FileList.tsx +2 -4
- package/src/lib/FileList2.test.tsx +3 -3
- package/src/lib/FileList2.tsx +2 -4
- package/src/lib/FilePickerBtn.test.tsx +1 -1
- package/src/lib/FileSelector.tsx +2 -2
- package/src/lib/FileSelector2.tsx +1 -1
- package/src/lib/HeaderMessage.tsx +1 -3
- package/src/lib/useFileDelivery.tsx +1 -3
- package/src/lib/util.ts +2 -2
- package/dist/index.d.mts +0 -450
- package/dist/index.mjs +0 -1599
- package/jest.config.js +0 -7
- package/tsconfig.spec.json +0 -10
package/dist/index.mjs
DELETED
|
@@ -1,1599 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
|
-
var __async = (__this, __arguments, generator) => {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
var fulfilled = (value) => {
|
|
35
|
-
try {
|
|
36
|
-
step(generator.next(value));
|
|
37
|
-
} catch (e) {
|
|
38
|
-
reject(e);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
var rejected = (value) => {
|
|
42
|
-
try {
|
|
43
|
-
step(generator.throw(value));
|
|
44
|
-
} catch (e) {
|
|
45
|
-
reject(e);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// src/lib/Dropzone.tsx
|
|
54
|
-
import { useCallback } from "react";
|
|
55
|
-
import { styled } from "@mui/material/styles";
|
|
56
|
-
import { useDropzone } from "react-dropzone";
|
|
57
|
-
import { useFormContext } from "react-hook-form";
|
|
58
|
-
import { Divider } from "@availity/mui-divider";
|
|
59
|
-
import { CloudUploadIcon, PlusIcon } from "@availity/mui-icon";
|
|
60
|
-
import { Box, Stack } from "@availity/mui-layout";
|
|
61
|
-
import { Typography } from "@availity/mui-typography";
|
|
62
|
-
|
|
63
|
-
// src/lib/FilePickerBtn.tsx
|
|
64
|
-
import { Controller } from "react-hook-form";
|
|
65
|
-
import { Button } from "@availity/mui-button";
|
|
66
|
-
import { Input } from "@availity/mui-form-utils";
|
|
67
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
68
|
-
var FilePickerBtn = (_a) => {
|
|
69
|
-
var _b = _a, {
|
|
70
|
-
name,
|
|
71
|
-
children,
|
|
72
|
-
color,
|
|
73
|
-
inputId,
|
|
74
|
-
inputProps = {},
|
|
75
|
-
maxSize,
|
|
76
|
-
onChange,
|
|
77
|
-
onClick
|
|
78
|
-
} = _b, rest = __objRest(_b, [
|
|
79
|
-
"name",
|
|
80
|
-
"children",
|
|
81
|
-
"color",
|
|
82
|
-
"inputId",
|
|
83
|
-
"inputProps",
|
|
84
|
-
"maxSize",
|
|
85
|
-
"onChange",
|
|
86
|
-
"onClick"
|
|
87
|
-
]);
|
|
88
|
-
const { accept, multiple, ref, style, type: inputType } = inputProps;
|
|
89
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
90
|
-
/* @__PURE__ */ jsx(
|
|
91
|
-
Controller,
|
|
92
|
-
{
|
|
93
|
-
name,
|
|
94
|
-
defaultValue: [],
|
|
95
|
-
render: ({ field }) => /* @__PURE__ */ jsx(
|
|
96
|
-
Input,
|
|
97
|
-
__spreadProps(__spreadValues({}, field), {
|
|
98
|
-
onChange,
|
|
99
|
-
value: [],
|
|
100
|
-
inputRef: ref,
|
|
101
|
-
type: inputType,
|
|
102
|
-
sx: style,
|
|
103
|
-
inputProps: {
|
|
104
|
-
accept,
|
|
105
|
-
size: maxSize != null ? maxSize : void 0,
|
|
106
|
-
multiple
|
|
107
|
-
},
|
|
108
|
-
id: inputId
|
|
109
|
-
})
|
|
110
|
-
)
|
|
111
|
-
}
|
|
112
|
-
),
|
|
113
|
-
/* @__PURE__ */ jsx(Button, __spreadProps(__spreadValues({ color }, rest), { onClick, fullWidth: false, children }))
|
|
114
|
-
] });
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
// src/lib/util.ts
|
|
118
|
-
import {
|
|
119
|
-
FileArchiveIcon,
|
|
120
|
-
FileCodeIcon,
|
|
121
|
-
FileCsvIcon,
|
|
122
|
-
FileExcelIcon,
|
|
123
|
-
FileIcon,
|
|
124
|
-
FileImageIcon,
|
|
125
|
-
FileLinesIcon,
|
|
126
|
-
FilePdfIcon,
|
|
127
|
-
FilePowerpointIcon,
|
|
128
|
-
FileWordIcon
|
|
129
|
-
} from "@availity/mui-icon";
|
|
130
|
-
function formatBytes(bytes, decimals = 2) {
|
|
131
|
-
if (!+bytes) return "0 Bytes";
|
|
132
|
-
const k = 1024;
|
|
133
|
-
const dm = decimals < 0 ? 0 : decimals;
|
|
134
|
-
const sizes = ["Bytes", "KB", "MB", "GB"];
|
|
135
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
136
|
-
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
137
|
-
}
|
|
138
|
-
var FILE_EXT_ICONS = {
|
|
139
|
-
png: FileImageIcon,
|
|
140
|
-
jpg: FileImageIcon,
|
|
141
|
-
jpeg: FileImageIcon,
|
|
142
|
-
gif: FileImageIcon,
|
|
143
|
-
csv: FileCsvIcon,
|
|
144
|
-
ppt: FilePowerpointIcon,
|
|
145
|
-
pptx: FilePowerpointIcon,
|
|
146
|
-
xls: FileExcelIcon,
|
|
147
|
-
xlsx: FileExcelIcon,
|
|
148
|
-
doc: FileWordIcon,
|
|
149
|
-
docx: FileWordIcon,
|
|
150
|
-
txt: FileLinesIcon,
|
|
151
|
-
text: FileLinesIcon,
|
|
152
|
-
zip: FileArchiveIcon,
|
|
153
|
-
"7zip": FileArchiveIcon,
|
|
154
|
-
xml: FileCodeIcon,
|
|
155
|
-
html: FileCodeIcon,
|
|
156
|
-
pdf: FilePdfIcon
|
|
157
|
-
};
|
|
158
|
-
var isValidKey = (key) => key ? key in FILE_EXT_ICONS : false;
|
|
159
|
-
var getFileExtension = (fileName) => {
|
|
160
|
-
var _a;
|
|
161
|
-
return ((_a = fileName.split(".").pop()) == null ? void 0 : _a.toLowerCase()) || "";
|
|
162
|
-
};
|
|
163
|
-
var getFileExtIcon = (fileName) => {
|
|
164
|
-
const ext = getFileExtension(fileName);
|
|
165
|
-
return isValidKey(ext) ? FILE_EXT_ICONS[ext] : FileIcon;
|
|
166
|
-
};
|
|
167
|
-
var dedupeErrors = (errors) => {
|
|
168
|
-
const dedupedErrors = errors.reduce((acc, error) => {
|
|
169
|
-
if (!acc.find((err) => err.code === error.code)) {
|
|
170
|
-
acc.push(error);
|
|
171
|
-
}
|
|
172
|
-
return acc;
|
|
173
|
-
}, []);
|
|
174
|
-
return dedupedErrors;
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
// src/lib/Dropzone.tsx
|
|
178
|
-
import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
179
|
-
var outerBoxStyles = {
|
|
180
|
-
backgroundColor: "background.secondary",
|
|
181
|
-
border: "1px dotted",
|
|
182
|
-
borderColor: "secondary.light",
|
|
183
|
-
borderRadius: "4px",
|
|
184
|
-
padding: "2rem",
|
|
185
|
-
"&:hover": {
|
|
186
|
-
backgroundColor: "background.primary",
|
|
187
|
-
borderColor: "border.primary"
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
var innerBoxStyles = {
|
|
191
|
-
width: "100%",
|
|
192
|
-
height: "100%"
|
|
193
|
-
};
|
|
194
|
-
var createCounter = () => {
|
|
195
|
-
let id = 0;
|
|
196
|
-
const increment = () => id += 1;
|
|
197
|
-
return {
|
|
198
|
-
id,
|
|
199
|
-
increment
|
|
200
|
-
};
|
|
201
|
-
};
|
|
202
|
-
var counter = createCounter();
|
|
203
|
-
var DropzoneContainer = styled(Box, { name: "AvDropzoneContainer", slot: "root" })({
|
|
204
|
-
".MuiDivider-root": {
|
|
205
|
-
width: "196px",
|
|
206
|
-
marginLeft: "auto",
|
|
207
|
-
marginRight: "auto"
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
var Dropzone = ({
|
|
211
|
-
allowedFileTypes = [],
|
|
212
|
-
allowedFileNameCharacters,
|
|
213
|
-
disabled,
|
|
214
|
-
enableDropArea = true,
|
|
215
|
-
maxFiles,
|
|
216
|
-
maxSize,
|
|
217
|
-
maxTotalSize,
|
|
218
|
-
multiple,
|
|
219
|
-
name,
|
|
220
|
-
onChange,
|
|
221
|
-
onClick,
|
|
222
|
-
onDrop,
|
|
223
|
-
setFileRejections,
|
|
224
|
-
setTotalSize,
|
|
225
|
-
validator
|
|
226
|
-
}) => {
|
|
227
|
-
const { getValues, setValue, watch } = useFormContext();
|
|
228
|
-
const handleValidation = useCallback(
|
|
229
|
-
(file) => {
|
|
230
|
-
var _a2;
|
|
231
|
-
const previous = (_a2 = watch(name)) != null ? _a2 : [];
|
|
232
|
-
const errors = [];
|
|
233
|
-
const isDuplicate = previous.some((prev) => prev.name === file.name);
|
|
234
|
-
if (isDuplicate) {
|
|
235
|
-
errors.push({
|
|
236
|
-
code: "duplicate-name",
|
|
237
|
-
message: "A file with this name already exists"
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
const hasMaxFiles = maxFiles && previous.length >= maxFiles;
|
|
241
|
-
if (hasMaxFiles) {
|
|
242
|
-
errors.push({
|
|
243
|
-
code: "too-many-files",
|
|
244
|
-
message: `Too many files. You may only upload ${maxFiles} file(s).`
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
if (allowedFileNameCharacters) {
|
|
248
|
-
const fileName = file.name.substring(0, file.name.lastIndexOf("."));
|
|
249
|
-
const regExp = new RegExp(`([^${allowedFileNameCharacters}])`, "g");
|
|
250
|
-
if (fileName.match(regExp) !== null) {
|
|
251
|
-
errors.push({
|
|
252
|
-
code: "invalid-file-name-characters",
|
|
253
|
-
message: "File name contains characters not allowed"
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
if (allowedFileTypes.length > 0) {
|
|
258
|
-
const fileName = file.name;
|
|
259
|
-
const fileExt = fileName.substring(fileName.lastIndexOf(".")).toLowerCase();
|
|
260
|
-
const lowerCaseAllowedTypes = allowedFileTypes.map((type) => type.toLowerCase());
|
|
261
|
-
if (!lowerCaseAllowedTypes.includes(fileExt)) {
|
|
262
|
-
errors.push({
|
|
263
|
-
code: "file-invalid-type",
|
|
264
|
-
message: `File type ${fileExt} is not allowed`
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
if (validator) {
|
|
269
|
-
const validatorErrors = validator(file);
|
|
270
|
-
if (validatorErrors) {
|
|
271
|
-
if (Array.isArray(validatorErrors)) {
|
|
272
|
-
errors.push(...validatorErrors);
|
|
273
|
-
} else {
|
|
274
|
-
errors.push(validatorErrors);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return errors.length > 0 ? errors : null;
|
|
279
|
-
},
|
|
280
|
-
[maxFiles, validator, allowedFileNameCharacters, watch, name, allowedFileTypes]
|
|
281
|
-
);
|
|
282
|
-
const handleOnDrop = useCallback(
|
|
283
|
-
(acceptedFiles, fileRejections, event) => {
|
|
284
|
-
var _a2;
|
|
285
|
-
let newSize = 0;
|
|
286
|
-
for (const file of acceptedFiles) {
|
|
287
|
-
newSize += file.size;
|
|
288
|
-
}
|
|
289
|
-
setTotalSize((prev) => prev + newSize);
|
|
290
|
-
const previous = (_a2 = watch(name)) != null ? _a2 : [];
|
|
291
|
-
if (maxTotalSize) {
|
|
292
|
-
const currentTotalSize = previous.reduce((sum, file) => sum + file.size, 0);
|
|
293
|
-
let newSize2 = 0;
|
|
294
|
-
const availableSize = Math.max(0, maxTotalSize - currentTotalSize);
|
|
295
|
-
let sizeCounter = 0;
|
|
296
|
-
const cutoffIndex = acceptedFiles.findIndex((file) => {
|
|
297
|
-
sizeCounter += file.size;
|
|
298
|
-
return sizeCounter > availableSize;
|
|
299
|
-
});
|
|
300
|
-
if (cutoffIndex !== -1) {
|
|
301
|
-
const filesToAdd2 = acceptedFiles.slice(0, cutoffIndex === 0 ? 0 : cutoffIndex);
|
|
302
|
-
fileRejections.push({
|
|
303
|
-
file: acceptedFiles[cutoffIndex],
|
|
304
|
-
errors: [
|
|
305
|
-
{
|
|
306
|
-
code: "upload-too-large",
|
|
307
|
-
message: `Total upload size exceeds the limit of ${formatBytes(maxTotalSize)}.`
|
|
308
|
-
}
|
|
309
|
-
],
|
|
310
|
-
id: counter.increment()
|
|
311
|
-
});
|
|
312
|
-
acceptedFiles = filesToAdd2;
|
|
313
|
-
}
|
|
314
|
-
newSize2 = acceptedFiles.reduce((sum, file) => sum + file.size, 0);
|
|
315
|
-
setTotalSize((prev) => prev + newSize2);
|
|
316
|
-
}
|
|
317
|
-
const remainingSlots = maxFiles ? Math.max(0, maxFiles - previous.length) : acceptedFiles.length;
|
|
318
|
-
const filesToAdd = acceptedFiles.slice(0, remainingSlots);
|
|
319
|
-
setValue(name, previous.concat(filesToAdd));
|
|
320
|
-
if (maxFiles && acceptedFiles.length > remainingSlots) {
|
|
321
|
-
fileRejections.push({
|
|
322
|
-
file: acceptedFiles[remainingSlots],
|
|
323
|
-
// Use the first excess file
|
|
324
|
-
errors: [
|
|
325
|
-
{
|
|
326
|
-
code: "too-many-files",
|
|
327
|
-
message: `Too many files. You may only upload ${maxFiles} file(s).`
|
|
328
|
-
}
|
|
329
|
-
],
|
|
330
|
-
id: counter.increment()
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
if (fileRejections.length > 0) {
|
|
334
|
-
const TOO_MANY_FILES_CODE = "too-many-files";
|
|
335
|
-
let hasTooManyFiles = false;
|
|
336
|
-
fileRejections = fileRejections.reduce(
|
|
337
|
-
(acc, rejection) => {
|
|
338
|
-
const isTooManyFiles = rejection.errors.some((error) => error.code === TOO_MANY_FILES_CODE);
|
|
339
|
-
if (isTooManyFiles) {
|
|
340
|
-
if (!hasTooManyFiles) {
|
|
341
|
-
hasTooManyFiles = true;
|
|
342
|
-
acc.push(__spreadProps(__spreadValues({}, rejection), {
|
|
343
|
-
id: counter.increment()
|
|
344
|
-
}));
|
|
345
|
-
}
|
|
346
|
-
} else {
|
|
347
|
-
acc.push(__spreadProps(__spreadValues({}, rejection), {
|
|
348
|
-
id: counter.increment()
|
|
349
|
-
}));
|
|
350
|
-
}
|
|
351
|
-
return acc;
|
|
352
|
-
},
|
|
353
|
-
[]
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
|
-
if (setFileRejections) setFileRejections(fileRejections);
|
|
357
|
-
if (onDrop) onDrop(acceptedFiles, fileRejections, event);
|
|
358
|
-
},
|
|
359
|
-
[setFileRejections, setTotalSize, watch, name, maxTotalSize, maxFiles, setValue, onDrop]
|
|
360
|
-
);
|
|
361
|
-
const accept = allowedFileTypes.join(",");
|
|
362
|
-
const { getRootProps, getInputProps } = useDropzone({
|
|
363
|
-
onDrop: handleOnDrop,
|
|
364
|
-
maxSize,
|
|
365
|
-
maxFiles,
|
|
366
|
-
disabled,
|
|
367
|
-
multiple,
|
|
368
|
-
accept,
|
|
369
|
-
validator: handleValidation
|
|
370
|
-
});
|
|
371
|
-
const inputProps = getInputProps({
|
|
372
|
-
multiple,
|
|
373
|
-
accept,
|
|
374
|
-
onChange
|
|
375
|
-
});
|
|
376
|
-
const _a = getRootProps(), { role, tabIndex } = _a, rootProps = __objRest(_a, ["role", "tabIndex"]);
|
|
377
|
-
const handleOnChange = (event) => {
|
|
378
|
-
if (inputProps.onChange) {
|
|
379
|
-
inputProps.onChange(event);
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
const handleOnClick = (event) => {
|
|
383
|
-
if (!enableDropArea && rootProps.onClick) rootProps.onClick(event);
|
|
384
|
-
if (onClick) onClick(event);
|
|
385
|
-
};
|
|
386
|
-
const getFieldValue = () => {
|
|
387
|
-
const field = getValues();
|
|
388
|
-
return field[name] || [];
|
|
389
|
-
};
|
|
390
|
-
const currentFileCount = getFieldValue().length;
|
|
391
|
-
const hasFiles = currentFileCount > 0;
|
|
392
|
-
const isMaxFilesReached = maxFiles && currentFileCount >= maxFiles;
|
|
393
|
-
if (isMaxFilesReached) {
|
|
394
|
-
disabled = true;
|
|
395
|
-
}
|
|
396
|
-
return enableDropArea ? /* @__PURE__ */ jsx2(DropzoneContainer, __spreadProps(__spreadValues({ sx: outerBoxStyles }, rootProps), { children: /* @__PURE__ */ jsx2(Box, { sx: innerBoxStyles, children: /* @__PURE__ */ jsx2(Stack, { spacing: 2, alignItems: "center", justifyContent: "center", children: /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
397
|
-
/* @__PURE__ */ jsx2(CloudUploadIcon, { fontSize: "xlarge", color: "secondary" }),
|
|
398
|
-
/* @__PURE__ */ jsx2(Typography, { variant: "subtitle2", fontWeight: "700", children: "Drag and Drop Files Here" }),
|
|
399
|
-
/* @__PURE__ */ jsx2(Divider, { flexItem: true, children: /* @__PURE__ */ jsx2(Typography, { variant: "subtitle2", children: "OR" }) }),
|
|
400
|
-
/* @__PURE__ */ jsx2(
|
|
401
|
-
FilePickerBtn,
|
|
402
|
-
{
|
|
403
|
-
name,
|
|
404
|
-
color: "primary",
|
|
405
|
-
disabled,
|
|
406
|
-
maxSize,
|
|
407
|
-
onClick,
|
|
408
|
-
inputProps,
|
|
409
|
-
onChange: handleOnChange,
|
|
410
|
-
children: "Browse Files"
|
|
411
|
-
}
|
|
412
|
-
)
|
|
413
|
-
] }) }) }) })) : /* @__PURE__ */ jsx2(
|
|
414
|
-
FilePickerBtn,
|
|
415
|
-
{
|
|
416
|
-
name,
|
|
417
|
-
color: "tertiary",
|
|
418
|
-
disabled,
|
|
419
|
-
maxSize,
|
|
420
|
-
onClick: handleOnClick,
|
|
421
|
-
inputProps,
|
|
422
|
-
onChange: handleOnChange,
|
|
423
|
-
startIcon: /* @__PURE__ */ jsx2(PlusIcon, {}),
|
|
424
|
-
children: hasFiles ? "Add More Files" : "Add File(s)"
|
|
425
|
-
}
|
|
426
|
-
);
|
|
427
|
-
};
|
|
428
|
-
|
|
429
|
-
// src/lib/Dropzone2.tsx
|
|
430
|
-
import { useCallback as useCallback2 } from "react";
|
|
431
|
-
import { useDropzone as useDropzone2 } from "react-dropzone";
|
|
432
|
-
import { useFormContext as useFormContext2 } from "react-hook-form";
|
|
433
|
-
import { Divider as Divider2 } from "@availity/mui-divider";
|
|
434
|
-
import { CloudUploadIcon as CloudUploadIcon2, PlusIcon as PlusIcon2 } from "@availity/mui-icon";
|
|
435
|
-
import { Box as Box2, Stack as Stack2 } from "@availity/mui-layout";
|
|
436
|
-
import { Typography as Typography2 } from "@availity/mui-typography";
|
|
437
|
-
import Upload from "@availity/upload-core";
|
|
438
|
-
import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
439
|
-
var counter2 = createCounter();
|
|
440
|
-
function startUpload(file, options) {
|
|
441
|
-
return __async(this, null, function* () {
|
|
442
|
-
const _a = options, { onSuccess, onError, onProgress, onChunkComplete } = _a, uploadOptions = __objRest(_a, ["onSuccess", "onError", "onProgress", "onChunkComplete"]);
|
|
443
|
-
const upload = new Upload(file, uploadOptions);
|
|
444
|
-
yield upload.generateId();
|
|
445
|
-
if (onSuccess) upload.onSuccess.push(onSuccess);
|
|
446
|
-
if (onError) upload.onError.push(onError);
|
|
447
|
-
if (onProgress) upload.onProgress.push(onProgress);
|
|
448
|
-
if (onChunkComplete) upload.onChunkComplete.push(onChunkComplete);
|
|
449
|
-
upload.start();
|
|
450
|
-
return upload;
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
var Dropzone2 = ({
|
|
454
|
-
allowedFileTypes = [],
|
|
455
|
-
disabled,
|
|
456
|
-
enableDropArea = true,
|
|
457
|
-
maxFiles,
|
|
458
|
-
maxSize,
|
|
459
|
-
maxTotalSize,
|
|
460
|
-
multiple,
|
|
461
|
-
name,
|
|
462
|
-
onChange,
|
|
463
|
-
onClick,
|
|
464
|
-
onDrop,
|
|
465
|
-
setFileRejections,
|
|
466
|
-
setTotalSize,
|
|
467
|
-
uploadOptions,
|
|
468
|
-
validator
|
|
469
|
-
}) => {
|
|
470
|
-
const { getValues, setValue, watch } = useFormContext2();
|
|
471
|
-
const accept = allowedFileTypes.join(",");
|
|
472
|
-
const handleValidation = useCallback2(
|
|
473
|
-
(file) => {
|
|
474
|
-
var _a2;
|
|
475
|
-
const previous = (_a2 = watch(name)) != null ? _a2 : [];
|
|
476
|
-
const errors = [];
|
|
477
|
-
const isDuplicate = previous.some((prev) => prev.file.name === file.name);
|
|
478
|
-
if (isDuplicate) {
|
|
479
|
-
errors.push({
|
|
480
|
-
code: "duplicate-name",
|
|
481
|
-
message: "A file with this name already exists"
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
const hasMaxFiles = maxFiles && previous.length >= maxFiles;
|
|
485
|
-
if (hasMaxFiles) {
|
|
486
|
-
errors.push({
|
|
487
|
-
code: "too-many-files",
|
|
488
|
-
message: `Too many files. You may only upload ${maxFiles} file(s).`
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
if (uploadOptions.allowedFileNameCharacters) {
|
|
492
|
-
const fileName = file.name.substring(0, file.name.lastIndexOf("."));
|
|
493
|
-
const regExp = new RegExp(`([^${uploadOptions.allowedFileNameCharacters}])`, "g");
|
|
494
|
-
if (fileName.match(regExp) !== null) {
|
|
495
|
-
errors.push({
|
|
496
|
-
code: "invalid-file-name-characters",
|
|
497
|
-
message: "File name contains characters not allowed"
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
if (allowedFileTypes.length > 0) {
|
|
502
|
-
const fileName = file.name;
|
|
503
|
-
const fileExt = fileName.substring(fileName.lastIndexOf(".")).toLowerCase();
|
|
504
|
-
const lowerCaseAllowedTypes = allowedFileTypes.map((type) => type.toLowerCase());
|
|
505
|
-
if (!lowerCaseAllowedTypes.includes(fileExt)) {
|
|
506
|
-
errors.push({
|
|
507
|
-
code: "file-invalid-type",
|
|
508
|
-
message: `File type ${fileExt} is not allowed`
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
if (validator) {
|
|
513
|
-
const validatorErrors = validator(file);
|
|
514
|
-
if (validatorErrors) {
|
|
515
|
-
if (Array.isArray(validatorErrors)) {
|
|
516
|
-
errors.push(...validatorErrors);
|
|
517
|
-
} else {
|
|
518
|
-
errors.push(validatorErrors);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
return errors.length > 0 ? dedupeErrors(errors) : null;
|
|
523
|
-
},
|
|
524
|
-
[maxFiles, validator, uploadOptions.allowedFileNameCharacters, allowedFileTypes, watch, name]
|
|
525
|
-
);
|
|
526
|
-
const handleOnDrop = useCallback2(
|
|
527
|
-
(acceptedFiles, fileRejections, event) => __async(null, null, function* () {
|
|
528
|
-
var _a2;
|
|
529
|
-
let newSize = 0;
|
|
530
|
-
for (const file of acceptedFiles) {
|
|
531
|
-
newSize += file.size;
|
|
532
|
-
}
|
|
533
|
-
setTotalSize((prev) => prev + newSize);
|
|
534
|
-
const previous = (_a2 = watch(name)) != null ? _a2 : [];
|
|
535
|
-
if (maxTotalSize) {
|
|
536
|
-
const currentTotalSize = previous.reduce((sum, upload) => sum + upload.file.size, 0);
|
|
537
|
-
let newSize2 = 0;
|
|
538
|
-
const availableSize = Math.max(0, maxTotalSize - currentTotalSize);
|
|
539
|
-
let sizeCounter = 0;
|
|
540
|
-
const cutoffIndex = acceptedFiles.findIndex((file) => {
|
|
541
|
-
sizeCounter += file.size;
|
|
542
|
-
return sizeCounter > availableSize;
|
|
543
|
-
});
|
|
544
|
-
if (cutoffIndex !== -1) {
|
|
545
|
-
const filesToAdd2 = acceptedFiles.slice(0, cutoffIndex === 0 ? 0 : cutoffIndex);
|
|
546
|
-
fileRejections.push({
|
|
547
|
-
file: acceptedFiles[cutoffIndex],
|
|
548
|
-
errors: [
|
|
549
|
-
{
|
|
550
|
-
code: "upload-too-large",
|
|
551
|
-
message: `Total upload size exceeds the limit of ${formatBytes(maxTotalSize)}.`
|
|
552
|
-
}
|
|
553
|
-
],
|
|
554
|
-
id: counter2.increment()
|
|
555
|
-
});
|
|
556
|
-
acceptedFiles = filesToAdd2;
|
|
557
|
-
}
|
|
558
|
-
newSize2 = acceptedFiles.reduce((sum, file) => sum + file.size, 0);
|
|
559
|
-
setTotalSize((prev) => prev + newSize2);
|
|
560
|
-
}
|
|
561
|
-
const remainingSlots = maxFiles ? Math.max(0, maxFiles - previous.length) : acceptedFiles.length;
|
|
562
|
-
const filesToAdd = acceptedFiles.slice(0, remainingSlots);
|
|
563
|
-
const uploads = filesToAdd.map((file) => startUpload(file, uploadOptions));
|
|
564
|
-
setValue(name, previous.concat(yield Promise.all(uploads)));
|
|
565
|
-
if (maxFiles && acceptedFiles.length > remainingSlots) {
|
|
566
|
-
fileRejections.push({
|
|
567
|
-
file: acceptedFiles[remainingSlots],
|
|
568
|
-
// Use the first excess file
|
|
569
|
-
errors: [
|
|
570
|
-
{
|
|
571
|
-
code: "too-many-files",
|
|
572
|
-
message: `Too many files. You may only upload ${maxFiles} file(s).`
|
|
573
|
-
}
|
|
574
|
-
],
|
|
575
|
-
id: counter2.increment()
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
if (fileRejections.length > 0) {
|
|
579
|
-
const TOO_MANY_FILES_CODE = "too-many-files";
|
|
580
|
-
let hasTooManyFiles = false;
|
|
581
|
-
fileRejections = fileRejections.reduce(
|
|
582
|
-
(acc, rejection) => {
|
|
583
|
-
const isTooManyFiles = rejection.errors.some((error) => error.code === TOO_MANY_FILES_CODE);
|
|
584
|
-
if (isTooManyFiles) {
|
|
585
|
-
if (!hasTooManyFiles) {
|
|
586
|
-
hasTooManyFiles = true;
|
|
587
|
-
acc.push(__spreadProps(__spreadValues({}, rejection), {
|
|
588
|
-
id: counter2.increment()
|
|
589
|
-
}));
|
|
590
|
-
}
|
|
591
|
-
} else {
|
|
592
|
-
acc.push(__spreadProps(__spreadValues({}, rejection), {
|
|
593
|
-
id: counter2.increment()
|
|
594
|
-
}));
|
|
595
|
-
}
|
|
596
|
-
return acc;
|
|
597
|
-
},
|
|
598
|
-
[]
|
|
599
|
-
);
|
|
600
|
-
}
|
|
601
|
-
if (setFileRejections) setFileRejections(fileRejections);
|
|
602
|
-
if (onDrop) onDrop(acceptedFiles, fileRejections, event);
|
|
603
|
-
}),
|
|
604
|
-
[setFileRejections, setTotalSize, watch, name, maxTotalSize, maxFiles, uploadOptions, setValue, onDrop]
|
|
605
|
-
);
|
|
606
|
-
const { getRootProps, getInputProps } = useDropzone2({
|
|
607
|
-
onDrop: handleOnDrop,
|
|
608
|
-
maxSize,
|
|
609
|
-
maxFiles,
|
|
610
|
-
disabled,
|
|
611
|
-
multiple,
|
|
612
|
-
accept,
|
|
613
|
-
validator: handleValidation
|
|
614
|
-
});
|
|
615
|
-
const inputProps = getInputProps({
|
|
616
|
-
multiple,
|
|
617
|
-
accept,
|
|
618
|
-
onChange
|
|
619
|
-
});
|
|
620
|
-
const _a = getRootProps(), { role, tabIndex } = _a, rootProps = __objRest(_a, ["role", "tabIndex"]);
|
|
621
|
-
const handleOnChange = (event) => {
|
|
622
|
-
if (inputProps.onChange) {
|
|
623
|
-
inputProps.onChange(event);
|
|
624
|
-
}
|
|
625
|
-
};
|
|
626
|
-
const handleOnClick = (event) => {
|
|
627
|
-
if (!enableDropArea && rootProps.onClick) rootProps.onClick(event);
|
|
628
|
-
if (onClick) onClick(event);
|
|
629
|
-
};
|
|
630
|
-
const getFieldValue = () => {
|
|
631
|
-
const field = getValues();
|
|
632
|
-
return field[name] || [];
|
|
633
|
-
};
|
|
634
|
-
const currentFileCount = getFieldValue().length;
|
|
635
|
-
const hasFiles = currentFileCount > 0;
|
|
636
|
-
const isMaxFilesReached = maxFiles && currentFileCount >= maxFiles;
|
|
637
|
-
if (isMaxFilesReached) {
|
|
638
|
-
disabled = true;
|
|
639
|
-
}
|
|
640
|
-
return enableDropArea ? /* @__PURE__ */ jsx3(DropzoneContainer, __spreadProps(__spreadValues({ sx: outerBoxStyles }, rootProps), { children: /* @__PURE__ */ jsx3(Box2, { sx: innerBoxStyles, children: /* @__PURE__ */ jsx3(Stack2, { spacing: 2, alignItems: "center", justifyContent: "center", children: /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
641
|
-
/* @__PURE__ */ jsx3(CloudUploadIcon2, { fontSize: "xlarge", color: "secondary" }),
|
|
642
|
-
/* @__PURE__ */ jsx3(Typography2, { variant: "subtitle2", fontWeight: "700", children: "Drag and Drop Files Here" }),
|
|
643
|
-
/* @__PURE__ */ jsx3(Divider2, { flexItem: true, children: /* @__PURE__ */ jsx3(Typography2, { variant: "subtitle2", children: "OR" }) }),
|
|
644
|
-
/* @__PURE__ */ jsx3(
|
|
645
|
-
FilePickerBtn,
|
|
646
|
-
{
|
|
647
|
-
name,
|
|
648
|
-
color: "primary",
|
|
649
|
-
disabled,
|
|
650
|
-
maxSize,
|
|
651
|
-
onClick,
|
|
652
|
-
inputProps,
|
|
653
|
-
onChange: handleOnChange,
|
|
654
|
-
children: "Browse Files"
|
|
655
|
-
}
|
|
656
|
-
)
|
|
657
|
-
] }) }) }) })) : /* @__PURE__ */ jsx3(
|
|
658
|
-
FilePickerBtn,
|
|
659
|
-
{
|
|
660
|
-
name,
|
|
661
|
-
color: "tertiary",
|
|
662
|
-
disabled,
|
|
663
|
-
maxSize,
|
|
664
|
-
onClick: handleOnClick,
|
|
665
|
-
inputProps,
|
|
666
|
-
onChange: handleOnChange,
|
|
667
|
-
startIcon: /* @__PURE__ */ jsx3(PlusIcon2, {}),
|
|
668
|
-
children: hasFiles ? "Add More Files" : "Add File(s)"
|
|
669
|
-
}
|
|
670
|
-
);
|
|
671
|
-
};
|
|
672
|
-
|
|
673
|
-
// src/lib/ErrorAlert.tsx
|
|
674
|
-
import { Alert, AlertTitle } from "@availity/mui-alert";
|
|
675
|
-
import { List, ListItem } from "@availity/mui-list";
|
|
676
|
-
import { Fragment as Fragment4, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
677
|
-
var codes = {
|
|
678
|
-
"file-too-large": "File exceeds maximum size",
|
|
679
|
-
"upload-too-large": "File causes maximum total upload size to be exceeded",
|
|
680
|
-
"file-invalid-type": "File has an invalid type",
|
|
681
|
-
"file-too-small": "File is smaller than minimum size",
|
|
682
|
-
"too-many-file": "Too many files",
|
|
683
|
-
"duplicate-name": "Duplicate file selected"
|
|
684
|
-
};
|
|
685
|
-
var FILE_SIZE_REGEX = /\b(\d+)\b/;
|
|
686
|
-
var formatFileTooLarge = (message) => {
|
|
687
|
-
const fileSize = message.match(FILE_SIZE_REGEX);
|
|
688
|
-
if (!fileSize) return message;
|
|
689
|
-
const formattedSize = formatBytes(Number(fileSize[0]));
|
|
690
|
-
return message.replace(` bytes`, "").replace(FILE_SIZE_REGEX, formattedSize);
|
|
691
|
-
};
|
|
692
|
-
var ErrorAlert = ({ errors, fileName, id, onClose }) => {
|
|
693
|
-
if (errors.length === 0) return null;
|
|
694
|
-
return /* @__PURE__ */ jsx4(Alert, { severity: "error", onClose, children: errors.length > 1 ? /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
695
|
-
/* @__PURE__ */ jsxs4(AlertTitle, { children: [
|
|
696
|
-
"There were ",
|
|
697
|
-
errors.length,
|
|
698
|
-
" error(s) found when uploading ",
|
|
699
|
-
fileName
|
|
700
|
-
] }),
|
|
701
|
-
/* @__PURE__ */ jsx4(
|
|
702
|
-
List,
|
|
703
|
-
{
|
|
704
|
-
sx: {
|
|
705
|
-
listStyleType: "disc",
|
|
706
|
-
listStylePosition: "inside",
|
|
707
|
-
marginLeft: 1,
|
|
708
|
-
".MuiListItem-root": {
|
|
709
|
-
display: "list-item"
|
|
710
|
-
}
|
|
711
|
-
},
|
|
712
|
-
disablePadding: true,
|
|
713
|
-
children: /* @__PURE__ */ jsx4(Fragment4, { children: errors.map((error) => {
|
|
714
|
-
const message = error.code === "file-too-large" ? formatFileTooLarge(error.message) : error.message;
|
|
715
|
-
return /* @__PURE__ */ jsx4(ListItem, { disableGutters: true, disablePadding: true, divider: false, children: message }, `${id}-${error.code}`);
|
|
716
|
-
}) })
|
|
717
|
-
}
|
|
718
|
-
)
|
|
719
|
-
] }) : /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
720
|
-
/* @__PURE__ */ jsxs4(AlertTitle, { children: [
|
|
721
|
-
codes[errors[0].code] || "Error",
|
|
722
|
-
": ",
|
|
723
|
-
fileName
|
|
724
|
-
] }),
|
|
725
|
-
errors[0].code === "file-too-large" ? formatFileTooLarge(errors[0].message) : errors[0].message
|
|
726
|
-
] }) });
|
|
727
|
-
};
|
|
728
|
-
|
|
729
|
-
// src/lib/FileList.tsx
|
|
730
|
-
import { List as List2, ListItem as ListItem2, ListItemText as ListItemText2, ListItemIcon } from "@availity/mui-list";
|
|
731
|
-
import { IconButton as IconButton3 } from "@availity/mui-button";
|
|
732
|
-
import { DeleteIcon } from "@availity/mui-icon";
|
|
733
|
-
import { Grid as Grid2 } from "@availity/mui-layout";
|
|
734
|
-
import { Divider as Divider3 } from "@availity/mui-divider";
|
|
735
|
-
|
|
736
|
-
// src/lib/UploadProgressBar.tsx
|
|
737
|
-
import { useState as useState2 } from "react";
|
|
738
|
-
import { Button as Button2, IconButton as IconButton2 } from "@availity/mui-button";
|
|
739
|
-
|
|
740
|
-
// ../dialog/src/lib/Dialog.tsx
|
|
741
|
-
import MuiDialog from "@mui/material/Dialog";
|
|
742
|
-
import { styled as styled2 } from "@mui/material/styles";
|
|
743
|
-
import { IconButton } from "@availity/mui-button";
|
|
744
|
-
import { CloseIcon } from "@availity/mui-icon";
|
|
745
|
-
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
746
|
-
var CloseButton = (args) => /* @__PURE__ */ jsx5(IconButton, __spreadProps(__spreadValues({ title: "Close Dialog", color: "secondary" }, args), { children: /* @__PURE__ */ jsx5(CloseIcon, { fontSize: "xsmall" }) }));
|
|
747
|
-
var CloseButtonSlot = styled2(CloseButton, {
|
|
748
|
-
name: "MuiDialog",
|
|
749
|
-
slot: "AvCloseButton",
|
|
750
|
-
overridesResolver: (props, styles) => styles.avCloseButton
|
|
751
|
-
})({
|
|
752
|
-
position: "absolute",
|
|
753
|
-
top: ".5rem",
|
|
754
|
-
right: ".5rem",
|
|
755
|
-
"~ .MuiDialogTitle-root": {
|
|
756
|
-
marginRight: "3.5rem"
|
|
757
|
-
}
|
|
758
|
-
});
|
|
759
|
-
var Dialog = (_a) => {
|
|
760
|
-
var _b = _a, { children, closeButton = true, onClose } = _b, rest = __objRest(_b, ["children", "closeButton", "onClose"]);
|
|
761
|
-
return /* @__PURE__ */ jsxs5(MuiDialog, __spreadProps(__spreadValues({ onClose }, rest), { children: [
|
|
762
|
-
closeButton ? /* @__PURE__ */ jsx5(CloseButtonSlot, { onClick: onClose }) : null,
|
|
763
|
-
children
|
|
764
|
-
] }));
|
|
765
|
-
};
|
|
766
|
-
|
|
767
|
-
// ../dialog/src/lib/DialogActions.tsx
|
|
768
|
-
import MuiDialogActions from "@mui/material/DialogActions";
|
|
769
|
-
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
770
|
-
var DialogActions = (_a) => {
|
|
771
|
-
var _b = _a, { children } = _b, rest = __objRest(_b, ["children"]);
|
|
772
|
-
return /* @__PURE__ */ jsx6(MuiDialogActions, __spreadProps(__spreadValues({}, rest), { children }));
|
|
773
|
-
};
|
|
774
|
-
|
|
775
|
-
// ../dialog/src/lib/DialogContent.tsx
|
|
776
|
-
import MuiDialogContent from "@mui/material/DialogContent";
|
|
777
|
-
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
778
|
-
var DialogContent = (_a) => {
|
|
779
|
-
var _b = _a, { children } = _b, rest = __objRest(_b, ["children"]);
|
|
780
|
-
return /* @__PURE__ */ jsx7(MuiDialogContent, __spreadProps(__spreadValues({}, rest), { children }));
|
|
781
|
-
};
|
|
782
|
-
|
|
783
|
-
// ../dialog/src/lib/DialogTitle.tsx
|
|
784
|
-
import MuiDialogTitle from "@mui/material/DialogTitle";
|
|
785
|
-
import { AlertIcons } from "@availity/mui-alert";
|
|
786
|
-
import { styled as styled3 } from "@mui/material/styles";
|
|
787
|
-
import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
788
|
-
var AlertIcon = styled3("div", {
|
|
789
|
-
name: "MuiDialogTitle",
|
|
790
|
-
slot: "AvIcon",
|
|
791
|
-
overridesResolver: (props, styles) => styles.avIcon
|
|
792
|
-
})({
|
|
793
|
-
display: "inline-flex",
|
|
794
|
-
fontSize: "inherit",
|
|
795
|
-
marginRight: ".5rem",
|
|
796
|
-
verticalAlign: "text-bottom"
|
|
797
|
-
});
|
|
798
|
-
var DialogTitle = (_a) => {
|
|
799
|
-
var _b = _a, { children, component = "h2", icon, variant = "h5" } = _b, rest = __objRest(_b, ["children", "component", "icon", "variant"]);
|
|
800
|
-
return /* @__PURE__ */ jsxs6(MuiDialogTitle, __spreadProps(__spreadValues({ component, variant }, rest), { children: [
|
|
801
|
-
icon ? /* @__PURE__ */ jsx8(AlertIcon, { children: AlertIcons[icon] }) : null,
|
|
802
|
-
children
|
|
803
|
-
] }));
|
|
804
|
-
};
|
|
805
|
-
|
|
806
|
-
// src/lib/UploadProgressBar.tsx
|
|
807
|
-
import { InputAdornment } from "@availity/mui-form-utils";
|
|
808
|
-
import { EyeIcon, EyeSlashIcon, WarningTriangleIcon } from "@availity/mui-icon";
|
|
809
|
-
import { Box as Box3 } from "@availity/mui-layout";
|
|
810
|
-
import { ListItemText } from "@availity/mui-list";
|
|
811
|
-
import { LinearProgress } from "@availity/mui-progress";
|
|
812
|
-
|
|
813
|
-
// ../textfield/src/lib/TextField.tsx
|
|
814
|
-
import { forwardRef, useState } from "react";
|
|
815
|
-
import MuiTextField from "@mui/material/TextField";
|
|
816
|
-
import {
|
|
817
|
-
FormHelperText,
|
|
818
|
-
FormLabel,
|
|
819
|
-
InputPropOverrides,
|
|
820
|
-
SelectAccessibilityOverrides,
|
|
821
|
-
SelectPropOverrides
|
|
822
|
-
} from "@availity/mui-form-utils";
|
|
823
|
-
import { Grid } from "@availity/mui-layout";
|
|
824
|
-
import { Typography as Typography3 } from "@availity/mui-typography";
|
|
825
|
-
import { Fragment as Fragment5, jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
826
|
-
var TextFieldFormHelperText = (_a) => {
|
|
827
|
-
var _b = _a, {
|
|
828
|
-
charCount,
|
|
829
|
-
helperText,
|
|
830
|
-
maxLength,
|
|
831
|
-
showCharacterCount
|
|
832
|
-
} = _b, FormHelperTextProps2 = __objRest(_b, [
|
|
833
|
-
"charCount",
|
|
834
|
-
"helperText",
|
|
835
|
-
"maxLength",
|
|
836
|
-
"showCharacterCount"
|
|
837
|
-
]);
|
|
838
|
-
if (showCharacterCount) {
|
|
839
|
-
return /* @__PURE__ */ jsxs7(Grid, { container: true, justifyContent: "space-between", flexWrap: "nowrap", children: [
|
|
840
|
-
/* @__PURE__ */ jsx9(FormHelperText, __spreadProps(__spreadValues({}, FormHelperTextProps2), { sx: { marginRight: "12px" }, children: helperText })),
|
|
841
|
-
/* @__PURE__ */ jsxs7(Typography3, { variant: "caption", marginTop: "4px", lineHeight: "1.25rem", children: [
|
|
842
|
-
/* @__PURE__ */ jsx9(Typography3, { component: "span", variant: "inherit", color: charCount > maxLength ? "error" : "textPrimary", children: charCount || 0 }),
|
|
843
|
-
"/",
|
|
844
|
-
maxLength
|
|
845
|
-
] })
|
|
846
|
-
] });
|
|
847
|
-
}
|
|
848
|
-
return /* @__PURE__ */ jsx9(FormHelperText, __spreadProps(__spreadValues({}, FormHelperTextProps2), { children: helperText }));
|
|
849
|
-
};
|
|
850
|
-
var TextField = forwardRef((props, ref) => {
|
|
851
|
-
var _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
852
|
-
const _a = props, {
|
|
853
|
-
InputProps: InputProps2,
|
|
854
|
-
helpTopicId,
|
|
855
|
-
InputLabelProps,
|
|
856
|
-
FormHelperTextProps: FormHelperTextProps2,
|
|
857
|
-
required,
|
|
858
|
-
SelectProps: SelectProps2,
|
|
859
|
-
inputProps,
|
|
860
|
-
helperText,
|
|
861
|
-
showCharacterCount = false,
|
|
862
|
-
displayOverflowMaxLength = false
|
|
863
|
-
} = _a, rest = __objRest(_a, [
|
|
864
|
-
"InputProps",
|
|
865
|
-
"helpTopicId",
|
|
866
|
-
"InputLabelProps",
|
|
867
|
-
"FormHelperTextProps",
|
|
868
|
-
"required",
|
|
869
|
-
"SelectProps",
|
|
870
|
-
"inputProps",
|
|
871
|
-
"helperText",
|
|
872
|
-
"showCharacterCount",
|
|
873
|
-
"displayOverflowMaxLength"
|
|
874
|
-
]);
|
|
875
|
-
const [openDetected, setOpenDetected] = useState(false);
|
|
876
|
-
const [charCount, setCharCount] = useState(0);
|
|
877
|
-
const maxLength = (inputProps == null ? void 0 : inputProps.maxLength) || ((_c = (_b = rest.slotProps) == null ? void 0 : _b.htmlInput) == null ? void 0 : _c.maxLength);
|
|
878
|
-
const allReadOnly = (InputProps2 == null ? void 0 : InputProps2.readOnly) || (inputProps == null ? void 0 : inputProps.readOnly) || ((_e = (_d = rest.slotProps) == null ? void 0 : _d.htmlInput) == null ? void 0 : _e.readOnly) || ((_g = (_f = rest.slotProps) == null ? void 0 : _f.input) == null ? void 0 : _g.readOnly);
|
|
879
|
-
const resolvedProps = (props2) => !props2 || Object.keys(props2).length === 0 ? void 0 : props2;
|
|
880
|
-
return /* @__PURE__ */ jsx9(
|
|
881
|
-
MuiTextField,
|
|
882
|
-
__spreadProps(__spreadValues({}, rest), {
|
|
883
|
-
onChange: (event) => {
|
|
884
|
-
setCharCount(event.target.value.length);
|
|
885
|
-
if (rest.onChange) rest.onChange(event);
|
|
886
|
-
},
|
|
887
|
-
helperText: helperText || /* @__PURE__ */ jsx9(Fragment5, {}),
|
|
888
|
-
slots: { formHelperText: TextFieldFormHelperText },
|
|
889
|
-
slotProps: {
|
|
890
|
-
input: resolvedProps(__spreadProps(__spreadValues(__spreadValues(__spreadValues({}, InputProps2), InputPropOverrides), (_h = rest.slotProps) == null ? void 0 : _h.input), {
|
|
891
|
-
readOnly: allReadOnly
|
|
892
|
-
})),
|
|
893
|
-
htmlInput: resolvedProps(__spreadProps(__spreadValues(__spreadValues({
|
|
894
|
-
"aria-required": required
|
|
895
|
-
}, inputProps), (_i = rest.slotProps) == null ? void 0 : _i.htmlInput), {
|
|
896
|
-
maxLength: !displayOverflowMaxLength ? maxLength : void 0
|
|
897
|
-
})),
|
|
898
|
-
select: resolvedProps(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, SelectProps2), SelectPropOverrides), SelectAccessibilityOverrides(openDetected, setOpenDetected, SelectProps2 == null ? void 0 : SelectProps2.open)), (_j = rest.slotProps) == null ? void 0 : _j.select)),
|
|
899
|
-
inputLabel: resolvedProps(__spreadValues(__spreadValues({
|
|
900
|
-
component: FormLabel,
|
|
901
|
-
helpTopicId,
|
|
902
|
-
required,
|
|
903
|
-
shrink: true
|
|
904
|
-
}, InputLabelProps), (_k = rest.slotProps) == null ? void 0 : _k.inputLabel)),
|
|
905
|
-
formHelperText: resolvedProps(__spreadProps(__spreadValues(__spreadValues({
|
|
906
|
-
component: "div"
|
|
907
|
-
}, FormHelperTextProps2), (_l = rest.slotProps) == null ? void 0 : _l.formHelperText), {
|
|
908
|
-
charCount,
|
|
909
|
-
helperText,
|
|
910
|
-
maxLength,
|
|
911
|
-
showCharacterCount
|
|
912
|
-
}))
|
|
913
|
-
},
|
|
914
|
-
ref
|
|
915
|
-
})
|
|
916
|
-
);
|
|
917
|
-
});
|
|
918
|
-
|
|
919
|
-
// src/lib/UploadProgressBar.tsx
|
|
920
|
-
import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
921
|
-
var ERROR_MAPPINGS = [
|
|
922
|
-
{
|
|
923
|
-
pattern: /but has an extension for/i,
|
|
924
|
-
friendlyMessage: "File format does not match file extension."
|
|
925
|
-
}
|
|
926
|
-
];
|
|
927
|
-
var friendlyErrorMessage = (errorMessage) => {
|
|
928
|
-
const mapping = ERROR_MAPPINGS.find(({ pattern }) => pattern.test(errorMessage));
|
|
929
|
-
return mapping ? mapping.friendlyMessage : errorMessage;
|
|
930
|
-
};
|
|
931
|
-
var UploadProgressBar = ({ upload, onProgress, onError, onSuccess }) => {
|
|
932
|
-
const [statePercentage, setStatePercentage] = useState2(upload.percentage || 0);
|
|
933
|
-
const [errorMessage, setErrorMessage] = useState2(
|
|
934
|
-
upload.errorMessage ? friendlyErrorMessage(upload.errorMessage) : ""
|
|
935
|
-
);
|
|
936
|
-
const [password, setPassword] = useState2("");
|
|
937
|
-
const [showPassword, setShowPassword] = useState2(false);
|
|
938
|
-
const [modalOpen, setModalOpen] = useState2(false);
|
|
939
|
-
const handleOnProgress = () => {
|
|
940
|
-
setStatePercentage(upload.percentage);
|
|
941
|
-
setErrorMessage("");
|
|
942
|
-
if (onProgress) onProgress(upload);
|
|
943
|
-
};
|
|
944
|
-
const handleOnError = () => {
|
|
945
|
-
setErrorMessage(upload.errorMessage ? friendlyErrorMessage(upload.errorMessage) : "Error");
|
|
946
|
-
if (onError) onError(upload);
|
|
947
|
-
};
|
|
948
|
-
const handleOnSuccess = () => {
|
|
949
|
-
setStatePercentage(100);
|
|
950
|
-
setErrorMessage("");
|
|
951
|
-
if (onSuccess) onSuccess(upload);
|
|
952
|
-
};
|
|
953
|
-
const toggleModal = () => {
|
|
954
|
-
setModalOpen((prev) => !prev);
|
|
955
|
-
setPassword("");
|
|
956
|
-
};
|
|
957
|
-
const verifyPassword = (event) => {
|
|
958
|
-
event.preventDefault();
|
|
959
|
-
event.stopPropagation();
|
|
960
|
-
upload.sendPassword(password);
|
|
961
|
-
toggleModal();
|
|
962
|
-
};
|
|
963
|
-
const handlePasswordChange = (event) => {
|
|
964
|
-
setPassword(event.target.value);
|
|
965
|
-
};
|
|
966
|
-
upload.onProgress.push(handleOnProgress);
|
|
967
|
-
upload.onSuccess.push(handleOnSuccess);
|
|
968
|
-
upload.onError.push(handleOnError);
|
|
969
|
-
return errorMessage ? /* @__PURE__ */ jsxs8(Box3, { sx: { display: "flex", flexWrap: "wrap", columnGap: "4px" }, children: [
|
|
970
|
-
/* @__PURE__ */ jsxs8(
|
|
971
|
-
ListItemText,
|
|
972
|
-
{
|
|
973
|
-
slotProps: { primary: { color: "text.error", variant: "body2", component: "div" } },
|
|
974
|
-
sx: { wordWrap: "break-word" },
|
|
975
|
-
children: [
|
|
976
|
-
/* @__PURE__ */ jsx10(WarningTriangleIcon, { sx: { verticalAlign: "middle", mt: "-2px" } }),
|
|
977
|
-
" ",
|
|
978
|
-
errorMessage
|
|
979
|
-
]
|
|
980
|
-
}
|
|
981
|
-
),
|
|
982
|
-
upload.status === "encrypted" && /* @__PURE__ */ jsxs8("div", { className: "pwRequired", children: [
|
|
983
|
-
/* @__PURE__ */ jsx10(Button2, { color: "secondary", size: "small", onClick: toggleModal, children: "Enter Password" }),
|
|
984
|
-
/* @__PURE__ */ jsx10(Dialog, { open: modalOpen, onClose: toggleModal, children: /* @__PURE__ */ jsxs8("form", { onSubmit: verifyPassword, children: [
|
|
985
|
-
/* @__PURE__ */ jsx10(DialogTitle, { children: "Enter Password" }),
|
|
986
|
-
/* @__PURE__ */ jsx10(DialogContent, { children: /* @__PURE__ */ jsx10(
|
|
987
|
-
TextField,
|
|
988
|
-
{
|
|
989
|
-
type: showPassword ? "text" : "password",
|
|
990
|
-
name: "upload-password",
|
|
991
|
-
label: "Password",
|
|
992
|
-
onChange: handlePasswordChange,
|
|
993
|
-
autoFocus: true,
|
|
994
|
-
InputProps: {
|
|
995
|
-
endAdornment: /* @__PURE__ */ jsx10(InputAdornment, { position: "end", children: /* @__PURE__ */ jsx10(
|
|
996
|
-
IconButton2,
|
|
997
|
-
{
|
|
998
|
-
title: "password visibility",
|
|
999
|
-
onClick: () => setShowPassword((prev) => !prev),
|
|
1000
|
-
edge: "end",
|
|
1001
|
-
children: showPassword ? /* @__PURE__ */ jsx10(EyeIcon, { fontSize: "small" }) : /* @__PURE__ */ jsx10(EyeSlashIcon, { fontSize: "small" })
|
|
1002
|
-
}
|
|
1003
|
-
) })
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
) }),
|
|
1007
|
-
/* @__PURE__ */ jsx10(DialogActions, { children: /* @__PURE__ */ jsx10(Button2, { color: "primary", type: "submit", children: "Ok" }) })
|
|
1008
|
-
] }) })
|
|
1009
|
-
] })
|
|
1010
|
-
] }) : /* @__PURE__ */ jsx10(LinearProgress, { value: statePercentage, "aria-label": `${upload.file.name}-progress` });
|
|
1011
|
-
};
|
|
1012
|
-
|
|
1013
|
-
// src/lib/useUploadCore.tsx
|
|
1014
|
-
import { useQuery } from "@tanstack/react-query";
|
|
1015
|
-
import Upload2 from "@availity/upload-core";
|
|
1016
|
-
function startUpload2(file, options) {
|
|
1017
|
-
return __async(this, null, function* () {
|
|
1018
|
-
const _a = options, { onSuccess, onError, onProgress, onChunkComplete } = _a, uploadOptions = __objRest(_a, ["onSuccess", "onError", "onProgress", "onChunkComplete"]);
|
|
1019
|
-
const upload = new Upload2(file, uploadOptions);
|
|
1020
|
-
yield upload.generateId();
|
|
1021
|
-
if (onSuccess) upload.onSuccess.push(onSuccess);
|
|
1022
|
-
if (onError) upload.onError.push(onError);
|
|
1023
|
-
if (onProgress) upload.onProgress.push(onProgress);
|
|
1024
|
-
if (onChunkComplete) upload.onChunkComplete.push(onChunkComplete);
|
|
1025
|
-
upload.start();
|
|
1026
|
-
return upload;
|
|
1027
|
-
});
|
|
1028
|
-
}
|
|
1029
|
-
function useUploadCore(file, options, queryOptions) {
|
|
1030
|
-
const isQueryEnabled = !!file;
|
|
1031
|
-
return useQuery(__spreadValues({
|
|
1032
|
-
queryKey: ["upload", file.name, options],
|
|
1033
|
-
queryFn: () => startUpload2(file, options),
|
|
1034
|
-
enabled: isQueryEnabled,
|
|
1035
|
-
retry: false,
|
|
1036
|
-
refetchOnWindowFocus: false
|
|
1037
|
-
}, queryOptions));
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
// src/lib/FileList.tsx
|
|
1041
|
-
import { jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1042
|
-
var FileRow = ({
|
|
1043
|
-
file,
|
|
1044
|
-
options,
|
|
1045
|
-
onRemoveFile,
|
|
1046
|
-
queryOptions,
|
|
1047
|
-
customFileRow: CustomRow,
|
|
1048
|
-
disableRemove = false
|
|
1049
|
-
}) => {
|
|
1050
|
-
const Icon = getFileExtIcon(file.name);
|
|
1051
|
-
const { data: upload } = useUploadCore(file, options, queryOptions);
|
|
1052
|
-
if (!upload) return null;
|
|
1053
|
-
if (CustomRow) return /* @__PURE__ */ jsx11(CustomRow, { upload, options, onRemoveFile });
|
|
1054
|
-
return /* @__PURE__ */ jsxs9(
|
|
1055
|
-
ListItem2,
|
|
1056
|
-
{
|
|
1057
|
-
disableGutters: true,
|
|
1058
|
-
secondaryAction: !disableRemove && /* @__PURE__ */ jsx11(
|
|
1059
|
-
IconButton3,
|
|
1060
|
-
{
|
|
1061
|
-
title: "remove file",
|
|
1062
|
-
edge: "end",
|
|
1063
|
-
onClick: () => {
|
|
1064
|
-
onRemoveFile(upload.id, upload);
|
|
1065
|
-
},
|
|
1066
|
-
children: /* @__PURE__ */ jsx11(DeleteIcon, {})
|
|
1067
|
-
}
|
|
1068
|
-
),
|
|
1069
|
-
children: [
|
|
1070
|
-
/* @__PURE__ */ jsxs9(Grid2, { container: true, spacing: 2, alignItems: "center", justifyContent: "space-between", width: "100%", flexWrap: "wrap", children: [
|
|
1071
|
-
/* @__PURE__ */ jsx11(Grid2, { size: { xs: "auto" }, children: /* @__PURE__ */ jsx11(ListItemIcon, { sx: { minWidth: "1.5rem" }, children: /* @__PURE__ */ jsx11(Icon, {}) }) }),
|
|
1072
|
-
/* @__PURE__ */ jsx11(Grid2, { size: { xs: 4 }, sx: { minWidth: "8rem" }, children: /* @__PURE__ */ jsx11(ListItemText2, { sx: { wordBreak: "break-all" }, children: upload.trimFileName(upload.file.name) }) }),
|
|
1073
|
-
/* @__PURE__ */ jsx11(Grid2, { size: { xs: 2 }, sx: { minWidth: "3rem" }, children: /* @__PURE__ */ jsx11(ListItemText2, { sx: { textAlign: "end" }, children: formatBytes(upload.file.size) }) }),
|
|
1074
|
-
/* @__PURE__ */ jsx11(Grid2, { size: { xs: "grow" }, sx: { minWidth: "6rem" }, children: /* @__PURE__ */ jsx11(UploadProgressBar, { upload }) })
|
|
1075
|
-
] }),
|
|
1076
|
-
/* @__PURE__ */ jsx11(Divider3, {})
|
|
1077
|
-
]
|
|
1078
|
-
}
|
|
1079
|
-
);
|
|
1080
|
-
};
|
|
1081
|
-
var FileList = ({
|
|
1082
|
-
files,
|
|
1083
|
-
options,
|
|
1084
|
-
onRemoveFile,
|
|
1085
|
-
queryOptions,
|
|
1086
|
-
customFileRow,
|
|
1087
|
-
disableRemove
|
|
1088
|
-
}) => {
|
|
1089
|
-
if (files.length === 0) return null;
|
|
1090
|
-
return /* @__PURE__ */ jsx11(List2, { children: files.map((file) => {
|
|
1091
|
-
return /* @__PURE__ */ jsx11(
|
|
1092
|
-
FileRow,
|
|
1093
|
-
{
|
|
1094
|
-
file,
|
|
1095
|
-
options,
|
|
1096
|
-
onRemoveFile,
|
|
1097
|
-
queryOptions,
|
|
1098
|
-
customFileRow,
|
|
1099
|
-
disableRemove
|
|
1100
|
-
},
|
|
1101
|
-
file.name
|
|
1102
|
-
);
|
|
1103
|
-
}) });
|
|
1104
|
-
};
|
|
1105
|
-
|
|
1106
|
-
// src/lib/FileList2.tsx
|
|
1107
|
-
import { List as List3, ListItem as ListItem3, ListItemText as ListItemText3, ListItemIcon as ListItemIcon2 } from "@availity/mui-list";
|
|
1108
|
-
import { IconButton as IconButton4 } from "@availity/mui-button";
|
|
1109
|
-
import { DeleteIcon as DeleteIcon2 } from "@availity/mui-icon";
|
|
1110
|
-
import { Grid as Grid3 } from "@availity/mui-layout";
|
|
1111
|
-
import { Divider as Divider4 } from "@availity/mui-divider";
|
|
1112
|
-
import { jsx as jsx12, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
1113
|
-
var FileRow2 = ({
|
|
1114
|
-
upload,
|
|
1115
|
-
options,
|
|
1116
|
-
onRemoveFile,
|
|
1117
|
-
customFileRow: CustomRow,
|
|
1118
|
-
disableRemove = false
|
|
1119
|
-
}) => {
|
|
1120
|
-
const Icon = getFileExtIcon(upload.file.name);
|
|
1121
|
-
if (!upload) return null;
|
|
1122
|
-
if (CustomRow) return /* @__PURE__ */ jsx12(CustomRow, { upload, options, onRemoveFile });
|
|
1123
|
-
return /* @__PURE__ */ jsxs10(
|
|
1124
|
-
ListItem3,
|
|
1125
|
-
{
|
|
1126
|
-
disableGutters: true,
|
|
1127
|
-
secondaryAction: !disableRemove && /* @__PURE__ */ jsx12(
|
|
1128
|
-
IconButton4,
|
|
1129
|
-
{
|
|
1130
|
-
title: "remove file",
|
|
1131
|
-
edge: "end",
|
|
1132
|
-
onClick: () => {
|
|
1133
|
-
onRemoveFile(upload.id, upload);
|
|
1134
|
-
},
|
|
1135
|
-
children: /* @__PURE__ */ jsx12(DeleteIcon2, {})
|
|
1136
|
-
}
|
|
1137
|
-
),
|
|
1138
|
-
children: [
|
|
1139
|
-
/* @__PURE__ */ jsxs10(Grid3, { container: true, spacing: 2, alignItems: "center", justifyContent: "space-between", width: "100%", flexWrap: "wrap", children: [
|
|
1140
|
-
/* @__PURE__ */ jsx12(Grid3, { size: { xs: "auto" }, children: /* @__PURE__ */ jsx12(ListItemIcon2, { sx: { minWidth: "1.5rem" }, children: /* @__PURE__ */ jsx12(Icon, {}) }) }),
|
|
1141
|
-
/* @__PURE__ */ jsx12(Grid3, { size: { xs: 4 }, sx: { minWidth: "8rem" }, children: /* @__PURE__ */ jsx12(ListItemText3, { sx: { wordBreak: "break-all" }, children: upload.trimFileName(upload.file.name) }) }),
|
|
1142
|
-
/* @__PURE__ */ jsx12(Grid3, { size: { xs: 2 }, sx: { minWidth: "3rem" }, children: /* @__PURE__ */ jsx12(ListItemText3, { sx: { textAlign: "end" }, children: formatBytes(upload.file.size) }) }),
|
|
1143
|
-
/* @__PURE__ */ jsx12(Grid3, { size: { xs: "grow" }, sx: { minWidth: "6rem" }, children: /* @__PURE__ */ jsx12(UploadProgressBar, { upload }) })
|
|
1144
|
-
] }),
|
|
1145
|
-
/* @__PURE__ */ jsx12(Divider4, {})
|
|
1146
|
-
]
|
|
1147
|
-
}
|
|
1148
|
-
);
|
|
1149
|
-
};
|
|
1150
|
-
var FileList2 = ({
|
|
1151
|
-
uploads,
|
|
1152
|
-
options,
|
|
1153
|
-
onRemoveFile,
|
|
1154
|
-
customFileRow,
|
|
1155
|
-
disableRemove
|
|
1156
|
-
}) => {
|
|
1157
|
-
if (uploads.length === 0) return null;
|
|
1158
|
-
return /* @__PURE__ */ jsx12(List3, { children: uploads.map((upload) => {
|
|
1159
|
-
return /* @__PURE__ */ jsx12(
|
|
1160
|
-
FileRow2,
|
|
1161
|
-
{
|
|
1162
|
-
upload,
|
|
1163
|
-
options,
|
|
1164
|
-
onRemoveFile,
|
|
1165
|
-
customFileRow,
|
|
1166
|
-
disableRemove
|
|
1167
|
-
},
|
|
1168
|
-
upload.id
|
|
1169
|
-
);
|
|
1170
|
-
}) });
|
|
1171
|
-
};
|
|
1172
|
-
|
|
1173
|
-
// src/lib/FileSelector.tsx
|
|
1174
|
-
import { useState as useState3 } from "react";
|
|
1175
|
-
import { useFormContext as useFormContext3 } from "react-hook-form";
|
|
1176
|
-
import { useQueryClient } from "@tanstack/react-query";
|
|
1177
|
-
import { Grid as Grid4 } from "@availity/mui-layout";
|
|
1178
|
-
import { Typography as Typography6 } from "@availity/mui-typography";
|
|
1179
|
-
import { Alert as Alert2, AlertTitle as AlertTitle2 } from "@availity/mui-alert";
|
|
1180
|
-
|
|
1181
|
-
// src/lib/FileTypesMessage.tsx
|
|
1182
|
-
import { Typography as Typography4 } from "@availity/mui-typography";
|
|
1183
|
-
import { jsxs as jsxs11 } from "react/jsx-runtime";
|
|
1184
|
-
var FileTypesMessage = ({
|
|
1185
|
-
allowedFileTypes = [],
|
|
1186
|
-
customSizeMessage,
|
|
1187
|
-
customTotalSizeMessage,
|
|
1188
|
-
customTypesMessage,
|
|
1189
|
-
maxFileSize,
|
|
1190
|
-
maxTotalSize,
|
|
1191
|
-
variant = "caption"
|
|
1192
|
-
}) => {
|
|
1193
|
-
const fileSizeMsg = customSizeMessage || (typeof maxFileSize === "number" ? `Maximum file size is ${formatBytes(maxFileSize)}. ` : null);
|
|
1194
|
-
const totalFileSizeMsg = customTotalSizeMessage || (typeof maxTotalSize === "number" ? `Maximum total upload size is ${formatBytes(maxTotalSize)}. ` : null);
|
|
1195
|
-
const fileTypesMsg = customTypesMessage || (allowedFileTypes.length > 0 ? `Supported file types include: ${allowedFileTypes.join(", ")}` : "All file types allowed.");
|
|
1196
|
-
return /* @__PURE__ */ jsxs11(Typography4, { variant, children: [
|
|
1197
|
-
fileSizeMsg,
|
|
1198
|
-
totalFileSizeMsg,
|
|
1199
|
-
fileTypesMsg
|
|
1200
|
-
] });
|
|
1201
|
-
};
|
|
1202
|
-
|
|
1203
|
-
// src/lib/HeaderMessage.tsx
|
|
1204
|
-
import { Typography as Typography5 } from "@availity/mui-typography";
|
|
1205
|
-
import { jsxs as jsxs12 } from "react/jsx-runtime";
|
|
1206
|
-
var HeaderMessage = ({ maxFiles, maxSize, maxTotalSize }) => {
|
|
1207
|
-
return /* @__PURE__ */ jsxs12(Typography5, { variant: "h6", children: [
|
|
1208
|
-
"Attach up to ",
|
|
1209
|
-
maxFiles,
|
|
1210
|
-
" file(s), with a maximum individual size of ",
|
|
1211
|
-
formatBytes(maxSize),
|
|
1212
|
-
" ",
|
|
1213
|
-
maxTotalSize && `and a maximum total size of ${formatBytes(maxTotalSize)}`
|
|
1214
|
-
] });
|
|
1215
|
-
};
|
|
1216
|
-
|
|
1217
|
-
// src/lib/FileSelector.tsx
|
|
1218
|
-
import { Fragment as Fragment6, jsx as jsx13, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
1219
|
-
var CLOUD_URL = "/cloud/web/appl/vault/upload/v1/resumable";
|
|
1220
|
-
var FileSelector = ({
|
|
1221
|
-
name,
|
|
1222
|
-
allowedFileNameCharacters,
|
|
1223
|
-
allowedFileTypes = [],
|
|
1224
|
-
bucketId,
|
|
1225
|
-
clientId,
|
|
1226
|
-
children,
|
|
1227
|
-
customSizeMessage,
|
|
1228
|
-
customTotalSizeMessage,
|
|
1229
|
-
customTypesMessage,
|
|
1230
|
-
customerId,
|
|
1231
|
-
customFileRow,
|
|
1232
|
-
disabled = false,
|
|
1233
|
-
enableDropArea = true,
|
|
1234
|
-
endpoint,
|
|
1235
|
-
isCloud = true,
|
|
1236
|
-
label = "Upload file",
|
|
1237
|
-
maxFiles,
|
|
1238
|
-
maxSize,
|
|
1239
|
-
maxTotalSize,
|
|
1240
|
-
multiple = true,
|
|
1241
|
-
onChange,
|
|
1242
|
-
onDrop,
|
|
1243
|
-
onUploadRemove,
|
|
1244
|
-
queryOptions,
|
|
1245
|
-
uploadOptions,
|
|
1246
|
-
validator,
|
|
1247
|
-
disableRemove
|
|
1248
|
-
}) => {
|
|
1249
|
-
const [totalSize, setTotalSize] = useState3(0);
|
|
1250
|
-
const [fileRejections, setFileRejections] = useState3([]);
|
|
1251
|
-
const client = useQueryClient();
|
|
1252
|
-
const formMethods = useFormContext3();
|
|
1253
|
-
const options = __spreadProps(__spreadValues({}, uploadOptions), {
|
|
1254
|
-
bucketId,
|
|
1255
|
-
customerId,
|
|
1256
|
-
clientId,
|
|
1257
|
-
fileTypes: allowedFileTypes,
|
|
1258
|
-
maxSize,
|
|
1259
|
-
allowedFileNameCharacters
|
|
1260
|
-
});
|
|
1261
|
-
if (endpoint) options.endpoint = endpoint;
|
|
1262
|
-
else if (isCloud) options.endpoint = CLOUD_URL;
|
|
1263
|
-
const handleOnRemoveFile = (uploadId, upload) => {
|
|
1264
|
-
const prevFiles = formMethods.getValues(name);
|
|
1265
|
-
const newFiles = prevFiles.filter((file) => file.name !== upload.file.name);
|
|
1266
|
-
if (newFiles.length !== prevFiles.length) {
|
|
1267
|
-
const removedFile = prevFiles.find((file) => file.name === upload.file.name);
|
|
1268
|
-
try {
|
|
1269
|
-
upload.abort();
|
|
1270
|
-
} catch (e) {
|
|
1271
|
-
console.error("Encountered an issue stopping the file upload");
|
|
1272
|
-
}
|
|
1273
|
-
formMethods.setValue(name, newFiles);
|
|
1274
|
-
client.removeQueries(["upload", upload.file.name]);
|
|
1275
|
-
if (removedFile == null ? void 0 : removedFile.size) setTotalSize(totalSize - removedFile.size);
|
|
1276
|
-
if (onUploadRemove) onUploadRemove(newFiles, uploadId);
|
|
1277
|
-
}
|
|
1278
|
-
};
|
|
1279
|
-
const files = formMethods.watch(name);
|
|
1280
|
-
const handleRemoveRejection = (id) => {
|
|
1281
|
-
const rejections = fileRejections.filter((value) => value.id !== id);
|
|
1282
|
-
setFileRejections(rejections);
|
|
1283
|
-
};
|
|
1284
|
-
const TOO_MANY_FILES_CODE = "too-many-files";
|
|
1285
|
-
const tooManyFilesRejections = fileRejections.filter(
|
|
1286
|
-
(rejection) => rejection.errors.some((error) => error.code === TOO_MANY_FILES_CODE)
|
|
1287
|
-
);
|
|
1288
|
-
const otherRejections = fileRejections.filter(
|
|
1289
|
-
(rejection) => !rejection.errors.some((error) => error.code === TOO_MANY_FILES_CODE)
|
|
1290
|
-
);
|
|
1291
|
-
return /* @__PURE__ */ jsxs13(Fragment6, { children: [
|
|
1292
|
-
enableDropArea ? /* @__PURE__ */ jsxs13(Fragment6, { children: [
|
|
1293
|
-
label ? /* @__PURE__ */ jsx13(Typography6, { marginBottom: "4px", children: label }) : null,
|
|
1294
|
-
/* @__PURE__ */ jsx13(
|
|
1295
|
-
Dropzone,
|
|
1296
|
-
{
|
|
1297
|
-
name,
|
|
1298
|
-
allowedFileTypes,
|
|
1299
|
-
allowedFileNameCharacters,
|
|
1300
|
-
disabled,
|
|
1301
|
-
enableDropArea,
|
|
1302
|
-
maxFiles,
|
|
1303
|
-
maxSize,
|
|
1304
|
-
maxTotalSize,
|
|
1305
|
-
multiple,
|
|
1306
|
-
onChange,
|
|
1307
|
-
onDrop,
|
|
1308
|
-
setFileRejections,
|
|
1309
|
-
setTotalSize,
|
|
1310
|
-
validator
|
|
1311
|
-
}
|
|
1312
|
-
),
|
|
1313
|
-
/* @__PURE__ */ jsx13(
|
|
1314
|
-
FileTypesMessage,
|
|
1315
|
-
{
|
|
1316
|
-
allowedFileTypes,
|
|
1317
|
-
maxFileSize: maxSize,
|
|
1318
|
-
maxTotalSize,
|
|
1319
|
-
customSizeMessage,
|
|
1320
|
-
customTotalSizeMessage,
|
|
1321
|
-
customTypesMessage,
|
|
1322
|
-
variant: "caption"
|
|
1323
|
-
}
|
|
1324
|
-
),
|
|
1325
|
-
children
|
|
1326
|
-
] }) : /* @__PURE__ */ jsxs13(Grid4, { container: true, rowSpacing: 3, flexDirection: "column", children: [
|
|
1327
|
-
/* @__PURE__ */ jsxs13(Grid4, { children: [
|
|
1328
|
-
/* @__PURE__ */ jsx13(HeaderMessage, { maxFiles, maxSize, maxTotalSize }),
|
|
1329
|
-
/* @__PURE__ */ jsx13(
|
|
1330
|
-
FileTypesMessage,
|
|
1331
|
-
{
|
|
1332
|
-
allowedFileTypes,
|
|
1333
|
-
customTotalSizeMessage,
|
|
1334
|
-
customSizeMessage,
|
|
1335
|
-
customTypesMessage,
|
|
1336
|
-
variant: "body2"
|
|
1337
|
-
}
|
|
1338
|
-
)
|
|
1339
|
-
] }),
|
|
1340
|
-
children ? /* @__PURE__ */ jsx13(Grid4, { children }) : null,
|
|
1341
|
-
/* @__PURE__ */ jsx13(Grid4, { children: /* @__PURE__ */ jsx13(
|
|
1342
|
-
Dropzone,
|
|
1343
|
-
{
|
|
1344
|
-
name,
|
|
1345
|
-
allowedFileTypes,
|
|
1346
|
-
allowedFileNameCharacters,
|
|
1347
|
-
disabled,
|
|
1348
|
-
enableDropArea,
|
|
1349
|
-
maxFiles,
|
|
1350
|
-
maxSize,
|
|
1351
|
-
maxTotalSize,
|
|
1352
|
-
multiple,
|
|
1353
|
-
onChange,
|
|
1354
|
-
onDrop,
|
|
1355
|
-
setFileRejections,
|
|
1356
|
-
setTotalSize,
|
|
1357
|
-
validator
|
|
1358
|
-
}
|
|
1359
|
-
) })
|
|
1360
|
-
] }),
|
|
1361
|
-
tooManyFilesRejections.length > 0 && /* @__PURE__ */ jsxs13(
|
|
1362
|
-
Alert2,
|
|
1363
|
-
{
|
|
1364
|
-
severity: "error",
|
|
1365
|
-
onClose: () => tooManyFilesRejections.forEach((rejection) => handleRemoveRejection(rejection.id)),
|
|
1366
|
-
children: [
|
|
1367
|
-
/* @__PURE__ */ jsx13(AlertTitle2, { children: "Items not allowed." }),
|
|
1368
|
-
"Too many files are selected for upload, maximum ",
|
|
1369
|
-
maxFiles,
|
|
1370
|
-
" allowed."
|
|
1371
|
-
]
|
|
1372
|
-
}
|
|
1373
|
-
),
|
|
1374
|
-
otherRejections.length > 0 && otherRejections.map((rejection) => /* @__PURE__ */ jsx13(
|
|
1375
|
-
ErrorAlert,
|
|
1376
|
-
{
|
|
1377
|
-
errors: rejection.errors,
|
|
1378
|
-
fileName: rejection.file.name,
|
|
1379
|
-
id: rejection.id,
|
|
1380
|
-
onClose: () => handleRemoveRejection(rejection.id)
|
|
1381
|
-
},
|
|
1382
|
-
rejection.id
|
|
1383
|
-
)),
|
|
1384
|
-
/* @__PURE__ */ jsx13(
|
|
1385
|
-
FileList,
|
|
1386
|
-
{
|
|
1387
|
-
files: files || [],
|
|
1388
|
-
options,
|
|
1389
|
-
onRemoveFile: handleOnRemoveFile,
|
|
1390
|
-
queryOptions,
|
|
1391
|
-
customFileRow,
|
|
1392
|
-
disableRemove
|
|
1393
|
-
}
|
|
1394
|
-
)
|
|
1395
|
-
] });
|
|
1396
|
-
};
|
|
1397
|
-
|
|
1398
|
-
// src/lib/FileSelector2.tsx
|
|
1399
|
-
import { useState as useState4 } from "react";
|
|
1400
|
-
import { useFormContext as useFormContext4 } from "react-hook-form";
|
|
1401
|
-
import { Grid as Grid5 } from "@availity/mui-layout";
|
|
1402
|
-
import { Typography as Typography7 } from "@availity/mui-typography";
|
|
1403
|
-
import { Alert as Alert3, AlertTitle as AlertTitle3 } from "@availity/mui-alert";
|
|
1404
|
-
import { Fragment as Fragment7, jsx as jsx14, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
1405
|
-
var FileSelector2 = ({
|
|
1406
|
-
name,
|
|
1407
|
-
allowedFileNameCharacters,
|
|
1408
|
-
allowedFileTypes = [],
|
|
1409
|
-
bucketId,
|
|
1410
|
-
clientId,
|
|
1411
|
-
children,
|
|
1412
|
-
customSizeMessage,
|
|
1413
|
-
customTotalSizeMessage,
|
|
1414
|
-
customTypesMessage,
|
|
1415
|
-
customerId,
|
|
1416
|
-
customFileRow,
|
|
1417
|
-
disabled = false,
|
|
1418
|
-
enableDropArea = true,
|
|
1419
|
-
endpoint,
|
|
1420
|
-
isCloud = true,
|
|
1421
|
-
label = "Upload file",
|
|
1422
|
-
maxFiles,
|
|
1423
|
-
maxSize,
|
|
1424
|
-
maxTotalSize,
|
|
1425
|
-
multiple = true,
|
|
1426
|
-
onChange,
|
|
1427
|
-
onDrop,
|
|
1428
|
-
onUploadRemove,
|
|
1429
|
-
uploadOptions,
|
|
1430
|
-
validator,
|
|
1431
|
-
disableRemove
|
|
1432
|
-
}) => {
|
|
1433
|
-
const [totalSize, setTotalSize] = useState4(0);
|
|
1434
|
-
const [fileRejections, setFileRejections] = useState4([]);
|
|
1435
|
-
const formMethods = useFormContext4();
|
|
1436
|
-
const options = __spreadProps(__spreadValues({}, uploadOptions), {
|
|
1437
|
-
bucketId,
|
|
1438
|
-
customerId,
|
|
1439
|
-
clientId,
|
|
1440
|
-
fileTypes: allowedFileTypes,
|
|
1441
|
-
maxSize,
|
|
1442
|
-
allowedFileNameCharacters
|
|
1443
|
-
});
|
|
1444
|
-
if (endpoint) options.endpoint = endpoint;
|
|
1445
|
-
else if (isCloud) options.endpoint = CLOUD_URL;
|
|
1446
|
-
const handleOnRemoveFile = (uploadId, upload) => {
|
|
1447
|
-
const prevFiles = formMethods.getValues(name);
|
|
1448
|
-
const newFiles = prevFiles.filter((prev) => prev.file.name !== upload.file.name);
|
|
1449
|
-
if (newFiles.length !== prevFiles.length) {
|
|
1450
|
-
const removedFile = prevFiles.find((prev) => prev.file.name === upload.file.name);
|
|
1451
|
-
try {
|
|
1452
|
-
upload.abort();
|
|
1453
|
-
} catch (e) {
|
|
1454
|
-
console.error("Encountered an issue stopping the file upload");
|
|
1455
|
-
}
|
|
1456
|
-
formMethods.setValue(name, newFiles);
|
|
1457
|
-
if (removedFile == null ? void 0 : removedFile.file.size) setTotalSize(totalSize - removedFile.file.size);
|
|
1458
|
-
if (onUploadRemove) onUploadRemove(newFiles, uploadId);
|
|
1459
|
-
}
|
|
1460
|
-
};
|
|
1461
|
-
const uploads = formMethods.watch(name) || [];
|
|
1462
|
-
const handleRemoveRejection = (id) => {
|
|
1463
|
-
const rejections = fileRejections.filter((value) => value.id !== id);
|
|
1464
|
-
setFileRejections(rejections);
|
|
1465
|
-
};
|
|
1466
|
-
const TOO_MANY_FILES_CODE = "too-many-files";
|
|
1467
|
-
const tooManyFilesRejections = fileRejections.filter(
|
|
1468
|
-
(rejection) => rejection.errors.some((error) => error.code === TOO_MANY_FILES_CODE)
|
|
1469
|
-
);
|
|
1470
|
-
const otherRejections = fileRejections.filter(
|
|
1471
|
-
(rejection) => !rejection.errors.some((error) => error.code === TOO_MANY_FILES_CODE)
|
|
1472
|
-
);
|
|
1473
|
-
return /* @__PURE__ */ jsxs14(Fragment7, { children: [
|
|
1474
|
-
enableDropArea ? /* @__PURE__ */ jsxs14(Fragment7, { children: [
|
|
1475
|
-
label ? /* @__PURE__ */ jsx14(Typography7, { marginBottom: "4px", children: label }) : null,
|
|
1476
|
-
/* @__PURE__ */ jsx14(
|
|
1477
|
-
Dropzone2,
|
|
1478
|
-
{
|
|
1479
|
-
name,
|
|
1480
|
-
allowedFileTypes,
|
|
1481
|
-
disabled,
|
|
1482
|
-
enableDropArea,
|
|
1483
|
-
maxFiles,
|
|
1484
|
-
maxSize,
|
|
1485
|
-
maxTotalSize,
|
|
1486
|
-
multiple,
|
|
1487
|
-
onChange,
|
|
1488
|
-
onDrop,
|
|
1489
|
-
setFileRejections,
|
|
1490
|
-
setTotalSize,
|
|
1491
|
-
uploadOptions: options,
|
|
1492
|
-
validator
|
|
1493
|
-
}
|
|
1494
|
-
),
|
|
1495
|
-
/* @__PURE__ */ jsx14(
|
|
1496
|
-
FileTypesMessage,
|
|
1497
|
-
{
|
|
1498
|
-
allowedFileTypes,
|
|
1499
|
-
maxFileSize: maxSize,
|
|
1500
|
-
maxTotalSize,
|
|
1501
|
-
customSizeMessage,
|
|
1502
|
-
customTotalSizeMessage,
|
|
1503
|
-
customTypesMessage,
|
|
1504
|
-
variant: "caption"
|
|
1505
|
-
}
|
|
1506
|
-
),
|
|
1507
|
-
children
|
|
1508
|
-
] }) : /* @__PURE__ */ jsxs14(Grid5, { container: true, rowSpacing: 3, flexDirection: "column", children: [
|
|
1509
|
-
/* @__PURE__ */ jsxs14(Grid5, { children: [
|
|
1510
|
-
/* @__PURE__ */ jsx14(HeaderMessage, { maxFiles, maxSize, maxTotalSize }),
|
|
1511
|
-
/* @__PURE__ */ jsx14(
|
|
1512
|
-
FileTypesMessage,
|
|
1513
|
-
{
|
|
1514
|
-
allowedFileTypes,
|
|
1515
|
-
customSizeMessage,
|
|
1516
|
-
customTotalSizeMessage,
|
|
1517
|
-
customTypesMessage,
|
|
1518
|
-
variant: "body2"
|
|
1519
|
-
}
|
|
1520
|
-
)
|
|
1521
|
-
] }),
|
|
1522
|
-
children ? /* @__PURE__ */ jsx14(Grid5, { children }) : null,
|
|
1523
|
-
/* @__PURE__ */ jsx14(Grid5, { children: /* @__PURE__ */ jsx14(
|
|
1524
|
-
Dropzone2,
|
|
1525
|
-
{
|
|
1526
|
-
name,
|
|
1527
|
-
allowedFileTypes,
|
|
1528
|
-
disabled,
|
|
1529
|
-
enableDropArea,
|
|
1530
|
-
maxFiles,
|
|
1531
|
-
maxSize,
|
|
1532
|
-
maxTotalSize,
|
|
1533
|
-
multiple,
|
|
1534
|
-
onChange,
|
|
1535
|
-
onDrop,
|
|
1536
|
-
setFileRejections,
|
|
1537
|
-
setTotalSize,
|
|
1538
|
-
uploadOptions: options,
|
|
1539
|
-
validator
|
|
1540
|
-
}
|
|
1541
|
-
) })
|
|
1542
|
-
] }),
|
|
1543
|
-
tooManyFilesRejections.length > 0 && /* @__PURE__ */ jsxs14(
|
|
1544
|
-
Alert3,
|
|
1545
|
-
{
|
|
1546
|
-
severity: "error",
|
|
1547
|
-
onClose: () => tooManyFilesRejections.forEach((rejection) => handleRemoveRejection(rejection.id)),
|
|
1548
|
-
children: [
|
|
1549
|
-
/* @__PURE__ */ jsx14(AlertTitle3, { children: "Items not allowed." }),
|
|
1550
|
-
"Too many files are selected for upload, maximum ",
|
|
1551
|
-
maxFiles,
|
|
1552
|
-
" allowed."
|
|
1553
|
-
]
|
|
1554
|
-
}
|
|
1555
|
-
),
|
|
1556
|
-
otherRejections.length > 0 && otherRejections.map((rejection) => /* @__PURE__ */ jsx14(
|
|
1557
|
-
ErrorAlert,
|
|
1558
|
-
{
|
|
1559
|
-
errors: rejection.errors,
|
|
1560
|
-
fileName: rejection.file.name,
|
|
1561
|
-
id: rejection.id,
|
|
1562
|
-
onClose: () => handleRemoveRejection(rejection.id)
|
|
1563
|
-
},
|
|
1564
|
-
rejection.id
|
|
1565
|
-
)),
|
|
1566
|
-
/* @__PURE__ */ jsx14(
|
|
1567
|
-
FileList2,
|
|
1568
|
-
{
|
|
1569
|
-
uploads: uploads || [],
|
|
1570
|
-
options,
|
|
1571
|
-
onRemoveFile: handleOnRemoveFile,
|
|
1572
|
-
customFileRow,
|
|
1573
|
-
disableRemove
|
|
1574
|
-
}
|
|
1575
|
-
)
|
|
1576
|
-
] });
|
|
1577
|
-
};
|
|
1578
|
-
export {
|
|
1579
|
-
CLOUD_URL,
|
|
1580
|
-
Dropzone,
|
|
1581
|
-
Dropzone2,
|
|
1582
|
-
DropzoneContainer,
|
|
1583
|
-
ErrorAlert,
|
|
1584
|
-
FileList,
|
|
1585
|
-
FileList2,
|
|
1586
|
-
FilePickerBtn,
|
|
1587
|
-
FileRow,
|
|
1588
|
-
FileRow2,
|
|
1589
|
-
FileSelector,
|
|
1590
|
-
FileSelector2,
|
|
1591
|
-
FileTypesMessage,
|
|
1592
|
-
HeaderMessage,
|
|
1593
|
-
UploadProgressBar,
|
|
1594
|
-
createCounter,
|
|
1595
|
-
formatFileTooLarge,
|
|
1596
|
-
innerBoxStyles,
|
|
1597
|
-
outerBoxStyles,
|
|
1598
|
-
useUploadCore
|
|
1599
|
-
};
|