15 lines
35 KiB
JavaScript
15 lines
35 KiB
JavaScript
var VueFormulario=function(){"use strict";var t=function(t,r){return{classification:t,component:"FormularioInput"+(r||t[0].toUpperCase()+t.substr(1))}},r=Object.assign({},["text","email","number","color","date","hidden","month","password","search","tel","time","url","week","datetime-local"].reduce((function(r,e){var i;return Object.assign({},r,((i={})[e]=t("text"),i))}),{}),{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")}),e=function(t){if("string"!=typeof t)return!1;var r=t.match(i);if(!r)return!1;var e=r[1];if(!e)return!1;if(o.test(e)||n.test(e))return!0;return!1},i=/^(?:\w+:)?\/\/(\S+)$/,o=/^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/,n=/^[^\s\.]+\.\S{2,}$/;for(var s="-_",a=36;a--;)s+=a.toString(36);for(a=36;a---10;)s+=a.toString(36).toUpperCase();var u=function(t){var r="";for(a=t||21;a--;)r+=s[64*Math.random()|0];return r},l=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 f(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 h(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 c(t){return t?"string"==typeof t?[t]:Array.isArray(t)?t:"object"==typeof t?Object.values(t):[]:[]}function d(t,r){return"string"==typeof t?d(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=p((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=p(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 p(t){return/^[\^]/.test(t.charAt(0))?[h(t.substr(1)),t.charAt(0)]:[h(t),null]}function m(t){switch(typeof t){case"symbol":case"number":case"string":case"boolean":case"undefined":return!0;default:return null===t}}function v(t,r){return Object.prototype.hasOwnProperty.call(t,r)}function g(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}l.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)},l.prototype.addFileList=function(t){for(var r=this,e=function(e){var i=t[e],o=u();r.files.push({progress:!1,error:!1,complete:!1,justFinished:!1,name:i.name||"file-upload",file:i,uuid:o,path:!1,removeFile:function(){this.removeFile(o)}.bind(r),previewData:i.previewData||!1})},i=0;i<t.length;i++)e(i)},l.prototype.hasUploader=function(){return!!this.context.uploader},l.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)},l.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)},l.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)}))}))},l.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}},l.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)}}))},l.prototype.getFileList=function(){return this.fileList},l.prototype.getFiles=function(){return this.files},l.prototype.toString=function(){var t=this.files.length?this.files.length+" files":"empty";return this.results?JSON.stringify(this.results,null," "):"FileUpload("+t+")"};var y={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?f(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 l)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?f(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 l?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(t){var r=t.value;return Promise.resolve(e(r))},bail:function(){return Promise.resolve(!0)}},b="image/",E={csv:"text/csv",gif:b+"gif",jpg:b+"jpeg",jpeg:b+"jpeg",png:b+"png",pdf:"application/pdf",svg:b+"svg+xml"},x={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 V(t){t.extend({validationMessages:x})}
|
|
/*!
|
|
* isobject <https://github.com/jonschlinkert/isobject>
|
|
*
|
|
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
* Released under the MIT License.
|
|
*/
|
|
/*!
|
|
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
|
*
|
|
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
* Released under the MIT License.
|
|
*/
|
|
function w(t){return!0==(null!=(r=t)&&"object"==typeof r&&!1===Array.isArray(r))&&"[object Object]"===Object.prototype.toString.call(t);var r}function O(t){var r,e;return!1!==w(t)&&("function"==typeof(r=t.constructor)&&(!1!==w(e=r.prototype)&&!1!==e.hasOwnProperty("isPrototypeOf")))}function $(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 F(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 j=function(t){this.registry=new Map,this.ctx=t};j.prototype.add=function(t,r){return this.registry.set(t,r),this},j.prototype.remove=function(t){this.registry.delete(t);var r=this.ctx.proxy,e=(r[t],F(r,[String(t)]));return this.ctx.proxy=e,this},j.prototype.has=function(t){return this.registry.has(t)},j.prototype.get=function(t){return this.registry.get(t)},j.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},j.prototype.keys=function(){return Array.from(this.registry.keys())},j.prototype.register=function(t,r){if(this.registry.has(t))return!1;this.registry.set(t,r);var e=v(r.$options.propsData,"formularioValue"),i=v(r.$options.propsData,"value");!e&&this.ctx.hasInitialValue&&void 0!==g(this.ctx.initialValues,t)?r.context.model=g(this.ctx.initialValues,t):!e&&!i||f(r.proxy,g(this.ctx.initialValues,t))||this.ctx.setFieldValue(t,r.proxy),this.childrenShouldShowErrors&&(r.formShouldShowErrors=!0)},j.prototype.reduce=function(t,r){return this.registry.forEach((function(e,i){r=t(r,e,i)})),r},j.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 A=function(t){this.form=t};function P(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}A.prototype.hasValidationErrors=function(){return this.form.hasValidationErrors()},A.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 l||m(r[i])?e[i]=r[i]:e[i]=t(r[i]);return e}(t.form.proxy),n=function(r){"object"==typeof t.form.proxy[r]&&t.form.proxy[r]instanceof l&&i.push(t.form.proxy[r].upload().then((function(t){var e;return Object.assign(o,((e={})[r]=t,e))})))};for(var s in o)n(s);Promise.all(i).then((function(){return r(o)})).catch((function(t){return e(t)}))}))};var S={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 j(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 v(this.$options.propsData,"formularioValue")&&"object"==typeof this.formularioValue?Object.assign({},this.formularioValue):v(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]=c(this.errors[r]);for(var e in this.namedFieldErrors)t[e]=c(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],F(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)||f(g(t,e),g(r.proxy,e))||f(g(t,e),r.registry.get(e).proxy)||(r.setFieldValue(e,g(t,e)),r.registry.get(e).context.model=g(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):v(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 A(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)}})},N=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)};N._withStripped=!0;var R=P({render:N,staticRenderFns:[]},void 0,S,void 0,!1,void 0,!1,void 0,void 0,void 0),_={context:function(){return U.call(this,{attributes:this.elementAttributes,blurHandler:D.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=c(this.errors).concat(this.localErrors).concat(c(this.error));return t=t.map((function(t){return{message:t,rule:null,context:null}}))},allErrors:function(){return this.explicitErrors.concat(c(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 D(){this.$emit("blur"),"blur"===this.errorBehavior&&(this.behavioralErrorVisibility=!0)}function U(t){return Object.defineProperty(t,"model",{get:k.bind(this),set:I.bind(this)})}function k(){var t=this.isVmodeled?"formularioValue":"proxy";return void 0===this[t]?"":this[t]}function I(t){f(t,this.proxy)||(this.proxy=t),this.$emit("input",t),this.context.name&&"function"==typeof this.formularioSetter&&this.formularioSetter(this.context.name,t)}var M={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({},_,{parsedValidationRules:function(){var t=this,r={};return Object.keys(this.validationRules).forEach((function(e){r[h(e)]=t.validationRules[e]})),r},messages:function(){var t=this,r={};return Object.keys(this.validationMessages).forEach((function(e){r[h(e)]=t.validationMessages[e]})),Object.keys(this.messageRegistry).forEach((function(e){r[h(e)]=t.messageRegistry[e]})),r}}),watch:{$attrs:{handler:function(t){this.updateLocalAttributes(t)},deep:!0},proxy:function(t,r){this.performValidation(),this.isVmodeled||f(t,r)||(this.context.model=t)},formularioValue:function(t,r){this.isVmodeled&&!f(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 v(this.$options.propsData,"value")?this.value:v(this.$options.propsData,"formularioValue")?this.formularioValue:""},applyInitialValue:function(){f(this.context.model,this.proxy)||(this.context.model=this.proxy)},updateLocalAttributes:function(t){f(t,this.localAttributes)||(this.localAttributes=t)},performValidation:function(){var t=this,r=d(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=!f(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=h(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=c(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])}}},B=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)};B._withStripped=!0;var L=P({render:B,staticRenderFns:[]},void 0,M,void 0,!1,void 0,!1,void 0,void 0,void 0),C={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}}},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;var W=P({render:T,staticRenderFns:[]},void 0,C,void 0,!1,void 0,!1,void 0,void 0,void 0),G=function(){this.options={},this.defaults={components:{FormularioForm:R,FormularioInput:L,FormularioGrouping:W},library:r,rules:y,mimes:E,locale:!1,uploader:$,uploadUrl:!1,fileUrlKey:"url",uploadJustCompleteDuration:1e3,errorHandler:function(t){return t},plugins:[V],validationMessages:{},idPrefix:"formulario-"},this.registry=new Map,this.idRegistry={}};return G.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])},G.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]},G.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+")")},G.prototype.merge=function(t,r,e){void 0===e&&(e=!0);var i={};for(var o in t)r.hasOwnProperty(o)?O(r[o])&&O(t[o])?i[o]=this.merge(t[o],r[o],e):e&&Array.isArray(t[o])&&Array.isArray(r[o])?i[o]=t[o].concat(r[o]):i[o]=r[o]:i[o]=t[o];for(var n in r)i.hasOwnProperty(n)||(i[n]=r[n]);return i},G.prototype.classify=function(t){return this.options.library.hasOwnProperty(t)?this.options.library[t].classification:"unknown"},G.prototype.component=function(t){return!!this.options.library.hasOwnProperty(t)&&this.options.library[t].component},G.prototype.rules=function(t){return void 0===t&&(t={}),Object.assign({},this.options.rules,t)},G.prototype.validationMessage=function(t,r,e){return this.options.validationMessages.hasOwnProperty(t)?this.options.validationMessages[t](e,r):this.options.validationMessages.default(e,r)},G.prototype.register=function(t){"FormularioForm"===t.$options.name&&t.name&&this.registry.set(t.name,t)},G.prototype.deregister=function(t){"FormularioForm"===t.$options.name&&t.name&&this.registry.has(t.name)&&this.registry.delete(t.name)},G.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:c(i.formErrors),inputErrors:i.inputErrors||{}}),i},G.prototype.reset=function(t,r){void 0===r&&(r={}),this.resetValidation(t),this.setValues(t,r)},G.prototype.resetValidation=function(t){var r=this.registry.get(t);r.hideErrors(t),r.namedErrors=[],r.namedFieldErrors={}},G.prototype.setValues=function(t,r){r&&!Array.isArray(r)&&"object"==typeof r&&this.registry.get(t).setValues(Object.assign({},r))},G.prototype.getUploader=function(){return this.options.uploader||!1},G.prototype.getUploadUrl=function(){return this.options.uploadUrl||!1},G.prototype.getFileUrlKey=function(){return this.options.fileUrlKey||"url"},G.prototype.createUpload=function(t,r){return new l(t,r,this.options)},new G}();
|