1
0
mirror of synced 2024-11-29 08:36:12 +03:00
vue-formulario/dist/formulario.umd.js
2020-10-23 14:15:57 +03:00

16 lines
23 KiB
JavaScript

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("is-url"),require("is-plain-object"),require("vue"),require("vue-property-decorator")):"function"==typeof define&&define.amd?define(["is-url","is-plain-object","vue","vue-property-decorator"],t):(e=e||self).Formulario=t(e.isUrl,e.isPlainObject,e.Vue,e.vuePropertyDecorator)}(this,(function(e,t,r,i){"use strict";function o(e,t){if(e===t)return!0;if(!e||!t)return!1;const r=Object.keys(e);if(Object.keys(t).length!==r.length)return!1;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(0===r.length)return e===t;for(let i=0;i<r.length;i++){const o=r[i];if(e[o]!==t[o])return!1}return!0}function s(e){return"string"==typeof e?e.replace(/([_][a-z0-9])/gi,t=>0!==e.indexOf(t)&&"_"!==e[e.indexOf(t)-1]?t.toUpperCase().replace("_",""):t):e}function a(e){return"string"==typeof e&&/^[\^]/.test(e.charAt(0))?[s(e.substr(1)),e.charAt(0)]:[s(e),null]}function n(e){return e?"string"==typeof e?[e]:Array.isArray(e)?e:"object"==typeof e?Object.values(e):[]:[]}function l(e,t){return"string"==typeof e?l(e.split("|").filter(e=>e.length),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]=a(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]=a(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 u(e){switch(typeof e){case"symbol":case"number":case"string":case"boolean":case"undefined":return!0;default:return null===e}}function d(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function h(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}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;var c={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=d(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=d(r,t)?t:"default";return Promise.resolve(r[i].test(e))},before({value:e},t=!1){const r=!1!==t?Date.parse(t):Date.now(),i=e instanceof Date?e.getTime():Date.parse(e);return Promise.resolve(!isNaN(i)&&i<r)},between:({value:e},t=0,r=10,i)=>Promise.resolve(null!==t&&null!==r&&!isNaN(t)&&!isNaN(r)&&(!isNaN(Number(e))&&"length"!==i||"value"===i?(e=Number(e),t=Number(t),r=Number(r),e>t&&e<r):("string"==typeof e||"length"===i)&&(e=isNaN(Number(e))?e:e.toString()).length>t&&e.length<r)),confirm:({value:e,getFormValues:t,name:r},i)=>Promise.resolve((()=>{let o=i;return o||(o=/_confirm$/.test(r)?r.substr(0,r.length-8):r+"_confirm"),t()[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?o(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))),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?o(t,e):t===e)),number:({value:e})=>Promise.resolve(String(e).length>0&&!isNaN(Number(e))),required:({value:e},t=!0)=>Promise.resolve(!(t&&!["no","false"].includes(t)&&(Array.isArray(e)?!e.length:"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)},p={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 f(e,r,i=!0){const o={};for(const s in e)d(r,s)?t(r[s])&&t(e[s])?o[s]=f(e[s],r[s],i):i&&Array.isArray(e[s])&&Array.isArray(r[s])?o[s]=e[s].concat(r[s]):o[s]=r[s]:o[s]=e[s];for(const e in r)d(o,e)||(o[e]=r[e]);return o}
/*! *****************************************************************************
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 m(e,t){var r={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(r[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++)t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(r[i[o]]=e[i[o]])}return r}function v(e,t,r,i){var o,s=arguments.length,a=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,i);else for(var n=e.length-1;n>=0;n--)(o=e[n])&&(a=(s<3?o(a):s>3?o(t,r,a):o(t,r))||a);return s>3&&a&&Object.defineProperty(t,r,a),a}class g{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],m(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=d(t.$options.propsData||{},"formularioValue"),i=d(t.$options.propsData||{},"value");!r&&this.ctx.hasInitialValue&&void 0!==h(this.ctx.initialValues,e)?t.context.model=h(this.ctx.initialValues,e):!r&&!i||o(t.proxy,h(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 y{constructor(e=[]){this.observers=[],this.observers=e}add(e){this.observers.some(t=>t.callback===e.callback)||this.observers.push(e)}remove(e){this.observers=this.observers.filter(t=>t.callback!==e)}filter(e){return new y(this.observers.filter(e))}some(e){return this.observers.some(e)}observe(e){this.observers.forEach(t=>{"form"===t.type?t.callback(e):t.field&&!Array.isArray(e)&&d(e,t.field)&&t.callback(e[t.field])})}}let b=class extends r{constructor(){super(...arguments),this.path="",this.proxy={},this.registry=new g(this),this.errorObserverRegistry=new y,this.localFormErrors=[],this.localFieldErrors={}}get mergedFormErrors(){return[...this.formErrors,...this.localFormErrors]}get mergedFieldErrors(){return f(this.errors||{},this.localFieldErrors)}get hasModel(){return d(this.$options.propsData||{},"formularioValue")}get hasInitialValue(){return this.formularioValue&&"object"==typeof this.formularioValue}get initialValues(){return this.hasModel&&"object"==typeof this.formularioValue?Object.assign({},this.formularioValue):{}}onFormularioValueChanged(e){this.hasModel&&e&&"object"==typeof e&&this.setValues(e)}onMergedFormErrorsChanged(e){this.errorObserverRegistry.filter(e=>"form"===e.type).observe(e)}onMergedFieldErrorsChanged(e){this.errorObserverRegistry.filter(e=>"input"===e.type).observe(e)}created(){this.initProxy()}getFormValues(){return this.proxy}onFormSubmit(){return this.hasValidationErrors().then(e=>e?void 0: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)&&(u(t[i])?r[i]=t[i]:r[i]=e(t[i]));return r}(this.proxy)).then(e=>{void 0!==e?this.$emit("submit",e):this.$emit("error")})}onFormularioFieldValidation(e){this.$emit("validation",e)}addErrorObserver(e){this.errorObserverRegistry.add(e),"form"===e.type?e.callback(this.mergedFormErrors):e.field&&d(this.mergedFieldErrors,e.field)&&e.callback(this.mergedFieldErrors[e.field])}removeErrorObserver(e){this.errorObserverRegistry.remove(e)}register(e,t){this.registry.register(e,t)}deregister(e){this.registry.remove(e)}initProxy(){this.hasInitialValue&&(this.proxy=this.initialValues)}setValues(e){const t=Array.from(new Set([...Object.keys(e),...Object.keys(this.proxy)]));let r=!1;t.forEach(t=>{this.registry.hasNested(t)&&this.registry.getNested(t).forEach((t,i)=>{const s=this.registry.get(i),a=h(this.proxy,i),n=h(e,i);o(n,a)||(this.setFieldValue(i,n,!1),r=!0),o(n,s.proxy)||(s.context.model=n)})}),this.initProxy(),r&&this.$emit("input",Object.assign({},this.proxy))}setFieldValue(e,t,r=!0){if(void 0===t){const t=this.proxy,r=e,i=(t[r],m(t,["symbol"==typeof r?r:r+""]));this.proxy=i}else!function(e,t,r){const i=t.split(".");let o=e;for(let e=0;e<i.length;e++){const t=i[e],s=t.match(/(.+)\[(\d+)\]$/);if(s){if(void 0===o[s[1]]&&(o[s[1]]=[]),o=o[s[1]],e===i.length-1){o[s[2]]=r;break}o=o[s[2]]}else{if(e===i.length-1){o[t]=r;break}void 0===o[t]&&(o[t]={}),o=o[t]}}}(this.proxy,e,t);r&&this.$emit("input",Object.assign({},this.proxy))}hasValidationErrors(){return Promise.all(this.registry.reduce((e,t)=>(e.push(t.performValidation()&&t.hasValidationErrors()),e),[])).then(e=>e.some(e=>e))}setErrors({formErrors:e,inputErrors:t}){this.localFormErrors=e||[],this.localFieldErrors=t||{}}resetValidation(){this.localFormErrors=[],this.localFieldErrors={},this.registry.forEach(e=>{e.resetValidation()})}};function E(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}v([i.Model("input",{default:()=>({})})],b.prototype,"formularioValue",void 0),v([i.Prop({default:()=>({})})],b.prototype,"errors",void 0),v([i.Prop({default:()=>[]})],b.prototype,"formErrors",void 0),v([i.Provide()],b.prototype,"path",void 0),v([i.Watch("formularioValue",{deep:!0})],b.prototype,"onFormularioValueChanged",null),v([i.Watch("mergedFormErrors")],b.prototype,"onMergedFormErrorsChanged",null),v([i.Watch("mergedFieldErrors",{immediate:!0})],b.prototype,"onMergedFieldErrorsChanged",null),v([i.Provide()],b.prototype,"getFormValues",null),v([i.Provide()],b.prototype,"onFormularioFieldValidation",null),v([i.Provide()],b.prototype,"addErrorObserver",null),v([i.Provide()],b.prototype,"removeErrorObserver",null),v([i.Provide("formularioRegister")],b.prototype,"register",null),v([i.Provide("formularioDeregister")],b.prototype,"deregister",null),v([i.Provide("formularioSetter")],b.prototype,"setFieldValue",null),b=v([i.Component({name:"FormularioForm"})],b);const V=b;var $=function(){var e=this,t=e.$createElement;return(e._self._c||t)("form",{on:{submit:function(t){return t.preventDefault(),e.onFormSubmit(t)}}},[e._t("default",null,{errors:e.mergedFormErrors})],2)};$._withStripped=!0;const x=E({render:$,staticRenderFns:[]},void 0,V,void 0,!1,void 0,!1,void 0,void 0,void 0);function P(e){const t=[];if(e.length){let r=e.shift();t.push(r),e.forEach(e=>{e.bail||e.bail!==r.bail?(r=Object.assign({},e),t.push(r)):r.validators.push(...e.validators)})}return t}const F={BLUR:"blur",LIVE:"live",SUBMIT:"submit"};let O=class extends r{constructor(){super(...arguments),this.defaultId=this.$formulario.nextId(this),this.proxy=this.getInitialValue(),this.localErrors=[],this.validationErrors=[],this.pendingValidation=Promise.resolve()}get context(){return Object.defineProperty({id:this.id||this.defaultId,name:this.nameOrFallback,blurHandler:this.blurHandler.bind(this),errors:this.explicitErrors,allErrors:this.allErrors,performValidation:this.performValidation.bind(this),validationErrors:this.validationErrors,value:this.value},"model",{get:this.modelGetter.bind(this),set:this.modelSetter.bind(this)})}get parsedValidationRules(){const e={};return Object.keys(this.validationRules).forEach(t=>{e[s(t)]=this.validationRules[t]}),e}get messages(){const e={};return Object.keys(this.validationMessages).forEach(t=>{e[s(t)]=this.validationMessages[t]}),e}get nameOrFallback(){return""!==this.path?`${this.path}.${this.name}`:this.name}get hasErrors(){return this.allErrors.length>0}get allErrors(){return[...this.explicitErrors.map(e=>({message:e})),...n(this.validationErrors)]}get explicitErrors(){return[...n(this.errors),...this.localErrors]}get hasModel(){return d(this.$options.propsData||{},"formularioValue")}onProxyChanged(e,t){this.errorBehavior===F.LIVE?this.performValidation():this.validationErrors=[],this.hasModel||o(e,t)||(this.context.model=e)}onFormularioValueChanged(e,t){this.hasModel&&!o(e,t)&&(this.context.model=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.errorBehavior===F.LIVE&&this.performValidation()}beforeDestroy(){this.disableErrors||"function"!=typeof this.removeErrorObserver||this.removeErrorObserver(this.setErrors),"function"==typeof this.formularioDeregister&&this.formularioDeregister(this.nameOrFallback)}modelGetter(){const e=this.hasModel?"formularioValue":"proxy";return void 0===this[e]?"":this[e]}modelSetter(e){o(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"),this.errorBehavior===F.BLUR&&this.performValidation()}getInitialValue(){return d(this.$options.propsData,"value")?this.value:d(this.$options.propsData,"formularioValue")?this.formularioValue:""}applyInitialValue(){o(this.context.model,this.proxy)||(this.context.model=this.proxy)}performValidation(){return this.pendingValidation=this.validate().then(e=>{this.didValidate(e)}),this.pendingValidation}applyValidator(e){return function(e,t){return Promise.resolve(e.rule(t,...e.args))}(e,{value:this.context.model,name:this.context.name,getFormValues:this.getFormValues.bind(this)}).then(t=>!t&&this.getMessageObject(e.name,e.args))}applyValidatorGroup(e){return Promise.all(e.validators.map(this.applyValidator)).then(e=>e.filter(e=>!1!==e))}validate(){return new Promise(e=>{const t=(r,i=[])=>{if(r.length){const o=r.shift();this.applyValidatorGroup(o).then(s=>0!==s.length&&o.bail||!r.length?e(i.concat(s)):t(r,i.concat(s)))}else e([])};t(function(e){const t=([e,t,r,i])=>({validators:[{name:r,rule:e,args:t}],bail:"^"===i}),r=[],i=e.findIndex(([,,e])=>"bail"===e.toLowerCase());return i>=0?(r.push(...P(e.splice(0,i+1).slice(0,-1).map(t))),r.push(...e.map(([e,t,r])=>({validators:[{rule:e,args:t,name:r}],bail:!0})))):r.push(...P(e.map(t))),r}(l(this.validation,this.$formulario.rules(this.parsedValidationRules))))})}didValidate(e){const t=!o(e,this.validationErrors);if(this.validationErrors=e,t){const e={name:this.context.name,errors:this.validationErrors};this.$emit("validation",e),this.onFormularioFieldValidation&&"function"==typeof this.onFormularioFieldValidation&&this.onFormularioFieldValidation(e)}}getMessageObject(e,t){const r={args:t,name:this.name,value:this.context.model,formValues:this.getFormValues()};return{rule:e,context:r,message:this.getMessageFunc(e||"")(r)}}getMessageFunc(e){if(e=s(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))})})}setErrors(e){this.localErrors=n(e)}resetValidation(){this.localErrors=[],this.validationErrors=[]}};v([i.Inject({default:void 0})],O.prototype,"formularioSetter",void 0),v([i.Inject({default:()=>()=>{}})],O.prototype,"onFormularioFieldValidation",void 0),v([i.Inject({default:void 0})],O.prototype,"formularioRegister",void 0),v([i.Inject({default:void 0})],O.prototype,"formularioDeregister",void 0),v([i.Inject({default:()=>()=>({})})],O.prototype,"getFormValues",void 0),v([i.Inject({default:void 0})],O.prototype,"addErrorObserver",void 0),v([i.Inject({default:void 0})],O.prototype,"removeErrorObserver",void 0),v([i.Inject({default:""})],O.prototype,"path",void 0),v([i.Model("input",{default:""})],O.prototype,"formularioValue",void 0),v([i.Prop({default:null})],O.prototype,"id",void 0),v([i.Prop({required:!0})],O.prototype,"name",void 0),v([i.Prop({default:!1})],O.prototype,"value",void 0),v([i.Prop({default:""})],O.prototype,"validation",void 0),v([i.Prop({default:()=>({})})],O.prototype,"validationRules",void 0),v([i.Prop({default:()=>({})})],O.prototype,"validationMessages",void 0),v([i.Prop({default:()=>[]})],O.prototype,"errors",void 0),v([i.Prop({default:F.BLUR,validator:e=>[F.BLUR,F.LIVE,F.SUBMIT].includes(e)})],O.prototype,"errorBehavior",void 0),v([i.Prop({default:!1})],O.prototype,"disableErrors",void 0),v([i.Watch("proxy")],O.prototype,"onProxyChanged",null),v([i.Watch("formularioValue")],O.prototype,"onFormularioValueChanged",null),O=v([i.Component({name:"FormularioInput",inheritAttrs:!1})],O);const j=O;var N=function(){var e=this.$createElement;return(this._self._c||e)("div",{staticClass:"formulario-input"},[this._t("default",null,{id:this.id,context:this.context,violations:this.validationErrors})],2)};N._withStripped=!0;const A=E({render:N,staticRenderFns:[]},void 0,j,void 0,!1,void 0,!1,void 0,void 0,void 0);let w=class extends r{get groupPath(){return this.isArrayItem?`${this.path}[${this.name}]`:""===this.path?this.name:`${this.path}.${this.name}`}};v([i.Inject({default:""})],w.prototype,"path",void 0),v([i.Prop({required:!0})],w.prototype,"name",void 0),v([i.Prop({default:!1})],w.prototype,"isArrayItem",void 0),v([i.Provide("path")],w.prototype,"groupPath",null),w=v([i.Component({name:"FormularioGrouping"})],w);const R=w;var _=function(){var e=this.$createElement;return(this._self._c||e)("div",[this._t("default")],2)};_._withStripped=!0;const I=E({render:_,staticRenderFns:[]},void 0,R,void 0,!1,void 0,!1,void 0,void 0,void 0);return new class{constructor(){this.options={rules:c,validationMessages:p},this.idRegistry={}}install(e,t){e.prototype.$formulario=this,e.component("FormularioForm",x),e.component("FormularioGrouping",I),e.component("FormularioInput",A),this.extend(t||{})}nextId(e){const t=!(!e.$route||!e.$route.path)&&e.$route.path?e.$route.path.replace(/[/\\.\s]/g,"-"):"global";return d(this.idRegistry,t)||(this.idRegistry[t]=0),`formulario-${t}-${++this.idRegistry[t]}`}extend(e){if("object"==typeof e)return this.options=f(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 d(this.options.validationMessages,e)?this.options.validationMessages[e](r,t):this.options.validationMessages.default(r,t)}}}));