2020-10-19 14:38:35 +03:00
|
|
|
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("is-url"),require("nanoid/non-secure"),require("is-plain-object"),require("vue"),require("vue-property-decorator")):"function"==typeof define&&define.amd?define(["is-url","nanoid/non-secure","is-plain-object","vue","vue-property-decorator"],t):(e=e||self).Formulario=t(e.isUrl,e.nanoid,e.isPlainObject,e.Vue,e.vuePropertyDecorator)}(this,(function(e,t,r,i,o){"use strict";e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e,t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t,r=r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r,i=i&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i;const s=(e,t)=>({classification:e,component:"FormularioInput"+(t||e[0].toUpperCase()+e.substr(1))});var a=Object.assign(Object.assign({},["text","email","number","color","date","hidden","month","password","search","tel","time","url","week","datetime-local"].reduce((e,t)=>Object.assign(Object.assign({},e),{[t]:s("text")}),{})),{range:s("slider"),textarea:s("textarea","TextArea"),checkbox:s("box"),radio:s("box"),submit:s("button"),button:s("button"),select:s("select"),file:s("file"),image:s("file"),group:s("group")});class n{constructor(e,t={},r={}){this.input=e,this.fileList=e.files,this.files=[],this.options=Object.assign({mimes:{}},r),this.results=!1,this.context=t,Array.isArray(this.fileList)?this.rehydrateFileList(this.fileList):this.addFileList(this.fileList)}rehydrateFileList(e){const t=e.reduce((e,t)=>{const r=t[this.options?this.options.fileUrlKey:"url"],i=!(!r||-1===r.lastIndexOf("."))&&r.substr(r.lastIndexOf(".")+1),o=this.options.mimes[i]||!1;return e.push(Object.assign({},t,r?{name:r.substr(r.lastIndexOf("/")+1||0),type:t.type?t.type:o,previewData:r}:{})),e},[]);this.results=e,this.addFileList(t)}addFileList(e){for(let r=0;r<e.length;r++){const i=e[r],o=t();this.files.push({progress:!1,error:!1,complete:!1,justFinished:!1,name:i.name||"file-upload",file:i,uuid:o,path:!1,removeFile:()=>this.removeFile(o),previewData:i.previewData||!1})}}hasUploader(){return!!this.context.uploader}uploaderIsAxios(){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}getUploader(...e){if(this.uploaderIsAxios()){const t=new FormData;if(t.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,t,{headers:{"Content-Type":"multipart/form-data"},onUploadProgress:t=>{e[1](Math.round(100*t.loaded/t.total))}}).then(e=>e.data).catch(e[2])}return this.context.uploader(...e)}upload(){return this.results?Promise.resolve(this.results):new Promise((e,t)=>{if(!this.hasUploader)return t(new Error("No uploader has been defined"));Promise.all(this.files.map(e=>e.path?Promise.resolve(e.path):this.getUploader(e.file,t=>{e.progress=t,t>=100&&(e.complete||(e.justFinished=!0,setTimeout(()=>{e.justFinished=!1},this.options.uploadJustCompleteDuration)),e.complete=!0)},t=>{e.progress=0,e.error=t,e.complete=!0},this.options))).then(t=>{this.results=t,e(t)}).catch(e=>{throw new Error(e)})})}removeFile(e){if(this.files=this.files.filter(t=>t.uuid!==e),this.context.performValidation(),window&&this.fileList instanceof FileList){const e=new DataTransfer;this.files.map(({file:t})=>e.items.add(t)),this.fileList=e.files,this.input=e}}loadPreviews(){this.files.map(e=>{if(!e.previewData&&window&&window.FileReader&&/^image\//.test(e.file.type)){const t=new FileReader;t.onload=t=>Object.assign(e,{previewData:t.target.result}),t.readAsDataURL(e.file)}})}getFileList(){return this.fileList}getFiles(){return this.files}toString(){const e=this.files.length?this.files.length+" files":"empty";return this.results?JSON.stringify(this.results,null," "):`FileUpload(${e})`}}function l(e,t){if(e===t)return!0;if(!e||!t)return!1;const r=Object
|
|
|
|
/*! *****************************************************************************
|
|
|
|
Copyright (c) Microsoft Corporation.
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
purpose with or without fee is hereby granted.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
***************************************************************************** */
|
2020-10-21 10:58:40 +03:00
|
|
|
function x(e,t){var r={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(r[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++)t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(r[i[o]]=e[i[o]])}return r}function V(e,t,r,i){var o,s=arguments.length,a=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,i);else for(var n=e.length-1;n>=0;n--)(o=e[n])&&(a=(s<3?o(a):s>3?o(t,r,a):o(t,r))||a);return s>3&&a&&Object.defineProperty(t,r,a),a}class O{constructor(e){this.registry=new Map,this.ctx=e}add(e,t){this.registry.set(e,t)}remove(e){this.registry.delete(e);const t=this.ctx.proxy,r=e,i=(t[r],x(t,["symbol"==typeof r?r:r+""]));this.ctx.proxy=i}has(e){return this.registry.has(e)}hasNested(e){for(const t of this.registry.keys())if(t===e||t.includes(e+"."))return!0;return!1}get(e){return this.registry.get(e)}getNested(e){const t=new Map;for(const r of this.registry.keys())(r===e||r.includes(e+"."))&&t.set(r,this.registry.get(r));return t}map(e){const t={};return this.registry.forEach((r,i)=>Object.assign(t,{[i]:e(r,i)})),t}forEach(e){this.registry.forEach((t,r)=>{e(t,r)})}keys(){return Array.from(this.registry.keys())}register(e,t){if(this.registry.has(e))return;this.registry.set(e,t);const r=f(t.$options.propsData,"formularioValue"),i=f(t.$options.propsData,"value");!r&&this.ctx.hasInitialValue&&void 0!==m(this.ctx.initialValues,e)?t.context.model=m(this.ctx.initialValues,e):!r&&!i||l(t.proxy,m(this.ctx.initialValues,e))||this.ctx.setFieldValue(e,t.proxy),this.ctx.childrenShouldShowErrors&&(t.formShouldShowErrors=!0)}reduce(e,t){return this.registry.forEach((r,i)=>{t=e(t,r,i)}),t}}class P{constructor(e){this.form=e}hasValidationErrors(){return this.form.hasValidationErrors()}values(){return new Promise((e,t)=>{const r=this.form,i=[],o=function e(t){if("object"!=typeof t)return t;const r=Array.isArray(t)?[]:{};for(const i in t)Object.prototype.hasOwnProperty.call(t,i)&&(c(t[i])||t[i]instanceof n?r[i]=t[i]:r[i]=e(t[i]));return r}(r.proxy);for(const e in o)Object.prototype.hasOwnProperty.call(o,e)&&"object"==typeof r.proxy[e]&&r.proxy[e]instanceof n&&i.push(r.proxy[e].upload().then(t=>Object.assign(o,{[e]:t})));Promise.all(i).then(()=>e(o)).catch(e=>t(e))})}}let w=class extends i{constructor(){super(...arguments),this.formularioRegister=this.register,this.formularioDeregister=this.deregister,this.formularioSetter=this.setFieldValue,this.getFormValues=()=>this.proxy,this.path="",this.proxy={},this.registry=new O(this),this.childrenShouldShowErrors=!1,this.formShouldShowErrors=!1,this.errorObservers=[],this.namedErrors=[],this.namedFieldErrors={}}formularioFieldValidation(e){this.$emit("validation",e)}removeErrorObserver(e){this.errorObservers=this.errorObservers.filter(t=>t.callback!==e)}get mergedFormErrors(){return this.formErrors.concat(this.namedErrors)}get mergedFieldErrors(){const e={};if(this.errors)for(const t in this.errors)e[t]=d(this.errors[t]);for(const t in this.namedFieldErrors)e[t]=d(this.namedFieldErrors[t]);return e}get hasFormErrorObservers(){return this.errorObservers.some(e=>"form"===e.type)}get hasInitialValue(){return this.formularioValue&&"object"==typeof this.formularioValue||this.values&&"object"==typeof this.values||this.isGrouping&&"object"==typeof this.context.model[this.index]}get isVmodeled(){return!!(f(this.$options.propsData,"formularioValue")&&this._events&&Array.isArray(this._events.input)&&this._events.input.length)}get initialValues(){return f(this.$options.propsData,"formularioValue")&&"object"==typeof this.formularioValue?Object.assign({},this.formularioValue):f(this.$options.propsData,"values")&&"object"==typeof this.values?Object.assign({},this.values):this.isGrouping&&"object"==typeof this.context.model[this.index]?this.context.model[this.index]:{}}onFormularioValueChanged(e){this.isVmodeled&&e&&"object"==typeof e&&this.setValues(e)}onMergedFormErrorsChanged(e){this.errorObserv
|