1
0
mirror of synced 2024-11-25 06:46:02 +03:00
vue-formulario/dist/formulario.min.js
2020-10-23 14:15:57 +03:00

35 lines
29 KiB
JavaScript

var VueFormulario=function(e){"use strict";function t(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 o=0;o<r.length;o++){const i=r[o];if(e[i]!==t[i])return!1}return!0}function r(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 o(e){return"string"==typeof e&&/^[\^]/.test(e.charAt(0))?[r(e.substr(1)),e.charAt(0)]:[r(e),null]}function i(e){return e?"string"==typeof e?[e]:Array.isArray(e)?e:"object"==typeof e?Object.values(e):[]:[]}function a(e,t){return"string"==typeof e?a(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]=o(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,a]=o(r.shift());if(Object.prototype.hasOwnProperty.call(t,i))return[t[i],r.length?r.join(":").split(","):[],i,a];throw new Error("Unknown validation rule "+e)}return!1}(e,t)).filter(e=>!!e):[]}function s(e){switch(typeof e){case"symbol":case"number":case"string":case"boolean":case"undefined":return!0;default:return null===e}}function n(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function l(e,t){const r=t.split(".");let o=e;for(const e in r){const t=r[e].match(/(.+)\[(\d+)\]$/);if(void 0===o)return null;if(t){if(o=o[t[1]],void 0===o)return null;o=o[t[2]]}else o=o[r[e]]}return o}e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;var u=function(e){if("string"!=typeof e)return!1;var t=e.match(c);if(!t)return!1;var r=t[1];if(!r)return!1;if(d.test(r)||f.test(r))return!0;return!1},c=/^(?:\w+:)?\/\/(\S+)$/,d=/^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/,f=/^[^\s\.]+\.\S{2,}$/;var h={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(),o=e instanceof Date?e.getTime():Date.parse(e);return Promise.resolve(!isNaN(o)&&o>r)},alpha({value:e},t="default"){const r={default:/^[a-zA-ZÀ-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z]+$/},o=n(r,t)?t:"default";return Promise.resolve(r[o].test(e))},alphanumeric({value:e},t="default"){const r={default:/^[a-zA-Z0-9À-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z0-9]+$/},o=n(r,t)?t:"default";return Promise.resolve(r[o].test(e))},before({value:e},t=!1){const r=!1!==t?Date.parse(t):Date.now(),o=e instanceof Date?e.getTime():Date.parse(e);return Promise.resolve(!isNaN(o)&&o<r)},between:({value:e},t=0,r=10,o)=>Promise.resolve(null!==t&&null!==r&&!isNaN(t)&&!isNaN(r)&&(!isNaN(Number(e))&&"length"!==o||"value"===o?(e=Number(e),t=Number(t),r=Number(r),e>t&&e<r):("string"==typeof e||"length"===o)&&(e=isNaN(Number(e))?e:e.toString()).length>t&&e.length<r)),confirm:({value:e,getFormValues:t,name:r},o)=>Promise.resolve((()=>{let i=o;return i||(i=/_confirm$/.test(r)?r.substr(0,r.length-8):r+"_confirm"),t()[i]===e})()),date:({value:e},t=!1)=>Promise.resolve(t?function(e){const t=`^${r=e,r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}$`;var r;const o={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(o).reduce((e,t)=>e.replace(t,o[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},...r)=>Promise.resolve(r.some(r=>"object"==typeof r?t(r,e):r===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},...r)=>Promise.resolve(!r.some(r=>"object"==typeof r?t(r,e):r===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:e})=>Promise.resolve(u(e)),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 o=!(!Array.isArray(t.args)||!t.args[1])&&t.args[1];return!isNaN(t.value)&&"length"!==o||"value"===o?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 o=!(!Array.isArray(t.args)||!t.args[1])&&t.args[1];return!isNaN(t.value)&&"length"!==o||"value"===o?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)};
/*!
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
function m(e){return!0==(null!=(t=e)&&"object"==typeof t&&!1===Array.isArray(t))&&"[object Object]"===Object.prototype.toString.call(e);
/*!
* isobject <https://github.com/jonschlinkert/isobject>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
var t}function v(e){var t,r;return!1!==m(e)&&("function"==typeof(t=e.constructor)&&(!1!==m(r=t.prototype)&&!1!==r.hasOwnProperty("isPrototypeOf")))}function y(e,t,r=!0){const o={};for(const i in e)n(t,i)?v(t[i])&&v(e[i])?o[i]=y(e[i],t[i],r):r&&Array.isArray(e[i])&&Array.isArray(t[i])?o[i]=e[i].concat(t[i]):o[i]=t[i]:o[i]=e[i];for(const e in t)n(o,e)||(o[e]=t[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 g(e,t){var r={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(e);i<o.length;i++)t.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(e,o[i])&&(r[o[i]]=e[o[i]])}return r}function b(e,t,r,o){var i,a=arguments.length,s=a<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,o);else for(var n=e.length-1;n>=0;n--)(i=e[n])&&(s=(a<3?i(s):a>3?i(t,r,s):i(t,r))||s);return a>3&&s&&Object.defineProperty(t,r,s),s
/**
* vue-class-component v7.2.3
* (c) 2015-present Evan You
* @license MIT
*/}function O(e){return(O="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 E(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function x(e){return function(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t<e.length;t++)r[t]=e[t];return r}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function V(){return"undefined"!=typeof Reflect&&Reflect.defineMetadata&&Reflect.getOwnMetadataKeys}function $(e,t){_(e,t),Object.getOwnPropertyNames(t.prototype).forEach((function(r){_(e.prototype,t.prototype,r)})),Object.getOwnPropertyNames(t).forEach((function(r){_(e,t,r)}))}function _(e,t,r){(r?Reflect.getOwnMetadataKeys(t,r):Reflect.getOwnMetadataKeys(t)).forEach((function(o){var i=r?Reflect.getOwnMetadata(o,t,r):Reflect.getOwnMetadata(o,t);r?Reflect.defineMetadata(o,i,e,r):Reflect.defineMetadata(o,i,e)}))}var j={__proto__:[]}instanceof Array;function F(e){return function(t,r,o){var i="function"==typeof t?t:t.constructor;i.__decorators__||(i.__decorators__=[]),"number"!=typeof o&&(o=void 0),i.__decorators__.push((function(t){return e(t,r,o)}))}}function w(e){"undefined"!=typeof console&&console.warn("[vue-class-component] "+e)}function P(t,r){var o=r.prototype._init;r.prototype._init=function(){var e=this,r=Object.getOwnPropertyNames(t);if(t.$options.props)for(var o in t.$options.props)t.hasOwnProperty(o)||r.push(o);r.forEach((function(r){"_"!==r.charAt(0)&&Object.defineProperty(e,r,{get:function(){return t[r]},set:function(e){t[r]=e},configurable:!0})}))};var i=new r;r.prototype._init=o;var a={};return Object.keys(i).forEach((function(e){void 0!==i[e]&&(a[e]=i[e])})),"production"!==process.env.NODE_ENV&&!(r.prototype instanceof e)&&Object.keys(a).length>0&&w("Component class must inherit Vue or its descendant class when class property is used."),a}var N=["data","beforeCreate","created","beforeMount","mounted","beforeDestroy","destroyed","beforeUpdate","updated","activated","deactivated","render","errorCaptured","serverPrefetch"];function A(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};r.name=r.name||t._componentTag||t.name;var o=t.prototype;Object.getOwnPropertyNames(o).forEach((function(e){if("constructor"!==e)if(N.indexOf(e)>-1)r[e]=o[e];else{var t=Object.getOwnPropertyDescriptor(o,e);void 0!==t.value?"function"==typeof t.value?(r.methods||(r.methods={}))[e]=t.value:(r.mixins||(r.mixins=[])).push({data:function(){return E({},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 P(this,t)}});var i=t.__decorators__;i&&(i.forEach((function(e){return e(r)})),delete t.__decorators__);var a=Object.getPrototypeOf(t.prototype),s=a instanceof e?a.constructor:e,n=s.extend(r);return S(n,t,s),V()&&$(n,t),n}var R=["cid","super","options","superOptions","extendOptions","sealedOptions","component","directive","filter"],M={prototype:!0,arguments:!0,callee:!0,caller:!0};function S(e,t,r){Object.getOwnPropertyNames(t).forEach((function(o){if(!M[o]){var i=Object.getOwnPropertyDescriptor(e,o);if(!i||i.configurable){var a,s,n=Object.getOwnPropertyDescriptor(t,o);if(!j){if("cid"===o)return;var l=Object.getOwnPropertyDescriptor(r,o);if(a=n.value,s=O(a),null!=a&&("object"===s||"function"===s)&&l&&l.value===n.value)return}"production"!==process.env.NODE_ENV&&R.indexOf(o)>=0&&w("Static property name '".concat(o,"' 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,o,n)}}}))}function D(e){return"function"==typeof e?A(e):function(t){return A(t,e)}}D.registerHooks=function(e){N.push.apply(N,x(e))};function k(e){return F((function(t,r){void 0===t.inject&&(t.inject={}),Array.isArray(t.inject)||(t.inject[r]=e||r)}))}function I(e){return F((function(t,r){var o,i=t.provide;("function"!=typeof(o=i)||!o.managed&&!o.managedReactive)&&(i=t.provide=function(e){var t=function(){var r=this,o="function"==typeof e?e.call(this):e;for(var i in(o=Object.create(o||null)).__reactiveInject__=this.__reactiveInject__||{},t.managed)o[t.managed[i]]=this[i];var a=function(e){o[t.managedReactive[e]]=s[e],Object.defineProperty(o.__reactiveInject__,t.managedReactive[e],{enumerable:!0,get:function(){return r[e]}})},s=this;for(var i in t.managedReactive)a(i);return o};return t.managed={},t.managedReactive={},t}(i)),i.managed[r]=e||r}))}var C="undefined"!=typeof Reflect&&void 0!==Reflect.getMetadata;function T(e,t,r){if(C&&!Array.isArray(e)&&"function"!=typeof e&&void 0===e.type){var o=Reflect.getMetadata("design:type",t,r);o!==Object&&(e.type=o)}}function U(e,t){return void 0===t&&(t={}),function(r,o){T(t,r,o),F((function(r,o){(r.props||(r.props={}))[o]=t,r.model={prop:o,event:e||o}}))(r,o)}}function B(e){return void 0===e&&(e={}),function(t,r){T(e,t,r),F((function(t,r){(t.props||(t.props={}))[r]=e}))(t,r)}}function L(e,t){void 0===t&&(t={});var r=t.deep,o=void 0!==r&&r,i=t.immediate,a=void 0!==i&&i;return F((function(t,r){"object"!=typeof t.watch&&(t.watch=Object.create(null));var i=t.watch;"object"!=typeof i[e]||Array.isArray(i[e])?void 0===i[e]&&(i[e]=[]):i[e]=[i[e]],i[e].push({handler:r,deep:o,immediate:a})}))}class W{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,o=(t[r],g(t,["symbol"==typeof r?r:r+""]));this.ctx.proxy=o}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,o)=>Object.assign(t,{[o]:e(r,o)})),t}forEach(e){this.registry.forEach((t,r)=>{e(t,r)})}keys(){return Array.from(this.registry.keys())}register(e,r){if(this.registry.has(e))return;this.registry.set(e,r);const o=n(r.$options.propsData||{},"formularioValue"),i=n(r.$options.propsData||{},"value");!o&&this.ctx.hasInitialValue&&void 0!==l(this.ctx.initialValues,e)?r.context.model=l(this.ctx.initialValues,e):!o&&!i||t(r.proxy,l(this.ctx.initialValues,e))||this.ctx.setFieldValue(e,r.proxy),this.ctx.childrenShouldShowErrors&&(r.formShouldShowErrors=!0)}reduce(e,t){return this.registry.forEach((r,o)=>{t=e(t,r,o)}),t}}class G{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 G(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)&&n(e,t.field)&&t.callback(e[t.field])})}}let Y=class extends e{constructor(){super(...arguments),this.path="",this.proxy={},this.registry=new W(this),this.errorObserverRegistry=new G,this.localFormErrors=[],this.localFieldErrors={}}get mergedFormErrors(){return[...this.formErrors,...this.localFormErrors]}get mergedFieldErrors(){return y(this.errors||{},this.localFieldErrors)}get hasModel(){return n(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 o in t)Object.prototype.hasOwnProperty.call(t,o)&&(s(t[o])?r[o]=t[o]:r[o]=e(t[o]));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&&n(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 r=Array.from(new Set([...Object.keys(e),...Object.keys(this.proxy)]));let o=!1;r.forEach(r=>{this.registry.hasNested(r)&&this.registry.getNested(r).forEach((r,i)=>{const a=this.registry.get(i),s=l(this.proxy,i),n=l(e,i);t(n,s)||(this.setFieldValue(i,n,!1),o=!0),t(n,a.proxy)||(a.context.model=n)})}),this.initProxy(),o&&this.$emit("input",Object.assign({},this.proxy))}setFieldValue(e,t,r=!0){if(void 0===t){const t=this.proxy,r=e,o=(t[r],g(t,["symbol"==typeof r?r:r+""]));this.proxy=o}else!function(e,t,r){const o=t.split(".");let i=e;for(let e=0;e<o.length;e++){const t=o[e],a=t.match(/(.+)\[(\d+)\]$/);if(a){if(void 0===i[a[1]]&&(i[a[1]]=[]),i=i[a[1]],e===o.length-1){i[a[2]]=r;break}i=i[a[2]]}else{if(e===o.length-1){i[t]=r;break}void 0===i[t]&&(i[t]={}),i=i[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 q(e,t,r,o,i,a,s,n,l,u){"boolean"!=typeof s&&(l=n,n=s,s=!1);const c="function"==typeof r?r.options:r;let d;if(e&&e.render&&(c.render=e.render,c.staticRenderFns=e.staticRenderFns,c._compiled=!0,i&&(c.functional=!0)),o&&(c._scopeId=o),a?(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(a)},c._ssrRegister=d):t&&(d=s?function(e){t.call(this,u(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,n(e))}),d)if(c.functional){const e=c.render;c.render=function(t,r){return d.call(r),e(t,r)}}else{const e=c.beforeCreate;c.beforeCreate=e?[].concat(e,d):[d]}return r}b([U("input",{default:()=>({})})],Y.prototype,"formularioValue",void 0),b([B({default:()=>({})})],Y.prototype,"errors",void 0),b([B({default:()=>[]})],Y.prototype,"formErrors",void 0),b([I()],Y.prototype,"path",void 0),b([L("formularioValue",{deep:!0})],Y.prototype,"onFormularioValueChanged",null),b([L("mergedFormErrors")],Y.prototype,"onMergedFormErrorsChanged",null),b([L("mergedFieldErrors",{immediate:!0})],Y.prototype,"onMergedFieldErrorsChanged",null),b([I()],Y.prototype,"getFormValues",null),b([I()],Y.prototype,"onFormularioFieldValidation",null),b([I()],Y.prototype,"addErrorObserver",null),b([I()],Y.prototype,"removeErrorObserver",null),b([I("formularioRegister")],Y.prototype,"register",null),b([I("formularioDeregister")],Y.prototype,"deregister",null),b([I("formularioSetter")],Y.prototype,"setFieldValue",null),Y=b([D({name:"FormularioForm"})],Y);const z=Y;var H=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)};H._withStripped=!0;const Z=q({render:H,staticRenderFns:[]},void 0,z,void 0,!1,void 0,!1,void 0,void 0,void 0);function K(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 X={BLUR:"blur",LIVE:"live",SUBMIT:"submit"};let J=class extends e{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[r(t)]=this.validationRules[t]}),e}get messages(){const e={};return Object.keys(this.validationMessages).forEach(t=>{e[r(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})),...i(this.validationErrors)]}get explicitErrors(){return[...i(this.errors),...this.localErrors]}get hasModel(){return n(this.$options.propsData||{},"formularioValue")}onProxyChanged(e,r){this.errorBehavior===X.LIVE?this.performValidation():this.validationErrors=[],this.hasModel||t(e,r)||(this.context.model=e)}onFormularioValueChanged(e,r){this.hasModel&&!t(e,r)&&(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===X.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){t(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===X.BLUR&&this.performValidation()}getInitialValue(){return n(this.$options.propsData,"value")?this.value:n(this.$options.propsData,"formularioValue")?this.formularioValue:""}applyInitialValue(){t(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,o=[])=>{if(r.length){const i=r.shift();this.applyValidatorGroup(i).then(a=>0!==a.length&&i.bail||!r.length?e(o.concat(a)):t(r,o.concat(a)))}else e([])};t(function(e){const t=([e,t,r,o])=>({validators:[{name:r,rule:e,args:t}],bail:"^"===o}),r=[],o=e.findIndex(([,,e])=>"bail"===e.toLowerCase());return o>=0?(r.push(...K(e.splice(0,o+1).slice(0,-1).map(t))),r.push(...e.map(([e,t,r])=>({validators:[{rule:e,args:t,name:r}],bail:!0})))):r.push(...K(e.map(t))),r}(a(this.validation,this.$formulario.rules(this.parsedValidationRules))))})}didValidate(e){const r=!t(e,this.validationErrors);if(this.validationErrors=e,r){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=r(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=i(e)}resetValidation(){this.localErrors=[],this.validationErrors=[]}};b([k({default:void 0})],J.prototype,"formularioSetter",void 0),b([k({default:()=>()=>{}})],J.prototype,"onFormularioFieldValidation",void 0),b([k({default:void 0})],J.prototype,"formularioRegister",void 0),b([k({default:void 0})],J.prototype,"formularioDeregister",void 0),b([k({default:()=>()=>({})})],J.prototype,"getFormValues",void 0),b([k({default:void 0})],J.prototype,"addErrorObserver",void 0),b([k({default:void 0})],J.prototype,"removeErrorObserver",void 0),b([k({default:""})],J.prototype,"path",void 0),b([U("input",{default:""})],J.prototype,"formularioValue",void 0),b([B({default:null})],J.prototype,"id",void 0),b([B({required:!0})],J.prototype,"name",void 0),b([B({default:!1})],J.prototype,"value",void 0),b([B({default:""})],J.prototype,"validation",void 0),b([B({default:()=>({})})],J.prototype,"validationRules",void 0),b([B({default:()=>({})})],J.prototype,"validationMessages",void 0),b([B({default:()=>[]})],J.prototype,"errors",void 0),b([B({default:X.BLUR,validator:e=>[X.BLUR,X.LIVE,X.SUBMIT].includes(e)})],J.prototype,"errorBehavior",void 0),b([B({default:!1})],J.prototype,"disableErrors",void 0),b([L("proxy")],J.prototype,"onProxyChanged",null),b([L("formularioValue")],J.prototype,"onFormularioValueChanged",null),J=b([D({name:"FormularioInput",inheritAttrs:!1})],J);const Q=J;var ee=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)};ee._withStripped=!0;const te=q({render:ee,staticRenderFns:[]},void 0,Q,void 0,!1,void 0,!1,void 0,void 0,void 0);let re=class extends e{get groupPath(){return this.isArrayItem?`${this.path}[${this.name}]`:""===this.path?this.name:`${this.path}.${this.name}`}};b([k({default:""})],re.prototype,"path",void 0),b([B({required:!0})],re.prototype,"name",void 0),b([B({default:!1})],re.prototype,"isArrayItem",void 0),b([I("path")],re.prototype,"groupPath",null),re=b([D({name:"FormularioGrouping"})],re);const oe=re;var ie=function(){var e=this.$createElement;return(this._self._c||e)("div",[this._t("default")],2)};ie._withStripped=!0;const ae=q({render:ie,staticRenderFns:[]},void 0,oe,void 0,!1,void 0,!1,void 0,void 0,void 0);return new class{constructor(){this.options={rules:h,validationMessages:p},this.idRegistry={}}install(e,t){e.prototype.$formulario=this,e.component("FormularioForm",Z),e.component("FormularioGrouping",ae),e.component("FormularioInput",te),this.extend(t||{})}nextId(e){const t=!(!e.$route||!e.$route.path)&&e.$route.path?e.$route.path.replace(/[/\\.\s]/g,"-"):"global";return n(this.idRegistry,t)||(this.idRegistry[t]=0),`formulario-${t}-${++this.idRegistry[t]}`}extend(e){if("object"==typeof e)return this.options=y(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 n(this.options.validationMessages,e)?this.options.validationMessages[e](r,t):this.options.validationMessages.default(r,t)}}}(Vue);