36 lines
27 KiB
JavaScript
36 lines
27 KiB
JavaScript
var VueFormulario=function(e){"use strict";
|
|
/*!
|
|
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
|
*
|
|
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
* Released under the MIT License.
|
|
*/
|
|
function t(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 r(e){var r,o;return!1!==t(e)&&("function"==typeof(r=e.constructor)&&(!1!==t(o=r.prototype)&&!1!==o.hasOwnProperty("isPrototypeOf")))}function o(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function i(e,t,n=!0){const a={};for(const s in e)o(t,s)?r(t[s])&&r(e[s])?a[s]=i(e[s],t[s],n):n&&Array.isArray(e[s])&&Array.isArray(t[s])?a[s]=e[s].concat(t[s]):a[s]=t[s]:a[s]=e[s];for(const e in t)o(a,e)||(a[e]=t[e]);return a}e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;var n=function(e){if("string"!=typeof e)return!1;var t=e.match(a);if(!t)return!1;var r=t[1];if(!r)return!1;if(s.test(r)||l.test(r))return!0;return!1},a=/^(?:\w+:)?\/\/(\S+)$/,s=/^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/,l=/^[^\s\.]+\.\S{2,}$/;function u(e){switch(typeof e){case"symbol":case"number":case"string":case"boolean":case"undefined":return!0;default:return null===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 o=0;o<r.length;o++){const i=r[o];if(e[i]!==t[i])return!1}return!0}function d(e){return e.replace(/([_][a-z0-9])/gi,t=>0!==e.indexOf(t)&&"_"!==e[e.indexOf(t)-1]?t.toUpperCase().replace("_",""):t)}function f(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}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]+$/},i=o(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=o(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(),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,formValues: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},...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))),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),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),not:({value:e},...t)=>Promise.resolve(!t.some(t=>"object"==typeof t?c(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:e})=>Promise.resolve(n(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,r=!1)=>"string"==typeof r&&r.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,r=!1)=>"string"==typeof r&&r.length?e.$t("validation.before.compare",t):e.$t("validation.before.default",t),between(e,t,r=0,o=10,i){const n=Object.assign(Object.assign({},t),{from:r,to:o});return!isNaN(t.value)&&"length"!==i||"value"===i?e.$t("validation.between.force",n):e.$t("validation.between.default",n)},confirm:(e,t)=>e.$t("validation.confirm",t),date:(e,t,r=!1)=>"string"==typeof r&&r.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,r=10,o)=>Array.isArray(t.value)?e.$tc("validation.max.array",r,t):!isNaN(t.value)&&"length"!==o||"value"===o?e.$tc("validation.max.force",r,t):e.$tc("validation.max.default",r,t),min:(e,t,r=1,o)=>Array.isArray(t.value)?e.$tc("validation.min.array",r,t):!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)};
|
|
/*! *****************************************************************************
|
|
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 v(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 m(e,t,r,o){var i,n=arguments.length,a=n<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,o);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(a=(n<3?i(a):n>3?i(t,r,a):i(t,r))||a);return n>3&&a&&Object.defineProperty(t,r,a),a
|
|
/**
|
|
* vue-class-component v7.2.3
|
|
* (c) 2015-present Evan You
|
|
* @license MIT
|
|
*/}function y(e){return(y="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 g(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function b(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 O(){return"undefined"!=typeof Reflect&&Reflect.defineMetadata&&Reflect.getOwnMetadataKeys}function E(e,t){x(e,t),Object.getOwnPropertyNames(t.prototype).forEach((function(r){x(e.prototype,t.prototype,r)})),Object.getOwnPropertyNames(t).forEach((function(r){x(e,t,r)}))}function x(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 $={__proto__:[]}instanceof Array;function _(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 j(e){"undefined"!=typeof console&&console.warn("[vue-class-component] "+e)}function N(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 n={};return Object.keys(i).forEach((function(e){void 0!==i[e]&&(n[e]=i[e])})),"production"!==process.env.NODE_ENV&&!(r.prototype instanceof e)&&Object.keys(n).length>0&&j("Component class must inherit Vue or its descendant class when class property is used."),n}var P=["data","beforeCreate","created","beforeMount","mounted","beforeDestroy","destroyed","beforeUpdate","updated","activated","deactivated","render","errorCaptured","serverPrefetch"];function V(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(P.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 g({},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 N(this,t)}});var i=t.__decorators__;i&&(i.forEach((function(e){return e(r)})),delete t.__decorators__);var n=Object.getPrototypeOf(t.prototype),a=n instanceof e?n.constructor:e,s=a.extend(r);return R(s,t,a),O()&&E(s,t),s}var w=["cid","super","options","superOptions","extendOptions","sealedOptions","component","directive","filter"],F={prototype:!0,arguments:!0,callee:!0,caller:!0};function R(e,t,r){Object.getOwnPropertyNames(t).forEach((function(o){if(!F[o]){var i=Object.getOwnPropertyDescriptor(e,o);if(!i||i.configurable){var n,a,s=Object.getOwnPropertyDescriptor(t,o);if(!$){if("cid"===o)return;var l=Object.getOwnPropertyDescriptor(r,o);if(n=s.value,a=y(n),null!=n&&("object"===a||"function"===a)&&l&&l.value===s.value)return}"production"!==process.env.NODE_ENV&&w.indexOf(o)>=0&&j("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,s)}}}))}function A(e){return"function"==typeof e?V(e):function(t){return V(t,e)}}A.registerHooks=function(e){P.push.apply(P,b(e))};function M(e){return _((function(t,r){void 0===t.inject&&(t.inject={}),Array.isArray(t.inject)||(t.inject[r]=e||r)}))}function D(e){return _((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 n=function(e){o[t.managedReactive[e]]=a[e],Object.defineProperty(o.__reactiveInject__,t.managedReactive[e],{enumerable:!0,get:function(){return r[e]}})},a=this;for(var i in t.managedReactive)n(i);return o};return t.managed={},t.managedReactive={},t}(i)),i.managed[r]=e||r}))}var S="undefined"!=typeof Reflect&&void 0!==Reflect.getMetadata;function C(e,t,r){if(S&&!Array.isArray(e)&&"function"!=typeof e&&void 0===e.type){var o=Reflect.getMetadata("design:type",t,r);o!==Object&&(e.type=o)}}function k(e,t){return void 0===t&&(t={}),function(r,o){C(t,r,o),_((function(r,o){(r.props||(r.props={}))[o]=t,r.model={prop:o,event:e||o}}))(r,o)}}function I(e){return void 0===e&&(e={}),function(t,r){C(e,t,r),_((function(t,r){(t.props||(t.props={}))[r]=e}))(t,r)}}function T(e,t){void 0===t&&(t={});var r=t.deep,o=void 0!==r&&r,i=t.immediate,n=void 0!==i&&i;return _((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:n})}))}class z{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],v(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}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=o(t.$options.propsData||{},"value");!r&&this.ctx.hasInitialValue&&void 0!==f(this.ctx.initialValues,e)?t.context.model=f(this.ctx.initialValues,e):r&&!c(t.proxy,f(this.ctx.initialValues,e))&&this.ctx.setFieldValue(e,t.proxy)}reduce(e,t){return this.registry.forEach((r,o)=>{t=e(t,r,o)}),t}}class W{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 W(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)&&o(e,t.field)&&t.callback(e[t.field])})}}let Y=class extends e{constructor(){super(...arguments),this.path="",this.proxy={},this.registry=new z(this),this.errorObserverRegistry=new W,this.localFormErrors=[],this.localFieldErrors={}}get initialValues(){return this.hasModel&&"object"==typeof this.formularioValue?Object.assign({},this.formularioValue):{}}get mergedFormErrors(){return[...this.formErrors,...this.localFormErrors]}get mergedFieldErrors(){return i(this.errors||{},this.localFieldErrors)}get hasModel(){return o(this.$options.propsData||{},"formularioValue")}get hasInitialValue(){return this.formularioValue&&"object"==typeof 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)o(t,i)&&(r[i]=u(t[i])?t[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&&o(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,o)=>{const i=this.registry.get(o),n=f(this.proxy,o),a=f(e,o);c(a,n)||(this.setFieldValue(o,a,!1),r=!0),c(a,i.proxy)||(i.context.model=a)})}),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,o=(t[r],v(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],n=t.match(/(.+)\[(\d+)\]$/);if(n){if(void 0===i[n[1]]&&(i[n[1]]=[]),i=i[n[1]],e===o.length-1){i[n[2]]=r;break}i=i[n[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))}setErrors({formErrors:e,inputErrors:t}){this.localFormErrors=e||[],this.localFieldErrors=t||{}}hasValidationErrors(){return Promise.all(this.registry.reduce((e,t)=>(e.push(t.runValidation()&&t.hasValidationErrors()),e),[])).then(e=>e.some(e=>e))}resetValidation(){this.localFormErrors=[],this.localFieldErrors={},this.registry.forEach(e=>{e.resetValidation()})}};function q(e,t,r,o,i,n,a,s,l,u){"boolean"!=typeof a&&(l=s,s=a,a=!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),n?(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(n)},c._ssrRegister=d):t&&(d=a?function(e){t.call(this,u(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,s(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}m([k("input",{default:()=>({})})],Y.prototype,"formularioValue",void 0),m([I({default:()=>({})})],Y.prototype,"errors",void 0),m([I({default:()=>[]})],Y.prototype,"formErrors",void 0),m([D()],Y.prototype,"path",void 0),m([T("formularioValue",{deep:!0})],Y.prototype,"onFormularioValueChanged",null),m([T("mergedFormErrors")],Y.prototype,"onMergedFormErrorsChanged",null),m([T("mergedFieldErrors",{deep:!0,immediate:!0})],Y.prototype,"onMergedFieldErrorsChanged",null),m([D()],Y.prototype,"getFormValues",null),m([D()],Y.prototype,"onFormularioFieldValidation",null),m([D()],Y.prototype,"addErrorObserver",null),m([D()],Y.prototype,"removeErrorObserver",null),m([D("formularioRegister")],Y.prototype,"register",null),m([D("formularioDeregister")],Y.prototype,"deregister",null),m([D("formularioSetter")],Y.prototype,"setFieldValue",null),Y=m([A({name:"FormularioForm"})],Y);const Q=Y;var U=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)};U._withStripped=!0;const B=q({render:U,staticRenderFns:[]},void 0,Q,void 0,!1,void 0,!1,void 0,void 0,void 0);let L=class extends e{get groupPath(){return this.isArrayItem?`${this.path}[${this.name}]`:""===this.path?this.name:`${this.path}.${this.name}`}};m([M({default:""})],L.prototype,"path",void 0),m([I({required:!0})],L.prototype,"name",void 0),m([I({default:!1})],L.prototype,"isArrayItem",void 0),m([D("path")],L.prototype,"groupPath",null),L=m([A({name:"FormularioGrouping"})],L);const Z=L;var K=function(){var e=this.$createElement;return(this._self._c||e)("div",[this._t("default")],2)};K._withStripped=!0;const G=q({render:K,staticRenderFns:[]},void 0,Z,void 0,!1,void 0,!1,void 0,void 0,void 0);function X(e,t,r,o){return i=>Promise.resolve(e(i,...r)).then(e=>e?null:{rule:t,args:r,context:i,message:o(i,...r)})}function H(e){return/^[\^]/.test(e.charAt(0))?[d(e.substr(1)),e.charAt(0)]:[d(e),null]}function J(e,t,r){return"function"==typeof e?[e,null,null]:Array.isArray(e)&&e.length?function(e,t,r){const i=e.slice(),n=i.shift();if("function"==typeof n)return[n,null,null];if("string"!=typeof n)throw new Error("[Formulario]: For array constraint first element must be rule name or Validator function");const[a,s]=H(n);if(o(t,a))return[X(t[a],a,i,r[a]||r.default),a,s];throw new Error("[Formulario] Can't create validator for constraint: "+JSON.stringify(e))}(e,t,r):"string"==typeof e?function(e,t,r){const i=e.split(":"),[n,a]=H(i.shift()||"");if(o(t,n))return[X(t[n],n,i.length?i.join(":").split(","):[],r[n]||r.default),n,a];throw new Error("[Formulario] Can't create validator for constraint: "+e)}(e,t,r):[()=>Promise.resolve(null),null,null]}function ee(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}function te(e,t){return new Promise(r=>{const o=(e,i=[])=>{if(e.length){const n=e.shift();(function(e,t){return Promise.all(e.validators.map(e=>e(t))).then(e=>e.filter(e=>null!==e))})(n,t).then(t=>0!==t.length&&n.bail||!e.length?r(i.concat(t)):o(e,i.concat(t)))}else r([])};o(function(e){const t=([e,,t])=>({validators:[e],bail:"^"===t}),r=[],o=e.findIndex(([,e])=>e&&"bail"===e.toLowerCase());return o>=0?(r.push(...ee(e.splice(0,o+1).slice(0,-1).map(t))),r.push(...e.map(([e])=>({validators:[e],bail:!0})))):r.push(...ee(e.map(t))),r}(e))})}const re={DEMAND:"demand",LIVE:"live",SUBMIT:"submit"};let oe=class extends e{constructor(){super(...arguments),this.proxy=this.getInitialValue(),this.localErrors=[],this.violations=[],this.validationRun=Promise.resolve()}get fullQualifiedName(){return""!==this.path?`${this.path}.${this.name}`:this.name}get model(){const e=this.hasModel?"value":"proxy";return void 0===this[e]?"":this[e]}set model(e){c(e,this.proxy)||(this.proxy=e),this.$emit("input",e),"function"==typeof this.formularioSetter&&this.formularioSetter(this.context.name,e)}get context(){return Object.defineProperty({name:this.fullQualifiedName,runValidation:this.runValidation.bind(this),violations:this.violations,errors:this.localErrors,allErrors:[...this.localErrors,...this.violations.map(e=>e.message)]},"model",{get:()=>this.model,set:e=>{this.model=e}})}get normalizedValidationRules(){const e={};return Object.keys(this.validationRules).forEach(t=>{e[d(t)]=this.validationRules[t]}),e}get normalizedValidationMessages(){const e={};return Object.keys(this.validationMessages).forEach(t=>{e[d(t)]=this.validationMessages[t]}),e}get hasModel(){return o(this.$options.propsData||{},"value")}onProxyChanged(e,t){this.hasModel||c(e,t)||(this.context.model=e),this.validationBehavior===re.LIVE?this.runValidation():this.violations=[]}onValueChanged(e,t){this.hasModel&&!c(e,t)&&(this.context.model=e)}created(){this.initProxy(),"function"==typeof this.formularioRegister&&this.formularioRegister(this.fullQualifiedName,this),"function"!=typeof this.addErrorObserver||this.errorsDisabled||this.addErrorObserver({callback:this.setErrors,type:"input",field:this.fullQualifiedName}),this.validationBehavior===re.LIVE&&this.runValidation()}beforeDestroy(){this.errorsDisabled||"function"!=typeof this.removeErrorObserver||this.removeErrorObserver(this.setErrors),"function"==typeof this.formularioDeregister&&this.formularioDeregister(this.fullQualifiedName)}getInitialValue(){return o(this.$options.propsData||{},"value")?this.value:""}initProxy(){c(this.context.model,this.proxy)||(this.context.model=this.proxy)}runValidation(){return this.validationRun=this.validate().then(e=>{const t=!c(e,this.violations);if(this.violations=e,t){const e={name:this.context.name,violations:this.violations};this.$emit("validation",e),"function"==typeof this.onFormularioFieldValidation&&this.onFormularioFieldValidation(e)}return this.violations}),this.validationRun}validate(){return te(function e(t,r,o){return"string"==typeof t?e(t.split("|").filter(e=>e.length),r,o):Array.isArray(t)?t.map(e=>J(e,r,o)):[]}(this.validation,this.$formulario.getRules(this.normalizedValidationRules),this.$formulario.getMessages(this,this.normalizedValidationMessages)),{value:this.context.model,name:this.context.name,formValues:this.getFormValues()})}hasValidationErrors(){return new Promise(e=>{this.$nextTick(()=>{this.validationRun.then(()=>e(this.violations.length>0))})})}setErrors(e){var t;this.localErrors=(t=e)?"string"==typeof t?[t]:Array.isArray(t)?t:"object"==typeof t?Object.values(t):[]:[]}resetValidation(){this.localErrors=[],this.violations=[]}};m([M({default:void 0})],oe.prototype,"formularioSetter",void 0),m([M({default:()=>()=>{}})],oe.prototype,"onFormularioFieldValidation",void 0),m([M({default:void 0})],oe.prototype,"formularioRegister",void 0),m([M({default:void 0})],oe.prototype,"formularioDeregister",void 0),m([M({default:()=>()=>({})})],oe.prototype,"getFormValues",void 0),m([M({default:void 0})],oe.prototype,"addErrorObserver",void 0),m([M({default:void 0})],oe.prototype,"removeErrorObserver",void 0),m([M({default:""})],oe.prototype,"path",void 0),m([k("input",{default:""})],oe.prototype,"value",void 0),m([I({required:!0,validator:e=>"string"==typeof e&&e.length>0})],oe.prototype,"name",void 0),m([I({default:""})],oe.prototype,"validation",void 0),m([I({default:()=>({})})],oe.prototype,"validationRules",void 0),m([I({default:()=>({})})],oe.prototype,"validationMessages",void 0),m([I({default:re.DEMAND,validator:e=>Object.values(re).includes(e)})],oe.prototype,"validationBehavior",void 0),m([I({default:!1})],oe.prototype,"errorsDisabled",void 0),m([T("proxy")],oe.prototype,"onProxyChanged",null),m([T("value")],oe.prototype,"onValueChanged",null),oe=m([A({name:"FormularioInput",inheritAttrs:!1})],oe);const ie=oe;var ne=function(){var e=this.$createElement;return(this._self._c||e)("div",{staticClass:"formulario-input"},[this._t("default",null,{context:this.context})],2)};ne._withStripped=!0;const ae=q({render:ne,staticRenderFns:[]},void 0,ie,void 0,!1,void 0,!1,void 0,void 0,void 0);return new class{constructor(){this.validationRules={},this.validationMessages={},this.validationRules=h,this.validationMessages=p}install(e,t){e.prototype.$formulario=this,e.component("FormularioForm",B),e.component("FormularioGrouping",G),e.component("FormularioInput",ae),this.extend(t||{})}extend(e){if("object"==typeof e)return this.validationRules=i(this.validationRules,e.validationRules||{}),this.validationMessages=i(this.validationMessages,e.validationMessages||{}),this;throw new Error(`[Formulario]: Formulario.extend() should be passed an object (was ${typeof e})`)}getRules(e={}){return i(this.validationRules,e)}getMessages(e,t){const r=i(this.validationMessages||{},t),o={};for(const t in r)o[t]=(o,...i)=>"string"==typeof r[t]?r[t]:r[t](e,o,...i);return o}}}(Vue);
|