From 947722b5db52712808c4e1b71f653602d04c17a3 Mon Sep 17 00:00:00 2001 From: 1on Date: Tue, 27 Oct 2020 10:50:02 +0300 Subject: [PATCH] 0.3.0 --- dist/formulario.esm.js | 5 ++-- dist/formulario.min.js | 57 +++++++++++++++++++++--------------------- dist/formulario.umd.js | 5 ++-- package.json | 2 +- 4 files changed, 36 insertions(+), 33 deletions(-) diff --git a/dist/formulario.esm.js b/dist/formulario.esm.js index e9d61b1..cbf81d9 100644 --- a/dist/formulario.esm.js +++ b/dist/formulario.esm.js @@ -1,4 +1,4 @@ -import t from"is-url";import e from"is-plain-object";import r from"vue";import{Model as i,Prop as o,Provide as s,Watch as a,Component as n,Inject as l}from"vue-property-decorator";function u(t,e){if(t===e)return!0;if(!t||!e)return!1;const r=Object.keys(t);if(Object.keys(e).length!==r.length)return!1;if(t instanceof Date&&e instanceof Date)return t.getTime()===e.getTime();if(0===r.length)return t===e;for(let i=0;i0!==t.indexOf(e)&&"_"!==t[t.indexOf(e)-1]?e.toUpperCase().replace("_",""):e):t}function h(t){return"string"==typeof t&&/^[\^]/.test(t.charAt(0))?[d(t.substr(1)),t.charAt(0)]:[d(t),null]}function c(t){return t?"string"==typeof t?[t]:Array.isArray(t)?t:"object"==typeof t?Object.values(t):[]:[]}function p(t,e){return"string"==typeof t?p(t.split("|").filter(t=>t.length),e):Array.isArray(t)?t.map(t=>function(t,e){if("function"==typeof t)return[t,[]];if(Array.isArray(t)&&t.length){t=t.slice();const[r,i]=h(t.shift());if("string"==typeof r&&Object.prototype.hasOwnProperty.call(e,r))return[e[r],t,r,i];if("function"==typeof r)return[r,t,r,i]}if("string"==typeof t){const r=t.split(":"),[i,o]=h(r.shift());if(Object.prototype.hasOwnProperty.call(e,i))return[e[i],r.length?r.join(":").split(","):[],i,o];throw new Error("Unknown validation rule "+t)}return!1}(t,e)).filter(t=>!!t):[]}function f(t){switch(typeof t){case"symbol":case"number":case"string":case"boolean":case"undefined":return!0;default:return null===t}}function m(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function v(t,e){const r=e.split(".");let i=t;for(const t in r){const e=r[t].match(/(.+)\[(\d+)\]$/);if(void 0===i)return null;if(e){if(i=i[e[1]],void 0===i)return null;i=i[e[2]]}else i=i[r[t]]}return i}var g={accepted:({value:t})=>Promise.resolve(["yes","on","1",1,!0,"true"].includes(t)),after({value:t},e=!1){const r=!1!==e?Date.parse(e):Date.now(),i=t instanceof Date?t.getTime():Date.parse(t);return Promise.resolve(!isNaN(i)&&i>r)},alpha({value:t},e="default"){const r={default:/^[a-zA-ZÀ-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z]+$/},i=m(r,e)?e:"default";return Promise.resolve(r[i].test(t))},alphanumeric({value:t},e="default"){const r={default:/^[a-zA-Z0-9À-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z0-9]+$/},i=m(r,e)?e:"default";return Promise.resolve(r[i].test(t))},before({value:t},e=!1){const r=!1!==e?Date.parse(e):Date.now(),i=t instanceof Date?t.getTime():Date.parse(t);return Promise.resolve(!isNaN(i)&&iPromise.resolve(null!==e&&null!==r&&!isNaN(e)&&!isNaN(r)&&(!isNaN(Number(t))&&"length"!==i||"value"===i?(t=Number(t),e=Number(e),r=Number(r),t>e&&te&&t.lengthPromise.resolve((()=>{let o=i;return o||(o=/_confirm$/.test(r)?r.substr(0,r.length-8):r+"_confirm"),e()[o]===t})()),date:({value:t},e=!1)=>Promise.resolve(e?function(t){const e=`^${r=t,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((t,e)=>t.replace(e,i[e]),e))}(e).test(t):!isNaN(Date.parse(t))),email({value:t}){if(!t)return Promise.resolve(!0);return Promise.resolve(/^(([^<>()\[\].,;:\s@"]+(\.[^<>()\[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/i.test(t))},endsWith:({value:t},...e)=>t?"string"==typeof t?Promise.resolve(0===e.length||e.some(e=>t.endsWith(e))):Promise.resolve(!1):Promise.resolve(!0),in:({value:t},...e)=>Promise.resolve(e.some(e=>"object"==typeof e?u(e,t):e===t)),matches:({value:t},...e)=>Promise.resolve(!!e.find(e=>("string"==typeof e&&"/"===e.substr(0,1)&&"/"===e.substr(-1)&&(e=new RegExp(e.substr(1,e.length-2))),e instanceof RegExp?e.test(t):e===t))),min:({value:t},e=1,r)=>Promise.resolve(Array.isArray(t)?(e=isNaN(e)?e:Number(e),t.length>=e):!isNaN(t)&&"length"!==r||"value"===r?(t=isNaN(t)?t:Number(t))>=e:("string"==typeof t||"length"===r)&&(t=isNaN(t)?t:t.toString()).length>=e),max:({value:t},e=10,r)=>Promise.resolve(Array.isArray(t)?(e=isNaN(Number(e))?e:Number(e),t.length<=e):!isNaN(t)&&"length"!==r||"value"===r?(t=isNaN(t)?t:Number(t))<=e:("string"==typeof t||"length"===r)&&(t=isNaN(t)?t:t.toString()).length<=e),not:({value:t},...e)=>Promise.resolve(!e.some(e=>"object"==typeof e?u(e,t):e===t)),number:({value:t})=>Promise.resolve(String(t).length>0&&!isNaN(Number(t))),required:({value:t},e=!0)=>Promise.resolve(!(e&&!["no","false"].includes(e)&&(Array.isArray(t)?!t.length:"string"==typeof t?!t:!("object"!=typeof t||t&&Object.keys(t).length)))),startsWith:({value:t},...e)=>t?"string"==typeof t?Promise.resolve(0===e.length||e.some(e=>t.startsWith(e))):Promise.resolve(!1):Promise.resolve(!0),url:({value:e})=>Promise.resolve(t(e)),bail:()=>Promise.resolve(!0)},y={default:(t,e)=>t.$t("validation.default",e),accepted:(t,e)=>t.$t("validation.accepted",e),after:(t,e)=>Array.isArray(e.args)&&e.args.length?t.$t("validation.after.compare",e):t.$t("validation.after.default",e),alpha:(t,e)=>t.$t("validation.alpha",e),alphanumeric:(t,e)=>t.$t("validation.alphanumeric",e),before:(t,e)=>Array.isArray(e.args)&&e.args.length?t.$t("validation.before.compare",e):t.$t("validation.before.default",e),between(t,e){const r=!(!Array.isArray(e.args)||!e.args[2])&&e.args[2];return!isNaN(e.value)&&"length"!==r||"value"===r?t.$t("validation.between.force",e):t.$t("validation.between.default",e)},confirm:(t,e)=>t.$t("validation.confirm",e),date:(t,e)=>Array.isArray(e.args)&&e.args.length?t.$t("validation.date.format",e):t.$t("validation.date.default",e),email:(t,e)=>t.$t("validation.email.default",e),endsWith:(t,e)=>t.$t("validation.endsWith.default",e),in:function(t,e){return"string"==typeof e.value&&e.value?t.$t("validation.in.string",e):t.$t("validation.in.default",e)},matches:(t,e)=>t.$t("validation.matches.default",e),max(t,e){const r=e.args[0];if(Array.isArray(e.value))return t.$tc("validation.max.array",r,e);const i=!(!Array.isArray(e.args)||!e.args[1])&&e.args[1];return!isNaN(e.value)&&"length"!==i||"value"===i?t.$tc("validation.max.force",r,e):t.$tc("validation.max.default",r,e)},mime:(t,e)=>e.args[0]?t.$t("validation.mime.default",e):t.$t("validation.mime.no_formats_allowed",e),min(t,e){const r=e.args[0];if(Array.isArray(e.value))return t.$tc("validation.min.array",r,e);const i=!(!Array.isArray(e.args)||!e.args[1])&&e.args[1];return!isNaN(e.value)&&"length"!==i||"value"===i?t.$tc("validation.min.force",r,e):t.$tc("validation.min.default",r,e)},not:(t,e)=>t.$t("validation.not.default",e),number:(t,e)=>t.$t("validation.number.default",e),required:(t,e)=>t.$t("validation.required.default",e),startsWith:(t,e)=>t.$t("validation.startsWith.default",e),url:(t,e)=>t.$t("validation.url.default",e)};function b(t,r,i=!0){const o={};for(const s in t)m(r,s)?e(r[s])&&e(t[s])?o[s]=b(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 t in r)m(o,t)||(o[t]=r[t]);return o} +import e from"is-plain-object";import t from"is-url";import r from"vue";import{Model as i,Prop as o,Provide as s,Watch as a,Component as n,Inject as l}from"vue-property-decorator";function u(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function d(t,r,i=!0){const o={};for(const s in t)u(r,s)?e(r[s])&&e(t[s])?o[s]=d(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)u(o,e)||(o[e]=r[e]);return o}function h(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 i=0;i0!==e.indexOf(t)&&"_"!==e[e.indexOf(t)-1]?t.toUpperCase().replace("_",""):t)}function p(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 v={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=u(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=u(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((()=>{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?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(t(e)),bail:()=>Promise.resolve(!0)},m={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,i=10,o){const s=Object.assign(Object.assign({},t),{from:r,to:i});return!isNaN(t.value)&&"length"!==o||"value"===o?e.$t("validation.between.force",s):e.$t("validation.between.default",s)},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,i)=>Array.isArray(t.value)?e.$tc("validation.max.array",r,t):!isNaN(t.value)&&"length"!==i||"value"===i?e.$tc("validation.max.force",r,t):e.$tc("validation.max.default",r,t),min:(e,t,r=1,i)=>Array.isArray(t.value)?e.$tc("validation.min.array",r,t):!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)}; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. @@ -12,4 +12,5 @@ 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,e){var r={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(r[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(t);o=0;n--)(o=t[n])&&(a=(s<3?o(a):s>3?o(e,r,a):o(e,r))||a);return s>3&&a&&Object.defineProperty(e,r,a),a}class V{constructor(t){this.registry=new Map,this.ctx=t}add(t,e){this.registry.set(t,e)}remove(t){this.registry.delete(t);const e=this.ctx.proxy,r=t,i=(e[r],E(e,["symbol"==typeof r?r:r+""]));this.ctx.proxy=i}has(t){return this.registry.has(t)}hasNested(t){for(const e of this.registry.keys())if(e===t||e.includes(t+"."))return!0;return!1}get(t){return this.registry.get(t)}getNested(t){const e=new Map;for(const r of this.registry.keys())(r===t||r.includes(t+"."))&&e.set(r,this.registry.get(r));return e}map(t){const e={};return this.registry.forEach((r,i)=>Object.assign(e,{[i]:t(r,i)})),e}forEach(t){this.registry.forEach((e,r)=>{t(e,r)})}keys(){return Array.from(this.registry.keys())}register(t,e){if(this.registry.has(t))return;this.registry.set(t,e);const r=m(e.$options.propsData||{},"formularioValue"),i=m(e.$options.propsData||{},"value");!r&&this.ctx.hasInitialValue&&void 0!==v(this.ctx.initialValues,t)?e.context.model=v(this.ctx.initialValues,t):!r&&!i||u(e.proxy,v(this.ctx.initialValues,t))||this.ctx.setFieldValue(t,e.proxy),this.ctx.childrenShouldShowErrors&&(e.formShouldShowErrors=!0)}reduce(t,e){return this.registry.forEach((r,i)=>{e=t(e,r,i)}),e}}class x{constructor(t=[]){this.observers=[],this.observers=t}add(t){this.observers.some(e=>e.callback===t.callback)||this.observers.push(t)}remove(t){this.observers=this.observers.filter(e=>e.callback!==t)}filter(t){return new x(this.observers.filter(t))}some(t){return this.observers.some(t)}observe(t){this.observers.forEach(e=>{"form"===e.type?e.callback(t):e.field&&!Array.isArray(t)&&m(t,e.field)&&e.callback(t[e.field])})}}let F=class extends r{constructor(){super(...arguments),this.path="",this.proxy={},this.registry=new V(this),this.errorObserverRegistry=new x,this.localFormErrors=[],this.localFieldErrors={}}get mergedFormErrors(){return[...this.formErrors,...this.localFormErrors]}get mergedFieldErrors(){return b(this.errors||{},this.localFieldErrors)}get hasModel(){return m(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(t){this.hasModel&&t&&"object"==typeof t&&this.setValues(t)}onMergedFormErrorsChanged(t){this.errorObserverRegistry.filter(t=>"form"===t.type).observe(t)}onMergedFieldErrorsChanged(t){this.errorObserverRegistry.filter(t=>"input"===t.type).observe(t)}created(){this.initProxy()}getFormValues(){return this.proxy}onFormSubmit(){return this.hasValidationErrors().then(t=>t?void 0:function t(e){if("object"!=typeof e)return e;const r=Array.isArray(e)?[]:{};for(const i in e)Object.prototype.hasOwnProperty.call(e,i)&&(f(e[i])?r[i]=e[i]:r[i]=t(e[i]));return r}(this.proxy)).then(t=>{void 0!==t?this.$emit("submit",t):this.$emit("error")})}onFormularioFieldValidation(t){this.$emit("validation",t)}addErrorObserver(t){this.errorObserverRegistry.add(t),"form"===t.type?t.callback(this.mergedFormErrors):t.field&&m(this.mergedFieldErrors,t.field)&&t.callback(this.mergedFieldErrors[t.field])}removeErrorObserver(t){this.errorObserverRegistry.remove(t)}register(t,e){this.registry.register(t,e)}deregister(t){this.registry.remove(t)}initProxy(){this.hasInitialValue&&(this.proxy=this.initialValues)}setValues(t){const e=Array.from(new Set([...Object.keys(t),...Object.keys(this.proxy)]));let r=!1;e.forEach(e=>{this.registry.hasNested(e)&&this.registry.getNested(e).forEach((e,i)=>{const o=this.registry.get(i),s=v(this.proxy,i),a=v(t,i);u(a,s)||(this.setFieldValue(i,a,!1),r=!0),u(a,o.proxy)||(o.context.model=a)})}),this.initProxy(),r&&this.$emit("input",Object.assign({},this.proxy))}setFieldValue(t,e,r=!0){if(void 0===e){const e=this.proxy,r=t,i=(e[r],E(e,["symbol"==typeof r?r:r+""]));this.proxy=i}else!function(t,e,r){const i=e.split(".");let o=t;for(let t=0;t(t.push(e.performValidation()&&e.hasValidationErrors()),t),[])).then(t=>t.some(t=>t))}setErrors({formErrors:t,inputErrors:e}){this.localFormErrors=t||[],this.localFieldErrors=e||{}}resetValidation(){this.localFormErrors=[],this.localFieldErrors={},this.registry.forEach(t=>{t.resetValidation()})}};function O(t,e,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(t&&t.render&&(d.render=t.render,d.staticRenderFns=t.staticRenderFns,d._compiled=!0,o&&(d.functional=!0)),i&&(d._scopeId=i),s?(h=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__),e&&e.call(this,l(t)),t&&t._registeredComponents&&t._registeredComponents.add(s)},d._ssrRegister=h):e&&(h=a?function(t){e.call(this,u(t,this.$root.$options.shadowRoot))}:function(t){e.call(this,n(t))}),h)if(d.functional){const t=d.render;d.render=function(e,r){return h.call(r),t(e,r)}}else{const t=d.beforeCreate;d.beforeCreate=t?[].concat(t,h):[h]}return r}$([i("input",{default:()=>({})})],F.prototype,"formularioValue",void 0),$([o({default:()=>({})})],F.prototype,"errors",void 0),$([o({default:()=>[]})],F.prototype,"formErrors",void 0),$([s()],F.prototype,"path",void 0),$([a("formularioValue",{deep:!0})],F.prototype,"onFormularioValueChanged",null),$([a("mergedFormErrors")],F.prototype,"onMergedFormErrorsChanged",null),$([a("mergedFieldErrors",{immediate:!0})],F.prototype,"onMergedFieldErrorsChanged",null),$([s()],F.prototype,"getFormValues",null),$([s()],F.prototype,"onFormularioFieldValidation",null),$([s()],F.prototype,"addErrorObserver",null),$([s()],F.prototype,"removeErrorObserver",null),$([s("formularioRegister")],F.prototype,"register",null),$([s("formularioDeregister")],F.prototype,"deregister",null),$([s("formularioSetter")],F.prototype,"setFieldValue",null),F=$([n({name:"FormularioForm"})],F);const N=F;var P=function(){var t=this,e=t.$createElement;return(t._self._c||e)("form",{on:{submit:function(e){return e.preventDefault(),t.onFormSubmit(e)}}},[t._t("default",null,{errors:t.mergedFormErrors})],2)};P._withStripped=!0;const A=O({render:P,staticRenderFns:[]},void 0,N,void 0,!1,void 0,!1,void 0,void 0,void 0);function j(t){const e=[];if(t.length){let r=t.shift();e.push(r),t.forEach(t=>{t.bail||t.bail!==r.bail?(r=Object.assign({},t),e.push(r)):r.validators.push(...t.validators)})}return e}const w={BLUR:"blur",LIVE:"live",SUBMIT:"submit"};let R=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 t={};return Object.keys(this.validationRules).forEach(e=>{t[d(e)]=this.validationRules[e]}),t}get messages(){const t={};return Object.keys(this.validationMessages).forEach(e=>{t[d(e)]=this.validationMessages[e]}),t}get nameOrFallback(){return""!==this.path?`${this.path}.${this.name}`:this.name}get hasErrors(){return this.allErrors.length>0}get allErrors(){return[...this.explicitErrors.map(t=>({message:t})),...c(this.validationErrors)]}get explicitErrors(){return[...c(this.errors),...this.localErrors]}get hasModel(){return m(this.$options.propsData||{},"formularioValue")}onProxyChanged(t,e){this.errorBehavior===w.LIVE?this.performValidation():this.validationErrors=[],this.hasModel||u(t,e)||(this.context.model=t)}onFormularioValueChanged(t,e){this.hasModel&&!u(t,e)&&(this.context.model=t)}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===w.LIVE&&this.performValidation()}beforeDestroy(){this.disableErrors||"function"!=typeof this.removeErrorObserver||this.removeErrorObserver(this.setErrors),"function"==typeof this.formularioDeregister&&this.formularioDeregister(this.nameOrFallback)}modelGetter(){const t=this.hasModel?"formularioValue":"proxy";return void 0===this[t]?"":this[t]}modelSetter(t){u(t,this.proxy)||(this.proxy=t),this.$emit("input",t),this.context.name&&"function"==typeof this.formularioSetter&&this.formularioSetter(this.context.name,t)}blurHandler(){this.$emit("blur"),this.errorBehavior===w.BLUR&&this.performValidation()}getInitialValue(){return m(this.$options.propsData,"value")?this.value:m(this.$options.propsData,"formularioValue")?this.formularioValue:""}applyInitialValue(){u(this.context.model,this.proxy)||(this.context.model=this.proxy)}performValidation(){return this.pendingValidation=this.validate().then(t=>{this.didValidate(t)}),this.pendingValidation}applyValidator(t){return function(t,e){return Promise.resolve(t.rule(e,...t.args))}(t,{value:this.context.model,name:this.context.name,getFormValues:this.getFormValues.bind(this)}).then(e=>!e&&this.getMessageObject(t.name,t.args))}applyValidatorGroup(t){return Promise.all(t.validators.map(this.applyValidator)).then(t=>t.filter(t=>!1!==t))}validate(){return new Promise(t=>{const e=(r,i=[])=>{if(r.length){const o=r.shift();this.applyValidatorGroup(o).then(s=>0!==s.length&&o.bail||!r.length?t(i.concat(s)):e(r,i.concat(s)))}else t([])};e(function(t){const e=([t,e,r,i])=>({validators:[{name:r,rule:t,args:e}],bail:"^"===i}),r=[],i=t.findIndex(([,,t])=>"bail"===t.toLowerCase());return i>=0?(r.push(...j(t.splice(0,i+1).slice(0,-1).map(e))),r.push(...t.map(([t,e,r])=>({validators:[{rule:t,args:e,name:r}],bail:!0})))):r.push(...j(t.map(e))),r}(p(this.validation,this.$formulario.rules(this.parsedValidationRules))))})}didValidate(t){const e=!u(t,this.validationErrors);if(this.validationErrors=t,e){const t={name:this.context.name,errors:this.validationErrors};this.$emit("validation",t),this.onFormularioFieldValidation&&"function"==typeof this.onFormularioFieldValidation&&this.onFormularioFieldValidation(t)}}getMessageObject(t,e){const r={args:e,name:this.name,value:this.context.model,formValues:this.getFormValues()};return{rule:t,context:r,message:this.getMessageFunc(t||"")(r)}}getMessageFunc(t){if(t=d(t),this.messages&&void 0!==this.messages[t])switch(typeof this.messages[t]){case"function":return this.messages[t];case"string":case"boolean":return()=>this.messages[t]}return e=>this.$formulario.validationMessage(t,e,this)}hasValidationErrors(){return new Promise(t=>{this.$nextTick(()=>{this.pendingValidation.then(()=>t(!!this.validationErrors.length))})})}setErrors(t){this.localErrors=c(t)}resetValidation(){this.localErrors=[],this.validationErrors=[]}};$([l({default:void 0})],R.prototype,"formularioSetter",void 0),$([l({default:()=>()=>{}})],R.prototype,"onFormularioFieldValidation",void 0),$([l({default:void 0})],R.prototype,"formularioRegister",void 0),$([l({default:void 0})],R.prototype,"formularioDeregister",void 0),$([l({default:()=>()=>({})})],R.prototype,"getFormValues",void 0),$([l({default:void 0})],R.prototype,"addErrorObserver",void 0),$([l({default:void 0})],R.prototype,"removeErrorObserver",void 0),$([l({default:""})],R.prototype,"path",void 0),$([i("input",{default:""})],R.prototype,"formularioValue",void 0),$([o({default:null})],R.prototype,"id",void 0),$([o({required:!0})],R.prototype,"name",void 0),$([o({default:!1})],R.prototype,"value",void 0),$([o({default:""})],R.prototype,"validation",void 0),$([o({default:()=>({})})],R.prototype,"validationRules",void 0),$([o({default:()=>({})})],R.prototype,"validationMessages",void 0),$([o({default:()=>[]})],R.prototype,"errors",void 0),$([o({default:w.BLUR,validator:t=>[w.BLUR,w.LIVE,w.SUBMIT].includes(t)})],R.prototype,"errorBehavior",void 0),$([o({default:!1})],R.prototype,"disableErrors",void 0),$([a("proxy")],R.prototype,"onProxyChanged",null),$([a("formularioValue")],R.prototype,"onFormularioValueChanged",null),R=$([n({name:"FormularioInput",inheritAttrs:!1})],R);const _=R;var M=function(){var t=this.$createElement;return(this._self._c||t)("div",{staticClass:"formulario-input"},[this._t("default",null,{id:this.id,context:this.context,violations:this.validationErrors})],2)};M._withStripped=!0;const k=O({render:M,staticRenderFns:[]},void 0,_,void 0,!1,void 0,!1,void 0,void 0,void 0);let S=class extends r{get groupPath(){return this.isArrayItem?`${this.path}[${this.name}]`:""===this.path?this.name:`${this.path}.${this.name}`}};$([l({default:""})],S.prototype,"path",void 0),$([o({required:!0})],S.prototype,"name",void 0),$([o({default:!1})],S.prototype,"isArrayItem",void 0),$([s("path")],S.prototype,"groupPath",null),S=$([n({name:"FormularioGrouping"})],S);const D=S;var I=function(){var t=this.$createElement;return(this._self._c||t)("div",[this._t("default")],2)};I._withStripped=!0;const C=O({render:I,staticRenderFns:[]},void 0,D,void 0,!1,void 0,!1,void 0,void 0,void 0);var T=new class{constructor(){this.options={rules:g,validationMessages:y},this.idRegistry={}}install(t,e){t.prototype.$formulario=this,t.component("FormularioForm",A),t.component("FormularioGrouping",C),t.component("FormularioInput",k),this.extend(e||{})}nextId(t){const e=!(!t.$route||!t.$route.path)&&t.$route.path?t.$route.path.replace(/[/\\.\s]/g,"-"):"global";return m(this.idRegistry,e)||(this.idRegistry[e]=0),`formulario-${e}-${++this.idRegistry[e]}`}extend(t){if("object"==typeof t)return this.options=b(this.options,t),this;throw new Error(`VueFormulario extend() should be passed an object (was ${typeof t})`)}rules(t={}){return Object.assign(Object.assign({},this.options.rules),t)}validationMessage(t,e,r){return m(this.options.validationMessages,t)?this.options.validationMessages[t](r,e):this.options.validationMessages.default(r,e)}};export default T; +***************************************************************************** */ +function y(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 b{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],y(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}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=u(t.$options.propsData||{},"value");!r&&this.ctx.hasInitialValue&&void 0!==p(this.ctx.initialValues,e)?t.context.model=p(this.ctx.initialValues,e):r&&!c(t.proxy,p(this.ctx.initialValues,e))&&this.ctx.setFieldValue(e,t.proxy)}reduce(e,t){return this.registry.forEach((r,i)=>{t=e(t,r,i)}),t}}class E{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 E(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)&&u(e,t.field)&&t.callback(e[t.field])})}}let x=class extends r{constructor(){super(...arguments),this.path="",this.proxy={},this.registry=new b(this),this.errorObserverRegistry=new E,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 d(this.errors||{},this.localFieldErrors)}get hasModel(){return u(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)u(t,i)&&(r[i]=h(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&&u(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 o=this.registry.get(i),s=p(this.proxy,i),a=p(e,i);c(a,s)||(this.setFieldValue(i,a,!1),r=!0),c(a,o.proxy)||(o.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,i=(t[r],y(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.runValidation()&&t.hasValidationErrors()),e),[])).then(e=>e.some(e=>e))}resetValidation(){this.localFormErrors=[],this.localFieldErrors={},this.registry.forEach(e=>{e.resetValidation()})}};function $(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}g([i("input",{default:()=>({})})],x.prototype,"formularioValue",void 0),g([o({default:()=>({})})],x.prototype,"errors",void 0),g([o({default:()=>[]})],x.prototype,"formErrors",void 0),g([s()],x.prototype,"path",void 0),g([a("formularioValue",{deep:!0})],x.prototype,"onFormularioValueChanged",null),g([a("mergedFormErrors")],x.prototype,"onMergedFormErrorsChanged",null),g([a("mergedFieldErrors",{immediate:!0})],x.prototype,"onMergedFieldErrorsChanged",null),g([s()],x.prototype,"getFormValues",null),g([s()],x.prototype,"onFormularioFieldValidation",null),g([s()],x.prototype,"addErrorObserver",null),g([s()],x.prototype,"removeErrorObserver",null),g([s("formularioRegister")],x.prototype,"register",null),g([s("formularioDeregister")],x.prototype,"deregister",null),g([s("formularioSetter")],x.prototype,"setFieldValue",null),x=g([n({name:"FormularioForm"})],x);const N=x;var F=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)};F._withStripped=!0;const V=$({render:F,staticRenderFns:[]},void 0,N,void 0,!1,void 0,!1,void 0,void 0,void 0);let O=class extends r{get groupPath(){return this.isArrayItem?`${this.path}[${this.name}]`:""===this.path?this.name:`${this.path}.${this.name}`}};g([l({default:""})],O.prototype,"path",void 0),g([o({required:!0})],O.prototype,"name",void 0),g([o({default:!1})],O.prototype,"isArrayItem",void 0),g([s("path")],O.prototype,"groupPath",null),O=g([n({name:"FormularioGrouping"})],O);const P=O;var R=function(){var e=this.$createElement;return(this._self._c||e)("div",[this._t("default")],2)};R._withStripped=!0;const j=$({render:R,staticRenderFns:[]},void 0,P,void 0,!1,void 0,!1,void 0,void 0,void 0);function w(e,t,r,i){return o=>Promise.resolve(e(o,...r)).then(e=>e?null:{rule:t,args:r,context:o,message:i(o,...r)})}function A(e){return/^[\^]/.test(e.charAt(0))?[f(e.substr(1)),e.charAt(0)]:[f(e),null]}function _(e,t,r){return"function"==typeof e?[e,null,null]:Array.isArray(e)&&e.length?function(e,t,r){const i=e.slice(),o=i.shift();if("function"==typeof o)return[o,null,null];if("string"!=typeof o)throw new Error("[Formulario]: For array constraint first element must be rule name or Validator function");const[s,a]=A(o);if(u(t,s))return[w(t[s],s,i,r[s]||r.default),s,a];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(":"),[o,s]=A(i.shift()||"");if(u(t,o))return[w(t[o],o,i.length?i.join(":").split(","):[],r[o]||r.default),o,s];throw new Error("[Formulario] Can't create validator for constraint: "+e)}(e,t,r):[()=>Promise.resolve(null),null,null]}function D(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 M(e,t){return new Promise(r=>{const i=(e,o=[])=>{if(e.length){const s=e.shift();(function(e,t){return Promise.all(e.validators.map(e=>e(t))).then(e=>e.filter(e=>null!==e))})(s,t).then(t=>0!==t.length&&s.bail||!e.length?r(o.concat(t)):i(e,o.concat(t)))}else r([])};i(function(e){const t=([e,,t])=>({validators:[e],bail:"^"===t}),r=[],i=e.findIndex(([,e])=>e&&"bail"===e.toLowerCase());return i>=0?(r.push(...D(e.splice(0,i+1).slice(0,-1).map(t))),r.push(...e.map(([e])=>({validators:[e],bail:!0})))):r.push(...D(e.map(t))),r}(e))})}const k={DEMAND:"demand",LIVE:"live",SUBMIT:"submit"};let C=class extends r{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[f(t)]=this.validationRules[t]}),e}get normalizedValidationMessages(){const e={};return Object.keys(this.validationMessages).forEach(t=>{e[f(t)]=this.validationMessages[t]}),e}get hasModel(){return u(this.$options.propsData||{},"value")}onProxyChanged(e,t){this.hasModel||c(e,t)||(this.context.model=e),this.validationBehavior===k.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===k.LIVE&&this.runValidation()}beforeDestroy(){this.errorsDisabled||"function"!=typeof this.removeErrorObserver||this.removeErrorObserver(this.setErrors),"function"==typeof this.formularioDeregister&&this.formularioDeregister(this.fullQualifiedName)}getInitialValue(){return u(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 M(function e(t,r,i){return"string"==typeof t?e(t.split("|").filter(e=>e.length),r,i):Array.isArray(t)?t.map(e=>_(e,r,i)):[]}(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=[]}};g([l({default:void 0})],C.prototype,"formularioSetter",void 0),g([l({default:()=>()=>{}})],C.prototype,"onFormularioFieldValidation",void 0),g([l({default:void 0})],C.prototype,"formularioRegister",void 0),g([l({default:void 0})],C.prototype,"formularioDeregister",void 0),g([l({default:()=>()=>({})})],C.prototype,"getFormValues",void 0),g([l({default:void 0})],C.prototype,"addErrorObserver",void 0),g([l({default:void 0})],C.prototype,"removeErrorObserver",void 0),g([l({default:""})],C.prototype,"path",void 0),g([i("input",{default:""})],C.prototype,"value",void 0),g([o({required:!0,validator:e=>"string"==typeof e&&e.length>0})],C.prototype,"name",void 0),g([o({default:""})],C.prototype,"validation",void 0),g([o({default:()=>({})})],C.prototype,"validationRules",void 0),g([o({default:()=>({})})],C.prototype,"validationMessages",void 0),g([o({default:k.DEMAND,validator:e=>Object.values(k).includes(e)})],C.prototype,"validationBehavior",void 0),g([o({default:!1})],C.prototype,"errorsDisabled",void 0),g([a("proxy")],C.prototype,"onProxyChanged",null),g([a("value")],C.prototype,"onValueChanged",null),C=g([n({name:"FormularioInput",inheritAttrs:!1})],C);const S=C;var I=function(){var e=this.$createElement;return(this._self._c||e)("div",{staticClass:"formulario-input"},[this._t("default",null,{context:this.context})],2)};I._withStripped=!0;const T=$({render:I,staticRenderFns:[]},void 0,S,void 0,!1,void 0,!1,void 0,void 0,void 0);var z=new class{constructor(){this.validationRules={},this.validationMessages={},this.validationRules=v,this.validationMessages=m}install(e,t){e.prototype.$formulario=this,e.component("FormularioForm",V),e.component("FormularioGrouping",j),e.component("FormularioInput",T),this.extend(t||{})}extend(e){if("object"==typeof e)return this.validationRules=d(this.validationRules,e.validationRules||{}),this.validationMessages=d(this.validationMessages,e.validationMessages||{}),this;throw new Error(`[Formulario]: Formulario.extend() should be passed an object (was ${typeof e})`)}getRules(e={}){return d(this.validationRules,e)}getMessages(e,t){const r=d(this.validationMessages||{},t),i={};for(const t in r)i[t]=(i,...o)=>"string"==typeof r[t]?r[t]:r[t](e,i,...o);return i}};export default z; diff --git a/dist/formulario.min.js b/dist/formulario.min.js index 113e028..006c302 100644 --- a/dist/formulario.min.js +++ b/dist/formulario.min.js @@ -1,34 +1,35 @@ -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;o0!==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)&&oPromise.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&&et&&e.lengthPromise.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)}; +var VueFormulario=function(e){"use strict"; /*! - * 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); + * 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 - * - * 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} + * 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;o0!==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)&&oPromise.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&&et&&e.lengthPromise.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. + Copyright (c) Microsoft Corporation. - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted. + 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=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 + 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=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 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);t0&&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(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); + * 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);t0&&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(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",{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); diff --git a/dist/formulario.umd.js b/dist/formulario.umd.js index fc27feb..9c0f45c 100644 --- a/dist/formulario.umd.js +++ b/dist/formulario.umd.js @@ -1,4 +1,4 @@ -!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;i0!==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)&&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((()=>{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} +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("is-plain-object"),require("is-url"),require("vue"),require("vue-property-decorator")):"function"==typeof define&&define.amd?define(["is-plain-object","is-url","vue","vue-property-decorator"],t):(e=e||self).Formulario=t(e.isPlainObject,e.isUrl,e.Vue,e.vuePropertyDecorator)}(this,(function(e,t,r,i){"use strict";function o(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function s(t,r,i=!0){const a={};for(const n in t)o(r,n)?e(r[n])&&e(t[n])?a[n]=s(t[n],r[n],i):i&&Array.isArray(t[n])&&Array.isArray(r[n])?a[n]=t[n].concat(r[n]):a[n]=r[n]:a[n]=t[n];for(const e in r)o(a,e)||(a[e]=r[e]);return a}function a(e){switch(typeof e){case"symbol":case"number":case"string":case"boolean":case"undefined":return!0;default:return null===e}}function n(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)}function u(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 d={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=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(),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((()=>{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?n(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?n(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(t(e)),bail:()=>Promise.resolve(!0)},h={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,i=10,o){const s=Object.assign(Object.assign({},t),{from:r,to:i});return!isNaN(t.value)&&"length"!==o||"value"===o?e.$t("validation.between.force",s):e.$t("validation.between.default",s)},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,i)=>Array.isArray(t.value)?e.$tc("validation.max.array",r,t):!isNaN(t.value)&&"length"!==i||"value"===i?e.$tc("validation.max.force",r,t):e.$tc("validation.max.default",r,t),min:(e,t,r=1,i)=>Array.isArray(t.value)?e.$tc("validation.min.array",r,t):!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)}; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. @@ -12,4 +12,5 @@ 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=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(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)}}})); + ***************************************************************************** */ +function c(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 p{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],c(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}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!==u(this.ctx.initialValues,e)?t.context.model=u(this.ctx.initialValues,e):r&&!n(t.proxy,u(this.ctx.initialValues,e))&&this.ctx.setFieldValue(e,t.proxy)}reduce(e,t){return this.registry.forEach((r,i)=>{t=e(t,r,i)}),t}}class v{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 v(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 m=class extends r{constructor(){super(...arguments),this.path="",this.proxy={},this.registry=new p(this),this.errorObserverRegistry=new v,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 s(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]=a(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,i)=>{const o=this.registry.get(i),s=u(this.proxy,i),a=u(e,i);n(a,s)||(this.setFieldValue(i,a,!1),r=!0),n(a,o.proxy)||(o.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,i=(t[r],c(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.runValidation()&&t.hasValidationErrors()),e),[])).then(e=>e.some(e=>e))}resetValidation(){this.localFormErrors=[],this.localFieldErrors={},this.registry.forEach(e=>{e.resetValidation()})}};function y(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}f([i.Model("input",{default:()=>({})})],m.prototype,"formularioValue",void 0),f([i.Prop({default:()=>({})})],m.prototype,"errors",void 0),f([i.Prop({default:()=>[]})],m.prototype,"formErrors",void 0),f([i.Provide()],m.prototype,"path",void 0),f([i.Watch("formularioValue",{deep:!0})],m.prototype,"onFormularioValueChanged",null),f([i.Watch("mergedFormErrors")],m.prototype,"onMergedFormErrorsChanged",null),f([i.Watch("mergedFieldErrors",{immediate:!0})],m.prototype,"onMergedFieldErrorsChanged",null),f([i.Provide()],m.prototype,"getFormValues",null),f([i.Provide()],m.prototype,"onFormularioFieldValidation",null),f([i.Provide()],m.prototype,"addErrorObserver",null),f([i.Provide()],m.prototype,"removeErrorObserver",null),f([i.Provide("formularioRegister")],m.prototype,"register",null),f([i.Provide("formularioDeregister")],m.prototype,"deregister",null),f([i.Provide("formularioSetter")],m.prototype,"setFieldValue",null),m=f([i.Component({name:"FormularioForm"})],m);const g=m;var b=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)};b._withStripped=!0;const E=y({render:b,staticRenderFns:[]},void 0,g,void 0,!1,void 0,!1,void 0,void 0,void 0);let x=class extends r{get groupPath(){return this.isArrayItem?`${this.path}[${this.name}]`:""===this.path?this.name:`${this.path}.${this.name}`}};f([i.Inject({default:""})],x.prototype,"path",void 0),f([i.Prop({required:!0})],x.prototype,"name",void 0),f([i.Prop({default:!1})],x.prototype,"isArrayItem",void 0),f([i.Provide("path")],x.prototype,"groupPath",null),x=f([i.Component({name:"FormularioGrouping"})],x);const P=x;var $=function(){var e=this.$createElement;return(this._self._c||e)("div",[this._t("default")],2)};$._withStripped=!0;const N=y({render:$,staticRenderFns:[]},void 0,P,void 0,!1,void 0,!1,void 0,void 0,void 0);function F(e,t,r,i){return o=>Promise.resolve(e(o,...r)).then(e=>e?null:{rule:t,args:r,context:o,message:i(o,...r)})}function V(e){return/^[\^]/.test(e.charAt(0))?[l(e.substr(1)),e.charAt(0)]:[l(e),null]}function O(e,t,r){return"function"==typeof e?[e,null,null]:Array.isArray(e)&&e.length?function(e,t,r){const i=e.slice(),s=i.shift();if("function"==typeof s)return[s,null,null];if("string"!=typeof s)throw new Error("[Formulario]: For array constraint first element must be rule name or Validator function");const[a,n]=V(s);if(o(t,a))return[F(t[a],a,i,r[a]||r.default),a,n];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(":"),[s,a]=V(i.shift()||"");if(o(t,s))return[F(t[s],s,i.length?i.join(":").split(","):[],r[s]||r.default),s,a];throw new Error("[Formulario] Can't create validator for constraint: "+e)}(e,t,r):[()=>Promise.resolve(null),null,null]}function j(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 R(e,t){return new Promise(r=>{const i=(e,o=[])=>{if(e.length){const s=e.shift();(function(e,t){return Promise.all(e.validators.map(e=>e(t))).then(e=>e.filter(e=>null!==e))})(s,t).then(t=>0!==t.length&&s.bail||!e.length?r(o.concat(t)):i(e,o.concat(t)))}else r([])};i(function(e){const t=([e,,t])=>({validators:[e],bail:"^"===t}),r=[],i=e.findIndex(([,e])=>e&&"bail"===e.toLowerCase());return i>=0?(r.push(...j(e.splice(0,i+1).slice(0,-1).map(t))),r.push(...e.map(([e])=>({validators:[e],bail:!0})))):r.push(...j(e.map(t))),r}(e))})}const w={DEMAND:"demand",LIVE:"live",SUBMIT:"submit"};let A=class extends r{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){n(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[l(t)]=this.validationRules[t]}),e}get normalizedValidationMessages(){const e={};return Object.keys(this.validationMessages).forEach(t=>{e[l(t)]=this.validationMessages[t]}),e}get hasModel(){return o(this.$options.propsData||{},"value")}onProxyChanged(e,t){this.hasModel||n(e,t)||(this.context.model=e),this.validationBehavior===w.LIVE?this.runValidation():this.violations=[]}onValueChanged(e,t){this.hasModel&&!n(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===w.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(){n(this.context.model,this.proxy)||(this.context.model=this.proxy)}runValidation(){return this.validationRun=this.validate().then(e=>{const t=!n(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 R(function e(t,r,i){return"string"==typeof t?e(t.split("|").filter(e=>e.length),r,i):Array.isArray(t)?t.map(e=>O(e,r,i)):[]}(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=[]}};f([i.Inject({default:void 0})],A.prototype,"formularioSetter",void 0),f([i.Inject({default:()=>()=>{}})],A.prototype,"onFormularioFieldValidation",void 0),f([i.Inject({default:void 0})],A.prototype,"formularioRegister",void 0),f([i.Inject({default:void 0})],A.prototype,"formularioDeregister",void 0),f([i.Inject({default:()=>()=>({})})],A.prototype,"getFormValues",void 0),f([i.Inject({default:void 0})],A.prototype,"addErrorObserver",void 0),f([i.Inject({default:void 0})],A.prototype,"removeErrorObserver",void 0),f([i.Inject({default:""})],A.prototype,"path",void 0),f([i.Model("input",{default:""})],A.prototype,"value",void 0),f([i.Prop({required:!0,validator:e=>"string"==typeof e&&e.length>0})],A.prototype,"name",void 0),f([i.Prop({default:""})],A.prototype,"validation",void 0),f([i.Prop({default:()=>({})})],A.prototype,"validationRules",void 0),f([i.Prop({default:()=>({})})],A.prototype,"validationMessages",void 0),f([i.Prop({default:w.DEMAND,validator:e=>Object.values(w).includes(e)})],A.prototype,"validationBehavior",void 0),f([i.Prop({default:!1})],A.prototype,"errorsDisabled",void 0),f([i.Watch("proxy")],A.prototype,"onProxyChanged",null),f([i.Watch("value")],A.prototype,"onValueChanged",null),A=f([i.Component({name:"FormularioInput",inheritAttrs:!1})],A);const M=A;var _=function(){var e=this.$createElement;return(this._self._c||e)("div",{staticClass:"formulario-input"},[this._t("default",null,{context:this.context})],2)};_._withStripped=!0;const D=y({render:_,staticRenderFns:[]},void 0,M,void 0,!1,void 0,!1,void 0,void 0,void 0);return new class{constructor(){this.validationRules={},this.validationMessages={},this.validationRules=d,this.validationMessages=h}install(e,t){e.prototype.$formulario=this,e.component("FormularioForm",E),e.component("FormularioGrouping",N),e.component("FormularioInput",D),this.extend(t||{})}extend(e){if("object"==typeof e)return this.validationRules=s(this.validationRules,e.validationRules||{}),this.validationMessages=s(this.validationMessages,e.validationMessages||{}),this;throw new Error(`[Formulario]: Formulario.extend() should be passed an object (was ${typeof e})`)}getRules(e={}){return s(this.validationRules,e)}getMessages(e,t){const r=s(this.validationMessages||{},t),i={};for(const t in r)i[t]=(i,...o)=>"string"==typeof r[t]?r[t]:r[t](e,i,...o);return i}}})); diff --git a/package.json b/package.json index 93d65a1..6eb9761 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@retailcrm/vue-formulario", - "version": "0.2.0", + "version": "0.3.0", "author": "RetailDriverLLC ", "scripts": { "build": "npm run build:esm & npm run build:umd & npm run build:iife & wait && echo \"Build complete:\nesm: $(gzip -c dist/formulario.esm.js | wc -c)b gzip\numd: $(gzip -c dist/formulario.umd.js | wc -c)b gzip\nmin: $(gzip -c dist/formulario.min.js | wc -c)b gzip\"",