1
0
mirror of synced 2024-11-29 00:26:12 +03:00
vue-formulario/dist/formulario.esm.js
2020-10-19 12:32:15 +03:00

2 lines
34 KiB
JavaScript

import t from"is-url";import r from"nanoid/non-secure";import e from"is-plain-object";var i=function(t,r){return{classification:t,component:"FormularioInput"+(r||t[0].toUpperCase()+t.substr(1))}},o=Object.assign({},["text","email","number","color","date","hidden","month","password","search","tel","time","url","week","datetime-local"].reduce((function(t,r){var e;return Object.assign({},t,((e={})[r]=i("text"),e))}),{}),{range:i("slider"),textarea:i("textarea","TextArea"),checkbox:i("box"),radio:i("box"),submit:i("button"),button:i("button"),select:i("select"),file:i("file"),image:i("file"),group:i("group")}),n=function(t,r,e){void 0===e&&(e={}),this.input=t,this.fileList=t.files,this.files=[],this.options=Object.assign({},{mimes:{}},e),this.results=!1,this.context=r,Array.isArray(this.fileList)?this.rehydrateFileList(this.fileList):this.addFileList(this.fileList)};function s(t,r){if(t===r)return!0;if(!t||!r)return!1;var e=Object.keys(t),i=Object.keys(r),o=e.length;if(i.length!==o)return!1;if(t instanceof Date&&r instanceof Date)return t.getTime()===r.getTime();if(0===o)return t===r;for(var n=0;n<o;n++){var s=e[n];if(t[s]!==r[s])return!1}return!0}function a(t){return"string"==typeof t?t.replace(/([_][a-z0-9])/gi,(function(r){return 0!==t.indexOf(r)&&"_"!==t[t.indexOf(r)-1]?r.toUpperCase().replace("_",""):r})):t}function u(t){return t?"string"==typeof t?[t]:Array.isArray(t)?t:"object"==typeof t?Object.values(t):[]:[]}function l(t,r){return"string"==typeof t?l(t.split("|"),r):Array.isArray(t)?t.map((function(t){return function(t,r){if("function"==typeof t)return[t,[]];if(Array.isArray(t)&&t.length){var e=f((t=t.map((function(t){return t}))).shift()),i=e[0],o=e[1];if("string"==typeof i&&r.hasOwnProperty(i))return[r[i],t,i,o];if("function"==typeof i)return[i,t,i,o]}if("string"==typeof t){var n=t.split(":"),s=f(n.shift()),a=s[0],u=s[1];if(r.hasOwnProperty(a))return[r[a],n.length?n.join(":").split(","):[],a,u];throw new Error("Unknown validation rule "+t)}return!1}(t,r)})).filter((function(t){return!!t})):[]}function f(t){return/^[\^]/.test(t.charAt(0))?[a(t.substr(1)),t.charAt(0)]:[a(t),null]}function h(t){switch(typeof t){case"symbol":case"number":case"string":case"boolean":case"undefined":return!0;default:return null===t}}function c(t,r){return Object.prototype.hasOwnProperty.call(t,r)}function d(t,r){var e=r.split("."),i=t;for(var o in e){var n=e[o].match(/(.+)\[(\d+)\]$/);if(void 0===i)return null;if(n){if(void 0===(i=i[n[1]]))return null;i=i[n[2]]}else i=i[e[o]]}return i}n.prototype.rehydrateFileList=function(t){var r=this,e=t.reduce((function(t,e){var i=e[r.options?r.options.fileUrlKey:"url"],o=!(!i||-1===i.lastIndexOf("."))&&i.substr(i.lastIndexOf(".")+1),n=r.options.mimes[o]||!1;return t.push(Object.assign({},e,i?{name:i.substr(i.lastIndexOf("/")+1||0),type:e.type?e.type:n,previewData:i}:{})),t}),[]);this.results=t,this.addFileList(e)},n.prototype.addFileList=function(t){for(var e=this,i=function(i){var o=t[i],n=r();e.files.push({progress:!1,error:!1,complete:!1,justFinished:!1,name:o.name||"file-upload",file:o,uuid:n,path:!1,removeFile:function(){this.removeFile(n)}.bind(e),previewData:o.previewData||!1})},o=0;o<t.length;o++)i(o)},n.prototype.hasUploader=function(){return!!this.context.uploader},n.prototype.uploaderIsAxios=function(){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)},n.prototype.getUploader=function(){for(var t,r=[],e=arguments.length;e--;)r[e]=arguments[e];if(this.uploaderIsAxios()){var i=new FormData;if(i.append(this.context.name||"file",r[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,i,{headers:{"Content-Type":"multipart/form-data"},onUploadProgress:function(t){r[1](Math.round(100*t.loaded/t.total))}}).then((function(t){return t.data})).catch((function(t){return r[2](t)}))}return(t=this.context).uploader.apply(t,r)},n.prototype.upload=function(){var t=this;return this.results?Promise.resolve(this.results):new Promise((function(r,e){if(!t.hasUploader)return e(new Error("No uploader has been defined"));Promise.all(t.files.map((function(r){return r.path?Promise.resolve(r.path):t.getUploader(r.file,(function(e){r.progress=e,e>=100&&(r.complete||(r.justFinished=!0,setTimeout((function(){r.justFinished=!1}),t.options.uploadJustCompleteDuration)),r.complete=!0)}),(function(t){r.progress=0,r.error=t,r.complete=!0}),t.options)}))).then((function(e){t.results=e,r(e)})).catch((function(t){throw new Error(t)}))}))},n.prototype.removeFile=function(t){if(this.files=this.files.filter((function(r){return r.uuid!==t})),this.context.performValidation(),window&&this.fileList instanceof FileList){var r=new DataTransfer;this.files.map((function(t){return r.items.add(t.file)})),this.fileList=r.files,this.input.files=this.fileList}},n.prototype.loadPreviews=function(){this.files.map((function(t){if(!t.previewData&&window&&window.FileReader&&/^image\//.test(t.file.type)){var r=new FileReader;r.onload=function(r){return Object.assign(t,{previewData:r.target.result})},r.readAsDataURL(t.file)}}))},n.prototype.getFileList=function(){return this.fileList},n.prototype.getFiles=function(){return this.files},n.prototype.toString=function(){var t=this.files.length?this.files.length+" files":"empty";return this.results?JSON.stringify(this.results,null," "):"FileUpload("+t+")"};var p={accepted:function(t){var r=t.value;return Promise.resolve(["yes","on","1",1,!0,"true"].includes(r))},after:function(t,r){var e=t.value;void 0===r&&(r=!1);var i=Date.parse(r||new Date),o=Date.parse(e);return Promise.resolve(!isNaN(o)&&o>i)},alpha:function(t,r){var e=t.value;void 0===r&&(r="default");var i={default:/^[a-zA-ZÀ-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z]+$/},o=i.hasOwnProperty(r)?r:"default";return Promise.resolve(i[o].test(e))},alphanumeric:function(t,r){var e=t.value;void 0===r&&(r="default");var i={default:/^[a-zA-Z0-9À-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z0-9]+$/},o=i.hasOwnProperty(r)?r:"default";return Promise.resolve(i[o].test(e))},before:function(t,r){var e=t.value;void 0===r&&(r=!1);var i=Date.parse(r||new Date),o=Date.parse(e);return Promise.resolve(!isNaN(o)&&o<i)},between:function(t,r,e,i){var o=t.value;return void 0===r&&(r=0),void 0===e&&(e=10),Promise.resolve(null!==r&&null!==e&&!isNaN(r)&&!isNaN(e)&&(!isNaN(o)&&"length"!==i||"value"===i?(o=Number(o),r=Number(r),e=Number(e),o>r&&o<e):("string"==typeof o||"length"===i)&&(o=isNaN(o)?o:o.toString()).length>r&&o.length<e))},confirm:function(t,r){var e,i,o=t.value,n=t.getFormValues,s=t.name;return Promise.resolve((e=n(),(i=r)||(i=/_confirm$/.test(s)?s.substr(0,s.length-8):s+"_confirm"),e[i]===o))},date:function(t,r){var e=t.value;return void 0===r&&(r=!1),Promise.resolve(r&&"string"==typeof r?function(t){var r="^"+t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"$",e={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(e).reduce((function(t,r){return t.replace(r,e[r])}),r))}(r).test(e):!isNaN(Date.parse(e)))},email:function(t){var r=t.value;if(!r)return Promise.resolve((function(){return!0}));return Promise.resolve(/^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i.test(r))},endsWith:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return r?Promise.resolve("string"==typeof r&&e.length?void 0!==e.find((function(t){return r.endsWith(t)})):"string"==typeof r&&0===e.length):Promise.resolve((function(){return!0}))},in:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(void 0!==e.find((function(t){return"object"==typeof t?s(t,r):t===r})))},matches:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(!!e.find((function(t){return"string"==typeof t&&"/"===t.substr(0,1)&&"/"===t.substr(-1)&&(t=new RegExp(t.substr(1,t.length-2))),t instanceof RegExp?t.test(r):t===r})))},mime:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(function(){if(r instanceof n)for(var t=r.getFiles(),i=0;i<t.length;i++){var o=t[i].file;if(!e.includes(o.type))return!1}return!0}())},min:function(t,r,e){var i=t.value;return void 0===r&&(r=1),Promise.resolve(Array.isArray(i)?(r=isNaN(r)?r:Number(r),i.length>=r):!isNaN(i)&&"length"!==e||"value"===e?(i=isNaN(i)?i:Number(i))>=r:("string"==typeof i||"length"===e)&&(i=isNaN(i)?i:i.toString()).length>=r)},max:function(t,r,e){var i=t.value;return void 0===r&&(r=10),Promise.resolve(Array.isArray(i)?(r=isNaN(r)?r:Number(r),i.length<=r):!isNaN(i)&&"length"!==e||"value"===e?(i=isNaN(i)?i:Number(i))<=r:("string"==typeof i||"length"===e)&&(i=isNaN(i)?i:i.toString()).length<=r)},not:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return Promise.resolve(void 0===e.find((function(t){return"object"==typeof t?s(t,r):t===r})))},number:function(t){var r=t.value;return Promise.resolve(!isNaN(r))},required:function(t,r){var e=t.value;return void 0===r&&(r=!0),Promise.resolve(!(r&&!["no","false"].includes(r))||(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:function(t){for(var r=t.value,e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return r?Promise.resolve("string"==typeof r&&e.length?void 0!==e.find((function(t){return r.startsWith(t)})):"string"==typeof r&&0===e.length):Promise.resolve((function(){return!0}))},url:function(r){var e=r.value;return Promise.resolve(t(e))},bail:function(){return Promise.resolve(!0)}},m="image/",v={csv:"text/csv",gif:m+"gif",jpg:m+"jpeg",jpeg:m+"jpeg",png:m+"png",pdf:"application/pdf",svg:m+"svg+xml"},g={default:function(t,r){return t.$t("validation.default",r)},accepted:function(t,r){return t.$t("validation.accepted",r)},after:function(t,r){return Array.isArray(r.args)&&r.args.length?(r.compare=r.args[0],t.$t("validation.after.compare",r)):t.$t("validation.after.default",r)},alpha:function(t,r){return t.$t("validation.alpha",r)},alphanumeric:function(t,r){return t.$t("validation.alphanumeric",r)},before:function(t,r){return Array.isArray(r.args)&&r.args.length?(r.compare=r.args[0],t.$t("validation.before.compare",r)):t.$t("validation.before.default",r)},between:function(t,r){r.from=r.args[0],r.to=r.args[1];var e=!(!Array.isArray(r.args)||!r.args[2])&&r.args[2];return!isNaN(value)&&"length"!==e||"value"===e?t.$t("validation.between.force",r):t.$t("validation.between.default",r)},confirm:function(t,r){return t.$t("validation.confirm",r)},date:function(t,r){return Array.isArray(r.args)&&r.args.length?(r.format=r.args[0],t.$t("validation.date.format",r)):t.$t("validation.date.default",r)},email:function(t,r){return t.$t("validation.email.default",r)},endsWith:function(t,r){return t.$t("validation.endsWith.default",r)},in:function(t,r){return"string"==typeof r.value&&r.value?t.$t("validation.in.string",r):t.$t("validation.in.default",r)},matches:function(t,r){return t.$t("validation.matches.default",r)},max:function(t,r){if(r.maximum=r.args[0],Array.isArray(r.value))return t.$tc("validation.max.array",r.maximum,r);var e=!(!Array.isArray(r.args)||!r.args[1])&&r.args[1];return!isNaN(r.value)&&"length"!==e||"value"===e?t.$tc("validation.max.force",r.maximum,r):t.$tc("validation.max.default",r.maximum,r)},mime:function(t,r){return r.types=r.args[0],r.types?t.$t("validation.mime.default",r):t.$t("validation.mime.no_formats_allowed",r)},min:function(t,r){if(r.minimum=r.args[0],Array.isArray(r.value))return t.$tc("validation.min.array",r.minimum,r);var e=!(!Array.isArray(r.args)||!r.args[1])&&r.args[1];return!isNaN(r.value)&&"length"!==e||"value"===e?t.$tc("validation.min.force",r.minimum,r):t.$tc("validation.min.default",r.minimum,r)},not:function(t,r){return t.$t("validation.not.default",r)},number:function(t,r){return t.$t("validation.number.default",r)},required:function(t,r){return t.$t("validation.required.default",r)},startsWith:function(t,r){return t.$t("validation.startsWith.default",r)},url:function(t,r){return t.$t("validation.url.default",r)}};function y(t){t.extend({validationMessages:g})}function b(t,r,e,i){return new Promise((function(e,o){var n=(i.fauxUploaderDuration||2e3)*(.5+Math.random()),s=performance.now(),a=function(){return setTimeout((function(){var i=performance.now()-s,o=Math.min(100,Math.round(i/n*100));if(r(o),o>=100)return e({url:"http://via.placeholder.com/350x150.png",name:t.name});a()}),20)};a()}))}function E(t,r){var e={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&-1===r.indexOf(i)&&(e[i]=t[i]);return e}var x=function(t){this.registry=new Map,this.ctx=t};x.prototype.add=function(t,r){return this.registry.set(t,r),this},x.prototype.remove=function(t){this.registry.delete(t);var r=this.ctx.proxy,e=(r[t],E(r,[String(t)]));return this.ctx.proxy=e,this},x.prototype.has=function(t){return this.registry.has(t)},x.prototype.get=function(t){return this.registry.get(t)},x.prototype.map=function(t){var r={};return this.registry.forEach((function(e,i){var o;return Object.assign(r,((o={})[i]=t(e,i),o))})),r},x.prototype.keys=function(){return Array.from(this.registry.keys())},x.prototype.register=function(t,r){if(this.registry.has(t))return!1;this.registry.set(t,r);var e=c(r.$options.propsData,"formularioValue"),i=c(r.$options.propsData,"value");!e&&this.ctx.hasInitialValue&&void 0!==d(this.ctx.initialValues,t)?r.context.model=d(this.ctx.initialValues,t):!e&&!i||s(r.proxy,d(this.ctx.initialValues,t))||this.ctx.setFieldValue(t,r.proxy),this.childrenShouldShowErrors&&(r.formShouldShowErrors=!0)},x.prototype.reduce=function(t,r){return this.registry.forEach((function(e,i){r=t(r,e,i)})),r},x.prototype.dataProps=function(){var t=this;return{proxy:{},registry:this,register:this.register.bind(this),deregister:function(r){return t.remove(r)},childrenShouldShowErrors:!1}};var V=function(t){this.form=t};function w(t,r,e,i,o,n,s,a,u,l){"boolean"!=typeof s&&(u=a,a=s,s=!1);var f,h="function"==typeof e?e.options:e;if(t&&t.render&&(h.render=t.render,h.staticRenderFns=t.staticRenderFns,h._compiled=!0,o&&(h.functional=!0)),i&&(h._scopeId=i),n?(f=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),r&&r.call(this,u(t)),t&&t._registeredComponents&&t._registeredComponents.add(n)},h._ssrRegister=f):r&&(f=s?function(t){r.call(this,l(t,this.$root.$options.shadowRoot))}:function(t){r.call(this,a(t))}),f)if(h.functional){var c=h.render;h.render=function(t,r){return f.call(r),c(t,r)}}else{var d=h.beforeCreate;h.beforeCreate=d?[].concat(d,f):[f]}return e}V.prototype.hasValidationErrors=function(){return this.form.hasValidationErrors()},V.prototype.values=function(){var t=this;return new Promise((function(r,e){var i=[],o=function t(r){if("object"!=typeof r)return r;var e=Array.isArray(r)?[]:{};for(var i in r)r[i]instanceof n||h(r[i])?e[i]=r[i]:e[i]=t(r[i]);return e}(t.form.proxy),s=function(r){"object"==typeof t.form.proxy[r]&&t.form.proxy[r]instanceof n&&i.push(t.form.proxy[r].upload().then((function(t){var e;return Object.assign(o,((e={})[r]=t,e))})))};for(var a in o)s(a);Promise.all(i).then((function(){return r(o)})).catch((function(t){return e(t)}))}))};var O={provide:function(){return Object.assign({},{formularioSetter:(t=this).setFieldValue,formularioRegister:t.register,formularioDeregister:t.deregister,getFormValues:t.getFormValues},{observeErrors:this.addErrorObserver,removeErrorObserver:this.removeErrorObserver,formularioFieldValidation:this.formularioFieldValidation,path:""});var t},name:"FormularioForm",model:{prop:"formularioValue",event:"input"},props:{name:{type:[String,Boolean],default:!1},formularioValue:{type:Object,default:function(){return{}}},values:{type:[Object,Boolean],default:!1},errors:{type:[Object,Boolean],default:!1},formErrors:{type:Array,default:function(){return[]}}},data:function(){return Object.assign({},new x(this).dataProps(),{formShouldShowErrors:!1,errorObservers:[],namedErrors:[],namedFieldErrors:{}})},computed:Object.assign({},{hasInitialValue:function(){return this.formularioValue&&"object"==typeof this.formularioValue||this.values&&"object"==typeof this.values||this.isGrouping&&"object"==typeof this.context.model[this.index]},isVmodeled:function(){return!!(this.$options.propsData.hasOwnProperty("formularioValue")&&this._events&&Array.isArray(this._events.input)&&this._events.input.length)},initialValues:function(){return c(this.$options.propsData,"formularioValue")&&"object"==typeof this.formularioValue?Object.assign({},this.formularioValue):c(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]:{}}},{classes:function(){var t={"formulario-form":!0};return this.name&&(t["formulario-form--"+this.name]=!0),t},mergedFormErrors:function(){return this.formErrors.concat(this.namedErrors)},mergedFieldErrors:function(){var t={};if(this.errors)for(var r in this.errors)t[r]=u(this.errors[r]);for(var e in this.namedFieldErrors)t[e]=u(this.namedFieldErrors[e]);return t},hasFormErrorObservers:function(){return!!this.errorObservers.filter((function(t){return"form"===t.type})).length}}),watch:{formularioValue:{handler:function(t){this.isVmodeled&&t&&"object"==typeof t&&this.setValues(t)},deep:!0},mergedFormErrors:function(t){this.errorObservers.filter((function(t){return"form"===t.type})).forEach((function(r){return r.callback(t)}))},mergedFieldErrors:{handler:function(t){this.errorObservers.filter((function(t){return"input"===t.type})).forEach((function(r){return r.callback(t[r.field]||[])}))},immediate:!0}},created:function(){this.$formulario.register(this),this.applyInitialValues()},destroyed:function(){this.$formulario.deregister(this)},methods:Object.assign({},function(t){void 0===t&&(t=[]);var r={applyInitialValues:function(){this.hasInitialValue&&(this.proxy=this.initialValues)},setFieldValue:function(t,r){if(void 0===r){var e=this.proxy,i=(e[t],E(e,[String(t)]));this.proxy=i}else!function(t,r,e){for(var i=r.split("."),o=t,n=0;n<i.length;n++){var s=i[n],a=s.match(/(.+)\[(\d+)\]$/);if(a){if(void 0===o[a[1]]&&(o[a[1]]=[]),o=o[a[1]],n==i.length-1){o[a[2]]=e;break}o=o[a[2]]}else{if(n==i.length-1){o[s]=e;break}void 0===o[s]&&(o[s]={}),o=o[s]}}}(this.proxy,t,r);this.$emit("input",Object.assign({},this.proxy))},getFormValues:function(){return this.proxy},hasValidationErrors:function(){return Promise.all(this.registry.reduce((function(t,r,e){return t.push(r.performValidation()&&r.getValidationErrors()),t}),[])).then((function(t){return t.some((function(t){return t.hasErrors}))}))},showErrors:function(){this.childrenShouldShowErrors=!0,this.registry.map((function(t){t.formShouldShowErrors=!0}))},hideErrors:function(){this.childrenShouldShowErrors=!1,this.registry.map((function(t){t.formShouldShowErrors=!1,t.behavioralErrorVisibility=!1}))},setValues:function(t){var r=this;Array.from(new Set(Object.keys(t).concat(Object.keys(this.proxy)))).forEach((function(e){!r.registry.has(e)||s(d(t,e),d(r.proxy,e))||s(d(t,e),r.registry.get(e).proxy)||(r.setFieldValue(e,d(t,e)),r.registry.get(e).context.model=d(t,e))})),this.applyInitialValues()}};return Object.keys(r).reduce((function(e,i){var o;return t.includes(i)?e:Object.assign({},e,((o={})[i]=r[i],o))}),{})}(),{applyErrors:function(t){var r=t.formErrors,e=t.inputErrors;this.namedErrors=r,this.namedFieldErrors=e},addErrorObserver:function(t){this.errorObservers.find((function(r){return t.callback===r.callback}))||(this.errorObservers.push(t),"form"===t.type?t.callback(this.mergedFormErrors):c(this.mergedFieldErrors,t.field)&&t.callback(this.mergedFieldErrors[t.field]))},removeErrorObserver:function(t){this.errorObservers=this.errorObservers.filter((function(r){return r.callback!==t}))},registerErrorComponent:function(t){this.errorComponents.includes(t)||this.errorComponents.push(t)},formSubmitted:function(){var t=this;this.showErrors();var r=new V(this);return this.$emit("submit-raw",r),r.hasValidationErrors().then((function(t){return t?void 0:r.values()})).then((function(r){if(void 0!==r)return t.$emit("submit",r),r}))},formularioFieldValidation:function(t){this.$emit("validation",t)}})},$=function(){var t=this,r=t.$createElement;return(t._self._c||r)("form",{class:t.classes,on:{submit:function(r){return r.preventDefault(),t.formSubmitted(r)}}},[t._t("default",null,{errors:t.mergedFormErrors})],2)};$._withStripped=!0;var F=w({render:$,staticRenderFns:[]},void 0,O,void 0,!1,void 0,!1,void 0,void 0,void 0),j={context:function(){return P.call(this,{attributes:this.elementAttributes,blurHandler:A.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),help:this.help,id:this.id||this.defaultId,imageBehavior:this.imageBehavior,limit:this.limit,name:this.nameOrFallback,performValidation:this.performValidation.bind(this),preventWindowDrops:this.preventWindowDrops,repeatable:this.repeatable,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})},nameOrFallback:function(){if(""!==this.path)return this.path+"."+this.name;return this.name},hasGivenName:function(){return"boolean"!=typeof this.name},elementAttributes:function(){var t=Object.assign({},this.localAttributes);this.id?t.id=this.id:t.id=this.defaultId;this.hasGivenName&&(t.name=this.name);this.help&&(t["aria-describedby"]=t.id+"-help");return t},mergedUploadUrl:function(){return this.uploadUrl||this.$formulario.getUploadUrl()},isVmodeled:function(){return!!(this.$options.propsData.hasOwnProperty("formularioValue")&&this._events&&Array.isArray(this._events.input)&&this._events.input.length)},mergedValidationName:function(){if(this.validationName)return this.validationName;return this.name},explicitErrors:function(){var t=u(this.errors).concat(this.localErrors).concat(u(this.error));return t=t.map((function(t){return{message:t,rule:null,context:null}}))},allErrors:function(){return this.explicitErrors.concat(u(this.validationErrors))},hasErrors:function(){return!!this.allErrors.length},hasVisibleErrors:function(){return this.validationErrors&&this.showValidationErrors||!!this.explicitErrors.length},showValidationErrors:function(){if(this.showErrors||this.formShouldShowErrors)return!0;return this.behavioralErrorVisibility},visibleValidationErrors:function(){return this.showValidationErrors&&this.validationErrors.length?this.validationErrors:[]}};function A(){this.$emit("blur"),"blur"===this.errorBehavior&&(this.behavioralErrorVisibility=!0)}function P(t){return Object.defineProperty(t,"model",{get:N.bind(this),set:S.bind(this)})}function N(){var t=this.isVmodeled?"formularioValue":"proxy";return void 0===this[t]?"":this[t]}function S(t){s(t,this.proxy)||(this.proxy=t),this.$emit("input",t),this.context.name&&"function"==typeof this.formularioSetter&&this.formularioSetter(this.context.name,t)}var R={name:"FormularioInput",inheritAttrs:!1,provide:function(){return{formularioRegisterRule:this.registerRule,formularioRemoveRule:this.removeRule}},inject:{formularioSetter:{default:void 0},formularioFieldValidation:{default:function(){return function(){return{}}}},formularioRegister:{default:void 0},formularioDeregister:{default:void 0},getFormValues:{default:function(){return function(){return{}}}},observeErrors:{default:void 0},removeErrorObserver:{default:void 0},path:{default:""}},model:{prop:"formularioValue",event:"input"},props:{type:{type:String,default:"text"},name:{type:String,required:!0},formularioValue:{default:""},value:{default:!1},id:{type:[String,Boolean,Number],default:!1},errors:{type:[String,Array,Boolean],default:!1},validation:{type:[String,Boolean,Array],default:!1},validationName:{type:[String,Boolean],default:!1},errorBehavior:{type:String,default:"blur",validator:function(t){return["blur","live","submit"].includes(t)}},showErrors:{type:Boolean,default:!1},imageBehavior:{type:String,default:"preview"},uploadUrl:{type:[String,Boolean],default:!1},uploader:{type:[Function,Object,Boolean],default:!1},uploadBehavior:{type:String,default:"live"},preventWindowDrops:{type:Boolean,default:!0},validationMessages:{type:Object,default:function(){return{}}},validationRules:{type:Object,default:function(){return{}}},disableErrors:{type:Boolean,default:!1}},data:function(){return{defaultId:this.$formulario.nextId(this),localAttributes:{},localErrors:[],proxy:this.getInitialValue(),behavioralErrorVisibility:"live"===this.errorBehavior,formShouldShowErrors:!1,validationErrors:[],pendingValidation:Promise.resolve(),ruleRegistry:[],messageRegistry:{}}},computed:Object.assign({},j,{parsedValidationRules:function(){var t=this,r={};return Object.keys(this.validationRules).forEach((function(e){r[a(e)]=t.validationRules[e]})),r},messages:function(){var t=this,r={};return Object.keys(this.validationMessages).forEach((function(e){r[a(e)]=t.validationMessages[e]})),Object.keys(this.messageRegistry).forEach((function(e){r[a(e)]=t.messageRegistry[e]})),r}}),watch:{$attrs:{handler:function(t){this.updateLocalAttributes(t)},deep:!0},proxy:function(t,r){this.performValidation(),this.isVmodeled||s(t,r)||(this.context.model=t)},formularioValue:function(t,r){this.isVmodeled&&!s(t,r)&&(this.context.model=t)},showValidationErrors:{handler:function(t){this.$emit("error-visibility",t)},immediate:!0}},created:function(){this.applyInitialValue(),this.formularioRegister&&"function"==typeof this.formularioRegister&&this.formularioRegister(this.nameOrFallback,this),this.disableErrors||"function"!=typeof this.observeErrors||this.observeErrors({callback:this.setErrors,type:"input",field:this.nameOrFallback}),this.updateLocalAttributes(this.$attrs),"live"===this.errorBehavior&&this.performValidation()},beforeDestroy:function(){this.disableErrors||"function"!=typeof this.removeErrorObserver||this.removeErrorObserver(this.setErrors),"function"==typeof this.formularioDeregister&&this.formularioDeregister(this.nameOrFallback)},methods:{getInitialValue:function(){return c(this.$options.propsData,"value")?this.value:c(this.$options.propsData,"formularioValue")?this.formularioValue:""},applyInitialValue:function(){s(this.context.model,this.proxy)||(this.context.model=this.proxy)},updateLocalAttributes:function(t){s(t,this.localAttributes)||(this.localAttributes=t)},performValidation:function(){var t=this,r=l(this.validation,this.$formulario.rules(this.parsedValidationRules));return r=this.ruleRegistry.length?this.ruleRegistry.concat(r):r,this.pendingValidation=this.runRules(r).then((function(r){return t.didValidate(r)})),this.pendingValidation},runRules:function(t){var r=this,e=function(t){var e=t[0],i=t[1],o=t[2],n=(t[3],e.apply(void 0,[{value:r.context.model,getFormValues:r.getFormValues.bind(r),name:r.context.name}].concat(i)));return(n=n instanceof Promise?n:Promise.resolve(n)).then((function(t){return!t&&r.getMessageObject(o,i)}))};return new Promise((function(r){var i=function(t,o){void 0===o&&(o=[]);var n=t.shift();Array.isArray(n)&&n.length?Promise.all(n.map(e)).then((function(t){return t.filter((function(t){return!!t}))})).then((function(e){return(e=Array.isArray(e)?e:[]).length&&n.bail||!t.length?r(o.concat(e)):i(t,o.concat(e))})):r([])};i(function(t){var r=[],e=t.findIndex((function(t){return"bail"===t[2].toLowerCase()}));if(e>=0){var i=t.splice(0,e+1).slice(0,-1);i.length&&r.push(i),t.map((function(t){return r.push(Object.defineProperty([t],"bail",{value:!0}))}))}else r.push(t);return r.reduce((function(t,r){var e=function(t,r){if(void 0===r&&(r=!1),t.length<2)return Object.defineProperty([t],"bail",{value:r});var i=[],o=t.findIndex((function(t){return"^"===t[3]}));if(o>=0){var n=t.splice(0,o);n.length&&i.push.apply(i,e(n,r)),i.push(Object.defineProperty([t.shift()],"bail",{value:!0})),t.length&&i.push.apply(i,e(t,r))}else i.push(t);return i};return t.concat(e(r))}),[])}(t))}))},didValidate:function(t){var r=!s(t,this.validationErrors);if(this.validationErrors=t,r){var e=this.getErrorObject();this.$emit("validation",e),this.formularioFieldValidation&&"function"==typeof this.formularioFieldValidation&&this.formularioFieldValidation(e)}},getMessageObject:function(t,r){var e={args:r,name:this.mergedValidationName,value:this.context.model,vm:this,formValues:this.getFormValues()};return{message:this.getMessageFunc(t)(e),rule:t,context:e}},getMessageFunc:function(t){var r=this;if(t=a(t),this.messages&&void 0!==this.messages[t])switch(typeof this.messages[t]){case"function":return this.messages[t];case"string":case"boolean":return function(){return r.messages[t]}}return function(e){return r.$formulario.validationMessage(t,e,r)}},hasValidationErrors:function(){var t=this;return new Promise((function(r){t.$nextTick((function(){t.pendingValidation.then((function(){return r(!!t.validationErrors.length)}))}))}))},getValidationErrors:function(){var t=this;return new Promise((function(r){t.$nextTick((function(){return t.pendingValidation.then((function(){return r(t.getErrorObject())}))}))}))},getErrorObject:function(){return{name:this.context.nameOrFallback||this.context.name,errors:this.validationErrors.filter((function(t){return"object"==typeof t})),hasErrors:!!this.validationErrors.length}},setErrors:function(t){this.localErrors=u(t)},registerRule:function(t,r,e,i){void 0===i&&(i=null),this.ruleRegistry.some((function(t){return t[2]===e}))||(this.ruleRegistry.push([t,r,e]),null!==i&&(this.messageRegistry[e]=i))},removeRule:function(t){var r=this.ruleRegistry.findIndex((function(r){return r[2]===t}));r>=0&&(this.ruleRegistry.splice(r,1),delete this.messageRegistry[t])}}},_=function(){var t=this,r=t.$createElement;return(t._self._c||r)("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)};_._withStripped=!0;var D=w({render:_,staticRenderFns:[]},void 0,R,void 0,!1,void 0,!1,void 0,void 0,void 0),U={name:"FormularioGrouping",props:{name:{type:String,required:!0},isArrayItem:{type:Boolean,default:!1}},provide:function(){return{path:this.groupPath}},inject:["path"],computed:{groupPath:function(){return this.isArrayItem?this.path+"["+this.name+"]":""===this.path?this.name:this.path+"."+this.name}}},k=function(){var t=this.$createElement;return(this._self._c||t)("div",{staticClass:"formulario-group",attrs:{"data-type":"group"}},[this._t("default")],2)};k._withStripped=!0;var I=w({render:k,staticRenderFns:[]},void 0,U,void 0,!1,void 0,!1,void 0,void 0,void 0),B=function(){this.options={},this.defaults={components:{FormularioForm:F,FormularioInput:D,FormularioGrouping:I},library:o,rules:p,mimes:v,locale:!1,uploader:b,uploadUrl:!1,fileUrlKey:"url",uploadJustCompleteDuration:1e3,errorHandler:function(t){return t},plugins:[y],validationMessages:{},idPrefix:"formulario-"},this.registry=new Map,this.idRegistry={}};B.prototype.install=function(t,r){var e=this;t.prototype.$formulario=this,this.options=this.defaults;var i=this.defaults.plugins;for(var o in r&&Array.isArray(r.plugins)&&r.plugins.length&&(i=i.concat(r.plugins)),i.forEach((function(t){return"function"==typeof t?t(e):null})),this.extend(r||{}),this.options.components)t.component(o,this.options.components[o])},B.prototype.nextId=function(t){var r=!(!t.$route||!t.$route.path)&&t.$route.path?t.$route.path.replace(/[/\\.\s]/g,"-"):"global";return Object.prototype.hasOwnProperty.call(this.idRegistry,r)||(this.idRegistry[r]=0),""+this.options.idPrefix+r+"-"+ ++this.idRegistry[r]},B.prototype.extend=function(t){if("object"==typeof t)return this.options=this.merge(this.options,t),this;throw new Error("VueFormulario extend() should be passed an object (was "+typeof t+")")},B.prototype.merge=function(t,r,i){void 0===i&&(i=!0);var o={};for(var n in t)r.hasOwnProperty(n)?e(r[n])&&e(t[n])?o[n]=this.merge(t[n],r[n],i):i&&Array.isArray(t[n])&&Array.isArray(r[n])?o[n]=t[n].concat(r[n]):o[n]=r[n]:o[n]=t[n];for(var s in r)o.hasOwnProperty(s)||(o[s]=r[s]);return o},B.prototype.classify=function(t){return this.options.library.hasOwnProperty(t)?this.options.library[t].classification:"unknown"},B.prototype.component=function(t){return!!this.options.library.hasOwnProperty(t)&&this.options.library[t].component},B.prototype.rules=function(t){return void 0===t&&(t={}),Object.assign({},this.options.rules,t)},B.prototype.validationMessage=function(t,r,e){return this.options.validationMessages.hasOwnProperty(t)?this.options.validationMessages[t](e,r):this.options.validationMessages.default(e,r)},B.prototype.register=function(t){"FormularioForm"===t.$options.name&&t.name&&this.registry.set(t.name,t)},B.prototype.deregister=function(t){"FormularioForm"===t.$options.name&&t.name&&this.registry.has(t.name)&&this.registry.delete(t.name)},B.prototype.handle=function(t,r,e){void 0===e&&(e=!1);var i=e?t:this.options.errorHandler(t,r);return r&&this.registry.has(r)&&this.registry.get(r).applyErrors({formErrors:u(i.formErrors),inputErrors:i.inputErrors||{}}),i},B.prototype.reset=function(t,r){void 0===r&&(r={}),this.resetValidation(t),this.setValues(t,r)},B.prototype.resetValidation=function(t){var r=this.registry.get(t);r.hideErrors(t),r.namedErrors=[],r.namedFieldErrors={}},B.prototype.setValues=function(t,r){r&&!Array.isArray(r)&&"object"==typeof r&&this.registry.get(t).setValues(Object.assign({},r))},B.prototype.getUploader=function(){return this.options.uploader||!1},B.prototype.getUploadUrl=function(){return this.options.uploadUrl||!1},B.prototype.getFileUrlKey=function(){return this.options.fileUrlKey||"url"},B.prototype.createUpload=function(t,r){return new n(t,r,this.options)};var M=new B;export default M;