1
0
mirror of synced 2024-11-29 08:36:12 +03:00
vue-formulario/dist/formulate.esm.js

2 lines
45 KiB
JavaScript
Raw Normal View History

2020-05-18 16:58:56 +03:00
import t from"is-url";import e from"nanoid/non-secure";import r from"is-plain-object";import{en as i}from"@braid/vue-formulate-i18n";var o=function(t,e){return{classification:t,component:"FormulateInput"+(e||t[0].toUpperCase()+t.substr(1))}},n=Object.assign({},["text","email","number","color","date","hidden","month","password","search","tel","time","url","week","datetime-local"].reduce((function(t,e){var r;return Object.assign({},t,((r={})[e]=o("text"),r))}),{}),{range:o("slider"),textarea:o("textarea","TextArea"),checkbox:o("box"),radio:o("box"),submit:o("button"),button:o("button"),select:o("select"),file:o("file"),image:o("file"),group:o("group")}),s=function(t,e,r){void 0===r&&(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)};function a(t,e){var r={};for(var i in t)r[i]=e(i,t[i]);return r}function l(t,e){if(t===e)return!0;if(!t||!e)return!1;var r=Object.keys(t),i=Object.keys(e),o=r.length;if(i.length!==o)return!1;for(var n=0;n<o;n++){var s=r[n];if(t[s]!==e[s])return!1}return!0}function u(t){return"string"==typeof t?t.replace(/([_][a-z0-9])/gi,(function(e){return 0!==t.indexOf(e)&&"_"!==t[t.indexOf(e)-1]?e.toUpperCase().replace("_",""):e})):t}function c(t){return t?"string"==typeof t?[t]:Array.isArray(t)?t:"object"==typeof t?Object.values(t):[]:[]}function h(t,e){return"string"==typeof t?h(t.split("|"),e):Array.isArray(t)?t.map((function(t){return function(t,e){if("function"==typeof t)return[t,[]];if(Array.isArray(t)&&t.length){var r=d((t=t.map((function(t){return t}))).shift()),i=r[0],o=r[1];if("string"==typeof i&&e.hasOwnProperty(i))return[e[i],t,i,o];if("function"==typeof i)return[i,t,i,o]}if("string"==typeof t){var n=t.split(":"),s=d(n.shift()),a=s[0],l=s[1];if(e.hasOwnProperty(a))return[e[a],n.length?n.join(":").split(","):[],a,l];throw new Error("Unknown validation rule "+t)}return!1}(t,e)})).filter((function(t){return!!t})):[]}function d(t){return/^[\^]/.test(t.charAt(0))?[u(t.substr(1)),t.charAt(0)]:[u(t),null]}function f(t){switch(typeof t){case"symbol":case"number":case"string":case"boolean":case"undefined":return!0;default:return null===t}}function p(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function m(t,e){return Object.defineProperty(t,"__id",Object.assign(Object.create(null),{value:e||Symbol("uuid")}))}s.prototype.rehydrateFileList=function(t){var e=this,r=t.reduce((function(t,r){var i=r[e.options?e.options.fileUrlKey:"url"],o=!(!i||-1===i.lastIndexOf("."))&&i.substr(i.lastIndexOf(".")+1),n=e.options.mimes[o]||!1;return t.push(Object.assign({},r,i?{name:i.substr(i.lastIndexOf("/")+1||0),type:r.type?r.type:n,previewData:i}:{})),t}),[]);this.results=t,this.addFileList(r)},s.prototype.addFileList=function(t){for(var r=this,i=function(i){var o=t[i],n=e();r.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(r),previewData:o.previewData||!1})},o=0;o<t.length;o++)i(o)},s.prototype.hasUploader=function(){return!!this.context.uploader},s.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)},s.prototype.getUploader=function(){for(var t,e=[],r=arguments.length;r--;)e[r]=arguments[r];if(this.uploaderIsAxios()){var i=new FormData;if(i.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,i,{headers:{"Content-Type":"multipart/form-data"},onUploadProgress:function(t){e[1](Math.round(100*t.loaded/t.total))}}).then((function(t){return t.data})).catch((function(t){return e[2](t)}))}return(t=this.context).uploader.apply(t,e)},s.prototype.upload=function(){var t=this;ret