From 9488c8e8fd16d0f198b6269321df4afcef5bd162 Mon Sep 17 00:00:00 2001 From: 1on Date: Mon, 19 Oct 2020 14:38:35 +0300 Subject: [PATCH] 0.1.0 --- dist/formulario.esm.js | 17 ++++++++++++++++- dist/formulario.min.js | 24 ++++++++++++++++++++++-- dist/formulario.umd.js | 17 ++++++++++++++++- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/dist/formulario.esm.js b/dist/formulario.esm.js index 5f466db..b48e016 100644 --- a/dist/formulario.esm.js +++ b/dist/formulario.esm.js @@ -1 +1,16 @@ -import t from"is-url";import r from"nanoid/non-secure";import e from"is-plain-object";var i=function(t,r){return{classification:t,component:"FormularioInput"+(r||t[0].toUpperCase()+t.substr(1))}},o=Object.assign({},["text","email","number","color","date","hidden","month","password","search","tel","time","url","week","datetime-local"].reduce((function(t,r){var e;return Object.assign({},t,((e={})[r]=i("text"),e))}),{}),{range:i("slider"),textarea:i("textarea","TextArea"),checkbox:i("box"),radio:i("box"),submit:i("button"),button:i("button"),select:i("select"),file:i("file"),image:i("file"),group:i("group")}),n=function(t,r,e){void 0===e&&(e={}),this.input=t,this.fileList=t.files,this.files=[],this.options=Object.assign({},{mimes:{}},e),this.results=!1,this.context=r,Array.isArray(this.fileList)?this.rehydrateFileList(this.fileList):this.addFileList(this.fileList)};function s(t,r){if(t===r)return!0;if(!t||!r)return!1;var e=Object.keys(t),i=Object.keys(r),o=e.length;if(i.length!==o)return!1;if(t instanceof Date&&r instanceof Date)return t.getTime()===r.getTime();if(0===o)return t===r;for(var n=0;n=100&&(r.complete||(r.justFinished=!0,setTimeout((function(){r.justFinished=!1}),t.options.uploadJustCompleteDuration)),r.complete=!0)}),(function(t){r.progress=0,r.error=t,r.complete=!0}),t.options)}))).then((function(e){t.results=e,r(e)})).catch((function(t){throw new Error(t)}))}))},n.prototype.removeFile=function(t){if(this.files=this.files.filter((function(r){return r.uuid!==t})),this.context.performValidation(),window&&this.fileList instanceof FileList){var r=new DataTransfer;this.files.map((function(t){return r.items.add(t.file)})),this.fileList=r.files,this.input.files=this.fileList}},n.prototype.loadPreviews=function(){this.files.map((function(t){if(!t.previewData&&window&&window.FileReader&&/^image\//.test(t.file.type)){var r=new FileReader;r.onload=function(r){return Object.assign(t,{previewData:r.target.result})},r.readAsDataURL(t.file)}}))},n.prototype.getFileList=function(){return this.fileList},n.prototype.getFiles=function(){return this.files},n.prototype.toString=function(){var t=this.files.length?this.files.length+" files":"empty";return this.results?JSON.stringify(this.results,null," "):"FileUpload("+t+")"};var p={accepted:function(t){var r=t.value;return Promise.resolve(["yes","on","1",1,!0,"true"].includes(r))},after:function(t,r){var e=t.value;void 0===r&&(r=!1);var i=Date.parse(r||new Date),o=Date.parse(e);return Promise.resolve(!isNaN(o)&&o>i)},alpha:function(t,r){var e=t.value;void 0===r&&(r="default");var i={default:/^[a-zA-ZÀ-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z]+$/},o=i.hasOwnProperty(r)?r:"default";return Promise.resolve(i[o].test(e))},alphanumeric:function(t,r){var e=t.value;void 0===r&&(r="default");var i={default:/^[a-zA-Z0-9À-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z0-9]+$/},o=i.hasOwnProperty(r)?r:"default";return Promise.resolve(i[o].test(e))},before:function(t,r){var e=t.value;void 0===r&&(r=!1);var i=Date.parse(r||new Date),o=Date.parse(e);return Promise.resolve(!isNaN(o)&&or&&or&&o.length()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i.test(r))},endsWith:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return r?Promise.resolve("string"==typeof r&&e.length?void 0!==e.find((function(t){return r.endsWith(t)})):"string"==typeof r&&0===e.length):Promise.resolve((function(){return!0}))},in:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(void 0!==e.find((function(t){return"object"==typeof t?s(t,r):t===r})))},matches:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(!!e.find((function(t){return"string"==typeof t&&"/"===t.substr(0,1)&&"/"===t.substr(-1)&&(t=new RegExp(t.substr(1,t.length-2))),t instanceof RegExp?t.test(r):t===r})))},mime:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(function(){if(r instanceof n)for(var t=r.getFiles(),i=0;i=r):!isNaN(i)&&"length"!==e||"value"===e?(i=isNaN(i)?i:Number(i))>=r:("string"==typeof i||"length"===e)&&(i=isNaN(i)?i:i.toString()).length>=r)},max:function(t,r,e){var i=t.value;return void 0===r&&(r=10),Promise.resolve(Array.isArray(i)?(r=isNaN(r)?r:Number(r),i.length<=r):!isNaN(i)&&"length"!==e||"value"===e?(i=isNaN(i)?i:Number(i))<=r:("string"==typeof i||"length"===e)&&(i=isNaN(i)?i:i.toString()).length<=r)},not:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(void 0===e.find((function(t){return"object"==typeof t?s(t,r):t===r})))},number:function(t){var r=t.value;return Promise.resolve(!isNaN(r))},required:function(t,r){var e=t.value;return void 0===r&&(r=!0),Promise.resolve(!(r&&!["no","false"].includes(r))||(Array.isArray(e)?!!e.length:e instanceof n?e.getFiles().length>0:"string"==typeof e?!!e:"object"!=typeof e||!!e&&!!Object.keys(e).length))},startsWith:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return r?Promise.resolve("string"==typeof r&&e.length?void 0!==e.find((function(t){return r.startsWith(t)})):"string"==typeof r&&0===e.length):Promise.resolve((function(){return!0}))},url:function(r){var e=r.value;return Promise.resolve(t(e))},bail:function(){return Promise.resolve(!0)}},m="image/",v={csv:"text/csv",gif:m+"gif",jpg:m+"jpeg",jpeg:m+"jpeg",png:m+"png",pdf:"application/pdf",svg:m+"svg+xml"},g={default:function(t,r){return t.$t("validation.default",r)},accepted:function(t,r){return t.$t("validation.accepted",r)},after:function(t,r){return Array.isArray(r.args)&&r.args.length?(r.compare=r.args[0],t.$t("validation.after.compare",r)):t.$t("validation.after.default",r)},alpha:function(t,r){return t.$t("validation.alpha",r)},alphanumeric:function(t,r){return t.$t("validation.alphanumeric",r)},before:function(t,r){return Array.isArray(r.args)&&r.args.length?(r.compare=r.args[0],t.$t("validation.before.compare",r)):t.$t("validation.before.default",r)},between:function(t,r){r.from=r.args[0],r.to=r.args[1];var e=!(!Array.isArray(r.args)||!r.args[2])&&r.args[2];return!isNaN(value)&&"length"!==e||"value"===e?t.$t("validation.between.force",r):t.$t("validation.between.default",r)},confirm:function(t,r){return t.$t("validation.confirm",r)},date:function(t,r){return Array.isArray(r.args)&&r.args.length?(r.format=r.args[0],t.$t("validation.date.format",r)):t.$t("validation.date.default",r)},email:function(t,r){return t.$t("validation.email.default",r)},endsWith:function(t,r){return t.$t("validation.endsWith.default",r)},in:function(t,r){return"string"==typeof r.value&&r.value?t.$t("validation.in.string",r):t.$t("validation.in.default",r)},matches:function(t,r){return t.$t("validation.matches.default",r)},max:function(t,r){if(r.maximum=r.args[0],Array.isArray(r.value))return t.$tc("validation.max.array",r.maximum,r);var e=!(!Array.isArray(r.args)||!r.args[1])&&r.args[1];return!isNaN(r.value)&&"length"!==e||"value"===e?t.$tc("validation.max.force",r.maximum,r):t.$tc("validation.max.default",r.maximum,r)},mime:function(t,r){return r.types=r.args[0],r.types?t.$t("validation.mime.default",r):t.$t("validation.mime.no_formats_allowed",r)},min:function(t,r){if(r.minimum=r.args[0],Array.isArray(r.value))return t.$tc("validation.min.array",r.minimum,r);var e=!(!Array.isArray(r.args)||!r.args[1])&&r.args[1];return!isNaN(r.value)&&"length"!==e||"value"===e?t.$tc("validation.min.force",r.minimum,r):t.$tc("validation.min.default",r.minimum,r)},not:function(t,r){return t.$t("validation.not.default",r)},number:function(t,r){return t.$t("validation.number.default",r)},required:function(t,r){return t.$t("validation.required.default",r)},startsWith:function(t,r){return t.$t("validation.startsWith.default",r)},url:function(t,r){return t.$t("validation.url.default",r)}};function y(t){t.extend({validationMessages:g})}function b(t,r,e,i){return new Promise((function(e,o){var n=(i.fauxUploaderDuration||2e3)*(.5+Math.random()),s=performance.now(),a=function(){return setTimeout((function(){var i=performance.now()-s,o=Math.min(100,Math.round(i/n*100));if(r(o),o>=100)return e({url:"http://via.placeholder.com/350x150.png",name:t.name});a()}),20)};a()}))}function E(t,r){var e={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&-1===r.indexOf(i)&&(e[i]=t[i]);return e}var x=function(t){this.registry=new Map,this.ctx=t};x.prototype.add=function(t,r){return this.registry.set(t,r),this},x.prototype.remove=function(t){this.registry.delete(t);var r=this.ctx.proxy,e=(r[t],E(r,[String(t)]));return this.ctx.proxy=e,this},x.prototype.has=function(t){return this.registry.has(t)},x.prototype.get=function(t){return this.registry.get(t)},x.prototype.map=function(t){var r={};return this.registry.forEach((function(e,i){var o;return Object.assign(r,((o={})[i]=t(e,i),o))})),r},x.prototype.keys=function(){return Array.from(this.registry.keys())},x.prototype.register=function(t,r){if(this.registry.has(t))return!1;this.registry.set(t,r);var e=c(r.$options.propsData,"formularioValue"),i=c(r.$options.propsData,"value");!e&&this.ctx.hasInitialValue&&void 0!==d(this.ctx.initialValues,t)?r.context.model=d(this.ctx.initialValues,t):!e&&!i||s(r.proxy,d(this.ctx.initialValues,t))||this.ctx.setFieldValue(t,r.proxy),this.childrenShouldShowErrors&&(r.formShouldShowErrors=!0)},x.prototype.reduce=function(t,r){return this.registry.forEach((function(e,i){r=t(r,e,i)})),r},x.prototype.dataProps=function(){var t=this;return{proxy:{},registry:this,register:this.register.bind(this),deregister:function(r){return t.remove(r)},childrenShouldShowErrors:!1}};var V=function(t){this.form=t};function w(t,r,e,i,o,n,s,a,u,l){"boolean"!=typeof s&&(u=a,a=s,s=!1);var f,h="function"==typeof e?e.options:e;if(t&&t.render&&(h.render=t.render,h.staticRenderFns=t.staticRenderFns,h._compiled=!0,o&&(h.functional=!0)),i&&(h._scopeId=i),n?(f=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),r&&r.call(this,u(t)),t&&t._registeredComponents&&t._registeredComponents.add(n)},h._ssrRegister=f):r&&(f=s?function(t){r.call(this,l(t,this.$root.$options.shadowRoot))}:function(t){r.call(this,a(t))}),f)if(h.functional){var c=h.render;h.render=function(t,r){return f.call(r),c(t,r)}}else{var d=h.beforeCreate;h.beforeCreate=d?[].concat(d,f):[f]}return e}V.prototype.hasValidationErrors=function(){return this.form.hasValidationErrors()},V.prototype.values=function(){var t=this;return new Promise((function(r,e){var i=[],o=function t(r){if("object"!=typeof r)return r;var e=Array.isArray(r)?[]:{};for(var i in r)r[i]instanceof n||h(r[i])?e[i]=r[i]:e[i]=t(r[i]);return e}(t.form.proxy),s=function(r){"object"==typeof t.form.proxy[r]&&t.form.proxy[r]instanceof n&&i.push(t.form.proxy[r].upload().then((function(t){var e;return Object.assign(o,((e={})[r]=t,e))})))};for(var a in o)s(a);Promise.all(i).then((function(){return r(o)})).catch((function(t){return e(t)}))}))};var O={provide:function(){return Object.assign({},{formularioSetter:(t=this).setFieldValue,formularioRegister:t.register,formularioDeregister:t.deregister,getFormValues:t.getFormValues},{observeErrors:this.addErrorObserver,removeErrorObserver:this.removeErrorObserver,formularioFieldValidation:this.formularioFieldValidation,path:""});var t},name:"FormularioForm",model:{prop:"formularioValue",event:"input"},props:{name:{type:[String,Boolean],default:!1},formularioValue:{type:Object,default:function(){return{}}},values:{type:[Object,Boolean],default:!1},errors:{type:[Object,Boolean],default:!1},formErrors:{type:Array,default:function(){return[]}}},data:function(){return Object.assign({},new x(this).dataProps(),{formShouldShowErrors:!1,errorObservers:[],namedErrors:[],namedFieldErrors:{}})},computed:Object.assign({},{hasInitialValue:function(){return this.formularioValue&&"object"==typeof this.formularioValue||this.values&&"object"==typeof this.values||this.isGrouping&&"object"==typeof this.context.model[this.index]},isVmodeled:function(){return!!(this.$options.propsData.hasOwnProperty("formularioValue")&&this._events&&Array.isArray(this._events.input)&&this._events.input.length)},initialValues:function(){return c(this.$options.propsData,"formularioValue")&&"object"==typeof this.formularioValue?Object.assign({},this.formularioValue):c(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]:{}}},{classes:function(){var t={"formulario-form":!0};return this.name&&(t["formulario-form--"+this.name]=!0),t},mergedFormErrors:function(){return this.formErrors.concat(this.namedErrors)},mergedFieldErrors:function(){var t={};if(this.errors)for(var r in this.errors)t[r]=u(this.errors[r]);for(var e in this.namedFieldErrors)t[e]=u(this.namedFieldErrors[e]);return t},hasFormErrorObservers:function(){return!!this.errorObservers.filter((function(t){return"form"===t.type})).length}}),watch:{formularioValue:{handler:function(t){this.isVmodeled&&t&&"object"==typeof t&&this.setValues(t)},deep:!0},mergedFormErrors:function(t){this.errorObservers.filter((function(t){return"form"===t.type})).forEach((function(r){return r.callback(t)}))},mergedFieldErrors:{handler:function(t){this.errorObservers.filter((function(t){return"input"===t.type})).forEach((function(r){return r.callback(t[r.field]||[])}))},immediate:!0}},created:function(){this.$formulario.register(this),this.applyInitialValues()},destroyed:function(){this.$formulario.deregister(this)},methods:Object.assign({},function(t){void 0===t&&(t=[]);var r={applyInitialValues:function(){this.hasInitialValue&&(this.proxy=this.initialValues)},setFieldValue:function(t,r){if(void 0===r){var e=this.proxy,i=(e[t],E(e,[String(t)]));this.proxy=i}else!function(t,r,e){for(var i=r.split("."),o=t,n=0;n=0){var i=t.splice(0,e+1).slice(0,-1);i.length&&r.push(i),t.map((function(t){return r.push(Object.defineProperty([t],"bail",{value:!0}))}))}else r.push(t);return r.reduce((function(t,r){var e=function(t,r){if(void 0===r&&(r=!1),t.length<2)return Object.defineProperty([t],"bail",{value:r});var i=[],o=t.findIndex((function(t){return"^"===t[3]}));if(o>=0){var n=t.splice(0,o);n.length&&i.push.apply(i,e(n,r)),i.push(Object.defineProperty([t.shift()],"bail",{value:!0})),t.length&&i.push.apply(i,e(t,r))}else i.push(t);return i};return t.concat(e(r))}),[])}(t))}))},didValidate:function(t){var r=!s(t,this.validationErrors);if(this.validationErrors=t,r){var e=this.getErrorObject();this.$emit("validation",e),this.formularioFieldValidation&&"function"==typeof this.formularioFieldValidation&&this.formularioFieldValidation(e)}},getMessageObject:function(t,r){var e={args:r,name:this.mergedValidationName,value:this.context.model,vm:this,formValues:this.getFormValues()};return{message:this.getMessageFunc(t)(e),rule:t,context:e}},getMessageFunc:function(t){var r=this;if(t=a(t),this.messages&&void 0!==this.messages[t])switch(typeof this.messages[t]){case"function":return this.messages[t];case"string":case"boolean":return function(){return r.messages[t]}}return function(e){return r.$formulario.validationMessage(t,e,r)}},hasValidationErrors:function(){var t=this;return new Promise((function(r){t.$nextTick((function(){t.pendingValidation.then((function(){return r(!!t.validationErrors.length)}))}))}))},getValidationErrors:function(){var t=this;return new Promise((function(r){t.$nextTick((function(){return t.pendingValidation.then((function(){return r(t.getErrorObject())}))}))}))},getErrorObject:function(){return{name:this.context.nameOrFallback||this.context.name,errors:this.validationErrors.filter((function(t){return"object"==typeof t})),hasErrors:!!this.validationErrors.length}},setErrors:function(t){this.localErrors=u(t)},registerRule:function(t,r,e,i){void 0===i&&(i=null),this.ruleRegistry.some((function(t){return t[2]===e}))||(this.ruleRegistry.push([t,r,e]),null!==i&&(this.messageRegistry[e]=i))},removeRule:function(t){var r=this.ruleRegistry.findIndex((function(r){return r[2]===t}));r>=0&&(this.ruleRegistry.splice(r,1),delete this.messageRegistry[t])}}},_=function(){var t=this,r=t.$createElement;return(t._self._c||r)("div",{staticClass:"formulario-input",attrs:{"data-has-errors":t.hasErrors,"data-is-showing-errors":t.hasVisibleErrors,"data-type":t.type}},[t._t("default",null,{id:t.id,context:t.context,errors:t.errors,validationErrors:t.validationErrors})],2)};_._withStripped=!0;var D=w({render:_,staticRenderFns:[]},void 0,R,void 0,!1,void 0,!1,void 0,void 0,void 0),U={name:"FormularioGrouping",props:{name:{type:String,required:!0},isArrayItem:{type:Boolean,default:!1}},provide:function(){return{path:this.groupPath}},inject:["path"],computed:{groupPath:function(){return this.isArrayItem?this.path+"["+this.name+"]":""===this.path?this.name:this.path+"."+this.name}}},k=function(){var t=this.$createElement;return(this._self._c||t)("div",{staticClass:"formulario-group",attrs:{"data-type":"group"}},[this._t("default")],2)};k._withStripped=!0;var I=w({render:k,staticRenderFns:[]},void 0,U,void 0,!1,void 0,!1,void 0,void 0,void 0),B=function(){this.options={},this.defaults={components:{FormularioForm:F,FormularioInput:D,FormularioGrouping:I},library:o,rules:p,mimes:v,locale:!1,uploader:b,uploadUrl:!1,fileUrlKey:"url",uploadJustCompleteDuration:1e3,errorHandler:function(t){return t},plugins:[y],validationMessages:{},idPrefix:"formulario-"},this.registry=new Map,this.idRegistry={}};B.prototype.install=function(t,r){var e=this;t.prototype.$formulario=this,this.options=this.defaults;var i=this.defaults.plugins;for(var o in r&&Array.isArray(r.plugins)&&r.plugins.length&&(i=i.concat(r.plugins)),i.forEach((function(t){return"function"==typeof t?t(e):null})),this.extend(r||{}),this.options.components)t.component(o,this.options.components[o])},B.prototype.nextId=function(t){var r=!(!t.$route||!t.$route.path)&&t.$route.path?t.$route.path.replace(/[/\\.\s]/g,"-"):"global";return Object.prototype.hasOwnProperty.call(this.idRegistry,r)||(this.idRegistry[r]=0),""+this.options.idPrefix+r+"-"+ ++this.idRegistry[r]},B.prototype.extend=function(t){if("object"==typeof t)return this.options=this.merge(this.options,t),this;throw new Error("VueFormulario extend() should be passed an object (was "+typeof t+")")},B.prototype.merge=function(t,r,i){void 0===i&&(i=!0);var o={};for(var n in t)r.hasOwnProperty(n)?e(r[n])&&e(t[n])?o[n]=this.merge(t[n],r[n],i):i&&Array.isArray(t[n])&&Array.isArray(r[n])?o[n]=t[n].concat(r[n]):o[n]=r[n]:o[n]=t[n];for(var s in r)o.hasOwnProperty(s)||(o[s]=r[s]);return o},B.prototype.classify=function(t){return this.options.library.hasOwnProperty(t)?this.options.library[t].classification:"unknown"},B.prototype.component=function(t){return!!this.options.library.hasOwnProperty(t)&&this.options.library[t].component},B.prototype.rules=function(t){return void 0===t&&(t={}),Object.assign({},this.options.rules,t)},B.prototype.validationMessage=function(t,r,e){return this.options.validationMessages.hasOwnProperty(t)?this.options.validationMessages[t](e,r):this.options.validationMessages.default(e,r)},B.prototype.register=function(t){"FormularioForm"===t.$options.name&&t.name&&this.registry.set(t.name,t)},B.prototype.deregister=function(t){"FormularioForm"===t.$options.name&&t.name&&this.registry.has(t.name)&&this.registry.delete(t.name)},B.prototype.handle=function(t,r,e){void 0===e&&(e=!1);var i=e?t:this.options.errorHandler(t,r);return r&&this.registry.has(r)&&this.registry.get(r).applyErrors({formErrors:u(i.formErrors),inputErrors:i.inputErrors||{}}),i},B.prototype.reset=function(t,r){void 0===r&&(r={}),this.resetValidation(t),this.setValues(t,r)},B.prototype.resetValidation=function(t){var r=this.registry.get(t);r.hideErrors(t),r.namedErrors=[],r.namedFieldErrors={}},B.prototype.setValues=function(t,r){r&&!Array.isArray(r)&&"object"==typeof r&&this.registry.get(t).setValues(Object.assign({},r))},B.prototype.getUploader=function(){return this.options.uploader||!1},B.prototype.getUploadUrl=function(){return this.options.uploadUrl||!1},B.prototype.getFileUrlKey=function(){return this.options.fileUrlKey||"url"},B.prototype.createUpload=function(t,r){return new n(t,r,this.options)};var M=new B;export default M; +import e from"is-url";import t from"nanoid/non-secure";import r from"is-plain-object";import i from"vue";import{Provide as s,Model as o,Prop as a,Watch as n,Component as l,Inject as h}from"vue-property-decorator";const u=(e,t)=>({classification:e,component:"FormularioInput"+(t||e[0].toUpperCase()+e.substr(1))});var d=Object.assign(Object.assign({},["text","email","number","color","date","hidden","month","password","search","tel","time","url","week","datetime-local"].reduce((e,t)=>Object.assign(Object.assign({},e),{[t]:u("text")}),{})),{range:u("slider"),textarea:u("textarea","TextArea"),checkbox:u("box"),radio:u("box"),submit:u("button"),button:u("button"),select:u("select"),file:u("file"),image:u("file"),group:u("group")});class p{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),s=this.options.mimes[i]||!1;return e.push(Object.assign({},t,r?{name:r.substr(r.lastIndexOf("/")+1||0),type:t.type?t.type:s,previewData:r}:{})),e},[]);this.results=e,this.addFileList(t)}addFileList(e){for(let r=0;rthis.removeFile(s),previewData:i.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 c(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;i0!==e.indexOf(t)&&"_"!==e[e.indexOf(t)-1]?t.toUpperCase().replace("_",""):t):e}function m(e){return"string"==typeof e&&/^[\^]/.test(e.charAt(0))?[f(e.substr(1)),e.charAt(0)]:[f(e),null]}function g(e){return e?"string"==typeof e?[e]:Array.isArray(e)?e:"object"==typeof e?Object.values(e):[]:[]}function y(e,t){return"string"==typeof e?y(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]=m(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,s]=m(r.shift());if(Object.prototype.hasOwnProperty.call(t,i))return[t[i],r.length?r.join(":").split(","):[],i,s];throw new Error("Unknown validation rule "+e)}return!1}(e,t)).filter(e=>!!e):[]}function v(e){switch(typeof e){case"symbol":case"number":case"string":case"boolean":case"undefined":return!0;default:return null===e}}function b(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function E(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 x={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=b(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=b(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)&&iPromise.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&&et&&e.lengthPromise.resolve((()=>{const s=t();let o=i;return o||(o=/_confirm$/.test(r)?r.substr(0,r.length-8):r+"_confirm"),s[o]===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?c(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 p){const r=e.getFiles(),i=e=>t.includes(e.type),s=r.reduce((e,{file:t})=>e&&i(t),!0);return Promise.resolve(s)}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?c(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 p?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:t})=>Promise.resolve(e(t)),bail:()=>Promise.resolve(!0)},V={csv:"text/csv",gif:"image/gif",jpeg:"image/jpeg",jpg:"image/jpeg",png:"image/png",pdf:"application/pdf",svg:"image/svg+xml"};const w={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 O(e){e.extend({validationMessages:w})}function $(e,t,r,i){return new Promise(r=>{const s=(i.fauxUploaderDuration||2e3)*(.5+Math.random()),o=performance.now(),a=()=>setTimeout(()=>{const i=performance.now()-o,n=Math.min(100,Math.round(i/s*100));if(t(n),n>=100)return r({url:"http://via.placeholder.com/350x150.png",name:e.name});a()},20);a()})} +/*! ***************************************************************************** +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 F(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 s=0;for(i=Object.getOwnPropertySymbols(e);s=0;n--)(s=e[n])&&(a=(o<3?s(a):o>3?s(t,r,a):s(t,r))||a);return o>3&&a&&Object.defineProperty(t,r,a),a}class A{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],F(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=b(t.$options.propsData,"formularioValue"),i=b(t.$options.propsData,"value");!r&&this.ctx.hasInitialValue&&void 0!==E(this.ctx.initialValues,e)?t.context.model=E(this.ctx.initialValues,e):!r&&!i||c(t.proxy,E(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 N{constructor(e){this.form=e}hasValidationErrors(){return this.form.hasValidationErrors()}values(){return new Promise((e,t)=>{const r=this.form,i=[],s=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)&&(v(t[i])||t[i]instanceof p?r[i]=t[i]:r[i]=e(t[i]));return r}(r.proxy);for(const e in s)Object.prototype.hasOwnProperty.call(s,e)&&"object"==typeof r.proxy[e]&&r.proxy[e]instanceof p&&i.push(r.proxy[e].upload().then(t=>Object.assign(s,{[e]:t})));Promise.all(i).then(()=>e(s)).catch(e=>t(e))})}}let P=class extends i{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 A(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]=g(this.errors[t]);for(const t in this.namedFieldErrors)e[t]=g(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!!(b(this.$options.propsData,"formularioValue")&&this._events&&Array.isArray(this._events.input)&&this._events.input.length)}get initialValues(){return b(this.$options.propsData,"formularioValue")&&"object"==typeof this.formularioValue?Object.assign({},this.formularioValue):b(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):b(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 N(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],F(t,["symbol"==typeof r?r:r+""]));this.proxy=i}else!function(e,t,r){const i=t.split(".");let s=e;for(let e=0;e(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)=>{c(E(e,r),E(this.proxy,r))||this.setFieldValue(r,E(e,r)),c(E(e,r),this.registry.get(r).proxy)||(this.registry.get(r).context.model=E(e,r))})}),this.applyInitialValues()}};function R(e,t,r,i,s,o,a,n,l,h){"boolean"!=typeof a&&(l=n,n=a,a=!1);const u="function"==typeof r?r.options:r;let d;if(e&&e.render&&(u.render=e.render,u.staticRenderFns=e.staticRenderFns,u._compiled=!0,s&&(u.functional=!0)),i&&(u._scopeId=i),o?(d=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(o)},u._ssrRegister=d):t&&(d=a?function(e){t.call(this,h(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,n(e))}),d)if(u.functional){const e=u.render;u.render=function(t,r){return d.call(r),e(t,r)}}else{const e=u.beforeCreate;u.beforeCreate=e?[].concat(e,d):[d]}return r}j([s()],P.prototype,"formularioFieldValidation",null),j([s()],P.prototype,"formularioRegister",void 0),j([s()],P.prototype,"formularioDeregister",void 0),j([s()],P.prototype,"formularioSetter",void 0),j([s()],P.prototype,"getFormValues",void 0),j([s()],P.prototype,"path",void 0),j([s()],P.prototype,"removeErrorObserver",null),j([o("input",{type:Object,default:()=>({})})],P.prototype,"formularioValue",void 0),j([a({type:[String,Boolean],default:!1})],P.prototype,"name",void 0),j([a({type:[Object,Boolean],default:!1})],P.prototype,"values",void 0),j([a({default:!1})],P.prototype,"errors",void 0),j([a({default:()=>[]})],P.prototype,"formErrors",void 0),j([n("formularioValue",{deep:!0})],P.prototype,"onFormularioValueChanged",null),j([n("mergedFormErrors")],P.prototype,"onMergedFormErrorsChanged",null),j([n("mergedFieldErrors",{immediate:!0})],P.prototype,"onMergedFieldErrorsChanged",null),j([s()],P.prototype,"addErrorObserver",null),P=j([l],P);const S=P;var D=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)};D._withStripped=!0;const U=R({render:D,staticRenderFns:[]},void 0,S,void 0,!1,void 0,!1,void 0,void 0,void 0),_={BLUR:"blur",LIVE:"live",SUBMIT:"submit"};let k=class extends i{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[f(t)]=this.validationRules[t]}),e}get messages(){const e={};return Object.keys(this.validationMessages).forEach(t=>{e[f(t)]=this.validationMessages[t]}),Object.keys(this.messageRegistry).forEach(t=>{e[f(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,...g(this.validationErrors)]}get visibleValidationErrors(){return this.showValidationErrors&&this.validationErrors.length?this.validationErrors:[]}get explicitErrors(){return[...g(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||c(e,t)||(this.context.model=e)}onFormularioValueChanged(e,t){this.isVmodeled&&!c(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===_.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){c(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 b(this.$options.propsData,"value")?this.value:b(this.$options.propsData,"formularioValue")?this.formularioValue:""}applyInitialValue(){c(this.context.model,this.proxy)||(this.context.model=this.proxy)}updateLocalAttributes(e){c(e,this.localAttributes)||(this.localAttributes=e)}performValidation(){let e=y(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,s=[])=>{const o=e.shift();Array.isArray(o)&&o.length?Promise.all(o.map(t)).then(e=>e.filter(e=>!!e)).then(t=>(t=Array.isArray(t)?t:[]).length&&o.bail||!e.length?r(s.concat(t)):i(e,s.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=[],s=e.findIndex(([,,,e])=>"^"===e);if(s>=0){const o=e.splice(0,s);o.length&&i.push(...r(o,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=!c(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=f(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=g(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])}};j([h({default:void 0})],k.prototype,"formularioSetter",void 0),j([h({default:()=>()=>{}})],k.prototype,"formularioFieldValidation",void 0),j([h({default:void 0})],k.prototype,"formularioRegister",void 0),j([h({default:void 0})],k.prototype,"formularioDeregister",void 0),j([h({default:()=>()=>({})})],k.prototype,"getFormValues",void 0),j([h({default:void 0})],k.prototype,"addErrorObserver",void 0),j([h({default:void 0})],k.prototype,"removeErrorObserver",void 0),j([h({default:""})],k.prototype,"path",void 0),j([s()],k.prototype,"formularioRegisterRule",void 0),j([s()],k.prototype,"formularioRemoveRule",void 0),j([o("input",{default:""})],k.prototype,"formularioValue",void 0),j([a({type:[String,Number,Boolean],default:!1})],k.prototype,"id",void 0),j([a({default:"text"})],k.prototype,"type",void 0),j([a({required:!0})],k.prototype,"name",void 0),j([a({default:!1})],k.prototype,"value",void 0),j([a({type:[String,Boolean,Array],default:!1})],k.prototype,"validation",void 0),j([a({type:[String,Boolean],default:!1})],k.prototype,"validationName",void 0),j([a({type:Object,default:()=>({})})],k.prototype,"validationRules",void 0),j([a({type:Object,default:()=>({})})],k.prototype,"validationMessages",void 0),j([a({type:[Array,String,Boolean],default:!1})],k.prototype,"errors",void 0),j([a({type:String,default:_.BLUR,validator:e=>[_.BLUR,_.LIVE,_.SUBMIT].includes(e)})],k.prototype,"errorBehavior",void 0),j([a({default:!1})],k.prototype,"showErrors",void 0),j([a({default:!1})],k.prototype,"disableErrors",void 0),j([a({default:!0})],k.prototype,"preventWindowDrops",void 0),j([a({default:"preview"})],k.prototype,"imageBehavior",void 0),j([a({default:!1})],k.prototype,"uploader",void 0),j([a({default:!1})],k.prototype,"uploadUrl",void 0),j([a({default:"live"})],k.prototype,"uploadBehavior",void 0),j([n("$attrs",{deep:!0})],k.prototype,"onAttrsChanged",null),j([n("proxy")],k.prototype,"onProxyChanged",null),j([n("formularioValue")],k.prototype,"onFormularioValueChanged",null),j([n("showValidationErrors",{immediate:!0})],k.prototype,"onShowValidationErrorsChanged",null),k=j([l({inheritAttrs:!1})],k);const I=k;var C=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)};C._withStripped=!0;const M=R({render:C,staticRenderFns:[]},void 0,I,void 0,!1,void 0,!1,void 0,void 0,void 0);let L=class extends i{get groupPath(){return this.isArrayItem?`${this.path}[${this.name}]`:""===this.path?this.name:`${this.path}.${this.name}`}};j([h({default:""})],L.prototype,"path",void 0),j([a({required:!0})],L.prototype,"name",void 0),j([a({default:!1})],L.prototype,"isArrayItem",void 0),j([s("path")],L.prototype,"groupPath",null),L=j([l],L);const B=L;var T=function(){var e=this.$createElement;return(this._self._c||e)("div",{staticClass:"formulario-group",attrs:{"data-type":"group"}},[this._t("default")],2)};T._withStripped=!0;const W=R({render:T,staticRenderFns:[]},void 0,B,void 0,!1,void 0,!1,void 0,void 0,void 0);var G=new class{constructor(){this.options={},this.defaults={components:{FormularioForm:U,FormularioInput:M,FormularioGrouping:W},library:d,rules:x,mimes:V,locale:!1,uploader:$,uploadUrl:!1,fileUrlKey:"url",uploadJustCompleteDuration:1e3,errorHandler:e=>e,plugins:[O],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 b(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,i,s=!0){const o={};for(const a in t)b(i,a)?r(i[a])&&r(t[a])?o[a]=e(t[a],i[a],s):s&&Array.isArray(t[a])&&Array.isArray(i[a])?o[a]=t[a].concat(i[a]):o[a]=i[a]:o[a]=t[a];for(const e in i)b(o,e)||(o[e]=i[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 b(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:g(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 p(e,t,this.options)}};export default G; diff --git a/dist/formulario.min.js b/dist/formulario.min.js index 8bc6be0..6e9774f 100644 --- a/dist/formulario.min.js +++ b/dist/formulario.min.js @@ -1,4 +1,4 @@ -var VueFormulario=function(){"use strict";var t=function(t,r){return{classification:t,component:"FormularioInput"+(r||t[0].toUpperCase()+t.substr(1))}},r=Object.assign({},["text","email","number","color","date","hidden","month","password","search","tel","time","url","week","datetime-local"].reduce((function(r,e){var i;return Object.assign({},r,((i={})[e]=t("text"),i))}),{}),{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")}),e=function(t){if("string"!=typeof t)return!1;var r=t.match(i);if(!r)return!1;var e=r[1];if(!e)return!1;if(o.test(e)||n.test(e))return!0;return!1},i=/^(?:\w+:)?\/\/(\S+)$/,o=/^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/,n=/^[^\s\.]+\.\S{2,}$/;for(var s="-_",a=36;a--;)s+=a.toString(36);for(a=36;a---10;)s+=a.toString(36).toUpperCase();var u=function(t){var r="";for(a=t||21;a--;)r+=s[64*Math.random()|0];return r},l=function(t,r,e){void 0===e&&(e={}),this.input=t,this.fileList=t.files,this.files=[],this.options=Object.assign({},{mimes:{}},e),this.results=!1,this.context=r,Array.isArray(this.fileList)?this.rehydrateFileList(this.fileList):this.addFileList(this.fileList)};function f(t,r){if(t===r)return!0;if(!t||!r)return!1;var e=Object.keys(t),i=Object.keys(r),o=e.length;if(i.length!==o)return!1;if(t instanceof Date&&r instanceof Date)return t.getTime()===r.getTime();if(0===o)return t===r;for(var n=0;n=100&&(r.complete||(r.justFinished=!0,setTimeout((function(){r.justFinished=!1}),t.options.uploadJustCompleteDuration)),r.complete=!0)}),(function(t){r.progress=0,r.error=t,r.complete=!0}),t.options)}))).then((function(e){t.results=e,r(e)})).catch((function(t){throw new Error(t)}))}))},l.prototype.removeFile=function(t){if(this.files=this.files.filter((function(r){return r.uuid!==t})),this.context.performValidation(),window&&this.fileList instanceof FileList){var r=new DataTransfer;this.files.map((function(t){return r.items.add(t.file)})),this.fileList=r.files,this.input.files=this.fileList}},l.prototype.loadPreviews=function(){this.files.map((function(t){if(!t.previewData&&window&&window.FileReader&&/^image\//.test(t.file.type)){var r=new FileReader;r.onload=function(r){return Object.assign(t,{previewData:r.target.result})},r.readAsDataURL(t.file)}}))},l.prototype.getFileList=function(){return this.fileList},l.prototype.getFiles=function(){return this.files},l.prototype.toString=function(){var t=this.files.length?this.files.length+" files":"empty";return this.results?JSON.stringify(this.results,null," "):"FileUpload("+t+")"};var y={accepted:function(t){var r=t.value;return Promise.resolve(["yes","on","1",1,!0,"true"].includes(r))},after:function(t,r){var e=t.value;void 0===r&&(r=!1);var i=Date.parse(r||new Date),o=Date.parse(e);return Promise.resolve(!isNaN(o)&&o>i)},alpha:function(t,r){var e=t.value;void 0===r&&(r="default");var i={default:/^[a-zA-ZÀ-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z]+$/},o=i.hasOwnProperty(r)?r:"default";return Promise.resolve(i[o].test(e))},alphanumeric:function(t,r){var e=t.value;void 0===r&&(r="default");var i={default:/^[a-zA-Z0-9À-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z0-9]+$/},o=i.hasOwnProperty(r)?r:"default";return Promise.resolve(i[o].test(e))},before:function(t,r){var e=t.value;void 0===r&&(r=!1);var i=Date.parse(r||new Date),o=Date.parse(e);return Promise.resolve(!isNaN(o)&&or&&or&&o.length()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i.test(r))},endsWith:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return r?Promise.resolve("string"==typeof r&&e.length?void 0!==e.find((function(t){return r.endsWith(t)})):"string"==typeof r&&0===e.length):Promise.resolve((function(){return!0}))},in:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(void 0!==e.find((function(t){return"object"==typeof t?f(t,r):t===r})))},matches:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(!!e.find((function(t){return"string"==typeof t&&"/"===t.substr(0,1)&&"/"===t.substr(-1)&&(t=new RegExp(t.substr(1,t.length-2))),t instanceof RegExp?t.test(r):t===r})))},mime:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(function(){if(r instanceof l)for(var t=r.getFiles(),i=0;i=r):!isNaN(i)&&"length"!==e||"value"===e?(i=isNaN(i)?i:Number(i))>=r:("string"==typeof i||"length"===e)&&(i=isNaN(i)?i:i.toString()).length>=r)},max:function(t,r,e){var i=t.value;return void 0===r&&(r=10),Promise.resolve(Array.isArray(i)?(r=isNaN(r)?r:Number(r),i.length<=r):!isNaN(i)&&"length"!==e||"value"===e?(i=isNaN(i)?i:Number(i))<=r:("string"==typeof i||"length"===e)&&(i=isNaN(i)?i:i.toString()).length<=r)},not:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(void 0===e.find((function(t){return"object"==typeof t?f(t,r):t===r})))},number:function(t){var r=t.value;return Promise.resolve(!isNaN(r))},required:function(t,r){var e=t.value;return void 0===r&&(r=!0),Promise.resolve(!(r&&!["no","false"].includes(r))||(Array.isArray(e)?!!e.length:e instanceof l?e.getFiles().length>0:"string"==typeof e?!!e:"object"!=typeof e||!!e&&!!Object.keys(e).length))},startsWith:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return r?Promise.resolve("string"==typeof r&&e.length?void 0!==e.find((function(t){return r.startsWith(t)})):"string"==typeof r&&0===e.length):Promise.resolve((function(){return!0}))},url:function(t){var r=t.value;return Promise.resolve(e(r))},bail:function(){return Promise.resolve(!0)}},b="image/",E={csv:"text/csv",gif:b+"gif",jpg:b+"jpeg",jpeg:b+"jpeg",png:b+"png",pdf:"application/pdf",svg:b+"svg+xml"},x={default:function(t,r){return t.$t("validation.default",r)},accepted:function(t,r){return t.$t("validation.accepted",r)},after:function(t,r){return Array.isArray(r.args)&&r.args.length?(r.compare=r.args[0],t.$t("validation.after.compare",r)):t.$t("validation.after.default",r)},alpha:function(t,r){return t.$t("validation.alpha",r)},alphanumeric:function(t,r){return t.$t("validation.alphanumeric",r)},before:function(t,r){return Array.isArray(r.args)&&r.args.length?(r.compare=r.args[0],t.$t("validation.before.compare",r)):t.$t("validation.before.default",r)},between:function(t,r){r.from=r.args[0],r.to=r.args[1];var e=!(!Array.isArray(r.args)||!r.args[2])&&r.args[2];return!isNaN(value)&&"length"!==e||"value"===e?t.$t("validation.between.force",r):t.$t("validation.between.default",r)},confirm:function(t,r){return t.$t("validation.confirm",r)},date:function(t,r){return Array.isArray(r.args)&&r.args.length?(r.format=r.args[0],t.$t("validation.date.format",r)):t.$t("validation.date.default",r)},email:function(t,r){return t.$t("validation.email.default",r)},endsWith:function(t,r){return t.$t("validation.endsWith.default",r)},in:function(t,r){return"string"==typeof r.value&&r.value?t.$t("validation.in.string",r):t.$t("validation.in.default",r)},matches:function(t,r){return t.$t("validation.matches.default",r)},max:function(t,r){if(r.maximum=r.args[0],Array.isArray(r.value))return t.$tc("validation.max.array",r.maximum,r);var e=!(!Array.isArray(r.args)||!r.args[1])&&r.args[1];return!isNaN(r.value)&&"length"!==e||"value"===e?t.$tc("validation.max.force",r.maximum,r):t.$tc("validation.max.default",r.maximum,r)},mime:function(t,r){return r.types=r.args[0],r.types?t.$t("validation.mime.default",r):t.$t("validation.mime.no_formats_allowed",r)},min:function(t,r){if(r.minimum=r.args[0],Array.isArray(r.value))return t.$tc("validation.min.array",r.minimum,r);var e=!(!Array.isArray(r.args)||!r.args[1])&&r.args[1];return!isNaN(r.value)&&"length"!==e||"value"===e?t.$tc("validation.min.force",r.minimum,r):t.$tc("validation.min.default",r.minimum,r)},not:function(t,r){return t.$t("validation.not.default",r)},number:function(t,r){return t.$t("validation.number.default",r)},required:function(t,r){return t.$t("validation.required.default",r)},startsWith:function(t,r){return t.$t("validation.startsWith.default",r)},url:function(t,r){return t.$t("validation.url.default",r)}};function V(t){t.extend({validationMessages:x})} +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;tthis.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;i0!==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)&&iPromise.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&&et&&e.lengthPromise.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 * @@ -11,4 +11,24 @@ var VueFormulario=function(){"use strict";var t=function(t,r){return{classificat * Copyright (c) 2014-2017, Jon Schlinkert. * Released under the MIT License. */ -function w(t){return!0==(null!=(r=t)&&"object"==typeof r&&!1===Array.isArray(r))&&"[object Object]"===Object.prototype.toString.call(t);var r}function O(t){var r,e;return!1!==w(t)&&("function"==typeof(r=t.constructor)&&(!1!==w(e=r.prototype)&&!1!==e.hasOwnProperty("isPrototypeOf")))}function $(t,r,e,i){return new Promise((function(e,o){var n=(i.fauxUploaderDuration||2e3)*(.5+Math.random()),s=performance.now(),a=function(){return setTimeout((function(){var i=performance.now()-s,o=Math.min(100,Math.round(i/n*100));if(r(o),o>=100)return e({url:"http://via.placeholder.com/350x150.png",name:t.name});a()}),20)};a()}))}function F(t,r){var e={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&-1===r.indexOf(i)&&(e[i]=t[i]);return e}var j=function(t){this.registry=new Map,this.ctx=t};j.prototype.add=function(t,r){return this.registry.set(t,r),this},j.prototype.remove=function(t){this.registry.delete(t);var r=this.ctx.proxy,e=(r[t],F(r,[String(t)]));return this.ctx.proxy=e,this},j.prototype.has=function(t){return this.registry.has(t)},j.prototype.get=function(t){return this.registry.get(t)},j.prototype.map=function(t){var r={};return this.registry.forEach((function(e,i){var o;return Object.assign(r,((o={})[i]=t(e,i),o))})),r},j.prototype.keys=function(){return Array.from(this.registry.keys())},j.prototype.register=function(t,r){if(this.registry.has(t))return!1;this.registry.set(t,r);var e=v(r.$options.propsData,"formularioValue"),i=v(r.$options.propsData,"value");!e&&this.ctx.hasInitialValue&&void 0!==g(this.ctx.initialValues,t)?r.context.model=g(this.ctx.initialValues,t):!e&&!i||f(r.proxy,g(this.ctx.initialValues,t))||this.ctx.setFieldValue(t,r.proxy),this.childrenShouldShowErrors&&(r.formShouldShowErrors=!0)},j.prototype.reduce=function(t,r){return this.registry.forEach((function(e,i){r=t(r,e,i)})),r},j.prototype.dataProps=function(){var t=this;return{proxy:{},registry:this,register:this.register.bind(this),deregister:function(r){return t.remove(r)},childrenShouldShowErrors:!1}};var A=function(t){this.form=t};function P(t,r,e,i,o,n,s,a,u,l){"boolean"!=typeof s&&(u=a,a=s,s=!1);var f,h="function"==typeof e?e.options:e;if(t&&t.render&&(h.render=t.render,h.staticRenderFns=t.staticRenderFns,h._compiled=!0,o&&(h.functional=!0)),i&&(h._scopeId=i),n?(f=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),r&&r.call(this,u(t)),t&&t._registeredComponents&&t._registeredComponents.add(n)},h._ssrRegister=f):r&&(f=s?function(t){r.call(this,l(t,this.$root.$options.shadowRoot))}:function(t){r.call(this,a(t))}),f)if(h.functional){var c=h.render;h.render=function(t,r){return f.call(r),c(t,r)}}else{var d=h.beforeCreate;h.beforeCreate=d?[].concat(d,f):[f]}return e}A.prototype.hasValidationErrors=function(){return this.form.hasValidationErrors()},A.prototype.values=function(){var t=this;return new Promise((function(r,e){var i=[],o=function t(r){if("object"!=typeof r)return r;var e=Array.isArray(r)?[]:{};for(var i in r)r[i]instanceof l||m(r[i])?e[i]=r[i]:e[i]=t(r[i]);return e}(t.form.proxy),n=function(r){"object"==typeof t.form.proxy[r]&&t.form.proxy[r]instanceof l&&i.push(t.form.proxy[r].upload().then((function(t){var e;return Object.assign(o,((e={})[r]=t,e))})))};for(var s in o)n(s);Promise.all(i).then((function(){return r(o)})).catch((function(t){return e(t)}))}))};var S={provide:function(){return Object.assign({},{formularioSetter:(t=this).setFieldValue,formularioRegister:t.register,formularioDeregister:t.deregister,getFormValues:t.getFormValues},{observeErrors:this.addErrorObserver,removeErrorObserver:this.removeErrorObserver,formularioFieldValidation:this.formularioFieldValidation,path:""});var t},name:"FormularioForm",model:{prop:"formularioValue",event:"input"},props:{name:{type:[String,Boolean],default:!1},formularioValue:{type:Object,default:function(){return{}}},values:{type:[Object,Boolean],default:!1},errors:{type:[Object,Boolean],default:!1},formErrors:{type:Array,default:function(){return[]}}},data:function(){return Object.assign({},new j(this).dataProps(),{formShouldShowErrors:!1,errorObservers:[],namedErrors:[],namedFieldErrors:{}})},computed:Object.assign({},{hasInitialValue:function(){return this.formularioValue&&"object"==typeof this.formularioValue||this.values&&"object"==typeof this.values||this.isGrouping&&"object"==typeof this.context.model[this.index]},isVmodeled:function(){return!!(this.$options.propsData.hasOwnProperty("formularioValue")&&this._events&&Array.isArray(this._events.input)&&this._events.input.length)},initialValues:function(){return v(this.$options.propsData,"formularioValue")&&"object"==typeof this.formularioValue?Object.assign({},this.formularioValue):v(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]:{}}},{classes:function(){var t={"formulario-form":!0};return this.name&&(t["formulario-form--"+this.name]=!0),t},mergedFormErrors:function(){return this.formErrors.concat(this.namedErrors)},mergedFieldErrors:function(){var t={};if(this.errors)for(var r in this.errors)t[r]=c(this.errors[r]);for(var e in this.namedFieldErrors)t[e]=c(this.namedFieldErrors[e]);return t},hasFormErrorObservers:function(){return!!this.errorObservers.filter((function(t){return"form"===t.type})).length}}),watch:{formularioValue:{handler:function(t){this.isVmodeled&&t&&"object"==typeof t&&this.setValues(t)},deep:!0},mergedFormErrors:function(t){this.errorObservers.filter((function(t){return"form"===t.type})).forEach((function(r){return r.callback(t)}))},mergedFieldErrors:{handler:function(t){this.errorObservers.filter((function(t){return"input"===t.type})).forEach((function(r){return r.callback(t[r.field]||[])}))},immediate:!0}},created:function(){this.$formulario.register(this),this.applyInitialValues()},destroyed:function(){this.$formulario.deregister(this)},methods:Object.assign({},function(t){void 0===t&&(t=[]);var r={applyInitialValues:function(){this.hasInitialValue&&(this.proxy=this.initialValues)},setFieldValue:function(t,r){if(void 0===r){var e=this.proxy,i=(e[t],F(e,[String(t)]));this.proxy=i}else!function(t,r,e){for(var i=r.split("."),o=t,n=0;n=0){var i=t.splice(0,e+1).slice(0,-1);i.length&&r.push(i),t.map((function(t){return r.push(Object.defineProperty([t],"bail",{value:!0}))}))}else r.push(t);return r.reduce((function(t,r){var e=function(t,r){if(void 0===r&&(r=!1),t.length<2)return Object.defineProperty([t],"bail",{value:r});var i=[],o=t.findIndex((function(t){return"^"===t[3]}));if(o>=0){var n=t.splice(0,o);n.length&&i.push.apply(i,e(n,r)),i.push(Object.defineProperty([t.shift()],"bail",{value:!0})),t.length&&i.push.apply(i,e(t,r))}else i.push(t);return i};return t.concat(e(r))}),[])}(t))}))},didValidate:function(t){var r=!f(t,this.validationErrors);if(this.validationErrors=t,r){var e=this.getErrorObject();this.$emit("validation",e),this.formularioFieldValidation&&"function"==typeof this.formularioFieldValidation&&this.formularioFieldValidation(e)}},getMessageObject:function(t,r){var e={args:r,name:this.mergedValidationName,value:this.context.model,vm:this,formValues:this.getFormValues()};return{message:this.getMessageFunc(t)(e),rule:t,context:e}},getMessageFunc:function(t){var r=this;if(t=h(t),this.messages&&void 0!==this.messages[t])switch(typeof this.messages[t]){case"function":return this.messages[t];case"string":case"boolean":return function(){return r.messages[t]}}return function(e){return r.$formulario.validationMessage(t,e,r)}},hasValidationErrors:function(){var t=this;return new Promise((function(r){t.$nextTick((function(){t.pendingValidation.then((function(){return r(!!t.validationErrors.length)}))}))}))},getValidationErrors:function(){var t=this;return new Promise((function(r){t.$nextTick((function(){return t.pendingValidation.then((function(){return r(t.getErrorObject())}))}))}))},getErrorObject:function(){return{name:this.context.nameOrFallback||this.context.name,errors:this.validationErrors.filter((function(t){return"object"==typeof t})),hasErrors:!!this.validationErrors.length}},setErrors:function(t){this.localErrors=c(t)},registerRule:function(t,r,e,i){void 0===i&&(i=null),this.ruleRegistry.some((function(t){return t[2]===e}))||(this.ruleRegistry.push([t,r,e]),null!==i&&(this.messageRegistry[e]=i))},removeRule:function(t){var r=this.ruleRegistry.findIndex((function(r){return r[2]===t}));r>=0&&(this.ruleRegistry.splice(r,1),delete this.messageRegistry[t])}}},B=function(){var t=this,r=t.$createElement;return(t._self._c||r)("div",{staticClass:"formulario-input",attrs:{"data-has-errors":t.hasErrors,"data-is-showing-errors":t.hasVisibleErrors,"data-type":t.type}},[t._t("default",null,{id:t.id,context:t.context,errors:t.errors,validationErrors:t.validationErrors})],2)};B._withStripped=!0;var L=P({render:B,staticRenderFns:[]},void 0,M,void 0,!1,void 0,!1,void 0,void 0,void 0),C={name:"FormularioGrouping",props:{name:{type:String,required:!0},isArrayItem:{type:Boolean,default:!1}},provide:function(){return{path:this.groupPath}},inject:["path"],computed:{groupPath:function(){return this.isArrayItem?this.path+"["+this.name+"]":""===this.path?this.name:this.path+"."+this.name}}},T=function(){var t=this.$createElement;return(this._self._c||t)("div",{staticClass:"formulario-group",attrs:{"data-type":"group"}},[this._t("default")],2)};T._withStripped=!0;var W=P({render:T,staticRenderFns:[]},void 0,C,void 0,!1,void 0,!1,void 0,void 0,void 0),G=function(){this.options={},this.defaults={components:{FormularioForm:R,FormularioInput:L,FormularioGrouping:W},library:r,rules:y,mimes:E,locale:!1,uploader:$,uploadUrl:!1,fileUrlKey:"url",uploadJustCompleteDuration:1e3,errorHandler:function(t){return t},plugins:[V],validationMessages:{},idPrefix:"formulario-"},this.registry=new Map,this.idRegistry={}};return G.prototype.install=function(t,r){var e=this;t.prototype.$formulario=this,this.options=this.defaults;var i=this.defaults.plugins;for(var o in r&&Array.isArray(r.plugins)&&r.plugins.length&&(i=i.concat(r.plugins)),i.forEach((function(t){return"function"==typeof t?t(e):null})),this.extend(r||{}),this.options.components)t.component(o,this.options.components[o])},G.prototype.nextId=function(t){var r=!(!t.$route||!t.$route.path)&&t.$route.path?t.$route.path.replace(/[/\\.\s]/g,"-"):"global";return Object.prototype.hasOwnProperty.call(this.idRegistry,r)||(this.idRegistry[r]=0),""+this.options.idPrefix+r+"-"+ ++this.idRegistry[r]},G.prototype.extend=function(t){if("object"==typeof t)return this.options=this.merge(this.options,t),this;throw new Error("VueFormulario extend() should be passed an object (was "+typeof t+")")},G.prototype.merge=function(t,r,e){void 0===e&&(e=!0);var i={};for(var o in t)r.hasOwnProperty(o)?O(r[o])&&O(t[o])?i[o]=this.merge(t[o],r[o],e):e&&Array.isArray(t[o])&&Array.isArray(r[o])?i[o]=t[o].concat(r[o]):i[o]=r[o]:i[o]=t[o];for(var n in r)i.hasOwnProperty(n)||(i[n]=r[n]);return i},G.prototype.classify=function(t){return this.options.library.hasOwnProperty(t)?this.options.library[t].classification:"unknown"},G.prototype.component=function(t){return!!this.options.library.hasOwnProperty(t)&&this.options.library[t].component},G.prototype.rules=function(t){return void 0===t&&(t={}),Object.assign({},this.options.rules,t)},G.prototype.validationMessage=function(t,r,e){return this.options.validationMessages.hasOwnProperty(t)?this.options.validationMessages[t](e,r):this.options.validationMessages.default(e,r)},G.prototype.register=function(t){"FormularioForm"===t.$options.name&&t.name&&this.registry.set(t.name,t)},G.prototype.deregister=function(t){"FormularioForm"===t.$options.name&&t.name&&this.registry.has(t.name)&&this.registry.delete(t.name)},G.prototype.handle=function(t,r,e){void 0===e&&(e=!1);var i=e?t:this.options.errorHandler(t,r);return r&&this.registry.has(r)&&this.registry.get(r).applyErrors({formErrors:c(i.formErrors),inputErrors:i.inputErrors||{}}),i},G.prototype.reset=function(t,r){void 0===r&&(r={}),this.resetValidation(t),this.setValues(t,r)},G.prototype.resetValidation=function(t){var r=this.registry.get(t);r.hideErrors(t),r.namedErrors=[],r.namedFieldErrors={}},G.prototype.setValues=function(t,r){r&&!Array.isArray(r)&&"object"==typeof r&&this.registry.get(t).setValues(Object.assign({},r))},G.prototype.getUploader=function(){return this.options.uploader||!1},G.prototype.getUploadUrl=function(){return this.options.uploadUrl||!1},G.prototype.getFileUrlKey=function(){return this.options.fileUrlKey||"url"},G.prototype.createUpload=function(t,r){return new l(t,r,this.options)},new G}(); +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=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);t0&&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(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); diff --git a/dist/formulario.umd.js b/dist/formulario.umd.js index 70d414c..b632b13 100644 --- a/dist/formulario.umd.js +++ b/dist/formulario.umd.js @@ -1 +1,16 @@ -!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r(require("is-url"),require("nanoid/non-secure"),require("is-plain-object")):"function"==typeof define&&define.amd?define(["is-url","nanoid/non-secure","is-plain-object"],r):(t=t||self).Formulario=r(t.isUrl,t.nanoid,t.isPlainObject)}(this,(function(t,r,e){"use strict";t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t,r=r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r,e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;var i=function(t,r){return{classification:t,component:"FormularioInput"+(r||t[0].toUpperCase()+t.substr(1))}},o=Object.assign({},["text","email","number","color","date","hidden","month","password","search","tel","time","url","week","datetime-local"].reduce((function(t,r){var e;return Object.assign({},t,((e={})[r]=i("text"),e))}),{}),{range:i("slider"),textarea:i("textarea","TextArea"),checkbox:i("box"),radio:i("box"),submit:i("button"),button:i("button"),select:i("select"),file:i("file"),image:i("file"),group:i("group")}),n=function(t,r,e){void 0===e&&(e={}),this.input=t,this.fileList=t.files,this.files=[],this.options=Object.assign({},{mimes:{}},e),this.results=!1,this.context=r,Array.isArray(this.fileList)?this.rehydrateFileList(this.fileList):this.addFileList(this.fileList)};function s(t,r){if(t===r)return!0;if(!t||!r)return!1;var e=Object.keys(t),i=Object.keys(r),o=e.length;if(i.length!==o)return!1;if(t instanceof Date&&r instanceof Date)return t.getTime()===r.getTime();if(0===o)return t===r;for(var n=0;n=100&&(r.complete||(r.justFinished=!0,setTimeout((function(){r.justFinished=!1}),t.options.uploadJustCompleteDuration)),r.complete=!0)}),(function(t){r.progress=0,r.error=t,r.complete=!0}),t.options)}))).then((function(e){t.results=e,r(e)})).catch((function(t){throw new Error(t)}))}))},n.prototype.removeFile=function(t){if(this.files=this.files.filter((function(r){return r.uuid!==t})),this.context.performValidation(),window&&this.fileList instanceof FileList){var r=new DataTransfer;this.files.map((function(t){return r.items.add(t.file)})),this.fileList=r.files,this.input.files=this.fileList}},n.prototype.loadPreviews=function(){this.files.map((function(t){if(!t.previewData&&window&&window.FileReader&&/^image\//.test(t.file.type)){var r=new FileReader;r.onload=function(r){return Object.assign(t,{previewData:r.target.result})},r.readAsDataURL(t.file)}}))},n.prototype.getFileList=function(){return this.fileList},n.prototype.getFiles=function(){return this.files},n.prototype.toString=function(){var t=this.files.length?this.files.length+" files":"empty";return this.results?JSON.stringify(this.results,null," "):"FileUpload("+t+")"};var p={accepted:function(t){var r=t.value;return Promise.resolve(["yes","on","1",1,!0,"true"].includes(r))},after:function(t,r){var e=t.value;void 0===r&&(r=!1);var i=Date.parse(r||new Date),o=Date.parse(e);return Promise.resolve(!isNaN(o)&&o>i)},alpha:function(t,r){var e=t.value;void 0===r&&(r="default");var i={default:/^[a-zA-ZÀ-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z]+$/},o=i.hasOwnProperty(r)?r:"default";return Promise.resolve(i[o].test(e))},alphanumeric:function(t,r){var e=t.value;void 0===r&&(r="default");var i={default:/^[a-zA-Z0-9À-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z0-9]+$/},o=i.hasOwnProperty(r)?r:"default";return Promise.resolve(i[o].test(e))},before:function(t,r){var e=t.value;void 0===r&&(r=!1);var i=Date.parse(r||new Date),o=Date.parse(e);return Promise.resolve(!isNaN(o)&&or&&or&&o.length()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i.test(r))},endsWith:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return r?Promise.resolve("string"==typeof r&&e.length?void 0!==e.find((function(t){return r.endsWith(t)})):"string"==typeof r&&0===e.length):Promise.resolve((function(){return!0}))},in:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(void 0!==e.find((function(t){return"object"==typeof t?s(t,r):t===r})))},matches:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(!!e.find((function(t){return"string"==typeof t&&"/"===t.substr(0,1)&&"/"===t.substr(-1)&&(t=new RegExp(t.substr(1,t.length-2))),t instanceof RegExp?t.test(r):t===r})))},mime:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(function(){if(r instanceof n)for(var t=r.getFiles(),i=0;i=r):!isNaN(i)&&"length"!==e||"value"===e?(i=isNaN(i)?i:Number(i))>=r:("string"==typeof i||"length"===e)&&(i=isNaN(i)?i:i.toString()).length>=r)},max:function(t,r,e){var i=t.value;return void 0===r&&(r=10),Promise.resolve(Array.isArray(i)?(r=isNaN(r)?r:Number(r),i.length<=r):!isNaN(i)&&"length"!==e||"value"===e?(i=isNaN(i)?i:Number(i))<=r:("string"==typeof i||"length"===e)&&(i=isNaN(i)?i:i.toString()).length<=r)},not:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(void 0===e.find((function(t){return"object"==typeof t?s(t,r):t===r})))},number:function(t){var r=t.value;return Promise.resolve(!isNaN(r))},required:function(t,r){var e=t.value;return void 0===r&&(r=!0),Promise.resolve(!(r&&!["no","false"].includes(r))||(Array.isArray(e)?!!e.length:e instanceof n?e.getFiles().length>0:"string"==typeof e?!!e:"object"!=typeof e||!!e&&!!Object.keys(e).length))},startsWith:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return r?Promise.resolve("string"==typeof r&&e.length?void 0!==e.find((function(t){return r.startsWith(t)})):"string"==typeof r&&0===e.length):Promise.resolve((function(){return!0}))},url:function(r){var e=r.value;return Promise.resolve(t(e))},bail:function(){return Promise.resolve(!0)}},m="image/",v={csv:"text/csv",gif:m+"gif",jpg:m+"jpeg",jpeg:m+"jpeg",png:m+"png",pdf:"application/pdf",svg:m+"svg+xml"},g={default:function(t,r){return t.$t("validation.default",r)},accepted:function(t,r){return t.$t("validation.accepted",r)},after:function(t,r){return Array.isArray(r.args)&&r.args.length?(r.compare=r.args[0],t.$t("validation.after.compare",r)):t.$t("validation.after.default",r)},alpha:function(t,r){return t.$t("validation.alpha",r)},alphanumeric:function(t,r){return t.$t("validation.alphanumeric",r)},before:function(t,r){return Array.isArray(r.args)&&r.args.length?(r.compare=r.args[0],t.$t("validation.before.compare",r)):t.$t("validation.before.default",r)},between:function(t,r){r.from=r.args[0],r.to=r.args[1];var e=!(!Array.isArray(r.args)||!r.args[2])&&r.args[2];return!isNaN(value)&&"length"!==e||"value"===e?t.$t("validation.between.force",r):t.$t("validation.between.default",r)},confirm:function(t,r){return t.$t("validation.confirm",r)},date:function(t,r){return Array.isArray(r.args)&&r.args.length?(r.format=r.args[0],t.$t("validation.date.format",r)):t.$t("validation.date.default",r)},email:function(t,r){return t.$t("validation.email.default",r)},endsWith:function(t,r){return t.$t("validation.endsWith.default",r)},in:function(t,r){return"string"==typeof r.value&&r.value?t.$t("validation.in.string",r):t.$t("validation.in.default",r)},matches:function(t,r){return t.$t("validation.matches.default",r)},max:function(t,r){if(r.maximum=r.args[0],Array.isArray(r.value))return t.$tc("validation.max.array",r.maximum,r);var e=!(!Array.isArray(r.args)||!r.args[1])&&r.args[1];return!isNaN(r.value)&&"length"!==e||"value"===e?t.$tc("validation.max.force",r.maximum,r):t.$tc("validation.max.default",r.maximum,r)},mime:function(t,r){return r.types=r.args[0],r.types?t.$t("validation.mime.default",r):t.$t("validation.mime.no_formats_allowed",r)},min:function(t,r){if(r.minimum=r.args[0],Array.isArray(r.value))return t.$tc("validation.min.array",r.minimum,r);var e=!(!Array.isArray(r.args)||!r.args[1])&&r.args[1];return!isNaN(r.value)&&"length"!==e||"value"===e?t.$tc("validation.min.force",r.minimum,r):t.$tc("validation.min.default",r.minimum,r)},not:function(t,r){return t.$t("validation.not.default",r)},number:function(t,r){return t.$t("validation.number.default",r)},required:function(t,r){return t.$t("validation.required.default",r)},startsWith:function(t,r){return t.$t("validation.startsWith.default",r)},url:function(t,r){return t.$t("validation.url.default",r)}};function y(t){t.extend({validationMessages:g})}function b(t,r,e,i){return new Promise((function(e,o){var n=(i.fauxUploaderDuration||2e3)*(.5+Math.random()),s=performance.now(),a=function(){return setTimeout((function(){var i=performance.now()-s,o=Math.min(100,Math.round(i/n*100));if(r(o),o>=100)return e({url:"http://via.placeholder.com/350x150.png",name:t.name});a()}),20)};a()}))}function E(t,r){var e={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&-1===r.indexOf(i)&&(e[i]=t[i]);return e}var x=function(t){this.registry=new Map,this.ctx=t};x.prototype.add=function(t,r){return this.registry.set(t,r),this},x.prototype.remove=function(t){this.registry.delete(t);var r=this.ctx.proxy,e=(r[t],E(r,[String(t)]));return this.ctx.proxy=e,this},x.prototype.has=function(t){return this.registry.has(t)},x.prototype.get=function(t){return this.registry.get(t)},x.prototype.map=function(t){var r={};return this.registry.forEach((function(e,i){var o;return Object.assign(r,((o={})[i]=t(e,i),o))})),r},x.prototype.keys=function(){return Array.from(this.registry.keys())},x.prototype.register=function(t,r){if(this.registry.has(t))return!1;this.registry.set(t,r);var e=c(r.$options.propsData,"formularioValue"),i=c(r.$options.propsData,"value");!e&&this.ctx.hasInitialValue&&void 0!==d(this.ctx.initialValues,t)?r.context.model=d(this.ctx.initialValues,t):!e&&!i||s(r.proxy,d(this.ctx.initialValues,t))||this.ctx.setFieldValue(t,r.proxy),this.childrenShouldShowErrors&&(r.formShouldShowErrors=!0)},x.prototype.reduce=function(t,r){return this.registry.forEach((function(e,i){r=t(r,e,i)})),r},x.prototype.dataProps=function(){var t=this;return{proxy:{},registry:this,register:this.register.bind(this),deregister:function(r){return t.remove(r)},childrenShouldShowErrors:!1}};var V=function(t){this.form=t};function w(t,r,e,i,o,n,s,a,u,l){"boolean"!=typeof s&&(u=a,a=s,s=!1);var f,h="function"==typeof e?e.options:e;if(t&&t.render&&(h.render=t.render,h.staticRenderFns=t.staticRenderFns,h._compiled=!0,o&&(h.functional=!0)),i&&(h._scopeId=i),n?(f=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),r&&r.call(this,u(t)),t&&t._registeredComponents&&t._registeredComponents.add(n)},h._ssrRegister=f):r&&(f=s?function(t){r.call(this,l(t,this.$root.$options.shadowRoot))}:function(t){r.call(this,a(t))}),f)if(h.functional){var c=h.render;h.render=function(t,r){return f.call(r),c(t,r)}}else{var d=h.beforeCreate;h.beforeCreate=d?[].concat(d,f):[f]}return e}V.prototype.hasValidationErrors=function(){return this.form.hasValidationErrors()},V.prototype.values=function(){var t=this;return new Promise((function(r,e){var i=[],o=function t(r){if("object"!=typeof r)return r;var e=Array.isArray(r)?[]:{};for(var i in r)r[i]instanceof n||h(r[i])?e[i]=r[i]:e[i]=t(r[i]);return e}(t.form.proxy),s=function(r){"object"==typeof t.form.proxy[r]&&t.form.proxy[r]instanceof n&&i.push(t.form.proxy[r].upload().then((function(t){var e;return Object.assign(o,((e={})[r]=t,e))})))};for(var a in o)s(a);Promise.all(i).then((function(){return r(o)})).catch((function(t){return e(t)}))}))};var O={provide:function(){return Object.assign({},{formularioSetter:(t=this).setFieldValue,formularioRegister:t.register,formularioDeregister:t.deregister,getFormValues:t.getFormValues},{observeErrors:this.addErrorObserver,removeErrorObserver:this.removeErrorObserver,formularioFieldValidation:this.formularioFieldValidation,path:""});var t},name:"FormularioForm",model:{prop:"formularioValue",event:"input"},props:{name:{type:[String,Boolean],default:!1},formularioValue:{type:Object,default:function(){return{}}},values:{type:[Object,Boolean],default:!1},errors:{type:[Object,Boolean],default:!1},formErrors:{type:Array,default:function(){return[]}}},data:function(){return Object.assign({},new x(this).dataProps(),{formShouldShowErrors:!1,errorObservers:[],namedErrors:[],namedFieldErrors:{}})},computed:Object.assign({},{hasInitialValue:function(){return this.formularioValue&&"object"==typeof this.formularioValue||this.values&&"object"==typeof this.values||this.isGrouping&&"object"==typeof this.context.model[this.index]},isVmodeled:function(){return!!(this.$options.propsData.hasOwnProperty("formularioValue")&&this._events&&Array.isArray(this._events.input)&&this._events.input.length)},initialValues:function(){return c(this.$options.propsData,"formularioValue")&&"object"==typeof this.formularioValue?Object.assign({},this.formularioValue):c(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]:{}}},{classes:function(){var t={"formulario-form":!0};return this.name&&(t["formulario-form--"+this.name]=!0),t},mergedFormErrors:function(){return this.formErrors.concat(this.namedErrors)},mergedFieldErrors:function(){var t={};if(this.errors)for(var r in this.errors)t[r]=u(this.errors[r]);for(var e in this.namedFieldErrors)t[e]=u(this.namedFieldErrors[e]);return t},hasFormErrorObservers:function(){return!!this.errorObservers.filter((function(t){return"form"===t.type})).length}}),watch:{formularioValue:{handler:function(t){this.isVmodeled&&t&&"object"==typeof t&&this.setValues(t)},deep:!0},mergedFormErrors:function(t){this.errorObservers.filter((function(t){return"form"===t.type})).forEach((function(r){return r.callback(t)}))},mergedFieldErrors:{handler:function(t){this.errorObservers.filter((function(t){return"input"===t.type})).forEach((function(r){return r.callback(t[r.field]||[])}))},immediate:!0}},created:function(){this.$formulario.register(this),this.applyInitialValues()},destroyed:function(){this.$formulario.deregister(this)},methods:Object.assign({},function(t){void 0===t&&(t=[]);var r={applyInitialValues:function(){this.hasInitialValue&&(this.proxy=this.initialValues)},setFieldValue:function(t,r){if(void 0===r){var e=this.proxy,i=(e[t],E(e,[String(t)]));this.proxy=i}else!function(t,r,e){for(var i=r.split("."),o=t,n=0;n=0){var i=t.splice(0,e+1).slice(0,-1);i.length&&r.push(i),t.map((function(t){return r.push(Object.defineProperty([t],"bail",{value:!0}))}))}else r.push(t);return r.reduce((function(t,r){var e=function(t,r){if(void 0===r&&(r=!1),t.length<2)return Object.defineProperty([t],"bail",{value:r});var i=[],o=t.findIndex((function(t){return"^"===t[3]}));if(o>=0){var n=t.splice(0,o);n.length&&i.push.apply(i,e(n,r)),i.push(Object.defineProperty([t.shift()],"bail",{value:!0})),t.length&&i.push.apply(i,e(t,r))}else i.push(t);return i};return t.concat(e(r))}),[])}(t))}))},didValidate:function(t){var r=!s(t,this.validationErrors);if(this.validationErrors=t,r){var e=this.getErrorObject();this.$emit("validation",e),this.formularioFieldValidation&&"function"==typeof this.formularioFieldValidation&&this.formularioFieldValidation(e)}},getMessageObject:function(t,r){var e={args:r,name:this.mergedValidationName,value:this.context.model,vm:this,formValues:this.getFormValues()};return{message:this.getMessageFunc(t)(e),rule:t,context:e}},getMessageFunc:function(t){var r=this;if(t=a(t),this.messages&&void 0!==this.messages[t])switch(typeof this.messages[t]){case"function":return this.messages[t];case"string":case"boolean":return function(){return r.messages[t]}}return function(e){return r.$formulario.validationMessage(t,e,r)}},hasValidationErrors:function(){var t=this;return new Promise((function(r){t.$nextTick((function(){t.pendingValidation.then((function(){return r(!!t.validationErrors.length)}))}))}))},getValidationErrors:function(){var t=this;return new Promise((function(r){t.$nextTick((function(){return t.pendingValidation.then((function(){return r(t.getErrorObject())}))}))}))},getErrorObject:function(){return{name:this.context.nameOrFallback||this.context.name,errors:this.validationErrors.filter((function(t){return"object"==typeof t})),hasErrors:!!this.validationErrors.length}},setErrors:function(t){this.localErrors=u(t)},registerRule:function(t,r,e,i){void 0===i&&(i=null),this.ruleRegistry.some((function(t){return t[2]===e}))||(this.ruleRegistry.push([t,r,e]),null!==i&&(this.messageRegistry[e]=i))},removeRule:function(t){var r=this.ruleRegistry.findIndex((function(r){return r[2]===t}));r>=0&&(this.ruleRegistry.splice(r,1),delete this.messageRegistry[t])}}},_=function(){var t=this,r=t.$createElement;return(t._self._c||r)("div",{staticClass:"formulario-input",attrs:{"data-has-errors":t.hasErrors,"data-is-showing-errors":t.hasVisibleErrors,"data-type":t.type}},[t._t("default",null,{id:t.id,context:t.context,errors:t.errors,validationErrors:t.validationErrors})],2)};_._withStripped=!0;var D=w({render:_,staticRenderFns:[]},void 0,R,void 0,!1,void 0,!1,void 0,void 0,void 0),U={name:"FormularioGrouping",props:{name:{type:String,required:!0},isArrayItem:{type:Boolean,default:!1}},provide:function(){return{path:this.groupPath}},inject:["path"],computed:{groupPath:function(){return this.isArrayItem?this.path+"["+this.name+"]":""===this.path?this.name:this.path+"."+this.name}}},k=function(){var t=this.$createElement;return(this._self._c||t)("div",{staticClass:"formulario-group",attrs:{"data-type":"group"}},[this._t("default")],2)};k._withStripped=!0;var I=w({render:k,staticRenderFns:[]},void 0,U,void 0,!1,void 0,!1,void 0,void 0,void 0),B=function(){this.options={},this.defaults={components:{FormularioForm:F,FormularioInput:D,FormularioGrouping:I},library:o,rules:p,mimes:v,locale:!1,uploader:b,uploadUrl:!1,fileUrlKey:"url",uploadJustCompleteDuration:1e3,errorHandler:function(t){return t},plugins:[y],validationMessages:{},idPrefix:"formulario-"},this.registry=new Map,this.idRegistry={}};return B.prototype.install=function(t,r){var e=this;t.prototype.$formulario=this,this.options=this.defaults;var i=this.defaults.plugins;for(var o in r&&Array.isArray(r.plugins)&&r.plugins.length&&(i=i.concat(r.plugins)),i.forEach((function(t){return"function"==typeof t?t(e):null})),this.extend(r||{}),this.options.components)t.component(o,this.options.components[o])},B.prototype.nextId=function(t){var r=!(!t.$route||!t.$route.path)&&t.$route.path?t.$route.path.replace(/[/\\.\s]/g,"-"):"global";return Object.prototype.hasOwnProperty.call(this.idRegistry,r)||(this.idRegistry[r]=0),""+this.options.idPrefix+r+"-"+ ++this.idRegistry[r]},B.prototype.extend=function(t){if("object"==typeof t)return this.options=this.merge(this.options,t),this;throw new Error("VueFormulario extend() should be passed an object (was "+typeof t+")")},B.prototype.merge=function(t,r,i){void 0===i&&(i=!0);var o={};for(var n in t)r.hasOwnProperty(n)?e(r[n])&&e(t[n])?o[n]=this.merge(t[n],r[n],i):i&&Array.isArray(t[n])&&Array.isArray(r[n])?o[n]=t[n].concat(r[n]):o[n]=r[n]:o[n]=t[n];for(var s in r)o.hasOwnProperty(s)||(o[s]=r[s]);return o},B.prototype.classify=function(t){return this.options.library.hasOwnProperty(t)?this.options.library[t].classification:"unknown"},B.prototype.component=function(t){return!!this.options.library.hasOwnProperty(t)&&this.options.library[t].component},B.prototype.rules=function(t){return void 0===t&&(t={}),Object.assign({},this.options.rules,t)},B.prototype.validationMessage=function(t,r,e){return this.options.validationMessages.hasOwnProperty(t)?this.options.validationMessages[t](e,r):this.options.validationMessages.default(e,r)},B.prototype.register=function(t){"FormularioForm"===t.$options.name&&t.name&&this.registry.set(t.name,t)},B.prototype.deregister=function(t){"FormularioForm"===t.$options.name&&t.name&&this.registry.has(t.name)&&this.registry.delete(t.name)},B.prototype.handle=function(t,r,e){void 0===e&&(e=!1);var i=e?t:this.options.errorHandler(t,r);return r&&this.registry.has(r)&&this.registry.get(r).applyErrors({formErrors:u(i.formErrors),inputErrors:i.inputErrors||{}}),i},B.prototype.reset=function(t,r){void 0===r&&(r={}),this.resetValidation(t),this.setValues(t,r)},B.prototype.resetValidation=function(t){var r=this.registry.get(t);r.hideErrors(t),r.namedErrors=[],r.namedFieldErrors={}},B.prototype.setValues=function(t,r){r&&!Array.isArray(r)&&"object"==typeof r&&this.registry.get(t).setValues(Object.assign({},r))},B.prototype.getUploader=function(){return this.options.uploader||!1},B.prototype.getUploadUrl=function(){return this.options.uploadUrl||!1},B.prototype.getFileUrlKey=function(){return this.options.fileUrlKey||"url"},B.prototype.createUpload=function(t,r){return new n(t,r,this.options)},new B})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("is-url"),require("nanoid/non-secure"),require("is-plain-object"),require("vue"),require("vue-property-decorator")):"function"==typeof define&&define.amd?define(["is-url","nanoid/non-secure","is-plain-object","vue","vue-property-decorator"],t):(e=e||self).Formulario=t(e.isUrl,e.nanoid,e.isPlainObject,e.Vue,e.vuePropertyDecorator)}(this,(function(e,t,r,i,o){"use strict";e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e,t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t,r=r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r,i=i&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i;const s=(e,t)=>({classification:e,component:"FormularioInput"+(t||e[0].toUpperCase()+e.substr(1))});var a=Object.assign(Object.assign({},["text","email","number","color","date","hidden","month","password","search","tel","time","url","week","datetime-local"].reduce((e,t)=>Object.assign(Object.assign({},e),{[t]:s("text")}),{})),{range:s("slider"),textarea:s("textarea","TextArea"),checkbox:s("box"),radio:s("box"),submit:s("button"),button:s("button"),select:s("select"),file:s("file"),image:s("file"),group:s("group")});class n{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 r=0;rthis.removeFile(o),previewData:i.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 l(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;i0!==e.indexOf(t)&&"_"!==e[e.indexOf(t)-1]?t.toUpperCase().replace("_",""):t):e}function u(e){return"string"==typeof e&&/^[\^]/.test(e.charAt(0))?[h(e.substr(1)),e.charAt(0)]:[h(e),null]}function d(e){return e?"string"==typeof e?[e]:Array.isArray(e)?e:"object"==typeof e?Object.values(e):[]:[]}function p(e,t){return"string"==typeof e?p(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]=u(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]=u(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 c(e){switch(typeof e){case"symbol":case"number":case"string":case"boolean":case"undefined":return!0;default:return null===e}}function f(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function m(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 g={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=f(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=f(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)&&iPromise.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&&et&&e.lengthPromise.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?l(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 n){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?l(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 n?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:t})=>Promise.resolve(e(t)),bail:()=>Promise.resolve(!0)},y={csv:"text/csv",gif:"image/gif",jpeg:"image/jpeg",jpg:"image/jpeg",png:"image/png",pdf:"application/pdf",svg:"image/svg+xml"};const v={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 b(e){e.extend({validationMessages:v})}function E(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()})} +/*! ***************************************************************************** + 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 x(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=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}class O{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],x(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=f(t.$options.propsData,"formularioValue"),i=f(t.$options.propsData,"value");!r&&this.ctx.hasInitialValue&&void 0!==m(this.ctx.initialValues,e)?t.context.model=m(this.ctx.initialValues,e):!r&&!i||l(t.proxy,m(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 P{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)&&(c(t[i])||t[i]instanceof n?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 n&&i.push(r.proxy[e].upload().then(t=>Object.assign(o,{[e]:t})));Promise.all(i).then(()=>e(o)).catch(e=>t(e))})}}let w=class extends i{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 O(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]=d(this.errors[t]);for(const t in this.namedFieldErrors)e[t]=d(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!!(f(this.$options.propsData,"formularioValue")&&this._events&&Array.isArray(this._events.input)&&this._events.input.length)}get initialValues(){return f(this.$options.propsData,"formularioValue")&&"object"==typeof this.formularioValue?Object.assign({},this.formularioValue):f(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):f(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 P(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],x(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(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)=>{l(m(e,r),m(this.proxy,r))||this.setFieldValue(r,m(e,r)),l(m(e,r),this.registry.get(r).proxy)||(this.registry.get(r).context.model=m(e,r))})}),this.applyInitialValues()}};function $(e,t,r,i,o,s,a,n,l,h){"boolean"!=typeof a&&(l=n,n=a,a=!1);const u="function"==typeof r?r.options:r;let d;if(e&&e.render&&(u.render=e.render,u.staticRenderFns=e.staticRenderFns,u._compiled=!0,o&&(u.functional=!0)),i&&(u._scopeId=i),s?(d=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)},u._ssrRegister=d):t&&(d=a?function(e){t.call(this,h(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,n(e))}),d)if(u.functional){const e=u.render;u.render=function(t,r){return d.call(r),e(t,r)}}else{const e=u.beforeCreate;u.beforeCreate=e?[].concat(e,d):[d]}return r}V([o.Provide()],w.prototype,"formularioFieldValidation",null),V([o.Provide()],w.prototype,"formularioRegister",void 0),V([o.Provide()],w.prototype,"formularioDeregister",void 0),V([o.Provide()],w.prototype,"formularioSetter",void 0),V([o.Provide()],w.prototype,"getFormValues",void 0),V([o.Provide()],w.prototype,"path",void 0),V([o.Provide()],w.prototype,"removeErrorObserver",null),V([o.Model("input",{type:Object,default:()=>({})})],w.prototype,"formularioValue",void 0),V([o.Prop({type:[String,Boolean],default:!1})],w.prototype,"name",void 0),V([o.Prop({type:[Object,Boolean],default:!1})],w.prototype,"values",void 0),V([o.Prop({default:!1})],w.prototype,"errors",void 0),V([o.Prop({default:()=>[]})],w.prototype,"formErrors",void 0),V([o.Watch("formularioValue",{deep:!0})],w.prototype,"onFormularioValueChanged",null),V([o.Watch("mergedFormErrors")],w.prototype,"onMergedFormErrorsChanged",null),V([o.Watch("mergedFieldErrors",{immediate:!0})],w.prototype,"onMergedFieldErrorsChanged",null),V([o.Provide()],w.prototype,"addErrorObserver",null),w=V([o.Component],w);const j=w;var F=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)};F._withStripped=!0;const A=$({render:F,staticRenderFns:[]},void 0,j,void 0,!1,void 0,!1,void 0,void 0,void 0),N={BLUR:"blur",LIVE:"live",SUBMIT:"submit"};let R=class extends i{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[h(t)]=this.validationRules[t]}),e}get messages(){const e={};return Object.keys(this.validationMessages).forEach(t=>{e[h(t)]=this.validationMessages[t]}),Object.keys(this.messageRegistry).forEach(t=>{e[h(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,...d(this.validationErrors)]}get visibleValidationErrors(){return this.showValidationErrors&&this.validationErrors.length?this.validationErrors:[]}get explicitErrors(){return[...d(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||l(e,t)||(this.context.model=e)}onFormularioValueChanged(e,t){this.isVmodeled&&!l(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===N.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){l(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 f(this.$options.propsData,"value")?this.value:f(this.$options.propsData,"formularioValue")?this.formularioValue:""}applyInitialValue(){l(this.context.model,this.proxy)||(this.context.model=this.proxy)}updateLocalAttributes(e){l(e,this.localAttributes)||(this.localAttributes=e)}performValidation(){let e=p(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=!l(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=h(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=d(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])}};V([o.Inject({default:void 0})],R.prototype,"formularioSetter",void 0),V([o.Inject({default:()=>()=>{}})],R.prototype,"formularioFieldValidation",void 0),V([o.Inject({default:void 0})],R.prototype,"formularioRegister",void 0),V([o.Inject({default:void 0})],R.prototype,"formularioDeregister",void 0),V([o.Inject({default:()=>()=>({})})],R.prototype,"getFormValues",void 0),V([o.Inject({default:void 0})],R.prototype,"addErrorObserver",void 0),V([o.Inject({default:void 0})],R.prototype,"removeErrorObserver",void 0),V([o.Inject({default:""})],R.prototype,"path",void 0),V([o.Provide()],R.prototype,"formularioRegisterRule",void 0),V([o.Provide()],R.prototype,"formularioRemoveRule",void 0),V([o.Model("input",{default:""})],R.prototype,"formularioValue",void 0),V([o.Prop({type:[String,Number,Boolean],default:!1})],R.prototype,"id",void 0),V([o.Prop({default:"text"})],R.prototype,"type",void 0),V([o.Prop({required:!0})],R.prototype,"name",void 0),V([o.Prop({default:!1})],R.prototype,"value",void 0),V([o.Prop({type:[String,Boolean,Array],default:!1})],R.prototype,"validation",void 0),V([o.Prop({type:[String,Boolean],default:!1})],R.prototype,"validationName",void 0),V([o.Prop({type:Object,default:()=>({})})],R.prototype,"validationRules",void 0),V([o.Prop({type:Object,default:()=>({})})],R.prototype,"validationMessages",void 0),V([o.Prop({type:[Array,String,Boolean],default:!1})],R.prototype,"errors",void 0),V([o.Prop({type:String,default:N.BLUR,validator:e=>[N.BLUR,N.LIVE,N.SUBMIT].includes(e)})],R.prototype,"errorBehavior",void 0),V([o.Prop({default:!1})],R.prototype,"showErrors",void 0),V([o.Prop({default:!1})],R.prototype,"disableErrors",void 0),V([o.Prop({default:!0})],R.prototype,"preventWindowDrops",void 0),V([o.Prop({default:"preview"})],R.prototype,"imageBehavior",void 0),V([o.Prop({default:!1})],R.prototype,"uploader",void 0),V([o.Prop({default:!1})],R.prototype,"uploadUrl",void 0),V([o.Prop({default:"live"})],R.prototype,"uploadBehavior",void 0),V([o.Watch("$attrs",{deep:!0})],R.prototype,"onAttrsChanged",null),V([o.Watch("proxy")],R.prototype,"onProxyChanged",null),V([o.Watch("formularioValue")],R.prototype,"onFormularioValueChanged",null),V([o.Watch("showValidationErrors",{immediate:!0})],R.prototype,"onShowValidationErrorsChanged",null),R=V([o.Component({inheritAttrs:!1})],R);const S=R;var D=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)};D._withStripped=!0;const I=$({render:D,staticRenderFns:[]},void 0,S,void 0,!1,void 0,!1,void 0,void 0,void 0);let U=class extends i{get groupPath(){return this.isArrayItem?`${this.path}[${this.name}]`:""===this.path?this.name:`${this.path}.${this.name}`}};V([o.Inject({default:""})],U.prototype,"path",void 0),V([o.Prop({required:!0})],U.prototype,"name",void 0),V([o.Prop({default:!1})],U.prototype,"isArrayItem",void 0),V([o.Provide("path")],U.prototype,"groupPath",null),U=V([o.Component],U);const _=U;var C=function(){var e=this.$createElement;return(this._self._c||e)("div",{staticClass:"formulario-group",attrs:{"data-type":"group"}},[this._t("default")],2)};C._withStripped=!0;const k=$({render:C,staticRenderFns:[]},void 0,_,void 0,!1,void 0,!1,void 0,void 0,void 0);return new class{constructor(){this.options={},this.defaults={components:{FormularioForm:A,FormularioInput:I,FormularioGrouping:k},library:a,rules:g,mimes:y,locale:!1,uploader:E,uploadUrl:!1,fileUrlKey:"url",uploadJustCompleteDuration:1e3,errorHandler:e=>e,plugins:[b],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 f(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,i,o=!0){const s={};for(const a in t)f(i,a)?r(i[a])&&r(t[a])?s[a]=e(t[a],i[a],o):o&&Array.isArray(t[a])&&Array.isArray(i[a])?s[a]=t[a].concat(i[a]):s[a]=i[a]:s[a]=t[a];for(const e in i)f(s,e)||(s[e]=i[e]);return s}(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 f(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:d(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 n(e,t,this.options)}}}));