diff --git a/dist/formulario.esm.js b/dist/formulario.esm.js index dcb5a2f..e9d61b1 100644 --- a/dist/formulario.esm.js +++ b/dist/formulario.esm.js @@ -1,4 +1,4 @@ -import t from"is-url";import e from"nanoid/non-secure";import r from"is-plain-object";import i from"vue";import{Provide as s,Model as o,Prop as a,Watch as n,Component as l,Inject as h}from"vue-property-decorator";const u=(t,e)=>({classification:t,component:"FormularioInput"+(e||t[0].toUpperCase()+t.substr(1))});var d=Object.assign(Object.assign({},["text","email","number","color","date","hidden","month","password","search","tel","time","url","week","datetime-local"].reduce((t,e)=>Object.assign(Object.assign({},t),{[e]:u("text")}),{})),{range:u("slider"),textarea:u("textarea","TextArea"),checkbox:u("box"),radio:u("box"),submit:u("button"),button:u("button"),select:u("select"),file:u("file"),image:u("file"),group:u("group")});class p{constructor(t,e={},r={}){this.input=t,this.fileList=t.files,this.files=[],this.options=Object.assign({mimes:{}},r),this.results=!1,this.context=e,Array.isArray(this.fileList)?this.rehydrateFileList(this.fileList):this.addFileList(this.fileList)}rehydrateFileList(t){const e=t.reduce((t,e)=>{const r=e[this.options?this.options.fileUrlKey:"url"],i=!(!r||-1===r.lastIndexOf("."))&&r.substr(r.lastIndexOf(".")+1),s=this.options.mimes[i]||!1;return t.push(Object.assign({},e,r?{name:r.substr(r.lastIndexOf("/")+1||0),type:e.type?e.type:s,previewData:r}:{})),t},[]);this.results=t,this.addFileList(e)}addFileList(t){for(let r=0;rthis.removeFile(s),previewData:i.previewData||!1})}}hasUploader(){return!!this.context.uploader}uploaderIsAxios(){return this.hasUploader&&"function"==typeof this.context.uploader.request&&"function"==typeof this.context.uploader.get&&"function"==typeof this.context.uploader.delete&&"function"==typeof this.context.uploader.post}getUploader(...t){if(this.uploaderIsAxios()){const e=new FormData;if(e.append(this.context.name||"file",t[0]),!1===this.context.uploadUrl)throw new Error("No uploadURL specified: https://vueformulate.com/guide/inputs/file/#props");return this.context.uploader.post(this.context.uploadUrl,e,{headers:{"Content-Type":"multipart/form-data"},onUploadProgress:e=>{t[1](Math.round(100*e.loaded/e.total))}}).then(t=>t.data).catch(t[2])}return this.context.uploader(...t)}upload(){return this.results?Promise.resolve(this.results):new Promise((t,e)=>{if(!this.hasUploader)return e(new Error("No uploader has been defined"));Promise.all(this.files.map(t=>t.path?Promise.resolve(t.path):this.getUploader(t.file,e=>{t.progress=e,e>=100&&(t.complete||(t.justFinished=!0,setTimeout(()=>{t.justFinished=!1},this.options.uploadJustCompleteDuration)),t.complete=!0)},e=>{t.progress=0,t.error=e,t.complete=!0},this.options))).then(e=>{this.results=e,t(e)}).catch(t=>{throw new Error(t)})})}removeFile(t){if(this.files=this.files.filter(e=>e.uuid!==t),this.context.performValidation(),window&&this.fileList instanceof FileList){const t=new DataTransfer;this.files.map(({file:e})=>t.items.add(e)),this.fileList=t.files,this.input=t}}loadPreviews(){this.files.map(t=>{if(!t.previewData&&window&&window.FileReader&&/^image\//.test(t.file.type)){const e=new FileReader;e.onload=e=>Object.assign(t,{previewData:e.target.result}),e.readAsDataURL(t.file)}})}getFileList(){return this.fileList}getFiles(){return this.files}toString(){const t=this.files.length?this.files.length+" files":"empty";return this.results?JSON.stringify(this.results,null," "):`FileUpload(${t})`}}function c(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 m(t){return"string"==typeof t&&/^[\^]/.test(t.charAt(0))?[f(t.substr(1)),t.charAt(0)]:[f(t),null]}function g(t){return t?"string"==typeof t?[t]:Array.isArray(t)?t:"object"==typeof t?Object.values(t):[]:[]}function y(t,e){return"string"==typeof t?y(t.split("|"),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]=m(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,s]=m(r.shift());if(Object.prototype.hasOwnProperty.call(e,i))return[e[i],r.length?r.join(":").split(","):[],i,s];throw new Error("Unknown validation rule "+t)}return!1}(t,e)).filter(t=>!!t):[]}function v(t){switch(typeof t){case"symbol":case"number":case"string":case"boolean":case"undefined":return!0;default:return null===t}}function b(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function E(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 x={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=b(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=b(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((()=>{const s=e();let o=i;return o||(o=/_confirm$/.test(r)?r.substr(0,r.length-8):r+"_confirm"),s[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?c(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))),mime({value:t},...e){if(t instanceof p){const r=t.getFiles(),i=t=>e.includes(t.type),s=r.reduce((t,{file:e})=>t&&i(e),!0);return Promise.resolve(s)}return Promise.resolve(!0)},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?c(e,t):e===t)),number:({value:t})=>Promise.resolve(!isNaN(Number(t))),required:({value:t},e=!0)=>Promise.resolve(!(e&&!["no","false"].includes(e))||(Array.isArray(t)?!!t.length:t instanceof p?t.getFiles().length>0:"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)},V={csv:"text/csv",gif:"image/gif",jpeg:"image/jpeg",jpg:"image/jpeg",png:"image/png",pdf:"application/pdf",svg:"image/svg+xml"};const w={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 O(t){t.extend({validationMessages:w})}function $(t,e,r,i){return new Promise(r=>{const s=(i.fauxUploaderDuration||2e3)*(.5+Math.random()),o=performance.now(),a=()=>setTimeout(()=>{const i=performance.now()-o,n=Math.min(100,Math.round(i/s*100));if(e(n),n>=100)return r({url:"http://via.placeholder.com/350x150.png",name:t.name});a()},20);a()})} +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} /*! ***************************************************************************** Copyright (c) Microsoft Corporation. @@ -12,5 +12,4 @@ 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 F(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 s=0;for(i=Object.getOwnPropertySymbols(t);s=0;n--)(s=t[n])&&(a=(o<3?s(a):o>3?s(e,r,a):s(e,r))||a);return o>3&&a&&Object.defineProperty(e,r,a),a}class A{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],F(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=b(e.$options.propsData,"formularioValue"),i=b(e.$options.propsData,"value");!r&&this.ctx.hasInitialValue&&void 0!==E(this.ctx.initialValues,t)?e.context.model=E(this.ctx.initialValues,t):!r&&!i||c(e.proxy,E(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 N{constructor(t){this.form=t}hasValidationErrors(){return this.form.hasValidationErrors()}values(){return new Promise((t,e)=>{const r=this.form,i=[],s=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)&&(v(e[i])||e[i]instanceof p?r[i]=e[i]:r[i]=t(e[i]));return r}(r.proxy);for(const t in s)Object.prototype.hasOwnProperty.call(s,t)&&"object"==typeof r.proxy[t]&&r.proxy[t]instanceof p&&i.push(r.proxy[t].upload().then(e=>Object.assign(s,{[t]:e})));Promise.all(i).then(()=>t(s)).catch(t=>e(t))})}}let P=class extends i{constructor(){super(...arguments),this.formularioRegister=this.register,this.formularioDeregister=this.deregister,this.formularioSetter=this.setFieldValue,this.getFormValues=()=>this.proxy,this.path="",this.proxy={},this.registry=new A(this),this.childrenShouldShowErrors=!1,this.formShouldShowErrors=!1,this.errorObservers=[],this.namedErrors=[],this.namedFieldErrors={}}formularioFieldValidation(t){this.$emit("validation",t)}removeErrorObserver(t){this.errorObservers=this.errorObservers.filter(e=>e.callback!==t)}get mergedFormErrors(){return this.formErrors.concat(this.namedErrors)}get mergedFieldErrors(){const t={};if(this.errors)for(const e in this.errors)t[e]=g(this.errors[e]);for(const e in this.namedFieldErrors)t[e]=g(this.namedFieldErrors[e]);return t}get hasFormErrorObservers(){return this.errorObservers.some(t=>"form"===t.type)}get hasInitialValue(){return this.formularioValue&&"object"==typeof this.formularioValue||this.values&&"object"==typeof this.values||this.isGrouping&&"object"==typeof this.context.model[this.index]}get isVmodeled(){return!!(b(this.$options.propsData,"formularioValue")&&this._events&&Array.isArray(this._events.input)&&this._events.input.length)}get initialValues(){return b(this.$options.propsData,"formularioValue")&&"object"==typeof this.formularioValue?Object.assign({},this.formularioValue):b(this.$options.propsData,"values")&&"object"==typeof this.values?Object.assign({},this.values):this.isGrouping&&"object"==typeof this.context.model[this.index]?this.context.model[this.index]:{}}onFormularioValueChanged(t){this.isVmodeled&&t&&"object"==typeof t&&this.setValues(t)}onMergedFormErrorsChanged(t){this.errorObservers.filter(t=>"form"===t.type).forEach(e=>e.callback(t))}onMergedFieldErrorsChanged(t){this.errorObservers.filter(t=>"input"===t.type).forEach(e=>e.callback(t[e.field]||[]))}created(){this.$formulario.register(this),this.applyInitialValues()}destroyed(){this.$formulario.deregister(this)}register(t,e){this.registry.register(t,e)}deregister(t){this.registry.remove(t)}applyErrors({formErrors:t,inputErrors:e}){this.namedErrors=t,this.namedFieldErrors=e}addErrorObserver(t){this.errorObservers.find(e=>t.callback===e.callback)||(this.errorObservers.push(t),"form"===t.type?t.callback(this.mergedFormErrors):b(this.mergedFieldErrors,t.field)&&t.callback(this.mergedFieldErrors[t.field]))}registerErrorComponent(t){this.errorComponents.includes(t)||this.errorComponents.push(t)}formSubmitted(){this.showErrors();const t=new N(this);return this.$emit("submit-raw",t),t.hasValidationErrors().then(e=>e?void 0:t.values()).then(t=>{if(void 0!==t)return this.$emit("submit",t),t})}applyInitialValues(){this.hasInitialValue&&(this.proxy=this.initialValues)}setFieldValue(t,e,r=!0){if(void 0===e){const e=this.proxy,r=t,i=(e[r],F(e,["symbol"==typeof r?r:r+""]));this.proxy=i}else!function(t,e,r){const i=e.split(".");let s=t;for(let t=0;t(t.push(e.performValidation()&&e.getValidationErrors()),t),[])).then(t=>t.some(t=>t.hasErrors))}showErrors(){this.childrenShouldShowErrors=!0,this.registry.forEach(t=>{t.formShouldShowErrors=!0})}hideErrors(){this.childrenShouldShowErrors=!1,this.registry.forEach(t=>{t.formShouldShowErrors=!1,t.behavioralErrorVisibility=!1})}setValues(t){const e=Array.from(new Set(Object.keys(t).concat(Object.keys(this.proxy))));let r=!1;e.forEach(e=>{this.registry.hasNested(e)&&this.registry.getNested(e).forEach((e,i)=>{c(E(t,i),E(this.proxy,i))||(this.setFieldValue(i,E(t,i),!1),r=!0),c(E(t,i),this.registry.get(i).proxy)||(this.registry.get(i).context.model=E(t,i))})}),this.applyInitialValues(),r&&this.$emit("input",Object.assign({},this.proxy))}};function R(t,e,r,i,s,o,a,n,l,h){"boolean"!=typeof a&&(l=n,n=a,a=!1);const u="function"==typeof r?r.options:r;let d;if(t&&t.render&&(u.render=t.render,u.staticRenderFns=t.staticRenderFns,u._compiled=!0,s&&(u.functional=!0)),i&&(u._scopeId=i),o?(d=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(o)},u._ssrRegister=d):e&&(d=a?function(t){e.call(this,h(t,this.$root.$options.shadowRoot))}:function(t){e.call(this,n(t))}),d)if(u.functional){const t=u.render;u.render=function(e,r){return d.call(r),t(e,r)}}else{const t=u.beforeCreate;u.beforeCreate=t?[].concat(t,d):[d]}return r}j([s()],P.prototype,"formularioFieldValidation",null),j([s()],P.prototype,"formularioRegister",void 0),j([s()],P.prototype,"formularioDeregister",void 0),j([s()],P.prototype,"formularioSetter",void 0),j([s()],P.prototype,"getFormValues",void 0),j([s()],P.prototype,"path",void 0),j([s()],P.prototype,"removeErrorObserver",null),j([o("input",{type:Object,default:()=>({})})],P.prototype,"formularioValue",void 0),j([a({type:[String,Boolean],default:!1})],P.prototype,"name",void 0),j([a({type:[Object,Boolean],default:!1})],P.prototype,"values",void 0),j([a({default:!1})],P.prototype,"errors",void 0),j([a({default:()=>[]})],P.prototype,"formErrors",void 0),j([n("formularioValue",{deep:!0})],P.prototype,"onFormularioValueChanged",null),j([n("mergedFormErrors")],P.prototype,"onMergedFormErrorsChanged",null),j([n("mergedFieldErrors",{immediate:!0})],P.prototype,"onMergedFieldErrorsChanged",null),j([s()],P.prototype,"addErrorObserver",null),P=j([l({name:"FormularioForm"})],P);const S=P;var D=function(){var t=this,e=t.$createElement;return(t._self._c||e)("form",{on:{submit:function(e){return e.preventDefault(),t.formSubmitted(e)}}},[t._t("default",null,{errors:t.mergedFormErrors})],2)};D._withStripped=!0;const U=R({render:D,staticRenderFns:[]},void 0,S,void 0,!1,void 0,!1,void 0,void 0,void 0),_={BLUR:"blur",LIVE:"live",SUBMIT:"submit"};let I=class extends i{constructor(){super(...arguments),this.formularioRegisterRule=this.registerRule,this.formularioRemoveRule=this.removeRule,this.defaultId=this.$formulario.nextId(this),this.localAttributes={},this.localErrors=[],this.proxy=this.getInitialValue(),this.behavioralErrorVisibility="live"===this.errorBehavior,this.formShouldShowErrors=!1,this.validationErrors=[],this.pendingValidation=Promise.resolve(),this.ruleRegistry=[],this.messageRegistry={}}get context(){return this.defineModel({id:this.id||this.defaultId,name:this.nameOrFallback,attributes:this.elementAttributes,blurHandler:this.blurHandler.bind(this),disableErrors:this.disableErrors,errors:this.explicitErrors,allErrors:this.allErrors,formShouldShowErrors:this.formShouldShowErrors,getValidationErrors:this.getValidationErrors.bind(this),hasGivenName:this.hasGivenName,hasValidationErrors:this.hasValidationErrors.bind(this),imageBehavior:this.imageBehavior,performValidation:this.performValidation.bind(this),preventWindowDrops:this.preventWindowDrops,setErrors:this.setErrors.bind(this),showValidationErrors:this.showValidationErrors,uploadBehavior:this.uploadBehavior,uploadUrl:this.mergedUploadUrl,uploader:this.uploader||this.$formulario.getUploader(),validationErrors:this.validationErrors,value:this.value,visibleValidationErrors:this.visibleValidationErrors})}get parsedValidationRules(){const t={};return Object.keys(this.validationRules).forEach(e=>{t[f(e)]=this.validationRules[e]}),t}get messages(){const t={};return Object.keys(this.validationMessages).forEach(e=>{t[f(e)]=this.validationMessages[e]}),Object.keys(this.messageRegistry).forEach(e=>{t[f(e)]=this.messageRegistry[e]}),t}get elementAttributes(){const t=Object.assign({},this.localAttributes);return this.id?t.id=this.id:t.id=this.defaultId,this.hasGivenName&&(t.name=this.name),this.help&&(t["aria-describedby"]=t.id+"-help"),t}get nameOrFallback(){return""!==this.path?`${this.path}.${this.name}`:this.name}get hasGivenName(){return"boolean"!=typeof this.name}get mergedValidationName(){return this.validationName||this.name}get mergedUploadUrl(){return this.uploadUrl||this.$formulario.getUploadUrl()}get hasErrors(){return this.allErrors.length>0}get hasVisibleErrors(){return this.validationErrors&&this.showValidationErrors||!!this.explicitErrors.length}get allErrors(){return[...this.explicitErrors,...g(this.validationErrors)]}get visibleValidationErrors(){return this.showValidationErrors&&this.validationErrors.length?this.validationErrors:[]}get explicitErrors(){return[...g(this.errors),...this.localErrors].map(t=>({rule:null,context:null,message:t}))}get isVmodeled(){return!!(Object.prototype.hasOwnProperty.call(this.$options.propsData,"formularioValue")&&this._events&&Array.isArray(this._events.input)&&this._events.input.length)}get showValidationErrors(){return this.showErrors||this.formShouldShowErrors||this.behavioralErrorVisibility}onAttrsChanged(t){this.updateLocalAttributes(t)}onProxyChanged(t,e){this.errorBehavior===_.LIVE?this.performValidation():this.validationErrors=[],this.isVmodeled||c(t,e)||(this.context.model=t)}onFormularioValueChanged(t,e){this.isVmodeled&&!c(t,e)&&(this.context.model=t)}onShowValidationErrorsChanged(t){this.$emit("error-visibility",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.updateLocalAttributes(this.$attrs),this.errorBehavior===_.LIVE&&this.performValidation()}beforeDestroy(){this.disableErrors||"function"!=typeof this.removeErrorObserver||this.removeErrorObserver(this.setErrors),"function"==typeof this.formularioDeregister&&this.formularioDeregister(this.nameOrFallback)}defineModel(t){return Object.defineProperty(t,"model",{get:this.modelGetter.bind(this),set:this.modelSetter.bind(this)})}modelGetter(){const t=this.isVmodeled?"formularioValue":"proxy";return void 0===this[t]?"":this[t]}modelSetter(t){c(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"),"blur"===this.errorBehavior&&(this.behavioralErrorVisibility=!0)}getInitialValue(){return b(this.$options.propsData,"value")?this.value:b(this.$options.propsData,"formularioValue")?this.formularioValue:""}applyInitialValue(){c(this.context.model,this.proxy)||(this.context.model=this.proxy)}updateLocalAttributes(t){c(t,this.localAttributes)||(this.localAttributes=t)}performValidation(){let t=y(this.validation,this.$formulario.rules(this.parsedValidationRules));return t=this.ruleRegistry.length?this.ruleRegistry.concat(t):t,this.pendingValidation=this.runRules(t).then(t=>this.didValidate(t)),this.pendingValidation}runRules(t){const e=([t,e,r])=>{let i=t({value:this.context.model,getFormValues:this.getFormValues.bind(this),name:this.context.name},...e);return i=i instanceof Promise?i:Promise.resolve(i),i.then(t=>!t&&this.getMessageObject(r,e))};return new Promise(r=>{const i=(t,s=[])=>{const o=t.shift();Array.isArray(o)&&o.length?Promise.all(o.map(e)).then(t=>t.filter(t=>!!t)).then(e=>(e=Array.isArray(e)?e:[]).length&&o.bail||!t.length?r(s.concat(e)):i(t,s.concat(e))):r([])};i(function(t){const e=[],r=t.findIndex(([,,t])=>"bail"===t.toLowerCase());if(r>=0){const i=t.splice(0,r+1).slice(0,-1);i.length&&e.push(i),t.map(t=>e.push(Object.defineProperty([t],"bail",{value:!0})))}else e.push(t);return e.reduce((t,e)=>{const r=(t,e=!1)=>{if(t.length<2)return Object.defineProperty([t],"bail",{value:e});const i=[],s=t.findIndex(([,,,t])=>"^"===t);if(s>=0){const o=t.splice(0,s);o.length&&i.push(...r(o,e)),i.push(Object.defineProperty([t.shift()],"bail",{value:!0})),t.length&&i.push(...r(t,e))}else i.push(t);return i};return t.concat(r(e))},[])}(t))})}didValidate(t){const e=!c(t,this.validationErrors);if(this.validationErrors=t,e){const t=this.getErrorObject();this.$emit("validation",t),this.formularioFieldValidation&&"function"==typeof this.formularioFieldValidation&&this.formularioFieldValidation(t)}}getMessageObject(t,e){const r={args:e,name:this.mergedValidationName,value:this.context.model,vm:this,formValues:this.getFormValues()};return{rule:t,context:r,message:this.getMessageFunc(t)(r)}}getMessageFunc(t){if(t=f(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))})})}getValidationErrors(){return new Promise(t=>{this.$nextTick(()=>this.pendingValidation.then(()=>t(this.getErrorObject())))})}getErrorObject(){return{name:this.context.nameOrFallback||this.context.name,errors:this.validationErrors.filter(t=>"object"==typeof t),hasErrors:!!this.validationErrors.length}}setErrors(t){this.localErrors=g(t)}registerRule(t,e,r,i=null){this.ruleRegistry.some(t=>t[2]===r)||(this.ruleRegistry.push([t,e,r]),null!==i&&(this.messageRegistry[r]=i))}removeRule(t){const e=this.ruleRegistry.findIndex(e=>e[2]===t);e>=0&&(this.ruleRegistry.splice(e,1),delete this.messageRegistry[t])}};j([h({default:void 0})],I.prototype,"formularioSetter",void 0),j([h({default:()=>()=>{}})],I.prototype,"formularioFieldValidation",void 0),j([h({default:void 0})],I.prototype,"formularioRegister",void 0),j([h({default:void 0})],I.prototype,"formularioDeregister",void 0),j([h({default:()=>()=>({})})],I.prototype,"getFormValues",void 0),j([h({default:void 0})],I.prototype,"addErrorObserver",void 0),j([h({default:void 0})],I.prototype,"removeErrorObserver",void 0),j([h({default:""})],I.prototype,"path",void 0),j([s()],I.prototype,"formularioRegisterRule",void 0),j([s()],I.prototype,"formularioRemoveRule",void 0),j([o("input",{default:""})],I.prototype,"formularioValue",void 0),j([a({type:[String,Number,Boolean],default:!1})],I.prototype,"id",void 0),j([a({default:"text"})],I.prototype,"type",void 0),j([a({required:!0})],I.prototype,"name",void 0),j([a({default:!1})],I.prototype,"value",void 0),j([a({type:[String,Boolean,Array],default:!1})],I.prototype,"validation",void 0),j([a({type:[String,Boolean],default:!1})],I.prototype,"validationName",void 0),j([a({type:Object,default:()=>({})})],I.prototype,"validationRules",void 0),j([a({type:Object,default:()=>({})})],I.prototype,"validationMessages",void 0),j([a({type:[Array,String,Boolean],default:!1})],I.prototype,"errors",void 0),j([a({type:String,default:_.BLUR,validator:t=>[_.BLUR,_.LIVE,_.SUBMIT].includes(t)})],I.prototype,"errorBehavior",void 0),j([a({default:!1})],I.prototype,"showErrors",void 0),j([a({default:!1})],I.prototype,"disableErrors",void 0),j([a({default:!0})],I.prototype,"preventWindowDrops",void 0),j([a({default:"preview"})],I.prototype,"imageBehavior",void 0),j([a({default:!1})],I.prototype,"uploader",void 0),j([a({default:!1})],I.prototype,"uploadUrl",void 0),j([a({default:"live"})],I.prototype,"uploadBehavior",void 0),j([n("$attrs",{deep:!0})],I.prototype,"onAttrsChanged",null),j([n("proxy")],I.prototype,"onProxyChanged",null),j([n("formularioValue")],I.prototype,"onFormularioValueChanged",null),j([n("showValidationErrors",{immediate:!0})],I.prototype,"onShowValidationErrorsChanged",null),I=j([l({name:"FormularioInput",inheritAttrs:!1})],I);const k=I;var C=function(){var t=this,e=t.$createElement;return(t._self._c||e)("div",{staticClass:"formulario-input",attrs:{"data-has-errors":t.hasErrors,"data-is-showing-errors":t.hasVisibleErrors,"data-type":t.type}},[t._t("default",null,{id:t.id,context:t.context,errors:t.errors,validationErrors:t.validationErrors})],2)};C._withStripped=!0;const M=R({render:C,staticRenderFns:[]},void 0,k,void 0,!1,void 0,!1,void 0,void 0,void 0);let L=class extends i{get groupPath(){return this.isArrayItem?`${this.path}[${this.name}]`:""===this.path?this.name:`${this.path}.${this.name}`}};j([h({default:""})],L.prototype,"path",void 0),j([a({required:!0})],L.prototype,"name",void 0),j([a({default:!1})],L.prototype,"isArrayItem",void 0),j([s("path")],L.prototype,"groupPath",null),L=j([l({name:"FormularioGrouping"})],L);const B=L;var T=function(){var t=this.$createElement;return(this._self._c||t)("div",{staticClass:"formulario-group",attrs:{"data-type":"group"}},[this._t("default")],2)};T._withStripped=!0;const W=R({render:T,staticRenderFns:[]},void 0,B,void 0,!1,void 0,!1,void 0,void 0,void 0);var G=new class{constructor(){this.options={},this.defaults={components:{FormularioForm:U,FormularioInput:M,FormularioGrouping:W},library:d,rules:x,mimes:V,locale:!1,uploader:$,uploadUrl:!1,fileUrlKey:"url",uploadJustCompleteDuration:1e3,errorHandler:t=>t,plugins:[O],validationMessages:{},idPrefix:"formulario-"},this.registry=new Map,this.idRegistry={}}install(t,e){t.prototype.$formulario=this,this.options=this.defaults;let r=this.defaults.plugins;e&&Array.isArray(e.plugins)&&e.plugins.length&&(r=r.concat(e.plugins)),r.forEach(t=>"function"==typeof t?t(this):null),this.extend(e||{});for(const e in this.options.components)Object.prototype.hasOwnProperty.call(this.options.components,e)&&t.component(e,this.options.components[e])}nextId(t){const e=this.options,r=!(!t.$route||!t.$route.path)&&t.$route.path?t.$route.path.replace(/[/\\.\s]/g,"-"):"global";return b(this.idRegistry,r)||(this.idRegistry[r]=0),`${e.idPrefix}${r}-${++this.idRegistry[r]}`}extend(t){if("object"==typeof t)return this.options=function t(e,i,s=!0){const o={};for(const a in e)b(i,a)?r(i[a])&&r(e[a])?o[a]=t(e[a],i[a],s):s&&Array.isArray(e[a])&&Array.isArray(i[a])?o[a]=e[a].concat(i[a]):o[a]=i[a]:o[a]=e[a];for(const t in i)b(o,t)||(o[t]=i[t]);return o}(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 b(this.options.validationMessages,t)?this.options.validationMessages[t](r,e):this.options.validationMessages.default(r,e)}register(t){"FormularioForm"===t.$options.name&&t.name&&this.registry.set(t.name,t)}deregister(t){"FormularioForm"===t.$options.name&&t.name&&this.registry.has(t.name)&&this.registry.delete(t.name)}handle(t,e,r=!1){const i=r?t:this.options.errorHandler(t,e);if(e&&this.registry.has(e)){this.registry.get(e).applyErrors({formErrors:g(i.formErrors),inputErrors:i.inputErrors||{}})}return i}reset(t,e={}){this.resetValidation(t),this.setValues(t,e)}resetValidation(t){const e=this.registry.get(t);e.hideErrors(t),e.namedErrors=[],e.namedFieldErrors={}}setValues(t,e){if(e){this.registry.get(t).setValues(Object.assign({},e))}}getUploader(){return this.options.uploader||!1}getUploadUrl(){return this.options.uploadUrl||!1}getFileUrlKey(){return this.options.fileUrlKey||"url"}createUpload(t,e){return new p(t,e,this.options)}};export default G; +***************************************************************************** */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; diff --git a/dist/formulario.min.js b/dist/formulario.min.js index ebb2120..113e028 100644 --- a/dist/formulario.min.js +++ b/dist/formulario.min.js @@ -1,17 +1,18 @@ -var VueFormulario=function(e){"use strict";e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;const t=(e,t)=>({classification:e,component:"FormularioInput"+(t||e[0].toUpperCase()+e.substr(1))});var r=Object.assign(Object.assign({},["text","email","number","color","date","hidden","month","password","search","tel","time","url","week","datetime-local"].reduce((e,r)=>Object.assign(Object.assign({},e),{[r]:t("text")}),{})),{range:t("slider"),textarea:t("textarea","TextArea"),checkbox:t("box"),radio:t("box"),submit:t("button"),button:t("button"),select:t("select"),file:t("file"),image:t("file"),group:t("group")}),i=function(e){if("string"!=typeof e)return!1;var t=e.match(o);if(!t)return!1;var r=t[1];if(!r)return!1;if(s.test(r)||a.test(r))return!0;return!1},o=/^(?:\w+:)?\/\/(\S+)$/,s=/^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/,a=/^[^\s\.]+\.\S{2,}$/;for(var n="-_",l=36;l--;)n+=l.toString(36);for(l=36;l---10;)n+=l.toString(36).toUpperCase();var u=function(e){var t="";for(l=e||21;l--;)t+=n[64*Math.random()|0];return t};class d{constructor(e,t={},r={}){this.input=e,this.fileList=e.files,this.files=[],this.options=Object.assign({mimes:{}},r),this.results=!1,this.context=t,Array.isArray(this.fileList)?this.rehydrateFileList(this.fileList):this.addFileList(this.fileList)}rehydrateFileList(e){const t=e.reduce((e,t)=>{const r=t[this.options?this.options.fileUrlKey:"url"],i=!(!r||-1===r.lastIndexOf("."))&&r.substr(r.lastIndexOf(".")+1),o=this.options.mimes[i]||!1;return e.push(Object.assign({},t,r?{name:r.substr(r.lastIndexOf("/")+1||0),type:t.type?t.type:o,previewData:r}:{})),e},[]);this.results=e,this.addFileList(t)}addFileList(e){for(let t=0;tthis.removeFile(i),previewData:r.previewData||!1})}}hasUploader(){return!!this.context.uploader}uploaderIsAxios(){return this.hasUploader&&"function"==typeof this.context.uploader.request&&"function"==typeof this.context.uploader.get&&"function"==typeof this.context.uploader.delete&&"function"==typeof this.context.uploader.post}getUploader(...e){if(this.uploaderIsAxios()){const t=new FormData;if(t.append(this.context.name||"file",e[0]),!1===this.context.uploadUrl)throw new Error("No uploadURL specified: https://vueformulate.com/guide/inputs/file/#props");return this.context.uploader.post(this.context.uploadUrl,t,{headers:{"Content-Type":"multipart/form-data"},onUploadProgress:t=>{e[1](Math.round(100*t.loaded/t.total))}}).then(e=>e.data).catch(e[2])}return this.context.uploader(...e)}upload(){return this.results?Promise.resolve(this.results):new Promise((e,t)=>{if(!this.hasUploader)return t(new Error("No uploader has been defined"));Promise.all(this.files.map(e=>e.path?Promise.resolve(e.path):this.getUploader(e.file,t=>{e.progress=t,t>=100&&(e.complete||(e.justFinished=!0,setTimeout(()=>{e.justFinished=!1},this.options.uploadJustCompleteDuration)),e.complete=!0)},t=>{e.progress=0,e.error=t,e.complete=!0},this.options))).then(t=>{this.results=t,e(t)}).catch(e=>{throw new Error(e)})})}removeFile(e){if(this.files=this.files.filter(t=>t.uuid!==e),this.context.performValidation(),window&&this.fileList instanceof FileList){const e=new DataTransfer;this.files.map(({file:t})=>e.items.add(t)),this.fileList=e.files,this.input=e}}loadPreviews(){this.files.map(e=>{if(!e.previewData&&window&&window.FileReader&&/^image\//.test(e.file.type)){const t=new FileReader;t.onload=t=>Object.assign(e,{previewData:t.target.result}),t.readAsDataURL(e.file)}})}getFileList(){return this.fileList}getFiles(){return this.files}toString(){const e=this.files.length?this.files.length+" files":"empty";return this.results?JSON.stringify(this.results,null," "):`FileUpload(${e})`}}function h(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 c(e){return"string"==typeof e&&/^[\^]/.test(e.charAt(0))?[p(e.substr(1)),e.charAt(0)]:[p(e),null]}function f(e){return e?"string"==typeof e?[e]:Array.isArray(e)?e:"object"==typeof e?Object.values(e):[]:[]}function m(e,t){return"string"==typeof e?m(e.split("|"),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]=c(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]=c(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 g(e){switch(typeof e){case"symbol":case"number":case"string":case"boolean":case"undefined":return!0;default:return null===e}}function y(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function v(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 b={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=y(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=y(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((()=>{const o=t();let s=i;return s||(s=/_confirm$/.test(r)?r.substr(0,r.length-8):r+"_confirm"),o[s]===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?h(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))),mime({value:e},...t){if(e instanceof d){const r=e.getFiles(),i=e=>t.includes(e.type),o=r.reduce((e,{file:t})=>e&&i(t),!0);return Promise.resolve(o)}return Promise.resolve(!0)},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?h(t,e):t===e)),number:({value:e})=>Promise.resolve(!isNaN(Number(e))),required:({value:e},t=!0)=>Promise.resolve(!(t&&!["no","false"].includes(t))||(Array.isArray(e)?!!e.length:e instanceof d?e.getFiles().length>0:"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(i(e)),bail:()=>Promise.resolve(!0)},E={csv:"text/csv",gif:"image/gif",jpeg:"image/jpeg",jpg:"image/jpeg",png:"image/png",pdf:"application/pdf",svg:"image/svg+xml"};const O={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 x(e){e.extend({validationMessages:O})}function w(e,t,r,i){return new Promise(r=>{const o=(i.fauxUploaderDuration||2e3)*(.5+Math.random()),s=performance.now(),a=()=>setTimeout(()=>{const i=performance.now()-s,n=Math.min(100,Math.round(i/o*100));if(t(n),n>=100)return r({url:"http://via.placeholder.com/350x150.png",name:e.name});a()},20);a()})} -/*! - * isobject - * - * Copyright (c) 2014-2017, Jon Schlinkert. - * Released under the MIT License. - */ +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)}; /*! * is-plain-object * * Copyright (c) 2014-2017, Jon Schlinkert. * Released under the MIT License. */ -function V(e){return!0==(null!=(t=e)&&"object"==typeof t&&!1===Array.isArray(t))&&"[object Object]"===Object.prototype.toString.call(e);var t}function j(e){var t,r;return!1!==V(e)&&("function"==typeof(t=e.constructor)&&(!1!==V(r=t.prototype)&&!1!==r.hasOwnProperty("isPrototypeOf")))} +function m(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} /*! ***************************************************************************** Copyright (c) Microsoft Corporation. @@ -25,10 +26,9 @@ function V(e){return!0==(null!=(t=e)&&"object"==typeof t&&!1===Array.isArray(t)) 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){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 + ***************************************************************************** */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 /** * vue-class-component v7.2.3 * (c) 2015-present Evan You * @license MIT - */}function F(e){return(F="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,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function P(e){return function(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t0&&U("Component class must inherit Vue or its descendant class when class property is used."),s}var C=["data","beforeCreate","created","beforeMount","mounted","beforeDestroy","destroyed","beforeUpdate","updated","activated","deactivated","render","errorCaptured","serverPrefetch"];function k(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};r.name=r.name||t._componentTag||t.name;var i=t.prototype;Object.getOwnPropertyNames(i).forEach((function(e){if("constructor"!==e)if(C.indexOf(e)>-1)r[e]=i[e];else{var t=Object.getOwnPropertyDescriptor(i,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,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 I(this,t)}});var o=t.__decorators__;o&&(o.forEach((function(e){return e(r)})),delete t.__decorators__);var s=Object.getPrototypeOf(t.prototype),a=s instanceof e?s.constructor:e,n=a.extend(r);return T(n,t,a),R()&&N(n,t),n}var L=["cid","super","options","superOptions","extendOptions","sealedOptions","component","directive","filter"],B={prototype:!0,arguments:!0,callee:!0,caller:!0};function T(e,t,r){Object.getOwnPropertyNames(t).forEach((function(i){if(!B[i]){var o=Object.getOwnPropertyDescriptor(e,i);if(!o||o.configurable){var s,a,n=Object.getOwnPropertyDescriptor(t,i);if(!D){if("cid"===i)return;var l=Object.getOwnPropertyDescriptor(r,i);if(s=n.value,a=F(s),null!=s&&("object"===a||"function"===a)&&l&&l.value===n.value)return}"production"!==process.env.NODE_ENV&&L.indexOf(i)>=0&&U("Static property name '".concat(i,"' 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,i,n)}}}))}function W(e){return"function"==typeof e?k(e):function(t){return k(t,e)}}W.registerHooks=function(e){C.push.apply(C,P(e))};function G(e){return M((function(t,r){void 0===t.inject&&(t.inject={}),Array.isArray(t.inject)||(t.inject[r]=e||r)}))}function K(e){return M((function(t,r){var i,o=t.provide;("function"!=typeof(i=o)||!i.managed&&!i.managedReactive)&&(o=t.provide=function(e){var t=function(){var r=this,i="function"==typeof e?e.call(this):e;for(var o in(i=Object.create(i||null)).__reactiveInject__=this.__reactiveInject__||{},t.managed)i[t.managed[o]]=this[o];var s=function(e){i[t.managedReactive[e]]=a[e],Object.defineProperty(i.__reactiveInject__,t.managedReactive[e],{enumerable:!0,get:function(){return r[e]}})},a=this;for(var o in t.managedReactive)s(o);return i};return t.managed={},t.managedReactive={},t}(o)),o.managed[r]=e||r}))}var q="undefined"!=typeof Reflect&&void 0!==Reflect.getMetadata;function H(e,t,r){if(q&&!Array.isArray(e)&&"function"!=typeof e&&void 0===e.type){var i=Reflect.getMetadata("design:type",t,r);i!==Object&&(e.type=i)}}function Y(e,t){return void 0===t&&(t={}),function(r,i){H(t,r,i),M((function(r,i){(r.props||(r.props={}))[i]=t,r.model={prop:i,event:e||i}}))(r,i)}}function z(e){return void 0===e&&(e={}),function(t,r){H(e,t,r),M((function(t,r){(t.props||(t.props={}))[r]=e}))(t,r)}}function Z(e,t){void 0===t&&(t={});var r=t.deep,i=void 0!==r&&r,o=t.immediate,s=void 0!==o&&o;return M((function(t,r){"object"!=typeof t.watch&&(t.watch=Object.create(null));var o=t.watch;"object"!=typeof o[e]||Array.isArray(o[e])?void 0===o[e]&&(o[e]=[]):o[e]=[o[e]],o[e].push({handler:r,deep:i,immediate:s})}))}class J{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],$(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=y(t.$options.propsData,"formularioValue"),i=y(t.$options.propsData,"value");!r&&this.ctx.hasInitialValue&&void 0!==v(this.ctx.initialValues,e)?t.context.model=v(this.ctx.initialValues,e):!r&&!i||h(t.proxy,v(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 X{constructor(e){this.form=e}hasValidationErrors(){return this.form.hasValidationErrors()}values(){return new Promise((e,t)=>{const r=this.form,i=[],o=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)&&(g(t[i])||t[i]instanceof d?r[i]=t[i]:r[i]=e(t[i]));return r}(r.proxy);for(const e in o)Object.prototype.hasOwnProperty.call(o,e)&&"object"==typeof r.proxy[e]&&r.proxy[e]instanceof d&&i.push(r.proxy[e].upload().then(t=>Object.assign(o,{[e]:t})));Promise.all(i).then(()=>e(o)).catch(e=>t(e))})}}let Q=class extends e{constructor(){super(...arguments),this.formularioRegister=this.register,this.formularioDeregister=this.deregister,this.formularioSetter=this.setFieldValue,this.getFormValues=()=>this.proxy,this.path="",this.proxy={},this.registry=new J(this),this.childrenShouldShowErrors=!1,this.formShouldShowErrors=!1,this.errorObservers=[],this.namedErrors=[],this.namedFieldErrors={}}formularioFieldValidation(e){this.$emit("validation",e)}removeErrorObserver(e){this.errorObservers=this.errorObservers.filter(t=>t.callback!==e)}get mergedFormErrors(){return this.formErrors.concat(this.namedErrors)}get mergedFieldErrors(){const e={};if(this.errors)for(const t in this.errors)e[t]=f(this.errors[t]);for(const t in this.namedFieldErrors)e[t]=f(this.namedFieldErrors[t]);return e}get hasFormErrorObservers(){return this.errorObservers.some(e=>"form"===e.type)}get hasInitialValue(){return this.formularioValue&&"object"==typeof this.formularioValue||this.values&&"object"==typeof this.values||this.isGrouping&&"object"==typeof this.context.model[this.index]}get isVmodeled(){return!!(y(this.$options.propsData,"formularioValue")&&this._events&&Array.isArray(this._events.input)&&this._events.input.length)}get initialValues(){return y(this.$options.propsData,"formularioValue")&&"object"==typeof this.formularioValue?Object.assign({},this.formularioValue):y(this.$options.propsData,"values")&&"object"==typeof this.values?Object.assign({},this.values):this.isGrouping&&"object"==typeof this.context.model[this.index]?this.context.model[this.index]:{}}onFormularioValueChanged(e){this.isVmodeled&&e&&"object"==typeof e&&this.setValues(e)}onMergedFormErrorsChanged(e){this.errorObservers.filter(e=>"form"===e.type).forEach(t=>t.callback(e))}onMergedFieldErrorsChanged(e){this.errorObservers.filter(e=>"input"===e.type).forEach(t=>t.callback(e[t.field]||[]))}created(){this.$formulario.register(this),this.applyInitialValues()}destroyed(){this.$formulario.deregister(this)}register(e,t){this.registry.register(e,t)}deregister(e){this.registry.remove(e)}applyErrors({formErrors:e,inputErrors:t}){this.namedErrors=e,this.namedFieldErrors=t}addErrorObserver(e){this.errorObservers.find(t=>e.callback===t.callback)||(this.errorObservers.push(e),"form"===e.type?e.callback(this.mergedFormErrors):y(this.mergedFieldErrors,e.field)&&e.callback(this.mergedFieldErrors[e.field]))}registerErrorComponent(e){this.errorComponents.includes(e)||this.errorComponents.push(e)}formSubmitted(){this.showErrors();const e=new X(this);return this.$emit("submit-raw",e),e.hasValidationErrors().then(t=>t?void 0:e.values()).then(e=>{if(void 0!==e)return this.$emit("submit",e),e})}applyInitialValues(){this.hasInitialValue&&(this.proxy=this.initialValues)}setFieldValue(e,t,r=!0){if(void 0===t){const t=this.proxy,r=e,i=(t[r],$(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.getValidationErrors()),e),[])).then(e=>e.some(e=>e.hasErrors))}showErrors(){this.childrenShouldShowErrors=!0,this.registry.forEach(e=>{e.formShouldShowErrors=!0})}hideErrors(){this.childrenShouldShowErrors=!1,this.registry.forEach(e=>{e.formShouldShowErrors=!1,e.behavioralErrorVisibility=!1})}setValues(e){const t=Array.from(new Set(Object.keys(e).concat(Object.keys(this.proxy))));let r=!1;t.forEach(t=>{this.registry.hasNested(t)&&this.registry.getNested(t).forEach((t,i)=>{h(v(e,i),v(this.proxy,i))||(this.setFieldValue(i,v(e,i),!1),r=!0),h(v(e,i),this.registry.get(i).proxy)||(this.registry.get(i).context.model=v(e,i))})}),this.applyInitialValues(),r&&this.$emit("input",Object.assign({},this.proxy))}};function ee(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}A([K()],Q.prototype,"formularioFieldValidation",null),A([K()],Q.prototype,"formularioRegister",void 0),A([K()],Q.prototype,"formularioDeregister",void 0),A([K()],Q.prototype,"formularioSetter",void 0),A([K()],Q.prototype,"getFormValues",void 0),A([K()],Q.prototype,"path",void 0),A([K()],Q.prototype,"removeErrorObserver",null),A([Y("input",{type:Object,default:()=>({})})],Q.prototype,"formularioValue",void 0),A([z({type:[String,Boolean],default:!1})],Q.prototype,"name",void 0),A([z({type:[Object,Boolean],default:!1})],Q.prototype,"values",void 0),A([z({default:!1})],Q.prototype,"errors",void 0),A([z({default:()=>[]})],Q.prototype,"formErrors",void 0),A([Z("formularioValue",{deep:!0})],Q.prototype,"onFormularioValueChanged",null),A([Z("mergedFormErrors")],Q.prototype,"onMergedFormErrorsChanged",null),A([Z("mergedFieldErrors",{immediate:!0})],Q.prototype,"onMergedFieldErrorsChanged",null),A([K()],Q.prototype,"addErrorObserver",null),Q=A([W({name:"FormularioForm"})],Q);const te=Q;var re=function(){var e=this,t=e.$createElement;return(e._self._c||t)("form",{on:{submit:function(t){return t.preventDefault(),e.formSubmitted(t)}}},[e._t("default",null,{errors:e.mergedFormErrors})],2)};re._withStripped=!0;const ie=ee({render:re,staticRenderFns:[]},void 0,te,void 0,!1,void 0,!1,void 0,void 0,void 0),oe={BLUR:"blur",LIVE:"live",SUBMIT:"submit"};let se=class extends e{constructor(){super(...arguments),this.formularioRegisterRule=this.registerRule,this.formularioRemoveRule=this.removeRule,this.defaultId=this.$formulario.nextId(this),this.localAttributes={},this.localErrors=[],this.proxy=this.getInitialValue(),this.behavioralErrorVisibility="live"===this.errorBehavior,this.formShouldShowErrors=!1,this.validationErrors=[],this.pendingValidation=Promise.resolve(),this.ruleRegistry=[],this.messageRegistry={}}get context(){return this.defineModel({id:this.id||this.defaultId,name:this.nameOrFallback,attributes:this.elementAttributes,blurHandler:this.blurHandler.bind(this),disableErrors:this.disableErrors,errors:this.explicitErrors,allErrors:this.allErrors,formShouldShowErrors:this.formShouldShowErrors,getValidationErrors:this.getValidationErrors.bind(this),hasGivenName:this.hasGivenName,hasValidationErrors:this.hasValidationErrors.bind(this),imageBehavior:this.imageBehavior,performValidation:this.performValidation.bind(this),preventWindowDrops:this.preventWindowDrops,setErrors:this.setErrors.bind(this),showValidationErrors:this.showValidationErrors,uploadBehavior:this.uploadBehavior,uploadUrl:this.mergedUploadUrl,uploader:this.uploader||this.$formulario.getUploader(),validationErrors:this.validationErrors,value:this.value,visibleValidationErrors:this.visibleValidationErrors})}get parsedValidationRules(){const e={};return Object.keys(this.validationRules).forEach(t=>{e[p(t)]=this.validationRules[t]}),e}get messages(){const e={};return Object.keys(this.validationMessages).forEach(t=>{e[p(t)]=this.validationMessages[t]}),Object.keys(this.messageRegistry).forEach(t=>{e[p(t)]=this.messageRegistry[t]}),e}get elementAttributes(){const e=Object.assign({},this.localAttributes);return this.id?e.id=this.id:e.id=this.defaultId,this.hasGivenName&&(e.name=this.name),this.help&&(e["aria-describedby"]=e.id+"-help"),e}get nameOrFallback(){return""!==this.path?`${this.path}.${this.name}`:this.name}get hasGivenName(){return"boolean"!=typeof this.name}get mergedValidationName(){return this.validationName||this.name}get mergedUploadUrl(){return this.uploadUrl||this.$formulario.getUploadUrl()}get hasErrors(){return this.allErrors.length>0}get hasVisibleErrors(){return this.validationErrors&&this.showValidationErrors||!!this.explicitErrors.length}get allErrors(){return[...this.explicitErrors,...f(this.validationErrors)]}get visibleValidationErrors(){return this.showValidationErrors&&this.validationErrors.length?this.validationErrors:[]}get explicitErrors(){return[...f(this.errors),...this.localErrors].map(e=>({rule:null,context:null,message:e}))}get isVmodeled(){return!!(Object.prototype.hasOwnProperty.call(this.$options.propsData,"formularioValue")&&this._events&&Array.isArray(this._events.input)&&this._events.input.length)}get showValidationErrors(){return this.showErrors||this.formShouldShowErrors||this.behavioralErrorVisibility}onAttrsChanged(e){this.updateLocalAttributes(e)}onProxyChanged(e,t){this.errorBehavior===oe.LIVE?this.performValidation():this.validationErrors=[],this.isVmodeled||h(e,t)||(this.context.model=e)}onFormularioValueChanged(e,t){this.isVmodeled&&!h(e,t)&&(this.context.model=e)}onShowValidationErrorsChanged(e){this.$emit("error-visibility",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.updateLocalAttributes(this.$attrs),this.errorBehavior===oe.LIVE&&this.performValidation()}beforeDestroy(){this.disableErrors||"function"!=typeof this.removeErrorObserver||this.removeErrorObserver(this.setErrors),"function"==typeof this.formularioDeregister&&this.formularioDeregister(this.nameOrFallback)}defineModel(e){return Object.defineProperty(e,"model",{get:this.modelGetter.bind(this),set:this.modelSetter.bind(this)})}modelGetter(){const e=this.isVmodeled?"formularioValue":"proxy";return void 0===this[e]?"":this[e]}modelSetter(e){h(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"),"blur"===this.errorBehavior&&(this.behavioralErrorVisibility=!0)}getInitialValue(){return y(this.$options.propsData,"value")?this.value:y(this.$options.propsData,"formularioValue")?this.formularioValue:""}applyInitialValue(){h(this.context.model,this.proxy)||(this.context.model=this.proxy)}updateLocalAttributes(e){h(e,this.localAttributes)||(this.localAttributes=e)}performValidation(){let e=m(this.validation,this.$formulario.rules(this.parsedValidationRules));return e=this.ruleRegistry.length?this.ruleRegistry.concat(e):e,this.pendingValidation=this.runRules(e).then(e=>this.didValidate(e)),this.pendingValidation}runRules(e){const t=([e,t,r])=>{let i=e({value:this.context.model,getFormValues:this.getFormValues.bind(this),name:this.context.name},...t);return i=i instanceof Promise?i:Promise.resolve(i),i.then(e=>!e&&this.getMessageObject(r,t))};return new Promise(r=>{const i=(e,o=[])=>{const s=e.shift();Array.isArray(s)&&s.length?Promise.all(s.map(t)).then(e=>e.filter(e=>!!e)).then(t=>(t=Array.isArray(t)?t:[]).length&&s.bail||!e.length?r(o.concat(t)):i(e,o.concat(t))):r([])};i(function(e){const t=[],r=e.findIndex(([,,e])=>"bail"===e.toLowerCase());if(r>=0){const i=e.splice(0,r+1).slice(0,-1);i.length&&t.push(i),e.map(e=>t.push(Object.defineProperty([e],"bail",{value:!0})))}else t.push(e);return t.reduce((e,t)=>{const r=(e,t=!1)=>{if(e.length<2)return Object.defineProperty([e],"bail",{value:t});const i=[],o=e.findIndex(([,,,e])=>"^"===e);if(o>=0){const s=e.splice(0,o);s.length&&i.push(...r(s,t)),i.push(Object.defineProperty([e.shift()],"bail",{value:!0})),e.length&&i.push(...r(e,t))}else i.push(e);return i};return e.concat(r(t))},[])}(e))})}didValidate(e){const t=!h(e,this.validationErrors);if(this.validationErrors=e,t){const e=this.getErrorObject();this.$emit("validation",e),this.formularioFieldValidation&&"function"==typeof this.formularioFieldValidation&&this.formularioFieldValidation(e)}}getMessageObject(e,t){const r={args:t,name:this.mergedValidationName,value:this.context.model,vm:this,formValues:this.getFormValues()};return{rule:e,context:r,message:this.getMessageFunc(e)(r)}}getMessageFunc(e){if(e=p(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))})})}getValidationErrors(){return new Promise(e=>{this.$nextTick(()=>this.pendingValidation.then(()=>e(this.getErrorObject())))})}getErrorObject(){return{name:this.context.nameOrFallback||this.context.name,errors:this.validationErrors.filter(e=>"object"==typeof e),hasErrors:!!this.validationErrors.length}}setErrors(e){this.localErrors=f(e)}registerRule(e,t,r,i=null){this.ruleRegistry.some(e=>e[2]===r)||(this.ruleRegistry.push([e,t,r]),null!==i&&(this.messageRegistry[r]=i))}removeRule(e){const t=this.ruleRegistry.findIndex(t=>t[2]===e);t>=0&&(this.ruleRegistry.splice(t,1),delete this.messageRegistry[e])}};A([G({default:void 0})],se.prototype,"formularioSetter",void 0),A([G({default:()=>()=>{}})],se.prototype,"formularioFieldValidation",void 0),A([G({default:void 0})],se.prototype,"formularioRegister",void 0),A([G({default:void 0})],se.prototype,"formularioDeregister",void 0),A([G({default:()=>()=>({})})],se.prototype,"getFormValues",void 0),A([G({default:void 0})],se.prototype,"addErrorObserver",void 0),A([G({default:void 0})],se.prototype,"removeErrorObserver",void 0),A([G({default:""})],se.prototype,"path",void 0),A([K()],se.prototype,"formularioRegisterRule",void 0),A([K()],se.prototype,"formularioRemoveRule",void 0),A([Y("input",{default:""})],se.prototype,"formularioValue",void 0),A([z({type:[String,Number,Boolean],default:!1})],se.prototype,"id",void 0),A([z({default:"text"})],se.prototype,"type",void 0),A([z({required:!0})],se.prototype,"name",void 0),A([z({default:!1})],se.prototype,"value",void 0),A([z({type:[String,Boolean,Array],default:!1})],se.prototype,"validation",void 0),A([z({type:[String,Boolean],default:!1})],se.prototype,"validationName",void 0),A([z({type:Object,default:()=>({})})],se.prototype,"validationRules",void 0),A([z({type:Object,default:()=>({})})],se.prototype,"validationMessages",void 0),A([z({type:[Array,String,Boolean],default:!1})],se.prototype,"errors",void 0),A([z({type:String,default:oe.BLUR,validator:e=>[oe.BLUR,oe.LIVE,oe.SUBMIT].includes(e)})],se.prototype,"errorBehavior",void 0),A([z({default:!1})],se.prototype,"showErrors",void 0),A([z({default:!1})],se.prototype,"disableErrors",void 0),A([z({default:!0})],se.prototype,"preventWindowDrops",void 0),A([z({default:"preview"})],se.prototype,"imageBehavior",void 0),A([z({default:!1})],se.prototype,"uploader",void 0),A([z({default:!1})],se.prototype,"uploadUrl",void 0),A([z({default:"live"})],se.prototype,"uploadBehavior",void 0),A([Z("$attrs",{deep:!0})],se.prototype,"onAttrsChanged",null),A([Z("proxy")],se.prototype,"onProxyChanged",null),A([Z("formularioValue")],se.prototype,"onFormularioValueChanged",null),A([Z("showValidationErrors",{immediate:!0})],se.prototype,"onShowValidationErrorsChanged",null),se=A([W({name:"FormularioInput",inheritAttrs:!1})],se);const ae=se;var ne=function(){var e=this,t=e.$createElement;return(e._self._c||t)("div",{staticClass:"formulario-input",attrs:{"data-has-errors":e.hasErrors,"data-is-showing-errors":e.hasVisibleErrors,"data-type":e.type}},[e._t("default",null,{id:e.id,context:e.context,errors:e.errors,validationErrors:e.validationErrors})],2)};ne._withStripped=!0;const le=ee({render:ne,staticRenderFns:[]},void 0,ae,void 0,!1,void 0,!1,void 0,void 0,void 0);let ue=class extends e{get groupPath(){return this.isArrayItem?`${this.path}[${this.name}]`:""===this.path?this.name:`${this.path}.${this.name}`}};A([G({default:""})],ue.prototype,"path",void 0),A([z({required:!0})],ue.prototype,"name",void 0),A([z({default:!1})],ue.prototype,"isArrayItem",void 0),A([K("path")],ue.prototype,"groupPath",null),ue=A([W({name:"FormularioGrouping"})],ue);const de=ue;var he=function(){var e=this.$createElement;return(this._self._c||e)("div",{staticClass:"formulario-group",attrs:{"data-type":"group"}},[this._t("default")],2)};he._withStripped=!0;const pe=ee({render:he,staticRenderFns:[]},void 0,de,void 0,!1,void 0,!1,void 0,void 0,void 0);return new class{constructor(){this.options={},this.defaults={components:{FormularioForm:ie,FormularioInput:le,FormularioGrouping:pe},library:r,rules:b,mimes:E,locale:!1,uploader:w,uploadUrl:!1,fileUrlKey:"url",uploadJustCompleteDuration:1e3,errorHandler:e=>e,plugins:[x],validationMessages:{},idPrefix:"formulario-"},this.registry=new Map,this.idRegistry={}}install(e,t){e.prototype.$formulario=this,this.options=this.defaults;let r=this.defaults.plugins;t&&Array.isArray(t.plugins)&&t.plugins.length&&(r=r.concat(t.plugins)),r.forEach(e=>"function"==typeof e?e(this):null),this.extend(t||{});for(const t in this.options.components)Object.prototype.hasOwnProperty.call(this.options.components,t)&&e.component(t,this.options.components[t])}nextId(e){const t=this.options,r=!(!e.$route||!e.$route.path)&&e.$route.path?e.$route.path.replace(/[/\\.\s]/g,"-"):"global";return y(this.idRegistry,r)||(this.idRegistry[r]=0),`${t.idPrefix}${r}-${++this.idRegistry[r]}`}extend(e){if("object"==typeof e)return this.options=function e(t,r,i=!0){const o={};for(const s in t)y(r,s)?j(r[s])&&j(t[s])?o[s]=e(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)y(o,e)||(o[e]=r[e]);return o}(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 y(this.options.validationMessages,e)?this.options.validationMessages[e](r,t):this.options.validationMessages.default(r,t)}register(e){"FormularioForm"===e.$options.name&&e.name&&this.registry.set(e.name,e)}deregister(e){"FormularioForm"===e.$options.name&&e.name&&this.registry.has(e.name)&&this.registry.delete(e.name)}handle(e,t,r=!1){const i=r?e:this.options.errorHandler(e,t);if(t&&this.registry.has(t)){this.registry.get(t).applyErrors({formErrors:f(i.formErrors),inputErrors:i.inputErrors||{}})}return i}reset(e,t={}){this.resetValidation(e),this.setValues(e,t)}resetValidation(e){const t=this.registry.get(e);t.hideErrors(e),t.namedErrors=[],t.namedFieldErrors={}}setValues(e,t){if(t){this.registry.get(e).setValues(Object.assign({},t))}}getUploader(){return this.options.uploader||!1}getUploadUrl(){return this.options.uploadUrl||!1}getFileUrlKey(){return this.options.fileUrlKey||"url"}createUpload(e,t){return new d(e,t,this.options)}}}(Vue); + */}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); diff --git a/dist/formulario.umd.js b/dist/formulario.umd.js index 119d611..fc27feb 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("nanoid/non-secure"),require("is-plain-object"),require("vue"),require("vue-property-decorator")):"function"==typeof define&&define.amd?define(["is-url","nanoid/non-secure","is-plain-object","vue","vue-property-decorator"],t):(e=e||self).Formulario=t(e.isUrl,e.nanoid,e.isPlainObject,e.Vue,e.vuePropertyDecorator)}(this,(function(e,t,r,i,o){"use strict";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,i=i&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i;const s=(e,t)=>({classification:e,component:"FormularioInput"+(t||e[0].toUpperCase()+e.substr(1))});var a=Object.assign(Object.assign({},["text","email","number","color","date","hidden","month","password","search","tel","time","url","week","datetime-local"].reduce((e,t)=>Object.assign(Object.assign({},e),{[t]:s("text")}),{})),{range:s("slider"),textarea:s("textarea","TextArea"),checkbox:s("box"),radio:s("box"),submit:s("button"),button:s("button"),select:s("select"),file:s("file"),image:s("file"),group:s("group")});class n{constructor(e,t={},r={}){this.input=e,this.fileList=e.files,this.files=[],this.options=Object.assign({mimes:{}},r),this.results=!1,this.context=t,Array.isArray(this.fileList)?this.rehydrateFileList(this.fileList):this.addFileList(this.fileList)}rehydrateFileList(e){const t=e.reduce((e,t)=>{const r=t[this.options?this.options.fileUrlKey:"url"],i=!(!r||-1===r.lastIndexOf("."))&&r.substr(r.lastIndexOf(".")+1),o=this.options.mimes[i]||!1;return e.push(Object.assign({},t,r?{name:r.substr(r.lastIndexOf("/")+1||0),type:t.type?t.type:o,previewData:r}:{})),e},[]);this.results=e,this.addFileList(t)}addFileList(e){for(let r=0;rthis.removeFile(o),previewData:i.previewData||!1})}}hasUploader(){return!!this.context.uploader}uploaderIsAxios(){return this.hasUploader&&"function"==typeof this.context.uploader.request&&"function"==typeof this.context.uploader.get&&"function"==typeof this.context.uploader.delete&&"function"==typeof this.context.uploader.post}getUploader(...e){if(this.uploaderIsAxios()){const t=new FormData;if(t.append(this.context.name||"file",e[0]),!1===this.context.uploadUrl)throw new Error("No uploadURL specified: https://vueformulate.com/guide/inputs/file/#props");return this.context.uploader.post(this.context.uploadUrl,t,{headers:{"Content-Type":"multipart/form-data"},onUploadProgress:t=>{e[1](Math.round(100*t.loaded/t.total))}}).then(e=>e.data).catch(e[2])}return this.context.uploader(...e)}upload(){return this.results?Promise.resolve(this.results):new Promise((e,t)=>{if(!this.hasUploader)return t(new Error("No uploader has been defined"));Promise.all(this.files.map(e=>e.path?Promise.resolve(e.path):this.getUploader(e.file,t=>{e.progress=t,t>=100&&(e.complete||(e.justFinished=!0,setTimeout(()=>{e.justFinished=!1},this.options.uploadJustCompleteDuration)),e.complete=!0)},t=>{e.progress=0,e.error=t,e.complete=!0},this.options))).then(t=>{this.results=t,e(t)}).catch(e=>{throw new Error(e)})})}removeFile(e){if(this.files=this.files.filter(t=>t.uuid!==e),this.context.performValidation(),window&&this.fileList instanceof FileList){const e=new DataTransfer;this.files.map(({file:t})=>e.items.add(t)),this.fileList=e.files,this.input=e}}loadPreviews(){this.files.map(e=>{if(!e.previewData&&window&&window.FileReader&&/^image\//.test(e.file.type)){const t=new FileReader;t.onload=t=>Object.assign(e,{previewData:t.target.result}),t.readAsDataURL(e.file)}})}getFileList(){return this.fileList}getFiles(){return this.files}toString(){const e=this.files.length?this.files.length+" files":"empty";return this.results?JSON.stringify(this.results,null," "):`FileUpload(${e})`}}function l(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 u(e){return"string"==typeof e&&/^[\^]/.test(e.charAt(0))?[h(e.substr(1)),e.charAt(0)]:[h(e),null]}function d(e){return e?"string"==typeof e?[e]:Array.isArray(e)?e:"object"==typeof e?Object.values(e):[]:[]}function p(e,t){return"string"==typeof e?p(e.split("|"),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]=u(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]=u(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 c(e){switch(typeof e){case"symbol":case"number":case"string":case"boolean":case"undefined":return!0;default:return null===e}}function f(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function m(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 g={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=f(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=f(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((()=>{const o=t();let s=i;return s||(s=/_confirm$/.test(r)?r.substr(0,r.length-8):r+"_confirm"),o[s]===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?l(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))),mime({value:e},...t){if(e instanceof n){const r=e.getFiles(),i=e=>t.includes(e.type),o=r.reduce((e,{file:t})=>e&&i(t),!0);return Promise.resolve(o)}return Promise.resolve(!0)},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?l(t,e):t===e)),number:({value:e})=>Promise.resolve(!isNaN(Number(e))),required:({value:e},t=!0)=>Promise.resolve(!(t&&!["no","false"].includes(t))||(Array.isArray(e)?!!e.length:e instanceof n?e.getFiles().length>0:"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)},y={csv:"text/csv",gif:"image/gif",jpeg:"image/jpeg",jpg:"image/jpeg",png:"image/png",pdf:"application/pdf",svg:"image/svg+xml"};const v={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 b(e){e.extend({validationMessages:v})}function E(e,t,r,i){return new Promise(r=>{const o=(i.fauxUploaderDuration||2e3)*(.5+Math.random()),s=performance.now(),a=()=>setTimeout(()=>{const i=performance.now()-s,n=Math.min(100,Math.round(i/o*100));if(t(n),n>=100)return r({url:"http://via.placeholder.com/350x150.png",name:e.name});a()},20);a()})} +!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} /*! ***************************************************************************** Copyright (c) Microsoft Corporation. @@ -12,5 +12,4 @@ 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 x(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 O{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],x(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=f(t.$options.propsData,"formularioValue"),i=f(t.$options.propsData,"value");!r&&this.ctx.hasInitialValue&&void 0!==m(this.ctx.initialValues,e)?t.context.model=m(this.ctx.initialValues,e):!r&&!i||l(t.proxy,m(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 P{constructor(e){this.form=e}hasValidationErrors(){return this.form.hasValidationErrors()}values(){return new Promise((e,t)=>{const r=this.form,i=[],o=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)&&(c(t[i])||t[i]instanceof n?r[i]=t[i]:r[i]=e(t[i]));return r}(r.proxy);for(const e in o)Object.prototype.hasOwnProperty.call(o,e)&&"object"==typeof r.proxy[e]&&r.proxy[e]instanceof n&&i.push(r.proxy[e].upload().then(t=>Object.assign(o,{[e]:t})));Promise.all(i).then(()=>e(o)).catch(e=>t(e))})}}let w=class extends i{constructor(){super(...arguments),this.formularioRegister=this.register,this.formularioDeregister=this.deregister,this.formularioSetter=this.setFieldValue,this.getFormValues=()=>this.proxy,this.path="",this.proxy={},this.registry=new O(this),this.childrenShouldShowErrors=!1,this.formShouldShowErrors=!1,this.errorObservers=[],this.namedErrors=[],this.namedFieldErrors={}}formularioFieldValidation(e){this.$emit("validation",e)}removeErrorObserver(e){this.errorObservers=this.errorObservers.filter(t=>t.callback!==e)}get mergedFormErrors(){return this.formErrors.concat(this.namedErrors)}get mergedFieldErrors(){const e={};if(this.errors)for(const t in this.errors)e[t]=d(this.errors[t]);for(const t in this.namedFieldErrors)e[t]=d(this.namedFieldErrors[t]);return e}get hasFormErrorObservers(){return this.errorObservers.some(e=>"form"===e.type)}get hasInitialValue(){return this.formularioValue&&"object"==typeof this.formularioValue||this.values&&"object"==typeof this.values||this.isGrouping&&"object"==typeof this.context.model[this.index]}get isVmodeled(){return!!(f(this.$options.propsData,"formularioValue")&&this._events&&Array.isArray(this._events.input)&&this._events.input.length)}get initialValues(){return f(this.$options.propsData,"formularioValue")&&"object"==typeof this.formularioValue?Object.assign({},this.formularioValue):f(this.$options.propsData,"values")&&"object"==typeof this.values?Object.assign({},this.values):this.isGrouping&&"object"==typeof this.context.model[this.index]?this.context.model[this.index]:{}}onFormularioValueChanged(e){this.isVmodeled&&e&&"object"==typeof e&&this.setValues(e)}onMergedFormErrorsChanged(e){this.errorObservers.filter(e=>"form"===e.type).forEach(t=>t.callback(e))}onMergedFieldErrorsChanged(e){this.errorObservers.filter(e=>"input"===e.type).forEach(t=>t.callback(e[t.field]||[]))}created(){this.$formulario.register(this),this.applyInitialValues()}destroyed(){this.$formulario.deregister(this)}register(e,t){this.registry.register(e,t)}deregister(e){this.registry.remove(e)}applyErrors({formErrors:e,inputErrors:t}){this.namedErrors=e,this.namedFieldErrors=t}addErrorObserver(e){this.errorObservers.find(t=>e.callback===t.callback)||(this.errorObservers.push(e),"form"===e.type?e.callback(this.mergedFormErrors):f(this.mergedFieldErrors,e.field)&&e.callback(this.mergedFieldErrors[e.field]))}registerErrorComponent(e){this.errorComponents.includes(e)||this.errorComponents.push(e)}formSubmitted(){this.showErrors();const e=new P(this);return this.$emit("submit-raw",e),e.hasValidationErrors().then(t=>t?void 0:e.values()).then(e=>{if(void 0!==e)return this.$emit("submit",e),e})}applyInitialValues(){this.hasInitialValue&&(this.proxy=this.initialValues)}setFieldValue(e,t,r=!0){if(void 0===t){const t=this.proxy,r=e,i=(t[r],x(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.getValidationErrors()),e),[])).then(e=>e.some(e=>e.hasErrors))}showErrors(){this.childrenShouldShowErrors=!0,this.registry.forEach(e=>{e.formShouldShowErrors=!0})}hideErrors(){this.childrenShouldShowErrors=!1,this.registry.forEach(e=>{e.formShouldShowErrors=!1,e.behavioralErrorVisibility=!1})}setValues(e){const t=Array.from(new Set(Object.keys(e).concat(Object.keys(this.proxy))));let r=!1;t.forEach(t=>{this.registry.hasNested(t)&&this.registry.getNested(t).forEach((t,i)=>{l(m(e,i),m(this.proxy,i))||(this.setFieldValue(i,m(e,i),!1),r=!0),l(m(e,i),this.registry.get(i).proxy)||(this.registry.get(i).context.model=m(e,i))})}),this.applyInitialValues(),r&&this.$emit("input",Object.assign({},this.proxy))}};function $(e,t,r,i,o,s,a,n,l,h){"boolean"!=typeof a&&(l=n,n=a,a=!1);const u="function"==typeof r?r.options:r;let d;if(e&&e.render&&(u.render=e.render,u.staticRenderFns=e.staticRenderFns,u._compiled=!0,o&&(u.functional=!0)),i&&(u._scopeId=i),s?(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(s)},u._ssrRegister=d):t&&(d=a?function(e){t.call(this,h(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,n(e))}),d)if(u.functional){const e=u.render;u.render=function(t,r){return d.call(r),e(t,r)}}else{const e=u.beforeCreate;u.beforeCreate=e?[].concat(e,d):[d]}return r}V([o.Provide()],w.prototype,"formularioFieldValidation",null),V([o.Provide()],w.prototype,"formularioRegister",void 0),V([o.Provide()],w.prototype,"formularioDeregister",void 0),V([o.Provide()],w.prototype,"formularioSetter",void 0),V([o.Provide()],w.prototype,"getFormValues",void 0),V([o.Provide()],w.prototype,"path",void 0),V([o.Provide()],w.prototype,"removeErrorObserver",null),V([o.Model("input",{type:Object,default:()=>({})})],w.prototype,"formularioValue",void 0),V([o.Prop({type:[String,Boolean],default:!1})],w.prototype,"name",void 0),V([o.Prop({type:[Object,Boolean],default:!1})],w.prototype,"values",void 0),V([o.Prop({default:!1})],w.prototype,"errors",void 0),V([o.Prop({default:()=>[]})],w.prototype,"formErrors",void 0),V([o.Watch("formularioValue",{deep:!0})],w.prototype,"onFormularioValueChanged",null),V([o.Watch("mergedFormErrors")],w.prototype,"onMergedFormErrorsChanged",null),V([o.Watch("mergedFieldErrors",{immediate:!0})],w.prototype,"onMergedFieldErrorsChanged",null),V([o.Provide()],w.prototype,"addErrorObserver",null),w=V([o.Component({name:"FormularioForm"})],w);const j=w;var F=function(){var e=this,t=e.$createElement;return(e._self._c||t)("form",{on:{submit:function(t){return t.preventDefault(),e.formSubmitted(t)}}},[e._t("default",null,{errors:e.mergedFormErrors})],2)};F._withStripped=!0;const A=$({render:F,staticRenderFns:[]},void 0,j,void 0,!1,void 0,!1,void 0,void 0,void 0),N={BLUR:"blur",LIVE:"live",SUBMIT:"submit"};let R=class extends i{constructor(){super(...arguments),this.formularioRegisterRule=this.registerRule,this.formularioRemoveRule=this.removeRule,this.defaultId=this.$formulario.nextId(this),this.localAttributes={},this.localErrors=[],this.proxy=this.getInitialValue(),this.behavioralErrorVisibility="live"===this.errorBehavior,this.formShouldShowErrors=!1,this.validationErrors=[],this.pendingValidation=Promise.resolve(),this.ruleRegistry=[],this.messageRegistry={}}get context(){return this.defineModel({id:this.id||this.defaultId,name:this.nameOrFallback,attributes:this.elementAttributes,blurHandler:this.blurHandler.bind(this),disableErrors:this.disableErrors,errors:this.explicitErrors,allErrors:this.allErrors,formShouldShowErrors:this.formShouldShowErrors,getValidationErrors:this.getValidationErrors.bind(this),hasGivenName:this.hasGivenName,hasValidationErrors:this.hasValidationErrors.bind(this),imageBehavior:this.imageBehavior,performValidation:this.performValidation.bind(this),preventWindowDrops:this.preventWindowDrops,setErrors:this.setErrors.bind(this),showValidationErrors:this.showValidationErrors,uploadBehavior:this.uploadBehavior,uploadUrl:this.mergedUploadUrl,uploader:this.uploader||this.$formulario.getUploader(),validationErrors:this.validationErrors,value:this.value,visibleValidationErrors:this.visibleValidationErrors})}get parsedValidationRules(){const e={};return Object.keys(this.validationRules).forEach(t=>{e[h(t)]=this.validationRules[t]}),e}get messages(){const e={};return Object.keys(this.validationMessages).forEach(t=>{e[h(t)]=this.validationMessages[t]}),Object.keys(this.messageRegistry).forEach(t=>{e[h(t)]=this.messageRegistry[t]}),e}get elementAttributes(){const e=Object.assign({},this.localAttributes);return this.id?e.id=this.id:e.id=this.defaultId,this.hasGivenName&&(e.name=this.name),this.help&&(e["aria-describedby"]=e.id+"-help"),e}get nameOrFallback(){return""!==this.path?`${this.path}.${this.name}`:this.name}get hasGivenName(){return"boolean"!=typeof this.name}get mergedValidationName(){return this.validationName||this.name}get mergedUploadUrl(){return this.uploadUrl||this.$formulario.getUploadUrl()}get hasErrors(){return this.allErrors.length>0}get hasVisibleErrors(){return this.validationErrors&&this.showValidationErrors||!!this.explicitErrors.length}get allErrors(){return[...this.explicitErrors,...d(this.validationErrors)]}get visibleValidationErrors(){return this.showValidationErrors&&this.validationErrors.length?this.validationErrors:[]}get explicitErrors(){return[...d(this.errors),...this.localErrors].map(e=>({rule:null,context:null,message:e}))}get isVmodeled(){return!!(Object.prototype.hasOwnProperty.call(this.$options.propsData,"formularioValue")&&this._events&&Array.isArray(this._events.input)&&this._events.input.length)}get showValidationErrors(){return this.showErrors||this.formShouldShowErrors||this.behavioralErrorVisibility}onAttrsChanged(e){this.updateLocalAttributes(e)}onProxyChanged(e,t){this.errorBehavior===N.LIVE?this.performValidation():this.validationErrors=[],this.isVmodeled||l(e,t)||(this.context.model=e)}onFormularioValueChanged(e,t){this.isVmodeled&&!l(e,t)&&(this.context.model=e)}onShowValidationErrorsChanged(e){this.$emit("error-visibility",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.updateLocalAttributes(this.$attrs),this.errorBehavior===N.LIVE&&this.performValidation()}beforeDestroy(){this.disableErrors||"function"!=typeof this.removeErrorObserver||this.removeErrorObserver(this.setErrors),"function"==typeof this.formularioDeregister&&this.formularioDeregister(this.nameOrFallback)}defineModel(e){return Object.defineProperty(e,"model",{get:this.modelGetter.bind(this),set:this.modelSetter.bind(this)})}modelGetter(){const e=this.isVmodeled?"formularioValue":"proxy";return void 0===this[e]?"":this[e]}modelSetter(e){l(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"),"blur"===this.errorBehavior&&(this.behavioralErrorVisibility=!0)}getInitialValue(){return f(this.$options.propsData,"value")?this.value:f(this.$options.propsData,"formularioValue")?this.formularioValue:""}applyInitialValue(){l(this.context.model,this.proxy)||(this.context.model=this.proxy)}updateLocalAttributes(e){l(e,this.localAttributes)||(this.localAttributes=e)}performValidation(){let e=p(this.validation,this.$formulario.rules(this.parsedValidationRules));return e=this.ruleRegistry.length?this.ruleRegistry.concat(e):e,this.pendingValidation=this.runRules(e).then(e=>this.didValidate(e)),this.pendingValidation}runRules(e){const t=([e,t,r])=>{let i=e({value:this.context.model,getFormValues:this.getFormValues.bind(this),name:this.context.name},...t);return i=i instanceof Promise?i:Promise.resolve(i),i.then(e=>!e&&this.getMessageObject(r,t))};return new Promise(r=>{const i=(e,o=[])=>{const s=e.shift();Array.isArray(s)&&s.length?Promise.all(s.map(t)).then(e=>e.filter(e=>!!e)).then(t=>(t=Array.isArray(t)?t:[]).length&&s.bail||!e.length?r(o.concat(t)):i(e,o.concat(t))):r([])};i(function(e){const t=[],r=e.findIndex(([,,e])=>"bail"===e.toLowerCase());if(r>=0){const i=e.splice(0,r+1).slice(0,-1);i.length&&t.push(i),e.map(e=>t.push(Object.defineProperty([e],"bail",{value:!0})))}else t.push(e);return t.reduce((e,t)=>{const r=(e,t=!1)=>{if(e.length<2)return Object.defineProperty([e],"bail",{value:t});const i=[],o=e.findIndex(([,,,e])=>"^"===e);if(o>=0){const s=e.splice(0,o);s.length&&i.push(...r(s,t)),i.push(Object.defineProperty([e.shift()],"bail",{value:!0})),e.length&&i.push(...r(e,t))}else i.push(e);return i};return e.concat(r(t))},[])}(e))})}didValidate(e){const t=!l(e,this.validationErrors);if(this.validationErrors=e,t){const e=this.getErrorObject();this.$emit("validation",e),this.formularioFieldValidation&&"function"==typeof this.formularioFieldValidation&&this.formularioFieldValidation(e)}}getMessageObject(e,t){const r={args:t,name:this.mergedValidationName,value:this.context.model,vm:this,formValues:this.getFormValues()};return{rule:e,context:r,message:this.getMessageFunc(e)(r)}}getMessageFunc(e){if(e=h(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))})})}getValidationErrors(){return new Promise(e=>{this.$nextTick(()=>this.pendingValidation.then(()=>e(this.getErrorObject())))})}getErrorObject(){return{name:this.context.nameOrFallback||this.context.name,errors:this.validationErrors.filter(e=>"object"==typeof e),hasErrors:!!this.validationErrors.length}}setErrors(e){this.localErrors=d(e)}registerRule(e,t,r,i=null){this.ruleRegistry.some(e=>e[2]===r)||(this.ruleRegistry.push([e,t,r]),null!==i&&(this.messageRegistry[r]=i))}removeRule(e){const t=this.ruleRegistry.findIndex(t=>t[2]===e);t>=0&&(this.ruleRegistry.splice(t,1),delete this.messageRegistry[e])}};V([o.Inject({default:void 0})],R.prototype,"formularioSetter",void 0),V([o.Inject({default:()=>()=>{}})],R.prototype,"formularioFieldValidation",void 0),V([o.Inject({default:void 0})],R.prototype,"formularioRegister",void 0),V([o.Inject({default:void 0})],R.prototype,"formularioDeregister",void 0),V([o.Inject({default:()=>()=>({})})],R.prototype,"getFormValues",void 0),V([o.Inject({default:void 0})],R.prototype,"addErrorObserver",void 0),V([o.Inject({default:void 0})],R.prototype,"removeErrorObserver",void 0),V([o.Inject({default:""})],R.prototype,"path",void 0),V([o.Provide()],R.prototype,"formularioRegisterRule",void 0),V([o.Provide()],R.prototype,"formularioRemoveRule",void 0),V([o.Model("input",{default:""})],R.prototype,"formularioValue",void 0),V([o.Prop({type:[String,Number,Boolean],default:!1})],R.prototype,"id",void 0),V([o.Prop({default:"text"})],R.prototype,"type",void 0),V([o.Prop({required:!0})],R.prototype,"name",void 0),V([o.Prop({default:!1})],R.prototype,"value",void 0),V([o.Prop({type:[String,Boolean,Array],default:!1})],R.prototype,"validation",void 0),V([o.Prop({type:[String,Boolean],default:!1})],R.prototype,"validationName",void 0),V([o.Prop({type:Object,default:()=>({})})],R.prototype,"validationRules",void 0),V([o.Prop({type:Object,default:()=>({})})],R.prototype,"validationMessages",void 0),V([o.Prop({type:[Array,String,Boolean],default:!1})],R.prototype,"errors",void 0),V([o.Prop({type:String,default:N.BLUR,validator:e=>[N.BLUR,N.LIVE,N.SUBMIT].includes(e)})],R.prototype,"errorBehavior",void 0),V([o.Prop({default:!1})],R.prototype,"showErrors",void 0),V([o.Prop({default:!1})],R.prototype,"disableErrors",void 0),V([o.Prop({default:!0})],R.prototype,"preventWindowDrops",void 0),V([o.Prop({default:"preview"})],R.prototype,"imageBehavior",void 0),V([o.Prop({default:!1})],R.prototype,"uploader",void 0),V([o.Prop({default:!1})],R.prototype,"uploadUrl",void 0),V([o.Prop({default:"live"})],R.prototype,"uploadBehavior",void 0),V([o.Watch("$attrs",{deep:!0})],R.prototype,"onAttrsChanged",null),V([o.Watch("proxy")],R.prototype,"onProxyChanged",null),V([o.Watch("formularioValue")],R.prototype,"onFormularioValueChanged",null),V([o.Watch("showValidationErrors",{immediate:!0})],R.prototype,"onShowValidationErrorsChanged",null),R=V([o.Component({name:"FormularioInput",inheritAttrs:!1})],R);const S=R;var D=function(){var e=this,t=e.$createElement;return(e._self._c||t)("div",{staticClass:"formulario-input",attrs:{"data-has-errors":e.hasErrors,"data-is-showing-errors":e.hasVisibleErrors,"data-type":e.type}},[e._t("default",null,{id:e.id,context:e.context,errors:e.errors,validationErrors:e.validationErrors})],2)};D._withStripped=!0;const I=$({render:D,staticRenderFns:[]},void 0,S,void 0,!1,void 0,!1,void 0,void 0,void 0);let U=class extends i{get groupPath(){return this.isArrayItem?`${this.path}[${this.name}]`:""===this.path?this.name:`${this.path}.${this.name}`}};V([o.Inject({default:""})],U.prototype,"path",void 0),V([o.Prop({required:!0})],U.prototype,"name",void 0),V([o.Prop({default:!1})],U.prototype,"isArrayItem",void 0),V([o.Provide("path")],U.prototype,"groupPath",null),U=V([o.Component({name:"FormularioGrouping"})],U);const _=U;var C=function(){var e=this.$createElement;return(this._self._c||e)("div",{staticClass:"formulario-group",attrs:{"data-type":"group"}},[this._t("default")],2)};C._withStripped=!0;const k=$({render:C,staticRenderFns:[]},void 0,_,void 0,!1,void 0,!1,void 0,void 0,void 0);return new class{constructor(){this.options={},this.defaults={components:{FormularioForm:A,FormularioInput:I,FormularioGrouping:k},library:a,rules:g,mimes:y,locale:!1,uploader:E,uploadUrl:!1,fileUrlKey:"url",uploadJustCompleteDuration:1e3,errorHandler:e=>e,plugins:[b],validationMessages:{},idPrefix:"formulario-"},this.registry=new Map,this.idRegistry={}}install(e,t){e.prototype.$formulario=this,this.options=this.defaults;let r=this.defaults.plugins;t&&Array.isArray(t.plugins)&&t.plugins.length&&(r=r.concat(t.plugins)),r.forEach(e=>"function"==typeof e?e(this):null),this.extend(t||{});for(const t in this.options.components)Object.prototype.hasOwnProperty.call(this.options.components,t)&&e.component(t,this.options.components[t])}nextId(e){const t=this.options,r=!(!e.$route||!e.$route.path)&&e.$route.path?e.$route.path.replace(/[/\\.\s]/g,"-"):"global";return f(this.idRegistry,r)||(this.idRegistry[r]=0),`${t.idPrefix}${r}-${++this.idRegistry[r]}`}extend(e){if("object"==typeof e)return this.options=function e(t,i,o=!0){const s={};for(const a in t)f(i,a)?r(i[a])&&r(t[a])?s[a]=e(t[a],i[a],o):o&&Array.isArray(t[a])&&Array.isArray(i[a])?s[a]=t[a].concat(i[a]):s[a]=i[a]:s[a]=t[a];for(const e in i)f(s,e)||(s[e]=i[e]);return s}(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 f(this.options.validationMessages,e)?this.options.validationMessages[e](r,t):this.options.validationMessages.default(r,t)}register(e){"FormularioForm"===e.$options.name&&e.name&&this.registry.set(e.name,e)}deregister(e){"FormularioForm"===e.$options.name&&e.name&&this.registry.has(e.name)&&this.registry.delete(e.name)}handle(e,t,r=!1){const i=r?e:this.options.errorHandler(e,t);if(t&&this.registry.has(t)){this.registry.get(t).applyErrors({formErrors:d(i.formErrors),inputErrors:i.inputErrors||{}})}return i}reset(e,t={}){this.resetValidation(e),this.setValues(e,t)}resetValidation(e){const t=this.registry.get(e);t.hideErrors(e),t.namedErrors=[],t.namedFieldErrors={}}setValues(e,t){if(t){this.registry.get(e).setValues(Object.assign({},t))}}getUploader(){return this.options.uploader||!1}getUploadUrl(){return this.options.uploadUrl||!1}getFileUrlKey(){return this.options.fileUrlKey||"url"}createUpload(e,t){return new n(e,t,this.options)}}})); + ***************************************************************************** */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)}}})); diff --git a/package.json b/package.json index d73937c..93d65a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@retailcrm/vue-formulario", - "version": "0.1.1", + "version": "0.2.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\"",