1 |
- var Vuelidate=function(e,t){"use strict";function r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function n(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function u(e){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return Object.keys(e).reduce(((n,a)=>(r.includes(a)||(n[a]=t.unref(e[a])),n)),{})}function l(e){return"function"==typeof e}function o(e,t,r){let n=e;const a=t.split(".");for(let e=0;e<a.length;e++){if(!n[a[e]])return r;n=n[a[e]]}return n}function s(e,r,n){return t.computed((()=>e.some((e=>o(r,e,{[n]:!1})[n]))))}function i(e,r,n){return t.computed((()=>e.reduce(((e,t)=>{const a=o(r,t,{[n]:!1})[n]||[];return e.concat(a)}),[])))}function c(e,r,n,a){return e.call(a,t.unref(r),t.unref(n),a)}function $(e){return void 0!==e.$valid?!e.$valid:!e}function d(e,r,n,a,o,s,i,d,v,f,p){const m=t.ref(!1),h=e.$params||{},y=t.ref(null);let g,b;e.$async?({$invalid:g,$unwatch:b}=function(e,r,n,a,u,l,o){let{$lazy:s,$rewardEarly:i}=u,d=arguments.length>7&&void 0!==arguments[7]?arguments[7]:[],v=arguments.length>8?arguments[8]:void 0,f=arguments.length>9?arguments[9]:void 0,p=arguments.length>10?arguments[10]:void 0;const m=t.ref(!!a.value),h=t.ref(0);n.value=!1;const y=t.watch([r,a].concat(d,p),(()=>{if(s&&!a.value||i&&!f.value&&!n.value)return;let t;try{t=c(e,r,v,o)}catch(e){t=Promise.reject(e)}h.value++,n.value=!!h.value,m.value=!1,Promise.resolve(t).then((e=>{h.value--,n.value=!!h.value,l.value=e,m.value=$(e)})).catch((e=>{h.value--,n.value=!!h.value,l.value=e,m.value=!0}))}),{immediate:!0,deep:"object"==typeof r});return{$invalid:m,$unwatch:y}}(e.$validator,r,m,n,a,y,o,e.$watchTargets,v,f,p)):({$invalid:g,$unwatch:b}=function(e,r,n,a,u,l,o,s){let{$lazy:i,$rewardEarly:d}=a;return{$unwatch:()=>({}),$invalid:t.computed((()=>{if(i&&!n.value||d&&!s.value)return!1;let t=!0;try{const n=c(e,r,o,l);u.value=n,t=$(n)}catch(e){u.value=e}return t}))}}(e.$validator,r,n,a,y,o,v,f));const O=e.$message;return{$message:l(O)?t.computed((()=>O(u({$pending:m,$invalid:g,$params:u(h),$model:r,$response:y,$validator:s,$propertyPath:d,$property:i})))):O||"",$params:h,$pending:m,$invalid:g,$response:y,$unwatch:b}}const v="__root";function f(e){let{validations:r,state:a,key:u,parentKey:o,childResults:c,resultsCache:$,globalConfig:p={},instance:m,externalResults:h}=e;const y=o?`${o}.${u}`:u,{rules:g,nestedValidators:b,config:O,validationGroups:w}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const r=t.unref(e),n=Object.keys(r),a={},u={},o={};let s=null;return n.forEach((e=>{const t=r[e];switch(!0){case l(t.$validator):a[e]=t;break;case l(t):a[e]={$validator:t};break;case"$validationGroups"===e:s=t;break;case e.startsWith("$"):o[e]=t;break;default:u[e]=t}})),{rules:a,nestedValidators:u,config:o,validationGroups:s}}(r),E=n(n({},p),O),R=u?t.computed((()=>{const e=t.unref(a);return e?t.unref(e[u]):void 0})):a,j=n({},t.unref(h)||{}),C=t.computed((()=>{const e=t.unref(h);return u?e?t.unref(e[u]):void 0:e})),P=function(e,r,n,a,u,l,o,s,i){const c=Object.keys(e),$=a.get(u,e),v=t.ref(!1),f=t.ref(!1),p=t.ref(0);if($){if(!$.$partial)return $;$.$unwatch(),v.value=$.$dirty.value}const m={$dirty:v,$path:u,$touch:()=>{v.value||(v.value=!0)},$reset:()=>{v.value&&(v.value=!1)},$commit:()=>{}};return c.length?(c.forEach((t=>{m[t]=d(e[t],r,m.$dirty,l,o,t,n,u,i,f,p)})),m.$externalResults=t.computed((()=>s.value?[].concat(s.value).map(((e,t)=>({$propertyPath:u,$property:n,$validator:"$externalResults",$uid:`${u}-externalResult-${t}`,$message:e,$params:{},$response:null,$pending:!1}))):[])),m.$invalid=t.computed((()=>{const e=c.some((e=>t.unref(m[e].$invalid)));return f.value=e,!!m.$externalResults.value.length||e})),m.$pending=t.computed((()=>c.some((e=>t.unref(m[e].$pending))))),m.$error=t.computed((()=>!!m.$dirty.value&&(m.$pending.value||m.$invalid.value))),m.$silentErrors=t.computed((()=>c.filter((e=>t.unref(m[e].$invalid))).map((e=>{const r=m[e];return t.reactive({$propertyPath:u,$property:n,$validator:e,$uid:`${u}-${e}`,$message:r.$message,$params:r.$params,$response:r.$response,$pending:r.$pending})})).concat(m.$externalResults.value))),m.$errors=t.computed((()=>m.$dirty.value?m.$silentErrors.value:[])),m.$unwatch=()=>c.forEach((e=>{m[e].$unwatch()})),m.$commit=()=>{f.value=!0,p.value=Date.now()},a.set(u,e,m),m):($&&a.set(u,e,m),m)}(g,R,u,$,y,E,m,C,a),_=function(e,t,r,n,a,u,l){const o=Object.keys(e);return o.length?o.reduce(((o,s)=>(o[s]=f({validations:e[s],state:t,key:s,parentKey:r,resultsCache:n,globalConfig:a,instance:u,externalResults:l}),o)),{}):{}}(b,R,y,$,E,m,C),k={};w&&Object.entries(w).forEach((e=>{let[t,r]=e;k[t]={$invalid:s(r,_,"$invalid"),$error:s(r,_,"$error"),$pending:s(r,_,"$pending"),$errors:i(r,_,"$errors"),$silentErrors:i(r,_,"$silentErrors")}}));const{$dirty:L,$errors:x,$invalid:V,$anyDirty:D,$error:I,$pending:T,$touch:A,$reset:N,$silentErrors:F,$commit:G}=function(e,r,n){const a=t.computed((()=>[r,n].filter((e=>e)).reduce(((e,r)=>e.concat(Object.values(t.unref(r)))),[]))),u=t.computed({get:()=>e.$dirty.value||!!a.value.length&&a.value.every((e=>e.$dirty)),set(t){e.$dirty.value=t}}),l=t.computed((()=>{const r=t.unref(e.$silentErrors)||[],n=a.value.filter((e=>(t.unref(e).$silentErrors||[]).length)).reduce(((e,t)=>e.concat(...t.$silentErrors)),[]);return r.concat(n)})),o=t.computed((()=>{const r=t.unref(e.$errors)||[],n=a.value.filter((e=>(t.unref(e).$errors||[]).length)).reduce(((e,t)=>e.concat(...t.$errors)),[]);return r.concat(n)})),s=t.computed((()=>a.value.some((e=>e.$invalid))||t.unref(e.$invalid)||!1)),i=t.computed((()=>a.value.some((e=>t.unref(e.$pending)))||t.unref(e.$pending)||!1)),c=t.computed((()=>a.value.some((e=>e.$dirty))||a.value.some((e=>e.$anyDirty))||u.value)),$=t.computed((()=>!!u.value&&(i.value||s.value))),d=()=>{e.$touch(),a.value.forEach((e=>{e.$touch()}))};return a.value.length&&a.value.every((e=>e.$dirty))&&d(),{$dirty:u,$errors:o,$invalid:s,$anyDirty:c,$error:$,$pending:i,$touch:d,$reset:()=>{e.$reset(),a.value.forEach((e=>{e.$reset()}))},$silentErrors:l,$commit:()=>{e.$commit(),a.value.forEach((e=>{e.$commit()}))}}}(P,_,c),S=u?t.computed({get:()=>t.unref(R),set:e=>{L.value=!0;const r=t.unref(a),n=t.unref(h);n&&(n[u]=j[u]),t.isRef(r[u])?r[u].value=e:r[u]=e}}):null;return u&&E.$autoDirty&&t.watch(R,(()=>{L.value||A();const e=t.unref(h);e&&(e[u]=j[u])}),{flush:"sync"}),t.reactive(n(n(n({},P),{},{$model:S,$dirty:L,$error:I,$errors:x,$invalid:V,$anyDirty:D,$pending:T,$touch:A,$reset:N,$path:y||v,$silentErrors:F,$validate:async function(){return A(),E.$rewardEarly&&(G(),await t.nextTick()),await t.nextTick(),new Promise((e=>{if(!T.value)return e(!V.value);const r=t.watch(T,(()=>{e(!V.value),r()}))}))},$commit:G},c&&{$getResultsForChild:function(e){return(c.value||{})[e]},$clearExternalResults:function(){t.isRef(h)?h.value=j:0===Object.keys(j).length?Object.keys(h).forEach((e=>{delete h[e]})):Object.assign(h,j)},$validationGroups:k}),_))}class p{constructor(){this.storage=new Map}set(e,t,r){this.storage.set(e,{rules:t,result:r})}checkRulesValidity(e,r,n){const a=Object.keys(n),u=Object.keys(r);if(u.length!==a.length)return!1;return!!u.every((e=>a.includes(e)))&&u.every((e=>!r[e].$params||Object.keys(r[e].$params).every((a=>t.unref(n[e].$params[a])===t.unref(r[e].$params[a])))))}get(e,t){const r=this.storage.get(e);if(!r)return;const{rules:n,result:a}=r,u=this.checkRulesValidity(e,t,n),l=a.$unwatch?a.$unwatch:()=>({});return u?a:{$dirty:a.$dirty,$partial:!0,$unwatch:l}}}const m={COLLECT_ALL:!0,COLLECT_NONE:!1},h=Symbol("vuelidate#injectChildResults"),y=Symbol("vuelidate#removeChildResults");function g(e){return new Proxy(e,{get:(e,r)=>"object"==typeof e[r]?g(e[r]):t.computed((()=>e[r]))})}let b=0;function O(e,r){var a;let u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};1===arguments.length&&(u=e,e=void 0,r=void 0);let{$registerAs:o,$scope:s=m.COLLECT_ALL,$stopPropagation:i,$externalResults:c,currentVueInstance:$}=u;const d=$||(null===(a=t.getCurrentInstance())||void 0===a?void 0:a.proxy),v=d?d.$options:{};o||(b+=1,o=`_vuelidate_${b}`);const O=t.ref({}),w=new p,{childResults:E,sendValidationResultsToParent:R,removeValidationResultsFromParent:j}=d?function(e){let{$scope:r,instance:n}=e;const a={},u=t.ref([]),l=t.computed((()=>u.value.reduce(((e,r)=>(e[r]=t.unref(a[r]),e)),{})));n.__vuelidateInjectInstances=[].concat(n.__vuelidateInjectInstances||[],(function(e,t){let{$registerAs:n,$scope:l,$stopPropagation:o}=t;o||r===m.COLLECT_NONE||l===m.COLLECT_NONE||r!==m.COLLECT_ALL&&r!==l||(a[n]=e,u.value.push(n))})),n.__vuelidateRemoveInstances=[].concat(n.__vuelidateRemoveInstances||[],(function(e){u.value=u.value.filter((t=>t!==e)),delete a[e]}));const o=t.inject(h,[]);t.provide(h,n.__vuelidateInjectInstances);const s=t.inject(y,[]);return t.provide(y,n.__vuelidateRemoveInstances),{childResults:l,sendValidationResultsToParent:o,removeValidationResultsFromParent:s}}({$scope:s,instance:d}):{childResults:t.ref({})};if(!e&&v.validations){const e=v.validations;r=t.ref({}),t.onBeforeMount((()=>{r.value=d,t.watch((()=>l(e)?e.call(r.value,new g(r.value)):e),(e=>{O.value=f({validations:e,state:r,childResults:E,resultsCache:w,globalConfig:u,instance:d,externalResults:c||d.vuelidateExternalResults})}),{immediate:!0})})),u=v.validationsConfig||u}else{const n=t.isRef(e)||(C=e,t.isReactive(C)||t.isReadonly(C))?e:t.reactive(e||{});t.watch(n,(e=>{O.value=f({validations:e,state:r,childResults:E,resultsCache:w,globalConfig:u,instance:null!=d?d:{},externalResults:c})}),{immediate:!0})}var C;return d&&(R.forEach((e=>e(O,{$registerAs:o,$scope:s,$stopPropagation:i}))),t.onBeforeUnmount((()=>j.forEach((e=>e(o)))))),t.computed((()=>n(n({},t.unref(O.value)),E.value)))}return e.CollectFlag=m,e.default=O,e.useVuelidate=O,Object.defineProperty(e,"__esModule",{value:!0}),e}({},VueDemi);
|