You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
12 KiB
2 lines
12 KiB
import{r as we,ah as ae,u as Y,q as Me,b9 as ke,O as re,Q as N,bd as qe,ar as Ie,J as Se,K as fe,H as Pe,eZ as te,fn as Ce,d as Te,N as We,da as Ae,f as I,R as xe,T as G,b as Ne,U as ce,V as ie,dd as ve,df as le,eT as Le,de as Re,fo as se}from"./index-f4658ae7.js";import{v as He,d as Ve,F as _e,u as De,c as he,t as ne,g as me,a as ze}from"./FormItem-a040ce00.js";import{u as $e}from"./useSize-90c5eaba.js";function Oe(r){var e=!1,a=r.length,s=[];return r.length?new Promise(function(n,u){r.forEach(function(g,V){g.catch(function(S){return e=!0,S}).then(function(S){a-=1,s[V]=S,!(a>0)&&(e&&u(s),n(s))})})}):Promise.resolve([])}function ge(r){return typeof r=="object"&&r!=null&&r.nodeType===1}function pe(r,e){return(!e||r!=="hidden")&&r!=="visible"&&r!=="clip"}function oe(r,e){if(r.clientHeight<r.scrollHeight||r.clientWidth<r.scrollWidth){var a=getComputedStyle(r,null);return pe(a.overflowY,e)||pe(a.overflowX,e)||function(s){var n=function(u){if(!u.ownerDocument||!u.ownerDocument.defaultView)return null;try{return u.ownerDocument.defaultView.frameElement}catch(g){return null}}(s);return!!n&&(n.clientHeight<s.scrollHeight||n.clientWidth<s.scrollWidth)}(r)}return!1}function ee(r,e,a,s,n,u,g,V){return u<r&&g>e||u>r&&g<e?0:u<=r&&V<=a||g>=e&&V>=a?u-r-s:g>e&&V<a||u<r&&V>a?g-e+n:0}var Fe=function(r,e){var a=window,s=e.scrollMode,n=e.block,u=e.inline,g=e.boundary,V=e.skipOverflowHiddenElements,S=typeof g=="function"?g:function(Ee){return Ee!==g};if(!ge(r))throw new TypeError("Invalid target");for(var L,X,A=document.scrollingElement||document.documentElement,z=[],O=r;ge(O)&&S(O);){if((O=(X=(L=O).parentElement)==null?L.getRootNode().host||null:X)===A){z.push(O);break}O!=null&&O===document.body&&oe(O)&&!oe(document.documentElement)||O!=null&&oe(O,V)&&z.push(O)}for(var R=a.visualViewport?a.visualViewport.width:innerWidth,x=a.visualViewport?a.visualViewport.height:innerHeight,H=window.scrollX||pageXOffset,k=window.scrollY||pageYOffset,j=r.getBoundingClientRect(),y=j.height,i=j.width,l=j.top,c=j.right,p=j.bottom,m=j.left,d=n==="start"||n==="nearest"?l:n==="end"?p:l+y/2,F=u==="center"?m+i/2:u==="end"?c:m,E=[],b=0;b<z.length;b++){var h=z[b],C=h.getBoundingClientRect(),o=C.height,t=C.width,f=C.top,v=C.right,P=C.bottom,w=C.left;if(s==="if-needed"&&l>=0&&m>=0&&p<=x&&c<=R&&l>=f&&p<=P&&m>=w&&c<=v)return E;var q=getComputedStyle(h),_=parseInt(q.borderLeftWidth,10),M=parseInt(q.borderTopWidth,10),T=parseInt(q.borderRightWidth,10),W=parseInt(q.borderBottomWidth,10),$=0,Q=0,D="offsetWidth"in h?h.offsetWidth-h.clientWidth-_-T:0,U="offsetHeight"in h?h.offsetHeight-h.clientHeight-M-W:0,K="offsetWidth"in h?h.offsetWidth===0?0:t/h.offsetWidth:0,J="offsetHeight"in h?h.offsetHeight===0?0:o/h.offsetHeight:0;if(A===h)$=n==="start"?d:n==="end"?d-x:n==="nearest"?ee(k,k+x,x,M,W,k+d,k+d+y,y):d-x/2,Q=u==="start"?F:u==="center"?F-R/2:u==="end"?F-R:ee(H,H+R,R,_,T,H+F,H+F+i,i),$=Math.max(0,$+k),Q=Math.max(0,Q+H);else{$=n==="start"?d-f-M:n==="end"?d-P+W+U:n==="nearest"?ee(f,P,o,M,W+U,d,d+y,y):d-(f+o/2)+U/2,Q=u==="start"?F-w-_:u==="center"?F-(w+t/2)+D/2:u==="end"?F-v+T+D:ee(w,v,t,_,T+D,F,F+i,i);var B=h.scrollLeft,de=h.scrollTop;d+=de-($=Math.max(0,Math.min(de+$/J,h.scrollHeight-o/J+U))),F+=B-(Q=Math.max(0,Math.min(B+Q/K,h.scrollWidth-t/K+D)))}E.push({el:h,top:$,left:Q})}return E};function je(r){return r===Object(r)&&Object.keys(r).length!==0}function Qe(r,e){e===void 0&&(e="auto");var a="scrollBehavior"in document.body.style;r.forEach(function(s){var n=s.el,u=s.top,g=s.left;n.scroll&&a?n.scroll({top:u,left:g,behavior:e}):(n.scrollTop=u,n.scrollLeft=g)})}function Ue(r){return r===!1?{block:"end",inline:"nearest"}:je(r)?r:{block:"start",inline:"nearest"}}function Xe(r,e){var a=r.isConnected||r.ownerDocument.documentElement.contains(r);if(je(e)&&typeof e.behavior=="function")return e.behavior(a?Fe(r,e):[]);if(a){var s=Ue(e);return Qe(Fe(r,s),s.behavior)}}function ye(r){var e=!1;return r&&r.length&&r.every(function(a){return a.required?(e=!0,!1):!0}),e}function be(r){return r==null?[]:Array.isArray(r)?r:[r]}function ue(r,e,a){var s=r;e=e.replace(/\[(\w+)\]/g,".$1"),e=e.replace(/^\./,"");for(var n=e.split("."),u=0,g=n.length;u<g-1&&!(!s&&!a);++u){var V=n[u];if(V in s)s=s[V];else{if(a)throw new Error("please transfer a valid name path to validate!");break}}return{o:s,k:n[u],v:s?s[n[u]]:null,isValid:s&&n[u]in s}}function Ye(r){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:we({}),a=arguments.length>2?arguments[2]:void 0,s=ae(Y(r)),n=Me({}),u=ke([]),g=function(i){N(Y(r),N(N({},ae(s)),i)),Se(function(){Object.keys(n).forEach(function(l){n[l]={autoLink:!1,required:ye(Y(e)[l])}})})},V=function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],l=arguments.length>1?arguments[1]:void 0;return l.length?i.filter(function(c){var p=be(c.trigger||"change");return Ce(p,l).length}):i},S=null,L=function(i){for(var l=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},c=arguments.length>2?arguments[2]:void 0,p=[],m={},d=function(o){var t=i[o],f=ue(Y(r),t,c);if(!f.isValid)return"continue";m[t]=f.v;var v=V(Y(e)[t],be(l&&l.trigger));v.length&&p.push(X(t,f.v,v,l||{}).then(function(){return{name:t,errors:[],warnings:[]}}).catch(function(P){var w=[],q=[];return P.forEach(function(_){var M=_.rule.warningOnly,T=_.errors;M?q.push.apply(q,te(T)):w.push.apply(w,te(T))}),w.length?Promise.reject({name:t,errors:w,warnings:q}):{name:t,errors:w,warnings:q}}))},F=0;F<i.length;F++)var E=d(F);var b=Oe(p);S=b;var h=b.then(function(){return S===b?Promise.resolve(m):Promise.reject([])}).catch(function(C){var o=C.filter(function(t){return t&&t.errors.length});return Promise.reject({values:m,errorFields:o,outOfDate:S!==b})});return h.catch(function(C){return C}),h},X=function(i,l,c){var p=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{},m=He([i],l,c,N({validateMessages:Ve},p),!!p.validateFirst);return n[i]?(n[i].validateStatus="validating",m.catch(function(d){return d}).then(function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],F;if(n[i].validateStatus==="validating"){var E=d.filter(function(b){return b&&b.errors.length});n[i].validateStatus=E.length?"error":"success",n[i].help=E.length?E.map(function(b){return b.errors}):"",(F=a==null?void 0:a.onValidate)===null||F===void 0||F.call(a,i,!E.length,E.length?fe(n[i].help[0]):null)}}),m):m.catch(function(d){return d})},A=function(i,l){var c=[],p=!0;i?Array.isArray(i)?c=i:c=[i]:(p=!1,c=u.value);var m=L(c,l||{},p);return m.catch(function(d){return d}),m},z=function(i){var l=[];i?Array.isArray(i)?l=i:l=[i]:l=u.value,l.forEach(function(c){n[c]&&N(n[c],{validateStatus:"",help:""})})},O=function(i){for(var l={autoLink:!1},c=[],p=Array.isArray(i)?i:[i],m=0;m<p.length;m++){var d=p[m];(d==null?void 0:d.validateStatus)==="error"&&(l.validateStatus="error",d.help&&c.push(d.help)),l.required=l.required||(d==null?void 0:d.required)}return l.help=c,l},R=s,x=!0,H=function(i){var l=[];u.value.forEach(function(c){var p=ue(i,c,!1),m=ue(R,c,!1),d=x&&(a==null?void 0:a.immediate)&&p.isValid;(d||!Pe(p.v,m.v))&&l.push(c)}),A(l,{trigger:"change"}),x=!1,R=ae(fe(i))},k=a==null?void 0:a.debounce,j=!0;return re(e,function(){u.value=e?Object.keys(Y(e)):[],!j&&a&&a.validateOnRuleChange&&A(),j=!1},{deep:!0,immediate:!0}),re(u,function(){var y={};u.value.forEach(function(l){y[l]=N({},n[l],{autoLink:!1,required:ye(Y(e)[l])}),delete n[l]});for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&delete n[i];N(n,y)},{immediate:!0}),re(r,k&&k.wait?qe(H,k.wait,Ie(k,["wait"])):H,{immediate:a&&!!a.immediate,deep:!0}),{modelRef:r,rulesRef:e,initialModel:s,validateInfos:n,resetFields:g,validate:A,validateField:X,mergeValidateInfo:O,clearValidate:z}}var Ze=function(){return{layout:ie.oneOf(ve("horizontal","inline","vertical")),labelCol:{type:Object},wrapperCol:{type:Object},colon:{type:Boolean,default:void 0},labelAlign:ie.oneOf(ve("left","right")),labelWrap:{type:Boolean,default:void 0},prefixCls:String,requiredMark:{type:[String,Boolean],default:void 0},hideRequiredMark:{type:Boolean,default:void 0},model:ie.object,rules:{type:Object},validateMessages:{type:Object,default:void 0},validateOnRuleChange:{type:Boolean,default:void 0},scrollToFirstError:{type:[Boolean,Object]},onSubmit:Function,name:String,validateTrigger:{type:[String,Array]},size:{type:String},onValuesChange:{type:Function},onFieldsChange:{type:Function},onFinish:{type:Function},onFinishFailed:{type:Function},onValidate:{type:Function}}};function Ke(r,e){return Pe(ne(r),ne(e))}var Be=Te({name:"AForm",inheritAttrs:!1,props:We(Ze(),{layout:"horizontal",hideRequiredMark:!1,colon:!0}),Item:_e,useForm:Ye,setup:function(e,a){var s=a.emit,n=a.slots,u=a.expose,g=a.attrs,V=$e(e),S=Ae("form",e),L=S.prefixCls,X=S.direction,A=S.form,z=I(function(){return e.requiredMark===""||e.requiredMark}),O=I(function(){var o;return z.value!==void 0?z.value:A&&((o=A.value)===null||o===void 0?void 0:o.requiredMark)!==void 0?A.value.requiredMark:!e.hideRequiredMark}),R=I(function(){var o,t;return(o=e.colon)!==null&&o!==void 0?o:(t=A.value)===null||t===void 0?void 0:t.colon}),x=I(function(){return N(N({},Ve),e.validateMessages)}),H=I(function(){var o;return xe(L.value,(o={},G(o,"".concat(L.value,"-").concat(e.layout),!0),G(o,"".concat(L.value,"-hide-required-mark"),O.value===!1),G(o,"".concat(L.value,"-rtl"),X.value==="rtl"),G(o,"".concat(L.value,"-").concat(V.value),V.value),o))}),k=we(),j={},y=function(t,f){j[t]=f},i=function(t){delete j[t]},l=function(t){var f=!!t,v=f?ne(t).map(me):[];return f?Object.values(j).filter(function(P){return v.findIndex(function(w){return Ke(w,P.fieldName.value)})>-1}):Object.values(j)},c=function(t){if(!e.model){le(!1,"Form","model is required for resetFields to work.");return}l(t?[t]:void 0).forEach(function(f){f.resetField()})},p=function(t){l(t?[t]:void 0).forEach(function(f){f.clearValidate()})},m=function(t){var f=e.scrollToFirstError;if(s("finishFailed",t),f&&t.errorFields.length){var v={};Le(f)==="object"&&(v=f),F(t.errorFields[0].name,v)}},d=function(){return h.apply(void 0,arguments)},F=function(t){var f=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},v=l(t?[t]:void 0);if(v.length){var P=v[0].fieldId.value,w=P?document.getElementById(P):null;w&&Xe(w,N({scrollMode:"if-needed",block:"nearest"},f))}},E=function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!0;if(t===!0){var f=[];return Object.values(j).forEach(function(v){var P=v.namePath;f.push(P.value)}),he(e.model,f)}else return he(e.model,t)},b=function(t,f){if(le(!(t instanceof Function),"Form","validateFields/validateField/validate not support callback, please use promise instead"),!e.model)return le(!1,"Form","model is required for validateFields to work."),Promise.reject("Form `model` is required for validateFields to work.");var v=!!t,P=v?ne(t).map(me):[],w=[];Object.values(j).forEach(function(M){var T;if(v||P.push(M.namePath.value),!!(!((T=M.rules)===null||T===void 0)&&T.value.length)){var W=M.namePath.value;if(!v||ze(P,W)){var $=M.validateRules(N({validateMessages:x.value},f));w.push($.then(function(){return{name:W,errors:[],warnings:[]}}).catch(function(Q){var D=[],U=[];return Q.forEach(function(K){var J=K.rule.warningOnly,B=K.errors;J?U.push.apply(U,te(B)):D.push.apply(D,te(B))}),D.length?Promise.reject({name:W,errors:D,warnings:U}):{name:W,errors:D,warnings:U}}))}}});var q=Oe(w);k.value=q;var _=q.then(function(){return k.value===q?Promise.resolve(E(P)):Promise.reject([])}).catch(function(M){var T=M.filter(function(W){return W&&W.errors.length});return Promise.reject({values:E(P),errorFields:T,outOfDate:k.value!==q})});return _.catch(function(M){return M}),_},h=function(){return b.apply(void 0,arguments)},C=function(t){if(t.preventDefault(),t.stopPropagation(),s("submit",t),e.model){var f=b();f.then(function(v){s("finish",v)}).catch(function(v){m(v)})}};return u({resetFields:c,clearValidate:p,validateFields:b,getFieldsValue:E,validate:d,scrollToField:F}),De({model:I(function(){return e.model}),name:I(function(){return e.name}),labelAlign:I(function(){return e.labelAlign}),labelCol:I(function(){return e.labelCol}),labelWrap:I(function(){return e.labelWrap}),wrapperCol:I(function(){return e.wrapperCol}),vertical:I(function(){return e.layout==="vertical"}),colon:R,requiredMark:O,validateTrigger:I(function(){return e.validateTrigger}),rules:I(function(){return e.rules}),addField:y,removeField:i,onValidate:function(t,f,v){s("validate",t,f,v)},validateMessages:x}),re(function(){return e.rules},function(){e.validateOnRuleChange&&b()}),function(){var o;return Ne("form",ce(ce({},g),{},{onSubmit:C,class:[H.value,g.class]}),[(o=n.default)===null||o===void 0?void 0:o.call(n)])}}});const Z=Be;Z.useInjectFormItemContext=Re;Z.ItemRest=se;Z.install=function(r){return r.component(Z.name,Z),r.component(Z.Item.name,Z.Item),r.component(se.name,se),r};export{Z as F};
|