@webiny/app 5.40.3-beta.0 → 5.40.3
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/package.json +12 -10
- package/react-butterfiles/Files.d.ts +69 -0
- package/react-butterfiles/Files.js +252 -0
- package/react-butterfiles/Files.js.map +1 -0
- package/react-butterfiles/index.d.ts +2 -0
- package/react-butterfiles/index.js +10 -0
- package/react-butterfiles/index.js.map +1 -0
- package/react-butterfiles/utils/generateId.d.ts +1 -0
- package/react-butterfiles/utils/generateId.js +11 -0
- package/react-butterfiles/utils/generateId.js.map +1 -0
- package/react-butterfiles/utils/readFileContent.d.ts +1 -0
- package/react-butterfiles/utils/readFileContent.js +21 -0
- package/react-butterfiles/utils/readFileContent.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/app",
|
|
3
|
-
"version": "5.40.3
|
|
3
|
+
"version": "5.40.3",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
"@babel/runtime": "7.24.1",
|
|
19
19
|
"@emotion/styled": "11.10.6",
|
|
20
20
|
"@types/react": "18.2.79",
|
|
21
|
-
"@webiny/i18n": "5.40.3
|
|
22
|
-
"@webiny/i18n-react": "5.40.3
|
|
23
|
-
"@webiny/plugins": "5.40.3
|
|
24
|
-
"@webiny/react-composition": "5.40.3
|
|
25
|
-
"@webiny/react-router": "5.40.3
|
|
26
|
-
"@webiny/ui": "5.40.3
|
|
21
|
+
"@webiny/i18n": "5.40.3",
|
|
22
|
+
"@webiny/i18n-react": "5.40.3",
|
|
23
|
+
"@webiny/plugins": "5.40.3",
|
|
24
|
+
"@webiny/react-composition": "5.40.3",
|
|
25
|
+
"@webiny/react-router": "5.40.3",
|
|
26
|
+
"@webiny/ui": "5.40.3",
|
|
27
27
|
"apollo-cache": "1.3.5",
|
|
28
28
|
"apollo-cache-inmemory": "1.6.6",
|
|
29
29
|
"apollo-client": "2.6.10",
|
|
@@ -33,9 +33,11 @@
|
|
|
33
33
|
"apollo-link-http-common": "0.2.16",
|
|
34
34
|
"apollo-utilities": "1.3.4",
|
|
35
35
|
"boolean": "3.2.0",
|
|
36
|
+
"bytes": "3.1.2",
|
|
36
37
|
"graphql": "15.8.0",
|
|
37
38
|
"invariant": "2.2.4",
|
|
38
39
|
"lodash": "4.17.21",
|
|
40
|
+
"minimatch": "5.1.6",
|
|
39
41
|
"nanoid": "3.3.7",
|
|
40
42
|
"react": "18.2.0",
|
|
41
43
|
"react-dom": "18.2.0",
|
|
@@ -51,8 +53,8 @@
|
|
|
51
53
|
"@babel/preset-typescript": "7.24.1",
|
|
52
54
|
"@types/lodash": "4.14.195",
|
|
53
55
|
"@types/warning": "3.0.0",
|
|
54
|
-
"@webiny/cli": "5.40.3
|
|
55
|
-
"@webiny/project-utils": "5.40.3
|
|
56
|
+
"@webiny/cli": "5.40.3",
|
|
57
|
+
"@webiny/project-utils": "5.40.3",
|
|
56
58
|
"rimraf": "5.0.5",
|
|
57
59
|
"typescript": "4.7.4"
|
|
58
60
|
},
|
|
@@ -71,5 +73,5 @@
|
|
|
71
73
|
]
|
|
72
74
|
}
|
|
73
75
|
},
|
|
74
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "deb698c829c8633fd9abdab70cd61ad42387eef7"
|
|
75
77
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export declare type SelectedFile = {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
type: string;
|
|
6
|
+
size: number;
|
|
7
|
+
src: {
|
|
8
|
+
file: File;
|
|
9
|
+
base64: string | null;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare type FileError = {
|
|
13
|
+
id: string;
|
|
14
|
+
type: "unsupportedFileType" | "maxSizeExceeded" | "multipleMaxSizeExceeded" | "multipleMaxCountExceeded" | "multipleNotAllowed";
|
|
15
|
+
index?: number;
|
|
16
|
+
file?: SelectedFile | File;
|
|
17
|
+
multipleFileSize?: number;
|
|
18
|
+
multipleMaxSize?: number;
|
|
19
|
+
multipleMaxCount?: number;
|
|
20
|
+
multipleCount?: number;
|
|
21
|
+
};
|
|
22
|
+
export declare type BrowseFilesParams = {
|
|
23
|
+
onSuccess?: (files: SelectedFile[]) => void;
|
|
24
|
+
onError?: (errors: FileError[], files: SelectedFile[]) => void;
|
|
25
|
+
};
|
|
26
|
+
export declare type RenderPropParams = {
|
|
27
|
+
browseFiles: (params: BrowseFilesParams) => void;
|
|
28
|
+
getDropZoneProps: (additionalProps: any) => any;
|
|
29
|
+
getLabelProps: (additionalProps: any) => any;
|
|
30
|
+
validateFiles: (files: SelectedFile[] | File[]) => FileError[];
|
|
31
|
+
};
|
|
32
|
+
export declare type FilesRules = {
|
|
33
|
+
accept: string[];
|
|
34
|
+
multiple: boolean;
|
|
35
|
+
maxSize: string;
|
|
36
|
+
multipleMaxSize: string;
|
|
37
|
+
multipleMaxCount: number | null;
|
|
38
|
+
convertToBase64: boolean;
|
|
39
|
+
onSuccess?: (files: SelectedFile[]) => void;
|
|
40
|
+
onError?: (errors: FileError[], files: SelectedFile[]) => void;
|
|
41
|
+
};
|
|
42
|
+
export declare type Props = FilesRules & {
|
|
43
|
+
children: (params: RenderPropParams) => React.ReactNode;
|
|
44
|
+
id?: string;
|
|
45
|
+
};
|
|
46
|
+
export declare class Files extends React.Component<Props> {
|
|
47
|
+
static defaultProps: {
|
|
48
|
+
accept: never[];
|
|
49
|
+
multiple: boolean;
|
|
50
|
+
maxSize: string;
|
|
51
|
+
multipleMaxSize: string;
|
|
52
|
+
multipleMaxCount: null;
|
|
53
|
+
convertToBase64: boolean;
|
|
54
|
+
};
|
|
55
|
+
input: HTMLInputElement | null;
|
|
56
|
+
browseFilesPassedParams: BrowseFilesParams | null;
|
|
57
|
+
id: string;
|
|
58
|
+
validateFiles: (files: SelectedFile[] | File[]) => FileError[];
|
|
59
|
+
processSelectedFiles: (eventFiles: Array<File>) => Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Extracted into a separate method just for testing purposes.
|
|
62
|
+
*/
|
|
63
|
+
onDropFilesHandler: ({ e, onSuccess, onError }: any) => Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Extracted into a separate method just for testing purposes.
|
|
66
|
+
*/
|
|
67
|
+
browseFilesHandler: ({ onSuccess, onError }: any) => void;
|
|
68
|
+
render(): React.JSX.Element;
|
|
69
|
+
}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.Files = void 0;
|
|
8
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
9
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
var _callSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/callSuper"));
|
|
14
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
|
+
var _react = _interopRequireDefault(require("react"));
|
|
17
|
+
var _bytes = _interopRequireDefault(require("bytes"));
|
|
18
|
+
var _minimatch = _interopRequireDefault(require("minimatch"));
|
|
19
|
+
var _readFileContent = require("./utils/readFileContent");
|
|
20
|
+
var _generateId = require("./utils/generateId");
|
|
21
|
+
var _excluded = ["onSuccess", "onError", "onDragOver", "onDrop"];
|
|
22
|
+
var Files = exports.Files = /*#__PURE__*/function (_React$Component) {
|
|
23
|
+
function Files() {
|
|
24
|
+
var _this;
|
|
25
|
+
(0, _classCallCheck2.default)(this, Files);
|
|
26
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
27
|
+
args[_key] = arguments[_key];
|
|
28
|
+
}
|
|
29
|
+
_this = (0, _callSuper2.default)(this, Files, [].concat(args));
|
|
30
|
+
(0, _defineProperty2.default)(_this, "input", null);
|
|
31
|
+
(0, _defineProperty2.default)(_this, "browseFilesPassedParams", null);
|
|
32
|
+
(0, _defineProperty2.default)(_this, "id", (0, _generateId.generateId)());
|
|
33
|
+
(0, _defineProperty2.default)(_this, "validateFiles", function (files) {
|
|
34
|
+
var _this$props = _this.props,
|
|
35
|
+
multiple = _this$props.multiple,
|
|
36
|
+
multipleMaxSize = _this$props.multipleMaxSize,
|
|
37
|
+
multipleMaxCount = _this$props.multipleMaxCount,
|
|
38
|
+
accept = _this$props.accept,
|
|
39
|
+
maxSize = _this$props.maxSize;
|
|
40
|
+
var errors = [];
|
|
41
|
+
var multipleFileSize = 0;
|
|
42
|
+
if (!multiple && files.length > 1) {
|
|
43
|
+
errors.push({
|
|
44
|
+
id: (0, _generateId.generateId)(),
|
|
45
|
+
type: "multipleNotAllowed"
|
|
46
|
+
});
|
|
47
|
+
return errors;
|
|
48
|
+
}
|
|
49
|
+
var _loop = function _loop() {
|
|
50
|
+
var file = files[index];
|
|
51
|
+
if (Array.isArray(accept) && accept.length && !accept.some(function (type) {
|
|
52
|
+
return (0, _minimatch.default)(file.type, type);
|
|
53
|
+
})) {
|
|
54
|
+
errors.push({
|
|
55
|
+
id: (0, _generateId.generateId)(),
|
|
56
|
+
index: index,
|
|
57
|
+
file: file,
|
|
58
|
+
type: "unsupportedFileType"
|
|
59
|
+
});
|
|
60
|
+
} else if (maxSize) {
|
|
61
|
+
if (file.size > (0, _bytes.default)(maxSize)) {
|
|
62
|
+
errors.push({
|
|
63
|
+
id: (0, _generateId.generateId)(),
|
|
64
|
+
index: index,
|
|
65
|
+
file: file,
|
|
66
|
+
type: "maxSizeExceeded"
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (multiple) {
|
|
71
|
+
multipleFileSize += file.size;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
for (var index = 0; index < files.length; index++) {
|
|
75
|
+
_loop();
|
|
76
|
+
}
|
|
77
|
+
if (multiple) {
|
|
78
|
+
if (multipleMaxSize && multipleFileSize > (0, _bytes.default)(multipleMaxSize)) {
|
|
79
|
+
errors.push({
|
|
80
|
+
id: (0, _generateId.generateId)(),
|
|
81
|
+
type: "multipleMaxSizeExceeded",
|
|
82
|
+
multipleFileSize: multipleFileSize,
|
|
83
|
+
multipleMaxSize: (0, _bytes.default)(multipleMaxSize)
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (multipleMaxCount && files.length > multipleMaxCount) {
|
|
87
|
+
errors.push({
|
|
88
|
+
id: (0, _generateId.generateId)(),
|
|
89
|
+
type: "multipleMaxCountExceeded",
|
|
90
|
+
multipleCount: files.length,
|
|
91
|
+
multipleMaxCount: multipleMaxCount
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return errors;
|
|
96
|
+
});
|
|
97
|
+
(0, _defineProperty2.default)(_this, "processSelectedFiles", async function (eventFiles) {
|
|
98
|
+
if (eventFiles.length === 0) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
var _this$props2 = _this.props,
|
|
102
|
+
convertToBase64 = _this$props2.convertToBase64,
|
|
103
|
+
onSuccess = _this$props2.onSuccess,
|
|
104
|
+
onError = _this$props2.onError;
|
|
105
|
+
var _this2 = _this,
|
|
106
|
+
browseFilesPassedParams = _this2.browseFilesPassedParams;
|
|
107
|
+
var callbacks = {
|
|
108
|
+
onSuccess: onSuccess,
|
|
109
|
+
onError: onError
|
|
110
|
+
};
|
|
111
|
+
if (browseFilesPassedParams && browseFilesPassedParams.onSuccess) {
|
|
112
|
+
callbacks.onSuccess = browseFilesPassedParams.onSuccess;
|
|
113
|
+
}
|
|
114
|
+
if (browseFilesPassedParams && browseFilesPassedParams.onError) {
|
|
115
|
+
callbacks.onError = browseFilesPassedParams.onError;
|
|
116
|
+
}
|
|
117
|
+
var files = (0, _toConsumableArray2.default)(eventFiles).map(function (file) {
|
|
118
|
+
return {
|
|
119
|
+
id: (0, _generateId.generateId)(),
|
|
120
|
+
name: file.name,
|
|
121
|
+
type: file.type,
|
|
122
|
+
size: file.size,
|
|
123
|
+
src: {
|
|
124
|
+
file: file,
|
|
125
|
+
base64: null
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
var errors = _this.validateFiles(files);
|
|
130
|
+
if (errors.length) {
|
|
131
|
+
callbacks.onError && callbacks.onError(errors, files);
|
|
132
|
+
} else {
|
|
133
|
+
if (convertToBase64) {
|
|
134
|
+
for (var i = 0; i < files.length; i++) {
|
|
135
|
+
var file = files[i].src.file;
|
|
136
|
+
files[i].src.base64 = await (0, _readFileContent.readFileContent)(file);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
callbacks.onSuccess && callbacks.onSuccess(files);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Reset the browseFiles arguments.
|
|
143
|
+
if (_this.input) {
|
|
144
|
+
_this.input.value = "";
|
|
145
|
+
}
|
|
146
|
+
_this.browseFilesPassedParams = null;
|
|
147
|
+
});
|
|
148
|
+
/**
|
|
149
|
+
* Extracted into a separate method just for testing purposes.
|
|
150
|
+
*/
|
|
151
|
+
(0, _defineProperty2.default)(_this, "onDropFilesHandler", async function (_ref) {
|
|
152
|
+
var e = _ref.e,
|
|
153
|
+
onSuccess = _ref.onSuccess,
|
|
154
|
+
onError = _ref.onError;
|
|
155
|
+
_this.browseFilesPassedParams = {
|
|
156
|
+
onSuccess: onSuccess,
|
|
157
|
+
onError: onError
|
|
158
|
+
};
|
|
159
|
+
e.dataTransfer && e.dataTransfer.files && (await _this.processSelectedFiles(e.dataTransfer.files));
|
|
160
|
+
});
|
|
161
|
+
/**
|
|
162
|
+
* Extracted into a separate method just for testing purposes.
|
|
163
|
+
*/
|
|
164
|
+
(0, _defineProperty2.default)(_this, "browseFilesHandler", function (_ref2) {
|
|
165
|
+
var onSuccess = _ref2.onSuccess,
|
|
166
|
+
onError = _ref2.onError;
|
|
167
|
+
_this.browseFilesPassedParams = {
|
|
168
|
+
onSuccess: onSuccess,
|
|
169
|
+
onError: onError
|
|
170
|
+
};
|
|
171
|
+
_this.input && _this.input.click();
|
|
172
|
+
});
|
|
173
|
+
return _this;
|
|
174
|
+
}
|
|
175
|
+
(0, _inherits2.default)(Files, _React$Component);
|
|
176
|
+
return (0, _createClass2.default)(Files, [{
|
|
177
|
+
key: "render",
|
|
178
|
+
value: function render() {
|
|
179
|
+
var _this3 = this;
|
|
180
|
+
var _this$props3 = this.props,
|
|
181
|
+
multiple = _this$props3.multiple,
|
|
182
|
+
accept = _this$props3.accept,
|
|
183
|
+
id = _this$props3.id;
|
|
184
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, this.props.children({
|
|
185
|
+
getLabelProps: function getLabelProps(props) {
|
|
186
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, props), {}, {
|
|
187
|
+
htmlFor: id || _this3.id
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
validateFiles: this.validateFiles,
|
|
191
|
+
browseFiles: function browseFiles() {
|
|
192
|
+
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
193
|
+
onSuccess = _ref3.onSuccess,
|
|
194
|
+
onError = _ref3.onError;
|
|
195
|
+
_this3.browseFilesHandler({
|
|
196
|
+
onSuccess: onSuccess,
|
|
197
|
+
onError: onError
|
|
198
|
+
});
|
|
199
|
+
},
|
|
200
|
+
getDropZoneProps: function getDropZoneProps() {
|
|
201
|
+
var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
202
|
+
var onSuccess = _ref4.onSuccess,
|
|
203
|
+
onError = _ref4.onError,
|
|
204
|
+
_onDragOver = _ref4.onDragOver,
|
|
205
|
+
_onDrop = _ref4.onDrop,
|
|
206
|
+
rest = (0, _objectWithoutProperties2.default)(_ref4, _excluded);
|
|
207
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, rest), {}, {
|
|
208
|
+
onDragOver: function onDragOver(e) {
|
|
209
|
+
e.preventDefault();
|
|
210
|
+
typeof _onDragOver === "function" && _onDragOver();
|
|
211
|
+
},
|
|
212
|
+
onDrop: async function onDrop(e) {
|
|
213
|
+
e.preventDefault();
|
|
214
|
+
typeof _onDrop === "function" && _onDrop();
|
|
215
|
+
_this3.onDropFilesHandler({
|
|
216
|
+
e: e,
|
|
217
|
+
onSuccess: onSuccess,
|
|
218
|
+
onError: onError
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}), /*#__PURE__*/_react.default.createElement("input", {
|
|
224
|
+
id: id || this.id,
|
|
225
|
+
ref: function ref(_ref5) {
|
|
226
|
+
if (_ref5) {
|
|
227
|
+
_this3.input = _ref5;
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
accept: accept.join(","),
|
|
231
|
+
style: {
|
|
232
|
+
display: "none"
|
|
233
|
+
},
|
|
234
|
+
type: "file",
|
|
235
|
+
multiple: multiple,
|
|
236
|
+
onChange: function onChange(e) {
|
|
237
|
+
return _this3.processSelectedFiles(e.target.files ?? []);
|
|
238
|
+
}
|
|
239
|
+
}));
|
|
240
|
+
}
|
|
241
|
+
}]);
|
|
242
|
+
}(_react.default.Component);
|
|
243
|
+
(0, _defineProperty2.default)(Files, "defaultProps", {
|
|
244
|
+
accept: [],
|
|
245
|
+
multiple: false,
|
|
246
|
+
maxSize: "2mb",
|
|
247
|
+
multipleMaxSize: "10mb",
|
|
248
|
+
multipleMaxCount: null,
|
|
249
|
+
convertToBase64: false
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
//# sourceMappingURL=Files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireDefault","require","_bytes","_minimatch","_readFileContent","_generateId","_excluded","Files","exports","_React$Component","_this","_classCallCheck2","default","_len","arguments","length","args","Array","_key","_callSuper2","concat","_defineProperty2","generateId","files","_this$props","props","multiple","multipleMaxSize","multipleMaxCount","accept","maxSize","errors","multipleFileSize","push","id","type","_loop","file","index","isArray","some","minimatch","size","bytes","multipleCount","eventFiles","_this$props2","convertToBase64","onSuccess","onError","_this2","browseFilesPassedParams","callbacks","_toConsumableArray2","map","name","src","base64","validateFiles","i","readFileContent","input","value","_ref","e","dataTransfer","processSelectedFiles","_ref2","click","_inherits2","_createClass2","key","render","_this3","_this$props3","createElement","Fragment","children","getLabelProps","_objectSpread2","htmlFor","browseFiles","_ref3","undefined","browseFilesHandler","getDropZoneProps","_ref4","onDragOver","onDrop","rest","_objectWithoutProperties2","preventDefault","onDropFilesHandler","ref","join","style","display","onChange","target","React","Component"],"sources":["Files.tsx"],"sourcesContent":["import React from \"react\";\nimport bytes from \"bytes\";\nimport minimatch from \"minimatch\";\nimport { readFileContent } from \"./utils/readFileContent\";\nimport { generateId } from \"./utils/generateId\";\n\nexport type SelectedFile = {\n id: string;\n name: string;\n type: string;\n size: number;\n src: {\n file: File;\n base64: string | null;\n };\n};\n\nexport type FileError = {\n id: string;\n type:\n | \"unsupportedFileType\"\n | \"maxSizeExceeded\"\n | \"multipleMaxSizeExceeded\"\n | \"multipleMaxCountExceeded\"\n | \"multipleNotAllowed\";\n index?: number;\n file?: SelectedFile | File;\n multipleFileSize?: number;\n multipleMaxSize?: number;\n multipleMaxCount?: number;\n multipleCount?: number;\n};\n\nexport type BrowseFilesParams = {\n onSuccess?: (files: SelectedFile[]) => void;\n onError?: (errors: FileError[], files: SelectedFile[]) => void;\n};\n\nexport type RenderPropParams = {\n browseFiles: (params: BrowseFilesParams) => void;\n getDropZoneProps: (additionalProps: any) => any;\n getLabelProps: (additionalProps: any) => any;\n validateFiles: (files: SelectedFile[] | File[]) => FileError[];\n};\n\nexport type FilesRules = {\n accept: string[];\n multiple: boolean;\n maxSize: string;\n multipleMaxSize: string;\n multipleMaxCount: number | null;\n convertToBase64: boolean;\n onSuccess?: (files: SelectedFile[]) => void;\n onError?: (errors: FileError[], files: SelectedFile[]) => void;\n};\n\nexport type Props = FilesRules & {\n children: (params: RenderPropParams) => React.ReactNode;\n id?: string;\n};\n\nexport class Files extends React.Component<Props> {\n static defaultProps = {\n accept: [],\n multiple: false,\n maxSize: \"2mb\",\n multipleMaxSize: \"10mb\",\n multipleMaxCount: null,\n convertToBase64: false\n };\n\n input: HTMLInputElement | null = null;\n browseFilesPassedParams: BrowseFilesParams | null = null;\n id: string = generateId();\n\n validateFiles = (files: SelectedFile[] | File[]): FileError[] => {\n const { multiple, multipleMaxSize, multipleMaxCount, accept, maxSize } = this.props;\n\n const errors: FileError[] = [];\n let multipleFileSize = 0;\n\n if (!multiple && files.length > 1) {\n errors.push({\n id: generateId(),\n type: \"multipleNotAllowed\"\n });\n\n return errors;\n }\n\n for (let index = 0; index < files.length; index++) {\n const file = files[index];\n\n if (\n Array.isArray(accept) &&\n accept.length &&\n !accept.some(type => minimatch(file.type, type))\n ) {\n errors.push({\n id: generateId(),\n index,\n file,\n type: \"unsupportedFileType\"\n });\n } else if (maxSize) {\n if (file.size > bytes(maxSize)) {\n errors.push({\n id: generateId(),\n index,\n file,\n type: \"maxSizeExceeded\"\n });\n }\n }\n\n if (multiple) {\n multipleFileSize += file.size;\n }\n }\n\n if (multiple) {\n if (multipleMaxSize && multipleFileSize > bytes(multipleMaxSize)) {\n errors.push({\n id: generateId(),\n type: \"multipleMaxSizeExceeded\",\n multipleFileSize,\n multipleMaxSize: bytes(multipleMaxSize)\n });\n }\n\n if (multipleMaxCount && files.length > multipleMaxCount) {\n errors.push({\n id: generateId(),\n type: \"multipleMaxCountExceeded\",\n multipleCount: files.length,\n multipleMaxCount\n });\n }\n }\n\n return errors;\n };\n\n processSelectedFiles = async (eventFiles: Array<File>) => {\n if (eventFiles.length === 0) {\n return;\n }\n\n const { convertToBase64, onSuccess, onError } = this.props;\n const { browseFilesPassedParams } = this;\n const callbacks = {\n onSuccess,\n onError\n };\n\n if (browseFilesPassedParams && browseFilesPassedParams.onSuccess) {\n callbacks.onSuccess = browseFilesPassedParams.onSuccess;\n }\n\n if (browseFilesPassedParams && browseFilesPassedParams.onError) {\n callbacks.onError = browseFilesPassedParams.onError;\n }\n\n const files: SelectedFile[] = [...eventFiles].map(file => {\n return {\n id: generateId(),\n name: file.name,\n type: file.type,\n size: file.size,\n src: {\n file,\n base64: null\n }\n };\n });\n\n const errors = this.validateFiles(files);\n\n if (errors.length) {\n callbacks.onError && callbacks.onError(errors, files);\n } else {\n if (convertToBase64) {\n for (let i = 0; i < files.length; i++) {\n const file = files[i].src.file;\n files[i].src.base64 = await readFileContent(file);\n }\n }\n\n callbacks.onSuccess && callbacks.onSuccess(files);\n }\n\n // Reset the browseFiles arguments.\n if (this.input) {\n this.input.value = \"\";\n }\n this.browseFilesPassedParams = null;\n };\n\n /**\n * Extracted into a separate method just for testing purposes.\n */\n onDropFilesHandler = async ({ e, onSuccess, onError }: any) => {\n this.browseFilesPassedParams = { onSuccess, onError };\n e.dataTransfer &&\n e.dataTransfer.files &&\n (await this.processSelectedFiles(e.dataTransfer.files));\n };\n\n /**\n * Extracted into a separate method just for testing purposes.\n */\n browseFilesHandler = ({ onSuccess, onError }: any) => {\n this.browseFilesPassedParams = { onSuccess, onError };\n this.input && this.input.click();\n };\n\n override render() {\n const { multiple, accept, id } = this.props;\n return (\n <React.Fragment>\n {this.props.children({\n getLabelProps: (props: any) => {\n return {\n ...props,\n htmlFor: id || this.id\n };\n },\n validateFiles: this.validateFiles,\n browseFiles: ({ onSuccess, onError }: BrowseFilesParams = {}) => {\n this.browseFilesHandler({ onSuccess, onError });\n },\n getDropZoneProps: ({\n onSuccess,\n onError,\n onDragOver,\n onDrop,\n ...rest\n }: any = {}) => {\n return {\n ...rest,\n onDragOver: (e: DragEvent) => {\n e.preventDefault();\n typeof onDragOver === \"function\" && onDragOver();\n },\n onDrop: async (e: DragEvent) => {\n e.preventDefault();\n typeof onDrop === \"function\" && onDrop();\n this.onDropFilesHandler({ e, onSuccess, onError });\n }\n };\n }\n })}\n\n <input\n id={id || this.id}\n ref={ref => {\n if (ref) {\n this.input = ref;\n }\n }}\n accept={accept.join(\",\")}\n style={{ display: \"none\" }}\n type=\"file\"\n multiple={multiple}\n onChange={e =>\n this.processSelectedFiles((e.target.files as any as Array<File>) ?? [])\n }\n />\n </React.Fragment>\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AAAgD,IAAAK,SAAA;AAAA,IAyDnCC,KAAK,GAAAC,OAAA,CAAAD,KAAA,0BAAAE,gBAAA;EAAA,SAAAF,MAAA;IAAA,IAAAG,KAAA;IAAA,IAAAC,gBAAA,CAAAC,OAAA,QAAAL,KAAA;IAAA,SAAAM,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAC,IAAA,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAAF,IAAA,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;IAAA;IAAAR,KAAA,OAAAS,WAAA,CAAAP,OAAA,QAAAL,KAAA,KAAAa,MAAA,C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E;QACzBC,KAAK,EAAE;UAAEC,OAAO,EAAE;QAAO,CAAE;QAC3B7D,IAAI,EAAC,MAAM;QACXT,QAAQ,EAAEA,QAAS;QACnBuE,QAAQ,EAAE,SAAAA,SAAAjC,CAAC;UAAA,OACPS,MAAI,CAACP,oBAAoB,CAAEF,CAAC,CAACkC,MAAM,CAAC3E,KAAK,IAA2B,EAAE,CAAC;QAAA;MAC1E,CACJ,CACW,CAAC;IAEzB;EAAC;AAAA,EAjNsB4E,cAAK,CAACC,SAAS;AAAA,IAAA/E,gBAAA,CAAAT,OAAA,EAA7BL,KAAK,kBACQ;EAClBsB,MAAM,EAAE,EAAE;EACVH,QAAQ,EAAE,KAAK;EACfI,OAAO,EAAE,KAAK;EACdH,eAAe,EAAE,MAAM;EACvBC,gBAAgB,EAAE,IAAI;EACtBmB,eAAe,EAAE;AACrB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_Files","require","_default","exports","default","Files"],"sources":["index.ts"],"sourcesContent":["import { Files } from \"./Files\";\n\nexport default Files;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAgC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEjBC,YAAK","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const generateId: () => string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.generateId = void 0;
|
|
7
|
+
var generateId = exports.generateId = function generateId() {
|
|
8
|
+
return "_" + Math.random().toString(36).substr(2, 9);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=generateId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["generateId","exports","Math","random","toString","substr"],"sources":["generateId.ts"],"sourcesContent":["export const generateId = () => {\n return \"_\" + Math.random().toString(36).substr(2, 9);\n};\n"],"mappings":";;;;;;AAAO,IAAMA,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAG,SAAbA,UAAUA,CAAA,EAAS;EAC5B,OAAO,GAAG,GAAGE,IAAI,CAACC,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,EAAE,CAAC,CAACC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;AACxD,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const readFileContent: (file: File) => Promise<string>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.readFileContent = void 0;
|
|
7
|
+
var readFileContent = exports.readFileContent = async function readFileContent(file) {
|
|
8
|
+
return new Promise(function (resolve, reject) {
|
|
9
|
+
var reader = new window.FileReader();
|
|
10
|
+
reader.onload = function (e) {
|
|
11
|
+
if (e.target) {
|
|
12
|
+
resolve(e.target.result);
|
|
13
|
+
} else {
|
|
14
|
+
reject("Unable to read file contents!");
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
reader.readAsDataURL(file);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=readFileContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["readFileContent","exports","file","Promise","resolve","reject","reader","window","FileReader","onload","e","target","result","readAsDataURL"],"sources":["readFileContent.ts"],"sourcesContent":["export const readFileContent = async (file: File) => {\n return new Promise<string>((resolve, reject) => {\n const reader = new window.FileReader();\n reader.onload = function (e) {\n if (e.target) {\n resolve(e.target.result as string);\n } else {\n reject(`Unable to read file contents!`);\n }\n };\n\n reader.readAsDataURL(file);\n });\n};\n"],"mappings":";;;;;;AAAO,IAAMA,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAAG,eAAlBA,eAAeA,CAAUE,IAAU,EAAK;EACjD,OAAO,IAAIC,OAAO,CAAS,UAACC,OAAO,EAAEC,MAAM,EAAK;IAC5C,IAAMC,MAAM,GAAG,IAAIC,MAAM,CAACC,UAAU,CAAC,CAAC;IACtCF,MAAM,CAACG,MAAM,GAAG,UAAUC,CAAC,EAAE;MACzB,IAAIA,CAAC,CAACC,MAAM,EAAE;QACVP,OAAO,CAACM,CAAC,CAACC,MAAM,CAACC,MAAgB,CAAC;MACtC,CAAC,MAAM;QACHP,MAAM,gCAAgC,CAAC;MAC3C;IACJ,CAAC;IAEDC,MAAM,CAACO,aAAa,CAACX,IAAI,CAAC;EAC9B,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|