xt-admin/public/statics/build/admin/assets/FormItem.a93ea502.js
2022-11-05 17:45:11 +08:00

108 lines
31 KiB
JavaScript

import{m as te,n as ze,q as Me,s as Be,t as T,u as C,v as X,x as Ie,d as je,y as Te,z as ue,r as Z,A as ge,B as P,C as Le,D as xe,E as S,F as me,G as $e,H as We,I as oe,J as de,K as we,L as He,M as Ge,N as U,O as Ye,T as Ke,P as Je,Q as ke}from"./index.435adb25.js";function Xe(r,e,n){var t;const i=te(r,null);if(i===null)return;const s=(t=ze())===null||t===void 0?void 0:t.proxy;Me(n,a),a(n.value),Be(()=>{a(void 0,n.value)});function a(f,l){const m=i[e];l!==void 0&&o(m,l),f!==void 0&&d(m,f)}function o(f,l){f[l]||(f[l]=[]),f[l].splice(f[l].findIndex(m=>m===s),1)}function d(f,l){f[l]||(f[l]=[]),~f[l].findIndex(m=>m===s)||f[l].push(s)}}const Ze=T("form",[C("inline",`
width: 100%;
display: inline-flex;
align-items: flex-start;
align-content: space-around;
`,[T("form-item",{width:"auto",marginRight:"18px"},[X("&:last-child",{marginRight:0})])])]),re=Ie("n-form"),Ce=Ie("n-form-item-insts");var Qe=globalThis&&globalThis.__awaiter||function(r,e,n,t){function i(s){return s instanceof n?s:new n(function(a){a(s)})}return new(n||(n=Promise))(function(s,a){function o(l){try{f(t.next(l))}catch(m){a(m)}}function d(l){try{f(t.throw(l))}catch(m){a(m)}}function f(l){l.done?s(l.value):i(l.value).then(o,d)}f((t=t.apply(r,e||[])).next())})};const en=Object.assign(Object.assign({},ue.props),{inline:Boolean,labelWidth:[Number,String],labelAlign:String,labelPlacement:{type:String,default:"top"},model:{type:Object,default:()=>{}},rules:Object,disabled:Boolean,size:String,showRequireMark:{type:Boolean,default:void 0},requireMarkPlacement:String,showFeedback:{type:Boolean,default:!0},onSubmit:{type:Function,default:r=>r.preventDefault()},showLabel:{type:Boolean,default:void 0},validateMessages:Object}),Un=je({name:"Form",props:en,setup(r){const{mergedClsPrefixRef:e}=Te(r);ue("Form","-form",Ze,Le,r,e);const n={},t=Z(void 0),i=d=>{const f=t.value;(f===void 0||d>=f)&&(t.value=d)};function s(d,f=()=>!0){return Qe(this,void 0,void 0,function*(){return yield new Promise((l,m)=>{const h=[];for(const c of xe(n)){const y=n[c];for(const p of y)p.path&&h.push(p.internalValidate(null,f))}Promise.all(h).then(c=>{if(c.some(y=>!y.valid)){const y=c.filter(p=>p.errors).map(p=>p.errors);d&&d(y),m(y)}else d&&d(),l()})})})}function a(){for(const d of xe(n)){const f=n[d];for(const l of f)l.restoreValidation()}}return ge(re,{props:r,maxChildLabelWidthRef:t,deriveMaxChildLabelWidth:i}),ge(Ce,{formItems:n}),Object.assign({validate:s,restoreValidation:a},{mergedClsPrefix:e})},render(){const{mergedClsPrefix:r}=this;return P("form",{class:[`${r}-form`,this.inline&&`${r}-form--inline`],onSubmit:this.onSubmit},this.$slots)}});function W(){return W=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r},W.apply(this,arguments)}function nn(r,e){r.prototype=Object.create(e.prototype),r.prototype.constructor=r,ne(r,e)}function ve(r){return ve=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},ve(r)}function ne(r,e){return ne=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,i){return t.__proto__=i,t},ne(r,e)}function tn(){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 fe(r,e,n){return tn()?fe=Reflect.construct.bind():fe=function(i,s,a){var o=[null];o.push.apply(o,s);var d=Function.bind.apply(i,o),f=new d;return a&&ne(f,a.prototype),f},fe.apply(null,arguments)}function rn(r){return Function.toString.call(r).indexOf("[native code]")!==-1}function he(r){var e=typeof Map=="function"?new Map:void 0;return he=function(t){if(t===null||!rn(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 fe(t,arguments,ve(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),ne(i,t)},he(r)}var an=/%[sdj%]/g,sn=function(){};function be(r){if(!r||!r.length)return null;var e={};return r.forEach(function(n){var t=n.field;e[t]=e[t]||[],e[t].push(n)}),e}function M(r){for(var e=arguments.length,n=new Array(e>1?e-1:0),t=1;t<e;t++)n[t-1]=arguments[t];var i=0,s=n.length;if(typeof r=="function")return r.apply(null,n);if(typeof r=="string"){var a=r.replace(an,function(o){if(o==="%%")return"%";if(i>=s)return o;switch(o){case"%s":return String(n[i++]);case"%d":return Number(n[i++]);case"%j":try{return JSON.stringify(n[i++])}catch{return"[Circular]"}break;default:return o}});return a}return r}function on(r){return r==="string"||r==="url"||r==="hex"||r==="email"||r==="date"||r==="pattern"}function O(r,e){return!!(r==null||e==="array"&&Array.isArray(r)&&!r.length||on(e)&&typeof r=="string"&&!r)}function dn(r,e,n){var t=[],i=0,s=r.length;function a(o){t.push.apply(t,o||[]),i++,i===s&&n(t)}r.forEach(function(o){e(o,a)})}function Re(r,e,n){var t=0,i=r.length;function s(a){if(a&&a.length){n(a);return}var o=t;t=t+1,o<i?e(r[o],s):n([])}s([])}function ln(r){var e=[];return Object.keys(r).forEach(function(n){e.push.apply(e,r[n]||[])}),e}var Ee=function(r){nn(e,r);function e(n,t){var i;return i=r.call(this,"Async Validation Error")||this,i.errors=n,i.fields=t,i}return e}(he(Error));function fn(r,e,n,t,i){if(e.first){var s=new Promise(function(h,c){var y=function(u){return t(u),u.length?c(new Ee(u,be(u))):h(i)},p=ln(r);Re(p,n,y)});return s.catch(function(h){return h}),s}var a=e.firstFields===!0?Object.keys(r):e.firstFields||[],o=Object.keys(r),d=o.length,f=0,l=[],m=new Promise(function(h,c){var y=function(_){if(l.push.apply(l,_),f++,f===d)return t(l),l.length?c(new Ee(l,be(l))):h(i)};o.length||(t(l),h(i)),o.forEach(function(p){var _=r[p];a.indexOf(p)!==-1?Re(_,n,y):dn(_,n,y)})});return m.catch(function(h){return h}),m}function un(r){return!!(r&&r.message!==void 0)}function cn(r,e){for(var n=r,t=0;t<e.length;t++){if(n==null)return n;n=n[e[t]]}return n}function Oe(r,e){return function(n){var t;return r.fullFields?t=cn(e,r.fullFields):t=e[n.field||r.fullField],un(n)?(n.field=n.field||r.fullField,n.fieldValue=t,n):{message:typeof n=="function"?n():n,fieldValue:t,field:n.field||r.fullField}}}function Se(r,e){if(e){for(var n in e)if(e.hasOwnProperty(n)){var t=e[n];typeof t=="object"&&typeof r[n]=="object"?r[n]=W({},r[n],t):r[n]=t}}return r}var De=function(e,n,t,i,s,a){e.required&&(!t.hasOwnProperty(e.field)||O(n,a||e.type))&&i.push(M(s.messages.required,e.fullField))},mn=function(e,n,t,i,s){(/^\s+$/.test(n)||n==="")&&i.push(M(s.messages.whitespace,e.fullField))},le,pn=function(){if(le)return le;var r="[a-fA-F\\d:]",e=function(x){return x&&x.includeBoundaries?"(?:(?<=\\s|^)(?="+r+")|(?<="+r+")(?=\\s|$))":""},n="(?: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}(?:"+n+"|:"+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}(?::"+n+"|(?::"+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}:"+n+"|(?::"+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}:"+n+"|(?::"+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}:"+n+"|(?::"+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}:"+n+"|(?::"+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}:"+n+"|(?::"+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("(?:^"+n+"$)|(?:^"+i+"$)"),a=new RegExp("^"+n+"$"),o=new RegExp("^"+i+"$"),d=function(x){return x&&x.exact?s:new RegExp("(?:"+e(x)+n+e(x)+")|(?:"+e(x)+i+e(x)+")","g")};d.v4=function(g){return g&&g.exact?a:new RegExp(""+e(g)+n+e(g),"g")},d.v6=function(g){return g&&g.exact?o:new RegExp(""+e(g)+i+e(g),"g")};var f="(?:(?:[a-z]+:)?//)",l="(?:\\S+(?::\\S*)?@)?",m=d.v4().source,h=d.v6().source,c="(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)",y="(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*",p="(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))",_="(?::\\d{2,5})?",u='(?:[/?#][^\\s"]*)?',j="(?:"+f+"|www\\.)"+l+"(?:localhost|"+m+"|"+h+"|"+c+y+p+")"+_+u;return le=new RegExp("(?:^"+j+"$)","i"),le},qe={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},Q={integer:function(e){return Q.number(e)&&parseInt(e,10)===e},float:function(e){return Q.number(e)&&!Q.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"&&!Q.array(e)},method:function(e){return typeof e=="function"},email:function(e){return typeof e=="string"&&e.length<=320&&!!e.match(qe.email)},url:function(e){return typeof e=="string"&&e.length<=2048&&!!e.match(pn())},hex:function(e){return typeof e=="string"&&!!e.match(qe.hex)}},gn=function(e,n,t,i,s){if(e.required&&n===void 0){De(e,n,t,i,s);return}var a=["integer","float","array","regexp","object","method","email","number","date","url","hex"],o=e.type;a.indexOf(o)>-1?Q[o](n)||i.push(M(s.messages.types[o],e.fullField,e.type)):o&&typeof n!==e.type&&i.push(M(s.messages.types[o],e.fullField,e.type))},vn=function(e,n,t,i,s){var a=typeof e.len=="number",o=typeof e.min=="number",d=typeof e.max=="number",f=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,l=n,m=null,h=typeof n=="number",c=typeof n=="string",y=Array.isArray(n);if(h?m="number":c?m="string":y&&(m="array"),!m)return!1;y&&(l=n.length),c&&(l=n.replace(f,"_").length),a?l!==e.len&&i.push(M(s.messages[m].len,e.fullField,e.len)):o&&!d&&l<e.min?i.push(M(s.messages[m].min,e.fullField,e.min)):d&&!o&&l>e.max?i.push(M(s.messages[m].max,e.fullField,e.max)):o&&d&&(l<e.min||l>e.max)&&i.push(M(s.messages[m].range,e.fullField,e.min,e.max))},J="enum",hn=function(e,n,t,i,s){e[J]=Array.isArray(e[J])?e[J]:[],e[J].indexOf(n)===-1&&i.push(M(s.messages[J],e.fullField,e[J].join(", ")))},bn=function(e,n,t,i,s){if(e.pattern){if(e.pattern instanceof RegExp)e.pattern.lastIndex=0,e.pattern.test(n)||i.push(M(s.messages.pattern.mismatch,e.fullField,n,e.pattern));else if(typeof e.pattern=="string"){var a=new RegExp(e.pattern);a.test(n)||i.push(M(s.messages.pattern.mismatch,e.fullField,n,e.pattern))}}},v={required:De,whitespace:mn,type:gn,range:vn,enum:hn,pattern:bn},_n=function(e,n,t,i,s){var a=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(O(n,"string")&&!e.required)return t();v.required(e,n,i,a,s,"string"),O(n,"string")||(v.type(e,n,i,a,s),v.range(e,n,i,a,s),v.pattern(e,n,i,a,s),e.whitespace===!0&&v.whitespace(e,n,i,a,s))}t(a)},yn=function(e,n,t,i,s){var a=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(O(n)&&!e.required)return t();v.required(e,n,i,a,s),n!==void 0&&v.type(e,n,i,a,s)}t(a)},xn=function(e,n,t,i,s){var a=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(n===""&&(n=void 0),O(n)&&!e.required)return t();v.required(e,n,i,a,s),n!==void 0&&(v.type(e,n,i,a,s),v.range(e,n,i,a,s))}t(a)},wn=function(e,n,t,i,s){var a=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(O(n)&&!e.required)return t();v.required(e,n,i,a,s),n!==void 0&&v.type(e,n,i,a,s)}t(a)},kn=function(e,n,t,i,s){var a=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(O(n)&&!e.required)return t();v.required(e,n,i,a,s),O(n)||v.type(e,n,i,a,s)}t(a)},Rn=function(e,n,t,i,s){var a=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(O(n)&&!e.required)return t();v.required(e,n,i,a,s),n!==void 0&&(v.type(e,n,i,a,s),v.range(e,n,i,a,s))}t(a)},En=function(e,n,t,i,s){var a=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(O(n)&&!e.required)return t();v.required(e,n,i,a,s),n!==void 0&&(v.type(e,n,i,a,s),v.range(e,n,i,a,s))}t(a)},On=function(e,n,t,i,s){var a=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(n==null&&!e.required)return t();v.required(e,n,i,a,s,"array"),n!=null&&(v.type(e,n,i,a,s),v.range(e,n,i,a,s))}t(a)},Sn=function(e,n,t,i,s){var a=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(O(n)&&!e.required)return t();v.required(e,n,i,a,s),n!==void 0&&v.type(e,n,i,a,s)}t(a)},qn="enum",Fn=function(e,n,t,i,s){var a=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(O(n)&&!e.required)return t();v.required(e,n,i,a,s),n!==void 0&&v[qn](e,n,i,a,s)}t(a)},Pn=function(e,n,t,i,s){var a=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(O(n,"string")&&!e.required)return t();v.required(e,n,i,a,s),O(n,"string")||v.pattern(e,n,i,a,s)}t(a)},An=function(e,n,t,i,s){var a=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(O(n,"date")&&!e.required)return t();if(v.required(e,n,i,a,s),!O(n,"date")){var d;n instanceof Date?d=n:d=new Date(n),v.type(e,d,i,a,s),d&&v.range(e,d.getTime(),i,a,s)}}t(a)},Mn=function(e,n,t,i,s){var a=[],o=Array.isArray(n)?"array":typeof n;v.required(e,n,i,a,s,o),t(a)},pe=function(e,n,t,i,s){var a=e.type,o=[],d=e.required||!e.required&&i.hasOwnProperty(e.field);if(d){if(O(n,a)&&!e.required)return t();v.required(e,n,i,o,s,a),O(n,a)||v.type(e,n,i,o,s)}t(o)},In=function(e,n,t,i,s){var a=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(O(n)&&!e.required)return t();v.required(e,n,i,a,s)}t(a)},ee={string:_n,method:yn,number:xn,boolean:wn,regexp:kn,integer:Rn,float:En,array:On,object:Sn,enum:Fn,pattern:Pn,date:An,url:pe,hex:pe,email:pe,required:Mn,any:In};function _e(){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 ye=_e(),ie=function(){function r(n){this.rules=null,this._messages=ye,this.define(n)}var e=r.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=Se(_e(),t)),this._messages},e.validate=function(t,i,s){var a=this;i===void 0&&(i={}),s===void 0&&(s=function(){});var o=t,d=i,f=s;if(typeof d=="function"&&(f=d,d={}),!this.rules||Object.keys(this.rules).length===0)return f&&f(null,o),Promise.resolve(o);function l(p){var _=[],u={};function j(x){if(Array.isArray(x)){var q;_=(q=_).concat.apply(q,x)}else _.push(x)}for(var g=0;g<p.length;g++)j(p[g]);_.length?(u=be(_),f(_,u)):f(null,o)}if(d.messages){var m=this.messages();m===ye&&(m=_e()),Se(m,d.messages),d.messages=m}else d.messages=this.messages();var h={},c=d.keys||Object.keys(this.rules);c.forEach(function(p){var _=a.rules[p],u=o[p];_.forEach(function(j){var g=j;typeof g.transform=="function"&&(o===t&&(o=W({},o)),u=o[p]=g.transform(u)),typeof g=="function"?g={validator:g}:g=W({},g),g.validator=a.getValidationMethod(g),g.validator&&(g.field=p,g.fullField=g.fullField||p,g.type=a.getType(g),h[p]=h[p]||[],h[p].push({rule:g,value:u,source:o,field:p}))})});var y={};return fn(h,d,function(p,_){var u=p.rule,j=(u.type==="object"||u.type==="array")&&(typeof u.fields=="object"||typeof u.defaultField=="object");j=j&&(u.required||!u.required&&p.value),u.field=p.field;function g(k,D){return W({},D,{fullField:u.fullField+"."+k,fullFields:u.fullFields?[].concat(u.fullFields,[k]):[k]})}function x(k){k===void 0&&(k=[]);var D=Array.isArray(k)?k:[k];!d.suppressWarning&&D.length&&r.warning("async-validator:",D),D.length&&u.message!==void 0&&(D=[].concat(u.message));var I=D.map(Oe(u,o));if(d.first&&I.length)return y[u.field]=1,_(I);if(!j)_(I);else{if(u.required&&!p.value)return u.message!==void 0?I=[].concat(u.message).map(Oe(u,o)):d.error&&(I=[d.error(u,M(d.messages.required,u.field))]),_(I);var V={};u.defaultField&&Object.keys(p.value).map(function(R){V[R]=u.defaultField}),V=W({},V,p.rule.fields);var N={};Object.keys(V).forEach(function(R){var w=V[R],F=Array.isArray(w)?w:[w];N[R]=F.map(g.bind(null,R))});var b=new r(N);b.messages(d.messages),p.rule.options&&(p.rule.options.messages=d.messages,p.rule.options.error=d.error),b.validate(p.value,p.rule.options||d,function(R){var w=[];I&&I.length&&w.push.apply(w,I),R&&R.length&&w.push.apply(w,R),_(w.length?w:null)})}}var q;if(u.asyncValidator)q=u.asyncValidator(u,p.value,x,p.source,d);else if(u.validator){try{q=u.validator(u,p.value,x,p.source,d)}catch(k){console.error==null||console.error(k),d.suppressValidatorError||setTimeout(function(){throw k},0),x(k.message)}q===!0?x():q===!1?x(typeof u.message=="function"?u.message(u.fullField||u.field):u.message||(u.fullField||u.field)+" fails"):q instanceof Array?x(q):q instanceof Error&&x(q.message)}q&&q.then&&q.then(function(){return x()},function(k){return x(k)})},function(p){l(p)},o)},e.getType=function(t){if(t.type===void 0&&t.pattern instanceof RegExp&&(t.type="pattern"),typeof t.validator!="function"&&t.type&&!ee.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"?ee.required:ee[this.getType(t)]||void 0},r}();ie.register=function(e,n){if(typeof n!="function")throw new Error("Cannot register a validator by type, validator is not a function");ee[e]=n};ie.warning=sn;ie.messages=ye;ie.validators=ee;function jn(r){const e=te(re,null);return{mergedSize:S(()=>r.size!==void 0?r.size:(e==null?void 0:e.props.size)!==void 0?e.props.size:"medium")}}function Tn(r){const e=te(re,null),n=S(()=>{const{labelPlacement:c}=r;return c!==void 0?c:e!=null&&e.props.labelPlacement?e.props.labelPlacement:"top"}),t=S(()=>n.value==="left"&&(r.labelWidth==="auto"||(e==null?void 0:e.props.labelWidth)==="auto")),i=S(()=>{if(n.value==="top")return;const{labelWidth:c}=r;if(c!==void 0&&c!=="auto")return me(c);if(t.value){const y=e==null?void 0:e.maxChildLabelWidthRef.value;return y!==void 0?me(y):void 0}if((e==null?void 0:e.props.labelWidth)!==void 0)return me(e.props.labelWidth)}),s=S(()=>{const{labelAlign:c}=r;if(c)return c;if(e!=null&&e.props.labelAlign)return e.props.labelAlign}),a=S(()=>{var c;return[(c=r.labelProps)===null||c===void 0?void 0:c.style,r.labelStyle,{width:i.value}]}),o=S(()=>{const{showRequireMark:c}=r;return c!==void 0?c:e==null?void 0:e.props.showRequireMark}),d=S(()=>{const{requireMarkPlacement:c}=r;return c!==void 0?c:(e==null?void 0:e.props.requireMarkPlacement)||"right"}),f=Z(!1),l=S(()=>{const{validationStatus:c}=r;if(c!==void 0)return c;if(f.value)return"error"}),m=S(()=>{const{showFeedback:c}=r;return c!==void 0?c:(e==null?void 0:e.props.showFeedback)!==void 0?e.props.showFeedback:!0}),h=S(()=>{const{showLabel:c}=r;return c!==void 0?c:(e==null?void 0:e.props.showLabel)!==void 0?e.props.showLabel:!0});return{validationErrored:f,mergedLabelStyle:a,mergedLabelPlacement:n,mergedLabelAlign:s,mergedShowRequireMark:o,mergedRequireMarkPlacement:d,mergedValidationStatus:l,mergedShowFeedback:m,mergedShowLabel:h,isAutoLabelWidth:t}}function Ln(r){const e=te(re,null),n=S(()=>{const{rulePath:a}=r;if(a!==void 0)return a;const{path:o}=r;if(o!==void 0)return o}),t=S(()=>{const a=[],{rule:o}=r;if(o!==void 0&&(Array.isArray(o)?a.push(...o):a.push(o)),e){const{rules:d}=e.props,{value:f}=n;if(d!==void 0&&f!==void 0){const l=$e(d,f);l!==void 0&&(Array.isArray(l)?a.push(...l):a.push(l))}}return a}),i=S(()=>t.value.some(a=>a.required)),s=S(()=>i.value||r.required);return{mergedRules:t,mergedRequired:s}}const{cubicBezierEaseInOut:Fe}=We;function $n({name:r="fade-down",fromOffset:e="-4px",enterDuration:n=".3s",leaveDuration:t=".3s",enterCubicBezier:i=Fe,leaveCubicBezier:s=Fe}={}){return[X(`&.${r}-transition-enter-from, &.${r}-transition-leave-to`,{opacity:0,transform:`translateY(${e})`}),X(`&.${r}-transition-enter-to, &.${r}-transition-leave-from`,{opacity:1,transform:"translateY(0)"}),X(`&.${r}-transition-leave-active`,{transition:`opacity ${t} ${s}, transform ${t} ${s}`}),X(`&.${r}-transition-enter-active`,{transition:`opacity ${n} ${i}, transform ${n} ${i}`})]}const Cn=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;
`,[oe("asterisk",`
white-space: nowrap;
user-select: none;
-webkit-user-select: none;
color: var(--n-asterisk-color);
transition: color .3s var(--n-bezier);
`),oe("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);
`),C("auto-label-width",[T("form-item-label","white-space: nowrap;")]),C("left-labelled",`
grid-template-areas:
"label blank"
"label feedback";
grid-template-columns: auto minmax(0, 1fr);
grid-template-rows: auto 1fr;
align-items: 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;
`,[C("left-mark",`
grid-template-areas:
"mark text"
". text";
`),C("right-mark",`
grid-template-areas:
"text mark"
"text .";
`),C("right-hanging-mark",`
grid-template-areas:
"text mark"
"text .";
`),oe("text",`
grid-area: text;
`),oe("asterisk",`
grid-area: mark;
align-self: end;
`)])]),C("top-labelled",`
grid-template-areas:
"label"
"blank"
"feedback";
grid-template-rows: minmax(var(--n-label-height), auto) 1fr;
grid-template-columns: minmax(0, 100%);
`,[C("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;
`,[X("&:not(:empty)",`
padding: var(--n-feedback-padding);
`),T("form-item-feedback",{transition:"color .3s var(--n-bezier)",color:"var(--n-feedback-text-color)"},[C("warning",{color:"var(--n-feedback-text-color-warning)"}),C("error",{color:"var(--n-feedback-text-color-error)"}),$n({fromOffset:"-3px",enterDuration:".3s",leaveDuration:".2s"})])])]);var Pe=globalThis&&globalThis.__awaiter||function(r,e,n,t){function i(s){return s instanceof n?s:new n(function(a){a(s)})}return new(n||(n=Promise))(function(s,a){function o(l){try{f(t.next(l))}catch(m){a(m)}}function d(l){try{f(t.throw(l))}catch(m){a(m)}}function f(l){l.done?s(l.value):i(l.value).then(o,d)}f((t=t.apply(r,e||[])).next())})};const Dn=Object.assign(Object.assign({},ue.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,showLabel:{type:Boolean,default:void 0},labelProps:Object});function Ae(r,e){return(...n)=>{try{const t=r(...n);return!e&&(typeof t=="boolean"||t instanceof Error||Array.isArray(t))||(t==null?void 0:t.then)?t:(t===void 0||ke("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){ke("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 zn=je({name:"FormItem",props:Dn,setup(r){Xe(Ce,"formItems",de(r,"path"));const{mergedClsPrefixRef:e,inlineThemeDisabled:n}=Te(r),t=te(re,null),i=jn(r),s=Tn(r),{validationErrored:a}=s,{mergedRequired:o,mergedRules:d}=Ln(r),{mergedSize:f}=i,{mergedLabelPlacement:l,mergedLabelAlign:m}=s,h=Z([]),c=Z(we()),y=t?de(t.props,"disabled"):Z(!1),p=ue("Form","-form-item",Cn,Le,r,e);Me(de(r,"path"),()=>{r.ignorePathChange||_()});function _(){h.value=[],a.value=!1,r.feedback&&(c.value=we())}function u(){k("blur")}function j(){k("change")}function g(){k("focus")}function x(){k("input")}function q(b,R){return Pe(this,void 0,void 0,function*(){let w,F,z,H;return typeof b=="string"?(w=b,F=R):b!==null&&typeof b=="object"&&(w=b.trigger,F=b.callback,z=b.shouldRuleBeApplied,H=b.options),yield new Promise((G,Y)=>{k(w,z,H).then(({valid:K,errors:B})=>{K?(F&&F(),G()):(F&&F(B),Y(B))})})})}const k=(b=null,R=()=>!0,w={suppressWarning:!0})=>Pe(this,void 0,void 0,function*(){const{path:F}=r;w?w.first||(w.first=r.first):w={};const{value:z}=d,H=t?$e(t.props.model,F||""):void 0,G={},Y={},K=(b?z.filter(L=>Array.isArray(L.trigger)?L.trigger.includes(b):L.trigger===b):z).filter(R).map((L,$)=>{const E=Object.assign({},L);if(E.validator&&(E.validator=Ae(E.validator,!1)),E.asyncValidator&&(E.asyncValidator=Ae(E.asyncValidator,!0)),E.renderMessage){const A=`__renderMessage__${$}`;Y[A]=E.message,E.message=A,G[A]=E.renderMessage}return E});if(!K.length)return{valid:!0};const B=F!=null?F:"__n_no_path__",ae=new ie({[B]:K}),{validateMessages:se}=(t==null?void 0:t.props)||{};return se&&ae.messages(se),yield new Promise(L=>{ae.validate({[B]:H},w,$=>{$!=null&&$.length?(h.value=$.map(E=>{const A=(E==null?void 0:E.message)||"";return{key:A,render:()=>A.startsWith("__renderMessage__")?G[A]():A}}),$.forEach(E=>{var A;!((A=E.message)===null||A===void 0)&&A.startsWith("__renderMessage__")&&(E.message=Y[E.message])}),a.value=!0,L({valid:!1,errors:$})):(_(),L({valid:!0}))})})});ge(He,{path:de(r,"path"),disabled:y,mergedSize:i.mergedSize,mergedValidationStatus:s.mergedValidationStatus,restoreValidation:_,handleContentBlur:u,handleContentChange:j,handleContentFocus:g,handleContentInput:x});const D={validate:q,restoreValidation:_,internalValidate:k},I=Z(null);Ge(()=>{if(!s.isAutoLabelWidth.value)return;const b=I.value;if(b!==null){const R=b.style.whiteSpace;b.style.whiteSpace="nowrap",b.style.width="",t==null||t.deriveMaxChildLabelWidth(Number(getComputedStyle(b).width.slice(0,-2))),b.style.whiteSpace=R}});const V=S(()=>{var b;const{value:R}=f,{value:w}=l,F=w==="top"?"vertical":"horizontal",{common:{cubicBezierEaseInOut:z},self:{labelTextColor:H,asteriskColor:G,lineHeight:Y,feedbackTextColor:K,feedbackTextColorWarning:B,feedbackTextColorError:ae,feedbackPadding:se,[U("labelHeight",R)]:L,[U("blankHeight",R)]:$,[U("feedbackFontSize",R)]:E,[U("feedbackHeight",R)]:A,[U("labelPadding",F)]:Ne,[U("labelTextAlign",F)]:Ve,[U(U("labelFontSize",w),R)]:Ue}}=p.value;let ce=(b=m.value)!==null&&b!==void 0?b:Ve;return w==="top"&&(ce=ce==="right"?"flex-end":"flex-start"),{"--n-bezier":z,"--n-line-height":Y,"--n-blank-height":$,"--n-label-font-size":Ue,"--n-label-text-align":ce,"--n-label-height":L,"--n-label-padding":Ne,"--n-asterisk-color":G,"--n-label-text-color":H,"--n-feedback-padding":se,"--n-feedback-font-size":E,"--n-feedback-height":A,"--n-feedback-text-color":K,"--n-feedback-text-color-warning":B,"--n-feedback-text-color-error":ae}}),N=Ye("form-item",S(()=>{var b;return`${f.value[0]}${l.value[0]}${((b=m.value)===null||b===void 0?void 0:b[0])||""}`}),V,r);return Object.assign(Object.assign(Object.assign(Object.assign({labelElementRef:I,mergedClsPrefix:e,mergedRequired:o,feedbackId:c,renderExplains:h},s),i),D),{cssVars:n?void 0:V,themeClass:N==null?void 0:N.themeClass,onRender:N==null?void 0:N.onRender})},render(){const{$slots:r,mergedClsPrefix:e,mergedShowLabel:n,mergedShowRequireMark:t,mergedRequireMarkPlacement:i,onRender:s}=this,a=t!==void 0?t:this.mergedRequired;s==null||s();const o=()=>{const d=this.$slots.label?this.$slots.label():this.label;if(!d)return null;const f=P("span",{class:`${e}-form-item-label__text`},d),l=a?P("span",{class:`${e}-form-item-label__asterisk`},i!=="left"?"\xA0*":"*\xA0"):i==="right-hanging"&&P("span",{class:`${e}-form-item-label__asterisk-placeholder`},"\xA0*"),{labelProps:m}=this;return P("label",Object.assign({},m,{class:[m==null?void 0:m.class,`${e}-form-item-label`,`${e}-form-item-label--${i}-mark`],style:this.mergedLabelStyle,ref:"labelElementRef"}),i==="left"?[l,f]:[f,l])};return P("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`,!n&&`${e}-form-item--no-label`],style:this.cssVars},n&&o(),P("div",{class:[`${e}-form-item-blank`,this.mergedValidationStatus&&`${e}-form-item-blank--${this.mergedValidationStatus}`]},r),this.mergedShowFeedback?P("div",{key:this.feedbackId,class:`${e}-form-item-feedback-wrapper`},P(Ke,{name:"fade-down-transition",mode:"out-in"},{default:()=>{const{mergedValidationStatus:d}=this;return Je(r.feedback,f=>{var l;const{feedback:m}=this,h=f||m?P("div",{key:"__feedback__",class:`${e}-form-item-feedback__line`},f||m):this.renderExplains.length?(l=this.renderExplains)===null||l===void 0?void 0:l.map(({key:c,render:y})=>P("div",{key:c,class:`${e}-form-item-feedback__line`},y())):null;return h?d==="warning"?P("div",{key:"controlled-warning",class:`${e}-form-item-feedback ${e}-form-item-feedback--warning`},h):d==="error"?P("div",{key:"controlled-error",class:`${e}-form-item-feedback ${e}-form-item-feedback--error`},h):d==="success"?P("div",{key:"controlled-success",class:`${e}-form-item-feedback ${e}-form-item-feedback--success`},h):P("div",{key:"controlled-default",class:`${e}-form-item-feedback`},h):null})}})):null)}});export{Un as _,zn as a};