1
0
mirror of synced 2024-11-26 23:36:02 +03:00
vue-formulario/dist/formulario.min.js
2020-10-19 14:38:35 +03:00

35 lines
39 KiB
JavaScript

var VueFormulario=function(e){"use strict";e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;const t=(e,t)=>({classification:e,component:"FormularioInput"+(t||e[0].toUpperCase()+e.substr(1))});var r=Object.assign(Object.assign({},["text","email","number","color","date","hidden","month","password","search","tel","time","url","week","datetime-local"].reduce((e,r)=>Object.assign(Object.assign({},e),{[r]:t("text")}),{})),{range:t("slider"),textarea:t("textarea","TextArea"),checkbox:t("box"),radio:t("box"),submit:t("button"),button:t("button"),select:t("select"),file:t("file"),image:t("file"),group:t("group")}),i=function(e){if("string"!=typeof e)return!1;var t=e.match(o);if(!t)return!1;var r=t[1];if(!r)return!1;if(s.test(r)||a.test(r))return!0;return!1},o=/^(?:\w+:)?\/\/(\S+)$/,s=/^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/,a=/^[^\s\.]+\.\S{2,}$/;for(var n="-_",l=36;l--;)n+=l.toString(36);for(l=36;l---10;)n+=l.toString(36).toUpperCase();var u=function(e){var t="";for(l=e||21;l--;)t+=n[64*Math.random()|0];return t};class d{constructor(e,t={},r={}){this.input=e,this.fileList=e.files,this.files=[],this.options=Object.assign({mimes:{}},r),this.results=!1,this.context=t,Array.isArray(this.fileList)?this.rehydrateFileList(this.fileList):this.addFileList(this.fileList)}rehydrateFileList(e){const t=e.reduce((e,t)=>{const r=t[this.options?this.options.fileUrlKey:"url"],i=!(!r||-1===r.lastIndexOf("."))&&r.substr(r.lastIndexOf(".")+1),o=this.options.mimes[i]||!1;return e.push(Object.assign({},t,r?{name:r.substr(r.lastIndexOf("/")+1||0),type:t.type?t.type:o,previewData:r}:{})),e},[]);this.results=e,this.addFileList(t)}addFileList(e){for(let t=0;t<e.length;t++){const r=e[t],i=u();this.files.push({progress:!1,error:!1,complete:!1,justFinished:!1,name:r.name||"file-upload",file:r,uuid:i,path:!1,removeFile:()=>this.removeFile(i),previewData:r.previewData||!1})}}hasUploader(){return!!this.context.uploader}uploaderIsAxios(){return this.hasUploader&&"function"==typeof this.context.uploader.request&&"function"==typeof this.context.uploader.get&&"function"==typeof this.context.uploader.delete&&"function"==typeof this.context.uploader.post}getUploader(...e){if(this.uploaderIsAxios()){const t=new FormData;if(t.append(this.context.name||"file",e[0]),!1===this.context.uploadUrl)throw new Error("No uploadURL specified: https://vueformulate.com/guide/inputs/file/#props");return this.context.uploader.post(this.context.uploadUrl,t,{headers:{"Content-Type":"multipart/form-data"},onUploadProgress:t=>{e[1](Math.round(100*t.loaded/t.total))}}).then(e=>e.data).catch(e[2])}return this.context.uploader(...e)}upload(){return this.results?Promise.resolve(this.results):new Promise((e,t)=>{if(!this.hasUploader)return t(new Error("No uploader has been defined"));Promise.all(this.files.map(e=>e.path?Promise.resolve(e.path):this.getUploader(e.file,t=>{e.progress=t,t>=100&&(e.complete||(e.justFinished=!0,setTimeout(()=>{e.justFinished=!1},this.options.uploadJustCompleteDuration)),e.complete=!0)},t=>{e.progress=0,e.error=t,e.complete=!0},this.options))).then(t=>{this.results=t,e(t)}).catch(e=>{throw new Error(e)})})}removeFile(e){if(this.files=this.files.filter(t=>t.uuid!==e),this.context.performValidation(),window&&this.fileList instanceof FileList){const e=new DataTransfer;this.files.map(({file:t})=>e.items.add(t)),this.fileList=e.files,this.input=e}}loadPreviews(){this.files.map(e=>{if(!e.previewData&&window&&window.FileReader&&/^image\//.test(e.file.type)){const t=new FileReader;t.onload=t=>Object.assign(e,{previewData:t.target.result}),t.readAsDataURL(e.file)}})}getFileList(){return this.fileList}getFiles(){return this.files}toString(){const e=this.files.length?this.files.length+" files":"empty";return this.results?JSON.stringify(this.results,null," "):`FileUpload(${e})`}}function h(e,t){if(e===t)return!0;if(!e||!t)return!1;const r=Object.keys(e);if(Object.keys(t).length!==r.length)return!1;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(0===r.length)return e===t;for(let i=0;i<r.length;i++){const o=r[i];if(e[o]!==t[o])return!1}return!0}function p(e){return"string"==typeof e?e.replace(/([_][a-z0-9])/gi,t=>0!==e.indexOf(t)&&"_"!==e[e.indexOf(t)-1]?t.toUpperCase().replace("_",""):t):e}function c(e){return"string"==typeof e&&/^[\^]/.test(e.charAt(0))?[p(e.substr(1)),e.charAt(0)]:[p(e),null]}function f(e){return e?"string"==typeof e?[e]:Array.isArray(e)?e:"object"==typeof e?Object.values(e):[]:[]}function m(e,t){return"string"==typeof e?m(e.split("|"),t):Array.isArray(e)?e.map(e=>function(e,t){if("function"==typeof e)return[e,[]];if(Array.isArray(e)&&e.length){e=e.slice();const[r,i]=c(e.shift());if("string"==typeof r&&Object.prototype.hasOwnProperty.call(t,r))return[t[r],e,r,i];if("function"==typeof r)return[r,e,r,i]}if("string"==typeof e){const r=e.split(":"),[i,o]=c(r.shift());if(Object.prototype.hasOwnProperty.call(t,i))return[t[i],r.length?r.join(":").split(","):[],i,o];throw new Error("Unknown validation rule "+e)}return!1}(e,t)).filter(e=>!!e):[]}function g(e){switch(typeof e){case"symbol":case"number":case"string":case"boolean":case"undefined":return!0;default:return null===e}}function y(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function v(e,t){const r=t.split(".");let i=e;for(const e in r){const t=r[e].match(/(.+)\[(\d+)\]$/);if(void 0===i)return null;if(t){if(i=i[t[1]],void 0===i)return null;i=i[t[2]]}else i=i[r[e]]}return i}var b={accepted:({value:e})=>Promise.resolve(["yes","on","1",1,!0,"true"].includes(e)),after({value:e},t=!1){const r=!1!==t?Date.parse(t):Date.now(),i=e instanceof Date?e.getTime():Date.parse(e);return Promise.resolve(!isNaN(i)&&i>r)},alpha({value:e},t="default"){const r={default:/^[a-zA-ZÀ-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z]+$/},i=y(r,t)?t:"default";return Promise.resolve(r[i].test(e))},alphanumeric({value:e},t="default"){const r={default:/^[a-zA-Z0-9À-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z0-9]+$/},i=y(r,t)?t:"default";return Promise.resolve(r[i].test(e))},before({value:e},t=!1){const r=!1!==t?Date.parse(t):Date.now(),i=e instanceof Date?e.getTime():Date.parse(e);return Promise.resolve(!isNaN(i)&&i<r)},between:({value:e},t=0,r=10,i)=>Promise.resolve(null!==t&&null!==r&&!isNaN(t)&&!isNaN(r)&&(!isNaN(Number(e))&&"length"!==i||"value"===i?(e=Number(e),t=Number(t),r=Number(r),e>t&&e<r):("string"==typeof e||"length"===i)&&(e=isNaN(Number(e))?e:e.toString()).length>t&&e.length<r)),confirm:({value:e,getFormValues:t,name:r},i)=>Promise.resolve((()=>{const o=t();let s=i;return s||(s=/_confirm$/.test(r)?r.substr(0,r.length-8):r+"_confirm"),o[s]===e})()),date:({value:e},t=!1)=>Promise.resolve(t?function(e){const t=`^${r=e,r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}$`;var r;const i={MM:"(0[1-9]|1[012])",M:"([1-9]|1[012])",DD:"([012][1-9]|3[01])",D:"([012]?[1-9]|3[01])",YYYY:"\\d{4}",YY:"\\d{2}"};return new RegExp(Object.keys(i).reduce((e,t)=>e.replace(t,i[t]),t))}(t).test(e):!isNaN(Date.parse(e))),email({value:e}){if(!e)return Promise.resolve(!0);return Promise.resolve(/^(([^<>()\[\].,;:\s@"]+(\.[^<>()\[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/i.test(e))},endsWith:({value:e},...t)=>e?"string"==typeof e?Promise.resolve(0===t.length||t.some(t=>e.endsWith(t))):Promise.resolve(!1):Promise.resolve(!0),in:({value:e},...t)=>Promise.resolve(t.some(t=>"object"==typeof t?h(t,e):t===e)),matches:({value:e},...t)=>Promise.resolve(!!t.find(t=>("string"==typeof t&&"/"===t.substr(0,1)&&"/"===t.substr(-1)&&(t=new RegExp(t.substr(1,t.length-2))),t instanceof RegExp?t.test(e):t===e))),mime({value:e},...t){if(e instanceof d){const r=e.getFiles(),i=e=>t.includes(e.type),o=r.reduce((e,{file:t})=>e&&i(t),!0);return Promise.resolve(o)}return Promise.resolve(!0)},min:({value:e},t=1,r)=>Promise.resolve(Array.isArray(e)?(t=isNaN(t)?t:Number(t),e.length>=t):!isNaN(e)&&"length"!==r||"value"===r?(e=isNaN(e)?e:Number(e))>=t:("string"==typeof e||"length"===r)&&(e=isNaN(e)?e:e.toString()).length>=t),max:({value:e},t=10,r)=>Promise.resolve(Array.isArray(e)?(t=isNaN(Number(t))?t:Number(t),e.length<=t):!isNaN(e)&&"length"!==r||"value"===r?(e=isNaN(e)?e:Number(e))<=t:("string"==typeof e||"length"===r)&&(e=isNaN(e)?e:e.toString()).length<=t),not:({value:e},...t)=>Promise.resolve(!t.some(t=>"object"==typeof t?h(t,e):t===e)),number:({value:e})=>Promise.resolve(!isNaN(Number(e))),required:({value:e},t=!0)=>Promise.resolve(!(t&&!["no","false"].includes(t))||(Array.isArray(e)?!!e.length:e instanceof d?e.getFiles().length>0:"string"==typeof e?!!e:"object"!=typeof e||!!e&&!!Object.keys(e).length)),startsWith:({value:e},...t)=>e?"string"==typeof e?Promise.resolve(0===t.length||t.some(t=>e.startsWith(t))):Promise.resolve(!1):Promise.resolve(!0),url:({value:e})=>Promise.resolve(i(e)),bail:()=>Promise.resolve(!0)},E={csv:"text/csv",gif:"image/gif",jpeg:"image/jpeg",jpg:"image/jpeg",png:"image/png",pdf:"application/pdf",svg:"image/svg+xml"};const O={default:(e,t)=>e.$t("validation.default",t),accepted:(e,t)=>e.$t("validation.accepted",t),after:(e,t)=>Array.isArray(t.args)&&t.args.length?e.$t("validation.after.compare",t):e.$t("validation.after.default",t),alpha:(e,t)=>e.$t("validation.alpha",t),alphanumeric:(e,t)=>e.$t("validation.alphanumeric",t),before:(e,t)=>Array.isArray(t.args)&&t.args.length?e.$t("validation.before.compare",t):e.$t("validation.before.default",t),between(e,t){const r=!(!Array.isArray(t.args)||!t.args[2])&&t.args[2];return!isNaN(t.value)&&"length"!==r||"value"===r?e.$t("validation.between.force",t):e.$t("validation.between.default",t)},confirm:(e,t)=>e.$t("validation.confirm",t),date:(e,t)=>Array.isArray(t.args)&&t.args.length?e.$t("validation.date.format",t):e.$t("validation.date.default",t),email:(e,t)=>e.$t("validation.email.default",t),endsWith:(e,t)=>e.$t("validation.endsWith.default",t),in:function(e,t){return"string"==typeof t.value&&t.value?e.$t("validation.in.string",t):e.$t("validation.in.default",t)},matches:(e,t)=>e.$t("validation.matches.default",t),max(e,t){const r=t.args[0];if(Array.isArray(t.value))return e.$tc("validation.max.array",r,t);const i=!(!Array.isArray(t.args)||!t.args[1])&&t.args[1];return!isNaN(t.value)&&"length"!==i||"value"===i?e.$tc("validation.max.force",r,t):e.$tc("validation.max.default",r,t)},mime:(e,t)=>t.args[0]?e.$t("validation.mime.default",t):e.$t("validation.mime.no_formats_allowed",t),min(e,t){const r=t.args[0];if(Array.isArray(t.value))return e.$tc("validation.min.array",r,t);const i=!(!Array.isArray(t.args)||!t.args[1])&&t.args[1];return!isNaN(t.value)&&"length"!==i||"value"===i?e.$tc("validation.min.force",r,t):e.$tc("validation.min.default",r,t)},not:(e,t)=>e.$t("validation.not.default",t),number:(e,t)=>e.$t("validation.number.default",t),required:(e,t)=>e.$t("validation.required.default",t),startsWith:(e,t)=>e.$t("validation.startsWith.default",t),url:(e,t)=>e.$t("validation.url.default",t)};function x(e){e.extend({validationMessages:O})}function w(e,t,r,i){return new Promise(r=>{const o=(i.fauxUploaderDuration||2e3)*(.5+Math.random()),s=performance.now(),a=()=>setTimeout(()=>{const i=performance.now()-s,n=Math.min(100,Math.round(i/o*100));if(t(n),n>=100)return r({url:"http://via.placeholder.com/350x150.png",name:e.name});a()},20);a()})}
/*!
* isobject <https://github.com/jonschlinkert/isobject>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
/*!
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
function V(e){return!0==(null!=(t=e)&&"object"==typeof t&&!1===Array.isArray(t))&&"[object Object]"===Object.prototype.toString.call(e);var t}function j(e){var t,r;return!1!==V(e)&&("function"==typeof(t=e.constructor)&&(!1!==V(r=t.prototype)&&!1!==r.hasOwnProperty("isPrototypeOf")))}
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function $(e,t){var r={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(r[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++)t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(r[i[o]]=e[i[o]])}return r}function A(e,t,r,i){var o,s=arguments.length,a=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,i);else for(var n=e.length-1;n>=0;n--)(o=e[n])&&(a=(s<3?o(a):s>3?o(t,r,a):o(t,r))||a);return s>3&&a&&Object.defineProperty(t,r,a),a
/**
* vue-class-component v7.2.3
* (c) 2015-present Evan You
* @license MIT
*/}function _(e){return(_="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function P(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function F(e){return function(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t<e.length;t++)r[t]=e[t];return r}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function R(){return"undefined"!=typeof Reflect&&Reflect.defineMetadata&&Reflect.getOwnMetadataKeys}function N(e,t){S(e,t),Object.getOwnPropertyNames(t.prototype).forEach((function(r){S(e.prototype,t.prototype,r)})),Object.getOwnPropertyNames(t).forEach((function(r){S(e,t,r)}))}function S(e,t,r){(r?Reflect.getOwnMetadataKeys(t,r):Reflect.getOwnMetadataKeys(t)).forEach((function(i){var o=r?Reflect.getOwnMetadata(i,t,r):Reflect.getOwnMetadata(i,t);r?Reflect.defineMetadata(i,o,e,r):Reflect.defineMetadata(i,o,e)}))}var D={__proto__:[]}instanceof Array;function M(e){return function(t,r,i){var o="function"==typeof t?t:t.constructor;o.__decorators__||(o.__decorators__=[]),"number"!=typeof i&&(i=void 0),o.__decorators__.push((function(t){return e(t,r,i)}))}}function U(e){"undefined"!=typeof console&&console.warn("[vue-class-component] "+e)}function I(t,r){var i=r.prototype._init;r.prototype._init=function(){var e=this,r=Object.getOwnPropertyNames(t);if(t.$options.props)for(var i in t.$options.props)t.hasOwnProperty(i)||r.push(i);r.forEach((function(r){"_"!==r.charAt(0)&&Object.defineProperty(e,r,{get:function(){return t[r]},set:function(e){t[r]=e},configurable:!0})}))};var o=new r;r.prototype._init=i;var s={};return Object.keys(o).forEach((function(e){void 0!==o[e]&&(s[e]=o[e])})),"production"!==process.env.NODE_ENV&&!(r.prototype instanceof e)&&Object.keys(s).length>0&&U("Component class must inherit Vue or its descendant class when class property is used."),s}var C=["data","beforeCreate","created","beforeMount","mounted","beforeDestroy","destroyed","beforeUpdate","updated","activated","deactivated","render","errorCaptured","serverPrefetch"];function k(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};r.name=r.name||t._componentTag||t.name;var i=t.prototype;Object.getOwnPropertyNames(i).forEach((function(e){if("constructor"!==e)if(C.indexOf(e)>-1)r[e]=i[e];else{var t=Object.getOwnPropertyDescriptor(i,e);void 0!==t.value?"function"==typeof t.value?(r.methods||(r.methods={}))[e]=t.value:(r.mixins||(r.mixins=[])).push({data:function(){return P({},e,t.value)}}):(t.get||t.set)&&((r.computed||(r.computed={}))[e]={get:t.get,set:t.set})}})),(r.mixins||(r.mixins=[])).push({data:function(){return I(this,t)}});var o=t.__decorators__;o&&(o.forEach((function(e){return e(r)})),delete t.__decorators__);var s=Object.getPrototypeOf(t.prototype),a=s instanceof e?s.constructor:e,n=a.extend(r);return T(n,t,a),R()&&N(n,t),n}var L=["cid","super","options","superOptions","extendOptions","sealedOptions","component","directive","filter"],B={prototype:!0,arguments:!0,callee:!0,caller:!0};function T(e,t,r){Object.getOwnPropertyNames(t).forEach((function(i){if(!B[i]){var o=Object.getOwnPropertyDescriptor(e,i);if(!o||o.configurable){var s,a,n=Object.getOwnPropertyDescriptor(t,i);if(!D){if("cid"===i)return;var l=Object.getOwnPropertyDescriptor(r,i);if(s=n.value,a=_(s),null!=s&&("object"===a||"function"===a)&&l&&l.value===n.value)return}"production"!==process.env.NODE_ENV&&L.indexOf(i)>=0&&U("Static property name '".concat(i,"' declared on class '").concat(t.name,"' ")+"conflicts with reserved property name of Vue internal. It may cause unexpected behavior of the component. Consider renaming the property."),Object.defineProperty(e,i,n)}}}))}function W(e){return"function"==typeof e?k(e):function(t){return k(t,e)}}W.registerHooks=function(e){C.push.apply(C,F(e))};function G(e){return M((function(t,r){void 0===t.inject&&(t.inject={}),Array.isArray(t.inject)||(t.inject[r]=e||r)}))}function K(e){return M((function(t,r){var i,o=t.provide;("function"!=typeof(i=o)||!i.managed&&!i.managedReactive)&&(o=t.provide=function(e){var t=function(){var r=this,i="function"==typeof e?e.call(this):e;for(var o in(i=Object.create(i||null)).__reactiveInject__=this.__reactiveInject__||{},t.managed)i[t.managed[o]]=this[o];var s=function(e){i[t.managedReactive[e]]=a[e],Object.defineProperty(i.__reactiveInject__,t.managedReactive[e],{enumerable:!0,get:function(){return r[e]}})},a=this;for(var o in t.managedReactive)s(o);return i};return t.managed={},t.managedReactive={},t}(o)),o.managed[r]=e||r}))}var q="undefined"!=typeof Reflect&&void 0!==Reflect.getMetadata;function H(e,t,r){if(q&&!Array.isArray(e)&&"function"!=typeof e&&void 0===e.type){var i=Reflect.getMetadata("design:type",t,r);i!==Object&&(e.type=i)}}function Y(e,t){return void 0===t&&(t={}),function(r,i){H(t,r,i),M((function(r,i){(r.props||(r.props={}))[i]=t,r.model={prop:i,event:e||i}}))(r,i)}}function z(e){return void 0===e&&(e={}),function(t,r){H(e,t,r),M((function(t,r){(t.props||(t.props={}))[r]=e}))(t,r)}}function Z(e,t){void 0===t&&(t={});var r=t.deep,i=void 0!==r&&r,o=t.immediate,s=void 0!==o&&o;return M((function(t,r){"object"!=typeof t.watch&&(t.watch=Object.create(null));var o=t.watch;"object"!=typeof o[e]||Array.isArray(o[e])?void 0===o[e]&&(o[e]=[]):o[e]=[o[e]],o[e].push({handler:r,deep:i,immediate:s})}))}class J{constructor(e){this.registry=new Map,this.ctx=e}add(e,t){this.registry.set(e,t)}remove(e){this.registry.delete(e);const t=this.ctx.proxy,r=e,i=(t[r],$(t,["symbol"==typeof r?r:r+""]));this.ctx.proxy=i}has(e){return this.registry.has(e)}hasNested(e){for(const t of this.registry.keys())if(t===e||t.includes(e+"."))return!0;return!1}get(e){return this.registry.get(e)}getNested(e){const t=new Map;for(const r of this.registry.keys())(r===e||r.includes(e+"."))&&t.set(r,this.registry.get(r));return t}map(e){const t={};return this.registry.forEach((r,i)=>Object.assign(t,{[i]:e(r,i)})),t}forEach(e){this.registry.forEach((t,r)=>{e(t,r)})}keys(){return Array.from(this.registry.keys())}register(e,t){if(this.registry.has(e))return;this.registry.set(e,t);const r=y(t.$options.propsData,"formularioValue"),i=y(t.$options.propsData,"value");!r&&this.ctx.hasInitialValue&&void 0!==v(this.ctx.initialValues,e)?t.context.model=v(this.ctx.initialValues,e):!r&&!i||h(t.proxy,v(this.ctx.initialValues,e))||this.ctx.setFieldValue(e,t.proxy),this.ctx.childrenShouldShowErrors&&(t.formShouldShowErrors=!0)}reduce(e,t){return this.registry.forEach((r,i)=>{t=e(t,r,i)}),t}}class X{constructor(e){this.form=e}hasValidationErrors(){return this.form.hasValidationErrors()}values(){return new Promise((e,t)=>{const r=this.form,i=[],o=function e(t){if("object"!=typeof t)return t;const r=Array.isArray(t)?[]:{};for(const i in t)Object.prototype.hasOwnProperty.call(t,i)&&(g(t[i])||t[i]instanceof d?r[i]=t[i]:r[i]=e(t[i]));return r}(r.proxy);for(const e in o)Object.prototype.hasOwnProperty.call(o,e)&&"object"==typeof r.proxy[e]&&r.proxy[e]instanceof d&&i.push(r.proxy[e].upload().then(t=>Object.assign(o,{[e]:t})));Promise.all(i).then(()=>e(o)).catch(e=>t(e))})}}let Q=class extends e{constructor(){super(...arguments),this.formularioRegister=this.register,this.formularioDeregister=this.deregister,this.formularioSetter=this.setFieldValue,this.getFormValues=()=>this.proxy,this.path="",this.proxy={},this.registry=new J(this),this.childrenShouldShowErrors=!1,this.formShouldShowErrors=!1,this.errorObservers=[],this.namedErrors=[],this.namedFieldErrors={}}formularioFieldValidation(e){this.$emit("validation",e)}removeErrorObserver(e){this.errorObservers=this.errorObservers.filter(t=>t.callback!==e)}get mergedFormErrors(){return this.formErrors.concat(this.namedErrors)}get mergedFieldErrors(){const e={};if(this.errors)for(const t in this.errors)e[t]=f(this.errors[t]);for(const t in this.namedFieldErrors)e[t]=f(this.namedFieldErrors[t]);return e}get hasFormErrorObservers(){return this.errorObservers.some(e=>"form"===e.type)}get hasInitialValue(){return this.formularioValue&&"object"==typeof this.formularioValue||this.values&&"object"==typeof this.values||this.isGrouping&&"object"==typeof this.context.model[this.index]}get isVmodeled(){return!!(y(this.$options.propsData,"formularioValue")&&this._events&&Array.isArray(this._events.input)&&this._events.input.length)}get initialValues(){return y(this.$options.propsData,"formularioValue")&&"object"==typeof this.formularioValue?Object.assign({},this.formularioValue):y(this.$options.propsData,"values")&&"object"==typeof this.values?Object.assign({},this.values):this.isGrouping&&"object"==typeof this.context.model[this.index]?this.context.model[this.index]:{}}onFormularioValueChanged(e){this.isVmodeled&&e&&"object"==typeof e&&this.setValues(e)}onMergedFormErrorsChanged(e){this.errorObservers.filter(e=>"form"===e.type).forEach(t=>t.callback(e))}onMergedFieldErrorsChanged(e){this.errorObservers.filter(e=>"input"===e.type).forEach(t=>t.callback(e[t.field]||[]))}created(){this.$formulario.register(this),this.applyInitialValues()}destroyed(){this.$formulario.deregister(this)}register(e,t){this.registry.register(e,t)}deregister(e){this.registry.remove(e)}applyErrors({formErrors:e,inputErrors:t}){this.namedErrors=e,this.namedFieldErrors=t}addErrorObserver(e){this.errorObservers.find(t=>e.callback===t.callback)||(this.errorObservers.push(e),"form"===e.type?e.callback(this.mergedFormErrors):y(this.mergedFieldErrors,e.field)&&e.callback(this.mergedFieldErrors[e.field]))}registerErrorComponent(e){this.errorComponents.includes(e)||this.errorComponents.push(e)}formSubmitted(){this.showErrors();const e=new X(this);return this.$emit("submit-raw",e),e.hasValidationErrors().then(t=>t?void 0:e.values()).then(e=>{if(void 0!==e)return this.$emit("submit",e),e})}applyInitialValues(){this.hasInitialValue&&(this.proxy=this.initialValues)}setFieldValue(e,t){if(void 0===t){const t=this.proxy,r=e,i=(t[r],$(t,["symbol"==typeof r?r:r+""]));this.proxy=i}else!function(e,t,r){const i=t.split(".");let o=e;for(let e=0;e<i.length;e++){const t=i[e],s=t.match(/(.+)\[(\d+)\]$/);if(s){if(void 0===o[s[1]]&&(o[s[1]]=[]),o=o[s[1]],e===i.length-1){o[s[2]]=r;break}o=o[s[2]]}else{if(e===i.length-1){o[t]=r;break}void 0===o[t]&&(o[t]={}),o=o[t]}}}(this.proxy,e,t);this.$emit("input",Object.assign({},this.proxy))}hasValidationErrors(){return Promise.all(this.registry.reduce((e,t)=>(e.push(t.performValidation()&&t.getValidationErrors()),e),[])).then(e=>e.some(e=>e.hasErrors))}showErrors(){this.childrenShouldShowErrors=!0,this.registry.forEach(e=>{e.formShouldShowErrors=!0})}hideErrors(){this.childrenShouldShowErrors=!1,this.registry.forEach(e=>{e.formShouldShowErrors=!1,e.behavioralErrorVisibility=!1})}setValues(e){Array.from(new Set(Object.keys(e).concat(Object.keys(this.proxy)))).forEach(t=>{this.registry.hasNested(t)&&this.registry.getNested(t).forEach((t,r)=>{h(v(e,r),v(this.proxy,r))||this.setFieldValue(r,v(e,r)),h(v(e,r),this.registry.get(r).proxy)||(this.registry.get(r).context.model=v(e,r))})}),this.applyInitialValues()}};function ee(e,t,r,i,o,s,a,n,l,u){"boolean"!=typeof a&&(l=n,n=a,a=!1);const d="function"==typeof r?r.options:r;let h;if(e&&e.render&&(d.render=e.render,d.staticRenderFns=e.staticRenderFns,d._compiled=!0,o&&(d.functional=!0)),i&&(d._scopeId=i),s?(h=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),t&&t.call(this,l(e)),e&&e._registeredComponents&&e._registeredComponents.add(s)},d._ssrRegister=h):t&&(h=a?function(e){t.call(this,u(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,n(e))}),h)if(d.functional){const e=d.render;d.render=function(t,r){return h.call(r),e(t,r)}}else{const e=d.beforeCreate;d.beforeCreate=e?[].concat(e,h):[h]}return r}A([K()],Q.prototype,"formularioFieldValidation",null),A([K()],Q.prototype,"formularioRegister",void 0),A([K()],Q.prototype,"formularioDeregister",void 0),A([K()],Q.prototype,"formularioSetter",void 0),A([K()],Q.prototype,"getFormValues",void 0),A([K()],Q.prototype,"path",void 0),A([K()],Q.prototype,"removeErrorObserver",null),A([Y("input",{type:Object,default:()=>({})})],Q.prototype,"formularioValue",void 0),A([z({type:[String,Boolean],default:!1})],Q.prototype,"name",void 0),A([z({type:[Object,Boolean],default:!1})],Q.prototype,"values",void 0),A([z({default:!1})],Q.prototype,"errors",void 0),A([z({default:()=>[]})],Q.prototype,"formErrors",void 0),A([Z("formularioValue",{deep:!0})],Q.prototype,"onFormularioValueChanged",null),A([Z("mergedFormErrors")],Q.prototype,"onMergedFormErrorsChanged",null),A([Z("mergedFieldErrors",{immediate:!0})],Q.prototype,"onMergedFieldErrorsChanged",null),A([K()],Q.prototype,"addErrorObserver",null),Q=A([W],Q);const te=Q;var re=function(){var e=this,t=e.$createElement;return(e._self._c||t)("form",{on:{submit:function(t){return t.preventDefault(),e.formSubmitted(t)}}},[e._t("default",null,{errors:e.mergedFormErrors})],2)};re._withStripped=!0;const ie=ee({render:re,staticRenderFns:[]},void 0,te,void 0,!1,void 0,!1,void 0,void 0,void 0),oe={BLUR:"blur",LIVE:"live",SUBMIT:"submit"};let se=class extends e{constructor(){super(...arguments),this.formularioRegisterRule=this.registerRule,this.formularioRemoveRule=this.removeRule,this.defaultId=this.$formulario.nextId(this),this.localAttributes={},this.localErrors=[],this.proxy=this.getInitialValue(),this.behavioralErrorVisibility="live"===this.errorBehavior,this.formShouldShowErrors=!1,this.validationErrors=[],this.pendingValidation=Promise.resolve(),this.ruleRegistry=[],this.messageRegistry={}}get context(){return this.defineModel({id:this.id||this.defaultId,name:this.nameOrFallback,attributes:this.elementAttributes,blurHandler:this.blurHandler.bind(this),disableErrors:this.disableErrors,errors:this.explicitErrors,allErrors:this.allErrors,formShouldShowErrors:this.formShouldShowErrors,getValidationErrors:this.getValidationErrors.bind(this),hasGivenName:this.hasGivenName,hasValidationErrors:this.hasValidationErrors.bind(this),imageBehavior:this.imageBehavior,performValidation:this.performValidation.bind(this),preventWindowDrops:this.preventWindowDrops,setErrors:this.setErrors.bind(this),showValidationErrors:this.showValidationErrors,uploadBehavior:this.uploadBehavior,uploadUrl:this.mergedUploadUrl,uploader:this.uploader||this.$formulario.getUploader(),validationErrors:this.validationErrors,value:this.value,visibleValidationErrors:this.visibleValidationErrors})}get parsedValidationRules(){const e={};return Object.keys(this.validationRules).forEach(t=>{e[p(t)]=this.validationRules[t]}),e}get messages(){const e={};return Object.keys(this.validationMessages).forEach(t=>{e[p(t)]=this.validationMessages[t]}),Object.keys(this.messageRegistry).forEach(t=>{e[p(t)]=this.messageRegistry[t]}),e}get elementAttributes(){const e=Object.assign({},this.localAttributes);return this.id?e.id=this.id:e.id=this.defaultId,this.hasGivenName&&(e.name=this.name),this.help&&(e["aria-describedby"]=e.id+"-help"),e}get nameOrFallback(){return""!==this.path?`${this.path}.${this.name}`:this.name}get hasGivenName(){return"boolean"!=typeof this.name}get mergedValidationName(){return this.validationName||this.name}get mergedUploadUrl(){return this.uploadUrl||this.$formulario.getUploadUrl()}get hasErrors(){return this.allErrors.length>0}get hasVisibleErrors(){return this.validationErrors&&this.showValidationErrors||!!this.explicitErrors.length}get allErrors(){return[...this.explicitErrors,...f(this.validationErrors)]}get visibleValidationErrors(){return this.showValidationErrors&&this.validationErrors.length?this.validationErrors:[]}get explicitErrors(){return[...f(this.errors),...this.localErrors].map(e=>({rule:null,context:null,message:e}))}get isVmodeled(){return!!(Object.prototype.hasOwnProperty.call(this.$options.propsData,"formularioValue")&&this._events&&Array.isArray(this._events.input)&&this._events.input.length)}get showValidationErrors(){return this.showErrors||this.formShouldShowErrors||this.behavioralErrorVisibility}onAttrsChanged(e){this.updateLocalAttributes(e)}onProxyChanged(e,t){this.performValidation(),this.isVmodeled||h(e,t)||(this.context.model=e)}onFormularioValueChanged(e,t){this.isVmodeled&&!h(e,t)&&(this.context.model=e)}onShowValidationErrorsChanged(e){this.$emit("error-visibility",e)}created(){this.applyInitialValue(),this.formularioRegister&&"function"==typeof this.formularioRegister&&this.formularioRegister(this.nameOrFallback,this),this.disableErrors||"function"!=typeof this.addErrorObserver||this.addErrorObserver({callback:this.setErrors,type:"input",field:this.nameOrFallback}),this.updateLocalAttributes(this.$attrs),this.errorBehavior===oe.LIVE&&this.performValidation()}beforeDestroy(){this.disableErrors||"function"!=typeof this.removeErrorObserver||this.removeErrorObserver(this.setErrors),"function"==typeof this.formularioDeregister&&this.formularioDeregister(this.nameOrFallback)}defineModel(e){return Object.defineProperty(e,"model",{get:this.modelGetter.bind(this),set:this.modelSetter.bind(this)})}modelGetter(){const e=this.isVmodeled?"formularioValue":"proxy";return void 0===this[e]?"":this[e]}modelSetter(e){h(e,this.proxy)||(this.proxy=e),this.$emit("input",e),this.context.name&&"function"==typeof this.formularioSetter&&this.formularioSetter(this.context.name,e)}blurHandler(){this.$emit("blur"),"blur"===this.errorBehavior&&(this.behavioralErrorVisibility=!0)}getInitialValue(){return y(this.$options.propsData,"value")?this.value:y(this.$options.propsData,"formularioValue")?this.formularioValue:""}applyInitialValue(){h(this.context.model,this.proxy)||(this.context.model=this.proxy)}updateLocalAttributes(e){h(e,this.localAttributes)||(this.localAttributes=e)}performValidation(){let e=m(this.validation,this.$formulario.rules(this.parsedValidationRules));return e=this.ruleRegistry.length?this.ruleRegistry.concat(e):e,this.pendingValidation=this.runRules(e).then(e=>this.didValidate(e)),this.pendingValidation}runRules(e){const t=([e,t,r])=>{let i=e({value:this.context.model,getFormValues:this.getFormValues.bind(this),name:this.context.name},...t);return i=i instanceof Promise?i:Promise.resolve(i),i.then(e=>!e&&this.getMessageObject(r,t))};return new Promise(r=>{const i=(e,o=[])=>{const s=e.shift();Array.isArray(s)&&s.length?Promise.all(s.map(t)).then(e=>e.filter(e=>!!e)).then(t=>(t=Array.isArray(t)?t:[]).length&&s.bail||!e.length?r(o.concat(t)):i(e,o.concat(t))):r([])};i(function(e){const t=[],r=e.findIndex(([,,e])=>"bail"===e.toLowerCase());if(r>=0){const i=e.splice(0,r+1).slice(0,-1);i.length&&t.push(i),e.map(e=>t.push(Object.defineProperty([e],"bail",{value:!0})))}else t.push(e);return t.reduce((e,t)=>{const r=(e,t=!1)=>{if(e.length<2)return Object.defineProperty([e],"bail",{value:t});const i=[],o=e.findIndex(([,,,e])=>"^"===e);if(o>=0){const s=e.splice(0,o);s.length&&i.push(...r(s,t)),i.push(Object.defineProperty([e.shift()],"bail",{value:!0})),e.length&&i.push(...r(e,t))}else i.push(e);return i};return e.concat(r(t))},[])}(e))})}didValidate(e){const t=!h(e,this.validationErrors);if(this.validationErrors=e,t){const e=this.getErrorObject();this.$emit("validation",e),this.formularioFieldValidation&&"function"==typeof this.formularioFieldValidation&&this.formularioFieldValidation(e)}}getMessageObject(e,t){const r={args:t,name:this.mergedValidationName,value:this.context.model,vm:this,formValues:this.getFormValues()};return{rule:e,context:r,message:this.getMessageFunc(e)(r)}}getMessageFunc(e){if(e=p(e),this.messages&&void 0!==this.messages[e])switch(typeof this.messages[e]){case"function":return this.messages[e];case"string":case"boolean":return()=>this.messages[e]}return t=>this.$formulario.validationMessage(e,t,this)}hasValidationErrors(){return new Promise(e=>{this.$nextTick(()=>{this.pendingValidation.then(()=>e(!!this.validationErrors.length))})})}getValidationErrors(){return new Promise(e=>{this.$nextTick(()=>this.pendingValidation.then(()=>e(this.getErrorObject())))})}getErrorObject(){return{name:this.context.nameOrFallback||this.context.name,errors:this.validationErrors.filter(e=>"object"==typeof e),hasErrors:!!this.validationErrors.length}}setErrors(e){this.localErrors=f(e)}registerRule(e,t,r,i=null){this.ruleRegistry.some(e=>e[2]===r)||(this.ruleRegistry.push([e,t,r]),null!==i&&(this.messageRegistry[r]=i))}removeRule(e){const t=this.ruleRegistry.findIndex(t=>t[2]===e);t>=0&&(this.ruleRegistry.splice(t,1),delete this.messageRegistry[e])}};A([G({default:void 0})],se.prototype,"formularioSetter",void 0),A([G({default:()=>()=>{}})],se.prototype,"formularioFieldValidation",void 0),A([G({default:void 0})],se.prototype,"formularioRegister",void 0),A([G({default:void 0})],se.prototype,"formularioDeregister",void 0),A([G({default:()=>()=>({})})],se.prototype,"getFormValues",void 0),A([G({default:void 0})],se.prototype,"addErrorObserver",void 0),A([G({default:void 0})],se.prototype,"removeErrorObserver",void 0),A([G({default:""})],se.prototype,"path",void 0),A([K()],se.prototype,"formularioRegisterRule",void 0),A([K()],se.prototype,"formularioRemoveRule",void 0),A([Y("input",{default:""})],se.prototype,"formularioValue",void 0),A([z({type:[String,Number,Boolean],default:!1})],se.prototype,"id",void 0),A([z({default:"text"})],se.prototype,"type",void 0),A([z({required:!0})],se.prototype,"name",void 0),A([z({default:!1})],se.prototype,"value",void 0),A([z({type:[String,Boolean,Array],default:!1})],se.prototype,"validation",void 0),A([z({type:[String,Boolean],default:!1})],se.prototype,"validationName",void 0),A([z({type:Object,default:()=>({})})],se.prototype,"validationRules",void 0),A([z({type:Object,default:()=>({})})],se.prototype,"validationMessages",void 0),A([z({type:[Array,String,Boolean],default:!1})],se.prototype,"errors",void 0),A([z({type:String,default:oe.BLUR,validator:e=>[oe.BLUR,oe.LIVE,oe.SUBMIT].includes(e)})],se.prototype,"errorBehavior",void 0),A([z({default:!1})],se.prototype,"showErrors",void 0),A([z({default:!1})],se.prototype,"disableErrors",void 0),A([z({default:!0})],se.prototype,"preventWindowDrops",void 0),A([z({default:"preview"})],se.prototype,"imageBehavior",void 0),A([z({default:!1})],se.prototype,"uploader",void 0),A([z({default:!1})],se.prototype,"uploadUrl",void 0),A([z({default:"live"})],se.prototype,"uploadBehavior",void 0),A([Z("$attrs",{deep:!0})],se.prototype,"onAttrsChanged",null),A([Z("proxy")],se.prototype,"onProxyChanged",null),A([Z("formularioValue")],se.prototype,"onFormularioValueChanged",null),A([Z("showValidationErrors",{immediate:!0})],se.prototype,"onShowValidationErrorsChanged",null),se=A([W({inheritAttrs:!1})],se);const ae=se;var ne=function(){var e=this,t=e.$createElement;return(e._self._c||t)("div",{staticClass:"formulario-input",attrs:{"data-has-errors":e.hasErrors,"data-is-showing-errors":e.hasVisibleErrors,"data-type":e.type}},[e._t("default",null,{id:e.id,context:e.context,errors:e.errors,validationErrors:e.validationErrors})],2)};ne._withStripped=!0;const le=ee({render:ne,staticRenderFns:[]},void 0,ae,void 0,!1,void 0,!1,void 0,void 0,void 0);let ue=class extends e{get groupPath(){return this.isArrayItem?`${this.path}[${this.name}]`:""===this.path?this.name:`${this.path}.${this.name}`}};A([G({default:""})],ue.prototype,"path",void 0),A([z({required:!0})],ue.prototype,"name",void 0),A([z({default:!1})],ue.prototype,"isArrayItem",void 0),A([K("path")],ue.prototype,"groupPath",null),ue=A([W],ue);const de=ue;var he=function(){var e=this.$createElement;return(this._self._c||e)("div",{staticClass:"formulario-group",attrs:{"data-type":"group"}},[this._t("default")],2)};he._withStripped=!0;const pe=ee({render:he,staticRenderFns:[]},void 0,de,void 0,!1,void 0,!1,void 0,void 0,void 0);return new class{constructor(){this.options={},this.defaults={components:{FormularioForm:ie,FormularioInput:le,FormularioGrouping:pe},library:r,rules:b,mimes:E,locale:!1,uploader:w,uploadUrl:!1,fileUrlKey:"url",uploadJustCompleteDuration:1e3,errorHandler:e=>e,plugins:[x],validationMessages:{},idPrefix:"formulario-"},this.registry=new Map,this.idRegistry={}}install(e,t){e.prototype.$formulario=this,this.options=this.defaults;let r=this.defaults.plugins;t&&Array.isArray(t.plugins)&&t.plugins.length&&(r=r.concat(t.plugins)),r.forEach(e=>"function"==typeof e?e(this):null),this.extend(t||{});for(const t in this.options.components)Object.prototype.hasOwnProperty.call(this.options.components,t)&&e.component(t,this.options.components[t])}nextId(e){const t=this.options,r=!(!e.$route||!e.$route.path)&&e.$route.path?e.$route.path.replace(/[/\\.\s]/g,"-"):"global";return y(this.idRegistry,r)||(this.idRegistry[r]=0),`${t.idPrefix}${r}-${++this.idRegistry[r]}`}extend(e){if("object"==typeof e)return this.options=function e(t,r,i=!0){const o={};for(const s in t)y(r,s)?j(r[s])&&j(t[s])?o[s]=e(t[s],r[s],i):i&&Array.isArray(t[s])&&Array.isArray(r[s])?o[s]=t[s].concat(r[s]):o[s]=r[s]:o[s]=t[s];for(const e in r)y(o,e)||(o[e]=r[e]);return o}(this.options,e),this;throw new Error(`VueFormulario extend() should be passed an object (was ${typeof e})`)}rules(e={}){return Object.assign(Object.assign({},this.options.rules),e)}validationMessage(e,t,r){return y(this.options.validationMessages,e)?this.options.validationMessages[e](r,t):this.options.validationMessages.default(r,t)}register(e){"FormularioForm"===e.$options.name&&e.name&&this.registry.set(e.name,e)}deregister(e){"FormularioForm"===e.$options.name&&e.name&&this.registry.has(e.name)&&this.registry.delete(e.name)}handle(e,t,r=!1){const i=r?e:this.options.errorHandler(e,t);if(t&&this.registry.has(t)){this.registry.get(t).applyErrors({formErrors:f(i.formErrors),inputErrors:i.inputErrors||{}})}return i}reset(e,t={}){this.resetValidation(e),this.setValues(e,t)}resetValidation(e){const t=this.registry.get(e);t.hideErrors(e),t.namedErrors=[],t.namedFieldErrors={}}setValues(e,t){if(t){this.registry.get(e).setValues(Object.assign({},t))}}getUploader(){return this.options.uploader||!1}getUploadUrl(){return this.options.uploadUrl||!1}getFileUrlKey(){return this.options.fileUrlKey||"url"}createUpload(e,t){return new d(e,t,this.options)}}}(Vue);