UNPKG

formiojs

Version:

Common js library for client side interaction with <form.io>

109 lines (104 loc) • 1.81 MB
/******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = "./lib/contrib/index.js"); /******/ }) /************************************************************************/ /******/ ({ /***/ "./lib/Component.js": /*!**************************!*\ !*** ./lib/Component.js ***! \**************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.default = void 0;\n\n__webpack_require__(/*! core-js/modules/es6.function.name */ \"./node_modules/core-js/modules/es6.function.name.js\");\n\n__webpack_require__(/*! core-js/modules/es6.object.assign */ \"./node_modules/core-js/modules/es6.object.assign.js\");\n\n__webpack_require__(/*! core-js/modules/es6.regexp.replace */ \"./node_modules/core-js/modules/es6.regexp.replace.js\");\n\n__webpack_require__(/*! core-js/modules/es6.regexp.constructor */ \"./node_modules/core-js/modules/es6.regexp.constructor.js\");\n\n__webpack_require__(/*! core-js/modules/es6.regexp.to-string */ \"./node_modules/core-js/modules/es6.regexp.to-string.js\");\n\n__webpack_require__(/*! core-js/modules/web.dom.iterable */ \"./node_modules/core-js/modules/web.dom.iterable.js\");\n\nvar _eventemitter = _interopRequireDefault(__webpack_require__(/*! eventemitter2 */ \"./node_modules/eventemitter2/lib/eventemitter2.js\"));\n\nvar FormioUtils = _interopRequireWildcard(__webpack_require__(/*! ./utils/utils */ \"./lib/utils/utils.js\"));\n\nvar _i18next = _interopRequireDefault(__webpack_require__(/*! i18next */ \"./node_modules/i18next/dist/es/index.js\"));\n\nvar _lodash = _interopRequireDefault(__webpack_require__(/*! lodash */ \"./node_modules/lodash/lodash.js\"));\n\nvar _moment = _interopRequireDefault(__webpack_require__(/*! moment */ \"./node_modules/moment/moment.js\"));\n\nvar _vanillaTextMask = _interopRequireDefault(__webpack_require__(/*! vanilla-text-mask */ \"./node_modules/vanilla-text-mask/dist/vanillaTextMask.js\"));\n\nfunction _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _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, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\n/**\n * Root component for all elements within the renderer.\n */\nvar Component =\n/*#__PURE__*/\nfunction () {\n function Component(options, id) {\n _classCallCheck(this, Component);\n\n /**\n * The options for this component.\n * @type {{}}\n */\n this.options = _lodash.default.assign({\n language: 'en',\n highlightErrors: true,\n row: '',\n namespace: 'formio'\n }, options || {});\n /**\n * The ID of this component. This value is auto-generated when the component is created, but\n * can also be provided from the component.id value passed into the constructor.\n * @type {string}\n */\n\n this.id = id || FormioUtils.getRandomComponentId();\n /**\n * An array of event handlers so that the destry command can deregister them.\n * @type {Array}\n */\n\n this.eventHandlers = []; // Use the i18next that is passed in, otherwise use the global version.\n\n this.i18next = this.options.i18next || _i18next.default;\n /**\n * An instance of the EventEmitter class to handle the emitting and registration of events.\n *\n * @type {EventEmitter}\n */\n\n this.events = options && options.events ? options.events : new _eventemitter.default({\n wildcard: false,\n maxListeners: 0\n });\n /**\n * All of the input masks associated with this component.\n * @type {Array}\n */\n\n this.inputMasks = [];\n }\n /**\n * Register for a new event within this component.\n *\n * @example\n * let component = new BaseComponent({\n * type: 'textfield',\n * label: 'First Name',\n * key: 'firstName'\n * });\n * component.on('componentChange', (changed) => {\n * console.log('this element is changed.');\n * });\n *\n *\n * @param {string} event - The event you wish to register the handler for.\n * @param {function} cb - The callback handler to handle this event.\n * @param {boolean} internal - If this event is an \"internal\" event and should get removed when destroyed.\n * This parameter is necessary because any external \"on\" bindings should be persistent even through internal\n * redraw events which will call the \"destroy\" methods.\n */\n\n\n _createClass(Component, [{\n key: \"on\",\n value: function on(event, cb, internal) {\n if (!this.events) {\n return;\n }\n\n var type = \"\".concat(this.options.namespace, \".\").concat(event); // Store the component id in the handler so that we can determine which events are for this component.\n\n cb.id = this.id;\n cb.internal = internal; // Register for this event.\n\n return this.events.on(type, cb);\n }\n /**\n * Removes all listeners for a certain event.\n *\n * @param event\n */\n\n }, {\n key: \"off\",\n value: function off(event) {\n var _this = this;\n\n if (!this.events) {\n return;\n }\n\n var type = \"\".concat(this.options.namespace, \".\").concat(event); // Iterate through all the internal events.\n\n _lodash.default.each(this.events.listeners(type), function (listener) {\n // Ensure this event is for this component.\n if (listener && listener.id === _this.id) {\n // Turn off this event handler.\n _this.events.off(type, listener);\n }\n });\n }\n /**\n * Emit a new event.\n *\n * @param {string} event - The event to emit.\n * @param {Object} data - The data to emit with the handler.\n */\n\n }, {\n key: \"emit\",\n value: function emit(event, data) {\n if (this.events) {\n this.events.emit(\"\".concat(this.options.namespace, \".\").concat(event), data);\n }\n }\n /**\n * Wrapper method to add an event listener to an HTML element.\n *\n * @param obj\n * The DOM element to add the event to.\n * @param type\n * The event name to add.\n * @param func\n * The callback function to be executed when the listener is triggered.\n * @param persistent\n * If this listener should persist beyond \"destroy\" commands.\n */\n\n }, {\n key: \"addEventListener\",\n value: function addEventListener(obj, type, func, persistent) {\n if (!persistent) {\n this.eventHandlers.push({\n id: this.id,\n obj: obj,\n type: type,\n func: func\n });\n }\n\n if ('addEventListener' in obj) {\n obj.addEventListener(type, func, false);\n } else if ('attachEvent' in obj) {\n obj.attachEvent(\"on\".concat(type), func);\n }\n }\n /**\n * Remove an event listener from the object.\n *\n * @param obj\n * @param type\n */\n\n }, {\n key: \"removeEventListener\",\n value: function removeEventListener(obj, type) {\n var _this2 = this;\n\n var indexes = [];\n\n _lodash.default.each(this.eventHandlers, function (handler, index) {\n if (handler.id === _this2.id && obj.removeEventListener && handler.type === type) {\n obj.removeEventListener(type, handler.func);\n indexes.push(index);\n }\n });\n\n if (indexes.length) {\n _lodash.default.pullAt(this.eventHandlers, indexes);\n }\n }\n /**\n * Removes all event listeners attached to this component.\n */\n\n }, {\n key: \"destroy\",\n value: function destroy() {\n var _this3 = this;\n\n _lodash.default.each(this.events._events, function (events, type) {\n _lodash.default.each(events, function (listener) {\n if (listener && _this3.id === listener.id && listener.internal) {\n _this3.events.off(type, listener);\n }\n });\n });\n\n _lodash.default.each(this.eventHandlers, function (handler) {\n if (_this3.id === handler.id && handler.type && handler.obj && handler.obj.removeEventListener) {\n handler.obj.removeEventListener(handler.type, handler.func);\n }\n }); // Destroy the input masks.\n\n\n this.inputMasks.forEach(function (mask) {\n return mask.destroy();\n });\n this.inputMasks = [];\n }\n /**\n * Append an HTML DOM element to a container.\n *\n * @param element\n * @param container\n */\n\n }, {\n key: \"appendTo\",\n value: function appendTo(element, container) {\n if (container) {\n container.appendChild(element);\n }\n }\n /**\n * Prepend an HTML DOM element to a container.\n *\n * @param {HTMLElement} element - The DOM element to prepend.\n * @param {HTMLElement} container - The DOM element that is the container of the element getting prepended.\n */\n\n }, {\n key: \"prependTo\",\n value: function prependTo(element, container) {\n if (container) {\n if (container.firstChild) {\n try {\n container.insertBefore(element, container.firstChild);\n } catch (err) {\n console.warn(err);\n container.appendChild(element);\n }\n } else {\n container.appendChild(element);\n }\n }\n }\n /**\n * Removes an HTML DOM element from its bounding container.\n *\n * @param {HTMLElement} element - The element to remove.\n * @param {HTMLElement} container - The DOM element that is the container of the element to remove.\n */\n\n }, {\n key: \"removeChildFrom\",\n value: function removeChildFrom(element, container) {\n if (container && container.contains(element)) {\n try {\n container.removeChild(element);\n } catch (err) {\n console.warn(err);\n }\n }\n }\n /**\n * Alias for document.createElement.\n *\n * @param {string} type - The type of element to create\n * @param {Object} attr - The element attributes to add to the created element.\n * @param {Various} children - Child elements. Can be a DOM Element, string or array of both.\n *\n * @return {HTMLElement} - The created element.\n */\n\n }, {\n key: \"ce\",\n value: function ce(type, attr) {\n var children = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;\n // Create the element.\n var element = document.createElement(type); // Add attributes.\n\n if (attr) {\n this.attr(element, attr);\n } // Append the children.\n\n\n this.appendChild(element, children);\n return element;\n }\n /**\n * Append different types of children.\n *\n * @param child\n */\n\n }, {\n key: \"appendChild\",\n value: function appendChild(element, child) {\n var _this4 = this;\n\n if (Array.isArray(child)) {\n child.forEach(function (oneChild) {\n _this4.appendChild(element, oneChild);\n });\n } else if (child instanceof HTMLElement || child instanceof Text) {\n element.appendChild(child);\n } else if (child) {\n element.appendChild(this.text(child.toString()));\n }\n }\n /**\n * Creates a new input mask placeholder.\n * @param {HTMLElement} mask - The input mask.\n * @returns {string} - The placeholder that will exist within the input as they type.\n */\n\n }, {\n key: \"maskPlaceholder\",\n value: function maskPlaceholder(mask) {\n return mask.map(function (char) {\n return char instanceof RegExp ? '_' : char;\n }).join('');\n }\n /**\n * Sets the input mask for an input.\n *\n * @param {HTMLElement} input - The html input to apply the mask to.\n * @param {String} inputMask - The input mask to add to this input.\n * @param {Boolean} placeholder - Set the mask placeholder on the input.\n */\n\n }, {\n key: \"setInputMask\",\n value: function setInputMask(input, inputMask, placeholder) {\n if (input && inputMask) {\n var mask = FormioUtils.getInputMask(inputMask);\n this._inputMask = mask;\n input.mask = (0, _vanillaTextMask.default)({\n inputElement: input,\n mask: mask\n });\n\n if (mask.numeric) {\n input.setAttribute('pattern', '\\\\d*');\n }\n\n if (placeholder) {\n input.setAttribute('placeholder', this.maskPlaceholder(mask));\n }\n\n this.inputMasks.push(input.mask);\n }\n }\n /**\n * Translate a text using the i18n system.\n *\n * @param {string} text - The i18n identifier.\n * @param {Object} params - The i18n parameters to use for translation.\n */\n\n }, {\n key: \"t\",\n value: function t(text, params) {\n params = params || {};\n params.nsSeparator = '::';\n params.keySeparator = '.|.';\n params.pluralSeparator = '._.';\n params.contextSeparator = '._.';\n var translated = this.i18next.t(text, params);\n return translated || text;\n }\n /**\n * Alias to create a text node.\n * @param text\n * @returns {Text}\n */\n\n }, {\n key: \"text\",\n value: function text(_text) {\n return document.createTextNode(this.t(_text));\n }\n /**\n * Adds an object of attributes onto an element.\n * @param {HtmlElement} element - The element to add the attributes to.\n * @param {Object} attr - The attributes to add to the input element.\n */\n\n }, {\n key: \"attr\",\n value: function attr(element, _attr) {\n var _this5 = this;\n\n if (!element) {\n return;\n }\n\n _lodash.default.each(_attr, function (value, key) {\n if (typeof value !== 'undefined') {\n if (key.indexOf('on') === 0) {\n // If this is an event, add a listener.\n _this5.addEventListener(element, key.substr(2).toLowerCase(), value);\n } else {\n // Otherwise it is just an attribute.\n element.setAttribute(key, value);\n }\n }\n });\n }\n /**\n * Determines if an element has a class.\n *\n * Taken from jQuery https://j11y.io/jquery/#v=1.5.0&fn=jQuery.fn.hasClass\n */\n\n }, {\n key: \"hasClass\",\n value: function hasClass(element, className) {\n if (!element) {\n return;\n }\n\n className = \" \".concat(className, \" \");\n return \" \".concat(element.className, \" \").replace(/[\\n\\t\\r]/g, ' ').indexOf(className) > -1;\n }\n /**\n * Adds a class to a DOM element.\n *\n * @param element\n * The element to add a class to.\n * @param className\n * The name of the class to add.\n */\n\n }, {\n key: \"addClass\",\n value: function addClass(element, className) {\n if (!element) {\n return;\n }\n\n var classes = element.getAttribute('class');\n\n if (!classes || classes.indexOf(className) === -1) {\n element.setAttribute('class', \"\".concat(classes, \" \").concat(className));\n }\n }\n /**\n * Remove a class from a DOM element.\n *\n * @param element\n * The DOM element to remove the class from.\n * @param className\n * The name of the class that is to be removed.\n */\n\n }, {\n key: \"removeClass\",\n value: function removeClass(element, className) {\n if (!element) {\n return;\n }\n\n var cls = element.getAttribute('class');\n\n if (cls) {\n cls = cls.replace(new RegExp(\" \".concat(className), 'g'), '');\n element.setAttribute('class', cls);\n }\n }\n /**\n * Empty's an HTML DOM element.\n *\n * @param {HTMLElement} element - The element you wish to empty.\n */\n\n }, {\n key: \"empty\",\n value: function empty(element) {\n if (element) {\n while (element.firstChild) {\n element.removeChild(element.firstChild);\n }\n }\n }\n /**\n * Gets the classname for either Fontawesome or Bootstrap depending on their settings.\n *\n * @param name\n * @param spinning\n * @return {string}\n */\n\n }, {\n key: \"iconClass\",\n value: function iconClass(name, spinning) {\n if (!this.options.icons || this.options.icons === 'glyphicon') {\n return spinning ? \"glyphicon glyphicon-\".concat(name, \" glyphicon-spin\") : \"glyphicon glyphicon-\".concat(name);\n }\n\n switch (name) {\n case 'save':\n return 'fa fa-download';\n\n case 'zoom-in':\n return 'fa fa-search-plus';\n\n case 'zoom-out':\n return 'fa fa-search-minus';\n\n case 'question-sign':\n return 'fa fa-question-circle';\n\n case 'remove-circle':\n return 'fa fa-times-circle-o';\n\n case 'new-window':\n return 'fa fa-window-restore';\n\n default:\n return spinning ? \"fa fa-\".concat(name, \" fa-spin\") : \"fa fa-\".concat(name);\n }\n }\n /**\n * Returns an HTMLElement icon element.\n *\n * @param {string} name - The name of the icon to retrieve.\n * @returns {HTMLElement} - The icon element.\n */\n\n }, {\n key: \"getIcon\",\n value: function getIcon(name) {\n return this.ce('i', {\n class: this.iconClass(name)\n });\n }\n /**\n * Create an evaluation context for all script executions and interpolations.\n *\n * @param additional\n * @return {*}\n */\n\n }, {\n key: \"evalContext\",\n value: function evalContext(additional) {\n return Object.assign({\n _: _lodash.default,\n utils: FormioUtils,\n util: FormioUtils,\n moment: _moment.default,\n instance: this\n }, additional);\n }\n /**\n * Performs an interpolation using the evaluation context of this component.\n *\n * @param string\n * @param data\n * @return {XML|string|*|void}\n */\n\n }, {\n key: \"interpolate\",\n value: function interpolate(string, data) {\n return FormioUtils.interpolate(string, this.evalContext(data));\n }\n /**\n * Performs an evaluation using the evaluation context of this component.\n *\n * @param func\n * @param args\n * @param ret\n * @param tokenize\n * @return {*}\n */\n\n }, {\n key: \"evaluate\",\n value: function evaluate(func, args, ret, tokenize) {\n return FormioUtils.evaluate(func, this.evalContext(args), ret, tokenize);\n }\n /**\n * Allow for options to hook into the functionality of this renderer.\n * @return {*}\n */\n\n }, {\n key: \"hook\",\n value: function hook() {\n var name = arguments[0];\n\n if (this.options && this.options.hooks && this.options.hooks[name]) {\n return this.options.hooks[name].apply(this, Array.prototype.slice.call(arguments, 1));\n } else {\n // If this is an async hook instead of a sync.\n var fn = typeof arguments[arguments.length - 1] === 'function' ? arguments[arguments.length - 1] : null;\n\n if (fn) {\n return fn(null, arguments[1]);\n } else {\n return arguments[1];\n }\n }\n }\n }]);\n\n return Component;\n}();\n\nexports.default = Component;\n\n//# sourceURL=webpack:///./lib/Component.js?"); /***/ }), /***/ "./lib/Formio.js": /*!***********************!*\ !*** ./lib/Formio.js ***! \***********************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; eval("/* WEBPACK VAR INJECTION */(function(global) {\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.default = void 0;\n\n__webpack_require__(/*! core-js/modules/es6.function.name */ \"./node_modules/core-js/modules/es6.function.name.js\");\n\n__webpack_require__(/*! core-js/modules/es7.symbol.async-iterator */ \"./node_modules/core-js/modules/es7.symbol.async-iterator.js\");\n\n__webpack_require__(/*! core-js/modules/es6.symbol */ \"./node_modules/core-js/modules/es6.symbol.js\");\n\n__webpack_require__(/*! core-js/modules/es6.number.constructor */ \"./node_modules/core-js/modules/es6.number.constructor.js\");\n\n__webpack_require__(/*! core-js/modules/web.dom.iterable */ \"./node_modules/core-js/modules/web.dom.iterable.js\");\n\n__webpack_require__(/*! core-js/modules/es6.array.iterator */ \"./node_modules/core-js/modules/es6.array.iterator.js\");\n\n__webpack_require__(/*! core-js/modules/es6.string.iterator */ \"./node_modules/core-js/modules/es6.string.iterator.js\");\n\n__webpack_require__(/*! core-js/modules/es6.object.assign */ \"./node_modules/core-js/modules/es6.object.assign.js\");\n\n__webpack_require__(/*! core-js/modules/es7.array.includes */ \"./node_modules/core-js/modules/es7.array.includes.js\");\n\n__webpack_require__(/*! core-js/modules/es6.string.includes */ \"./node_modules/core-js/modules/es6.string.includes.js\");\n\n__webpack_require__(/*! core-js/modules/es6.regexp.replace */ \"./node_modules/core-js/modules/es6.regexp.replace.js\");\n\n__webpack_require__(/*! core-js/modules/es6.regexp.constructor */ \"./node_modules/core-js/modules/es6.regexp.constructor.js\");\n\n__webpack_require__(/*! core-js/modules/es6.regexp.split */ \"./node_modules/core-js/modules/es6.regexp.split.js\");\n\n__webpack_require__(/*! core-js/modules/es6.regexp.search */ \"./node_modules/core-js/modules/es6.regexp.search.js\");\n\n__webpack_require__(/*! core-js/modules/es6.regexp.match */ \"./node_modules/core-js/modules/es6.regexp.match.js\");\n\nvar _nativePromiseOnly = _interopRequireDefault(__webpack_require__(/*! native-promise-only */ \"./node_modules/native-promise-only/lib/npo.src.js\"));\n\n__webpack_require__(/*! whatwg-fetch */ \"./node_modules/whatwg-fetch/fetch.js\");\n\nvar _eventemitter = __webpack_require__(/*! eventemitter2 */ \"./node_modules/eventemitter2/lib/eventemitter2.js\");\n\nvar _browserCookies = _interopRequireDefault(__webpack_require__(/*! browser-cookies */ \"./node_modules/browser-cookies/src/browser-cookies.js\"));\n\nvar _shallowCopy = _interopRequireDefault(__webpack_require__(/*! shallow-copy */ \"./node_modules/shallow-copy/index.js\"));\n\nvar providers = _interopRequireWildcard(__webpack_require__(/*! ./providers */ \"./lib/providers/index.js\"));\n\nvar _get2 = _interopRequireDefault(__webpack_require__(/*! lodash/get */ \"./node_modules/lodash/get.js\"));\n\nfunction _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _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, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _typeof(obj) { if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nvar isBoolean = function isBoolean(val) {\n return _typeof(val) === _typeof(true);\n};\n\nvar isNil = function isNil(val) {\n return val === null || val === undefined;\n};\n\nvar isObject = function isObject(val) {\n return val && _typeof(val) === 'object';\n};\n/**\n * The Formio interface class.\n *\n * let formio = new Formio('https://examples.form.io/example');\n */\n\n\nvar Formio =\n/*#__PURE__*/\nfunction () {\n /* eslint-disable max-statements */\n function Formio(path) {\n var _this = this;\n\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n\n _classCallCheck(this, Formio);\n\n // Ensure we have an instance of Formio.\n if (!(this instanceof Formio)) {\n return new Formio(path);\n } // Initialize our variables.\n\n\n this.base = '';\n this.projectsUrl = '';\n this.projectUrl = '';\n this.projectId = '';\n this.formUrl = '';\n this.formsUrl = '';\n this.formId = '';\n this.submissionsUrl = '';\n this.submissionUrl = '';\n this.submissionId = '';\n this.actionsUrl = '';\n this.actionId = '';\n this.actionUrl = '';\n this.vsUrl = '';\n this.vId = '';\n this.vUrl = '';\n this.query = ''; // Store the original path and options.\n\n this.path = path;\n this.options = options;\n\n if (options.hasOwnProperty('base')) {\n this.base = options.base;\n } else if (Formio.baseUrl) {\n this.base = Formio.baseUrl;\n } else {\n this.base = window.location.href.match(/http[s]?:\\/\\/api./)[0];\n }\n\n if (!path) {\n // Allow user to create new projects if this was instantiated without\n // a url\n this.projectUrl = \"\".concat(this.base, \"/project\");\n this.projectsUrl = \"\".concat(this.base, \"/project\");\n this.projectId = false;\n this.query = '';\n return;\n }\n\n if (options.hasOwnProperty('project')) {\n this.projectUrl = options.project;\n }\n\n var project = this.projectUrl || Formio.projectUrl;\n var projectRegEx = /(^|\\/)(project)($|\\/[^/]+)/;\n var isProjectUrl = path.search(projectRegEx) !== -1; // The baseURL is the same as the projectUrl, and does not contain \"/project/MONGO_ID\" in\n // its domain. This is almost certainly against the Open Source server.\n\n if (project && this.base === project && !isProjectUrl) {\n this.noProject = true;\n this.projectUrl = this.base;\n } // Normalize to an absolute path.\n\n\n if (path.indexOf('http') !== 0 && path.indexOf('//') !== 0) {\n path = this.base + path;\n }\n\n var hostparts = this.getUrlParts(path);\n var parts = [];\n var hostName = hostparts[1] + hostparts[2];\n path = hostparts.length > 3 ? hostparts[3] : '';\n var queryparts = path.split('?');\n\n if (queryparts.length > 1) {\n path = queryparts[0];\n this.query = \"?\".concat(queryparts[1]);\n } // Register a specific path.\n\n\n var registerPath = function registerPath(name, base) {\n _this[\"\".concat(name, \"sUrl\")] = \"\".concat(base, \"/\").concat(name);\n var regex = new RegExp(\"/\".concat(name, \"/([^/]+)\"));\n\n if (path.search(regex) !== -1) {\n parts = path.match(regex);\n _this[\"\".concat(name, \"Url\")] = parts ? base + parts[0] : '';\n _this[\"\".concat(name, \"Id\")] = parts.length > 1 ? parts[1] : '';\n base += parts[0];\n }\n\n return base;\n }; // Register an array of items.\n\n\n var registerItems = function registerItems(items, base, staticBase) {\n for (var i in items) {\n if (items.hasOwnProperty(i)) {\n var item = items[i];\n\n if (Array.isArray(item)) {\n registerItems(item, base, true);\n } else {\n var newBase = registerPath(item, base);\n base = staticBase ? base : newBase;\n }\n }\n }\n };\n\n if (!this.projectUrl || this.projectUrl === this.base) {\n this.projectUrl = hostName;\n }\n\n if (!this.noProject) {\n // Determine the projectUrl and projectId\n if (isProjectUrl) {\n // Get project id as project/:projectId.\n registerItems(['project'], hostName);\n path = path.replace(projectRegEx, '');\n } else if (hostName === this.base) {\n // Get project id as first part of path (subdirectory).\n if (hostparts.length > 3 && path.split('/').length > 1) {\n var pathParts = path.split('/');\n pathParts.shift(); // Throw away the first /.\n\n this.projectId = pathParts.shift();\n path = \"/\".concat(pathParts.join('/'));\n this.projectUrl = \"\".concat(hostName, \"/\").concat(this.projectId);\n }\n } else {\n // Get project id from subdomain.\n if (hostparts.length > 2 && (hostparts[2].split('.').length > 2 || hostName.includes('localhost'))) {\n this.projectUrl = hostName;\n this.projectId = hostparts[2].split('.')[0];\n }\n }\n\n this.projectsUrl = this.projectsUrl || \"\".concat(this.base, \"/project\");\n } // Configure Form urls and form ids.\n\n\n if (path.search(/(^|\\/)(form)($|\\/)/) !== -1) {\n registerItems(['form', ['submission', 'action', 'v']], this.projectUrl);\n } else {\n var subRegEx = new RegExp('/(submission|action|v)($|/.*)');\n var subs = path.match(subRegEx);\n this.pathType = subs && subs.length > 1 ? subs[1] : '';\n path = path.replace(subRegEx, '');\n path = path.replace(/\\/$/, '');\n this.formsUrl = \"\".concat(this.projectUrl, \"/form\");\n this.formUrl = path ? this.projectUrl + path : '';\n this.formId = path.replace(/^\\/+|\\/+$/g, '');\n var items = ['submission', 'action', 'v'];\n\n for (var i in items) {\n if (items.hasOwnProperty(i)) {\n var item = items[i];\n this[\"\".concat(item, \"sUrl\")] = \"\".concat(this.projectUrl + path, \"/\").concat(item);\n\n if (this.pathType === item && subs.length > 2 && subs[2]) {\n this[\"\".concat(item, \"Id\")] = subs[2].replace(/^\\/+|\\/+$/g, '');\n this[\"\".concat(item, \"Url\")] = this.projectUrl + path + subs[0];\n }\n }\n }\n } // Set the app url if it is not set.\n\n\n if (!Formio.projectUrlSet) {\n Formio.projectUrl = this.projectUrl;\n }\n }\n /* eslint-enable max-statements */\n\n\n _createClass(Formio, [{\n key: \"delete\",\n value: function _delete(type, opts) {\n var _id = \"\".concat(type, \"Id\");\n\n var _url = \"\".concat(type, \"Url\");\n\n if (!this[_id]) {\n _nativePromiseOnly.default.reject('Nothing to delete');\n }\n\n Formio.cache = {};\n return this.makeRequest(type, this[_url], 'delete', null, opts);\n }\n }, {\n key: \"index\",\n value: function index(type, query, opts) {\n var _url = \"\".concat(type, \"Url\");\n\n query = query || '';\n\n if (query && isObject(query)) {\n query = \"?\".concat(Formio.serialize(query.params));\n }\n\n return this.makeRequest(type, this[_url] + query, 'get', null, opts);\n }\n }, {\n key: \"save\",\n value: function save(type, data, opts) {\n var _id = \"\".concat(type, \"Id\");\n\n var _url = \"\".concat(type, \"Url\");\n\n var method = this[_id] || data._id ? 'put' : 'post';\n var reqUrl = this[_id] ? this[_url] : this[\"\".concat(type, \"sUrl\")];\n\n if (!this[_id] && data._id && method === 'put' && !reqUrl.includes(data._id)) {\n reqUrl += \"/\".concat(data._id);\n }\n\n Formio.cache = {};\n return this.makeRequest(type, reqUrl + this.query, method, data, opts);\n }\n }, {\n key: \"load\",\n value: function load(type, query, opts) {\n var _id = \"\".concat(type, \"Id\");\n\n var _url = \"\".concat(type, \"Url\");\n\n if (query && isObject(query)) {\n query = Formio.serialize(query.params);\n }\n\n if (query) {\n query = this.query ? \"\".concat(this.query, \"&\").concat(query) : \"?\".concat(query);\n } else {\n query = this.query;\n }\n\n if (!this[_id]) {\n return _nativePromiseOnly.default.reject(\"Missing \".concat(_id));\n }\n\n return this.makeRequest(type, this[_url] + query, 'get', null, opts);\n }\n }, {\n key: \"makeRequest\",\n value: function makeRequest() {\n for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n args[_key] = arguments[_key];\n }\n\n return Formio.makeRequest.apply(Formio, [this].concat(args));\n }\n }, {\n key: \"loadProject\",\n value: function loadProject(query, opts) {\n return this.load('project', query, opts);\n }\n }, {\n key: \"saveProject\",\n value: function saveProject(data, opts) {\n return this.save('project', data, opts);\n }\n }, {\n key: \"deleteProject\",\n value: function deleteProject(opts) {\n return this.delete('project', opts);\n }\n }, {\n key: \"loadForm\",\n value: function loadForm(query, opts) {\n var _this2 = this;\n\n return this.load('form', query, opts).then(function (currentForm) {\n // Check to see if there isn't a number in vId.\n if (!currentForm.revisions || isNaN(parseInt(_this2.vId))) {\n return currentForm;\n } // If a submission already exists but form is marked to load current version of form.\n\n\n if (currentForm.revisions === 'current' && _this2.submissionId) {\n return currentForm;\n } // If they specified a revision form, load the revised form components.\n\n\n if (query && isObject(query)) {\n query = Formio.serialize(query.params);\n }\n\n if (query) {\n query = _this2.query ? \"\".concat(_this2.query, \"&\").concat(query) : \"?\".concat(query);\n } else {\n query = _this2.query;\n }\n\n return _this2.makeRequest('form', _this2.vUrl + query, 'get', null, opts).then(function (revisionForm) {\n currentForm.components = revisionForm.components; // Using object.assign so we don't cross polinate multiple form loads.\n\n return Object.assign({}, currentForm);\n }) // If we couldn't load the revision, just return the original form.\n .catch(function () {\n return Object.assign({}, currentForm);\n });\n });\n }\n }, {\n key: \"saveForm\",\n value: function saveForm(data, opts) {\n return this.save('form', data, opts);\n }\n }, {\n key: \"deleteForm\",\n value: function deleteForm(opts) {\n return this.delete('form', opts);\n }\n }, {\n key: \"loadForms\",\n value: function loadForms(query, opts) {\n return this.index('forms', query, opts);\n }\n }, {\n key: \"loadSubmission\",\n value: function loadSubmission(query, opts) {\n var _this3 = this;\n\n return this.load('submission', query, opts).then(function (submission) {\n _this3.vId = submission._fvid;\n _this3.vUrl = \"\".concat(_this3.formUrl, \"/v/\").concat(_this3.vId);\n return submission;\n });\n }\n }, {\n key: \"saveSubmission\",\n value: function saveSubmission(data, opts) {\n if (!isNaN(parseInt(this.vId))) {\n data._fvid = this.vId;\n }\n\n return this.save('submission', data, opts);\n }\n }, {\n key: \"deleteSubmission\",\n value: function deleteSubmission(opts) {\n return this.delete('submission', opts);\n }\n }, {\n key: \"loadSubmissions\",\n value: function loadSubmissions(query, opts) {\n return this.index('submissions', query, opts);\n }\n }, {\n key: \"loadAction\",\n value: function loadAction(query, opts) {\n return this.load('action', query, opts);\n }\n }, {\n key: \"saveAction\",\n value: function saveAction(data, opts) {\n return this.save('action', data, opts);\n }\n }, {\n key: \"deleteAction\",\n value: function deleteAction(opts) {\n return this.delete('action', opts);\n }\n }, {\n key: \"loadActions\",\n value: function loadActions(query, opts) {\n return this.index('actions', query, opts);\n }\n }, {\n key: \"availableActions\",\n value: function availableActions() {\n return this.makeRequest('availableActions', \"\".concat(this.formUrl, \"/actions\"));\n }\n }, {\n key: \"actionInfo\",\n value: function actionInfo(name) {\n return this.makeRequest('actionInfo', \"\".concat(this.formUrl, \"/actions/\").concat(name));\n }\n }, {\n key: \"isObjectId\",\n value: function isObjectId(id) {\n var checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$');\n return checkForHexRegExp.test(id);\n }\n }, {\n key: \"getProjectId\",\n value: function getProjectId() {\n if (!this.projectId) {\n return _nativePromiseOnly.default.resolve('');\n }\n\n if (this.isObjectId(this.projectId)) {\n return _nativePromiseOnly.default.resolve(this.projectId);\n } else {\n return this.loadProject().then(function (project) {\n return project._id;\n });\n }\n }\n }, {\n key: \"getFormId\",\n value: function getFormId() {\n if (!this.formId) {\n return _nativePromiseOnly.default.resolve('');\n }\n\n if (this.isObjectId(this.formId)) {\n return _nativePromiseOnly.default.resolve(this.formId);\n } else {\n return this.loadForm().then(function (form) {\n return form._id;\n });\n }\n }\n }, {\n key: \"currentUser\",\n value: function currentUser(options) {\n return Formio.currentUser(this, options);\n }\n }, {\n key: \"accessInfo\",\n value: function accessInfo() {\n return Formio.accessInfo(this);\n }\n /**\n * Returns the JWT token for this instance.\n *\n * @return {*}\n */\n\n }, {\n key: \"getToken\",\n value: function getToken(options) {\n return Formio.getToken(Object.assign({\n formio: this\n }, this.options, options));\n }\n /**\n * Sets the JWT token for this instance.\n *\n * @return {*}\n */\n\n }, {\n key: \"setToken\",\n value: function setToken(token, options) {\n return Formio.setToken(token, Object.assign({\n formio: this\n }, this.options, options));\n }\n /**\n * Returns a temporary authentication token for single purpose token generation.\n */\n\n }, {\n key: \"getTempToken\",\n value: function getTempToken(expire, allowed, options) {\n var token = Formio.getToken(options);\n\n if (!token) {\n return _nativePromiseOnly.default.reject('You must be authenticated to generate a temporary auth token.');\n }\n\n return this.makeRequest('tempToken', \"\".concat(this.projectUrl, \"/token\"), 'GET', null, {\n ignoreCache: true,\n header: new Headers({\n 'x-expire': expire,\n 'x-allow': allowed\n })\n });\n }\n /**\n * Get a download url for a submission PDF of this submission.\n *\n * @return {*}\n */\n\n }, {\n key: \"getDownloadUrl\",\n value: function getDownloadUrl(form) {\n var _this4 = this;\n\n if (!this.submissionId) {\n return _nativePromiseOnly.default.resolve('');\n }\n\n if (!form) {\n // Make sure to load the form first.\n return this.loadForm().then(function (_form) {\n if (!_form) {\n return '';\n }\n\n return _this4.getDownloadUrl(_form);\n });\n }\n\n var apiUrl = \"/project/\".concat(form.project);\n apiUrl += \"/form/\".concat(form._id);\n apiUrl += \"/submission/\".concat(this.submissionId);\n apiUrl += '/download';\n var download = this.base + apiUrl;\n return new _nativePromiseOnly.default(function (resolve, reject) {\n _this4.getTempToken(3600, \"GET:\".concat(apiUrl)).then(function (tempToken) {\n download += \"?token=\".concat(tempToken.key);\n resolve(download);\n }, function () {\n resolve(download);\n }).catch(reject);\n });\n }\n }, {\n key: \"uploadFile\",\n value: function uploadFile(storage, file, fileName, dir, progressCallback, url) {\n var _this5 = this;\n\n var requestArgs = {\n provider: storage,\n method: 'upload',\n file: file,\n fileName: fileName,\n dir: dir\n };\n var request = Formio.pluginWait('preRequest', requestArgs).then(function () {\n return Formio.pluginGet('fileRequest', requestArgs).then(function (result) {\n if (storage && isNil(result)) {\n if (Formio.providers.storage.hasOwnProperty(storage)) {\n var provider = new Formio.providers.storage[storage](_this5);\n return provider.uploadFile(file, fileName, dir, progressCallback, url);\n } else {\n throw 'Storage provider not found';\n }\n }\n\n return result || {\n url: ''\n };\n });\n });\n return Formio.pluginAlter('wrapFileRequestPromise', request, requestArgs);\n }\n }, {\n key: \"downloadFile\",\n value: function downloadFile(file) {\n var _this6 = this;\n\n var requestArgs = {\n method: 'download',\n file: file\n };\n var request = Formio.pluginWait('preRequest', requestArgs).then(function () {\n return Formio.pluginGet('fileRequest', requestArgs).then(function (result) {\n if (file.storage && isNil(result)) {\n if (Formio.providers.storage.hasOwnProperty(file.storage)) {\n var provider = new Formio.providers.storage[file.storage](_this6);\n return provider.downloadFile(file);\n } else {\n throw 'Storage provider not found';\n }\n }\n\n return result || {\n url: ''\n };\n });\n });\n return Formio.pluginAlter('wrapFileRequestPromise', request, requestArgs);\n } // Determine if the user can submit the form.\n\n }, {\n key: \"canSubmit\",\n value: function canSubmit() {\n /* eslint-disable max-statements, max-depth */\n return _nativePromiseOnly.default.all([this.loadForm(), this.currentUser(), this.accessInfo()]).then(function (results) {\n var form = results.shift();\n var user = results.shift();\n var access = results.shift(); // Get the anonymous and admin roles.\n\n var anonRole = {};\n var adminRole = {};\n\n for (var roleName in access.roles) {\n if (access.roles.hasOwnProperty(roleName)) {\n var role = access.roles[roleName];\n\n if (role.default) {\n anonRole = role;\n }\n\n if (role.admin) {\n adminRole = role;\n }\n }\n }\n\n var canSubmit = false;\n var canSubmitAnonymously = false; // If the user is an admin, then they can submit this form.\n\n if (user && user.roles.includes(adminRole._id)) {\n return true;\n }\n\n for (var i in form.submissionAccess) {\n if (form.submissionAccess.hasOwnProperty(i)) {\n var subRole = form.submissionAccess[i];\n\n if (subRole.type === 'create_all' || subRole.type === 'create_own') {\n for (var j in subRole.roles) {\n if (subRole.roles.hasOwnProperty(j)) {\n // Check if anonymous is allowed.\n if (anonRole._id === subRole.roles[j]) {\n canSubmitAnonymously = true;\n } // Check if the logged in user has the appropriate role.\n\n\n if (user && user.roles.includes(subRole.roles[j])) {\n canSubmit = true;\n break;\n }\n }\n }\n\n if (canSubmit) {\n break;\n }\n }\n }\n } // If their user cannot submit, but anonymous can, then delete token and allow submission.\n\n\n if (!canSubmit && canSubmitAnonymously) {\n canSubmit = true;\n Formio.setUser(null);\n }\n\n return canSubmit;\n });\n /* eslint-enable max-statements, max-depth */\n }\n }, {\n key: \"getUrlParts\",\n value: function getUrlParts(url) {\n return Formio.getUrlParts(url, this);\n }\n }], [{\n key: \"loadProjects\",\n value: function loadProjects(query, opts) {\n query = query || '';\n\n if (isObject(query)) {\n query = \"?\".concat(Formio.serialize(query.params));\n }\n\n return Formio.makeStaticRequest(\"\".concat(Formio.baseUrl, \"/project\").concat(query), 'GET', null, opts);\n }\n }, {\n key: \"getUrlParts\",\n value: function getUrlParts(url, formio) {\n var base = formio && formio.b