1
0
mirror of synced 2024-11-23 05:46:05 +03:00
vue-formulario/dist/formulate.esm.js

2 lines
37 KiB
JavaScript
Raw Normal View History

import t from"is-url";import e from"nanoid";import n from"is-plain-object";var r={text:{classification:"text",component:"FormulateInputText"},email:{classification:"text",component:"FormulateInputText"},number:{classification:"text",component:"FormulateInputText"},color:{classification:"text",component:"FormulateInputText"},date:{classification:"text",component:"FormulateInputText"},hidden:{classification:"text",component:"FormulateInputText"},month:{classification:"text",component:"FormulateInputText"},password:{classification:"text",component:"FormulateInputText"},search:{classification:"text",component:"FormulateInputText"},tel:{classification:"text",component:"FormulateInputText"},time:{classification:"text",component:"FormulateInputText"},url:{classification:"text",component:"FormulateInputText"},week:{classification:"text",component:"FormulateInputText"},"datetime-local":{classification:"text",component:"FormulateInputText"},range:{classification:"slider",component:"FormulateInputSlider"},textarea:{classification:"textarea",component:"FormulateInputTextArea"},checkbox:{classification:"box",component:"FormulateInputBox"},radio:{classification:"box",component:"FormulateInputBox"},submit:{classification:"button",component:"FormulateInputButton"},button:{classification:"button",component:"FormulateInputButton"},select:{classification:"select",component:"FormulateInputSelect"},file:{classification:"file",component:"FormulateInputFile"},image:{classification:"file",component:"FormulateInputFile"}},o=function(t,e,n){this.input=t,this.fileList=t.files,this.files=[],this.options=n,this.addFileList(this.fileList),this.context=e};function i(t,e){var n={};for(var r in t)n[r]=e(r,t[r]);return n}function a(t,e){if(t===e)return!0;if(!t||!e)return!1;var n=Object.keys(t),r=Object.keys(e),o=n.length;if(r.length!==o)return!1;for(var i=0;i<o;i++){var a=n[i];if(t[a]!==e[a])return!1}return!0}function s(t){return t?"string"==typeof t?[t]:Array.isArray(t)?t:"object"==typeof t?Object.values(t):[]:[]}function l(t){return"string"==typeof t?t[0].toUpperCase()+t.substr(1):t}function u(t,e){return"string"==typeof t?u(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("string"==typeof(t=t.map((function(t){return 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 n=t.split(":"),r=n.shift();if(e.hasOwnProperty(r))return[e[r],n.length?n.join(":").split(","):[]];throw new Error("Unknown validation rule "+t)}return!1}(t,e)})).filter((function(t){return!!t})):[]}function c(t){switch(typeof t){case"symbol":case"number":case"string":case"boolean":case"undefined":return!0;default:return null===t}}o.prototype.addFileList=function(t){for(var n=this,r=function(r){var o=t[r],i=e();n.files.push({progress:!1,error:!1,complete:!1,justFinished:!1,name:o.name||"file-upload",file:o,uuid:i,path:!1,removeFile:function(){this.removeFile(i)}.bind(n),previewData:!1})},o=0;o<t.length;o++)r(o)},o.prototype.hasUploader=function(){return!!this.context.uploader},o.prototype.uploaderIsAxios=function(){return!(!this.hasUploader||"function"!=typeof this.hasUploader.request||"function"!=typeof this.hasUploader.get||"function"!=typeof this.hasUploader.delete||"function"!=typeof this.hasUploader.post)},o.prototype.getUploader=function(){for(var t,e=[],n=arguments.length;n--;)e[n]=arguments[n];if(this.uploaderIsAxios()){var r=new FormData;return r.append(this.context.name||"file",e[0]),this.uploader.post(this.context.uploadUrl,r,{headers:{"Content-Type":"multipart/form-data"},onUploadProgress:function(t){e[1](Math.round(100*t.loaded/t.total))}}).catch((function(t){return e[2](t)}))}return(t=this.context).uploader.apply(t,e)},o.prototype.upload=function(){var t=this;return new Promise((function(e,n){if(!t.hasUploader)return n(new Error("No uploader has been defined"));Promise.all(t.files.map((function(e){return e.path?Promise.resolve(e.path):t.getUploader(e.file,(function(n){e.progress=n,n>=100&&(e.complete||(e.