物管理前端
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.
 
 
 
 

105 lines
31 KiB

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=function(R){if(l.push.apply(l,R),u++,u===f)return t(l),l.length?_(new Ae(l,qe(l))):p(i)};o.length||(t(l),p(i)),o.forEach(function(m){var R=n[m];a.indexOf(m)!==-1?Se(R,r,c):or(R,r,c)})});return g.catch(function(p){return p}),g}function dr(n){return!!(n&&n.message!==void 0)}function ur(n,e){for(var r=n,t=0;t<e.length;t++){if(r==null)return r;r=r[e[t]]}return r}function $e(n,e){return function(r){var t;return n.fullFields?t=ur(e,n.fullFields):t=e[r.field||n.fullField],dr(r)?(r.field=r.field||n.fullField,r.fieldValue=t,r):{message:typeof r=="function"?r():r,fieldValue:t,field:r.field||n.fullField}}}function Ee(n,e){if(e){for(var r in e)if(e.hasOwnProperty(r)){var t=e[r];typeof t=="object"&&typeof n[r]=="object"?n[r]=J({},n[r],t):n[r]=t}}return n}var We=function(e,r,t,i,s,a){e.required&&(!t.hasOwnProperty(e.field)||k(r,a||e.type))&&i.push(M(s.messages.required,e.fullField))},cr=function(e,r,t,i,s){(/^\s+$/.test(r)||r==="")&&i.push(M(s.messages.whitespace,e.fullField))},pe,mr=function(){if(pe)return pe;var n="[a-fA-F\\d:]",e=function(w){return w&&w.includeBoundaries?"(?:(?<=\\s|^)(?="+n+")|(?<="+n+")(?=\\s|$))":""},r="(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",t="[a-fA-F\\d]{1,4}",i=(`
(?:
(?:`+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,s),r!==void 0&&v.type(e,r,i,a,s)}t(a)},Rr=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),k(r)||v.type(e,r,i,a,s)}t(a)},kr=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),v.range(e,r,i,a,s))}t(a)},qr=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),v.range(e,r,i,a,s))}t(a)},Fr=function(e,r,t,i,s){var a=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(r==null&&!e.required)return t();v.required(e,r,i,a,s,"array"),r!=null&&(v.type(e,r,i,a,s),v.range(e,r,i,a,s))}t(a)},_r=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)},Pr="enum",Or=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[Pr](e,r,i,a,s)}t(a)},Sr=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),k(r,"string")||v.pattern(e,r,i,a,s)}t(a)},Ar=function(e,r,t,i,s){var a=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(k(r,"date")&&!e.required)return t();if(v.required(e,r,i,a,s),!k(r,"date")){var f;r instanceof Date?f=r:f=new Date(r),v.type(e,f,i,a,s),f&&v.range(e,f.getTime(),i,a,s)}}t(a)},$r=function(e,r,t,i,s){var a=[],o=Array.isArray(r)?"array":typeof r;v.required(e,r,i,a,s,o),t(a)},xe=function(e,r,t,i,s){var a=e.type,o=[],f=e.required||!e.required&&i.hasOwnProperty(e.field);if(f){if(k(r,a)&&!e.required)return t();v.required(e,r,i,o,s,a),k(r,a)||v.type(e,r,i,o,s)}t(o)},Er=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)}t(a)},oe={string:br,method:yr,number:wr,boolean:xr,regexp:Rr,integer:kr,float:qr,array:Fr,object:_r,enum:Or,pattern:Sr,date:Ar,url:xe,hex:xe,email:xe,required:$r,any:Er};function Fe(){return{default:"Validation error on field %s",required:"%s is required",enum:"%s must be one of %s",whitespace:"%s cannot be empty",date:{format:"%s date %s is invalid for format %s",parse:"%s date could not be parsed, %s is invalid ",invalid:"%s date %s is invalid"},types:{string:"%s is not a %s",method:"%s is not a %s (function)",array:"%s is not an %s",object:"%s is not an %s",number:"%s is not a %s",date:"%s is not a %s",boolean:"%s is not a %s",integer:"%s is not an %s",float:"%s is not a %s",regexp:"%s is not a valid %s",email:"%s is not a valid %s",url:"%s is not a valid %s",hex:"%s is not a valid %s"},string:{len:"%s must be exactly %s characters",min:"%s must be at least %s characters",max:"%s cannot be longer than %s characters",range:"%s must be between %s and %s characters"},number:{len:"%s must equal %s",min:"%s cannot be less than %s",max:"%s cannot be greater than %s",range:"%s must be between %s and %s"},array:{len:"%s must be exactly %s in length",min:"%s cannot be less than %s in length",max:"%s cannot be greater than %s in length",range:"%s must be between %s and %s in length"},pattern:{mismatch:"%s value %s does not match pattern %s"},clone:function(){var e=JSON.parse(JSON.stringify(this));return e.clone=this.clone,e}}}var _e=Fe(),re=function(){function n(r){this.rules=null,this._messages=_e,this.define(r)}var e=n.prototype;return e.define=function(t){var i=this;if(!t)throw new Error("Cannot configure a schema with no rules");if(typeof t!="object"||Array.isArray(t))throw new Error("Rules must be an object");this.rules={},Object.keys(t).forEach(function(s){var a=t[s];i.rules[s]=Array.isArray(a)?a:[a]})},e.messages=function(t){return t&&(this._messages=Ee(Fe(),t)),this._messages},e.validate=function(t,i,s){var a=this;i===void 0&&(i={}),s===void 0&&(s=function(){});var o=t,f=i,u=s;if(typeof f=="function"&&(u=f,f={}),!this.rules||Object.keys(this.rules).length===0)return u&&u(null,o),Promise.resolve(o);function l(m){var R=[],d={};function $(w){if(Array.isArray(w)){var P;R=(P=R).concat.apply(P,w)}else R.push(w)}for(var h=0;h<m.length;h++)$(m[h]);R.length?(d=qe(R),u(R,d)):u(null,o)}if(f.messages){var g=this.messages();g===_e&&(g=Fe()),Ee(g,f.messages),f.messages=g}else f.messages=this.messages();var p={},_=f.keys||Object.keys(this.rules);_.forEach(function(m){var R=a.rules[m],d=o[m];R.forEach(function($){var h=$;typeof h.transform=="function"&&(o===t&&(o=J({},o)),d=o[m]=h.transform(d)),typeof h=="function"?h={validator:h}:h=J({},h),h.validator=a.getValidationMethod(h),h.validator&&(h.field=m,h.fullField=h.fullField||m,h.type=a.getType(h),p[m]=p[m]||[],p[m].push({rule:h,value:d,source:o,field:m}))})});var c={};return lr(p,f,function(m,R){var d=m.rule,$=(d.type==="object"||d.type==="array")&&(typeof d.fields=="object"||typeof d.defaultField=="object");$=$&&(d.required||!d.required&&m.value),d.field=m.field;function h(F,C){return J({},C,{fullField:d.fullField+"."+F,fullFields:d.fullFields?[].concat(d.fullFields,[F]):[F]})}function w(F){F===void 0&&(F=[]);var C=Array.isArray(F)?F:[F];!f.suppressWarning&&C.length&&n.warning("async-validator:",C),C.length&&d.message!==void 0&&(C=[].concat(d.message));var L=C.map($e(d,o));if(f.first&&L.length)return c[d.field]=1,R(L);if(!$)R(L);else{if(d.required&&!m.value)return d.message!==void 0?L=[].concat(d.message).map($e(d,o)):f.error&&(L=[f.error(d,M(f.messages.required,d.field))]),R(L);var Y={};d.defaultField&&Object.keys(m.value).map(function(O){Y[O]=d.defaultField}),Y=J({},Y,m.rule.fields);var te={};Object.keys(Y).forEach(function(O){var z=Y[O],b=Array.isArray(z)?z:[z];te[O]=b.map(h.bind(null,O))});var ne=new n(te);ne.messages(f.messages),m.rule.options&&(m.rule.options.messages=f.messages,m.rule.options.error=f.error),ne.validate(m.value,m.rule.options||f,function(O){var z=[];L&&L.length&&z.push.apply(z,L),O&&O.length&&z.push.apply(z,O),R(z.length?z:null)})}}var P;if(d.asyncValidator)P=d.asyncValidator(d,m.value,w,m.source,f);else if(d.validator){try{P=d.validator(d,m.value,w,m.source,f)}catch(F){console.error==null||console.error(F),f.suppressValidatorError||setTimeout(function(){throw F},0),w(F.message)}P===!0?w():P===!1?w(typeof d.message=="function"?d.message(d.fullField||d.field):d.message||(d.fullField||d.field)+" fails"):P instanceof Array?w(P):P instanceof Error&&w(P.message)}P&&P.then&&P.then(function(){return w()},function(F){return w(F)})},function(m){l(m)},o)},e.getType=function(t){if(t.type===void 0&&t.pattern instanceof RegExp&&(t.type="pattern"),typeof t.validator!="function"&&t.type&&!oe.hasOwnProperty(t.type))throw new Error(M("Unknown rule type %s",t.type));return t.type||"string"},e.getValidationMethod=function(t){if(typeof t.validator=="function")return t.validator;var i=Object.keys(t),s=i.indexOf("message");return s!==-1&&i.splice(s,1),i.length===1&&i[0]==="required"?oe.required:oe[this.getType(t)]||void 0},n}();re.register=function(e,r){if(typeof r!="function")throw new Error("Cannot register a validator by type, validator is not a function");oe[e]=r};re.warning=ar;re.messages=_e;re.validators=oe;function jr(n){const e=le(ye,null);return{mergedSize:q(()=>n.size!==void 0?n.size:(e==null?void 0:e.props.size)!==void 0?e.props.size:"medium")}}function Mr(n){const e=le(ye,null),r=q(()=>{const{labelPlacement:c}=n;return c!==void 0?c:e!=null&&e.props.labelPlacement?e.props.labelPlacement:"top"}),t=q(()=>r.value==="left"&&(n.labelWidth==="auto"||(e==null?void 0:e.props.labelWidth)==="auto")),i=q(()=>{if(r.value==="top")return;const{labelWidth:c}=n;if(c!==void 0&&c!=="auto")return we(c);if(t.value){const m=e==null?void 0:e.maxChildLabelWidthRef.value;return m!==void 0?we(m):void 0}if((e==null?void 0:e.props.labelWidth)!==void 0)return we(e.props.labelWidth)}),s=q(()=>{const{labelAlign:c}=n;if(c)return c;if(e!=null&&e.props.labelAlign)return e.props.labelAlign}),a=q(()=>{var c;return[(c=n.labelProps)===null||c===void 0?void 0:c.style,n.labelStyle,{width:i.value}]}),o=q(()=>{const{showRequireMark:c}=n;return c!==void 0?c:e==null?void 0:e.props.showRequireMark}),f=q(()=>{const{requireMarkPlacement:c}=n;return c!==void 0?c:(e==null?void 0:e.props.requireMarkPlacement)||"right"}),u=ee(!1),l=ee(!1),g=q(()=>{const{validationStatus:c}=n;if(c!==void 0)return c;if(u.value)return"error";if(l.value)return"warning"}),p=q(()=>{const{showFeedback:c}=n;return c!==void 0?c:(e==null?void 0:e.props.showFeedback)!==void 0?e.props.showFeedback:!0}),_=q(()=>{const{showLabel:c}=n;return c!==void 0?c:(e==null?void 0:e.props.showLabel)!==void 0?e.props.showLabel:!0});return{validationErrored:u,validationWarned:l,mergedLabelStyle:a,mergedLabelPlacement:r,mergedLabelAlign:s,mergedShowRequireMark:o,mergedRequireMarkPlacement:f,mergedValidationStatus:g,mergedShowFeedback:p,mergedShowLabel:_,isAutoLabelWidth:t}}function zr(n){const e=le(ye,null),r=q(()=>{const{rulePath:a}=n;if(a!==void 0)return a;const{path:o}=n;if(o!==void 0)return o}),t=q(()=>{const a=[],{rule:o}=n;if(o!==void 0&&(Array.isArray(o)?a.push(...o):a.push(o)),e){const{rules:f}=e.props,{value:u}=r;if(f!==void 0&&u!==void 0){const l=Ie(f,u);l!==void 0&&(Array.isArray(l)?a.push(...l):a.push(l))}}return a}),i=q(()=>t.value.some(a=>a.required)),s=q(()=>i.value||n.required);return{mergedRules:t,mergedRequired:s}}const{cubicBezierEaseInOut:Me}=Ke;function Vr({name:n="fade-down",fromOffset:e="-4px",enterDuration:r=".3s",leaveDuration:t=".3s",enterCubicBezier:i=Me,leaveCubicBezier:s=Me}={}){return[ae(`&.${n}-transition-enter-from, &.${n}-transition-leave-to`,{opacity:0,transform:`translateY(${e})`}),ae(`&.${n}-transition-enter-to, &.${n}-transition-leave-from`,{opacity:1,transform:"translateY(0)"}),ae(`&.${n}-transition-leave-active`,{transition:`opacity ${t} ${s}, transform ${t} ${s}`}),ae(`&.${n}-transition-enter-active`,{transition:`opacity ${r} ${i}, transform ${r} ${i}`})]}const Lr=T("form-item",`
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,{warnings:B}),K({warnings:B})):(S&&S(D,{warnings:B}),Z(D))})})})}Be(Ue,{path:he(n,"path"),disabled:R,mergedSize:i.mergedSize,mergedValidationStatus:s.mergedValidationStatus,restoreValidation:$,handleContentBlur:w,handleContentChange:P,handleContentFocus:F,handleContentInput:C});const Y={validate:L,restoreValidation:$,internalValidate:h},te=ee(null);He(()=>{if(!s.isAutoLabelWidth.value)return;const b=te.value;if(b!==null){const j=b.style.whiteSpace;b.style.whiteSpace="nowrap",b.style.width="",t==null||t.deriveMaxChildLabelWidth(Number(getComputedStyle(b).width.slice(0,-2))),b.style.whiteSpace=j}});const ne=q(()=>{var b;const{value:j}=l,{value:W}=g,S=W==="top"?"vertical":"horizontal",{common:{cubicBezierEaseInOut:N},self:{labelTextColor:U,asteriskColor:K,lineHeight:Z,feedbackTextColor:G,feedbackTextColorWarning:D,feedbackTextColorError:B,feedbackPadding:de,labelFontWeight:V,[H("labelHeight",j)]:Q,[H("blankHeight",j)]:ue,[H("feedbackFontSize",j)]:ce,[H("feedbackHeight",j)]:ie,[H("labelPadding",S)]:me,[H("labelTextAlign",S)]:y,[H(H("labelFontSize",W),j)]:A}}=d.value;let x=(b=p.value)!==null&&b!==void 0?b:y;return W==="top"&&(x=x==="right"?"flex-end":"flex-start"),{"--n-bezier":N,"--n-line-height":Z,"--n-blank-height":ue,"--n-label-font-size":A,"--n-label-text-align":x,"--n-label-height":Q,"--n-label-padding":me,"--n-label-font-weight":V,"--n-asterisk-color":K,"--n-label-text-color":U,"--n-feedback-padding":de,"--n-feedback-font-size":ce,"--n-feedback-height":ie,"--n-feedback-text-color":G,"--n-feedback-text-color-warning":D,"--n-feedback-text-color-error":B}}),O=r?Ge("form-item",q(()=>{var b;return`${l.value[0]}${g.value[0]}${((b=p.value)===null||b===void 0?void 0:b[0])||""}`}),ne,n):void 0,z=q(()=>g.value==="left"&&_.value==="left"&&p.value==="left");return Object.assign(Object.assign(Object.assign(Object.assign({labelElementRef:te,mergedClsPrefix:e,mergedRequired:f,feedbackId:m,renderExplains:c,reverseColSpace:z},s),i),Y),{cssVars:r?void 0:ne,themeClass:O==null?void 0:O.themeClass,onRender:O==null?void 0:O.onRender})},render(){const{$slots:n,mergedClsPrefix:e,mergedShowLabel:r,mergedShowRequireMark:t,mergedRequireMarkPlacement:i,onRender:s}=this,a=t!==void 0?t:this.mergedRequired;s==null||s();const o=()=>{const f=this.$slots.label?this.$slots.label():this.label;if(!f)return null;const u=E("span",{class:`${e}-form-item-label__text`},f),l=a?E("span",{class:`${e}-form-item-label__asterisk`},i!=="left"?" *":"* "):i==="right-hanging"&&E("span",{class:`${e}-form-item-label__asterisk-placeholder`}," *"),{labelProps:g}=this;return E("label",Object.assign({},g,{class:[g==null?void 0:g.class,`${e}-form-item-label`,`${e}-form-item-label--${i}-mark`,this.reverseColSpace&&`${e}-form-item-label--reverse-columns-space`],style:this.mergedLabelStyle,ref:"labelElementRef"}),i==="left"?[l,u]:[u,l])};return E("div",{class:[`${e}-form-item`,this.themeClass,`${e}-form-item--${this.mergedSize}-size`,`${e}-form-item--${this.mergedLabelPlacement}-labelled`,this.isAutoLabelWidth&&`${e}-form-item--auto-label-width`,!r&&`${e}-form-item--no-label`],style:this.cssVars},r&&o(),E("div",{class:[`${e}-form-item-blank`,this.mergedValidationStatus&&`${e}-form-item-blank--${this.mergedValidationStatus}`]},n),this.mergedShowFeedback?E("div",{key:this.feedbackId,style:this.feedbackStyle,class:[`${e}-form-item-feedback-wrapper`,this.feedbackClass]},E(Ye,{name:"fade-down-transition",mode:"out-in"},{default:()=>{const{mergedValidationStatus:f}=this;return Xe(n.feedback,u=>{var l;const{feedback:g}=this,p=u||g?E("div",{key:"__feedback__",class:`${e}-form-item-feedback__line`},u||g):this.renderExplains.length?(l=this.renderExplains)===null||l===void 0?void 0:l.map(({key:_,render:c})=>E("div",{key:_,class:`${e}-form-item-feedback__line`},c())):null;return p?f==="warning"?E("div",{key:"controlled-warning",class:`${e}-form-item-feedback ${e}-form-item-feedback--warning`},p):f==="error"?E("div",{key:"controlled-error",class:`${e}-form-item-feedback ${e}-form-item-feedback--error`},p):f==="success"?E("div",{key:"controlled-success",class:`${e}-form-item-feedback ${e}-form-item-feedback--success`},p):E("div",{key:"controlled-default",class:`${e}-form-item-feedback`},p):null})}})):null)}});export{Jr as _};