2 lines
34 KiB
JavaScript
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).uplo
|