2024-06-27 16:44:51 +00:00
|
|
|
import{u as Le,F as ke,i as Ce,V as B,_ as A,a as De,C as qe,r as b,s as Fe,v as We}from"./form-model.53f397fa.js";import{i as Ie,_ as Me}from"./helper.423f0a4e.js";import{u as Z,_ as j}from"./useConfig.f6485710.js";import{d as Pe,i as xe,c as p,f as V,t as we,r as Ae,o as He,b as Ke,w as je,aI as M,p as Oe,n as Ue}from"./arco.7f845a67.js";import{c as Re,d as Ge,N as Je,i as Ee,e as Xe,O as Y,M as ze,w as Ne}from"./index.4eb55f07.js";import{i as _e}from"./useDisabled.110213c8.js";import{g as se,r as Qe}from"./index.70f5a9a5.js";import{a as Ye,C as Ze,E as er}from"./dialog.9bb37d96.js";/**
|
2024-06-15 00:08:13 +00:00
|
|
|
* tdesign v1.9.4
|
|
|
|
* (c) 2024 tdesign
|
|
|
|
* @license MIT
|
|
|
|
*/var rr={for:{type:String,default:""},help:{type:[String,Function]},label:{type:[String,Function],default:""},labelAlign:{type:String,validator:function(e){return e?["left","right","top"].includes(e):!0}},labelWidth:{type:[String,Number]},name:{type:String,default:""},requiredMark:{type:Boolean,default:void 0},rules:{type:Array},showErrorMessage:{type:Boolean,default:void 0},status:{type:String,default:""},statusIcon:{type:[Boolean,Function],default:void 0},successBorder:Boolean,tips:{type:[String,Function]}};/**
|
|
|
|
* tdesign v1.9.4
|
|
|
|
* (c) 2024 tdesign
|
|
|
|
* @license MIT
|
|
|
|
*/function ar(c,e){return c.replace(/\${(.*?)}/g,function(f,v){return e[v.trim()]||""})}/**
|
|
|
|
* tdesign v1.9.4
|
|
|
|
* (c) 2024 tdesign
|
|
|
|
* @license MIT
|
|
|
|
*/function Ve(c,e){var f=Object.keys(c);if(Object.getOwnPropertySymbols){var v=Object.getOwnPropertySymbols(c);e&&(v=v.filter(function(_){return Object.getOwnPropertyDescriptor(c,_).enumerable})),f.push.apply(f,v)}return f}function Se(c){for(var e=1;e<arguments.length;e++){var f=arguments[e]!=null?arguments[e]:{};e%2?Ve(Object(f),!0).forEach(function(v){j(c,v,f[v])}):Object.getOwnPropertyDescriptors?Object.defineProperties(c,Object.getOwnPropertyDescriptors(f)):Ve(Object(f)).forEach(function(v){Object.defineProperty(c,v,Object.getOwnPropertyDescriptor(f,v))})}return c}function Te(c,e){return e?"".concat(c,"__").concat(e).replace(/(\[|\]\.)/g,"_"):""}var tr=Pe({name:"TFormItem",props:Se({},rr),setup:function(e,f){var v=f.slots,_=Re(),y=Le(),oe=Ge("form"),D=oe.globalConfig,$=Ye({CheckCircleFilledIcon:Ze,CloseCircleFilledIcon:qe,ErrorCircleFilledIcon:er}),C=$.CheckCircleFilledIcon,ce=$.CloseCircleFilledIcon,ve=$.ErrorCircleFilledIcon,r=xe(ke,void 0),ee=Z(),re=Z("form-item"),fe=p(function(){var t,n,a=(t=(n=e.requiredMark)!==null&&n!==void 0?n:r==null?void 0:r.requiredMark)!==null&&t!==void 0?t:D.value.requiredMark,d=g.value.filter(function(o){return o.required}).length>0;return a!=null?a:d}),ae=p(function(){return v.label||e.label}),de=p(function(){return!!(r!=null&&r.colon&&ae.value)}),q=Z("form__label"),W=p(function(){return Ce(e.labelAlign)?r==null?void 0:r.labelAlign:e.labelAlign}),w=p(function(){return Ce(e.labelWidth)?r==null?void 0:r.labelWidth:e.labelWidth}),me=p(function(){return[y.value.label,j(j(j(j(j({},"".concat(q.value,"--required"),fe.value),"".concat(q.value,"--colon"),de.value),"".concat(q.value,"--top"),ae.value&&(W.value==="top"||!w.value)),"".concat(q.value,"--left"),W.value==="left"&&w.value),"".concat(q.value,"--right"),W.value==="right"&&w.value)]}),ge=function(){if(Number(w.value)!==0){var n={};return w.value&&W.value!=="top"&&(Ie(w.value)?n={width:"".concat(w.value,"px")}:n={width:w.value}),M("div",{class:me.value,style:n},[M("label",{for:e.for||null},[_("label")])])}},X=function(){var n=function(h){return M("span",{class:y.value.status},[M(h,null,null)])},a=L.value;if(N.value===B.SUCCESS)return n(C);if(a!=null&&a[0]){var d=a[0].type||"error",o={error:ce,warning:ve}[d]||C;return n(o)}return null},pe=function(){var n=e.statusIcon;if(n!==!1){var a=_("statusIcon",{defaultNode:X()});if(a)return M("span",{class:y.value.status},[a]);if(a!==!1&&(a=r==null?void 0:r.renderContent("statusIcon",{defaultNode:X(),params:e}),a))return a}},H=p(function(){if(!I.value)return"";if(N.value===B.SUCCESS)return e.successBorder?[y.value.success,y.value.successBorder].join(" "):y.value.success;if(!!L.value.length){var t=L.value[0].type||"error";return t==="error"?y.value.error:y.value.warning}}),te=p(function(){return[y.value.controls,H.value]}),ne=p(function(){var t={};return w.value&&W.value!=="top"&&(Ie(w.value)?t={marginLeft:"".concat(w.value,"px")}:t={marginLeft:w.value}),t}),L=V([]),R=V([]),N=V(B.TO_BE_VALIDATED),z=V(!1),T=V(!1),Q=function(){T.value=!1,L.value=[],R.value=[],N.value=B.TO_BE_VALIDATED},be=function(){var n=Object.prototype.toString.call(se(r==null?void 0:r.data,e.name)),a;return n==="[object String]"&&(a=""),n==="[object Array]"&&(a=[]),n==="[object Object]"&&(a={}),a},ye=function(){var t=A(b.mark(function n(){var a,d=arguments;return b.wrap(function(O){for(;;)switch(O.prev=O.next){case 0:if(a=d.length>0&&d[0]!==void 0?d[0]:r==null?void 0:r.resetType,e.name){O.next=3;break}return O.abrupt("return");case 3:return a==="empty"?Fe(r==null?void 0:r.data,e.name,be()):a==="initial"&&Fe(r==null?void 0:r.data,e.name,F.value),O.next=6,Ue();case 6:z.value?T.value=!0:Q();case 7:case"end":return O.stop()}},n)}));return function(){return t.apply(this,arguments)}}(),le=p(function(){var t;return(t=r==null?void 0:r.errorMessage)!==null&&t!==void 0?t:D.value.errorMessage}),g=p(function(){var t;if((t=e.rules)!==null&&t!==void 0&&t.length)return e.rules;if(!e.name)return[];var n="".concat(e.name).lastIndexOf(".")||-1,a="".concat(e.name).slice(n+1);return se(r==null?void 0:r.rules,e.name)||se(r==null?void 0:r.rules,a)||[]}
|
|
|
|
* tdesign v1.9.4
|
|
|
|
* (c) 2024 tdesign
|
|
|
|
* @license MIT
|
|
|
|
*/var nr={colon:Boolean,data:{type:Object,default:function(){return{}}},disabled:{type:Boolean,default:void 0},errorMessage:{type:Object},formControlledComponents:{type:Array},labelAlign:{type:String,default:"right",validator:function(e){return e?["left","right","top"].includes(e):!0}},labelWidth:{type:[String,Number],default:"100px"},layout:{type:String,default:"vertical",validator:function(e){return e?["vertical","inline"].includes(e):!0}},preventSubmitDefault:{type:Boolean,default:!0},requiredMark:{type:Boolean,default:void 0},resetType:{type:String,default:"empty",validator:function(e){return e?["empty","initial"].includes(e):!0}},rules:{type:Object},scrollToFirstError:{type:String,validator:function(e){return e?["","smooth","auto"].includes(e):!0}},showErrorMessage:{type:Boolean,default:!0},statusIcon:{type:[Boolean,Function],default:void 0},submitWithWarningMessage:Boolean,onReset:Function,onSubmit:Function,onValidate:Function};/**
|
|
|
|
* tdesign v1.9.4
|
|
|
|
* (c) 2024 tdesign
|
|
|
|
* @license MIT
|
|
|
|
*/function $e(c,e){var f=Object.keys(c);if(Object.getOwnPropertySymbols){var v=Object.getOwnPropertySymbols(c);e&&(v=v.filter(function(_){return Object.getOwnPropertyDescriptor(c,_).enumerable})),f.push.apply(f,v)}return f}function lr(c){for(var e=1;e<arguments.length;e++){var f=arguments[e]!=null?arguments[e]:{};e%2?$e(Object(f),!0).forEach(function(v){j(c,v,f[v])}):Object.getOwnPropertyDescriptors?Object.defineProperties(c,Object.getOwnPropertyDescriptors(f)):$e(Object(f)).forEach(function(v){Object.defineProperty(c,v,Object.getOwnPropertyDescriptor(f,v))})}return c}var ur=Pe({name:"TForm",props:lr({},nr),setup:function(e,f){var v=f.expose,_=Re(),y=we(e),oe=y.disabled;Oe("formDisabled",{disabled:oe});var D=V(null),$=V([]),C=we(e),ce=C.showErrorMessage,ve=C.labelWidth,r=C.labelAlign,ee=C.data,re=C.colon,fe=C.requiredMark,ae=C.rules,de=C.errorMessage,q=C.resetType;Oe(ke,Ae({showErrorMessage:ce,labelWidth:ve,labelAlign:r,data:ee,colon:re,requiredMark:fe,rules:ae,errorMessage:de,resetType:q,children:$,renderContent:_}));var W=Z("form"),w=Le(),me=p(function(){return[w.value.form,j({},"".concat(W.value,"-inline"),e.layout==="inline")]}),ge=Z("form-item"),X=function(l){if(_e(l))return"";var u=Object.keys(l),s=Me(u,1),i=s[0];if(e.scrollToFirstError){var S=Te(ge.value,i);pe(S)}var F=l[i];return Ee(F)?F.filter(function(k){return!k.result})[0].message:""},pe=function(l){var u=D.value.getElementsByClassName(l),s=Me(u,1),i=s[0],S=e.scrollToFirstError;S&&i&&i.scrollIntoView({behavior:S})},H=function(l,u){return!u||!Ee(u)?!0:u.indexOf("".concat(l))!==-1},te=function(l){var u=l.reduce(function(s,i){return Object.assign(s||{},i)},{});return Object.keys(u).forEach(function(s){u[s]===!0&&delete u[s]}),ze(u)?!0:u},ne=function(){var g=A(b.mark(function l(u){var s,i,S,F,k,x,K,E,I,ue;return b.wrap(function(P){for(;;)switch(P.prev=P.next){case 0:return i=u||{},S=i.fields,F=i.trigger,k=F===void 0?"all":F,x=i.showErrorMessage,K=$.value.filter(function(U){return Y(U.validate)&&H(String(U.name),S)}).map(function(U){return U.validate(k,x)}),P.next=4,Promise.all(K);case 4:return E=P.sent,I=te(E),ue=X(I),(s=e.onValidate)===null||s===void 0||s.call(e,{validateResult:I,firstError:ue}),P.abrupt("return",I);case 9:case"end":return P.stop()}},l)}));return function(u){return g.apply(this,arguments)}}(),L=function(){var g=A(b.mark(function l(u){var s,i,S,F,k,x;return b.wrap(function(E){for(;;)switch(E.prev=E.next){case 0:return s=u||{},i=s.fields,S=s.trigger,F=S===void 0?"all":S,k=$.value.filter(function(I){return Y(I.validateOnly)&&H(String(I.name),i)}).map(function(I){return I.validateOnly(F)}),E.next=4,Promise.all(k);case 4:return x=E.sent,E.abrupt("return",te(x));case 6:case"end":return E.stop()}},l)}));return function(u){return g.apply(this,arguments)}}(),R=V(),N=function(l){e.preventSubmitDefault&&l&&(l.preventDefault(),l.stopPropagation()),ne(R.value).then(function(u){var s;(s=e.onSubmit)===null||s===void 0||s.call(e,{validateResult:u,firstError:X(u),e:l})}),R.value=void 0},z=function(){var g=A(b.mark(function l(u){return b.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:R.value=u,Qe(D.value);case 2:case"end":return i.stop()}},l)}));return function(u){return g.apply(this,arguments)}}(),T=V(),Q=function(l){var u;e.preventSubmitDefault&&l&&(l.preventDefault(),l.stopPropagation()),$.value.filter(function(s){var i;return Y(s.resetField)&&H(String(s.name),(i=T.value)===null||i===void 0?void 0:i.fields)}).forEach(function(s){var i;return s.resetField((i=T.value)===null||i===void 0?void 0:i.type)}),T.value=void 0,(u=e.onReset)===null||u===void 0||u.call(e,{e:l})},be=function(l){T.value=l,D.value.reset()},ye=function(l){$.value.forEach(function(u){Y(u.resetHandler)&&H(String(u.name),l)&&u.resetHandler()})},le=function(l){var u=Object.keys(l);if(!!u.length){var s=$.value.filter(function(i){return Y(i.setValidateMessage)&&u.includes("".concat(i.name))}).map(function(i){return i.setValidateMessage(l[i.name])});Promise.all(s)}};return v({validate:ne,submit:z,reset:be,clearValidate:ye,setValidateMessage:le,validateOnly:L}),function(){return M("form",{ref:
|
|
|
|
* tdesign v1.9.4
|
|
|
|
* (c) 2024 tdesign
|
|
|
|
* @license MIT
|
|
|
|
*/var pr=Ne(ur),br=Ne(tr);export{br as F,pr as a};
|