1
0
mirror of synced 2024-11-22 21:36:04 +03:00
vue-formulario/dist/formulate.min.js

16 lines
46 KiB
JavaScript
Raw Normal View History

var VueFormulate=function(){"use strict";var t=function(t,e){return{classification:t,component:"FormulateInput"+(e||t[0].toUpperCase()+t.substr(1))}},e=Object.assign({},["text","email","number","color","date","hidden","month","password","search","tel","time","url","week","datetime-local"].reduce((function(e,r){var o;return Object.assign({},e,((o={})[r]=t("text"),o))}),{}),{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")}),r=function(t){if("string"!=typeof t)return!1;var e=t.match(o);if(!e)return!1;var r=e[1];if(!r)return!1;if(n.test(r)||i.test(r))return!0;return!1},o=/^(?:\w+:)?\/\/(\S+)$/,n=/^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/,i=/^[^\s\.]+\.\S{2,}$/;for(var a="-_",s=36;s--;)a+=s.toString(36);for(s=36;s---10;)a+=s.toString(36).toUpperCase();var l=function(t){var e="";for(s=t||21;s--;)e+=a[64*Math.random()|0];return e},u=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 c(t,e){var r={};for(var o in t)r[o]=e(o,t[o]);return r}function d(t,e){if(t===e)return!0;if(!t||!e)return!1;var r=Object.keys(t),o=Object.keys(e),n=r.length;if(o.length!==n)return!1;for(var i=0;i<n;i++){var a=r[i];if(t[a]!==e[a])return!1}return!0}function p(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 f(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){if((t=t.map((function(t){return t})))[0]=p(t[0]),"string"==typeof t[0]&&e.hasOwnProperty(t[0]))return[e[t.shift()],t];if("function"==typeof t[0])return[t.shift(),t]}if("string"==typeof t){var r=t.split(":"),o=p(r.shift());if(e.hasOwnProperty(o))return[e[o],r.length?r.join(":").split(","):[]];throw new Error("Unknown validation rule "+t)}return!1}(t,e)})).filter((function(t){return!!t})):[]}function m(t){switch(typeof t){case"symbol":case"number":case"string":case"boolean":case"undefined":return!0;default:return null===t}}u.prototype.rehydrateFileList=function(t){var e=this,r=t.reduce((function(t,r){var o=r[e.options?e.options.fileUrlKey:"url"],n=!(!o||-1===o.lastIndexOf("."))&&o.substr(o.lastIndexOf(".")+1),i=e.options.mimes[n]||!1;return t.push(Object.assign({},r,o?{name:o.substr(o.lastIndexOf("/")+1||0),type:r.type?r.type:i,previewData:o}:{})),t}),[]);this.results=t,this.addFileList(r)},u.prototype.addFileList=function(t){for(var e=this,r=function(r){var o=t[r],n=l();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++)r(o)},u.prototype.hasUploader=function(){return!!this.context.uploader},u.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)},u.prototype.getUploader=function(){for(var t,e=[],r=arguments.length;r--;)e[r]=arguments[r];if(this.uploaderIsAxios()){var o=new FormData;if(o.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,o,{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)},u.prototype.upload=function(){var t=t
/*!
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
function g(t){return!0==(null!=(e=t)&&"object"==typeof e&&!1===Array.isArray(e))&&"[object Object]"===Object.prototype.toString.call(t);
/*!
* isobject <https://github.com/jonschlinkert/isobject>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
var e}function x(t){var e,r;return!1!==g(t)&&("function"==typeof(e=t.constructor)&&(!1!==g(r=e.prototype)&&!1!==r.hasOwnProperty("isPrototypeOf")))}function w(t){return"string"==typeof t?t[0].toUpperCase()+t.substr(1):t}var _={accepted:function(t){return"Please accept the "+t.name+"."},after:function(t){var e=t.name,r=t.args;return Array.isArray(r)&&r.length?w(e)+" must be after "+r[0]+".":w(e)+" must be a later date."},alpha:function(t){return w(t.name)+" can only contain alphabetical characters."},alphanumeric:function(t){return w(t.name)+" can only contain letters and numbers."},before:function(t){var e=t.name,r=t.args;return Array.isArray(r)&&r.length?w(e)+" must be before "+r[0]+".":w(e)+" must be an earlier date."},between:function(t){var e=t.name,r=t.value,o=t.args;return isNaN(r)?w(e)+" must be between "+o[0]+" and "+o[1]+" characters long.":w(e)+" must be between "+o[0]+" and "+o[1]+"."},confirm:function(t){var e=t.name;return t.args,w(e)+" does not match."},date:function(t){var e=t.name,r=t.args;return Array.isArray(r)&&r.length?w(e)+" is not a valid, please use the format "+r[0]:w(e)+" is not a valid date."},default:function(t){return t.name,"This field isnt valid."},email:function(t){t.name;var e=t.value;return e?"“"+e+"” is not a valid email address.":"Please enter a valid email address."},endsWith:function(t){t.name;var e=t.value;return e?"“"+e+"” doesnt end with a valid value.":"This field doesnt end with a valid value."},in:function(t){var e=t.name,r=t.value;return"string"==typeof r&&r?"“"+w(r)+"” is not an allowed "+e+".":"This is not an allowed "+e+"."},matches:function(t){return w(t.name)+" is not an allowed value."},max:function(t){var e=t.name,r=t.value,o=t.args;if(Array.isArray(r))return"You may only select "+o[0]+" "+e+".";var n=!(!Array.isArray(o)||!o[1])&&o[1];return!isNaN(r)&&"length"!==n||"value"===n?w(e)+" must be less than or equal to "+o[0]+".":w(e)+" must be less than or equal to "+o[0]+" characters long."},mime:function(t){var e=t.name,r=t.args;return w(e)+" must be of the the type: "+(r[0]||"No file formats allowed.")},min:function(t){var e=t.name,r=t.value,o=t.args;if(Array.isArray(r))return"You must select at least "+o[0]+" "+e+".";var n=!(!Array.isArray(o)||!o[1])&&o[1];return!isNaN(r)&&"length"!==n||"value"===n?w(e)+" must be more than "+o[0]+".":w(e)+" must be more than "+o[0]+" characters long."},not:function(t){var e=t.name;return"“"+t.value+"” is not an allowed "+e+"."},number:function(t){return w(t.name)+" must be a number."},required:function(t){return w(t.name)+" is required."},startsWith:function(t){t.name;var e=t.value;return e?"“"+e+"” doesnt start with a valid value.":"This field doesnt start with a valid value."},url:function(t){return t.name,"Please include a valid url."}};function F(t){var e;t.extend({locales:(e={},e.en=_,e)})}function E(t,e,r,o){return new Promise((function(r,n){var i=(o.fauxUploaderDuration||2e3)*(.5+Math.random()),a=performance.now(),s=function(){return setTimeout((function(){var o=performance.now()-a,n=Math.min(100,Math.round(o/i*100));if(e(n),n>=100)return r({url:"http://via.placeholder.com/350x150.png",name:t.name});s()}),20)};s()}))}var P={context:function(){return A.call(this,Object.assign({},{type:this.type,value:this.value,name:this.nameOrFallback,classification:this.classification,component:this.component,id:this.id||this.defaultId,hasLabel:this.label&&"button"!==this.classification,label:this.label,labelPosition:this.logicalLabelPosition,attributes:this.elementAttributes,performValidation:this.performValidation.bind(this),blurHandler:V.bind(this),imageBehavior:this.imageBehavior,uploadUrl:this.mergedUploadUrl,uploader:this.uploader||this.$formulate.getUploader(),uploadBehavior:this.uploadBehavior,preventWindowDrops:this.preventWindowDrops,hasValidationErrors:this.hasValidationErrors},this.typeContext))},nameOrFallback:function(){if(!0===this.name&&"button"!==this.classification)return this.type+"_"+this.elementAttributes.id;if(!1===this.name||"button"===this.classification&&!0===this.name)return!1;return th