From 8c7d71467f4618a1fec6e3f3603c1adee915f106 Mon Sep 17 00:00:00 2001 From: 1on Date: Tue, 21 Sep 2021 10:32:18 +0300 Subject: [PATCH] Build --- dist/formulario.esm.js | 16 +++++++++++----- dist/formulario.min.js | 6 +++--- dist/formulario.umd.js | 16 +++++++++++----- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/dist/formulario.esm.js b/dist/formulario.esm.js index 977f5ca..5b335bb 100644 --- a/dist/formulario.esm.js +++ b/dist/formulario.esm.js @@ -66,6 +66,15 @@ var TYPE; TYPE["UNDEFINED"] = "UNDEFINED"; TYPE["NULL"] = "NULL"; })(TYPE || (TYPE = {})); +const constructorOf = (value) => { + return Object.getPrototypeOf(value).constructor; +}; +function isRecord(value) { + return constructorOf(value) === Object && Object.keys(Object.getPrototypeOf(value)).length === 0; +} +function isRecordLike(value) { + return typeof value === 'object' && value !== null && (isRecord(value) || Array.isArray(value)); +} function typeOf(value) { switch (typeof value) { case 'bigint': @@ -92,16 +101,13 @@ function typeOf(value) { if (Array.isArray(value)) { return TYPE.ARRAY; } - if (value.constructor.name === 'Object') { + if (isRecord(value)) { return TYPE.RECORD; } - return 'InstanceOf<' + value.constructor.name + '>'; + return 'InstanceOf<' + constructorOf(value).name + '>'; } throw new Error(); } -function isRecordLike(value) { - return typeof value === 'object' && value !== null && ['Array', 'Object'].includes(value.constructor.name); -} function isScalar(value) { switch (typeof value) { case 'bigint': diff --git a/dist/formulario.min.js b/dist/formulario.min.js index 8e2b17a..a9554fb 100644 --- a/dist/formulario.min.js +++ b/dist/formulario.min.js @@ -12,7 +12,7 @@ function e(t){return!0==(null!=(e=t)&&"object"==typeof e&&!1===Array.isArray(e)) * Copyright (c) 2014-2017, Jon Schlinkert. * Released under the MIT License. */ -var e}function r(t){var r,o;return!1!==e(t)&&("function"==typeof(r=t.constructor)&&(!1!==e(o=r.prototype)&&!1!==o.hasOwnProperty("isPrototypeOf")))}function o(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function n(t,e,i=!0){const a={};for(const s in t)o(e,s)?r(e[s])&&r(t[s])?a[s]=n(t[s],e[s],i):i&&Array.isArray(t[s])&&Array.isArray(e[s])?a[s]=t[s].concat(e[s]):a[s]=e[s]:a[s]=t[s];for(const t in e)o(a,t)||(a[t]=e[t]);return a}t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t;var i=function(t){if("string"!=typeof t)return!1;var e=t.match(a);if(!e)return!1;var r=e[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,}$/;const u=new Map;var c;function f(t){switch(typeof t){case"bigint":return c.BIGINT;case"boolean":return c.BOOLEAN;case"function":return c.FUNCTION;case"number":return c.NUMBER;case"string":return c.STRING;case"symbol":return c.SYMBOL;case"undefined":return c.UNDEFINED;case"object":return null===t?c.NULL:t instanceof Date?c.DATE:Array.isArray(t)?c.ARRAY:"Object"===t.constructor.name?c.RECORD:"InstanceOf<"+t.constructor.name+">"}throw new Error}function d(t){return"object"==typeof t&&null!==t&&["Array","Object"].includes(t.constructor.name)}function p(t){switch(typeof t){case"bigint":case"boolean":case"number":case"string":case"symbol":case"undefined":return!0;default:return null===t}}!function(t){t.ARRAY="ARRAY",t.BIGINT="BIGINT",t.BOOLEAN="BOOLEAN",t.DATE="DATE",t.FUNCTION="FUNCTION",t.NUMBER="NUMBER",t.RECORD="RECORD",t.STRING="STRING",t.SYMBOL="SYMBOL",t.UNDEFINED="UNDEFINED",t.NULL="NULL"}(c||(c={}));function h(t){if(p(t))return t;if(t instanceof Date)return new Date(t);if(!d(t))return e=t,Object.assign(Object.create(Object.getPrototypeOf(e)),e);var e;if(Array.isArray(t))return t.slice().map(h);const r=t;return Object.keys(r).reduce(((t,e)=>Object.assign(Object.assign({},t),{[e]:h(r[e])})),{})} +var e}function r(t){var r,o;return!1!==e(t)&&("function"==typeof(r=t.constructor)&&(!1!==e(o=r.prototype)&&!1!==o.hasOwnProperty("isPrototypeOf")))}function o(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function n(t,e,i=!0){const a={};for(const s in t)o(e,s)?r(e[s])&&r(t[s])?a[s]=n(t[s],e[s],i):i&&Array.isArray(t[s])&&Array.isArray(e[s])?a[s]=t[s].concat(e[s]):a[s]=e[s]:a[s]=t[s];for(const t in e)o(a,t)||(a[t]=e[t]);return a}t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t;var i=function(t){if("string"!=typeof t)return!1;var e=t.match(a);if(!e)return!1;var r=e[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,}$/;const u=new Map;var c;!function(t){t.ARRAY="ARRAY",t.BIGINT="BIGINT",t.BOOLEAN="BOOLEAN",t.DATE="DATE",t.FUNCTION="FUNCTION",t.NUMBER="NUMBER",t.RECORD="RECORD",t.STRING="STRING",t.SYMBOL="SYMBOL",t.UNDEFINED="UNDEFINED",t.NULL="NULL"}(c||(c={}));const f=t=>Object.getPrototypeOf(t).constructor;function d(t){return f(t)===Object&&0===Object.keys(Object.getPrototypeOf(t)).length}function p(t){return"object"==typeof t&&null!==t&&(d(t)||Array.isArray(t))}function h(t){switch(typeof t){case"bigint":return c.BIGINT;case"boolean":return c.BOOLEAN;case"function":return c.FUNCTION;case"number":return c.NUMBER;case"string":return c.STRING;case"symbol":return c.SYMBOL;case"undefined":return c.UNDEFINED;case"object":return null===t?c.NULL:t instanceof Date?c.DATE:Array.isArray(t)?c.ARRAY:d(t)?c.RECORD:"InstanceOf<"+f(t).name+">"}throw new Error}function m(t){switch(typeof t){case"bigint":case"boolean":case"number":case"string":case"symbol":case"undefined":return!0;default:return null===t}}function y(t){if(m(t))return t;if(t instanceof Date)return new Date(t);if(!p(t))return e=t,Object.assign(Object.create(Object.getPrototypeOf(e)),e);var e;if(Array.isArray(t))return t.slice().map(y);const r=t;return Object.keys(r).reduce(((t,e)=>Object.assign(Object.assign({},t),{[e]:y(r[e])})),{})} /*! ***************************************************************************** Copyright (c) Microsoft Corporation. @@ -26,9 +26,9 @@ var e}function r(t){var r,o;return!1!==e(t)&&("function"==typeof(r=t.constructor 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(t,e,r,o){var n,i=arguments.length,a=i<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,r,o);else for(var s=t.length-1;s>=0;s--)(n=t[s])&&(a=(i<3?n(a):i>3?n(e,r,a):n(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a}const y=t=>{const e=parseInt(t);return e.toString()===t?e:NaN},v=t=>{const e=[];return t.split(".").forEach((t=>{/(.*)\[(\d+)]$/.test(t)?e.push(...t.substr(0,t.length-1).split("[").filter((t=>t.length))):e.push(t)})),e};function g(t,e,r){const n="string"==typeof e?v(e):e;if(p(t)||0===n.length)return r;const i=n.shift(),a=y(i);if(!isNaN(a))return Array.isArray(t)&&a>=0&&a{const r=t,o=e;r[o];return function(t,e){var r={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(r[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(t);n=0&&i0!==t.indexOf(e)&&"_"!==t[t.indexOf(e)-1]?e.toUpperCase().replace("_",""):e))}const w={accepted:({value:t})=>["yes","on","1",1,!0,"true"].includes(t),after({value:t},e=!1){const r=!1!==e?Date.parse(e):Date.now(),o=t instanceof Date?t.getTime():Date.parse(t);return!isNaN(o)&&o>r},alpha({value:t},e="default"){const r={default:/^[a-zA-ZÀ-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z]+$/};return"string"==typeof t&&r[o(r,e)?e:"default"].test(t)},alphanumeric({value:t},e="default"){const r={default:/^[a-zA-Z0-9À-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z0-9]+$/};return"string"==typeof t&&r[o(r,e)?e:"default"].test(t)},before({value:t},e=!1){const r=!1!==e?Date.parse(e):Date.now(),o=t instanceof Date?t.getTime():Date.parse(t);return!isNaN(o)&&onull!==e&&null!==r&&!isNaN(e)&&!isNaN(r)&&(!isNaN(Number(t))&&"length"!==o||"value"===o?(t=Number(t))>Number(e)&&te&&t.lengthe?function(t){const e=`^${r=t,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(((t,e)=>t.replace(e,o[e])),e))}(e).test(t):!isNaN(Date.parse(t)),email({value:t}){if(!t)return!0;return/^(([^<>()\[\].,;:\s@"]+(\.[^<>()\[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/i.test(t)},endsWith:({value:t},...e)=>!t||"string"==typeof t&&(0===e.length||e.some((e=>t.endsWith(e)))),in:({value:t},...e)=>e.some((e=>$(e,t))),matches:({value:t},...e)=>!!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))),max:({value:t},e=10,r)=>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,min:({value:t},e=1,r)=>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,not:({value:t},...e)=>!e.some((e=>$(e,t))),number:({value:t})=>String(t).length>0&&!isNaN(Number(t)),required:({value:t},e=!0)=>!(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&&(0===e.length||e.some((e=>t.startsWith(e)))),url:({value:t})=>!t||i(t),bail:()=>!0},R={default:(t,e)=>t.$t("validation.default",e),accepted:(t,e)=>t.$t("validation.accepted",e),after:(t,e,r=!1)=>"string"==typeof r&&r.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,r=!1)=>"string"==typeof r&&r.length?t.$t("validation.before.compare",e):t.$t("validation.before.default",e),between(t,e,r=0,o=10,n){const i=Object.assign(Object.assign({},e),{from:r,to:o});return!isNaN(e.value)&&"length"!==n||"value"===n?t.$t("validation.between.force",i):t.$t("validation.between.default",i)},confirm:(t,e)=>t.$t("validation.confirm",e),date:(t,e,r=!1)=>"string"==typeof r&&r.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:(t,e)=>"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,r=10,o)=>Array.isArray(e.value)?t.$tc("validation.max.array",r,e):!isNaN(e.value)&&"length"!==o||"value"===o?t.$tc("validation.max.force",r,e):t.$tc("validation.max.default",r,e),min:(t,e,r=1,o)=>Array.isArray(e.value)?t.$tc("validation.min.array",r,e):!isNaN(e.value)&&"length"!==o||"value"===o?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)};class A{constructor(t){this.validationRules={},this.validationMessages={},this.registry=new Map,this.validationRules=w,this.validationMessages=R,this.extend(t||{})}extend(t){if("object"==typeof t)return this.validationRules=n(this.validationRules,t.validationRules||{}),this.validationMessages=n(this.validationMessages,t.validationMessages||{}),this;throw new Error(`[Formulario]: Formulario.extend(): should be passed an object (was ${typeof t})`)}runValidation(t){if(!this.registry.has(t))throw new Error(`[Formulario]: Formulario.runValidation(): no forms with id "${t}"`);return this.registry.get(t).runValidation()}resetValidation(t){if(!this.registry.has(t))return;this.registry.get(t).resetValidation()}register(t,e){if(this.registry.has(t))throw new Error(`[Formulario]: Formulario.register(): id "${t}" is already in use`);this.registry.set(t,e)}unregister(t){this.registry.has(t)&&this.registry.delete(t)}getRules(t={}){return n(this.validationRules,t)}getMessages(t,e){const r=n(this.validationMessages||{},e),o={};for(const e in r)o[e]=(o,...n)=>"string"==typeof r[e]?r[e]:r[e](t,o,...n);return o}} + ***************************************************************************** */function v(t,e,r,o){var n,i=arguments.length,a=i<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,r,o);else for(var s=t.length-1;s>=0;s--)(n=t[s])&&(a=(i<3?n(a):i>3?n(e,r,a):n(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a}const g=t=>{const e=parseInt(t);return e.toString()===t?e:NaN},_=t=>{const e=[];return t.split(".").forEach((t=>{/(.*)\[(\d+)]$/.test(t)?e.push(...t.substr(0,t.length-1).split("[").filter((t=>t.length))):e.push(t)})),e};function b(t,e,r){const n="string"==typeof e?_(e):e;if(m(t)||0===n.length)return r;const i=n.shift(),a=g(i);if(!isNaN(a))return Array.isArray(t)&&a>=0&&a{const r=t,o=e;r[o];return function(t,e){var r={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(r[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(t);n=0&&i0!==t.indexOf(e)&&"_"!==t[t.indexOf(e)-1]?e.toUpperCase().replace("_",""):e))}const A={accepted:({value:t})=>["yes","on","1",1,!0,"true"].includes(t),after({value:t},e=!1){const r=!1!==e?Date.parse(e):Date.now(),o=t instanceof Date?t.getTime():Date.parse(t);return!isNaN(o)&&o>r},alpha({value:t},e="default"){const r={default:/^[a-zA-ZÀ-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z]+$/};return"string"==typeof t&&r[o(r,e)?e:"default"].test(t)},alphanumeric({value:t},e="default"){const r={default:/^[a-zA-Z0-9À-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z0-9]+$/};return"string"==typeof t&&r[o(r,e)?e:"default"].test(t)},before({value:t},e=!1){const r=!1!==e?Date.parse(e):Date.now(),o=t instanceof Date?t.getTime():Date.parse(t);return!isNaN(o)&&onull!==e&&null!==r&&!isNaN(e)&&!isNaN(r)&&(!isNaN(Number(t))&&"length"!==o||"value"===o?(t=Number(t))>Number(e)&&te&&t.lengthe?function(t){const e=`^${r=t,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(((t,e)=>t.replace(e,o[e])),e))}(e).test(t):!isNaN(Date.parse(t)),email({value:t}){if(!t)return!0;return/^(([^<>()\[\].,;:\s@"]+(\.[^<>()\[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/i.test(t)},endsWith:({value:t},...e)=>!t||"string"==typeof t&&(0===e.length||e.some((e=>t.endsWith(e)))),in:({value:t},...e)=>e.some((e=>w(e,t))),matches:({value:t},...e)=>!!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))),max:({value:t},e=10,r)=>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,min:({value:t},e=1,r)=>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,not:({value:t},...e)=>!e.some((e=>w(e,t))),number:({value:t})=>String(t).length>0&&!isNaN(Number(t)),required:({value:t},e=!0)=>!(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&&(0===e.length||e.some((e=>t.startsWith(e)))),url:({value:t})=>!t||i(t),bail:()=>!0},x={default:(t,e)=>t.$t("validation.default",e),accepted:(t,e)=>t.$t("validation.accepted",e),after:(t,e,r=!1)=>"string"==typeof r&&r.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,r=!1)=>"string"==typeof r&&r.length?t.$t("validation.before.compare",e):t.$t("validation.before.default",e),between(t,e,r=0,o=10,n){const i=Object.assign(Object.assign({},e),{from:r,to:o});return!isNaN(e.value)&&"length"!==n||"value"===n?t.$t("validation.between.force",i):t.$t("validation.between.default",i)},confirm:(t,e)=>t.$t("validation.confirm",e),date:(t,e,r=!1)=>"string"==typeof r&&r.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:(t,e)=>"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,r=10,o)=>Array.isArray(e.value)?t.$tc("validation.max.array",r,e):!isNaN(e.value)&&"length"!==o||"value"===o?t.$tc("validation.max.force",r,e):t.$tc("validation.max.default",r,e),min:(t,e,r=1,o)=>Array.isArray(e.value)?t.$tc("validation.min.array",r,e):!isNaN(e.value)&&"length"!==o||"value"===o?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)};class V{constructor(t){this.validationRules={},this.validationMessages={},this.registry=new Map,this.validationRules=A,this.validationMessages=x,this.extend(t||{})}extend(t){if("object"==typeof t)return this.validationRules=n(this.validationRules,t.validationRules||{}),this.validationMessages=n(this.validationMessages,t.validationMessages||{}),this;throw new Error(`[Formulario]: Formulario.extend(): should be passed an object (was ${typeof t})`)}runValidation(t){if(!this.registry.has(t))throw new Error(`[Formulario]: Formulario.runValidation(): no forms with id "${t}"`);return this.registry.get(t).runValidation()}resetValidation(t){if(!this.registry.has(t))return;this.registry.get(t).resetValidation()}register(t,e){if(this.registry.has(t))throw new Error(`[Formulario]: Formulario.register(): id "${t}" is already in use`);this.registry.set(t,e)}unregister(t){this.registry.has(t)&&this.registry.delete(t)}getRules(t={}){return n(this.validationRules,t)}getMessages(t,e){const r=n(this.validationMessages||{},e),o={};for(const e in r)o[e]=(o,...n)=>"string"==typeof r[e]?r[e]:r[e](t,o,...n);return o}} /** * vue-class-component v7.2.3 * (c) 2015-present Evan You * @license MIT - */function x(t){return(x="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function V(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function P(t){return function(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e0&&T("Component class must inherit Vue or its descendant class when class property is used."),i}var B=["data","beforeCreate","created","beforeMount","mounted","beforeDestroy","destroyed","beforeUpdate","updated","activated","deactivated","render","errorCaptured","serverPrefetch"];function L(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};r.name=r.name||e._componentTag||e.name;var o=e.prototype;Object.getOwnPropertyNames(o).forEach((function(t){if("constructor"!==t)if(B.indexOf(t)>-1)r[t]=o[t];else{var e=Object.getOwnPropertyDescriptor(o,t);void 0!==e.value?"function"==typeof e.value?(r.methods||(r.methods={}))[t]=e.value:(r.mixins||(r.mixins=[])).push({data:function(){return V({},t,e.value)}}):(e.get||e.set)&&((r.computed||(r.computed={}))[t]={get:e.get,set:e.set})}})),(r.mixins||(r.mixins=[])).push({data:function(){return U(this,e)}});var n=e.__decorators__;n&&(n.forEach((function(t){return t(r)})),delete e.__decorators__);var i=Object.getPrototypeOf(e.prototype),a=i instanceof t?i.constructor:t,s=a.extend(r);return G(s,e,a),D()&&S(s,e),s}var k=["cid","super","options","superOptions","extendOptions","sealedOptions","component","directive","filter"],Y={prototype:!0,arguments:!0,callee:!0,caller:!0};function G(t,e,r){Object.getOwnPropertyNames(e).forEach((function(o){if(!Y[o]){var n=Object.getOwnPropertyDescriptor(t,o);if(!n||n.configurable){var i,a,s=Object.getOwnPropertyDescriptor(e,o);if(!M){if("cid"===o)return;var l=Object.getOwnPropertyDescriptor(r,o);if(i=s.value,a=x(i),null!=i&&("object"===a||"function"===a)&&l&&l.value===s.value)return}"production"!==process.env.NODE_ENV&&k.indexOf(o)>=0&&T("Static property name '".concat(o,"' declared on class '").concat(e.name,"' ")+"conflicts with reserved property name of Vue internal. It may cause unexpected behavior of the component. Consider renaming the property."),Object.defineProperty(t,o,s)}}}))}function z(t){return"function"==typeof t?L(t):function(e){return L(e,t)}}z.registerHooks=function(t){B.push.apply(B,P(t))};function W(t){return I((function(e,r){void 0===e.inject&&(e.inject={}),Array.isArray(e.inject)||(e.inject[r]=t||r)}))}function q(t){return I((function(e,r){var o,n=e.provide;("function"!=typeof(o=n)||!o.managed&&!o.managedReactive)&&(n=e.provide=function(t){var e=function(){var r=this,o="function"==typeof t?t.call(this):t;for(var n in(o=Object.create(o||null)).__reactiveInject__=this.__reactiveInject__||{},e.managed)o[e.managed[n]]=this[n];var i=function(t){o[e.managedReactive[t]]=a[t],Object.defineProperty(o.__reactiveInject__,e.managedReactive[t],{enumerable:!0,get:function(){return r[t]}})},a=this;for(var n in e.managedReactive)i(n);return o};return e.managed={},e.managedReactive={},e}(n)),n.managed[r]=t||r}))}var Z="undefined"!=typeof Reflect&&void 0!==Reflect.getMetadata;function K(t,e,r){if(Z&&!Array.isArray(t)&&"function"!=typeof t&&void 0===t.type){var o=Reflect.getMetadata("design:type",e,r);o!==Object&&(t.type=o)}}function X(t,e){return void 0===e&&(e={}),function(r,o){K(e,r,o),I((function(r,o){(r.props||(r.props={}))[o]=e,r.model={prop:o,event:t||o}}))(r,o)}}function H(t){return void 0===t&&(t={}),function(e,r){K(t,e,r),I((function(e,r){(e.props||(e.props={}))[r]=t}))(e,r)}}function J(t,e){void 0===e&&(e={});var r=e.deep,o=void 0!==r&&r,n=e.immediate,i=void 0!==n&&n;return I((function(e,r){"object"!=typeof e.watch&&(e.watch=Object.create(null));var n=e.watch;"object"!=typeof n[t]||Array.isArray(n[t])?void 0===n[t]&&(n[t]=[]):n[t]=[n[t]],n[t].push({handler:r,deep:o,immediate:i})}))}function Q(t,e,r,o){return n=>Promise.resolve(t(n,...r)).then((t=>t?null:{rule:e,args:r,context:n,message:o(n,...r)}))}function tt(t){return/^[\^]/.test(t.charAt(0))?[j(t.substr(1)),t.charAt(0)]:[j(t),null]}function et(t,e,r){return"function"==typeof t?[t,null,null]:Array.isArray(t)&&t.length?function(t,e,r){const n=t.slice(),i=n.shift();if("function"==typeof i)return[i,null,null];if("string"!=typeof i)throw new Error("[Formulario]: For array constraint first element must be rule name or Validator function");const[a,s]=tt(i);if(o(e,a))return[Q(e[a],a,n,r[a]||r.default),a,s];throw new Error("[Formulario] Can't create validator for constraint: "+JSON.stringify(t))}(t,e,r):"string"==typeof t?function(t,e,r){const n=t.split(":"),[i,a]=tt(n.shift()||"");if(o(e,i))return[Q(e[i],i,n.length?n.join(":").split(","):[],r[i]||r.default),i,a];throw new Error("[Formulario] Can't create validator for constraint: "+t)}(t,e,r):[()=>Promise.resolve(null),null,null]}function rt(t,e,r){return"string"==typeof t?rt(t.split("|").filter((t=>t.length)),e,r):Array.isArray(t)?t.map((t=>et(t,e,r))):[]}function ot(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}function nt(t,e){return new Promise((r=>{const o=(t,n=[])=>{if(t.length){const i=t.shift();(function(t,e){return Promise.all(t.validators.map((t=>t(e)))).then((t=>t.filter((t=>null!==t))))})(i,e).then((e=>0!==e.length&&i.bail||!t.length?r(n.concat(e)):o(t,n.concat(e))))}else r([])};o(function(t){const e=([t,,e])=>({validators:[t],bail:"^"===e}),r=[],o=t.findIndex((([,t])=>t&&"bail"===t.toLowerCase()));return o>=0?(r.push(...ot(t.splice(0,o+1).slice(0,-1).map(e))),r.push(...t.map((([t])=>({validators:[t],bail:!0}))))):r.push(...ot(t.map(e))),r}(t))}))}const it={DEMAND:"demand",LIVE:"live",SUBMIT:"submit"};let at=class extends t{constructor(){super(...arguments),this.proxy=this.hasModel?this.value:"",this.localErrors=[],this.violations=[],this.validationRun=Promise.resolve([])}get fullPath(){return""!==this.__Formulario_path?`${this.__Formulario_path}.${this.name}`:this.name}get hasModel(){return o(this.$options.propsData||{},"value")}get context(){return Object.defineProperty({name:this.fullPath,path:this.fullPath,runValidation:this.runValidation.bind(this),violations:this.violations,errors:this.localErrors,allErrors:[...this.localErrors,...this.violations.map((t=>t.message))]},"model",{get:()=>this.modelGetConverter(this.proxy),set:t=>{this.syncProxy(this.modelSetConverter(t,this.proxy))}})}get normalizedValidationRules(){const t={};return Object.keys(this.validationRules).forEach((e=>{t[j(e)]=this.validationRules[e]})),t}get normalizedValidationMessages(){const t={};return Object.keys(this.validationMessages).forEach((e=>{t[j(e)]=this.validationMessages[e]})),t}onValueChange(){this.syncProxy(this.value)}onProxyChange(){this.validationBehavior===it.LIVE?this.runValidation():this.resetValidation()}created(){"function"==typeof this.__FormularioForm_register&&this.__FormularioForm_register(this.fullPath,this),this.validationBehavior===it.LIVE&&this.runValidation()}beforeDestroy(){"function"==typeof this.__FormularioForm_unregister&&this.__FormularioForm_unregister(this.fullPath)}syncProxy(t){E(t,this.proxy)||(this.proxy=t,this.$emit("input",t),"function"==typeof this.__FormularioForm_set&&(this.__FormularioForm_set(this.fullPath,t),this.__FormularioForm_emitInput()))}runValidation(){return this.validationRun=this.validate().then((t=>(this.violations=t,this.emitValidation(this.fullPath,t),this.violations))),this.validationRun}validate(){return nt(rt(this.validation,this.$formulario.getRules(this.normalizedValidationRules),this.$formulario.getMessages(this,this.normalizedValidationMessages)),{value:this.proxy,name:this.fullPath,formValues:this.__FormularioForm_getState()})}emitValidation(t,e){this.$emit("validation",{path:t,violations:e}),"function"==typeof this.__FormularioForm_emitValidation&&this.__FormularioForm_emitValidation(t,e)}hasValidationErrors(){return new Promise((t=>{this.$nextTick((()=>{this.validationRun.then((()=>t(this.violations.length>0)))}))}))}setErrors(t){this.errorsDisabled||(this.localErrors=t)}resetValidation(){this.localErrors=[],this.violations=[]}};function st(t,e,r,o,n,i,a,s,l,u){"boolean"!=typeof a&&(l=s,s=a,a=!1);const c="function"==typeof r?r.options:r;let f;if(t&&t.render&&(c.render=t.render,c.staticRenderFns=t.staticRenderFns,c._compiled=!0,n&&(c.functional=!0)),o&&(c._scopeId=o),i?(f=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),e&&e.call(this,l(t)),t&&t._registeredComponents&&t._registeredComponents.add(i)},c._ssrRegister=f):e&&(f=a?function(t){e.call(this,u(t,this.$root.$options.shadowRoot))}:function(t){e.call(this,s(t))}),f)if(c.functional){const t=c.render;c.render=function(e,r){return f.call(r),t(e,r)}}else{const t=c.beforeCreate;c.beforeCreate=t?[].concat(t,f):[f]}return r}m([W({default:""})],at.prototype,"__Formulario_path",void 0),m([W({default:void 0})],at.prototype,"__FormularioForm_set",void 0),m([W({default:()=>()=>{}})],at.prototype,"__FormularioForm_emitInput",void 0),m([W({default:()=>()=>{}})],at.prototype,"__FormularioForm_emitValidation",void 0),m([W({default:void 0})],at.prototype,"__FormularioForm_register",void 0),m([W({default:void 0})],at.prototype,"__FormularioForm_unregister",void 0),m([W({default:()=>()=>({})})],at.prototype,"__FormularioForm_getState",void 0),m([X("input",{default:""})],at.prototype,"value",void 0),m([H({required:!0,validator:t=>"string"==typeof t&&t.length>0})],at.prototype,"name",void 0),m([H({default:""})],at.prototype,"validation",void 0),m([H({default:()=>({})})],at.prototype,"validationRules",void 0),m([H({default:()=>({})})],at.prototype,"validationMessages",void 0),m([H({default:it.DEMAND,validator:t=>Object.values(it).includes(t)})],at.prototype,"validationBehavior",void 0),m([H({default:!1})],at.prototype,"errorsDisabled",void 0),m([H({default:()=>t=>t})],at.prototype,"modelGetConverter",void 0),m([H({default:()=>t=>t})],at.prototype,"modelSetConverter",void 0),m([J("value")],at.prototype,"onValueChange",null),m([J("proxy")],at.prototype,"onProxyChange",null),at=m([z({name:"FormularioField",inheritAttrs:!1})],at);const lt=at;var ut=function(){var t=this,e=t.$createElement;return(t._self._c||e)("div",t._b({},"div",t.$attrs,!1),[t._t("default",null,{context:t.context})],2)};ut._withStripped=!0;const ct=st({render:ut,staticRenderFns:[]},undefined,lt,undefined,false,undefined,!1,void 0,void 0,void 0);let ft=class extends t{get fullPath(){const t=""+this.name;return parseInt(t).toString()===t?`${this.__Formulario_path}[${t}]`:""===this.__Formulario_path?t:`${this.__Formulario_path}.${t}`}};m([W({default:""})],ft.prototype,"__Formulario_path",void 0),m([H({required:!0})],ft.prototype,"name",void 0),m([q("__Formulario_path")],ft.prototype,"fullPath",null),ft=m([z({name:"FormularioFieldGroup"})],ft);const dt=ft;var pt=function(){var t=this,e=t.$createElement;return(t._self._c||e)("div",[t._t("default")],2)};pt._withStripped=!0;const ht=st({render:pt,staticRenderFns:[]},undefined,dt,undefined,false,undefined,!1,void 0,void 0,void 0),mt=(t,e,r)=>void 0===r?O(t,e):_(t,e,r);let yt=class extends t{constructor(){super(...arguments),this.proxy={},this.registry=new Map,this.localFieldsErrors={},this.localFormErrors=[]}get fieldsErrorsComputed(){return n(this.fieldsErrors||{},this.localFieldsErrors)}get formErrorsComputed(){return[...this.formErrors,...this.localFormErrors]}register(t,e){this.registry.has(t)||this.registry.set(t,e);const r=g(this.proxy,t);e.hasModel?E(e.proxy,r)||(this.setFieldValue(t,e.proxy),this.emitInput()):void 0!==r?e.proxy=r:(this.setFieldValue(t,null),this.emitInput()),o(this.fieldsErrorsComputed,t)&&e.setErrors(this.fieldsErrorsComputed[t])}unregister(t){this.registry.has(t)&&(this.registry.delete(t),this.proxy=O(this.proxy,t),this.emitInput())}getState(){return this.proxy}setFieldValue(t,e){this.proxy=mt(this.proxy,t,e)}emitInput(){this.$emit("input",h(this.proxy))}emitValidation(t,e){this.$emit("validation",{path:t,violations:e})}onStateChange(t){const e=h(t),r=this.proxy;let o=!1;this.registry.forEach(((n,i)=>{const a=g(t,i,null),s=g(r,i,null);n.proxy=a,E(a,s)||(n.$emit("input",a),mt(e,i,a),o=!0)})),this.proxy=e,o&&this.emitInput()}onFieldsErrorsChange(t){this.registry.forEach(((e,r)=>{e.setErrors(t[r]||[])}))}created(){this.$formulario.register(this.id,this),"object"==typeof this.state&&(this.proxy=h(this.state))}beforeDestroy(){this.$formulario.unregister(this.id)}runValidation(){const t=[],e={};return this.registry.forEach(((r,o)=>{t.push(r.runValidation().then((t=>{e[o]=t})))})),Promise.all(t).then((()=>e))}hasValidationErrors(){return this.runValidation().then((t=>Object.keys(t).some((e=>t[e].length>0))))}setErrors({fieldsErrors:t,formErrors:e}){this.localFieldsErrors=t||{},this.localFormErrors=e||[]}resetValidation(){this.localFieldsErrors={},this.localFormErrors=[],this.registry.forEach((t=>{t.resetValidation()}))}onSubmit(){return this.runValidation().then((t=>{Object.keys(t).some((e=>t[e].length>0))?this.$emit("error",t):this.$emit("submit",h(this.proxy))}))}};m([X("input",{default:()=>({})})],yt.prototype,"state",void 0),m([H({default:()=>(t=>{const e=(u.get(t)||0)+1;return u.set(t,e),`${t}-${e}`})("formulario-form")})],yt.prototype,"id",void 0),m([H({default:()=>({})})],yt.prototype,"fieldsErrors",void 0),m([H({default:()=>[]})],yt.prototype,"formErrors",void 0),m([q("__FormularioForm_register")],yt.prototype,"register",null),m([q("__FormularioForm_unregister")],yt.prototype,"unregister",null),m([q("__FormularioForm_getState")],yt.prototype,"getState",null),m([q("__FormularioForm_set")],yt.prototype,"setFieldValue",null),m([q("__FormularioForm_emitInput")],yt.prototype,"emitInput",null),m([q("__FormularioForm_emitValidation")],yt.prototype,"emitValidation",null),m([J("state",{deep:!0})],yt.prototype,"onStateChange",null),m([J("fieldsErrorsComputed",{deep:!0,immediate:!0})],yt.prototype,"onFieldsErrorsChange",null),yt=m([z({name:"FormularioForm"})],yt);const vt=yt;var gt=function(){var t=this,e=t.$createElement;return(t._self._c||e)("form",{on:{submit:function(e){return e.preventDefault(),t.onSubmit(e)}}},[t._t("default",null,{errors:t.formErrorsComputed})],2)};gt._withStripped=!0;const _t=st({render:gt,staticRenderFns:[]},undefined,vt,undefined,false,undefined,!1,void 0,void 0,void 0);return{Formulario:A,install(t,e){t.component("FormularioField",ct),t.component("FormularioFieldGroup",ht),t.component("FormularioForm",_t),t.component("FormularioInput",ct),t.component("FormularioGrouping",ht),t.mixin({beforeCreate(){const t=this.$options;"function"==typeof t.formulario?this.$formulario=t.formulario():t.parent&&t.parent.$formulario?this.$formulario=t.parent.$formulario:this.$formulario=new A(e)}})}}}(Vue); + */function P(t){return(P="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function D(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function S(t){return function(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e0&&B("Component class must inherit Vue or its descendant class when class property is used."),i}var k=["data","beforeCreate","created","beforeMount","mounted","beforeDestroy","destroyed","beforeUpdate","updated","activated","deactivated","render","errorCaptured","serverPrefetch"];function Y(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};r.name=r.name||e._componentTag||e.name;var o=e.prototype;Object.getOwnPropertyNames(o).forEach((function(t){if("constructor"!==t)if(k.indexOf(t)>-1)r[t]=o[t];else{var e=Object.getOwnPropertyDescriptor(o,t);void 0!==e.value?"function"==typeof e.value?(r.methods||(r.methods={}))[t]=e.value:(r.mixins||(r.mixins=[])).push({data:function(){return D({},t,e.value)}}):(e.get||e.set)&&((r.computed||(r.computed={}))[t]={get:e.get,set:e.set})}})),(r.mixins||(r.mixins=[])).push({data:function(){return L(this,e)}});var n=e.__decorators__;n&&(n.forEach((function(t){return t(r)})),delete e.__decorators__);var i=Object.getPrototypeOf(e.prototype),a=i instanceof t?i.constructor:t,s=a.extend(r);return W(s,e,a),C()&&M(s,e),s}var G=["cid","super","options","superOptions","extendOptions","sealedOptions","component","directive","filter"],z={prototype:!0,arguments:!0,callee:!0,caller:!0};function W(t,e,r){Object.getOwnPropertyNames(e).forEach((function(o){if(!z[o]){var n=Object.getOwnPropertyDescriptor(t,o);if(!n||n.configurable){var i,a,s=Object.getOwnPropertyDescriptor(e,o);if(!T){if("cid"===o)return;var l=Object.getOwnPropertyDescriptor(r,o);if(i=s.value,a=P(i),null!=i&&("object"===a||"function"===a)&&l&&l.value===s.value)return}"production"!==process.env.NODE_ENV&&G.indexOf(o)>=0&&B("Static property name '".concat(o,"' declared on class '").concat(e.name,"' ")+"conflicts with reserved property name of Vue internal. It may cause unexpected behavior of the component. Consider renaming the property."),Object.defineProperty(t,o,s)}}}))}function q(t){return"function"==typeof t?Y(t):function(e){return Y(e,t)}}q.registerHooks=function(t){k.push.apply(k,S(t))};function Z(t){return U((function(e,r){void 0===e.inject&&(e.inject={}),Array.isArray(e.inject)||(e.inject[r]=t||r)}))}function K(t){return U((function(e,r){var o,n=e.provide;("function"!=typeof(o=n)||!o.managed&&!o.managedReactive)&&(n=e.provide=function(t){var e=function(){var r=this,o="function"==typeof t?t.call(this):t;for(var n in(o=Object.create(o||null)).__reactiveInject__=this.__reactiveInject__||{},e.managed)o[e.managed[n]]=this[n];var i=function(t){o[e.managedReactive[t]]=a[t],Object.defineProperty(o.__reactiveInject__,e.managedReactive[t],{enumerable:!0,get:function(){return r[t]}})},a=this;for(var n in e.managedReactive)i(n);return o};return e.managed={},e.managedReactive={},e}(n)),n.managed[r]=t||r}))}var X="undefined"!=typeof Reflect&&void 0!==Reflect.getMetadata;function H(t,e,r){if(X&&!Array.isArray(t)&&"function"!=typeof t&&void 0===t.type){var o=Reflect.getMetadata("design:type",e,r);o!==Object&&(t.type=o)}}function J(t,e){return void 0===e&&(e={}),function(r,o){H(e,r,o),U((function(r,o){(r.props||(r.props={}))[o]=e,r.model={prop:o,event:t||o}}))(r,o)}}function Q(t){return void 0===t&&(t={}),function(e,r){H(t,e,r),U((function(e,r){(e.props||(e.props={}))[r]=t}))(e,r)}}function tt(t,e){void 0===e&&(e={});var r=e.deep,o=void 0!==r&&r,n=e.immediate,i=void 0!==n&&n;return U((function(e,r){"object"!=typeof e.watch&&(e.watch=Object.create(null));var n=e.watch;"object"!=typeof n[t]||Array.isArray(n[t])?void 0===n[t]&&(n[t]=[]):n[t]=[n[t]],n[t].push({handler:r,deep:o,immediate:i})}))}function et(t,e,r,o){return n=>Promise.resolve(t(n,...r)).then((t=>t?null:{rule:e,args:r,context:n,message:o(n,...r)}))}function rt(t){return/^[\^]/.test(t.charAt(0))?[R(t.substr(1)),t.charAt(0)]:[R(t),null]}function ot(t,e,r){return"function"==typeof t?[t,null,null]:Array.isArray(t)&&t.length?function(t,e,r){const n=t.slice(),i=n.shift();if("function"==typeof i)return[i,null,null];if("string"!=typeof i)throw new Error("[Formulario]: For array constraint first element must be rule name or Validator function");const[a,s]=rt(i);if(o(e,a))return[et(e[a],a,n,r[a]||r.default),a,s];throw new Error("[Formulario] Can't create validator for constraint: "+JSON.stringify(t))}(t,e,r):"string"==typeof t?function(t,e,r){const n=t.split(":"),[i,a]=rt(n.shift()||"");if(o(e,i))return[et(e[i],i,n.length?n.join(":").split(","):[],r[i]||r.default),i,a];throw new Error("[Formulario] Can't create validator for constraint: "+t)}(t,e,r):[()=>Promise.resolve(null),null,null]}function nt(t,e,r){return"string"==typeof t?nt(t.split("|").filter((t=>t.length)),e,r):Array.isArray(t)?t.map((t=>ot(t,e,r))):[]}function it(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}function at(t,e){return new Promise((r=>{const o=(t,n=[])=>{if(t.length){const i=t.shift();(function(t,e){return Promise.all(t.validators.map((t=>t(e)))).then((t=>t.filter((t=>null!==t))))})(i,e).then((e=>0!==e.length&&i.bail||!t.length?r(n.concat(e)):o(t,n.concat(e))))}else r([])};o(function(t){const e=([t,,e])=>({validators:[t],bail:"^"===e}),r=[],o=t.findIndex((([,t])=>t&&"bail"===t.toLowerCase()));return o>=0?(r.push(...it(t.splice(0,o+1).slice(0,-1).map(e))),r.push(...t.map((([t])=>({validators:[t],bail:!0}))))):r.push(...it(t.map(e))),r}(t))}))}const st={DEMAND:"demand",LIVE:"live",SUBMIT:"submit"};let lt=class extends t{constructor(){super(...arguments),this.proxy=this.hasModel?this.value:"",this.localErrors=[],this.violations=[],this.validationRun=Promise.resolve([])}get fullPath(){return""!==this.__Formulario_path?`${this.__Formulario_path}.${this.name}`:this.name}get hasModel(){return o(this.$options.propsData||{},"value")}get context(){return Object.defineProperty({name:this.fullPath,path:this.fullPath,runValidation:this.runValidation.bind(this),violations:this.violations,errors:this.localErrors,allErrors:[...this.localErrors,...this.violations.map((t=>t.message))]},"model",{get:()=>this.modelGetConverter(this.proxy),set:t=>{this.syncProxy(this.modelSetConverter(t,this.proxy))}})}get normalizedValidationRules(){const t={};return Object.keys(this.validationRules).forEach((e=>{t[R(e)]=this.validationRules[e]})),t}get normalizedValidationMessages(){const t={};return Object.keys(this.validationMessages).forEach((e=>{t[R(e)]=this.validationMessages[e]})),t}onValueChange(){this.syncProxy(this.value)}onProxyChange(){this.validationBehavior===st.LIVE?this.runValidation():this.resetValidation()}created(){"function"==typeof this.__FormularioForm_register&&this.__FormularioForm_register(this.fullPath,this),this.validationBehavior===st.LIVE&&this.runValidation()}beforeDestroy(){"function"==typeof this.__FormularioForm_unregister&&this.__FormularioForm_unregister(this.fullPath)}syncProxy(t){j(t,this.proxy)||(this.proxy=t,this.$emit("input",t),"function"==typeof this.__FormularioForm_set&&(this.__FormularioForm_set(this.fullPath,t),this.__FormularioForm_emitInput()))}runValidation(){return this.validationRun=this.validate().then((t=>(this.violations=t,this.emitValidation(this.fullPath,t),this.violations))),this.validationRun}validate(){return at(nt(this.validation,this.$formulario.getRules(this.normalizedValidationRules),this.$formulario.getMessages(this,this.normalizedValidationMessages)),{value:this.proxy,name:this.fullPath,formValues:this.__FormularioForm_getState()})}emitValidation(t,e){this.$emit("validation",{path:t,violations:e}),"function"==typeof this.__FormularioForm_emitValidation&&this.__FormularioForm_emitValidation(t,e)}hasValidationErrors(){return new Promise((t=>{this.$nextTick((()=>{this.validationRun.then((()=>t(this.violations.length>0)))}))}))}setErrors(t){this.errorsDisabled||(this.localErrors=t)}resetValidation(){this.localErrors=[],this.violations=[]}};function ut(t,e,r,o,n,i,a,s,l,u){"boolean"!=typeof a&&(l=s,s=a,a=!1);const c="function"==typeof r?r.options:r;let f;if(t&&t.render&&(c.render=t.render,c.staticRenderFns=t.staticRenderFns,c._compiled=!0,n&&(c.functional=!0)),o&&(c._scopeId=o),i?(f=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),e&&e.call(this,l(t)),t&&t._registeredComponents&&t._registeredComponents.add(i)},c._ssrRegister=f):e&&(f=a?function(t){e.call(this,u(t,this.$root.$options.shadowRoot))}:function(t){e.call(this,s(t))}),f)if(c.functional){const t=c.render;c.render=function(e,r){return f.call(r),t(e,r)}}else{const t=c.beforeCreate;c.beforeCreate=t?[].concat(t,f):[f]}return r}v([Z({default:""})],lt.prototype,"__Formulario_path",void 0),v([Z({default:void 0})],lt.prototype,"__FormularioForm_set",void 0),v([Z({default:()=>()=>{}})],lt.prototype,"__FormularioForm_emitInput",void 0),v([Z({default:()=>()=>{}})],lt.prototype,"__FormularioForm_emitValidation",void 0),v([Z({default:void 0})],lt.prototype,"__FormularioForm_register",void 0),v([Z({default:void 0})],lt.prototype,"__FormularioForm_unregister",void 0),v([Z({default:()=>()=>({})})],lt.prototype,"__FormularioForm_getState",void 0),v([J("input",{default:""})],lt.prototype,"value",void 0),v([Q({required:!0,validator:t=>"string"==typeof t&&t.length>0})],lt.prototype,"name",void 0),v([Q({default:""})],lt.prototype,"validation",void 0),v([Q({default:()=>({})})],lt.prototype,"validationRules",void 0),v([Q({default:()=>({})})],lt.prototype,"validationMessages",void 0),v([Q({default:st.DEMAND,validator:t=>Object.values(st).includes(t)})],lt.prototype,"validationBehavior",void 0),v([Q({default:!1})],lt.prototype,"errorsDisabled",void 0),v([Q({default:()=>t=>t})],lt.prototype,"modelGetConverter",void 0),v([Q({default:()=>t=>t})],lt.prototype,"modelSetConverter",void 0),v([tt("value")],lt.prototype,"onValueChange",null),v([tt("proxy")],lt.prototype,"onProxyChange",null),lt=v([q({name:"FormularioField",inheritAttrs:!1})],lt);const ct=lt;var ft=function(){var t=this,e=t.$createElement;return(t._self._c||e)("div",t._b({},"div",t.$attrs,!1),[t._t("default",null,{context:t.context})],2)};ft._withStripped=!0;const dt=ut({render:ft,staticRenderFns:[]},undefined,ct,undefined,false,undefined,!1,void 0,void 0,void 0);let pt=class extends t{get fullPath(){const t=""+this.name;return parseInt(t).toString()===t?`${this.__Formulario_path}[${t}]`:""===this.__Formulario_path?t:`${this.__Formulario_path}.${t}`}};v([Z({default:""})],pt.prototype,"__Formulario_path",void 0),v([Q({required:!0})],pt.prototype,"name",void 0),v([K("__Formulario_path")],pt.prototype,"fullPath",null),pt=v([q({name:"FormularioFieldGroup"})],pt);const ht=pt;var mt=function(){var t=this,e=t.$createElement;return(t._self._c||e)("div",[t._t("default")],2)};mt._withStripped=!0;const yt=ut({render:mt,staticRenderFns:[]},undefined,ht,undefined,false,undefined,!1,void 0,void 0,void 0),vt=(t,e,r)=>void 0===r?N(t,e):O(t,e,r);let gt=class extends t{constructor(){super(...arguments),this.proxy={},this.registry=new Map,this.localFieldsErrors={},this.localFormErrors=[]}get fieldsErrorsComputed(){return n(this.fieldsErrors||{},this.localFieldsErrors)}get formErrorsComputed(){return[...this.formErrors,...this.localFormErrors]}register(t,e){this.registry.has(t)||this.registry.set(t,e);const r=b(this.proxy,t);e.hasModel?j(e.proxy,r)||(this.setFieldValue(t,e.proxy),this.emitInput()):void 0!==r?e.proxy=r:(this.setFieldValue(t,null),this.emitInput()),o(this.fieldsErrorsComputed,t)&&e.setErrors(this.fieldsErrorsComputed[t])}unregister(t){this.registry.has(t)&&(this.registry.delete(t),this.proxy=N(this.proxy,t),this.emitInput())}getState(){return this.proxy}setFieldValue(t,e){this.proxy=vt(this.proxy,t,e)}emitInput(){this.$emit("input",y(this.proxy))}emitValidation(t,e){this.$emit("validation",{path:t,violations:e})}onStateChange(t){const e=y(t),r=this.proxy;let o=!1;this.registry.forEach(((n,i)=>{const a=b(t,i,null),s=b(r,i,null);n.proxy=a,j(a,s)||(n.$emit("input",a),vt(e,i,a),o=!0)})),this.proxy=e,o&&this.emitInput()}onFieldsErrorsChange(t){this.registry.forEach(((e,r)=>{e.setErrors(t[r]||[])}))}created(){this.$formulario.register(this.id,this),"object"==typeof this.state&&(this.proxy=y(this.state))}beforeDestroy(){this.$formulario.unregister(this.id)}runValidation(){const t=[],e={};return this.registry.forEach(((r,o)=>{t.push(r.runValidation().then((t=>{e[o]=t})))})),Promise.all(t).then((()=>e))}hasValidationErrors(){return this.runValidation().then((t=>Object.keys(t).some((e=>t[e].length>0))))}setErrors({fieldsErrors:t,formErrors:e}){this.localFieldsErrors=t||{},this.localFormErrors=e||[]}resetValidation(){this.localFieldsErrors={},this.localFormErrors=[],this.registry.forEach((t=>{t.resetValidation()}))}onSubmit(){return this.runValidation().then((t=>{Object.keys(t).some((e=>t[e].length>0))?this.$emit("error",t):this.$emit("submit",y(this.proxy))}))}};v([J("input",{default:()=>({})})],gt.prototype,"state",void 0),v([Q({default:()=>(t=>{const e=(u.get(t)||0)+1;return u.set(t,e),`${t}-${e}`})("formulario-form")})],gt.prototype,"id",void 0),v([Q({default:()=>({})})],gt.prototype,"fieldsErrors",void 0),v([Q({default:()=>[]})],gt.prototype,"formErrors",void 0),v([K("__FormularioForm_register")],gt.prototype,"register",null),v([K("__FormularioForm_unregister")],gt.prototype,"unregister",null),v([K("__FormularioForm_getState")],gt.prototype,"getState",null),v([K("__FormularioForm_set")],gt.prototype,"setFieldValue",null),v([K("__FormularioForm_emitInput")],gt.prototype,"emitInput",null),v([K("__FormularioForm_emitValidation")],gt.prototype,"emitValidation",null),v([tt("state",{deep:!0})],gt.prototype,"onStateChange",null),v([tt("fieldsErrorsComputed",{deep:!0,immediate:!0})],gt.prototype,"onFieldsErrorsChange",null),gt=v([q({name:"FormularioForm"})],gt);const _t=gt;var bt=function(){var t=this,e=t.$createElement;return(t._self._c||e)("form",{on:{submit:function(e){return e.preventDefault(),t.onSubmit(e)}}},[t._t("default",null,{errors:t.formErrorsComputed})],2)};bt._withStripped=!0;const Ot=ut({render:bt,staticRenderFns:[]},undefined,_t,undefined,false,undefined,!1,void 0,void 0,void 0);return{Formulario:V,install(t,e){t.component("FormularioField",dt),t.component("FormularioFieldGroup",yt),t.component("FormularioForm",Ot),t.component("FormularioInput",dt),t.component("FormularioGrouping",yt),t.mixin({beforeCreate(){const t=this.$options;"function"==typeof t.formulario?this.$formulario=t.formulario():t.parent&&t.parent.$formulario?this.$formulario=t.parent.$formulario:this.$formulario=new V(e)}})}}}(Vue); diff --git a/dist/formulario.umd.js b/dist/formulario.umd.js index ff5a127..50bcba8 100644 --- a/dist/formulario.umd.js +++ b/dist/formulario.umd.js @@ -71,6 +71,15 @@ TYPE["UNDEFINED"] = "UNDEFINED"; TYPE["NULL"] = "NULL"; })(TYPE || (TYPE = {})); + const constructorOf = (value) => { + return Object.getPrototypeOf(value).constructor; + }; + function isRecord(value) { + return constructorOf(value) === Object && Object.keys(Object.getPrototypeOf(value)).length === 0; + } + function isRecordLike(value) { + return typeof value === 'object' && value !== null && (isRecord(value) || Array.isArray(value)); + } function typeOf(value) { switch (typeof value) { case 'bigint': @@ -97,16 +106,13 @@ if (Array.isArray(value)) { return TYPE.ARRAY; } - if (value.constructor.name === 'Object') { + if (isRecord(value)) { return TYPE.RECORD; } - return 'InstanceOf<' + value.constructor.name + '>'; + return 'InstanceOf<' + constructorOf(value).name + '>'; } throw new Error(); } - function isRecordLike(value) { - return typeof value === 'object' && value !== null && ['Array', 'Object'].includes(value.constructor.name); - } function isScalar(value) { switch (typeof value) { case 'bigint':