formiojs-eorion 0.1.39 → 0.1.41

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.
Files changed (37) hide show
  1. package/Formio.js +1 -1
  2. package/components/Data/editForm/Data.edit.display.js +2 -2
  3. package/components/builder.js +2 -0
  4. package/components/file_china_grid/File.form.js +36 -0
  5. package/components/file_china_grid/File.js +1018 -0
  6. package/components/file_china_grid/File.unit.js +175 -0
  7. package/components/file_china_grid/editForm/File.edit.data.js +11 -0
  8. package/components/file_china_grid/editForm/File.edit.display.js +11 -0
  9. package/components/file_china_grid/editForm/File.edit.file.js +257 -0
  10. package/components/file_china_grid/editForm/File.edit.validation.js +14 -0
  11. package/components/file_china_grid/fixtures/comp1.js +21 -0
  12. package/components/file_china_grid/fixtures/comp2.js +36 -0
  13. package/components/file_china_grid/fixtures/index.js +20 -0
  14. package/components/file_china_grid/fixtures/values.js +16 -0
  15. package/components/index.js +2 -0
  16. package/dist/formio.builder.css +38 -0
  17. package/dist/formio.builder.min.css +1 -1
  18. package/dist/formio.contrib.js +23 -2
  19. package/dist/formio.contrib.min.js +1 -1
  20. package/dist/formio.contrib.min.js.LICENSE.txt +1 -1
  21. package/dist/formio.embed.min.js.LICENSE.txt +1 -1
  22. package/dist/formio.form.js +92 -5
  23. package/dist/formio.form.min.js +1 -1
  24. package/dist/formio.form.min.js.LICENSE.txt +1 -1
  25. package/dist/formio.full.css +38 -0
  26. package/dist/formio.full.js +92 -5
  27. package/dist/formio.full.min.css +1 -1
  28. package/dist/formio.full.min.js +1 -1
  29. package/dist/formio.full.min.js.LICENSE.txt +1 -1
  30. package/dist/formio.js +1 -1
  31. package/dist/formio.min.js +1 -1
  32. package/dist/formio.min.js.LICENSE.txt +1 -1
  33. package/dist/formio.utils.min.js.LICENSE.txt +1 -1
  34. package/package.json +1 -1
  35. package/templates/bootstrap/fileUDS/form.ejs.js +227 -0
  36. package/templates/bootstrap/fileUDS/index.js +12 -0
  37. package/templates/bootstrap/index.js +3 -1
@@ -0,0 +1,1018 @@
1
+ "use strict";
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); }
4
+ require("core-js/modules/es.object.get-prototype-of.js");
5
+ require("core-js/modules/es.reflect.construct.js");
6
+ require("core-js/modules/es.reflect.get.js");
7
+ require("core-js/modules/es.object.get-own-property-descriptor.js");
8
+ require("core-js/modules/es.symbol.to-primitive.js");
9
+ require("core-js/modules/es.date.to-primitive.js");
10
+ require("core-js/modules/es.symbol.js");
11
+ require("core-js/modules/es.symbol.description.js");
12
+ require("core-js/modules/es.number.constructor.js");
13
+ require("core-js/modules/es.object.keys.js");
14
+ require("core-js/modules/es.array.filter.js");
15
+ require("core-js/modules/es.object.get-own-property-descriptors.js");
16
+ require("core-js/modules/es.symbol.iterator.js");
17
+ require("core-js/modules/es.string.iterator.js");
18
+ require("core-js/modules/web.dom-collections.iterator.js");
19
+ require("core-js/modules/es.symbol.async-iterator.js");
20
+ require("core-js/modules/es.symbol.to-string-tag.js");
21
+ require("core-js/modules/es.json.to-string-tag.js");
22
+ require("core-js/modules/es.math.to-string-tag.js");
23
+ Object.defineProperty(exports, "__esModule", {
24
+ value: true
25
+ });
26
+ exports.default = void 0;
27
+ require("core-js/modules/es.array.iterator.js");
28
+ require("core-js/modules/es.object.to-string.js");
29
+ require("core-js/modules/es.typed-array.uint8-array.js");
30
+ require("core-js/modules/es.typed-array.copy-within.js");
31
+ require("core-js/modules/es.typed-array.every.js");
32
+ require("core-js/modules/es.typed-array.fill.js");
33
+ require("core-js/modules/es.typed-array.filter.js");
34
+ require("core-js/modules/es.typed-array.find.js");
35
+ require("core-js/modules/es.typed-array.find-index.js");
36
+ require("core-js/modules/es.typed-array.for-each.js");
37
+ require("core-js/modules/es.typed-array.includes.js");
38
+ require("core-js/modules/es.typed-array.index-of.js");
39
+ require("core-js/modules/es.typed-array.iterator.js");
40
+ require("core-js/modules/es.typed-array.join.js");
41
+ require("core-js/modules/es.typed-array.last-index-of.js");
42
+ require("core-js/modules/es.typed-array.map.js");
43
+ require("core-js/modules/es.typed-array.reduce.js");
44
+ require("core-js/modules/es.typed-array.reduce-right.js");
45
+ require("core-js/modules/es.typed-array.reverse.js");
46
+ require("core-js/modules/es.typed-array.set.js");
47
+ require("core-js/modules/es.typed-array.slice.js");
48
+ require("core-js/modules/es.typed-array.some.js");
49
+ require("core-js/modules/es.typed-array.sort.js");
50
+ require("core-js/modules/es.typed-array.subarray.js");
51
+ require("core-js/modules/es.typed-array.to-locale-string.js");
52
+ require("core-js/modules/es.typed-array.to-string.js");
53
+ require("core-js/modules/es.array.join.js");
54
+ require("core-js/modules/es.array.map.js");
55
+ require("core-js/modules/web.dom-collections.for-each.js");
56
+ require("core-js/modules/es.function.name.js");
57
+ require("core-js/modules/es.string.trim.js");
58
+ require("core-js/modules/es.array.includes.js");
59
+ require("core-js/modules/es.string.includes.js");
60
+ require("core-js/modules/es.array.splice.js");
61
+ require("core-js/modules/es.array.find.js");
62
+ require("core-js/modules/es.array.concat.js");
63
+ require("core-js/modules/es.number.to-fixed.js");
64
+ require("core-js/modules/es.regexp.exec.js");
65
+ require("core-js/modules/es.string.replace.js");
66
+ require("core-js/modules/es.string.starts-with.js");
67
+ require("core-js/modules/es.regexp.constructor.js");
68
+ require("core-js/modules/es.regexp.to-string.js");
69
+ require("core-js/modules/es.string.search.js");
70
+ require("core-js/modules/es.array.slice.js");
71
+ require("core-js/modules/es.promise.js");
72
+ require("core-js/modules/esnext.string.replace-all.js");
73
+ require("core-js/modules/es.array.find-index.js");
74
+ var _Field2 = _interopRequireDefault(require("../_classes/field/Field"));
75
+ var _utils = require("../../utils/utils");
76
+ var _downloadjs = _interopRequireDefault(require("downloadjs"));
77
+ var _lodash = _interopRequireDefault(require("lodash"));
78
+ var _nativePromiseOnly = _interopRequireDefault(require("native-promise-only"));
79
+ var _fileProcessor = _interopRequireDefault(require("../../providers/processor/fileProcessor"));
80
+ var _browserMd5File = _interopRequireDefault(require("browser-md5-file"));
81
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
82
+ 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; }
83
+ 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); } }
84
+ 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); }); }; }
85
+ 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; }
86
+ 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; }
87
+ 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; }
88
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
89
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
90
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
91
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
92
+ 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); }
93
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
94
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
95
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
96
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
97
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
98
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
99
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
100
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
101
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
102
+ var Camera;
103
+ var webViewCamera = navigator.camera || Camera;
104
+
105
+ // canvas.toBlob polyfill.
106
+
107
+ var htmlCanvasElement;
108
+ if (typeof window !== 'undefined') {
109
+ htmlCanvasElement = window.HTMLCanvasElement;
110
+ } else if (typeof global !== 'undefined') {
111
+ htmlCanvasElement = global.HTMLCanvasElement;
112
+ }
113
+ if (htmlCanvasElement && !htmlCanvasElement.prototype.toBlob) {
114
+ Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', {
115
+ value: function value(callback, type, quality) {
116
+ var canvas = this;
117
+ setTimeout(function () {
118
+ var binStr = atob(canvas.toDataURL(type, quality).split(',')[1]),
119
+ len = binStr.length,
120
+ arr = new Uint8Array(len);
121
+ for (var i = 0; i < len; i++) {
122
+ arr[i] = binStr.charCodeAt(i);
123
+ }
124
+ callback(new Blob([arr], {
125
+ type: type || 'image/png'
126
+ }));
127
+ });
128
+ }
129
+ });
130
+ }
131
+ var FileComponent = /*#__PURE__*/function (_Field) {
132
+ _inherits(FileComponent, _Field);
133
+ var _super = _createSuper(FileComponent);
134
+ function FileComponent() {
135
+ _classCallCheck(this, FileComponent);
136
+ return _super.apply(this, arguments);
137
+ }
138
+ _createClass(FileComponent, [{
139
+ key: "init",
140
+ value: function init() {
141
+ _get(_getPrototypeOf(FileComponent.prototype), "init", this).call(this);
142
+ webViewCamera = navigator.camera || Camera;
143
+ var fileReaderSupported = typeof FileReader !== 'undefined';
144
+ var formDataSupported = typeof window !== 'undefined' ? Boolean(window.FormData) : false;
145
+ var progressSupported = typeof window !== 'undefined' && window.XMLHttpRequest ? 'upload' in new XMLHttpRequest() : false;
146
+ this.support = {
147
+ filereader: fileReaderSupported,
148
+ formdata: formDataSupported,
149
+ hasWarning: !fileReaderSupported || !formDataSupported || !progressSupported,
150
+ progress: progressSupported
151
+ };
152
+ this.cameraMode = false;
153
+ this.statuses = [];
154
+ this.fileDropHidden = false;
155
+ }
156
+ }, {
157
+ key: "dataReady",
158
+ get: function get() {
159
+ return this.filesReady || _nativePromiseOnly.default.resolve();
160
+ }
161
+ }, {
162
+ key: "defaultSchema",
163
+ get: function get() {
164
+ return FileComponent.schema();
165
+ }
166
+ }, {
167
+ key: "loadImage",
168
+ value: function loadImage(fileInfo) {
169
+ if (this.component.privateDownload) {
170
+ fileInfo.private = true;
171
+ }
172
+ return this.fileService.downloadFile(fileInfo).then(function (result) {
173
+ return result.url;
174
+ });
175
+ }
176
+ }, {
177
+ key: "emptyValue",
178
+ get: function get() {
179
+ return [];
180
+ }
181
+ }, {
182
+ key: "getValueAsString",
183
+ value: function getValueAsString(value) {
184
+ if (_lodash.default.isArray(value)) {
185
+ return _lodash.default.map(value, 'fileName').join(', ');
186
+ }
187
+ return _lodash.default.get(value, 'fileName', '');
188
+ }
189
+ }, {
190
+ key: "getValue",
191
+ value: function getValue() {
192
+ return this.dataValue;
193
+ }
194
+ }, {
195
+ key: "defaultValue",
196
+ get: function get() {
197
+ var value = _get(_getPrototypeOf(FileComponent.prototype), "defaultValue", this);
198
+ return Array.isArray(value) ? value : [];
199
+ }
200
+ }, {
201
+ key: "hasTypes",
202
+ get: function get() {
203
+ return this.component.fileTypes && Array.isArray(this.component.fileTypes) && this.component.fileTypes.length !== 0 && (this.component.fileTypes[0].label !== '' || this.component.fileTypes[0].value !== '');
204
+ }
205
+ }, {
206
+ key: "fileDropHidden",
207
+ get: function get() {
208
+ return this._fileBrowseHidden;
209
+ },
210
+ set: function set(value) {
211
+ if (typeof value !== 'boolean' || this.component.multiple) {
212
+ return;
213
+ }
214
+ this._fileBrowseHidden = value;
215
+ }
216
+ }, {
217
+ key: "render",
218
+ value: function render() {
219
+ return _get(_getPrototypeOf(FileComponent.prototype), "render", this).call(this, this.renderTemplate('fileUDS', {
220
+ fileSize: this.fileSize,
221
+ files: this.dataValue || [],
222
+ statuses: this.statuses,
223
+ disabled: this.disabled,
224
+ support: this.support,
225
+ fileDropHidden: this.fileDropHidden
226
+ }));
227
+ }
228
+ }, {
229
+ key: "getVideoStream",
230
+ value: function getVideoStream(constraints) {
231
+ return navigator.mediaDevices.getUserMedia({
232
+ video: _objectSpread({
233
+ width: {
234
+ min: 640,
235
+ ideal: 1920
236
+ },
237
+ height: {
238
+ min: 360,
239
+ ideal: 1080
240
+ },
241
+ aspectRatio: {
242
+ ideal: 16 / 9
243
+ }
244
+ }, constraints),
245
+ audio: false
246
+ });
247
+ }
248
+ }, {
249
+ key: "stopVideoStream",
250
+ value: function stopVideoStream(videoStream) {
251
+ videoStream.getVideoTracks().forEach(function (track) {
252
+ return track.stop();
253
+ });
254
+ }
255
+ }, {
256
+ key: "getFrame",
257
+ value: function getFrame(videoPlayer) {
258
+ return new _nativePromiseOnly.default(function (resolve) {
259
+ var canvas = document.createElement('canvas');
260
+ canvas.height = videoPlayer.videoHeight;
261
+ canvas.width = videoPlayer.videoWidth;
262
+ var context = canvas.getContext('2d');
263
+ context.drawImage(videoPlayer, 0, 0);
264
+ canvas.toBlob(resolve);
265
+ });
266
+ }
267
+ }, {
268
+ key: "startVideo",
269
+ value: function startVideo() {
270
+ var _this = this;
271
+ this.getVideoStream().then(function (stream) {
272
+ _this.videoStream = stream;
273
+ var videoPlayer = _this.refs.videoPlayer;
274
+ if (!videoPlayer) {
275
+ console.warn('Video player not found in template.');
276
+ _this.cameraMode = false;
277
+ _this.redraw();
278
+ return;
279
+ }
280
+ videoPlayer.srcObject = stream;
281
+ var width = parseInt(_this.component.webcamSize) || 320;
282
+ videoPlayer.setAttribute('width', width);
283
+ videoPlayer.play();
284
+ }).catch(function (err) {
285
+ console.error(err);
286
+ _this.cameraMode = false;
287
+ _this.redraw();
288
+ });
289
+ }
290
+ }, {
291
+ key: "stopVideo",
292
+ value: function stopVideo() {
293
+ if (this.videoStream) {
294
+ this.stopVideoStream(this.videoStream);
295
+ this.videoStream = null;
296
+ }
297
+ }
298
+ }, {
299
+ key: "takePicture",
300
+ value: function takePicture() {
301
+ var _this2 = this;
302
+ var videoPlayer = this.refs.videoPlayer;
303
+ if (!videoPlayer) {
304
+ console.warn('Video player not found in template.');
305
+ this.cameraMode = false;
306
+ this.redraw();
307
+ return;
308
+ }
309
+ this.getFrame(videoPlayer).then(function (frame) {
310
+ frame.name = "photo-".concat(Date.now(), ".png");
311
+ _this2.upload([frame]);
312
+ _this2.cameraMode = false;
313
+ _this2.redraw();
314
+ });
315
+ }
316
+ }, {
317
+ key: "browseFiles",
318
+ value: function browseFiles() {
319
+ var _this3 = this;
320
+ var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
321
+ return new _nativePromiseOnly.default(function (resolve) {
322
+ var fileInput = _this3.ce('input', _objectSpread({
323
+ type: 'file',
324
+ style: 'height: 0; width: 0; visibility: hidden;',
325
+ tabindex: '-1'
326
+ }, attrs));
327
+ document.body.appendChild(fileInput);
328
+ fileInput.addEventListener('change', function () {
329
+ resolve(fileInput.files);
330
+ document.body.removeChild(fileInput);
331
+ }, true);
332
+
333
+ // There is no direct way to trigger a file dialog. To work around this, create an input of type file and trigger
334
+ // a click event on it.
335
+ if (typeof fileInput.trigger === 'function') {
336
+ fileInput.trigger('click');
337
+ } else {
338
+ fileInput.click();
339
+ }
340
+ });
341
+ }
342
+ }, {
343
+ key: "cameraMode",
344
+ get: function get() {
345
+ return this._cameraMode;
346
+ },
347
+ set: function set(value) {
348
+ this._cameraMode = value;
349
+ if (value) {
350
+ this.startVideo();
351
+ } else {
352
+ this.stopVideo();
353
+ }
354
+ }
355
+ }, {
356
+ key: "useWebViewCamera",
357
+ get: function get() {
358
+ return this.imageUpload && webViewCamera;
359
+ }
360
+ }, {
361
+ key: "imageUpload",
362
+ get: function get() {
363
+ return Boolean(this.component.image);
364
+ }
365
+ }, {
366
+ key: "browseOptions",
367
+ get: function get() {
368
+ var options = {};
369
+ if (this.component.multiple) {
370
+ options.multiple = true;
371
+ }
372
+ //use "accept" attribute only for desktop devices because of its limited support by mobile browsers
373
+ if (!this.isMobile.any) {
374
+ var filePattern = this.component.filePattern.trim() || '';
375
+ var imagesPattern = 'image/*';
376
+ if (this.imageUpload && (!filePattern || filePattern === '*')) {
377
+ options.accept = imagesPattern;
378
+ } else if (this.imageUpload && !filePattern.includes(imagesPattern)) {
379
+ options.accept = "".concat(imagesPattern, ",").concat(filePattern);
380
+ } else {
381
+ options.accept = filePattern;
382
+ }
383
+ }
384
+ return options;
385
+ }
386
+ }, {
387
+ key: "deleteFile",
388
+ value: function deleteFile(fileInfo) {
389
+ var _this$component$optio = this.component.options,
390
+ options = _this$component$optio === void 0 ? {} : _this$component$optio;
391
+ if (fileInfo && ['url', 'indexeddb'].includes(this.component.storage)) {
392
+ var fileService = this.fileService;
393
+ if (fileService && typeof fileService.deleteFile === 'function') {
394
+ fileService.deleteFile(fileInfo, options);
395
+ } else {
396
+ var formio = this.options.formio || this.root && this.root.formio;
397
+ if (formio) {
398
+ formio.makeRequest('', fileInfo.url, 'delete');
399
+ }
400
+ }
401
+ }
402
+ }
403
+ }, {
404
+ key: "readCookie",
405
+ value: function readCookie() {
406
+ var cookies = document.cookie.split('; ');
407
+ var cookieData = {};
408
+ for (var i = 0; i < cookies.length; i++) {
409
+ if (cookies[i]) {
410
+ var parts = cookies[i].split('=');
411
+ var name = decodeURIComponent(parts[0]);
412
+ var value = decodeURIComponent(parts[1]);
413
+ cookieData[name] = value;
414
+ }
415
+ }
416
+ return cookieData;
417
+ }
418
+ }, {
419
+ key: "attach",
420
+ value: function attach(element) {
421
+ var _this4 = this;
422
+ this.loadRefs(element, {
423
+ fileDrop: 'single',
424
+ fileBrowse: 'single',
425
+ galleryButton: 'single',
426
+ cameraButton: 'single',
427
+ takePictureButton: 'single',
428
+ toggleCameraMode: 'single',
429
+ videoPlayer: 'single',
430
+ fileLink: 'multiple',
431
+ removeLink: 'multiple',
432
+ fileStatusRemove: 'multiple',
433
+ fileImage: 'multiple',
434
+ fileType: 'multiple',
435
+ fileProcessingLoader: 'single'
436
+ });
437
+ // Ensure we have an empty input refs. We need this for the setValue method to redraw the control when it is set.
438
+ this.refs.input = [];
439
+ var superAttach = _get(_getPrototypeOf(FileComponent.prototype), "attach", this).call(this, element);
440
+ if (this.refs.fileDrop) {
441
+ if (!this.statuses.length) {
442
+ this.refs.fileDrop.removeAttribute('hidden');
443
+ }
444
+ var _element = this;
445
+ this.addEventListener(this.refs.fileDrop, 'dragover', function (event) {
446
+ this.className = 'fileSelector fileDragOver';
447
+ event.preventDefault();
448
+ });
449
+ this.addEventListener(this.refs.fileDrop, 'dragleave', function (event) {
450
+ this.className = 'fileSelector';
451
+ event.preventDefault();
452
+ });
453
+ this.addEventListener(this.refs.fileDrop, 'drop', function (event) {
454
+ this.className = 'fileSelector';
455
+ event.preventDefault();
456
+ _element.upload(event.dataTransfer.files);
457
+ });
458
+ }
459
+ if (this.refs.fileBrowse) {
460
+ this.addEventListener(this.refs.fileBrowse, 'click', function (event) {
461
+ event.preventDefault();
462
+ _this4.browseFiles(_this4.browseOptions).then(function (files) {
463
+ _this4.upload(files);
464
+ });
465
+ });
466
+ }
467
+ this.refs.fileLink.forEach(function (fileLink, index) {
468
+ _this4.addEventListener(fileLink, 'click', function (event) {
469
+ event.preventDefault();
470
+ // this.getFile(this.dataValue[index]);
471
+ });
472
+ });
473
+
474
+ this.refs.removeLink.forEach(function (removeLink, index) {
475
+ _this4.addEventListener(removeLink, 'click', function (event) {
476
+ var fileInfo = _this4.dataValue[index];
477
+ _this4.deleteFile(fileInfo);
478
+ event.preventDefault();
479
+ _this4.splice(index);
480
+ _this4.redraw();
481
+ });
482
+ });
483
+ this.refs.fileStatusRemove.forEach(function (fileStatusRemove, index) {
484
+ _this4.addEventListener(fileStatusRemove, 'click', function (event) {
485
+ event.preventDefault();
486
+ if (_this4.abortUpload) {
487
+ _this4.abortUpload();
488
+ }
489
+ _this4.statuses.splice(index, 1);
490
+ _this4.redraw();
491
+ });
492
+ });
493
+ if (this.refs.galleryButton && webViewCamera) {
494
+ this.addEventListener(this.refs.galleryButton, 'click', function (event) {
495
+ event.preventDefault();
496
+ webViewCamera.getPicture(function (success) {
497
+ window.resolveLocalFileSystemURL(success, function (fileEntry) {
498
+ fileEntry.file(function (file) {
499
+ var reader = new FileReader();
500
+ reader.onloadend = function (evt) {
501
+ var blob = new Blob([new Uint8Array(evt.target.result)], {
502
+ type: file.type
503
+ });
504
+ blob.name = file.name;
505
+ _this4.upload([blob]);
506
+ };
507
+ reader.readAsArrayBuffer(file);
508
+ });
509
+ });
510
+ }, function (err) {
511
+ console.error(err);
512
+ }, {
513
+ sourceType: webViewCamera.PictureSourceType.PHOTOLIBRARY
514
+ });
515
+ });
516
+ }
517
+ if (this.refs.cameraButton && webViewCamera) {
518
+ this.addEventListener(this.refs.cameraButton, 'click', function (event) {
519
+ event.preventDefault();
520
+ webViewCamera.getPicture(function (success) {
521
+ window.resolveLocalFileSystemURL(success, function (fileEntry) {
522
+ fileEntry.file(function (file) {
523
+ var reader = new FileReader();
524
+ reader.onloadend = function (evt) {
525
+ var blob = new Blob([new Uint8Array(evt.target.result)], {
526
+ type: file.type
527
+ });
528
+ blob.name = file.name;
529
+ _this4.upload([blob]);
530
+ };
531
+ reader.readAsArrayBuffer(file);
532
+ });
533
+ });
534
+ }, function (err) {
535
+ console.error(err);
536
+ }, {
537
+ sourceType: webViewCamera.PictureSourceType.CAMERA,
538
+ encodingType: webViewCamera.EncodingType.PNG,
539
+ mediaType: webViewCamera.MediaType.PICTURE,
540
+ saveToPhotoAlbum: true,
541
+ correctOrientation: false
542
+ });
543
+ });
544
+ }
545
+ if (this.refs.takePictureButton) {
546
+ this.addEventListener(this.refs.takePictureButton, 'click', function (event) {
547
+ event.preventDefault();
548
+ _this4.takePicture();
549
+ });
550
+ }
551
+ if (this.refs.toggleCameraMode) {
552
+ this.addEventListener(this.refs.toggleCameraMode, 'click', function (event) {
553
+ event.preventDefault();
554
+ _this4.cameraMode = !_this4.cameraMode;
555
+ _this4.redraw();
556
+ });
557
+ }
558
+ this.refs.fileType.forEach(function (fileType, index) {
559
+ _this4.dataValue[index].fileType = _this4.dataValue[index].fileType || _this4.component.fileTypes[0].label;
560
+ _this4.addEventListener(fileType, 'change', function (event) {
561
+ event.preventDefault();
562
+ var fileType = _this4.component.fileTypes.find(function (typeObj) {
563
+ return typeObj.value === event.target.value;
564
+ });
565
+ _this4.dataValue[index].fileType = fileType.label;
566
+ });
567
+ });
568
+ var fileService = this.fileService;
569
+ if (fileService) {
570
+ var loadingImages = [];
571
+ this.filesReady = new _nativePromiseOnly.default(function (resolve, reject) {
572
+ _this4.filesReadyResolve = resolve;
573
+ _this4.filesReadyReject = reject;
574
+ });
575
+ this.refs.fileImage.forEach(function (image, index) {
576
+ loadingImages.push(_this4.loadImage(_this4.dataValue[index]).then(function (url) {
577
+ return image.src = url;
578
+ }));
579
+ });
580
+ if (loadingImages.length) {
581
+ _nativePromiseOnly.default.all(loadingImages).then(function () {
582
+ _this4.filesReadyResolve();
583
+ }).catch(function () {
584
+ return _this4.filesReadyReject();
585
+ });
586
+ } else {
587
+ this.filesReadyResolve();
588
+ }
589
+ }
590
+ return superAttach;
591
+ }
592
+
593
+ /* eslint-disable max-len */
594
+ }, {
595
+ key: "fileSize",
596
+ value: function fileSize(a, b, c, d, e) {
597
+ if (!a && !b && !c && !d && !e) {
598
+ return '--';
599
+ }
600
+ return "".concat((b = Math, c = b.log, d = 1024, e = c(a) / c(d) | 0, a / b.pow(d, e)).toFixed(2), " ").concat(e ? "".concat('kMGTPEZY'[--e], "B") : 'Bytes');
601
+ }
602
+
603
+ /* eslint-enable max-len */
604
+
605
+ /* eslint-disable max-depth */
606
+ }, {
607
+ key: "globStringToRegex",
608
+ value: function globStringToRegex(str) {
609
+ str = str.replace(/\s/g, '');
610
+ var regexp = '',
611
+ excludes = [];
612
+ if (str.length > 2 && str[0] === '/' && str[str.length - 1] === '/') {
613
+ regexp = str.substring(1, str.length - 1);
614
+ } else {
615
+ var split = str.split(',');
616
+ if (split.length > 1) {
617
+ for (var i = 0; i < split.length; i++) {
618
+ var r = this.globStringToRegex(split[i]);
619
+ if (r.regexp) {
620
+ regexp += "(".concat(r.regexp, ")");
621
+ if (i < split.length - 1) {
622
+ regexp += '|';
623
+ }
624
+ } else {
625
+ excludes = excludes.concat(r.excludes);
626
+ }
627
+ }
628
+ } else {
629
+ if (str.startsWith('!')) {
630
+ excludes.push("^((?!".concat(this.globStringToRegex(str.substring(1)).regexp, ").)*$"));
631
+ } else {
632
+ if (str.startsWith('.')) {
633
+ str = "*".concat(str);
634
+ }
635
+ regexp = "^".concat(str.replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\-]', 'g'), '\\$&'), "$");
636
+ regexp = regexp.replace(/\\\*/g, '.*').replace(/\\\?/g, '.');
637
+ }
638
+ }
639
+ }
640
+ return {
641
+ regexp: regexp,
642
+ excludes: excludes
643
+ };
644
+ }
645
+
646
+ /* eslint-enable max-depth */
647
+ }, {
648
+ key: "translateScalars",
649
+ value: function translateScalars(str) {
650
+ if (typeof str === 'string') {
651
+ if (str.search(/kb/i) === str.length - 2) {
652
+ return parseFloat(str.substring(0, str.length - 2) * 1024);
653
+ }
654
+ if (str.search(/mb/i) === str.length - 2) {
655
+ return parseFloat(str.substring(0, str.length - 2) * 1024 * 1024);
656
+ }
657
+ if (str.search(/gb/i) === str.length - 2) {
658
+ return parseFloat(str.substring(0, str.length - 2) * 1024 * 1024 * 1024);
659
+ }
660
+ if (str.search(/b/i) === str.length - 1) {
661
+ return parseFloat(str.substring(0, str.length - 1));
662
+ }
663
+ if (str.search(/s/i) === str.length - 1) {
664
+ return parseFloat(str.substring(0, str.length - 1));
665
+ }
666
+ if (str.search(/m/i) === str.length - 1) {
667
+ return parseFloat(str.substring(0, str.length - 1) * 60);
668
+ }
669
+ if (str.search(/h/i) === str.length - 1) {
670
+ return parseFloat(str.substring(0, str.length - 1) * 3600);
671
+ }
672
+ }
673
+ return str;
674
+ }
675
+ }, {
676
+ key: "validatePattern",
677
+ value: function validatePattern(file, val) {
678
+ if (!val) {
679
+ return true;
680
+ }
681
+ var pattern = this.globStringToRegex(val);
682
+ var valid = true;
683
+ if (pattern.regexp && pattern.regexp.length) {
684
+ var regexp = new RegExp(pattern.regexp, 'i');
685
+ valid = !_lodash.default.isNil(file.type) && regexp.test(file.type) || !_lodash.default.isNil(file.name) && regexp.test(file.name);
686
+ }
687
+ valid = pattern.excludes.reduce(function (result, excludePattern) {
688
+ var exclude = new RegExp(excludePattern, 'i');
689
+ return result && (_lodash.default.isNil(file.type) || !exclude.test(file.type)) && (_lodash.default.isNil(file.name) || !exclude.test(file.name));
690
+ }, valid);
691
+ return valid;
692
+ }
693
+ }, {
694
+ key: "validateMinSize",
695
+ value: function validateMinSize(file, val) {
696
+ return file.size + 0.1 >= this.translateScalars(val);
697
+ }
698
+ }, {
699
+ key: "validateMaxSize",
700
+ value: function validateMaxSize(file, val) {
701
+ return file.size - 0.1 <= this.translateScalars(val);
702
+ }
703
+ }, {
704
+ key: "parseTpl",
705
+ value: function parseTpl(template, map) {
706
+ return template.replace(/\$\{.+?}/g, function (match) {
707
+ var _$get;
708
+ var path = match.substr(2, match.length - 3).trim();
709
+ return (_$get = _lodash.default.get(map, path)) !== null && _$get !== void 0 ? _$get : '--';
710
+ });
711
+ }
712
+ }, {
713
+ key: "upload",
714
+ value: function upload(files) {
715
+ var _this5 = this;
716
+ // Only allow one upload if not multiple.
717
+ if (!this.component.multiple) {
718
+ if (this.statuses.length) {
719
+ this.statuses = [];
720
+ }
721
+ files = Array.prototype.slice.call(files, 0, 1);
722
+ }
723
+ if (this.component.storage && files && files.length) {
724
+ this.fileDropHidden = true;
725
+
726
+ // files is not really an array and does not have a forEach method, so fake it.
727
+ /* eslint-disable max-statements */
728
+ Array.prototype.forEach.call(files, /*#__PURE__*/function () {
729
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(file) {
730
+ var bmf, hash, fileName, escapedFileName, fileUpload, fileWithSameNameUploaded, fileWithSameNameUploadedWithError, dir, fileService, storage, _this5$component$opti, options, cookies, token, url, groupKey, groupPermissions, fileKey, groupResourceId, processedFile, fileProcessorHandler, filePromise;
731
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
732
+ while (1) switch (_context.prev = _context.next) {
733
+ case 0:
734
+ bmf = new _browserMd5File.default();
735
+ _context.next = 3;
736
+ return new Promise(function (resolve, reject) {
737
+ bmf.md5(file, function (err, md5) {
738
+ if (err) {
739
+ return reject(err);
740
+ }
741
+ return resolve(md5);
742
+ });
743
+ });
744
+ case 3:
745
+ hash = _context.sent;
746
+ fileName = (0, _utils.uniqueName)(file.name, _this5.component.fileNameTemplate, _this5.evalContext());
747
+ escapedFileName = file.name ? file.name.replaceAll('<', '&lt;').replaceAll('>', '&gt;') : file.name;
748
+ fileUpload = {
749
+ fileName: escapedFileName,
750
+ name: fileName,
751
+ size: file.size,
752
+ status: 'info',
753
+ message: _this5.t('Processing file. Please wait...'),
754
+ hash: hash
755
+ }; // Check if file with the same name is being uploaded
756
+ fileWithSameNameUploaded = _this5.dataValue.some(function (fileStatus) {
757
+ return fileStatus.fileName === file.name;
758
+ });
759
+ fileWithSameNameUploadedWithError = _this5.statuses.findIndex(function (fileStatus) {
760
+ return fileStatus.fileName === file.name && fileStatus.status === 'error';
761
+ });
762
+ if (fileWithSameNameUploaded) {
763
+ fileUpload.status = 'error';
764
+ fileUpload.message = _this5.t('File with the same name is already uploaded');
765
+ }
766
+ if (fileWithSameNameUploadedWithError !== -1) {
767
+ _this5.statuses.splice(fileWithSameNameUploadedWithError, 1);
768
+ _this5.redraw();
769
+ }
770
+
771
+ // Check file pattern
772
+ if (_this5.component.filePattern && !_this5.validatePattern(file, _this5.component.filePattern)) {
773
+ fileUpload.status = 'error';
774
+ fileUpload.message = _this5.t('File is the wrong type; it must be {{ pattern }}', {
775
+ pattern: _this5.component.filePattern
776
+ });
777
+ }
778
+
779
+ // Check file minimum size
780
+ if (_this5.component.fileMinSize && !_this5.validateMinSize(file, _this5.component.fileMinSize)) {
781
+ fileUpload.status = 'error';
782
+ fileUpload.message = _this5.t('File is too small; it must be at least {{ size }}', {
783
+ size: _this5.component.fileMinSize
784
+ });
785
+ }
786
+
787
+ // Check file maximum size
788
+ if (_this5.component.fileMaxSize && !_this5.validateMaxSize(file, _this5.component.fileMaxSize)) {
789
+ fileUpload.status = 'error';
790
+ fileUpload.message = _this5.t('File is too big; it must be at most {{ size }}', {
791
+ size: _this5.component.fileMaxSize
792
+ });
793
+ }
794
+
795
+ // Get a unique name for this file to keep file collisions from occurring.
796
+ dir = _this5.interpolate(_this5.component.dir || '');
797
+ fileService = _this5.fileService;
798
+ if (!fileService) {
799
+ fileUpload.status = 'error';
800
+ fileUpload.message = _this5.t('File Service not provided.');
801
+ }
802
+ _this5.statuses.push(fileUpload);
803
+ _this5.redraw();
804
+ if (!(fileUpload.status !== 'error')) {
805
+ _context.next = 57;
806
+ break;
807
+ }
808
+ if (_this5.component.privateDownload) {
809
+ file.private = true;
810
+ }
811
+ storage = _this5.component.storage;
812
+ _this5$component$opti = _this5.component.options, options = _this5$component$opti === void 0 ? {} : _this5$component$opti;
813
+ try {
814
+ options = JSON.parse(_this5.parseTpl(options, {
815
+ data: _this5.rootValue
816
+ }));
817
+ } catch (e) {
818
+ console.log(e);
819
+ options = {};
820
+ }
821
+ // 设置headers
822
+ cookies = _this5.readCookie();
823
+ token = cookies['eorion_basicToken'];
824
+ if (!token || token.length === 0 || token === 'undefined' || token === 'null') {
825
+ token = localStorage.getItem('eorion_poc-token');
826
+ }
827
+ if (options.headers) {
828
+ if (!options.headers.authorization && !options.headers.Authorization) {
829
+ options.headers.authorization = token;
830
+ }
831
+ } else {
832
+ options.headers = {
833
+ authorization: token
834
+ };
835
+ }
836
+ url = _this5.interpolate(_this5.component.url, {
837
+ file: fileUpload
838
+ });
839
+ groupKey = null;
840
+ groupPermissions = null; //Iterate through form components to find group resource if one exists
841
+ _this5.root.everyComponent(function (element) {
842
+ var _element$component, _element$component2;
843
+ if ((_element$component = element.component) !== null && _element$component !== void 0 && _element$component.submissionAccess || (_element$component2 = element.component) !== null && _element$component2 !== void 0 && _element$component2.defaultPermission) {
844
+ groupPermissions = !element.component.submissionAccess ? [{
845
+ type: element.component.defaultPermission,
846
+ roles: []
847
+ }] : element.component.submissionAccess;
848
+ groupPermissions.forEach(function (permission) {
849
+ groupKey = ['admin', 'write', 'create'].includes(permission.type) ? element.component.key : null;
850
+ });
851
+ }
852
+ });
853
+ fileKey = _this5.component.fileKey || 'file';
854
+ groupResourceId = groupKey ? _this5.currentForm.submission.data[groupKey]._id : null;
855
+ processedFile = null;
856
+ if (!_this5.root.options.fileProcessor) {
857
+ _context.next = 54;
858
+ break;
859
+ }
860
+ _context.prev = 36;
861
+ if (_this5.refs.fileProcessingLoader) {
862
+ _this5.refs.fileProcessingLoader.style.display = 'block';
863
+ }
864
+ fileProcessorHandler = (0, _fileProcessor.default)(_this5.fileService, _this5.root.options.fileProcessor);
865
+ _context.next = 41;
866
+ return fileProcessorHandler(file, _this5.component.properties);
867
+ case 41:
868
+ processedFile = _context.sent;
869
+ _context.next = 51;
870
+ break;
871
+ case 44:
872
+ _context.prev = 44;
873
+ _context.t0 = _context["catch"](36);
874
+ fileUpload.status = 'error';
875
+ fileUpload.message = _this5.t('File processing has been failed.');
876
+ _this5.fileDropHidden = false;
877
+ _this5.redraw();
878
+ return _context.abrupt("return");
879
+ case 51:
880
+ _context.prev = 51;
881
+ if (_this5.refs.fileProcessingLoader) {
882
+ _this5.refs.fileProcessingLoader.style.display = 'none';
883
+ }
884
+ return _context.finish(51);
885
+ case 54:
886
+ fileUpload.message = _this5.t('Starting upload.');
887
+ _this5.redraw();
888
+ filePromise = fileService.uploadFile(storage, processedFile || file, fileName, dir,
889
+ // Progress callback
890
+ function (evt) {
891
+ fileUpload.status = 'progress';
892
+ fileUpload.progress = parseInt(100.0 * evt.loaded / evt.total);
893
+ delete fileUpload.message;
894
+ _this5.redraw();
895
+ }, url, options, fileKey, groupPermissions, groupResourceId,
896
+ // Upload start callback
897
+ function () {
898
+ _this5.emit('fileUploadingStart', filePromise);
899
+ },
900
+ // Abort upload callback
901
+ function (abort) {
902
+ return _this5.abortUpload = abort;
903
+ }).then(function (fileInfo) {
904
+ var index = _this5.statuses.indexOf(fileUpload);
905
+ if (index !== -1) {
906
+ _this5.statuses.splice(index, 1);
907
+ }
908
+ fileInfo.fileName = escapedFileName;
909
+ fileInfo.hash = fileUpload.hash;
910
+ if (!_this5.hasValue()) {
911
+ _this5.dataValue = [];
912
+ }
913
+ _this5.dataValue.push({
914
+ documentId: fileInfo.data.documentId,
915
+ versionId: fileInfo.data.versionId,
916
+ fileName: fileInfo.data.fileName
917
+ });
918
+ _this5.fileDropHidden = false;
919
+ _this5.redraw();
920
+ _this5.triggerChange();
921
+ _this5.emit('fileUploadingEnd', filePromise);
922
+ }).catch(function (response) {
923
+ fileUpload.status = 'error';
924
+ fileUpload.message = typeof response === 'string' ? response : response.toString();
925
+ delete fileUpload.progress;
926
+ _this5.fileDropHidden = false;
927
+ _this5.redraw();
928
+ _this5.emit('fileUploadingEnd', filePromise);
929
+ });
930
+ case 57:
931
+ case "end":
932
+ return _context.stop();
933
+ }
934
+ }, _callee, null, [[36, 44, 51, 54]]);
935
+ }));
936
+ return function (_x) {
937
+ return _ref.apply(this, arguments);
938
+ };
939
+ }());
940
+ }
941
+ }
942
+ }, {
943
+ key: "getFile",
944
+ value: function getFile(fileInfo) {
945
+ var _this$component$optio2 = this.component.options,
946
+ options = _this$component$optio2 === void 0 ? {} : _this$component$optio2;
947
+ var fileService = this.fileService;
948
+ if (!fileService) {
949
+ return alert('File Service not provided');
950
+ }
951
+ if (this.component.privateDownload) {
952
+ fileInfo.private = true;
953
+ }
954
+ fileService.downloadFile(fileInfo, options).then(function (file) {
955
+ if (file) {
956
+ if (['base64', 'indexeddb'].includes(file.storage)) {
957
+ (0, _downloadjs.default)(file.url, file.fileName || file.name, file.type);
958
+ } else {
959
+ window.open(file.url, '_blank');
960
+ }
961
+ }
962
+ }).catch(function (response) {
963
+ // Is alert the best way to do this?
964
+ // User is expecting an immediate notification due to attempting to download a file.
965
+ alert(response);
966
+ });
967
+ }
968
+ }, {
969
+ key: "focus",
970
+ value: function focus() {
971
+ if ('beforeFocus' in this.parent) {
972
+ this.parent.beforeFocus(this);
973
+ }
974
+ if (this.refs.fileBrowse) {
975
+ this.refs.fileBrowse.focus();
976
+ }
977
+ }
978
+ }, {
979
+ key: "destroy",
980
+ value: function destroy() {
981
+ this.stopVideo();
982
+ _get(_getPrototypeOf(FileComponent.prototype), "destroy", this).call(this);
983
+ }
984
+ }], [{
985
+ key: "schema",
986
+ value: function schema() {
987
+ for (var _len = arguments.length, extend = new Array(_len), _key = 0; _key < _len; _key++) {
988
+ extend[_key] = arguments[_key];
989
+ }
990
+ return _Field2.default.schema.apply(_Field2.default, [{
991
+ type: 'fileUds',
992
+ label: '文件上传(UDS)',
993
+ key: 'fileUds',
994
+ image: false,
995
+ privateDownload: false,
996
+ imageSize: '200',
997
+ filePattern: '*',
998
+ fileMinSize: '0KB',
999
+ fileMaxSize: '1GB',
1000
+ uploadOnly: false
1001
+ }].concat(extend));
1002
+ }
1003
+ }, {
1004
+ key: "builderInfo",
1005
+ get: function get() {
1006
+ return {
1007
+ title: '文件上传(UDS)',
1008
+ group: 'advanced',
1009
+ icon: 'file',
1010
+ documentation: '/userguide/forms/premium-components#file',
1011
+ weight: 100,
1012
+ schema: FileComponent.schema()
1013
+ };
1014
+ }
1015
+ }]);
1016
+ return FileComponent;
1017
+ }(_Field2.default);
1018
+ exports.default = FileComponent;