2 lines
14 KiB
JavaScript
2 lines
14 KiB
JavaScript
import{ar as Ce,as as _e,at as Me,au as Ve,av as Ie,aw as je,ax as We,ay as qe,az as Ne,r as Te,aA as le,J as X,I as Re,s as He,$ as ie,aB as N,aC as de,ae as De,d as $e,aD as ze,k as C,aE as Ke,aF as Ue,aG as Xe,aH as Ye,C as Ge,aI as fe,aJ as Qe,aK as he,aL as Z,aM as B,aN as me,aO as ge,aP as Ze,aQ as ne,aR as Je}from"./D9_UoUeZ.js";import{t as ve,v as Be,d as ke,_ as et,u as tt,a as nt,c as pe,b as ae,g as be,e as rt}from"./D7MZVPk2.js";import{i as Le}from"./DbsdAWCo.js";import{S as it,c as ye}from"./CsINcLt-.js";import{a as at}from"./B4u2S65I.js";import{i as lt,b as ot,l as st}from"./DeEeg26y.js";import{i as ut}from"./ddbMuYut.js";import{f as ct}from"./CavPuMrz.js";import{u as dt,F as ce}from"./DGGMJEpV.js";function we(e){return typeof e=="object"&&e!=null&&e.nodeType===1}function Fe(e,t){return(!t||e!=="hidden")&&e!=="visible"&&e!=="clip"}function oe(e,t){if(e.clientHeight<e.scrollHeight||e.clientWidth<e.scrollWidth){var n=getComputedStyle(e,null);return Fe(n.overflowY,t)||Fe(n.overflowX,t)||(function(a){var r=(function(i){if(!i.ownerDocument||!i.ownerDocument.defaultView)return null;try{return i.ownerDocument.defaultView.frameElement}catch{return null}})(a);return!!r&&(r.clientHeight<a.scrollHeight||r.clientWidth<a.scrollWidth)})(e)}return!1}function re(e,t,n,a,r,i,u,h){return i<e&&u>t||i>e&&u<t?0:i<=e&&h<=n||u>=t&&h>=n?i-e-a:u>t&&h<n||i<e&&h>n?u-t+r:0}var Pe=function(e,t){var n=window,a=t.scrollMode,r=t.block,i=t.inline,u=t.boundary,h=t.skipOverflowHiddenElements,b=typeof u=="function"?u:function(Ae){return Ae!==u};if(!we(e))throw new TypeError("Invalid target");for(var O,k,E=document.scrollingElement||document.documentElement,M=[],w=e;we(w)&&b(w);){if((w=(k=(O=w).parentElement)==null?O.getRootNode().host||null:k)===E){M.push(w);break}w!=null&&w===document.body&&oe(w)&&!oe(document.documentElement)||w!=null&&oe(w,h)&&M.push(w)}for(var I=n.visualViewport?n.visualViewport.width:innerWidth,L=n.visualViewport?n.visualViewport.height:innerHeight,_=window.scrollX||pageXOffset,T=window.scrollY||pageYOffset,A=e.getBoundingClientRect(),o=A.height,l=A.width,g=A.top,c=A.right,f=A.bottom,d=A.left,F=r==="start"||r==="nearest"?g:r==="end"?f:g+o/2,v=i==="center"?d+l/2:i==="end"?c:d,P=[],V=0;V<M.length;V++){var p=M[V],j=p.getBoundingClientRect(),R=j.height,H=j.width,s=j.top,m=j.right,y=j.bottom,S=j.left;if(a==="if-needed"&&g>=0&&d>=0&&f<=L&&c<=I&&g>=s&&f<=y&&d>=S&&c<=m)return P;var q=getComputedStyle(p),$=parseInt(q.borderLeftWidth,10),U=parseInt(q.borderTopWidth,10),W=parseInt(q.borderRightWidth,10),D=parseInt(q.borderBottomWidth,10),x=0,z=0,G="offsetWidth"in p?p.offsetWidth-p.clientWidth-$-W:0,K="offsetHeight"in p?p.offsetHeight-p.clientHeight-U-D:0,Q="offsetWidth"in p?p.offsetWidth===0?0:H/p.offsetWidth:0,ee="offsetHeight"in p?p.offsetHeight===0?0:R/p.offsetHeight:0;if(E===p)x=r==="start"?F:r==="end"?F-L:r==="nearest"?re(T,T+L,L,U,D,T+F,T+F+o,o):F-L/2,z=i==="start"?v:i==="center"?v-I/2:i==="end"?v-I:re(_,_+I,I,$,W,_+v,_+v+l,l),x=Math.max(0,x+T),z=Math.max(0,z+_);else{x=r==="start"?F-s-U:r==="end"?F-y+D+K:r==="nearest"?re(s,y,R,U,D+K,F,F+o,o):F-(s+R/2)+K/2,z=i==="start"?v-S-$:i==="center"?v-(S+H/2)+G/2:i==="end"?v-m+W+G:re(S,m,H,$,W+G,v,v+l,l);var te=p.scrollLeft,J=p.scrollTop;F+=J-(x=Math.max(0,Math.min(J+x/ee,p.scrollHeight-R/ee+K))),v+=te-(z=Math.max(0,Math.min(te+z/Q,p.scrollWidth-H/Q+G)))}P.push({el:p,top:x,left:z})}return P};function Se(e){return e===Object(e)&&Object.keys(e).length!==0}function ft(e,t){t===void 0&&(t="auto");var n="scrollBehavior"in document.body.style;e.forEach(function(a){var r=a.el,i=a.top,u=a.left;r.scroll&&n?r.scroll({top:i,left:u,behavior:t}):(r.scrollTop=i,r.scrollLeft=u)})}function ht(e){return e===!1?{block:"end",inline:"nearest"}:Se(e)?e:{block:"start",inline:"nearest"}}function mt(e,t){var n=e.isConnected||e.ownerDocument.documentElement.contains(e);if(Se(t)&&typeof t.behavior=="function")return t.behavior(n?Pe(e,t):[]);if(n){var a=ht(t);return ft(Pe(e,a),a.behavior)}}function gt(e,t,n){var a=-1,r=e.length;t<0&&(t=-t>r?0:r+t),n=n>r?r:n,n<0&&(n+=r),r=t>n?0:n-t>>>0,t>>>=0;for(var i=Array(r);++a<r;)i[a]=e[a+t];return i}var se=function(){return Ce.Date.now()},vt="Expected a function",pt=Math.max,bt=Math.min;function yt(e,t,n){var a,r,i,u,h,b,O=0,k=!1,E=!1,M=!0;if(typeof e!="function")throw new TypeError(vt);t=ve(t)||0,_e(n)&&(k=!!n.leading,E="maxWait"in n,i=E?pt(ve(n.maxWait)||0,t):i,M="trailing"in n?!!n.trailing:M);function w(c){var f=a,d=r;return a=r=void 0,O=c,u=e.apply(d,f),u}function I(c){return O=c,h=setTimeout(T,t),k?w(c):u}function L(c){var f=c-b,d=c-O,F=t-f;return E?bt(F,i-d):F}function _(c){var f=c-b,d=c-O;return b===void 0||f>=t||f<0||E&&d>=i}function T(){var c=se();if(_(c))return A(c);h=setTimeout(T,L(c))}function A(c){return h=void 0,M&&a?w(c):(a=r=void 0,u)}function o(){h!==void 0&&clearTimeout(h),O=0,a=b=r=h=void 0}function l(){return h===void 0?u:A(se())}function g(){var c=se(),f=_(c);if(a=arguments,r=this,b=c,f){if(h===void 0)return I(b);if(E)return clearTimeout(h),h=setTimeout(T,t),w(b)}return h===void 0&&(h=setTimeout(T,t)),u}return g.cancel=o,g.flush=l,g}var wt=Math.min;function Ft(e,t,n){for(var a=at,r=e[0].length,i=e.length,u=i,h=Array(i),b=1/0,O=[];u--;){var k=e[u];b=wt(k.length,b),h[u]=r>=120&&k.length>=120?new it(u&&k):void 0}k=e[0];var E=-1,M=h[0];e:for(;++E<r&&O.length<b;){var w=k[E],I=w;if(w=w!==0?w:0,!(M?ye(M,I):a(O,I))){for(u=i;--u;){var L=h[u];if(!(L?ye(L,I):a(e[u],I)))continue e}M&&M.push(I),O.push(w)}}return O}function Pt(e){return lt(e)?e:[]}var Ot=ot(function(e){var t=Me(e,Pt);return t.length&&t[0]===e[0]?Ft(t):[]});function Et(e,t){return t.length<2?e:Ve(e,gt(t,0,-1))}var Mt=Object.prototype,It=Mt.hasOwnProperty;function Tt(e,t){t=Ie(t,e);var n=-1,a=t.length;if(!a)return!0;for(var r=e==null||typeof e!="object"&&typeof e!="function";++n<a;){var i=t[n];if(typeof i=="string"){if(i==="__proto__"&&!It.call(e,"__proto__"))return!1;if(i==="constructor"&&n+1<a&&typeof t[n+1]=="string"&&t[n+1]==="prototype"){if(r&&n===0)continue;return!1}}}var u=Et(e,t);return u==null||delete u[je(st(t))]}function kt(e){return ut(e)?void 0:e}var Lt=1,St=2,xt=4,At=ct(function(e,t){var n={};if(e==null)return n;var a=!1;t=Me(t,function(i){return i=Ie(i,e),a||(a=i.length>1),i}),We(e,qe(e),n),a&&(n=Ne(n,Lt|St|xt,kt));for(var r=t.length;r--;)Tt(n,t[r]);return n});function xe(e){let t=!1,n=e.length;const a=[];return e.length?new Promise((r,i)=>{e.forEach((u,h)=>{u.catch(b=>(t=!0,b)).then(b=>{n-=1,a[h]=b,!(n>0)&&(t&&i(a),r(a))})})}):Promise.resolve([])}function Oe(e){let t=!1;return e&&e.length&&e.every(n=>n.required?(t=!0,!1):!0),t}function Ee(e){return e==null?[]:Array.isArray(e)?e:[e]}function ue(e,t,n){let a=e;t=t.replace(/\[(\w+)\]/g,".$1"),t=t.replace(/^\./,"");const r=t.split(".");let i=0;for(let u=r.length;i<u-1&&!(!a&&!n);++i){const h=r[i];if(h in a)a=a[h];else{if(n)throw new Error("please transfer a valid name path to validate!");break}}return{o:a,k:r[i],v:a?a[r[i]]:null,isValid:a&&r[i]in a}}function Ct(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Te({}),n=arguments.length>2?arguments[2]:void 0;const a=le(X(e)),r=Re({}),i=He([]),u=o=>{N(X(e),N(N({},le(a)),o)),De(()=>{Object.keys(r).forEach(l=>{r[l]={autoLink:!1,required:Oe(X(t)[l])}})})},h=function(){let o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],l=arguments.length>1?arguments[1]:void 0;return l.length?o.filter(g=>{const c=Ee(g.trigger||"change");return Ot(c,l).length}):o};let b=null;const O=function(o){let l=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},g=arguments.length>2?arguments[2]:void 0;const c=[],f={};for(let v=0;v<o.length;v++){const P=o[v],V=ue(X(e),P,g);if(!V.isValid)continue;f[P]=V.v;const p=h(X(t)[P],Ee(l&&l.trigger));p.length&&c.push(k(P,V.v,p,l||{}).then(()=>({name:P,errors:[],warnings:[]})).catch(j=>{const R=[],H=[];return j.forEach(s=>{let{rule:{warningOnly:m},errors:y}=s;m?H.push(...y):R.push(...y)}),R.length?Promise.reject({name:P,errors:R,warnings:H}):{name:P,errors:R,warnings:H}}))}const d=xe(c);b=d;const F=d.then(()=>b===d?Promise.resolve(f):Promise.reject([])).catch(v=>{const P=v.filter(V=>V&&V.errors.length);return Promise.reject({values:f,errorFields:P,outOfDate:b!==d})});return F.catch(v=>v),F},k=function(o,l,g){let c=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};const f=Be([o],l,g,N({validateMessages:ke},c),!!c.validateFirst);return r[o]?(r[o].validateStatus="validating",f.catch(d=>d).then(function(){let d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];var F;if(r[o].validateStatus==="validating"){const v=d.filter(P=>P&&P.errors.length);r[o].validateStatus=v.length?"error":"success",r[o].help=v.length?v.map(P=>P.errors):null,(F=n?.onValidate)===null||F===void 0||F.call(n,o,!v.length,v.length?de(r[o].help[0]):null)}}),f):f.catch(d=>d)},E=(o,l)=>{let g=[],c=!0;o?Array.isArray(o)?g=o:g=[o]:(c=!1,g=i.value);const f=O(g,l||{},c);return f.catch(d=>d),f},M=o=>{let l=[];o?Array.isArray(o)?l=o:l=[o]:l=i.value,l.forEach(g=>{r[g]&&N(r[g],{validateStatus:"",help:null})})},w=o=>{const l={autoLink:!1},g=[],c=Array.isArray(o)?o:[o];for(let f=0;f<c.length;f++){const d=c[f];d?.validateStatus==="error"&&(l.validateStatus="error",d.help&&g.push(d.help)),l.required=l.required||d?.required}return l.help=g,l};let I=a,L=!0;const _=o=>{const l=[];i.value.forEach(g=>{const c=ue(o,g,!1),f=ue(I,g,!1);(L&&n?.immediate&&c.isValid||!Le(c.v,f.v))&&l.push(g)}),E(l,{trigger:"change"}),L=!1,I=le(de(o))},T=n?.debounce;let A=!0;return ie(t,()=>{i.value=t?Object.keys(X(t)):[],!A&&n&&n.validateOnRuleChange&&E(),A=!1},{deep:!0,immediate:!0}),ie(i,()=>{const o={};i.value.forEach(l=>{o[l]=N({},r[l],{autoLink:!1,required:Oe(X(t)[l])}),delete r[l]});for(const l in r)Object.prototype.hasOwnProperty.call(r,l)&&delete r[l];N(r,o)},{immediate:!0}),ie(e,T&&T.wait?yt(_,T.wait,At(T,["wait"])):_,{immediate:n&&!!n.immediate,deep:!0}),{modelRef:e,rulesRef:t,initialModel:a,validateInfos:r,resetFields:u,validate:E,validateField:k,mergeValidateInfo:w,clearValidate:M}}const _t=()=>({layout:he.oneOf(Je("horizontal","inline","vertical")),labelCol:ne(),wrapperCol:ne(),colon:B(),labelAlign:me(),labelWrap:B(),prefixCls:String,requiredMark:ge([String,Boolean]),hideRequiredMark:B(),model:he.object,rules:ne(),validateMessages:ne(),validateOnRuleChange:B(),scrollToFirstError:Ze(),onSubmit:Z(),name:String,validateTrigger:ge([String,Array]),size:me(),disabled:B(),onValuesChange:Z(),onFieldsChange:Z(),onFinish:Z(),onFinishFailed:Z(),onValidate:Z()});function Vt(e,t){return Le(ae(e),ae(t))}const Y=$e({compatConfig:{MODE:3},name:"AForm",inheritAttrs:!1,props:Qe(_t(),{layout:"horizontal",hideRequiredMark:!1,colon:!0}),Item:et,useForm:Ct,setup(e,t){let{emit:n,slots:a,expose:r,attrs:i}=t;const{prefixCls:u,direction:h,form:b,size:O,disabled:k}=ze("form",e),E=C(()=>e.requiredMark===""||e.requiredMark),M=C(()=>{var s;return E.value!==void 0?E.value:b&&((s=b.value)===null||s===void 0?void 0:s.requiredMark)!==void 0?b.value.requiredMark:!e.hideRequiredMark});Ke(O),Ue(k);const w=C(()=>{var s,m;return(s=e.colon)!==null&&s!==void 0?s:(m=b.value)===null||m===void 0?void 0:m.colon}),{validateMessages:I}=Xe(),L=C(()=>N(N(N({},ke),I.value),e.validateMessages)),[_,T]=tt(u),A=C(()=>Ye(u.value,{[`${u.value}-${e.layout}`]:!0,[`${u.value}-hide-required-mark`]:M.value===!1,[`${u.value}-rtl`]:h.value==="rtl",[`${u.value}-${O.value}`]:O.value},T.value)),o=Te(),l={},g=(s,m)=>{l[s]=m},c=s=>{delete l[s]},f=s=>{const m=!!s,y=m?ae(s).map(be):[];return m?Object.values(l).filter(S=>y.findIndex(q=>Vt(q,S.fieldName.value))>-1):Object.values(l)},d=s=>{e.model&&f(s).forEach(m=>{m.resetField()})},F=s=>{f(s).forEach(m=>{m.clearValidate()})},v=s=>{const{scrollToFirstError:m}=e;if(n("finishFailed",s),m&&s.errorFields.length){let y={};typeof m=="object"&&(y=m),V(s.errorFields[0].name,y)}},P=function(){return R(...arguments)},V=function(s){let m=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const y=f(s?[s]:void 0);if(y.length){const S=y[0].fieldId.value,q=S?document.getElementById(S):null;q&&mt(q,N({scrollMode:"if-needed",block:"nearest"},m))}},p=function(){let s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!0;if(s===!0){const m=[];return Object.values(l).forEach(y=>{let{namePath:S}=y;m.push(S.value)}),pe(e.model,m)}else return pe(e.model,s)},j=(s,m)=>{if(!e.model)return Promise.reject("Form `model` is required for validateFields to work.");const y=!!s,S=y?ae(s).map(be):[],q=[];Object.values(l).forEach(W=>{var D;if(y||S.push(W.namePath.value),!(!((D=W.rules)===null||D===void 0)&&D.value.length))return;const x=W.namePath.value;if(!y||rt(S,x)){const z=W.validateRules(N({validateMessages:L.value},m));q.push(z.then(()=>({name:x,errors:[],warnings:[]})).catch(G=>{const K=[],Q=[];return G.forEach(ee=>{let{rule:{warningOnly:te},errors:J}=ee;te?Q.push(...J):K.push(...J)}),K.length?Promise.reject({name:x,errors:K,warnings:Q}):{name:x,errors:K,warnings:Q}}))}});const $=xe(q);o.value=$;const U=$.then(()=>o.value===$?Promise.resolve(p(S)):Promise.reject([])).catch(W=>{const D=W.filter(x=>x&&x.errors.length);return Promise.reject({values:p(S),errorFields:D,outOfDate:o.value!==$})});return U.catch(W=>W),U},R=function(){return j(...arguments)},H=s=>{s.preventDefault(),s.stopPropagation(),n("submit",s),e.model&&j().then(y=>{n("finish",y)}).catch(y=>{v(y)})};return r({resetFields:d,clearValidate:F,validateFields:j,getFieldsValue:p,validate:P,scrollToField:V}),nt({model:C(()=>e.model),name:C(()=>e.name),labelAlign:C(()=>e.labelAlign),labelCol:C(()=>e.labelCol),labelWrap:C(()=>e.labelWrap),wrapperCol:C(()=>e.wrapperCol),vertical:C(()=>e.layout==="vertical"),colon:w,requiredMark:M,validateTrigger:C(()=>e.validateTrigger),rules:C(()=>e.rules),addField:g,removeField:c,onValidate:(s,m,y)=>{n("validate",s,m,y)},validateMessages:L}),ie(()=>e.rules,()=>{e.validateOnRuleChange&&j()}),()=>{var s;return _(Ge("form",fe(fe({},i),{},{onSubmit:H,class:[A.value,i.class]}),[(s=a.default)===null||s===void 0?void 0:s.call(a)]))}}});Y.useInjectFormItemContext=dt;Y.ItemRest=ce;Y.install=function(e){return e.component(Y.name,Y),e.component(Y.Item.name,Y.Item),e.component(ce.name,ce),e};export{Y as F,Tt as b,yt as d};
|