@availity/mui-file-selector 0.2.4 → 0.2.6
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 +15 -0
- package/dist/index.js +34 -9
- package/dist/index.mjs +34 -9
- package/package.json +2 -2
- package/src/lib/Dropzone.tsx +6 -1
- package/src/lib/useUploadCore.tsx +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [0.2.6](https://github.com/Availity/element/compare/@availity/mui-file-selector@0.2.5...@availity/mui-file-selector@0.2.6) (2025-01-08)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* add hover border and fix accessibility ([7d8e7e4](https://github.com/Availity/element/commit/7d8e7e4136b266d42b3e453e57efe83f780a9e57))
|
|
11
|
+
|
|
12
|
+
## [0.2.5](https://github.com/Availity/element/compare/@availity/mui-file-selector@0.2.4...@availity/mui-file-selector@0.2.5) (2025-01-07)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* bump upload-core ([60dc9a3](https://github.com/Availity/element/commit/60dc9a38f27aa93098d593efcd20026b39a2b7d7))
|
|
18
|
+
* generate id before starting ([3514684](https://github.com/Availity/element/commit/3514684dfb9ca218d8d320c43235d4a0866d31a4))
|
|
19
|
+
|
|
5
20
|
## [0.2.4](https://github.com/Availity/element/compare/@availity/mui-file-selector@0.2.3...@availity/mui-file-selector@0.2.4) (2025-01-06)
|
|
6
21
|
|
|
7
22
|
### Dependency Updates
|
package/dist/index.js
CHANGED
|
@@ -55,6 +55,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
55
55
|
mod
|
|
56
56
|
));
|
|
57
57
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
+
var __async = (__this, __arguments, generator) => {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
var fulfilled = (value) => {
|
|
61
|
+
try {
|
|
62
|
+
step(generator.next(value));
|
|
63
|
+
} catch (e) {
|
|
64
|
+
reject(e);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var rejected = (value) => {
|
|
68
|
+
try {
|
|
69
|
+
step(generator.throw(value));
|
|
70
|
+
} catch (e) {
|
|
71
|
+
reject(e);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
75
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
76
|
+
});
|
|
77
|
+
};
|
|
58
78
|
|
|
59
79
|
// src/index.ts
|
|
60
80
|
var src_exports = {};
|
|
@@ -139,7 +159,8 @@ var outerBoxStyles = {
|
|
|
139
159
|
borderRadius: "4px",
|
|
140
160
|
padding: "2rem",
|
|
141
161
|
"&:hover": {
|
|
142
|
-
backgroundColor: "background.primary"
|
|
162
|
+
backgroundColor: "background.primary",
|
|
163
|
+
borderColor: "border.primary"
|
|
143
164
|
}
|
|
144
165
|
};
|
|
145
166
|
var innerBoxStyles = {
|
|
@@ -170,8 +191,8 @@ var Dropzone = ({
|
|
|
170
191
|
const { setValue, watch } = (0, import_react_hook_form2.useFormContext)();
|
|
171
192
|
const validator = (0, import_react.useCallback)(
|
|
172
193
|
(file) => {
|
|
173
|
-
var
|
|
174
|
-
const previous = (
|
|
194
|
+
var _a2;
|
|
195
|
+
const previous = (_a2 = watch(name)) != null ? _a2 : [];
|
|
175
196
|
const isDuplicate = previous.some((prev) => prev.name === file.name);
|
|
176
197
|
if (isDuplicate) {
|
|
177
198
|
return {
|
|
@@ -192,13 +213,13 @@ var Dropzone = ({
|
|
|
192
213
|
);
|
|
193
214
|
const onDrop = (0, import_react.useCallback)(
|
|
194
215
|
(acceptedFiles, fileRejections) => {
|
|
195
|
-
var
|
|
216
|
+
var _a2;
|
|
196
217
|
let newSize = 0;
|
|
197
218
|
for (const file of acceptedFiles) {
|
|
198
219
|
newSize += file.size;
|
|
199
220
|
}
|
|
200
221
|
setTotalSize((prev) => prev + newSize);
|
|
201
|
-
const previous = (
|
|
222
|
+
const previous = (_a2 = watch(name)) != null ? _a2 : [];
|
|
202
223
|
setValue(name, previous.concat(acceptedFiles));
|
|
203
224
|
if (fileRejections.length > 0) {
|
|
204
225
|
for (const rejection of fileRejections) {
|
|
@@ -230,7 +251,8 @@ var Dropzone = ({
|
|
|
230
251
|
inputProps.onChange(event);
|
|
231
252
|
}
|
|
232
253
|
};
|
|
233
|
-
|
|
254
|
+
const _a = getRootProps(), { role, tabIndex } = _a, rootProps = __objRest(_a, ["role", "tabIndex"]);
|
|
255
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_layout.Box, __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: [
|
|
234
256
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_icon.CloudUploadIcon, { fontSize: "xlarge", color: "secondary" }),
|
|
235
257
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_typography.Typography, { variant: "subtitle2", fontWeight: "700", children: "Drag and Drop Files Here" }),
|
|
236
258
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mui_divider.Divider, { children: "OR" }),
|
|
@@ -359,9 +381,12 @@ var getFileExtIcon = (fileName) => {
|
|
|
359
381
|
var import_react_query = require("@tanstack/react-query");
|
|
360
382
|
var import_upload_core = __toESM(require("@availity/upload-core"));
|
|
361
383
|
function startUpload(file, options) {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
384
|
+
return __async(this, null, function* () {
|
|
385
|
+
const upload = new import_upload_core.default(file, options);
|
|
386
|
+
yield upload.generateId();
|
|
387
|
+
upload.start();
|
|
388
|
+
return upload;
|
|
389
|
+
});
|
|
365
390
|
}
|
|
366
391
|
function useUploadCore(file, options) {
|
|
367
392
|
const isQueryEnabled = !!file;
|
package/dist/index.mjs
CHANGED
|
@@ -29,6 +29,26 @@ var __objRest = (source, exclude) => {
|
|
|
29
29
|
}
|
|
30
30
|
return target;
|
|
31
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
|
+
};
|
|
32
52
|
|
|
33
53
|
// src/lib/FileSelector.tsx
|
|
34
54
|
import { useState as useState2 } from "react";
|
|
@@ -105,7 +125,8 @@ var outerBoxStyles = {
|
|
|
105
125
|
borderRadius: "4px",
|
|
106
126
|
padding: "2rem",
|
|
107
127
|
"&:hover": {
|
|
108
|
-
backgroundColor: "background.primary"
|
|
128
|
+
backgroundColor: "background.primary",
|
|
129
|
+
borderColor: "border.primary"
|
|
109
130
|
}
|
|
110
131
|
};
|
|
111
132
|
var innerBoxStyles = {
|
|
@@ -136,8 +157,8 @@ var Dropzone = ({
|
|
|
136
157
|
const { setValue, watch } = useFormContext2();
|
|
137
158
|
const validator = useCallback(
|
|
138
159
|
(file) => {
|
|
139
|
-
var
|
|
140
|
-
const previous = (
|
|
160
|
+
var _a2;
|
|
161
|
+
const previous = (_a2 = watch(name)) != null ? _a2 : [];
|
|
141
162
|
const isDuplicate = previous.some((prev) => prev.name === file.name);
|
|
142
163
|
if (isDuplicate) {
|
|
143
164
|
return {
|
|
@@ -158,13 +179,13 @@ var Dropzone = ({
|
|
|
158
179
|
);
|
|
159
180
|
const onDrop = useCallback(
|
|
160
181
|
(acceptedFiles, fileRejections) => {
|
|
161
|
-
var
|
|
182
|
+
var _a2;
|
|
162
183
|
let newSize = 0;
|
|
163
184
|
for (const file of acceptedFiles) {
|
|
164
185
|
newSize += file.size;
|
|
165
186
|
}
|
|
166
187
|
setTotalSize((prev) => prev + newSize);
|
|
167
|
-
const previous = (
|
|
188
|
+
const previous = (_a2 = watch(name)) != null ? _a2 : [];
|
|
168
189
|
setValue(name, previous.concat(acceptedFiles));
|
|
169
190
|
if (fileRejections.length > 0) {
|
|
170
191
|
for (const rejection of fileRejections) {
|
|
@@ -196,7 +217,8 @@ var Dropzone = ({
|
|
|
196
217
|
inputProps.onChange(event);
|
|
197
218
|
}
|
|
198
219
|
};
|
|
199
|
-
|
|
220
|
+
const _a = getRootProps(), { role, tabIndex } = _a, rootProps = __objRest(_a, ["role", "tabIndex"]);
|
|
221
|
+
return /* @__PURE__ */ jsx2(Box, __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: [
|
|
200
222
|
/* @__PURE__ */ jsx2(CloudUploadIcon, { fontSize: "xlarge", color: "secondary" }),
|
|
201
223
|
/* @__PURE__ */ jsx2(Typography, { variant: "subtitle2", fontWeight: "700", children: "Drag and Drop Files Here" }),
|
|
202
224
|
/* @__PURE__ */ jsx2(Divider, { children: "OR" }),
|
|
@@ -336,9 +358,12 @@ var getFileExtIcon = (fileName) => {
|
|
|
336
358
|
import { useQuery } from "@tanstack/react-query";
|
|
337
359
|
import Upload from "@availity/upload-core";
|
|
338
360
|
function startUpload(file, options) {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
361
|
+
return __async(this, null, function* () {
|
|
362
|
+
const upload = new Upload(file, options);
|
|
363
|
+
yield upload.generateId();
|
|
364
|
+
upload.start();
|
|
365
|
+
return upload;
|
|
366
|
+
});
|
|
342
367
|
}
|
|
343
368
|
function useUploadCore(file, options) {
|
|
344
369
|
const isQueryEnabled = !!file;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/mui-file-selector",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "Availity MUI file-selector Component - part of the @availity/element design system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@availity/mui-list": "^0.2.4",
|
|
43
43
|
"@availity/mui-progress": "^0.4.3",
|
|
44
44
|
"@availity/mui-typography": "^0.2.1",
|
|
45
|
-
"@availity/upload-core": "7.0.0-alpha.
|
|
45
|
+
"@availity/upload-core": "7.0.0-alpha.6",
|
|
46
46
|
"@tanstack/react-query": "^4.36.1",
|
|
47
47
|
"react-dropzone": "^11.7.1",
|
|
48
48
|
"react-hook-form": "^7.51.3",
|
package/src/lib/Dropzone.tsx
CHANGED
|
@@ -16,6 +16,7 @@ const outerBoxStyles = {
|
|
|
16
16
|
padding: '2rem',
|
|
17
17
|
'&:hover': {
|
|
18
18
|
backgroundColor: 'background.primary',
|
|
19
|
+
borderColor: 'border.primary',
|
|
19
20
|
},
|
|
20
21
|
};
|
|
21
22
|
|
|
@@ -176,8 +177,12 @@ export const Dropzone = ({
|
|
|
176
177
|
}
|
|
177
178
|
};
|
|
178
179
|
|
|
180
|
+
// Remove role and tabIndex for accessibility
|
|
181
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
182
|
+
const { role, tabIndex, ...rootProps } = getRootProps();
|
|
183
|
+
|
|
179
184
|
return (
|
|
180
|
-
<Box sx={outerBoxStyles} {...
|
|
185
|
+
<Box sx={outerBoxStyles} {...rootProps}>
|
|
181
186
|
<Box sx={innerBoxStyles}>
|
|
182
187
|
<Stack spacing={2} alignItems="center" justifyContent="center">
|
|
183
188
|
<>
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { useQuery } from '@tanstack/react-query';
|
|
2
2
|
import Upload, { UploadOptions } from '@availity/upload-core';
|
|
3
3
|
|
|
4
|
-
function startUpload(file: File, options: UploadOptions) {
|
|
4
|
+
async function startUpload(file: File, options: UploadOptions) {
|
|
5
5
|
const upload = new Upload(file, options);
|
|
6
6
|
|
|
7
|
+
await upload.generateId();
|
|
8
|
+
|
|
7
9
|
upload.start();
|
|
8
10
|
|
|
9
11
|
return upload;
|