@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/mui-file-selector",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Availity MUI file-selector Component - part of the @availity/element design system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -21,56 +21,56 @@
|
|
|
21
21
|
"author": "Availity Developers <AVOSS@availity.com>",
|
|
22
22
|
"browser": "./dist/index.js",
|
|
23
23
|
"main": "./dist/index.js",
|
|
24
|
-
"module": "./dist/index.mjs",
|
|
25
24
|
"types": "./dist/index.d.ts",
|
|
26
25
|
"exports": {
|
|
27
|
-
"./package.json": "./package.json",
|
|
28
26
|
".": {
|
|
29
27
|
"types": "./dist/index.d.ts",
|
|
30
|
-
"import": "./dist/index.
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
"import": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
33
31
|
},
|
|
34
32
|
"scripts": {
|
|
35
|
-
"build": "tsup src/index.ts --format esm
|
|
36
|
-
"dev": "tsup src/index.ts --format esm
|
|
33
|
+
"build": "tsup src/index.ts --format esm --dts",
|
|
34
|
+
"dev": "tsup src/index.ts --format esm --watch --dts",
|
|
37
35
|
"clean": "rm -rf dist",
|
|
38
36
|
"clean:nm": "rm -rf node_modules",
|
|
39
37
|
"publish": "yarn npm publish --tolerate-republish --access public",
|
|
40
38
|
"publish:canary": "yarn npm publish --access public --tag canary"
|
|
41
39
|
},
|
|
42
40
|
"dependencies": {
|
|
43
|
-
"@availity/api-axios": "^
|
|
44
|
-
"@availity/mui-alert": "^
|
|
45
|
-
"@availity/mui-button": "^
|
|
46
|
-
"@availity/mui-divider": "^
|
|
47
|
-
"@availity/mui-form-utils": "^
|
|
48
|
-
"@availity/mui-icon": "^
|
|
49
|
-
"@availity/mui-layout": "^
|
|
50
|
-
"@availity/mui-list": "^
|
|
51
|
-
"@availity/mui-progress": "^
|
|
52
|
-
"@availity/mui-typography": "^
|
|
53
|
-
"@availity/upload-core": "^
|
|
54
|
-
"@tanstack/react-query": "^4.36.1",
|
|
41
|
+
"@availity/api-axios": "^13.2.0",
|
|
42
|
+
"@availity/mui-alert": "^3.0.0",
|
|
43
|
+
"@availity/mui-button": "^3.0.0",
|
|
44
|
+
"@availity/mui-divider": "^3.0.0",
|
|
45
|
+
"@availity/mui-form-utils": "^3.0.0",
|
|
46
|
+
"@availity/mui-icon": "^3.0.0",
|
|
47
|
+
"@availity/mui-layout": "^3.0.0",
|
|
48
|
+
"@availity/mui-list": "^3.0.0",
|
|
49
|
+
"@availity/mui-progress": "^3.0.0",
|
|
50
|
+
"@availity/mui-typography": "^3.0.0",
|
|
51
|
+
"@availity/upload-core": "^9.2.0",
|
|
55
52
|
"react-dropzone": "^11.7.1",
|
|
56
|
-
"react-hook-form": "^7.
|
|
53
|
+
"react-hook-form": "^7.79.0",
|
|
57
54
|
"tus-js-client": "4.3.1",
|
|
58
55
|
"uuid": "^11.1.1"
|
|
59
56
|
},
|
|
60
57
|
"devDependencies": {
|
|
61
|
-
"@availity/mui-paper": "^
|
|
62
|
-
"@mui/material": "^7.3.
|
|
63
|
-
"react": "
|
|
64
|
-
"react
|
|
65
|
-
"
|
|
66
|
-
"
|
|
58
|
+
"@availity/mui-paper": "^3.0.0",
|
|
59
|
+
"@mui/material": "^7.3.11",
|
|
60
|
+
"@tanstack/react-query": "^5.101.0",
|
|
61
|
+
"react": "19.2.7",
|
|
62
|
+
"react-dom": "19.2.7",
|
|
63
|
+
"tsup": "^8.5.1",
|
|
64
|
+
"typescript": "^5.9.3"
|
|
67
65
|
},
|
|
68
66
|
"peerDependencies": {
|
|
69
67
|
"@mui/material": "^7.0.0",
|
|
68
|
+
"@tanstack/react-query": "^5.101.0",
|
|
70
69
|
"react": ">=17.0.0"
|
|
71
70
|
},
|
|
72
71
|
"publishConfig": {
|
|
73
72
|
"access": "public"
|
|
74
73
|
},
|
|
75
|
-
"sideEffects": false
|
|
74
|
+
"sideEffects": false,
|
|
75
|
+
"type": "module"
|
|
76
76
|
}
|
package/project.json
CHANGED
|
@@ -8,23 +8,20 @@
|
|
|
8
8
|
"lint": {
|
|
9
9
|
"executor": "@nx/eslint:lint",
|
|
10
10
|
"options": {
|
|
11
|
-
"eslintConfig": ".eslintrc.json",
|
|
12
11
|
"silent": false,
|
|
13
12
|
"fix": false,
|
|
14
13
|
"cache": true,
|
|
15
14
|
"cacheLocation": "./node_modules/.cache/file-selector/.eslintcache",
|
|
16
15
|
"maxWarnings": -1,
|
|
17
16
|
"quiet": false,
|
|
18
|
-
"noEslintrc": false,
|
|
19
17
|
"hasTypeAwareRules": true,
|
|
20
18
|
"cacheStrategy": "metadata"
|
|
21
19
|
}
|
|
22
20
|
},
|
|
23
21
|
"test": {
|
|
24
|
-
"executor": "
|
|
25
|
-
"outputs": ["{workspaceRoot}/coverage/file-selector"],
|
|
22
|
+
"executor": "nx:run-commands",
|
|
26
23
|
"options": {
|
|
27
|
-
"
|
|
24
|
+
"command": "vitest run packages/file-selector"
|
|
28
25
|
}
|
|
29
26
|
},
|
|
30
27
|
"version": {
|
|
@@ -34,7 +31,9 @@
|
|
|
34
31
|
"commitMessageFormat": "chore({projectName}): release version ${version} [skip ci]",
|
|
35
32
|
"tagPrefix": "@availity/{projectName}@",
|
|
36
33
|
"trackDeps": true,
|
|
37
|
-
"skipCommitTypes": [
|
|
34
|
+
"skipCommitTypes": [
|
|
35
|
+
"docs"
|
|
36
|
+
]
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
}
|
|
@@ -18,7 +18,7 @@ describe('Dropzone', () => {
|
|
|
18
18
|
render(
|
|
19
19
|
<QueryClientProvider client={client}>
|
|
20
20
|
<TestForm>
|
|
21
|
-
<Dropzone name="test" maxSize={1000} setTotalSize={
|
|
21
|
+
<Dropzone name="test" maxSize={1000} setTotalSize={vi.fn()} />
|
|
22
22
|
</TestForm>
|
|
23
23
|
</QueryClientProvider>
|
|
24
24
|
);
|
package/src/lib/Dropzone.tsx
CHANGED
|
@@ -156,7 +156,7 @@ export const Dropzone = ({
|
|
|
156
156
|
|
|
157
157
|
// Check for allowed file name characters
|
|
158
158
|
if (allowedFileNameCharacters) {
|
|
159
|
-
const fileName = file.name.
|
|
159
|
+
const fileName = file.name.slice(0, Math.max(0, file.name.lastIndexOf('.')));
|
|
160
160
|
const regExp = new RegExp(`([^${allowedFileNameCharacters}])`, 'g');
|
|
161
161
|
|
|
162
162
|
if (fileName.match(regExp) !== null) {
|
|
@@ -170,7 +170,7 @@ export const Dropzone = ({
|
|
|
170
170
|
// Explicit check for allowed file types
|
|
171
171
|
if (allowedFileTypes.length > 0) {
|
|
172
172
|
const fileName = file.name;
|
|
173
|
-
const fileExt = fileName.
|
|
173
|
+
const fileExt = fileName.slice(Math.max(0, fileName.lastIndexOf('.'))).toLowerCase();
|
|
174
174
|
|
|
175
175
|
// Convert all file types to lowercase for comparison
|
|
176
176
|
const lowerCaseAllowedTypes = allowedFileTypes.map((type) => type.toLowerCase());
|
|
@@ -325,7 +325,7 @@ export const Dropzone = ({
|
|
|
325
325
|
});
|
|
326
326
|
|
|
327
327
|
// Remove role and tabIndex for accessibility
|
|
328
|
-
|
|
328
|
+
|
|
329
329
|
const { role, tabIndex, ...rootProps } = getRootProps();
|
|
330
330
|
|
|
331
331
|
const handleOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
package/src/lib/Dropzone2.tsx
CHANGED
|
@@ -97,7 +97,7 @@ export const Dropzone2 = ({
|
|
|
97
97
|
|
|
98
98
|
// Check for allowed file name characters
|
|
99
99
|
if (uploadOptions.allowedFileNameCharacters) {
|
|
100
|
-
const fileName = file.name.
|
|
100
|
+
const fileName = file.name.slice(0, Math.max(0, file.name.lastIndexOf('.')));
|
|
101
101
|
const regExp = new RegExp(`([^${uploadOptions.allowedFileNameCharacters}])`, 'g');
|
|
102
102
|
|
|
103
103
|
if (fileName.match(regExp) !== null) {
|
|
@@ -111,7 +111,7 @@ export const Dropzone2 = ({
|
|
|
111
111
|
// Explicit check for allowed file types
|
|
112
112
|
if (allowedFileTypes.length > 0) {
|
|
113
113
|
const fileName = file.name;
|
|
114
|
-
const fileExt = fileName.
|
|
114
|
+
const fileExt = fileName.slice(Math.max(0, fileName.lastIndexOf('.'))).toLowerCase();
|
|
115
115
|
|
|
116
116
|
// Convert all file types to lowercase for comparison
|
|
117
117
|
const lowerCaseAllowedTypes = allowedFileTypes.map((type) => type.toLowerCase());
|
|
@@ -265,7 +265,7 @@ export const Dropzone2 = ({
|
|
|
265
265
|
});
|
|
266
266
|
|
|
267
267
|
// Remove role and tabIndex for accessibility
|
|
268
|
-
|
|
268
|
+
|
|
269
269
|
const { role, tabIndex, ...rootProps } = getRootProps();
|
|
270
270
|
|
|
271
271
|
const handleOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
@@ -4,7 +4,7 @@ import { ErrorAlert, formatFileTooLarge } from './ErrorAlert';
|
|
|
4
4
|
|
|
5
5
|
describe('ErrorAlert', () => {
|
|
6
6
|
test('should render error message', () => {
|
|
7
|
-
render(<ErrorAlert id={0} errors={[{ code: 'test', message: 'example' }]} fileName="file" onClose={
|
|
7
|
+
render(<ErrorAlert id={0} errors={[{ code: 'test', message: 'example' }]} fileName="file" onClose={vi.fn()} />);
|
|
8
8
|
|
|
9
9
|
expect(screen.getByText('Error: file')).toBeDefined();
|
|
10
10
|
});
|
|
@@ -25,7 +25,7 @@ describe('FileList', () => {
|
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
test('should call onRemoveFile', async () => {
|
|
28
|
-
const mockRemove =
|
|
28
|
+
const mockRemove = vi.fn();
|
|
29
29
|
const mockFile = new File(['file content'], 'mock.txt', { type: 'text/plain' });
|
|
30
30
|
|
|
31
31
|
render(
|
|
@@ -49,7 +49,7 @@ describe('FileList', () => {
|
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
test('should not display remove button when disableRemove is set to true', async () => {
|
|
52
|
-
const mockRemove =
|
|
52
|
+
const mockRemove = vi.fn();
|
|
53
53
|
const mockFile = new File(['file content'], 'mock.txt', { type: 'text/plain' });
|
|
54
54
|
|
|
55
55
|
render(
|
package/src/lib/FileList.tsx
CHANGED
|
@@ -114,8 +114,7 @@ export const FileList = ({
|
|
|
114
114
|
|
|
115
115
|
return (
|
|
116
116
|
<List>
|
|
117
|
-
{files.map((file) =>
|
|
118
|
-
return (
|
|
117
|
+
{files.map((file) => (
|
|
119
118
|
<FileRow
|
|
120
119
|
key={file.name}
|
|
121
120
|
file={file}
|
|
@@ -125,8 +124,7 @@ export const FileList = ({
|
|
|
125
124
|
customFileRow={customFileRow}
|
|
126
125
|
disableRemove={disableRemove}
|
|
127
126
|
/>
|
|
128
|
-
)
|
|
129
|
-
})}
|
|
127
|
+
))}
|
|
130
128
|
</List>
|
|
131
129
|
);
|
|
132
130
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { screen, render, fireEvent, waitFor } from '@testing-library/react';
|
|
2
2
|
|
|
3
|
-
import { FileList2 } from './FileList2';
|
|
4
3
|
import Upload from '@availity/upload-core';
|
|
4
|
+
import { FileList2 } from './FileList2';
|
|
5
5
|
|
|
6
6
|
const options = { bucketId: '123', customerId: '123', clientId: '123' };
|
|
7
7
|
|
|
@@ -26,7 +26,7 @@ describe('FileList2', () => {
|
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
test('should call onRemoveFile', async () => {
|
|
29
|
-
const mockRemove =
|
|
29
|
+
const mockRemove = vi.fn();
|
|
30
30
|
const mockFile = new File(['file content'], 'mock.txt', { type: 'text/plain' });
|
|
31
31
|
const upload = new Upload(mockFile, options);
|
|
32
32
|
|
|
@@ -49,7 +49,7 @@ describe('FileList2', () => {
|
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
test('should not display remove button when disableRemove is set to true', async () => {
|
|
52
|
-
const mockRemove =
|
|
52
|
+
const mockRemove = vi.fn();
|
|
53
53
|
const mockFile = new File(['file content'], 'mock.txt', { type: 'text/plain' });
|
|
54
54
|
const upload = new Upload(mockFile, options);
|
|
55
55
|
|
package/src/lib/FileList2.tsx
CHANGED
|
@@ -101,8 +101,7 @@ export const FileList2 = ({
|
|
|
101
101
|
|
|
102
102
|
return (
|
|
103
103
|
<List>
|
|
104
|
-
{uploads.map((upload) =>
|
|
105
|
-
return (
|
|
104
|
+
{uploads.map((upload) => (
|
|
106
105
|
<FileRow2
|
|
107
106
|
key={upload.id}
|
|
108
107
|
upload={upload}
|
|
@@ -111,8 +110,7 @@ export const FileList2 = ({
|
|
|
111
110
|
customFileRow={customFileRow}
|
|
112
111
|
disableRemove={disableRemove}
|
|
113
112
|
/>
|
|
114
|
-
)
|
|
115
|
-
})}
|
|
113
|
+
))}
|
|
116
114
|
</List>
|
|
117
115
|
);
|
|
118
116
|
};
|
|
@@ -10,7 +10,7 @@ const TestForm = () => {
|
|
|
10
10
|
|
|
11
11
|
return (
|
|
12
12
|
<FormProvider {...methods}>
|
|
13
|
-
<FilePickerBtn name="test" inputProps={{ ref }} onChange={
|
|
13
|
+
<FilePickerBtn name="test" inputProps={{ ref }} onChange={vi.fn()}>
|
|
14
14
|
Browse Files
|
|
15
15
|
</FilePickerBtn>
|
|
16
16
|
</FormProvider>
|
package/src/lib/FileSelector.tsx
CHANGED
|
@@ -214,7 +214,7 @@ export const FileSelector = ({
|
|
|
214
214
|
|
|
215
215
|
// Remove from context and cache
|
|
216
216
|
formMethods.setValue(name, newFiles);
|
|
217
|
-
client.removeQueries(['upload', upload.file.name]);
|
|
217
|
+
client.removeQueries({ queryKey: ['upload', upload.file.name] });
|
|
218
218
|
|
|
219
219
|
if (removedFile?.size) setTotalSize(totalSize - removedFile.size);
|
|
220
220
|
|
|
@@ -309,7 +309,7 @@ export const FileSelector = ({
|
|
|
309
309
|
{tooManyFilesRejections.length > 0 && (
|
|
310
310
|
<Alert
|
|
311
311
|
severity="error"
|
|
312
|
-
onClose={() =>
|
|
312
|
+
onClose={() => { for (const rejection of tooManyFilesRejections) handleRemoveRejection(rejection.id) }}
|
|
313
313
|
>
|
|
314
314
|
<AlertTitle>Items not allowed.</AlertTitle>
|
|
315
315
|
Too many files are selected for upload, maximum {maxFiles} allowed.
|
|
@@ -186,7 +186,7 @@ export const FileSelector2 = ({
|
|
|
186
186
|
{tooManyFilesRejections.length > 0 && (
|
|
187
187
|
<Alert
|
|
188
188
|
severity="error"
|
|
189
|
-
onClose={() =>
|
|
189
|
+
onClose={() => { for (const rejection of tooManyFilesRejections) handleRemoveRejection(rejection.id) }}
|
|
190
190
|
>
|
|
191
191
|
<AlertTitle>Items not allowed.</AlertTitle>
|
|
192
192
|
Too many files are selected for upload, maximum {maxFiles} allowed.
|
|
@@ -17,11 +17,9 @@ export type HeaderMessageProps = {
|
|
|
17
17
|
maxTotalSize?: number;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
export const HeaderMessage = ({ maxFiles, maxSize, maxTotalSize }: HeaderMessageProps) =>
|
|
21
|
-
return (
|
|
20
|
+
export const HeaderMessage = ({ maxFiles, maxSize, maxTotalSize }: HeaderMessageProps) => (
|
|
22
21
|
<Typography variant="h6">
|
|
23
22
|
Attach up to {maxFiles} file(s), with a maximum individual size of {formatBytes(maxSize)}{' '}
|
|
24
23
|
{maxTotalSize && `and a maximum total size of ${formatBytes(maxTotalSize)}`}
|
|
25
24
|
</Typography>
|
|
26
25
|
);
|
|
27
|
-
};
|
|
@@ -64,9 +64,7 @@ export function useFileDelivery({
|
|
|
64
64
|
return responses;
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
const validate = (errors: Record<string, unknown>) =>
|
|
68
|
-
return Object.keys(errors).length === 0;
|
|
69
|
-
};
|
|
67
|
+
const validate = (errors: Record<string, unknown>) => Object.keys(errors).length === 0;
|
|
70
68
|
|
|
71
69
|
const isQueryEnabled =
|
|
72
70
|
!!customerId &&
|
package/src/lib/util.ts
CHANGED
|
@@ -16,12 +16,12 @@ export function formatBytes(bytes: number, decimals = 2) {
|
|
|
16
16
|
if (!+bytes) return '0 Bytes';
|
|
17
17
|
|
|
18
18
|
const k = 1024;
|
|
19
|
-
const dm = decimals
|
|
19
|
+
const dm = Math.max(decimals, 0);
|
|
20
20
|
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
|
21
21
|
|
|
22
22
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
23
23
|
|
|
24
|
-
return `${parseFloat((bytes /
|
|
24
|
+
return `${Number.parseFloat((bytes / k**i).toFixed(dm))} ${sizes[i]}`;
|
|
25
25
|
}
|
|
26
26
|
export const FILE_EXT_ICONS = {
|
|
27
27
|
png: FileImageIcon,
|