2 lines
14 KiB
JavaScript
2 lines
14 KiB
JavaScript
import{as as _e,at as Ce,au as Me,av as Ve,aw as Te,ax as je,ay as We,az as qe,aA as Ne,r as Ie,aB as le,K as X,J as Re,s as De,a0 as ie,aC as N,aD as de,af as He,d as $e,aE as ze,l as _,aF as Ke,aG as Ue,aH as Xe,aI as Ye,D as Ge,aJ as fe,aK as Qe,aL as he,aM as Z,aN as B,aO as me,aP as ge,aQ as Ze,aR as ne,aS as Je}from"./CE4SaZgW.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"./DSWAPs-i.js";import{i as Le}from"./DFL6LqjW.js";import{S as it,c as ye}from"./0N7JoioX.js";import{a as at}from"./BK6U06JP.js";import{i as lt,b as ot,l as st}from"./B0tUBnBT.js";import{i as ut}from"./BQKhYWGC.js";import{f as ct}from"./DZnIL_2I.js";import{u as dt,F as ce}from"./CjPHwh7J.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 T=n.visualViewport?n.visualViewport.width:innerWidth,L=n.visualViewport?n.visualViewport.height:innerHeight,C=window.scrollX||pageXOffset,I=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,D=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<=T&&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),H=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-H:0,Q="offsetWidth"in p?p.offsetWidth===0?0:D/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(I,I+L,L,U,H,I+F,I+F+o,o):F-L/2,z=i==="start"?v:i==="center"?v-T/2:i==="end"?v-T:re(C,C+T,T,$,W,C+v,C+v+l,l),x=Math.max(0,x+I),z=Math.max(0,z+C);else{x=r==="start"?F-s-U:r==="end"?F-y+H+K:r==="nearest"?re(s,y,R,U,H+K,F,F+o,o):F-(s+R/2)+K/2,z=i==="start"?v-S-$:i==="center"?v-(S+D/2)+G/2:i==="end"?v-m+W+G:re(S,m,D,$,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-D/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 _e.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,Ce(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 T(c){return O=c,h=setTimeout(I,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(c){var f=c-b,d=c-O;return b===void 0||f>=t||f<0||E&&d>=i}function I(){var c=se();if(C(c))return A(c);h=setTimeout(I,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(c);if(a=arguments,r=this,b=c,f){if(h===void 0)return T(b);if(E)return clearTimeout(h),h=setTimeout(I,t),w(b)}return h===void 0&&(h=setTimeout(I,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],T=w;if(w=w!==0?w:0,!(M?ye(M,T):a(O,T))){for(u=i;--u;){var L=h[u];if(!(L?ye(L,T):a(e[u],T)))continue e}M&&M.push(T),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,Tt=Mt.hasOwnProperty;function It(e,t){t=Te(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__"&&!Tt.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=Te(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--;)It(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 _t(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ie({}),n=arguments.length>2?arguments[2]:void 0;const a=le(X(e)),r=Re({}),i=De([]),u=o=>{N(X(e),N(N({},le(a)),o)),He(()=>{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=[],D=[];return j.forEach(s=>{let{rule:{warningOnly:m},errors:y}=s;m?D.push(...y):R.push(...y)}),R.length?Promise.reject({name:P,errors:R,warnings:D}):{name:P,errors:R,warnings:D}}))}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 T=a,L=!0;const C=o=>{const l=[];i.value.forEach(g=>{const c=ue(o,g,!1),f=ue(T,g,!1);(L&&n?.immediate&&c.isValid||!Le(c.v,f.v))&&l.push(g)}),E(l,{trigger:"change"}),L=!1,T=le(de(o))},I=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,I&&I.wait?yt(C,I.wait,At(I,["wait"])):C,{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 Ct=()=>({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(Ct(),{layout:"horizontal",hideRequiredMark:!1,colon:!0}),Item:et,useForm:_t,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=_(()=>e.requiredMark===""||e.requiredMark),M=_(()=>{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=_(()=>{var s,m;return(s=e.colon)!==null&&s!==void 0?s:(m=b.value)===null||m===void 0?void 0:m.colon}),{validateMessages:T}=Xe(),L=_(()=>N(N(N({},ke),T.value),e.validateMessages)),[C,I]=tt(u),A=_(()=>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},I.value)),o=Ie(),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 H;if(y||S.push(W.namePath.value),!(!((H=W.rules)===null||H===void 0)&&H.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 H=W.filter(x=>x&&x.errors.length);return Promise.reject({values:p(S),errorFields:H,outOfDate:o.value!==$})});return U.catch(W=>W),U},R=function(){return j(...arguments)},D=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:_(()=>e.model),name:_(()=>e.name),labelAlign:_(()=>e.labelAlign),labelCol:_(()=>e.labelCol),labelWrap:_(()=>e.labelWrap),wrapperCol:_(()=>e.wrapperCol),vertical:_(()=>e.layout==="vertical"),colon:w,requiredMark:M,validateTrigger:_(()=>e.validateTrigger),rules:_(()=>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 C(Ge("form",fe(fe({},i),{},{onSubmit:D,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,It as b,yt as d};
|