|
|
import{i as le,R as Ne,t as Le,S as Te,c as q,s as ee,d as De,O as he,P as Be,v as He,G as E,T as Ye}from"./index-bVOhw2NF.js";import{f as Ue}from"./use-form-item-CNgNT5jP.js";import{f as ye,a as Je}from"./Form-BZRGTIxb.js";import{f as we}from"./format-length-B-p6aW7q.js";import{g as Ie}from"./get-BuNGRF3A.js";import{b as ae,s as Ke,c as T,a as ve,d as I,u as Ze,f as Ce,g as H,h as Ge,w as Pe}from"./light-Cua7cqmF.js";import{c as Oe}from"./index-L98eAIry.js";import{f as Qe}from"./light-CUlEsFk3.js";import{r as Xe}from"./resolve-slot-Dzko3qih.js";function er(n,e,r){var t;const i=le(n,null);if(i===null)return;const s=(t=Ne())===null||t===void 0?void 0:t.proxy;Le(r,a),a(r.value),Te(()=>{a(void 0,r.value)});function a(u,l){if(!i)return;const g=i[e];l!==void 0&&o(g,l),u!==void 0&&f(g,u)}function o(u,l){u[l]||(u[l]=[]),u[l].splice(u[l].findIndex(g=>g===s),1)}function f(u,l){u[l]||(u[l]=[]),~u[l].findIndex(g=>g===s)||u[l].push(s)}}function J(){return J=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(n[t]=r[t])}return n},J.apply(this,arguments)}function rr(n,e){n.prototype=Object.create(e.prototype),n.prototype.constructor=n,fe(n,e)}function Re(n){return Re=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(r){return r.__proto__||Object.getPrototypeOf(r)},Re(n)}function fe(n,e){return fe=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,i){return t.__proto__=i,t},fe(n,e)}function tr(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function be(n,e,r){return tr()?be=Reflect.construct.bind():be=function(i,s,a){var o=[null];o.push.apply(o,s);var f=Function.bind.apply(i,o),u=new f;return a&&fe(u,a.prototype),u},be.apply(null,arguments)}function nr(n){return Function.toString.call(n).indexOf("[native code]")!==-1}function ke(n){var e=typeof Map=="function"?new Map:void 0;return ke=function(t){if(t===null||!nr(t))return t;if(typeof t!="function")throw new TypeError("Super expression must either be null or a function");if(typeof e<"u"){if(e.has(t))return e.get(t);e.set(t,i)}function i(){return be(t,arguments,Re(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),fe(i,t)},ke(n)}var ir=/%[sdj%]/g,ar=function(){};function qe(n){if(!n||!n.length)return null;var e={};return n.forEach(function(r){var t=r.field;e[t]=e[t]||[],e[t].push(r)}),e}function M(n){for(var e=arguments.length,r=new Array(e>1?e-1:0),t=1;t<e;t++)r[t-1]=arguments[t];var i=0,s=r.length;if(typeof n=="function")return n.apply(null,r);if(typeof n=="string"){var a=n.replace(ir,function(o){if(o==="%%")return"%";if(i>=s)return o;switch(o){case"%s":return String(r[i++]);case"%d":return Number(r[i++]);case"%j":try{return JSON.stringify(r[i++])}catch{return"[Circular]"}break;default:return o}});return a}return n}function sr(n){return n==="string"||n==="url"||n==="hex"||n==="email"||n==="date"||n==="pattern"}function k(n,e){return!!(n==null||e==="array"&&Array.isArray(n)&&!n.length||sr(e)&&typeof n=="string"&&!n)}function or(n,e,r){var t=[],i=0,s=n.length;function a(o){t.push.apply(t,o||[]),i++,i===s&&r(t)}n.forEach(function(o){e(o,a)})}function Se(n,e,r){var t=0,i=n.length;function s(a){if(a&&a.length){r(a);return}var o=t;t=t+1,o<i?e(n[o],s):r([])}s([])}function fr(n){var e=[];return Object.keys(n).forEach(function(r){e.push.apply(e,n[r]||[])}),e}var Ae=function(n){rr(e,n);function e(r,t){var i;return i=n.call(this,"Async Validation Error")||this,i.errors=r,i.fields=t,i}return e}(ke(Error));function lr(n,e,r,t,i){if(e.first){var s=new Promise(function(p,_){var c=function(d){return t(d),d.length?_(new Ae(d,qe(d))):p(i)},m=fr(n);Se(m,r,c)});return s.catch(function(p){return p}),s}var a=e.firstFields===!0?Object.keys(n):e.firstFields||[],o=Object.keys(n),f=o.length,u=0,l=[],g=new Promise(function(p,_){var c=fu(?:(?:`+t+":){7}(?:"+t+`|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
(?:`+t+":){6}(?:"+r+"|:"+t+`|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
(?:`+t+":){5}(?::"+r+"|(?::"+t+`){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
(?:`+t+":){4}(?:(?::"+t+"){0,1}:"+r+"|(?::"+t+`){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
(?:`+t+":){3}(?:(?::"+t+"){0,2}:"+r+"|(?::"+t+`){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
(?:`+t+":){2}(?:(?::"+t+"){0,3}:"+r+"|(?::"+t+`){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
(?:`+t+":){1}(?:(?::"+t+"){0,4}:"+r+"|(?::"+t+`){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
(?::(?:(?::`+t+"){0,5}:"+r+"|(?::"+t+`){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
`).replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),s=new RegExp("(?:^"+r+"$)|(?:^"+i+"$)"),a=new RegExp("^"+r+"$"),o=new RegExp("^"+i+"$"),f=function(w){return w&&w.exact?s:new RegExp("(?:"+e(w)+r+e(w)+")|(?:"+e(w)+i+e(w)+")","g")};f.v4=function(h){return h&&h.exact?a:new RegExp(""+e(h)+r+e(h),"g")},f.v6=function(h){return h&&h.exact?o:new RegExp(""+e(h)+i+e(h),"g")};var u="(?:(?:[a-z]+:)?//)",l="(?:\\S+(?::\\S*)?@)?",g=f.v4().source,p=f.v6().source,_="(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)",c="(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*",m="(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))",R="(?::\\d{2,5})?",d='(?:[/?#][^\\s"]*)?',$="(?:"+u+"|www\\.)"+l+"(?:localhost|"+g+"|"+p+"|"+_+c+m+")"+R+d;return pe=new RegExp("(?:^"+$+"$)","i"),pe},je={email:/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+\.)+[a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}))$/,hex:/^#?([a-f0-9]{6}|[a-f0-9]{3})$/i},se={integer:function(e){return se.number(e)&&parseInt(e,10)===e},float:function(e){return se.number(e)&&!se.integer(e)},array:function(e){return Array.isArray(e)},regexp:function(e){if(e instanceof RegExp)return!0;try{return!!new RegExp(e)}catch{return!1}},date:function(e){return typeof e.getTime=="function"&&typeof e.getMonth=="function"&&typeof e.getYear=="function"&&!isNaN(e.getTime())},number:function(e){return isNaN(e)?!1:typeof e=="number"},object:function(e){return typeof e=="object"&&!se.array(e)},method:function(e){return typeof e=="function"},email:function(e){return typeof e=="string"&&e.length<=320&&!!e.match(je.email)},url:function(e){return typeof e=="string"&&e.length<=2048&&!!e.match(mr())},hex:function(e){return typeof e=="string"&&!!e.match(je.hex)}},gr=function(e,r,t,i,s){if(e.required&&r===void 0){We(e,r,t,i,s);return}var a=["integer","float","array","regexp","object","method","email","number","date","url","hex"],o=e.type;a.indexOf(o)>-1?se[o](r)||i.push(M(s.messages.types[o],e.fullField,e.type)):o&&typeof r!==e.type&&i.push(M(s.messages.types[o],e.fullField,e.type))},hr=function(e,r,t,i,s){var a=typeof e.len=="number",o=typeof e.min=="number",f=typeof e.max=="number",u=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,l=r,g=null,p=typeof r=="number",_=typeof r=="string",c=Array.isArray(r);if(p?g="number":_?g="string":c&&(g="array"),!g)return!1;c&&(l=r.length),_&&(l=r.replace(u,"_").length),a?l!==e.len&&i.push(M(s.messages[g].len,e.fullField,e.len)):o&&!f&&l<e.min?i.push(M(s.messages[g].min,e.fullField,e.min)):f&&!o&&l>e.max?i.push(M(s.messages[g].max,e.fullField,e.max)):o&&f&&(l<e.min||l>e.max)&&i.push(M(s.messages[g].range,e.fullField,e.min,e.max))},X="enum",vr=function(e,r,t,i,s){e[X]=Array.isArray(e[X])?e[X]:[],e[X].indexOf(r)===-1&&i.push(M(s.messages[X],e.fullField,e[X].join(", ")))},pr=function(e,r,t,i,s){if(e.pattern){if(e.pattern instanceof RegExp)e.pattern.lastIndex=0,e.pattern.test(r)||i.push(M(s.messages.pattern.mismatch,e.fullField,r,e.pattern));else if(typeof e.pattern=="string"){var a=new RegExp(e.pattern);a.test(r)||i.push(M(s.messages.pattern.mismatch,e.fullField,r,e.pattern))}}},v={required:We,whitespace:cr,type:gr,range:hr,enum:vr,pattern:pr},br=function(e,r,t,i,s){var a=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(k(r,"string")&&!e.required)return t();v.required(e,r,i,a,s,"string"),k(r,"string")||(v.type(e,r,i,a,s),v.range(e,r,i,a,s),v.pattern(e,r,i,a,s),e.whitespace===!0&&v.whitespace(e,r,i,a,s))}t(a)},yr=function(e,r,t,i,s){var a=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(k(r)&&!e.required)return t();v.required(e,r,i,a,s),r!==void 0&&v.type(e,r,i,a,s)}t(a)},wr=function(e,r,t,i,s){var a=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(r===""&&(r=void 0),k(r)&&!e.required)return t();v.required(e,r,i,a,s),r!==void 0&&(v.type(e,r,i,a,s),v.range(e,r,i,a,s))}t(a)},xr=function(e,r,t,i,s){var a=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(k(r)&&!e.required)return t();v.required(e,r,i,a
display: grid; line-height: var(--n-line-height);`,[T("form-item-label",` grid-area: label; align-items: center; line-height: 1.25; text-align: var(--n-label-text-align); font-size: var(--n-label-font-size); min-height: var(--n-label-height); padding: var(--n-label-padding); color: var(--n-label-text-color); transition: color .3s var(--n-bezier); box-sizing: border-box; font-weight: var(--n-label-font-weight); `,[ve("asterisk",` white-space: nowrap; user-select: none; -webkit-user-select: none; color: var(--n-asterisk-color); transition: color .3s var(--n-bezier); `),ve("asterisk-placeholder",` grid-area: mark; user-select: none; -webkit-user-select: none; visibility: hidden; `)]),T("form-item-blank",` grid-area: blank; min-height: var(--n-blank-height); `),I("auto-label-width",[T("form-item-label","white-space: nowrap;")]),I("left-labelled",` grid-template-areas: "label blank" "label feedback"; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto 1fr; align-items: flex-start; `,[T("form-item-label",` display: grid; grid-template-columns: 1fr auto; min-height: var(--n-blank-height); height: auto; box-sizing: border-box; flex-shrink: 0; flex-grow: 0; `,[I("reverse-columns-space",` grid-template-columns: auto 1fr; `),I("left-mark",` grid-template-areas: "mark text" ". text"; `),I("right-mark",` grid-template-areas: "text mark" "text ."; `),I("right-hanging-mark",` grid-template-areas: "text mark" "text ."; `),ve("text",` grid-area: text; `),ve("asterisk",` grid-area: mark; align-self: end; `)])]),I("top-labelled",` grid-template-areas: "label" "blank" "feedback"; grid-template-rows: minmax(var(--n-label-height), auto) 1fr; grid-template-columns: minmax(0, 100%); `,[I("no-label",` grid-template-areas: "blank" "feedback"; grid-template-rows: 1fr; `),T("form-item-label",` display: flex; align-items: flex-start; justify-content: var(--n-label-text-align); `)]),T("form-item-blank",` box-sizing: border-box; display: flex; align-items: center; position: relative; `),T("form-item-feedback-wrapper",` grid-area: feedback; box-sizing: border-box; min-height: var(--n-feedback-height); font-size: var(--n-feedback-font-size); line-height: 1.25; transform-origin: top left; `,[ae("&:not(:empty)",` padding: var(--n-feedback-padding); `),T("form-item-feedback",{transition:"color .3s var(--n-bezier)",color:"var(--n-feedback-text-color)"},[I("warning",{color:"var(--n-feedback-text-color-warning)"}),I("error",{color:"var(--n-feedback-text-color-error)"}),Vr({fromOffset:"-3px",enterDuration:".3s",leaveDuration:".2s"})])])]);var ze=function(n,e,r,t){function i(s){return s instanceof r?s:new r(function(a){a(s)})}return new(r||(r=Promise))(function(s,a){function o(l){try{u(t.next(l))}catch(g){a(g)}}function f(l){try{u(t.throw(l))}catch(g){a(g)}}function u(l){l.done?s(l.value):i(l.value).then(o,f)}u((t=t.apply(n,e||[])).next())})};const Ir=Object.assign(Object.assign({},Ce.props),{label:String,labelWidth:[Number,String],labelStyle:[String,Object],labelAlign:String,labelPlacement:String,path:String,first:Boolean,rulePath:String,required:Boolean,showRequireMark:{type:Boolean,default:void 0},requireMarkPlacement:String,showFeedback:{type:Boolean,default:void 0},rule:[Object,Array],size:String,ignorePathChange:Boolean,validationStatus:String,feedback:String,feedbackClass:String,feedbackStyle:[String,Object],showLabel:{type:Boolean,default:void 0},labelProps:Object});function Ve(n,e){return(...r)=>{try{const t=n(...r);return!e&&(typeof t=="boolean"||t instanceof Error||Array.isArray(t))||t!=null&&t.then?t:(t===void 0||Pe("form-item/validate",`You return a ${typeof t} typed value in the validator method, which is not recommended. Please use ${e?"`Promise`":"`boolean`, `Error` or `Promise`"} typed value instead.`),!0)}catch(t){Pe("form-item/validate","An error is catched in the validation, so the validation won't be done. Your callback in `validate` method of `n-form` or `n-form-item` won't be called in this validation."),console.error(t);return}}}const Jr=De({name:"FormItem",props:Ir,setup(n){er(Je,"formItems",he(n,"path"));const{mergedClsPrefixRef:e,inlineThemeDisabled:r}=Ze(n),t=le(ye,null),i=jr(n),s=Mr(n),{validationErrored:a,validationWarned:o}=s,{mergedRequired:f,mergedRules:u}=zr(n),{mergedSize:l}=i,{mergedLabelPlacement:g,mergedLabelAlign:p,mergedRequireMarkPlacement:_}=s,c=ee([]),m=ee(Oe()),R=t?he(t.props,"disabled"):ee(!1),d=Ce("Form","-form-item",Lr,Qe,n,e);Le(he(n,"path"),()=>{n.ignorePathChange||$()});function $(){c.value=[],a.value=!1,o.value=!1,n.feedback&&(m.value=Oe())}const h=(...b)=>ze(this,[...b],void 0,function*(j=null,W=()=>!0,S={suppressWarning:!0}){const{path:N}=n;S?S.first||(S.first=n.first):S={};const{value:U}=u,K=t?Ie(t.props.model,N||""):void 0,Z={},G={},D=(j?U.filter(y=>Array.isArray(y.trigger)?y.trigger.includes(j):y.trigger===j):U).filter(W).map((y,A)=>{const x=Object.assign({},y);if(x.validator&&(x.validator=Ve(x.validator,!1)),x.asyncValidator&&(x.asyncValidator=Ve(x.asyncValidator,!0)),x.renderMessage){const ge=`__renderMessage__${A}`;G[ge]=x.message,x.message=ge,Z[ge]=x.renderMessage}return x}),B=D.filter(y=>y.level!=="warning"),de=D.filter(y=>y.level==="warning"),V={valid:!0,errors:void 0,warnings:void 0};if(!D.length)return V;const Q=N??"__n_no_path__",ue=new re({[Q]:B}),ce=new re({[Q]:de}),{validateMessages:ie}=(t==null?void 0:t.props)||{};ie&&(ue.messages(ie),ce.messages(ie));const me=y=>{c.value=y.map(A=>{const x=(A==null?void 0:A.message)||"";return{key:x,render:()=>x.startsWith("__renderMessage__")?Z[x]():x}}),y.forEach(A=>{var x;!((x=A.message)===null||x===void 0)&&x.startsWith("__renderMessage__")&&(A.message=G[A.message])})};if(B.length){const y=yield new Promise(A=>{ue.validate({[Q]:K},S,A)});y!=null&&y.length&&(V.valid=!1,V.errors=y,me(y))}if(de.length&&!V.errors){const y=yield new Promise(A=>{ce.validate({[Q]:K},S,A)});y!=null&&y.length&&(me(y),V.warnings=y)}return!V.errors&&!V.warnings?$():(a.value=!!V.errors,o.value=!!V.warnings),V});function w(){h("blur")}function P(){h("change")}function F(){h("focus")}function C(){h("input")}function L(b,j){return ze(this,void 0,void 0,function*(){let W,S,N,U;return typeof b=="string"?(W=b,S=j):b!==null&&typeof b=="object"&&(W=b.trigger,S=b.callback,N=b.shouldRuleBeApplied,U=b.options),yield new Promise((K,Z)=>{h(W,N,U).then(({valid:G,errors:D,warnings:B})=>{G?(S&&S(void 0,{warn
|