@formio/js 5.2.6 → 5.2.7-rc.0

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.
@@ -7585,7 +7585,7 @@ eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\ncon
7585
7585
  /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
7586
7586
 
7587
7587
  "use strict";
7588
- eval("{\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nconst Element_1 = __importDefault(__webpack_require__(/*! ./Element */ \"./lib/cjs/Element.js\"));\nconst Formio_1 = __webpack_require__(/*! ./Formio */ \"./lib/cjs/Formio.js\");\nconst displays_1 = __importDefault(__webpack_require__(/*! ./displays */ \"./lib/cjs/displays/index.js\"));\nconst templates_1 = __importDefault(__webpack_require__(/*! ./templates */ \"./lib/cjs/templates/index.js\"));\nconst utils_1 = __importDefault(__webpack_require__(/*! ./utils */ \"./lib/cjs/utils/index.js\"));\nclass Form extends Element_1.default {\n constructor(elementOrForm, formOrOptions, options = {}) {\n let element, form, formOptions;\n if (elementOrForm instanceof HTMLElement) {\n element = elementOrForm;\n form = formOrOptions;\n formOptions = options;\n }\n else {\n element = null;\n form = elementOrForm;\n formOptions = formOrOptions || {};\n }\n if (Formio_1.Formio.options && Formio_1.Formio.options.form) {\n formOptions = Object.assign(formOptions, Formio_1.Formio.options.form);\n }\n super(formOptions);\n if (this.options.useSessionToken) {\n Formio_1.Formio.useSessionToken(this.options);\n }\n this.ready = new Promise((resolve, reject) => {\n this.readyResolve = resolve;\n this.readyReject = reject;\n });\n this.instance = null;\n if (element) {\n if (this.element) {\n delete this.element.component;\n }\n this.element = element;\n }\n else {\n this.element = null;\n }\n this.options = formOptions;\n this.options.events = this.events;\n if (form) {\n this.setForm(form)\n .then(() => this.readyResolve(this.instance))\n .catch(this.readyReject);\n }\n this.display = '';\n }\n createElement(tag, attrs, children) {\n const element = document.createElement(tag);\n for (const attr in attrs) {\n if (attrs.hasOwnProperty(attr)) {\n element.setAttribute(attr, attrs[attr]);\n }\n }\n (children || []).forEach(child => {\n element.appendChild(this.createElement(child.tag, child.attrs, child.children));\n });\n return element;\n }\n set loading(load) {\n if (!this.element || this.options.noLoader) {\n return;\n }\n if (load) {\n if (this.loader) {\n return;\n }\n this.loader = this.createElement('div', {\n 'class': 'formio-loader'\n }, [{\n tag: 'div',\n attrs: {\n class: 'loader-wrapper'\n },\n children: [{\n tag: 'div',\n attrs: {\n class: 'loader text-center'\n }\n }]\n }]);\n this.element.appendChild(this.loader);\n }\n else if (this.loader) {\n if (this.element.contains(this.loader)) {\n this.element.removeChild(this.loader);\n }\n this.loader = null;\n }\n }\n /**\n * Create a new form instance provided the display of the form.\n * @param {string} display - The display of the form, either \"wizard\", \"form\", or \"pdf\"\n * @returns {Webform|Wizard|PDF} - The new form instance for the display.\n */\n create(display) {\n if (this.options && (this.options.flatten || this.options.renderMode === 'flat')) {\n display = 'form';\n }\n this.display = display;\n if (displays_1.default.displays[display]) {\n return new displays_1.default.displays[display](this.element, this.options);\n }\n else {\n // eslint-disable-next-line new-cap\n return new displays_1.default.displays['webform'](this.element, this.options);\n }\n }\n /**\n * Sets the form. Either as JSON or a URL to a form JSON schema.\n * @param {string|object} formParam - Either the form JSON or the URL of the form json.\n * @returns {void}\n */\n set form(formParam) {\n this.setForm(formParam);\n }\n errorForm(err) {\n return {\n components: [\n {\n 'label': 'HTML',\n 'tag': 'div',\n 'className': 'error error-message alert alert-danger ui red message',\n 'attrs': [\n {\n 'attr': 'role',\n 'value': 'alert'\n }\n ],\n 'key': 'errorMessage',\n 'type': 'htmlelement',\n 'input': false,\n 'content': typeof err === 'string' ? err : err.message,\n }\n ]\n };\n }\n /**\n * Check Subdirectories path and provide correct options\n * @param {string} url - The the URL of the form json.\n * @param {import('@formio/core').Form} form - The form json.\n * @returns {object} The initial options with base and project.\n */\n getFormInitOptions(url, form) {\n const options = {};\n const index = url.indexOf(form === null || form === void 0 ? void 0 : form.path);\n // form url doesn't include form path\n if (index === -1) {\n return options;\n }\n const projectUrl = url.substring(0, index - 1);\n const urlParts = Formio_1.Formio.getUrlParts(projectUrl);\n // project url doesn't include subdirectories path\n if (!urlParts || urlParts.filter(part => !!part).length < 4) {\n return options;\n }\n const baseUrl = `${urlParts[1]}${urlParts[2]}`;\n // Skip if baseUrl has already been set\n if (baseUrl !== Formio_1.Formio.baseUrl) {\n return {\n base: baseUrl,\n project: projectUrl,\n };\n }\n return {};\n }\n /**\n * Sets the form to the JSON schema of a form.\n * @param {import('@formio/core').Form} formParam - The form JSON to set this form to.\n * @returns {Promise<Webform|Wizard|PDF>} - The webform instance that was created.\n */\n setForm(formParam) {\n let result;\n formParam = formParam || this.form;\n if (typeof formParam === 'string') {\n const formio = new Formio_1.Formio(formParam);\n let error;\n this.loading = true;\n result = this.getSubmission(formio, this.options)\n .catch((err) => {\n error = err;\n })\n .then((submission) => {\n return formio.loadForm()\n // If the form returned an error, show it instead of the form.\n .catch(err => {\n error = err;\n })\n .then((form) => {\n // If the submission returned an error, show it instead of the form.\n if (error) {\n form = this.errorForm(error);\n }\n this.loading = false;\n this.instance = this.instance || this.create(form.display);\n const options = this.getFormInitOptions(formParam, form);\n this.instance.setUrl(formParam, options);\n this.instance.nosubmit = false;\n this._form = this.instance.form = form;\n if (submission) {\n this.instance.submission = submission;\n }\n if (error) {\n throw error;\n }\n return this.instance;\n });\n });\n }\n else {\n this.instance = this.instance || this.create(formParam.display);\n this._form = this.instance.form = formParam;\n result = this.instance.ready;\n }\n // A redraw has occurred so save off the new element in case of a setDisplay causing a rebuild.\n return result.then(() => {\n if (this.element) {\n delete this.element.component;\n }\n this.element = this.instance.element;\n return this.instance;\n });\n }\n getSubmission(formio, opts) {\n if (formio.submissionId) {\n return formio.loadSubmission(null, opts);\n }\n return Promise.resolve();\n }\n /**\n * Returns the loaded forms JSON.\n * @returns {object} - The loaded form's JSON\n */\n get form() {\n return this._form;\n }\n /**\n * Changes the display of the form.\n * @param {string} display - The display to set this form. Either \"wizard\", \"form\", or \"pdf\"\n * @returns {Promise<Webform|Wizard|PDF>} - The form instance that was created after changing the display.\n */\n setDisplay(display) {\n if ((this.display === display) && this.instance) {\n return Promise.resolve(this.instance);\n }\n this.form.display = display;\n this.instance.destroy();\n this.instance = this.create(display);\n return this.setForm(this.form);\n }\n empty() {\n if (this.element) {\n while (this.element.firstChild) {\n this.element.removeChild(this.element.firstChild);\n }\n }\n }\n static embed(embed) {\n return new Promise((resolve) => {\n if (!embed || !embed.src) {\n resolve();\n }\n const id = this.id || `formio-${Math.random().toString(36).substring(7)}`;\n const className = embed.class || 'formio-form-wrapper';\n let code = embed.styles ? `<link rel=\"stylesheet\" href=\"${embed.styles}\">` : '';\n code += `<div id=\"${id}\" class=\"${className}\"></div>`;\n document.write(code);\n let attempts = 0;\n const wait = setInterval(() => {\n attempts++;\n const formElement = document.getElementById(id);\n if (formElement || attempts > 10) {\n resolve(new Form(formElement, embed.src).ready);\n clearInterval(wait);\n }\n }, 10);\n });\n }\n /**\n * Sanitize an html string.\n * @param {string} dirty - The dirty html string to sanitize.\n * @param {boolean} forceSanitize - If the string should be force sanitized.\n * @returns {string} - The sanitized html string.\n */\n sanitize(dirty, forceSanitize) {\n // If Sanitize is turned off\n if (this.options.sanitize === false && !forceSanitize) {\n return dirty;\n }\n return utils_1.default.sanitize(dirty, this.options);\n }\n setContent(element, content, forceSanitize) {\n if (element instanceof HTMLElement) {\n element.innerHTML = this.sanitize(content, forceSanitize);\n return true;\n }\n return false;\n }\n /**\n * Build a new form.\n * @returns {Promise<Webform|Wizard|PDF>} - The form instance that was created.\n */\n build() {\n if (!this.instance) {\n return Promise.reject('Form not ready. Use form.ready promise');\n }\n if (!this.element) {\n return Promise.reject('No DOM element for form.');\n }\n // Add temporary loader.\n const template = (this.options && this.options.template) ? this.options.template : 'bootstrap';\n const loader = templates_1.default[template].loader || templates_1.default.bootstrap.loader;\n this.setContent(this.element, loader.form);\n return this.render().then(html => {\n this.setContent(this.element, html);\n return this.attach(this.element).then(() => this.instance);\n })\n .then((param) => {\n this.emit('build', param);\n return param;\n });\n }\n render() {\n if (!this.instance) {\n return Promise.reject('Form not ready. Use form.ready promise');\n }\n return Promise.resolve(this.instance.render())\n .then((param) => {\n this.emit('render', param);\n return param;\n });\n }\n attach(element) {\n if (!this.instance) {\n return Promise.reject('Form not ready. Use form.ready promise');\n }\n if (this.element) {\n delete this.element.component;\n }\n this.element = element;\n return this.instance.attach(this.element)\n .then((param) => {\n this.emit('attach', param);\n return param;\n });\n }\n teardown() {\n super.teardown();\n delete this.instance;\n delete this.ready;\n }\n}\nexports[\"default\"] = Form;\n// Allow simple embedding.\nFormio_1.Formio.embedForm = (embed) => Form.embed(embed);\n/**\n * Creates an easy to use interface for embedding webforms, pdfs, and wizards into your application.\n * @param {object} elementOrForm - The DOM element you wish to render this form within, or the form definition.\n * @param {object | string | FormOptions} formOrOptions - A Form JSON schema, the URL of a hosted form, or the form options.\n * @param {FormOptions} [options] - The options to create a new form instance.\n * @returns {Promise<Webform|Wizard|PDF>} - The form instance that was created.\n * @example\n * import { Formio } from '@formio/js';\n * Formio.createForm(document.getElementById('formio'), 'https://examples.form.io/example');\n */\nFormio_1.Formio.createForm = (elementOrForm, formOrOptions, options) => {\n return (new Form(elementOrForm, formOrOptions, options)).ready;\n};\nFormio_1.Formio.Form = Form;\n\n\n//# sourceURL=webpack://Formio/./lib/cjs/Form.js?\n}");
7588
+ eval("{\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nconst Element_1 = __importDefault(__webpack_require__(/*! ./Element */ \"./lib/cjs/Element.js\"));\nconst Formio_1 = __webpack_require__(/*! ./Formio */ \"./lib/cjs/Formio.js\");\nconst displays_1 = __importDefault(__webpack_require__(/*! ./displays */ \"./lib/cjs/displays/index.js\"));\nconst templates_1 = __importDefault(__webpack_require__(/*! ./templates */ \"./lib/cjs/templates/index.js\"));\nconst utils_1 = __importDefault(__webpack_require__(/*! ./utils */ \"./lib/cjs/utils/index.js\"));\nclass Form extends Element_1.default {\n constructor(elementOrForm, formOrOptions, options = {}) {\n let element, form, formOptions;\n if (elementOrForm instanceof HTMLElement) {\n element = elementOrForm;\n form = formOrOptions;\n formOptions = options;\n }\n else {\n element = null;\n form = elementOrForm;\n formOptions = formOrOptions || {};\n }\n if (Formio_1.Formio.options && Formio_1.Formio.options.form) {\n formOptions = Object.assign(formOptions, Formio_1.Formio.options.form);\n }\n super(formOptions);\n if (this.options.useSessionToken) {\n Formio_1.Formio.useSessionToken(this.options);\n }\n this.ready = new Promise((resolve, reject) => {\n this.readyResolve = resolve;\n this.readyReject = reject;\n });\n this.instance = null;\n if (element) {\n if (this.element) {\n delete this.element.component;\n }\n this.element = element;\n }\n else {\n this.element = null;\n }\n this.options = formOptions;\n this.options.events = this.events;\n if (form) {\n this.setForm(form)\n .then(() => this.readyResolve(this.instance))\n .catch(this.readyReject);\n }\n this.display = '';\n }\n createElement(tag, attrs, children) {\n const element = document.createElement(tag);\n for (const attr in attrs) {\n if (attrs.hasOwnProperty(attr)) {\n element.setAttribute(attr, attrs[attr]);\n }\n }\n (children || []).forEach(child => {\n element.appendChild(this.createElement(child.tag, child.attrs, child.children));\n });\n return element;\n }\n set loading(load) {\n if (!this.element || this.options.noLoader) {\n return;\n }\n if (load) {\n if (this.loader) {\n return;\n }\n this.loader = this.createElement('div', {\n 'class': 'formio-loader'\n }, [{\n tag: 'div',\n attrs: {\n class: 'loader-wrapper'\n },\n children: [{\n tag: 'div',\n attrs: {\n class: 'loader text-center'\n }\n }]\n }]);\n this.element.appendChild(this.loader);\n }\n else if (this.loader) {\n if (this.element.contains(this.loader)) {\n this.element.removeChild(this.loader);\n }\n this.loader = null;\n }\n }\n /**\n * Create a new form instance provided the display of the form.\n * @param {string} display - The display of the form, either \"wizard\", \"form\", or \"pdf\"\n * @returns {Webform|Wizard|PDF} - The new form instance for the display.\n */\n create(display) {\n if (this.options && (this.options.flatten || this.options.renderMode === 'flat')) {\n display = 'form';\n }\n this.display = display;\n if (displays_1.default.displays[display]) {\n return new displays_1.default.displays[display](this.element, this.options);\n }\n else {\n // eslint-disable-next-line new-cap\n return new displays_1.default.displays['webform'](this.element, this.options);\n }\n }\n /**\n * Sets the form. Either as JSON or a URL to a form JSON schema.\n * @param {string|object} formParam - Either the form JSON or the URL of the form json.\n * @returns {void}\n */\n set form(formParam) {\n this.setForm(formParam);\n }\n errorForm(err) {\n return {\n components: [\n {\n 'label': 'HTML',\n 'tag': 'div',\n 'className': 'error error-message alert alert-danger ui red message',\n 'attrs': [\n {\n 'attr': 'role',\n 'value': 'alert'\n }\n ],\n 'key': 'errorMessage',\n 'type': 'htmlelement',\n 'input': false,\n 'content': typeof err === 'string' ? err : err.message,\n }\n ]\n };\n }\n /**\n * Check Subdirectories path and provide correct options\n * @param {string} url - The the URL of the form json.\n * @param {import('@formio/core').Form} form - The form json.\n * @returns {object} The initial options with base and project.\n */\n getFormInitOptions(url, form) {\n const options = {};\n const index = url.indexOf(form === null || form === void 0 ? void 0 : form.path);\n // form url doesn't include form path\n if (index === -1) {\n return options;\n }\n const projectUrl = url.substring(0, index - 1);\n const urlParts = Formio_1.Formio.getUrlParts(projectUrl);\n // project url doesn't include subdirectories path\n if (!urlParts || urlParts.filter(part => !!part).length < 4) {\n return options;\n }\n const baseUrl = `${urlParts[1]}${urlParts[2]}`;\n // Skip if baseUrl has already been set\n if (baseUrl !== Formio_1.Formio.baseUrl) {\n return {\n base: baseUrl,\n project: projectUrl,\n };\n }\n return {};\n }\n /**\n * Sets the form to the JSON schema of a form.\n * @param {import('@formio/core').Form} formParam - The form JSON to set this form to.\n * @returns {Promise<Webform|Wizard|PDF>} - The webform instance that was created.\n */\n setForm(formParam) {\n let result;\n formParam = formParam || this.form;\n if (typeof formParam === 'string') {\n const formio = new Formio_1.Formio(formParam);\n let error;\n this.loading = true;\n result = this.getSubmission(formio, this.options)\n .catch((err) => {\n error = err;\n })\n .then((submission) => {\n return formio.loadForm()\n // If the form returned an error, show it instead of the form.\n .catch(err => {\n error = err;\n })\n .then((form) => {\n // If the submission returned an error, show it instead of the form.\n if (error) {\n form = this.errorForm(error);\n }\n this.loading = false;\n this.instance = this.instance || this.create(form.display);\n const options = this.getFormInitOptions(formParam, form);\n this.instance.setUrl(formParam, options);\n this.instance.nosubmit = false;\n this._form = this.instance.form = form;\n if (submission) {\n this.instance.submission = submission;\n }\n if (error) {\n throw error;\n }\n return this.instance;\n });\n });\n }\n else {\n this.instance = this.instance || this.create(formParam.display);\n this._form = this.instance.form = formParam;\n result = this.instance.ready;\n }\n // A redraw has occurred so save off the new element in case of a setDisplay causing a rebuild.\n return result.then(() => {\n if (this.element) {\n delete this.element.component;\n }\n this.element = this.instance.element;\n return this.instance;\n });\n }\n getSubmission(formio, opts) {\n if (formio.submissionId) {\n return formio.loadSubmission(null, opts);\n }\n return Promise.resolve();\n }\n /**\n * Returns the loaded forms JSON.\n * @returns {object} - The loaded form's JSON\n */\n get form() {\n return this._form;\n }\n /**\n * Changes the display of the form.\n * @param {string} display - The display to set this form. Either \"wizard\", \"form\", or \"pdf\"\n * @returns {Promise<Webform|Wizard|PDF>} - The form instance that was created after changing the display.\n */\n setDisplay(display) {\n if ((this.display === display) && this.instance) {\n return Promise.resolve(this.instance);\n }\n this.form.display = display;\n this.instance.destroy(true);\n this.instance = this.create(display);\n return this.setForm(this.form);\n }\n empty() {\n if (this.element) {\n while (this.element.firstChild) {\n this.element.removeChild(this.element.firstChild);\n }\n }\n }\n static embed(embed) {\n return new Promise((resolve) => {\n if (!embed || !embed.src) {\n resolve();\n }\n const id = this.id || `formio-${Math.random().toString(36).substring(7)}`;\n const className = embed.class || 'formio-form-wrapper';\n let code = embed.styles ? `<link rel=\"stylesheet\" href=\"${embed.styles}\">` : '';\n code += `<div id=\"${id}\" class=\"${className}\"></div>`;\n document.write(code);\n let attempts = 0;\n const wait = setInterval(() => {\n attempts++;\n const formElement = document.getElementById(id);\n if (formElement || attempts > 10) {\n resolve(new Form(formElement, embed.src).ready);\n clearInterval(wait);\n }\n }, 10);\n });\n }\n /**\n * Sanitize an html string.\n * @param {string} dirty - The dirty html string to sanitize.\n * @param {boolean} forceSanitize - If the string should be force sanitized.\n * @returns {string} - The sanitized html string.\n */\n sanitize(dirty, forceSanitize) {\n // If Sanitize is turned off\n if (this.options.sanitize === false && !forceSanitize) {\n return dirty;\n }\n return utils_1.default.sanitize(dirty, this.options);\n }\n setContent(element, content, forceSanitize) {\n if (element instanceof HTMLElement) {\n element.innerHTML = this.sanitize(content, forceSanitize);\n return true;\n }\n return false;\n }\n /**\n * Build a new form.\n * @returns {Promise<Webform|Wizard|PDF>} - The form instance that was created.\n */\n build() {\n if (!this.instance) {\n return Promise.reject('Form not ready. Use form.ready promise');\n }\n if (!this.element) {\n return Promise.reject('No DOM element for form.');\n }\n // Add temporary loader.\n const template = (this.options && this.options.template) ? this.options.template : 'bootstrap';\n const loader = templates_1.default[template].loader || templates_1.default.bootstrap.loader;\n this.setContent(this.element, loader.form);\n return this.render().then(html => {\n this.setContent(this.element, html);\n return this.attach(this.element).then(() => this.instance);\n })\n .then((param) => {\n this.emit('build', param);\n return param;\n });\n }\n render() {\n if (!this.instance) {\n return Promise.reject('Form not ready. Use form.ready promise');\n }\n return Promise.resolve(this.instance.render())\n .then((param) => {\n this.emit('render', param);\n return param;\n });\n }\n attach(element) {\n if (!this.instance) {\n return Promise.reject('Form not ready. Use form.ready promise');\n }\n if (this.element) {\n delete this.element.component;\n }\n this.element = element;\n return this.instance.attach(this.element)\n .then((param) => {\n this.emit('attach', param);\n return param;\n });\n }\n teardown() {\n super.teardown();\n delete this.instance;\n delete this.ready;\n }\n}\nexports[\"default\"] = Form;\n// Allow simple embedding.\nFormio_1.Formio.embedForm = (embed) => Form.embed(embed);\n/**\n * Creates an easy to use interface for embedding webforms, pdfs, and wizards into your application.\n * @param {object} elementOrForm - The DOM element you wish to render this form within, or the form definition.\n * @param {object | string | FormOptions} formOrOptions - A Form JSON schema, the URL of a hosted form, or the form options.\n * @param {FormOptions} [options] - The options to create a new form instance.\n * @returns {Promise<Webform|Wizard|PDF>} - The form instance that was created.\n * @example\n * import { Formio } from '@formio/js';\n * Formio.createForm(document.getElementById('formio'), 'https://examples.form.io/example');\n */\nFormio_1.Formio.createForm = (elementOrForm, formOrOptions, options) => {\n return (new Form(elementOrForm, formOrOptions, options)).ready;\n};\nFormio_1.Formio.Form = Form;\n\n\n//# sourceURL=webpack://Formio/./lib/cjs/Form.js?\n}");
7589
7589
 
7590
7590
  /***/ }),
7591
7591