2020-10-23 14:15:57 +03:00
|
|
|
import t from"is-url";import e from"is-plain-object";import r from"vue";import{Model as i,Prop as o,Provide as s,Watch as a,Component as n,Inject as l}from"vue-property-decorator";function u(t,e){if(t===e)return!0;if(!t||!e)return!1;const r=Object.keys(t);if(Object.keys(e).length!==r.length)return!1;if(t instanceof Date&&e instanceof Date)return t.getTime()===e.getTime();if(0===r.length)return t===e;for(let i=0;i<r.length;i++){const o=r[i];if(t[o]!==e[o])return!1}return!0}function d(t){return"string"==typeof t?t.replace(/([_][a-z0-9])/gi,e=>0!==t.indexOf(e)&&"_"!==t[t.indexOf(e)-1]?e.toUpperCase().replace("_",""):e):t}function h(t){return"string"==typeof t&&/^[\^]/.test(t.charAt(0))?[d(t.substr(1)),t.charAt(0)]:[d(t),null]}function c(t){return t?"string"==typeof t?[t]:Array.isArray(t)?t:"object"==typeof t?Object.values(t):[]:[]}function p(t,e){return"string"==typeof t?p(t.split("|").filter(t=>t.length),e):Array.isArray(t)?t.map(t=>function(t,e){if("function"==typeof t)return[t,[]];if(Array.isArray(t)&&t.length){t=t.slice();const[r,i]=h(t.shift());if("string"==typeof r&&Object.prototype.hasOwnProperty.call(e,r))return[e[r],t,r,i];if("function"==typeof r)return[r,t,r,i]}if("string"==typeof t){const r=t.split(":"),[i,o]=h(r.shift());if(Object.prototype.hasOwnProperty.call(e,i))return[e[i],r.length?r.join(":").split(","):[],i,o];throw new Error("Unknown validation rule "+t)}return!1}(t,e)).filter(t=>!!t):[]}function f(t){switch(typeof t){case"symbol":case"number":case"string":case"boolean":case"undefined":return!0;default:return null===t}}function m(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function v(t,e){const r=e.split(".");let i=t;for(const t in r){const e=r[t].match(/(.+)\[(\d+)\]$/);if(void 0===i)return null;if(e){if(i=i[e[1]],void 0===i)return null;i=i[e[2]]}else i=i[r[t]]}return i}var g={accepted:({value:t})=>Promise.resolve(["yes","on","1",1,!0,"true"].includes(t)),after({value:t},e=!1){const r=!1!==e?Date.parse(e):Date.now(),i=t instanceof Date?t.getTime():Date.parse(t);return Promise.resolve(!isNaN(i)&&i>r)},alpha({value:t},e="default"){const r={default:/^[a-zA-ZÀ-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z]+$/},i=m(r,e)?e:"default";return Promise.resolve(r[i].test(t))},alphanumeric({value:t},e="default"){const r={default:/^[a-zA-Z0-9À-ÖØ-öø-ÿ]+$/,latin:/^[a-zA-Z0-9]+$/},i=m(r,e)?e:"default";return Promise.resolve(r[i].test(t))},before({value:t},e=!1){const r=!1!==e?Date.parse(e):Date.now(),i=t instanceof Date?t.getTime():Date.parse(t);return Promise.resolve(!isNaN(i)&&i<r)},between:({value:t},e=0,r=10,i)=>Promise.resolve(null!==e&&null!==r&&!isNaN(e)&&!isNaN(r)&&(!isNaN(Number(t))&&"length"!==i||"value"===i?(t=Number(t),e=Number(e),r=Number(r),t>e&&t<r):("string"==typeof t||"length"===i)&&(t=isNaN(Number(t))?t:t.toString()).length>e&&t.length<r)),confirm:({value:t,getFormValues:e,name:r},i)=>Promise.resolve((()=>{let o=i;return o||(o=/_confirm$/.test(r)?r.substr(0,r.length-8):r+"_confirm"),e()[o]===t})()),date:({value:t},e=!1)=>Promise.resolve(e?function(t){const e=`^${r=t,r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}$`;var r;const i={MM:"(0[1-9]|1[012])",M:"([1-9]|1[012])",DD:"([012][1-9]|3[01])",D:"([012]?[1-9]|3[01])",YYYY:"\\d{4}",YY:"\\d{2}"};return new RegExp(Object.keys(i).reduce((t,e)=>t.replace(e,i[e]),e))}(e).test(t):!isNaN(Date.parse(t))),email({value:t}){if(!t)return Promise.resolve(!0);return Promise.resolve(/^(([^<>()\[\].,;:\s@"]+(\.[^<>()\[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/i.test(t))},endsWith:({value:t},...e)=>t?"string"==typeof t?Promise.resolve(0===e.length||e.some(e=>t.endsWith(e))):Promise.resolve(!1):Promise.resolve(!0),in:({value:t},...e)=>Promise.resolve(e.some(e=>"object"==typeof e?u(e,t):e===t)),matches:({value:t},...e)=>Promise.resolve(!!e.find(e=>("string"==typeof e&&"/"===e.substr(0,1)&&"/"===e.substr(-1)&&(e=new RegExp(e.substr(1,e.length-2))),e instanceof RegExp?e.test(t):e===t))),min:({value:t},e=1,r)=>Promise.resolve(Array.isArray(t)?(e=isNaN(e)?e:Number(e),t.length>=e):!isNaN(t)&&"length"!==r||"value"===r?(t=isNaN(t)?t:Number(t))>=e:("s
|
2020-10-19 14:38:35 +03:00
|
|
|
/*! *****************************************************************************
|
|
|
|
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-23 14:15:57 +03:00
|
|
|
***************************************************************************** */function E(t,e){var r={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(r[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(t);o<i.length;o++)e.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(t,i[o])&&(r[i[o]]=t[i[o]])}return r}function $(t,e,r,i){var o,s=arguments.length,a=s<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,r,i);else for(var n=t.length-1;n>=0;n--)(o=t[n])&&(a=(s<3?o(a):s>3?o(e,r,a):o(e,r))||a);return s>3&&a&&Object.defineProperty(e,r,a),a}class V{constructor(t){this.registry=new Map,this.ctx=t}add(t,e){this.registry.set(t,e)}remove(t){this.registry.delete(t);const e=this.ctx.proxy,r=t,i=(e[r],E(e,["symbol"==typeof r?r:r+""]));this.ctx.proxy=i}has(t){return this.registry.has(t)}hasNested(t){for(const e of this.registry.keys())if(e===t||e.includes(t+"."))return!0;return!1}get(t){return this.registry.get(t)}getNested(t){const e=new Map;for(const r of this.registry.keys())(r===t||r.includes(t+"."))&&e.set(r,this.registry.get(r));return e}map(t){const e={};return this.registry.forEach((r,i)=>Object.assign(e,{[i]:t(r,i)})),e}forEach(t){this.registry.forEach((e,r)=>{t(e,r)})}keys(){return Array.from(this.registry.keys())}register(t,e){if(this.registry.has(t))return;this.registry.set(t,e);const r=m(e.$options.propsData||{},"formularioValue"),i=m(e.$options.propsData||{},"value");!r&&this.ctx.hasInitialValue&&void 0!==v(this.ctx.initialValues,t)?e.context.model=v(this.ctx.initialValues,t):!r&&!i||u(e.proxy,v(this.ctx.initialValues,t))||this.ctx.setFieldValue(t,e.proxy),this.ctx.childrenShouldShowErrors&&(e.formShouldShowErrors=!0)}reduce(t,e){return this.registry.forEach((r,i)=>{e=t(e,r,i)}),e}}class x{constructor(t=[]){this.observers=[],this.observers=t}add(t){this.observers.some(e=>e.callback===t.callback)||this.observers.push(t)}remove(t){this.observers=this.observers.filter(e=>e.callback!==t)}filter(t){return new x(this.observers.filter(t))}some(t){return this.observers.some(t)}observe(t){this.observers.forEach(e=>{"form"===e.type?e.callback(t):e.field&&!Array.isArray(t)&&m(t,e.field)&&e.callback(t[e.field])})}}let F=class extends r{constructor(){super(...arguments),this.path="",this.proxy={},this.registry=new V(this),this.errorObserverRegistry=new x,this.localFormErrors=[],this.localFieldErrors={}}get mergedFormErrors(){return[...this.formErrors,...this.localFormErrors]}get mergedFieldErrors(){return b(this.errors||{},this.localFieldErrors)}get hasModel(){return m(this.$options.propsData||{},"formularioValue")}get hasInitialValue(){return this.formularioValue&&"object"==typeof this.formularioValue}get initialValues(){return this.hasModel&&"object"==typeof this.formularioValue?Object.assign({},this.formularioValue):{}}onFormularioValueChanged(t){this.hasModel&&t&&"object"==typeof t&&this.setValues(t)}onMergedFormErrorsChanged(t){this.errorObserverRegistry.filter(t=>"form"===t.type).observe(t)}onMergedFieldErrorsChanged(t){this.errorObserverRegistry.filter(t=>"input"===t.type).observe(t)}created(){this.initProxy()}getFormValues(){return this.proxy}onFormSubmit(){return this.hasValidationErrors().then(t=>t?void 0:function t(e){if("object"!=typeof e)return e;const r=Array.isArray(e)?[]:{};for(const i in e)Object.prototype.hasOwnProperty.call(e,i)&&(f(e[i])?r[i]=e[i]:r[i]=t(e[i]));return r}(this.proxy)).then(t=>{void 0!==t?this.$emit("submit",t):this.$emit("error")})}onFormularioFieldValidation(t){this.$emit("validation",t)}addErrorObserver(t){this.errorObserverRegistry.add(t),"form"===t.type?t.callback(this.mergedFormErrors):t.field&&m(this.mergedFieldErrors,t.field)&&t.callback(this.mergedFieldErrors[t.field])}removeErrorObserver(t){this.errorObserverRegistry.remove(t)}register(t,e){this.registry.register(t,e)}deregister(t){this.registry.remove(t)}initProxy(){this.hasInitialValue&&(this.proxy=this.initialValues)}setValues(t){const e=Array.
|