1
0
mirror of synced 2024-11-26 07:16:02 +03:00
vue-formulario/dist/formulario.min.js

15 lines
35 KiB
JavaScript
Raw Normal View History

2020-10-19 12:32:15 +03:00
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
/*!
* 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[]}}},dat