@veritone-ce/design-system 1.12.46 → 1.12.47
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/dist/cjs/components/FileUploader/index.js +166 -156
- package/dist/cjs/index.js +10 -1
- package/dist/esm/components/FileUploader/index.js +163 -153
- package/dist/esm/index.js +1 -1
- package/dist/types/components/FileUploader/index.d.ts +18 -14
- package/dist/types/index.d.ts +2 -2
- package/package.json +1 -1
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports["default"] =
|
|
8
|
+
exports["default"] = FileUploader;
|
|
9
|
+
exports.useFileUploader = useFileUploader;
|
|
9
10
|
var _react = require("react");
|
|
10
11
|
var _material = require("@mui/material");
|
|
11
12
|
var _styles = require("@mui/material/styles");
|
|
@@ -13,24 +14,21 @@ var _iconsMaterial = require("@mui/icons-material");
|
|
|
13
14
|
var _reactDropzone = require("react-dropzone");
|
|
14
15
|
var _index = _interopRequireDefault(require("../LinearProgress/index.js"));
|
|
15
16
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
|
-
var _excluded = ["accept", "multiple", "uploadFile", "onComplete", "onError"];
|
|
17
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
18
18
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
19
19
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
20
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
21
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
20
22
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
21
23
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
22
24
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
23
25
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
24
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
25
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
26
26
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
27
27
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
28
28
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
29
29
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
30
30
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
31
31
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
32
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
33
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
34
32
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
35
33
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
36
34
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -38,9 +36,17 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _ty
|
|
|
38
36
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
39
37
|
function _asyncIterator(iterable) { var method, async, sync, retry = 2; for ("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;) { if (async && null != (method = iterable[async])) return method.call(iterable); if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable)); async = "@@asyncIterator", sync = "@@iterator"; } throw new TypeError("Object is not async iterable"); }
|
|
40
38
|
function AsyncFromSyncIterator(s) { function AsyncFromSyncIteratorContinuation(r) { if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object.")); var done = r.done; return Promise.resolve(r.value).then(function (value) { return { value: value, done: done }; }); } return AsyncFromSyncIterator = function AsyncFromSyncIterator(s) { this.s = s, this.n = s.next; }, AsyncFromSyncIterator.prototype = { s: null, n: null, next: function next() { return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments)); }, "return": function _return(value) { var ret = this.s["return"]; return void 0 === ret ? Promise.resolve({ value: value, done: !0 }) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments)); }, "throw": function _throw(value) { var thr = this.s["return"]; return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments)); } }, new AsyncFromSyncIterator(s); }
|
|
41
|
-
|
|
39
|
+
function FileUploader(props) {
|
|
42
40
|
var _useTheme = (0, _styles.useTheme)(),
|
|
43
41
|
palette = _useTheme.palette;
|
|
42
|
+
var _useDropzone = (0, _reactDropzone.useDropzone)({
|
|
43
|
+
disabled: props.uploading || props.uploaded,
|
|
44
|
+
multiple: props.multiple,
|
|
45
|
+
accept: props.accept,
|
|
46
|
+
onDrop: props.onDrop
|
|
47
|
+
}),
|
|
48
|
+
getRootProps = _useDropzone.getRootProps,
|
|
49
|
+
getInputProps = _useDropzone.getInputProps;
|
|
44
50
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
45
51
|
"data-testid": props['data-testid'],
|
|
46
52
|
sx: props.sx,
|
|
@@ -64,13 +70,13 @@ var FileUploaderView = function FileUploaderView(props) {
|
|
|
64
70
|
cursor: 'pointer',
|
|
65
71
|
outline: "1px solid ".concat(palette.neutral.main)
|
|
66
72
|
}
|
|
67
|
-
},
|
|
73
|
+
}, getRootProps()), {}, {
|
|
68
74
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", _objectSpread({
|
|
69
75
|
type: 'file',
|
|
70
76
|
style: {
|
|
71
77
|
display: 'none'
|
|
72
78
|
}
|
|
73
|
-
},
|
|
79
|
+
}, getInputProps())), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
|
|
74
80
|
sx: {
|
|
75
81
|
display: 'flex',
|
|
76
82
|
alignItems: 'center',
|
|
@@ -113,7 +119,7 @@ var FileUploaderView = function FileUploaderView(props) {
|
|
|
113
119
|
lineHeight: '16px',
|
|
114
120
|
color: palette.neutral.main
|
|
115
121
|
},
|
|
116
|
-
children: ["Supported File Formats:
|
|
122
|
+
children: ["Supported File Formats:", ' ', Object.values(props.accept).flat().join(', ')]
|
|
117
123
|
})]
|
|
118
124
|
})]
|
|
119
125
|
})), props.filesState.map(function (file, index) {
|
|
@@ -135,7 +141,7 @@ var FileUploaderView = function FileUploaderView(props) {
|
|
|
135
141
|
isError: file.withError,
|
|
136
142
|
feedbackText: file.feedbackText,
|
|
137
143
|
isUploaded: file.isUploaded
|
|
138
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, {
|
|
144
|
+
}), !props.uploading && !props.uploaded && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, {
|
|
139
145
|
"data-testid": "file-item-delete-button",
|
|
140
146
|
"aria-label": "delete",
|
|
141
147
|
sx: {
|
|
@@ -155,23 +161,24 @@ var FileUploaderView = function FileUploaderView(props) {
|
|
|
155
161
|
}, index);
|
|
156
162
|
})]
|
|
157
163
|
});
|
|
158
|
-
}
|
|
164
|
+
}
|
|
159
165
|
|
|
160
166
|
// this returns a generator to provide incremental progress updates. See storybook for example
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
var _ref2;
|
|
164
|
-
var accept = _ref.accept,
|
|
165
|
-
multiple = _ref.multiple,
|
|
166
|
-
uploadFile = _ref.uploadFile,
|
|
167
|
-
onComplete = _ref.onComplete,
|
|
168
|
-
onError = _ref.onError,
|
|
169
|
-
props = _objectWithoutProperties(_ref, _excluded);
|
|
167
|
+
|
|
168
|
+
function useFileUploader(options) {
|
|
170
169
|
var filesRef = (0, _react.useRef)([]);
|
|
171
170
|
var _useState = (0, _react.useState)([]),
|
|
172
171
|
_useState2 = _slicedToArray(_useState, 2),
|
|
173
172
|
filesState = _useState2[0],
|
|
174
173
|
setFilesState = _useState2[1];
|
|
174
|
+
var _useState3 = (0, _react.useState)(false),
|
|
175
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
176
|
+
uploading = _useState4[0],
|
|
177
|
+
setUploading = _useState4[1];
|
|
178
|
+
var _useState5 = (0, _react.useState)(false),
|
|
179
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
180
|
+
uploaded = _useState6[0],
|
|
181
|
+
setUploaded = _useState6[1];
|
|
175
182
|
var updateFileState = function updateFileState(file, update) {
|
|
176
183
|
setFilesState(function (prevFilesState) {
|
|
177
184
|
var index = filesRef.current.indexOf(file);
|
|
@@ -187,144 +194,147 @@ var FileUploader = function FileUploader(_ref) {
|
|
|
187
194
|
});
|
|
188
195
|
});
|
|
189
196
|
};
|
|
190
|
-
var uploadFiles = /*#__PURE__*/function uploadFiles(_x2) {
|
|
191
|
-
return (_ref2 = _ref2 || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(acceptedFiles) {
|
|
192
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
193
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
194
|
-
case 0:
|
|
195
|
-
// add files to processing list
|
|
196
|
-
filesRef.current = [].concat(_toConsumableArray(filesRef.current), _toConsumableArray(acceptedFiles));
|
|
197
|
-
setFilesState(function (prevFilesState) {
|
|
198
|
-
return [].concat(_toConsumableArray(prevFilesState), _toConsumableArray(acceptedFiles.map(function (acceptedFile) {
|
|
199
|
-
return {
|
|
200
|
-
name: acceptedFile.name,
|
|
201
|
-
isUploaded: false,
|
|
202
|
-
uploadProgress: 0,
|
|
203
|
-
withError: false,
|
|
204
|
-
feedbackText: ''
|
|
205
|
-
};
|
|
206
|
-
})));
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
// upload
|
|
210
|
-
acceptedFiles.forEach(function (acceptedFile) {
|
|
211
|
-
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
212
|
-
var uploadProgress, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, newProgress;
|
|
213
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
214
|
-
while (1) switch (_context.prev = _context.next) {
|
|
215
|
-
case 0:
|
|
216
|
-
_context.prev = 0;
|
|
217
|
-
_context.next = 3;
|
|
218
|
-
return uploadFile(acceptedFile);
|
|
219
|
-
case 3:
|
|
220
|
-
uploadProgress = _context.sent;
|
|
221
|
-
// get progress updates
|
|
222
|
-
_iteratorAbruptCompletion = false;
|
|
223
|
-
_didIteratorError = false;
|
|
224
|
-
_context.prev = 6;
|
|
225
|
-
_iterator = _asyncIterator(uploadProgress);
|
|
226
|
-
case 8:
|
|
227
|
-
_context.next = 10;
|
|
228
|
-
return _iterator.next();
|
|
229
|
-
case 10:
|
|
230
|
-
if (!(_iteratorAbruptCompletion = !(_step = _context.sent).done)) {
|
|
231
|
-
_context.next = 16;
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
newProgress = _step.value;
|
|
235
|
-
updateFileState(acceptedFile, {
|
|
236
|
-
uploadProgress: newProgress
|
|
237
|
-
});
|
|
238
|
-
case 13:
|
|
239
|
-
_iteratorAbruptCompletion = false;
|
|
240
|
-
_context.next = 8;
|
|
241
|
-
break;
|
|
242
|
-
case 16:
|
|
243
|
-
_context.next = 22;
|
|
244
|
-
break;
|
|
245
|
-
case 18:
|
|
246
|
-
_context.prev = 18;
|
|
247
|
-
_context.t0 = _context["catch"](6);
|
|
248
|
-
_didIteratorError = true;
|
|
249
|
-
_iteratorError = _context.t0;
|
|
250
|
-
case 22:
|
|
251
|
-
_context.prev = 22;
|
|
252
|
-
_context.prev = 23;
|
|
253
|
-
if (!(_iteratorAbruptCompletion && _iterator["return"] != null)) {
|
|
254
|
-
_context.next = 27;
|
|
255
|
-
break;
|
|
256
|
-
}
|
|
257
|
-
_context.next = 27;
|
|
258
|
-
return _iterator["return"]();
|
|
259
|
-
case 27:
|
|
260
|
-
_context.prev = 27;
|
|
261
|
-
if (!_didIteratorError) {
|
|
262
|
-
_context.next = 30;
|
|
263
|
-
break;
|
|
264
|
-
}
|
|
265
|
-
throw _iteratorError;
|
|
266
|
-
case 30:
|
|
267
|
-
return _context.finish(27);
|
|
268
|
-
case 31:
|
|
269
|
-
return _context.finish(22);
|
|
270
|
-
case 32:
|
|
271
|
-
// complete
|
|
272
|
-
updateFileState(acceptedFile, {
|
|
273
|
-
isUploaded: true,
|
|
274
|
-
uploadProgress: 100
|
|
275
|
-
});
|
|
276
|
-
onComplete === null || onComplete === void 0 ? void 0 : onComplete(acceptedFile);
|
|
277
|
-
_context.next = 40;
|
|
278
|
-
break;
|
|
279
|
-
case 36:
|
|
280
|
-
_context.prev = 36;
|
|
281
|
-
_context.t1 = _context["catch"](0);
|
|
282
|
-
// catch error
|
|
283
|
-
updateFileState(acceptedFile, {
|
|
284
|
-
withError: true
|
|
285
|
-
});
|
|
286
|
-
onError === null || onError === void 0 ? void 0 : onError(_context.t1);
|
|
287
|
-
case 40:
|
|
288
|
-
case "end":
|
|
289
|
-
return _context.stop();
|
|
290
|
-
}
|
|
291
|
-
}, _callee, null, [[0, 36], [6, 18, 22, 32], [23,, 27, 31]]);
|
|
292
|
-
}))();
|
|
293
|
-
});
|
|
294
|
-
case 3:
|
|
295
|
-
case "end":
|
|
296
|
-
return _context2.stop();
|
|
297
|
-
}
|
|
298
|
-
}, _callee2);
|
|
299
|
-
}))).apply(this, arguments);
|
|
300
|
-
};
|
|
301
|
-
var _useDropzone = (0, _reactDropzone.useDropzone)({
|
|
302
|
-
multiple: multiple,
|
|
303
|
-
accept: accept,
|
|
304
|
-
onDrop: function onDrop(acceptedFiles) {
|
|
305
|
-
uploadFiles(acceptedFiles)["catch"](function (err) {
|
|
306
|
-
onError === null || onError === void 0 ? void 0 : onError(err);
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
}),
|
|
310
|
-
getRootProps = _useDropzone.getRootProps,
|
|
311
|
-
getInputProps = _useDropzone.getInputProps;
|
|
312
197
|
var handleDeleteFile = (0, _react.useCallback)(function (fileIndex) {
|
|
313
198
|
filesRef.current.splice(fileIndex, 1);
|
|
314
199
|
var nFileList = _toConsumableArray(filesState);
|
|
315
200
|
nFileList.splice(fileIndex, 1);
|
|
316
201
|
setFilesState(nFileList);
|
|
317
202
|
}, [filesState]);
|
|
318
|
-
return
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
203
|
+
return {
|
|
204
|
+
files: filesState,
|
|
205
|
+
onDrop: function onDrop(acceptedFiles) {
|
|
206
|
+
// add files to processing list
|
|
207
|
+
filesRef.current = [].concat(_toConsumableArray(filesRef.current), _toConsumableArray(acceptedFiles));
|
|
208
|
+
setFilesState(function (prevFilesState) {
|
|
209
|
+
return [].concat(_toConsumableArray(prevFilesState), _toConsumableArray(acceptedFiles.map(function (acceptedFile) {
|
|
210
|
+
return {
|
|
211
|
+
name: acceptedFile.name,
|
|
212
|
+
isUploaded: false,
|
|
213
|
+
uploadProgress: 0,
|
|
214
|
+
withError: false,
|
|
215
|
+
feedbackText: 'Pending'
|
|
216
|
+
};
|
|
217
|
+
})));
|
|
218
|
+
});
|
|
219
|
+
},
|
|
220
|
+
removeFile: handleDeleteFile,
|
|
221
|
+
uploading: uploading,
|
|
222
|
+
uploaded: uploaded,
|
|
223
|
+
uploadFiles: function uploadFiles() {
|
|
224
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
225
|
+
var _ref;
|
|
226
|
+
var results;
|
|
227
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
228
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
229
|
+
case 0:
|
|
230
|
+
if (!(uploading || uploaded)) {
|
|
231
|
+
_context2.next = 2;
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
return _context2.abrupt("return", []);
|
|
235
|
+
case 2:
|
|
236
|
+
setUploading(true);
|
|
237
|
+
_context2.next = 5;
|
|
238
|
+
return Promise.allSettled(filesRef.current.map( /*#__PURE__*/function (_x2) {
|
|
239
|
+
return (_ref = _ref || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(acceptedFile) {
|
|
240
|
+
var _options$onComplete, uploadProgress, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, newProgress, _options$onError;
|
|
241
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
242
|
+
while (1) switch (_context.prev = _context.next) {
|
|
243
|
+
case 0:
|
|
244
|
+
_context.prev = 0;
|
|
245
|
+
updateFileState(acceptedFile, {
|
|
246
|
+
feedbackText: ''
|
|
247
|
+
});
|
|
248
|
+
_context.next = 4;
|
|
249
|
+
return options.uploadFile(acceptedFile);
|
|
250
|
+
case 4:
|
|
251
|
+
uploadProgress = _context.sent;
|
|
252
|
+
// get progress updates
|
|
253
|
+
_iteratorAbruptCompletion = false;
|
|
254
|
+
_didIteratorError = false;
|
|
255
|
+
_context.prev = 7;
|
|
256
|
+
_iterator = _asyncIterator(uploadProgress);
|
|
257
|
+
case 9:
|
|
258
|
+
_context.next = 11;
|
|
259
|
+
return _iterator.next();
|
|
260
|
+
case 11:
|
|
261
|
+
if (!(_iteratorAbruptCompletion = !(_step = _context.sent).done)) {
|
|
262
|
+
_context.next = 17;
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
newProgress = _step.value;
|
|
266
|
+
updateFileState(acceptedFile, {
|
|
267
|
+
uploadProgress: newProgress,
|
|
268
|
+
feedbackText: ''
|
|
269
|
+
});
|
|
270
|
+
case 14:
|
|
271
|
+
_iteratorAbruptCompletion = false;
|
|
272
|
+
_context.next = 9;
|
|
273
|
+
break;
|
|
274
|
+
case 17:
|
|
275
|
+
_context.next = 23;
|
|
276
|
+
break;
|
|
277
|
+
case 19:
|
|
278
|
+
_context.prev = 19;
|
|
279
|
+
_context.t0 = _context["catch"](7);
|
|
280
|
+
_didIteratorError = true;
|
|
281
|
+
_iteratorError = _context.t0;
|
|
282
|
+
case 23:
|
|
283
|
+
_context.prev = 23;
|
|
284
|
+
_context.prev = 24;
|
|
285
|
+
if (!(_iteratorAbruptCompletion && _iterator["return"] != null)) {
|
|
286
|
+
_context.next = 28;
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
_context.next = 28;
|
|
290
|
+
return _iterator["return"]();
|
|
291
|
+
case 28:
|
|
292
|
+
_context.prev = 28;
|
|
293
|
+
if (!_didIteratorError) {
|
|
294
|
+
_context.next = 31;
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
throw _iteratorError;
|
|
298
|
+
case 31:
|
|
299
|
+
return _context.finish(28);
|
|
300
|
+
case 32:
|
|
301
|
+
return _context.finish(23);
|
|
302
|
+
case 33:
|
|
303
|
+
// complete
|
|
304
|
+
updateFileState(acceptedFile, {
|
|
305
|
+
isUploaded: true,
|
|
306
|
+
uploadProgress: 100
|
|
307
|
+
});
|
|
308
|
+
(_options$onComplete = options.onComplete) === null || _options$onComplete === void 0 ? void 0 : _options$onComplete.call(options, acceptedFile);
|
|
309
|
+
_context.next = 42;
|
|
310
|
+
break;
|
|
311
|
+
case 37:
|
|
312
|
+
_context.prev = 37;
|
|
313
|
+
_context.t1 = _context["catch"](0);
|
|
314
|
+
// catch error
|
|
315
|
+
updateFileState(acceptedFile, {
|
|
316
|
+
withError: true
|
|
317
|
+
});
|
|
318
|
+
(_options$onError = options.onError) === null || _options$onError === void 0 ? void 0 : _options$onError.call(options, _context.t1);
|
|
319
|
+
throw _context.t1;
|
|
320
|
+
case 42:
|
|
321
|
+
case "end":
|
|
322
|
+
return _context.stop();
|
|
323
|
+
}
|
|
324
|
+
}, _callee, null, [[0, 37], [7, 19, 23, 33], [24,, 28, 32]]);
|
|
325
|
+
}))).apply(this, arguments);
|
|
326
|
+
}));
|
|
327
|
+
case 5:
|
|
328
|
+
results = _context2.sent;
|
|
329
|
+
setUploading(false);
|
|
330
|
+
setUploaded(true);
|
|
331
|
+
return _context2.abrupt("return", results);
|
|
332
|
+
case 9:
|
|
333
|
+
case "end":
|
|
334
|
+
return _context2.stop();
|
|
335
|
+
}
|
|
336
|
+
}, _callee2);
|
|
337
|
+
}))();
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
@@ -267,6 +268,12 @@ Object.defineProperty(exports, "createDesignSystemTheme", {
|
|
|
267
268
|
return _theme.createDesignSystemTheme;
|
|
268
269
|
}
|
|
269
270
|
});
|
|
271
|
+
Object.defineProperty(exports, "useFileUploader", {
|
|
272
|
+
enumerable: true,
|
|
273
|
+
get: function get() {
|
|
274
|
+
return _index7.useFileUploader;
|
|
275
|
+
}
|
|
276
|
+
});
|
|
270
277
|
Object.defineProperty(exports, "useTheme", {
|
|
271
278
|
enumerable: true,
|
|
272
279
|
get: function get() {
|
|
@@ -280,7 +287,7 @@ var _index3 = _interopRequireDefault(require("./components/Breadcrumbs/index.js"
|
|
|
280
287
|
var _index4 = _interopRequireDefault(require("./components/Button/index.js"));
|
|
281
288
|
var _index5 = _interopRequireDefault(require("./components/Checkbox/index.js"));
|
|
282
289
|
var _index6 = _interopRequireDefault(require("./components/Drawer/index.js"));
|
|
283
|
-
var _index7 =
|
|
290
|
+
var _index7 = _interopRequireWildcard(require("./components/FileUploader/index.js"));
|
|
284
291
|
var _index8 = _interopRequireDefault(require("./components/FormControlLabel/index.js"));
|
|
285
292
|
var _index9 = _interopRequireDefault(require("./components/Input/index.js"));
|
|
286
293
|
var _index10 = _interopRequireDefault(require("./components/LinearProgress/index.js"));
|
|
@@ -309,4 +316,6 @@ var _index32 = _interopRequireDefault(require("./components/icons/HomeOutlinedIc
|
|
|
309
316
|
var _index33 = _interopRequireDefault(require("./components/icons/IconGroups/index.js"));
|
|
310
317
|
var _index34 = _interopRequireDefault(require("./components/icons/IconListItem/index.js"));
|
|
311
318
|
var _index35 = _interopRequireDefault(require("./components/Autocomplete/index.js"));
|
|
319
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
320
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
312
321
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
-
var _excluded = ["accept", "multiple", "uploadFile", "onComplete", "onError"];
|
|
5
4
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
6
5
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
6
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
7
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
7
8
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
9
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
10
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
10
11
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
11
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
12
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
13
12
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
14
13
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15
14
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
16
15
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
17
16
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
18
17
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
19
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
20
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
21
18
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
22
19
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
23
20
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -33,9 +30,17 @@ import { useDropzone } from 'react-dropzone';
|
|
|
33
30
|
import LinearProgress from '../LinearProgress/index.js';
|
|
34
31
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
35
32
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
36
|
-
export
|
|
33
|
+
export default function FileUploader(props) {
|
|
37
34
|
var _useTheme = useTheme(),
|
|
38
35
|
palette = _useTheme.palette;
|
|
36
|
+
var _useDropzone = useDropzone({
|
|
37
|
+
disabled: props.uploading || props.uploaded,
|
|
38
|
+
multiple: props.multiple,
|
|
39
|
+
accept: props.accept,
|
|
40
|
+
onDrop: props.onDrop
|
|
41
|
+
}),
|
|
42
|
+
getRootProps = _useDropzone.getRootProps,
|
|
43
|
+
getInputProps = _useDropzone.getInputProps;
|
|
39
44
|
return /*#__PURE__*/_jsxs(Box, {
|
|
40
45
|
"data-testid": props['data-testid'],
|
|
41
46
|
sx: props.sx,
|
|
@@ -59,13 +64,13 @@ export var FileUploaderView = function FileUploaderView(props) {
|
|
|
59
64
|
cursor: 'pointer',
|
|
60
65
|
outline: "1px solid ".concat(palette.neutral.main)
|
|
61
66
|
}
|
|
62
|
-
},
|
|
67
|
+
}, getRootProps()), {}, {
|
|
63
68
|
children: [/*#__PURE__*/_jsx("input", _objectSpread({
|
|
64
69
|
type: 'file',
|
|
65
70
|
style: {
|
|
66
71
|
display: 'none'
|
|
67
72
|
}
|
|
68
|
-
},
|
|
73
|
+
}, getInputProps())), /*#__PURE__*/_jsx(Box, {
|
|
69
74
|
sx: {
|
|
70
75
|
display: 'flex',
|
|
71
76
|
alignItems: 'center',
|
|
@@ -108,7 +113,7 @@ export var FileUploaderView = function FileUploaderView(props) {
|
|
|
108
113
|
lineHeight: '16px',
|
|
109
114
|
color: palette.neutral.main
|
|
110
115
|
},
|
|
111
|
-
children: ["Supported File Formats:
|
|
116
|
+
children: ["Supported File Formats:", ' ', Object.values(props.accept).flat().join(', ')]
|
|
112
117
|
})]
|
|
113
118
|
})]
|
|
114
119
|
})), props.filesState.map(function (file, index) {
|
|
@@ -130,7 +135,7 @@ export var FileUploaderView = function FileUploaderView(props) {
|
|
|
130
135
|
isError: file.withError,
|
|
131
136
|
feedbackText: file.feedbackText,
|
|
132
137
|
isUploaded: file.isUploaded
|
|
133
|
-
}), /*#__PURE__*/_jsx(IconButton, {
|
|
138
|
+
}), !props.uploading && !props.uploaded && /*#__PURE__*/_jsx(IconButton, {
|
|
134
139
|
"data-testid": "file-item-delete-button",
|
|
135
140
|
"aria-label": "delete",
|
|
136
141
|
sx: {
|
|
@@ -150,23 +155,24 @@ export var FileUploaderView = function FileUploaderView(props) {
|
|
|
150
155
|
}, index);
|
|
151
156
|
})]
|
|
152
157
|
});
|
|
153
|
-
}
|
|
158
|
+
}
|
|
154
159
|
|
|
155
160
|
// this returns a generator to provide incremental progress updates. See storybook for example
|
|
156
161
|
|
|
157
|
-
|
|
158
|
-
var _ref2;
|
|
159
|
-
var accept = _ref.accept,
|
|
160
|
-
multiple = _ref.multiple,
|
|
161
|
-
uploadFile = _ref.uploadFile,
|
|
162
|
-
onComplete = _ref.onComplete,
|
|
163
|
-
onError = _ref.onError,
|
|
164
|
-
props = _objectWithoutProperties(_ref, _excluded);
|
|
162
|
+
export function useFileUploader(options) {
|
|
165
163
|
var filesRef = useRef([]);
|
|
166
164
|
var _useState = useState([]),
|
|
167
165
|
_useState2 = _slicedToArray(_useState, 2),
|
|
168
166
|
filesState = _useState2[0],
|
|
169
167
|
setFilesState = _useState2[1];
|
|
168
|
+
var _useState3 = useState(false),
|
|
169
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
170
|
+
uploading = _useState4[0],
|
|
171
|
+
setUploading = _useState4[1];
|
|
172
|
+
var _useState5 = useState(false),
|
|
173
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
174
|
+
uploaded = _useState6[0],
|
|
175
|
+
setUploaded = _useState6[1];
|
|
170
176
|
var updateFileState = function updateFileState(file, update) {
|
|
171
177
|
setFilesState(function (prevFilesState) {
|
|
172
178
|
var index = filesRef.current.indexOf(file);
|
|
@@ -182,143 +188,147 @@ var FileUploader = function FileUploader(_ref) {
|
|
|
182
188
|
});
|
|
183
189
|
});
|
|
184
190
|
};
|
|
185
|
-
var uploadFiles = /*#__PURE__*/function uploadFiles(_x2) {
|
|
186
|
-
return (_ref2 = _ref2 || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(acceptedFiles) {
|
|
187
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
188
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
189
|
-
case 0:
|
|
190
|
-
// add files to processing list
|
|
191
|
-
filesRef.current = [].concat(_toConsumableArray(filesRef.current), _toConsumableArray(acceptedFiles));
|
|
192
|
-
setFilesState(function (prevFilesState) {
|
|
193
|
-
return [].concat(_toConsumableArray(prevFilesState), _toConsumableArray(acceptedFiles.map(function (acceptedFile) {
|
|
194
|
-
return {
|
|
195
|
-
name: acceptedFile.name,
|
|
196
|
-
isUploaded: false,
|
|
197
|
-
uploadProgress: 0,
|
|
198
|
-
withError: false,
|
|
199
|
-
feedbackText: ''
|
|
200
|
-
};
|
|
201
|
-
})));
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
// upload
|
|
205
|
-
acceptedFiles.forEach(function (acceptedFile) {
|
|
206
|
-
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
207
|
-
var uploadProgress, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, newProgress;
|
|
208
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
209
|
-
while (1) switch (_context.prev = _context.next) {
|
|
210
|
-
case 0:
|
|
211
|
-
_context.prev = 0;
|
|
212
|
-
_context.next = 3;
|
|
213
|
-
return uploadFile(acceptedFile);
|
|
214
|
-
case 3:
|
|
215
|
-
uploadProgress = _context.sent;
|
|
216
|
-
// get progress updates
|
|
217
|
-
_iteratorAbruptCompletion = false;
|
|
218
|
-
_didIteratorError = false;
|
|
219
|
-
_context.prev = 6;
|
|
220
|
-
_iterator = _asyncIterator(uploadProgress);
|
|
221
|
-
case 8:
|
|
222
|
-
_context.next = 10;
|
|
223
|
-
return _iterator.next();
|
|
224
|
-
case 10:
|
|
225
|
-
if (!(_iteratorAbruptCompletion = !(_step = _context.sent).done)) {
|
|
226
|
-
_context.next = 16;
|
|
227
|
-
break;
|
|
228
|
-
}
|
|
229
|
-
newProgress = _step.value;
|
|
230
|
-
updateFileState(acceptedFile, {
|
|
231
|
-
uploadProgress: newProgress
|
|
232
|
-
});
|
|
233
|
-
case 13:
|
|
234
|
-
_iteratorAbruptCompletion = false;
|
|
235
|
-
_context.next = 8;
|
|
236
|
-
break;
|
|
237
|
-
case 16:
|
|
238
|
-
_context.next = 22;
|
|
239
|
-
break;
|
|
240
|
-
case 18:
|
|
241
|
-
_context.prev = 18;
|
|
242
|
-
_context.t0 = _context["catch"](6);
|
|
243
|
-
_didIteratorError = true;
|
|
244
|
-
_iteratorError = _context.t0;
|
|
245
|
-
case 22:
|
|
246
|
-
_context.prev = 22;
|
|
247
|
-
_context.prev = 23;
|
|
248
|
-
if (!(_iteratorAbruptCompletion && _iterator["return"] != null)) {
|
|
249
|
-
_context.next = 27;
|
|
250
|
-
break;
|
|
251
|
-
}
|
|
252
|
-
_context.next = 27;
|
|
253
|
-
return _iterator["return"]();
|
|
254
|
-
case 27:
|
|
255
|
-
_context.prev = 27;
|
|
256
|
-
if (!_didIteratorError) {
|
|
257
|
-
_context.next = 30;
|
|
258
|
-
break;
|
|
259
|
-
}
|
|
260
|
-
throw _iteratorError;
|
|
261
|
-
case 30:
|
|
262
|
-
return _context.finish(27);
|
|
263
|
-
case 31:
|
|
264
|
-
return _context.finish(22);
|
|
265
|
-
case 32:
|
|
266
|
-
// complete
|
|
267
|
-
updateFileState(acceptedFile, {
|
|
268
|
-
isUploaded: true,
|
|
269
|
-
uploadProgress: 100
|
|
270
|
-
});
|
|
271
|
-
onComplete === null || onComplete === void 0 ? void 0 : onComplete(acceptedFile);
|
|
272
|
-
_context.next = 40;
|
|
273
|
-
break;
|
|
274
|
-
case 36:
|
|
275
|
-
_context.prev = 36;
|
|
276
|
-
_context.t1 = _context["catch"](0);
|
|
277
|
-
// catch error
|
|
278
|
-
updateFileState(acceptedFile, {
|
|
279
|
-
withError: true
|
|
280
|
-
});
|
|
281
|
-
onError === null || onError === void 0 ? void 0 : onError(_context.t1);
|
|
282
|
-
case 40:
|
|
283
|
-
case "end":
|
|
284
|
-
return _context.stop();
|
|
285
|
-
}
|
|
286
|
-
}, _callee, null, [[0, 36], [6, 18, 22, 32], [23,, 27, 31]]);
|
|
287
|
-
}))();
|
|
288
|
-
});
|
|
289
|
-
case 3:
|
|
290
|
-
case "end":
|
|
291
|
-
return _context2.stop();
|
|
292
|
-
}
|
|
293
|
-
}, _callee2);
|
|
294
|
-
}))).apply(this, arguments);
|
|
295
|
-
};
|
|
296
|
-
var _useDropzone = useDropzone({
|
|
297
|
-
multiple: multiple,
|
|
298
|
-
accept: accept,
|
|
299
|
-
onDrop: function onDrop(acceptedFiles) {
|
|
300
|
-
uploadFiles(acceptedFiles)["catch"](function (err) {
|
|
301
|
-
onError === null || onError === void 0 ? void 0 : onError(err);
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
}),
|
|
305
|
-
getRootProps = _useDropzone.getRootProps,
|
|
306
|
-
getInputProps = _useDropzone.getInputProps;
|
|
307
191
|
var handleDeleteFile = useCallback(function (fileIndex) {
|
|
308
192
|
filesRef.current.splice(fileIndex, 1);
|
|
309
193
|
var nFileList = _toConsumableArray(filesState);
|
|
310
194
|
nFileList.splice(fileIndex, 1);
|
|
311
195
|
setFilesState(nFileList);
|
|
312
196
|
}, [filesState]);
|
|
313
|
-
return
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
197
|
+
return {
|
|
198
|
+
files: filesState,
|
|
199
|
+
onDrop: function onDrop(acceptedFiles) {
|
|
200
|
+
// add files to processing list
|
|
201
|
+
filesRef.current = [].concat(_toConsumableArray(filesRef.current), _toConsumableArray(acceptedFiles));
|
|
202
|
+
setFilesState(function (prevFilesState) {
|
|
203
|
+
return [].concat(_toConsumableArray(prevFilesState), _toConsumableArray(acceptedFiles.map(function (acceptedFile) {
|
|
204
|
+
return {
|
|
205
|
+
name: acceptedFile.name,
|
|
206
|
+
isUploaded: false,
|
|
207
|
+
uploadProgress: 0,
|
|
208
|
+
withError: false,
|
|
209
|
+
feedbackText: 'Pending'
|
|
210
|
+
};
|
|
211
|
+
})));
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
removeFile: handleDeleteFile,
|
|
215
|
+
uploading: uploading,
|
|
216
|
+
uploaded: uploaded,
|
|
217
|
+
uploadFiles: function uploadFiles() {
|
|
218
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
219
|
+
var _ref;
|
|
220
|
+
var results;
|
|
221
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
222
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
223
|
+
case 0:
|
|
224
|
+
if (!(uploading || uploaded)) {
|
|
225
|
+
_context2.next = 2;
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
return _context2.abrupt("return", []);
|
|
229
|
+
case 2:
|
|
230
|
+
setUploading(true);
|
|
231
|
+
_context2.next = 5;
|
|
232
|
+
return Promise.allSettled(filesRef.current.map( /*#__PURE__*/function (_x2) {
|
|
233
|
+
return (_ref = _ref || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(acceptedFile) {
|
|
234
|
+
var _options$onComplete, uploadProgress, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, newProgress, _options$onError;
|
|
235
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
236
|
+
while (1) switch (_context.prev = _context.next) {
|
|
237
|
+
case 0:
|
|
238
|
+
_context.prev = 0;
|
|
239
|
+
updateFileState(acceptedFile, {
|
|
240
|
+
feedbackText: ''
|
|
241
|
+
});
|
|
242
|
+
_context.next = 4;
|
|
243
|
+
return options.uploadFile(acceptedFile);
|
|
244
|
+
case 4:
|
|
245
|
+
uploadProgress = _context.sent;
|
|
246
|
+
// get progress updates
|
|
247
|
+
_iteratorAbruptCompletion = false;
|
|
248
|
+
_didIteratorError = false;
|
|
249
|
+
_context.prev = 7;
|
|
250
|
+
_iterator = _asyncIterator(uploadProgress);
|
|
251
|
+
case 9:
|
|
252
|
+
_context.next = 11;
|
|
253
|
+
return _iterator.next();
|
|
254
|
+
case 11:
|
|
255
|
+
if (!(_iteratorAbruptCompletion = !(_step = _context.sent).done)) {
|
|
256
|
+
_context.next = 17;
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
newProgress = _step.value;
|
|
260
|
+
updateFileState(acceptedFile, {
|
|
261
|
+
uploadProgress: newProgress,
|
|
262
|
+
feedbackText: ''
|
|
263
|
+
});
|
|
264
|
+
case 14:
|
|
265
|
+
_iteratorAbruptCompletion = false;
|
|
266
|
+
_context.next = 9;
|
|
267
|
+
break;
|
|
268
|
+
case 17:
|
|
269
|
+
_context.next = 23;
|
|
270
|
+
break;
|
|
271
|
+
case 19:
|
|
272
|
+
_context.prev = 19;
|
|
273
|
+
_context.t0 = _context["catch"](7);
|
|
274
|
+
_didIteratorError = true;
|
|
275
|
+
_iteratorError = _context.t0;
|
|
276
|
+
case 23:
|
|
277
|
+
_context.prev = 23;
|
|
278
|
+
_context.prev = 24;
|
|
279
|
+
if (!(_iteratorAbruptCompletion && _iterator["return"] != null)) {
|
|
280
|
+
_context.next = 28;
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
_context.next = 28;
|
|
284
|
+
return _iterator["return"]();
|
|
285
|
+
case 28:
|
|
286
|
+
_context.prev = 28;
|
|
287
|
+
if (!_didIteratorError) {
|
|
288
|
+
_context.next = 31;
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
throw _iteratorError;
|
|
292
|
+
case 31:
|
|
293
|
+
return _context.finish(28);
|
|
294
|
+
case 32:
|
|
295
|
+
return _context.finish(23);
|
|
296
|
+
case 33:
|
|
297
|
+
// complete
|
|
298
|
+
updateFileState(acceptedFile, {
|
|
299
|
+
isUploaded: true,
|
|
300
|
+
uploadProgress: 100
|
|
301
|
+
});
|
|
302
|
+
(_options$onComplete = options.onComplete) === null || _options$onComplete === void 0 ? void 0 : _options$onComplete.call(options, acceptedFile);
|
|
303
|
+
_context.next = 42;
|
|
304
|
+
break;
|
|
305
|
+
case 37:
|
|
306
|
+
_context.prev = 37;
|
|
307
|
+
_context.t1 = _context["catch"](0);
|
|
308
|
+
// catch error
|
|
309
|
+
updateFileState(acceptedFile, {
|
|
310
|
+
withError: true
|
|
311
|
+
});
|
|
312
|
+
(_options$onError = options.onError) === null || _options$onError === void 0 ? void 0 : _options$onError.call(options, _context.t1);
|
|
313
|
+
throw _context.t1;
|
|
314
|
+
case 42:
|
|
315
|
+
case "end":
|
|
316
|
+
return _context.stop();
|
|
317
|
+
}
|
|
318
|
+
}, _callee, null, [[0, 37], [7, 19, 23, 33], [24,, 28, 32]]);
|
|
319
|
+
}))).apply(this, arguments);
|
|
320
|
+
}));
|
|
321
|
+
case 5:
|
|
322
|
+
results = _context2.sent;
|
|
323
|
+
setUploading(false);
|
|
324
|
+
setUploaded(true);
|
|
325
|
+
return _context2.abrupt("return", results);
|
|
326
|
+
case 9:
|
|
327
|
+
case "end":
|
|
328
|
+
return _context2.stop();
|
|
329
|
+
}
|
|
330
|
+
}, _callee2);
|
|
331
|
+
}))();
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -7,7 +7,7 @@ export { default as Breadcrumbs } from './components/Breadcrumbs/index.js';
|
|
|
7
7
|
export { default as Button } from './components/Button/index.js';
|
|
8
8
|
export { default as Checkbox } from './components/Checkbox/index.js';
|
|
9
9
|
export { default as Drawer } from './components/Drawer/index.js';
|
|
10
|
-
export { default as FileUploader } from './components/FileUploader/index.js';
|
|
10
|
+
export { default as FileUploader, useFileUploader } from './components/FileUploader/index.js';
|
|
11
11
|
export { default as FormControlLabel } from './components/FormControlLabel/index.js';
|
|
12
12
|
export { default as Input } from './components/Input/index.js';
|
|
13
13
|
export { default as LinearProgress } from './components/LinearProgress/index.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { SxProps, Theme } from '@mui/material/styles';
|
|
3
|
-
import { Accept
|
|
3
|
+
import { Accept } from 'react-dropzone';
|
|
4
4
|
export interface FileState {
|
|
5
5
|
name: string;
|
|
6
6
|
uploadProgress: number;
|
|
@@ -8,27 +8,31 @@ export interface FileState {
|
|
|
8
8
|
withError: boolean;
|
|
9
9
|
feedbackText: string;
|
|
10
10
|
}
|
|
11
|
-
export type
|
|
11
|
+
export type FileUploaderProps = {
|
|
12
12
|
'data-testid'?: string;
|
|
13
|
-
extensions: string[];
|
|
14
13
|
filesState: FileState[];
|
|
14
|
+
accept: Accept;
|
|
15
|
+
multiple?: boolean;
|
|
16
|
+
uploading?: boolean;
|
|
17
|
+
uploaded?: boolean;
|
|
18
|
+
onDrop(files: File[]): void;
|
|
15
19
|
onDelete(fileIndex: number): void;
|
|
16
|
-
rootProps?: DropzoneRootProps;
|
|
17
|
-
inputProps?: DropzoneInputProps;
|
|
18
20
|
sx?: SxProps<Theme>;
|
|
19
21
|
className?: string;
|
|
20
22
|
};
|
|
21
|
-
export
|
|
23
|
+
export default function FileUploader(props: FileUploaderProps): import("react").JSX.Element;
|
|
22
24
|
type FileUploadFn = (f: File) => AsyncGenerator<number>;
|
|
23
|
-
export type
|
|
24
|
-
'data-testid'?: string;
|
|
25
|
-
accept: Accept;
|
|
26
|
-
multiple?: boolean;
|
|
25
|
+
export type UseFileUploaderOptions = {
|
|
27
26
|
uploadFile: FileUploadFn;
|
|
28
27
|
onComplete?(f: File): void;
|
|
29
28
|
onError?(v: Error): void;
|
|
30
|
-
sx?: SxProps<Theme>;
|
|
31
|
-
className?: string;
|
|
32
29
|
};
|
|
33
|
-
declare
|
|
34
|
-
|
|
30
|
+
export declare function useFileUploader(options: UseFileUploaderOptions): {
|
|
31
|
+
files: FileState[];
|
|
32
|
+
onDrop(acceptedFiles: File[]): void;
|
|
33
|
+
removeFile: (fileIndex: number) => void;
|
|
34
|
+
uploading: boolean;
|
|
35
|
+
uploaded: boolean;
|
|
36
|
+
uploadFiles(): Promise<PromiseSettledResult<void>[]>;
|
|
37
|
+
};
|
|
38
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ export { default as Checkbox } from './components/Checkbox/index.js';
|
|
|
12
12
|
export type { CheckboxProps } from './components/Checkbox/index.js';
|
|
13
13
|
export { default as Drawer } from './components/Drawer/index.js';
|
|
14
14
|
export type { DrawerProps } from './components/Drawer/index.js';
|
|
15
|
-
export { default as FileUploader } from './components/FileUploader/index.js';
|
|
16
|
-
export type { FileUploaderProps } from './components/FileUploader/index.js';
|
|
15
|
+
export { default as FileUploader, useFileUploader } from './components/FileUploader/index.js';
|
|
16
|
+
export type { FileUploaderProps, UseFileUploaderOptions } from './components/FileUploader/index.js';
|
|
17
17
|
export { default as FormControlLabel } from './components/FormControlLabel/index.js';
|
|
18
18
|
export type { FormControlLabelProps } from './components/FormControlLabel/index.js';
|
|
19
19
|
export { default as Input } from './components/Input/index.js';
|