chaite
Version:
core for chatgpt-plugin and karin-plugin-chatgpt
111 lines (110 loc) • 33.5 kB
JavaScript
import{aL as oe,bM as Ze,K as Ne,bI as Ge,aK as Be,a8 as C,as as z,ar as te,d as De,G as E,ab as Ae,ae as xe,bL as ye,bR as He,b4 as Fe,j as Y,bS as Qe,b0 as ve,O as S,bT as Ke,aq as Re,T as Xe,aP as et,bU as Ee,ah as pe,s as tt,ag as nt,bV as rt,ba as je,au as H}from"./index-D3SoE8bB.js";function it(r,e,t){var n;const i=oe(r,null);if(i===null)return;const a=(n=Ze())===null||n===void 0?void 0:n.proxy;Ne(t,s),s(t.value),Ge(()=>{s(void 0,t.value)});function s(d,f){if(!i)return;const c=i[e];f!==void 0&&o(c,f),d!==void 0&&l(c,d)}function o(d,f){d[f]||(d[f]=[]),d[f].splice(d[f].findIndex(c=>c===a),1)}function l(d,f){d[f]||(d[f]=[]),~d[f].findIndex(c=>c===a)||d[f].push(a)}}const fe=Be("n-form"),Ue=Be("n-form-item-insts"),at=C("form",[z("inline",`
width: 100%;
display: inline-flex;
align-items: flex-start;
align-content: space-around;
`,[C("form-item",{width:"auto",marginRight:"18px"},[te("&:last-child",{marginRight:0})])])]);var st=function(r,e,t,n){function i(a){return a instanceof t?a:new t(function(s){s(a)})}return new(t||(t=Promise))(function(a,s){function o(f){try{d(n.next(f))}catch(c){s(c)}}function l(f){try{d(n.throw(f))}catch(c){s(c)}}function d(f){f.done?a(f.value):i(f.value).then(o,l)}d((n=n.apply(r,e||[])).next())})};const ot=Object.assign(Object.assign({},xe.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}),Kt=De({name:"Form",props:ot,setup(r){const{mergedClsPrefixRef:e}=Ae(r);xe("Form","-form",at,He,r,e);const t={},n=Y(void 0),i=d=>{const f=n.value;(f===void 0||d>=f)&&(n.value=d)};function a(){var d;for(const f of ye(t)){const c=t[f];for(const p of c)(d=p.invalidateLabelWidth)===null||d===void 0||d.call(p)}}function s(d){return st(this,arguments,void 0,function*(f,c=()=>!0){return yield new Promise((p,F)=>{const g=[];for(const m of ye(t)){const y=t[m];for(const u of y)u.path&&g.push(u.internalValidate(null,c))}Promise.all(g).then(m=>{const y=m.some(h=>!h.valid),u=[],P=[];m.forEach(h=>{var b,x;!((b=h.errors)===null||b===void 0)&&b.length&&u.push(h.errors),!((x=h.warnings)===null||x===void 0)&&x.length&&P.push(h.warnings)}),f&&f(u.length?u:void 0,{warnings:P.length?P:void 0}),y?F(u.length?u:void 0):p({warnings:P.length?P:void 0})})})})}function o(){for(const d of ye(t)){const f=t[d];for(const c of f)c.restoreValidation()}}return Fe(fe,{props:r,maxChildLabelWidthRef:n,deriveMaxChildLabelWidth:i}),Fe(Ue,{formItems:t}),Object.assign({validate:s,restoreValidation:o,invalidateLabelWidth:a},{mergedClsPrefix:e})},render(){const{mergedClsPrefix:r}=this;return E("form",{class:[`${r}-form`,this.inline&&`${r}-form--inline`],onSubmit:this.onSubmit},this.$slots)}});function J(){return J=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r},J.apply(this,arguments)}function ft(r,e){r.prototype=Object.create(e.prototype),r.prototype.constructor=r,se(r,e)}function Se(r){return Se=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Se(r)}function se(r,e){return se=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,i){return n.__proto__=i,n},se(r,e)}function lt(){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 we(r,e,t){return lt()?we=Reflect.construct.bind():we=function(i,a,s){var o=[null];o.push.apply(o,a);var l=Function.bind.apply(i,o),d=new l;return s&&se(d,s.prototype),d},we.apply(null,arguments)}function dt(r){return Function.toString.call(r).indexOf("[native code]")!==-1}function Pe(r){var e=typeof Map=="function"?new Map:void 0;return Pe=function(n){if(n===null||!dt(n))return n;if(typeof n!="function")throw new TypeError("Super expression must either be null or a function");if(typeof e<"u"){if(e.has(n))return e.get(n);e.set(n,i)}function i(){return we(n,arguments,Se(this).constructor)}return i.prototype=Object.create(n.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),se(i,n)},Pe(r)}var ut=/%[sdj%]/g,ct=function(){};function _e(r){if(!r||!r.length)return null;var e={};return r.forEach(function(t){var n=t.field;e[n]=e[n]||[],e[n].push(t)}),e}function M(r){for(var e=arguments.length,t=new Array(e>1?e-1:0),n=1;n<e;n++)t[n-1]=arguments[n];var i=0,a=t.length;if(typeof r=="function")return r.apply(null,t);if(typeof r=="string"){var s=r.replace(ut,function(o){if(o==="%%")return"%";if(i>=a)return o;switch(o){case"%s":return String(t[i++]);case"%d":return Number(t[i++]);case"%j":try{return JSON.stringify(t[i++])}catch{return"[Circular]"}break;default:return o}});return s}return r}function mt(r){return r==="string"||r==="url"||r==="hex"||r==="email"||r==="date"||r==="pattern"}function q(r,e){return!!(r==null||e==="array"&&Array.isArray(r)&&!r.length||mt(e)&&typeof r=="string"&&!r)}function gt(r,e,t){var n=[],i=0,a=r.length;function s(o){n.push.apply(n,o||[]),i++,i===a&&t(n)}r.forEach(function(o){e(o,s)})}function Me(r,e,t){var n=0,i=r.length;function a(s){if(s&&s.length){t(s);return}var o=n;n=n+1,o<i?e(r[o],a):t([])}a([])}function ht(r){var e=[];return Object.keys(r).forEach(function(t){e.push.apply(e,r[t]||[])}),e}var Ie=(function(r){ft(e,r);function e(t,n){var i;return i=r.call(this,"Async Validation Error")||this,i.errors=t,i.fields=n,i}return e})(Pe(Error));function vt(r,e,t,n,i){if(e.first){var a=new Promise(function(p,F){var g=function(u){return n(u),u.length?F(new Ie(u,_e(u))):p(i)},m=ht(r);Me(m,t,g)});return a.catch(function(p){return p}),a}var s=e.firstFields===!0?Object.keys(r):e.firstFields||[],o=Object.keys(r),l=o.length,d=0,f=[],c=new Promise(function(p,F){var g=function(y){if(f.push.apply(f,y),d++,d===l)return n(f),f.length?F(new Ie(f,_e(f))):p(i)};o.length||(n(f),p(i)),o.forEach(function(m){var y=r[m];s.indexOf(m)!==-1?Me(y,t,g):gt(y,t,g)})});return c.catch(function(p){return p}),c}function pt(r){return!!(r&&r.message!==void 0)}function bt(r,e){for(var t=r,n=0;n<e.length;n++){if(t==null)return t;t=t[e[n]]}return t}function Le(r,e){return function(t){var n;return r.fullFields?n=bt(e,r.fullFields):n=e[t.field||r.fullField],pt(t)?(t.field=t.field||r.fullField,t.fieldValue=n,t):{message:typeof t=="function"?t():t,fieldValue:n,field:t.field||r.fullField}}}function Ve(r,e){if(e){for(var t in e)if(e.hasOwnProperty(t)){var n=e[t];typeof n=="object"&&typeof r[t]=="object"?r[t]=J({},r[t],n):r[t]=n}}return r}var Ye=function(e,t,n,i,a,s){e.required&&(!n.hasOwnProperty(e.field)||q(t,s||e.type))&&i.push(M(a.messages.required,e.fullField))},yt=function(e,t,n,i,a){(/^\s+$/.test(t)||t==="")&&i.push(M(a.messages.whitespace,e.fullField))},be,wt=(function(){if(be)return be;var r="[a-fA-F\\d:]",e=function(b){return b&&b.includeBoundaries?"(?:(?<=\\s|^)(?="+r+")|(?<="+r+")(?=\\s|$))":""},t="(?: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}",n="[a-fA-F\\d]{1,4}",i=(`
(?:
(?:`+n+":){7}(?:"+n+`|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
(?:`+n+":){6}(?:"+t+"|:"+n+`|:)| // 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
(?:`+n+":){5}(?::"+t+"|(?::"+n+`){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
(?:`+n+":){4}(?:(?::"+n+"){0,1}:"+t+"|(?::"+n+`){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
(?:`+n+":){3}(?:(?::"+n+"){0,2}:"+t+"|(?::"+n+`){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
(?:`+n+":){2}(?:(?::"+n+"){0,3}:"+t+"|(?::"+n+`){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
(?:`+n+":){1}(?:(?::"+n+"){0,4}:"+t+"|(?::"+n+`){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
(?::(?:(?::`+n+"){0,5}:"+t+"|(?::"+n+`){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(),a=new RegExp("(?:^"+t+"$)|(?:^"+i+"$)"),s=new RegExp("^"+t+"$"),o=new RegExp("^"+i+"$"),l=function(b){return b&&b.exact?a:new RegExp("(?:"+e(b)+t+e(b)+")|(?:"+e(b)+i+e(b)+")","g")};l.v4=function(h){return h&&h.exact?s:new RegExp(""+e(h)+t+e(h),"g")},l.v6=function(h){return h&&h.exact?o:new RegExp(""+e(h)+i+e(h),"g")};var d="(?:(?:[a-z]+:)?//)",f="(?:\\S+(?::\\S*)?@)?",c=l.v4().source,p=l.v6().source,F="(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)",g="(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*",m="(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))",y="(?::\\d{2,5})?",u='(?:[/?#][^\\s"]*)?',P="(?:"+d+"|www\\.)"+f+"(?:localhost|"+c+"|"+p+"|"+F+g+m+")"+y+u;return be=new RegExp("(?:^"+P+"$)","i"),be}),ze={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},ie={integer:function(e){return ie.number(e)&&parseInt(e,10)===e},float:function(e){return ie.number(e)&&!ie.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"&&!ie.array(e)},method:function(e){return typeof e=="function"},email:function(e){return typeof e=="string"&&e.length<=320&&!!e.match(ze.email)},url:function(e){return typeof e=="string"&&e.length<=2048&&!!e.match(wt())},hex:function(e){return typeof e=="string"&&!!e.match(ze.hex)}},xt=function(e,t,n,i,a){if(e.required&&t===void 0){Ye(e,t,n,i,a);return}var s=["integer","float","array","regexp","object","method","email","number","date","url","hex"],o=e.type;s.indexOf(o)>-1?ie[o](t)||i.push(M(a.messages.types[o],e.fullField,e.type)):o&&typeof t!==e.type&&i.push(M(a.messages.types[o],e.fullField,e.type))},kt=function(e,t,n,i,a){var s=typeof e.len=="number",o=typeof e.min=="number",l=typeof e.max=="number",d=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,f=t,c=null,p=typeof t=="number",F=typeof t=="string",g=Array.isArray(t);if(p?c="number":F?c="string":g&&(c="array"),!c)return!1;g&&(f=t.length),F&&(f=t.replace(d,"_").length),s?f!==e.len&&i.push(M(a.messages[c].len,e.fullField,e.len)):o&&!l&&f<e.min?i.push(M(a.messages[c].min,e.fullField,e.min)):l&&!o&&f>e.max?i.push(M(a.messages[c].max,e.fullField,e.max)):o&&l&&(f<e.min||f>e.max)&&i.push(M(a.messages[c].range,e.fullField,e.min,e.max))},ee="enum",Rt=function(e,t,n,i,a){e[ee]=Array.isArray(e[ee])?e[ee]:[],e[ee].indexOf(t)===-1&&i.push(M(a.messages[ee],e.fullField,e[ee].join(", ")))},qt=function(e,t,n,i,a){if(e.pattern){if(e.pattern instanceof RegExp)e.pattern.lastIndex=0,e.pattern.test(t)||i.push(M(a.messages.pattern.mismatch,e.fullField,t,e.pattern));else if(typeof e.pattern=="string"){var s=new RegExp(e.pattern);s.test(t)||i.push(M(a.messages.pattern.mismatch,e.fullField,t,e.pattern))}}},v={required:Ye,whitespace:yt,type:xt,range:kt,enum:Rt,pattern:qt},Ft=function(e,t,n,i,a){var s=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(q(t,"string")&&!e.required)return n();v.required(e,t,i,s,a,"string"),q(t,"string")||(v.type(e,t,i,s,a),v.range(e,t,i,s,a),v.pattern(e,t,i,s,a),e.whitespace===!0&&v.whitespace(e,t,i,s,a))}n(s)},St=function(e,t,n,i,a){var s=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(q(t)&&!e.required)return n();v.required(e,t,i,s,a),t!==void 0&&v.type(e,t,i,s,a)}n(s)},Pt=function(e,t,n,i,a){var s=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(t===""&&(t=void 0),q(t)&&!e.required)return n();v.required(e,t,i,s,a),t!==void 0&&(v.type(e,t,i,s,a),v.range(e,t,i,s,a))}n(s)},_t=function(e,t,n,i,a){var s=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(q(t)&&!e.required)return n();v.required(e,t,i,s,a),t!==void 0&&v.type(e,t,i,s,a)}n(s)},Ot=function(e,t,n,i,a){var s=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(q(t)&&!e.required)return n();v.required(e,t,i,s,a),q(t)||v.type(e,t,i,s,a)}n(s)},$t=function(e,t,n,i,a){var s=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(q(t)&&!e.required)return n();v.required(e,t,i,s,a),t!==void 0&&(v.type(e,t,i,s,a),v.range(e,t,i,s,a))}n(s)},At=function(e,t,n,i,a){var s=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(q(t)&&!e.required)return n();v.required(e,t,i,s,a),t!==void 0&&(v.type(e,t,i,s,a),v.range(e,t,i,s,a))}n(s)},Et=function(e,t,n,i,a){var s=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(t==null&&!e.required)return n();v.required(e,t,i,s,a,"array"),t!=null&&(v.type(e,t,i,s,a),v.range(e,t,i,s,a))}n(s)},jt=function(e,t,n,i,a){var s=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(q(t)&&!e.required)return n();v.required(e,t,i,s,a),t!==void 0&&v.type(e,t,i,s,a)}n(s)},Mt="enum",It=function(e,t,n,i,a){var s=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(q(t)&&!e.required)return n();v.required(e,t,i,s,a),t!==void 0&&v[Mt](e,t,i,s,a)}n(s)},Lt=function(e,t,n,i,a){var s=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(q(t,"string")&&!e.required)return n();v.required(e,t,i,s,a),q(t,"string")||v.pattern(e,t,i,s,a)}n(s)},Vt=function(e,t,n,i,a){var s=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(q(t,"date")&&!e.required)return n();if(v.required(e,t,i,s,a),!q(t,"date")){var l;t instanceof Date?l=t:l=new Date(t),v.type(e,l,i,s,a),l&&v.range(e,l.getTime(),i,s,a)}}n(s)},zt=function(e,t,n,i,a){var s=[],o=Array.isArray(t)?"array":typeof t;v.required(e,t,i,s,a,o),n(s)},qe=function(e,t,n,i,a){var s=e.type,o=[],l=e.required||!e.required&&i.hasOwnProperty(e.field);if(l){if(q(t,s)&&!e.required)return n();v.required(e,t,i,o,a,s),q(t,s)||v.type(e,t,i,o,a)}n(o)},Ct=function(e,t,n,i,a){var s=[],o=e.required||!e.required&&i.hasOwnProperty(e.field);if(o){if(q(t)&&!e.required)return n();v.required(e,t,i,s,a)}n(s)},ae={string:Ft,method:St,number:Pt,boolean:_t,regexp:Ot,integer:$t,float:At,array:Et,object:jt,enum:It,pattern:Lt,date:Vt,url:qe,hex:qe,email:qe,required:zt,any:Ct};function Oe(){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=Oe(),ne=(function(){function r(t){this.rules=null,this._messages=$e,this.define(t)}var e=r.prototype;return e.define=function(n){var i=this;if(!n)throw new Error("Cannot configure a schema with no rules");if(typeof n!="object"||Array.isArray(n))throw new Error("Rules must be an object");this.rules={},Object.keys(n).forEach(function(a){var s=n[a];i.rules[a]=Array.isArray(s)?s:[s]})},e.messages=function(n){return n&&(this._messages=Ve(Oe(),n)),this._messages},e.validate=function(n,i,a){var s=this;i===void 0&&(i={}),a===void 0&&(a=function(){});var o=n,l=i,d=a;if(typeof l=="function"&&(d=l,l={}),!this.rules||Object.keys(this.rules).length===0)return d&&d(null,o),Promise.resolve(o);function f(m){var y=[],u={};function P(b){if(Array.isArray(b)){var x;y=(x=y).concat.apply(x,b)}else y.push(b)}for(var h=0;h<m.length;h++)P(m[h]);y.length?(u=_e(y),d(y,u)):d(null,o)}if(l.messages){var c=this.messages();c===$e&&(c=Oe()),Ve(c,l.messages),l.messages=c}else l.messages=this.messages();var p={},F=l.keys||Object.keys(this.rules);F.forEach(function(m){var y=s.rules[m],u=o[m];y.forEach(function(P){var h=P;typeof h.transform=="function"&&(o===n&&(o=J({},o)),u=o[m]=h.transform(u)),typeof h=="function"?h={validator:h}:h=J({},h),h.validator=s.getValidationMethod(h),h.validator&&(h.field=m,h.fullField=h.fullField||m,h.type=s.getType(h),p[m]=p[m]||[],p[m].push({rule:h,value:u,source:o,field:m}))})});var g={};return vt(p,l,function(m,y){var u=m.rule,P=(u.type==="object"||u.type==="array")&&(typeof u.fields=="object"||typeof u.defaultField=="object");P=P&&(u.required||!u.required&&m.value),u.field=m.field;function h(_,W){return J({},W,{fullField:u.fullField+"."+_,fullFields:u.fullFields?[].concat(u.fullFields,[_]):[_]})}function b(_){_===void 0&&(_=[]);var W=Array.isArray(_)?_:[_];!l.suppressWarning&&W.length&&r.warning("async-validator:",W),W.length&&u.message!==void 0&&(W=[].concat(u.message));var V=W.map(Le(u,o));if(l.first&&V.length)return g[u.field]=1,y(V);if(!P)y(V);else{if(u.required&&!m.value)return u.message!==void 0?V=[].concat(u.message).map(Le(u,o)):l.error&&(V=[l.error(u,M(l.messages.required,u.field))]),y(V);var K={};u.defaultField&&Object.keys(m.value).map(function(I){K[I]=u.defaultField}),K=J({},K,m.rule.fields);var le={};Object.keys(K).forEach(function(I){var O=K[I],ke=Array.isArray(O)?O:[O];le[I]=ke.map(h.bind(null,I))});var de=new r(le);de.messages(l.messages),m.rule.options&&(m.rule.options.messages=l.messages,m.rule.options.error=l.error),de.validate(m.value,m.rule.options||l,function(I){var O=[];V&&V.length&&O.push.apply(O,V),I&&I.length&&O.push.apply(O,I),y(O.length?O:null)})}}var x;if(u.asyncValidator)x=u.asyncValidator(u,m.value,b,m.source,l);else if(u.validator){try{x=u.validator(u,m.value,b,m.source,l)}catch(_){console.error?.(_),l.suppressValidatorError||setTimeout(function(){throw _},0),b(_.message)}x===!0?b():x===!1?b(typeof u.message=="function"?u.message(u.fullField||u.field):u.message||(u.fullField||u.field)+" fails"):x instanceof Array?b(x):x instanceof Error&&b(x.message)}x&&x.then&&x.then(function(){return b()},function(_){return b(_)})},function(m){f(m)},o)},e.getType=function(n){if(n.type===void 0&&n.pattern instanceof RegExp&&(n.type="pattern"),typeof n.validator!="function"&&n.type&&!ae.hasOwnProperty(n.type))throw new Error(M("Unknown rule type %s",n.type));return n.type||"string"},e.getValidationMethod=function(n){if(typeof n.validator=="function")return n.validator;var i=Object.keys(n),a=i.indexOf("message");return a!==-1&&i.splice(a,1),i.length===1&&i[0]==="required"?ae.required:ae[this.getType(n)]||void 0},r})();ne.register=function(e,t){if(typeof t!="function")throw new Error("Cannot register a validator by type, validator is not a function");ae[e]=t};ne.warning=ct;ne.messages=$e;ne.validators=ae;const{cubicBezierEaseInOut:Ce}=Qe;function Wt({name:r="fade-down",fromOffset:e="-4px",enterDuration:t=".3s",leaveDuration:n=".3s",enterCubicBezier:i=Ce,leaveCubicBezier:a=Ce}={}){return[te(`&.${r}-transition-enter-from, &.${r}-transition-leave-to`,{opacity:0,transform:`translateY(${e})`}),te(`&.${r}-transition-enter-to, &.${r}-transition-leave-from`,{opacity:1,transform:"translateY(0)"}),te(`&.${r}-transition-leave-active`,{transition:`opacity ${n} ${a}, transform ${n} ${a}`}),te(`&.${r}-transition-enter-active`,{transition:`opacity ${t} ${i}, transform ${t} ${i}`})]}const Tt=C("form-item",`
display: grid;
line-height: var(--n-line-height);
`,[C("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;
`)]),C("form-item-blank",`
grid-area: blank;
min-height: var(--n-blank-height);
`),z("auto-label-width",[C("form-item-label","white-space: nowrap;")]),z("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;
`,[C("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;
`,[z("reverse-columns-space",`
grid-template-columns: auto 1fr;
`),z("left-mark",`
grid-template-areas:
"mark text"
". text";
`),z("right-mark",`
grid-template-areas:
"text mark"
"text .";
`),z("right-hanging-mark",`
grid-template-areas:
"text mark"
"text .";
`),ve("text",`
grid-area: text;
`),ve("asterisk",`
grid-area: mark;
align-self: end;
`)])]),z("top-labelled",`
grid-template-areas:
"label"
"blank"
"feedback";
grid-template-rows: minmax(var(--n-label-height), auto) 1fr;
grid-template-columns: minmax(0, 100%);
`,[z("no-label",`
grid-template-areas:
"blank"
"feedback";
grid-template-rows: 1fr;
`),C("form-item-label",`
display: flex;
align-items: flex-start;
justify-content: var(--n-label-text-align);
`)]),C("form-item-blank",`
box-sizing: border-box;
display: flex;
align-items: center;
position: relative;
`),C("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;
`,[te("&:not(:empty)",`
padding: var(--n-feedback-padding);
`),C("form-item-feedback",{transition:"color .3s var(--n-bezier)",color:"var(--n-feedback-text-color)"},[z("warning",{color:"var(--n-feedback-text-color-warning)"}),z("error",{color:"var(--n-feedback-text-color-error)"}),Wt({fromOffset:"-3px",enterDuration:".3s",leaveDuration:".2s"})])])]);function Nt(r){const e=oe(fe,null),{mergedComponentPropsRef:t}=Ae(r);return{mergedSize:S(()=>{var n,i;if(r.size!==void 0)return r.size;if(e?.props.size!==void 0)return e.props.size;const a=(i=(n=t?.value)===null||n===void 0?void 0:n.Form)===null||i===void 0?void 0:i.size;return a||"medium"})}}function Bt(r){const e=oe(fe,null),t=S(()=>{const{labelPlacement:g}=r;return g!==void 0?g:e?.props.labelPlacement?e.props.labelPlacement:"top"}),n=S(()=>t.value==="left"&&(r.labelWidth==="auto"||e?.props.labelWidth==="auto")),i=S(()=>{if(t.value==="top")return;const{labelWidth:g}=r;if(g!==void 0&&g!=="auto")return Re(g);if(n.value){const m=e?.maxChildLabelWidthRef.value;return m!==void 0?Re(m):void 0}if(e?.props.labelWidth!==void 0)return Re(e.props.labelWidth)}),a=S(()=>{const{labelAlign:g}=r;if(g)return g;if(e?.props.labelAlign)return e.props.labelAlign}),s=S(()=>{var g;return[(g=r.labelProps)===null||g===void 0?void 0:g.style,r.labelStyle,{width:i.value}]}),o=S(()=>{const{showRequireMark:g}=r;return g!==void 0?g:e?.props.showRequireMark}),l=S(()=>{const{requireMarkPlacement:g}=r;return g!==void 0?g:e?.props.requireMarkPlacement||"right"}),d=Y(!1),f=Y(!1),c=S(()=>{const{validationStatus:g}=r;if(g!==void 0)return g;if(d.value)return"error";if(f.value)return"warning"}),p=S(()=>{const{showFeedback:g}=r;return g!==void 0?g:e?.props.showFeedback!==void 0?e.props.showFeedback:!0}),F=S(()=>{const{showLabel:g}=r;return g!==void 0?g:e?.props.showLabel!==void 0?e.props.showLabel:!0});return{validationErrored:d,validationWarned:f,mergedLabelStyle:s,mergedLabelPlacement:t,mergedLabelAlign:a,mergedShowRequireMark:o,mergedRequireMarkPlacement:l,mergedValidationStatus:c,mergedShowFeedback:p,mergedShowLabel:F,isAutoLabelWidth:n}}function Dt(r){const e=oe(fe,null),t=S(()=>{const{rulePath:s}=r;if(s!==void 0)return s;const{path:o}=r;if(o!==void 0)return o}),n=S(()=>{const s=[],{rule:o}=r;if(o!==void 0&&(Array.isArray(o)?s.push(...o):s.push(o)),e){const{rules:l}=e.props,{value:d}=t;if(l!==void 0&&d!==void 0){const f=Ke(l,d);f!==void 0&&(Array.isArray(f)?s.push(...f):s.push(f))}}return s}),i=S(()=>n.value.some(s=>s.required)),a=S(()=>i.value||r.required);return{mergedRules:n,mergedRequired:a}}var We=function(r,e,t,n){function i(a){return a instanceof t?a:new t(function(s){s(a)})}return new(t||(t=Promise))(function(a,s){function o(f){try{d(n.next(f))}catch(c){s(c)}}function l(f){try{d(n.throw(f))}catch(c){s(c)}}function d(f){f.done?a(f.value):i(f.value).then(o,l)}d((n=n.apply(r,e||[])).next())})};const Je=Object.assign(Object.assign({},xe.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,contentClass:String,contentStyle:[String,Object]}),Ut=ye(Je);function Te(r,e){return(...t)=>{try{const n=r(...t);return!e&&(typeof n=="boolean"||n instanceof Error||Array.isArray(n))||n?.then?n:(n===void 0||je("form-item/validate",`You return a ${typeof n} typed value in the validator method, which is not recommended. Please use ${e?"`Promise`":"`boolean`, `Error` or `Promise`"} typed value instead.`),!0)}catch(n){je("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(n);return}}}const Yt=De({name:"FormItem",props:Je,slots:Object,setup(r){it(Ue,"formItems",pe(r,"path"));const{mergedClsPrefixRef:e,inlineThemeDisabled:t}=Ae(r),n=oe(fe,null),i=Nt(r),a=Bt(r),{validationErrored:s,validationWarned:o}=a,{mergedRequired:l,mergedRules:d}=Dt(r),{mergedSize:f}=i,{mergedLabelPlacement:c,mergedLabelAlign:p,mergedRequireMarkPlacement:F}=a,g=Y([]),m=Y(Ee()),y=Y(null),u=n?pe(n.props,"disabled"):Y(!1),P=xe("Form","-form-item",Tt,He,r,e);Ne(pe(r,"path"),()=>{r.ignorePathChange||b()});function h(){if(!a.isAutoLabelWidth.value)return;const k=y.value;if(k!==null){const j=k.style.whiteSpace;k.style.whiteSpace="nowrap",k.style.width="",n?.deriveMaxChildLabelWidth(Number(getComputedStyle(k).width.slice(0,-2))),k.style.whiteSpace=j}}function b(){g.value=[],s.value=!1,o.value=!1,r.feedback&&(m.value=Ee())}const x=(...k)=>We(this,[...k],void 0,function*(j=null,T=()=>!0,$={suppressWarning:!0}){const{path:N}=r;$?$.first||($.first=r.first):$={};const{value:U}=d,Z=n?Ke(n.props.model,N||""):void 0,G={},Q={},B=(j?U.filter(w=>Array.isArray(w.trigger)?w.trigger.includes(j):w.trigger===j):U).filter(T).map((w,A)=>{const R=Object.assign({},w);if(R.validator&&(R.validator=Te(R.validator,!1)),R.asyncValidator&&(R.asyncValidator=Te(R.asyncValidator,!0)),R.renderMessage){const he=`__renderMessage__${A}`;Q[he]=R.message,R.message=he,G[he]=R.renderMessage}return R}),D=B.filter(w=>w.level!=="warning"),ue=B.filter(w=>w.level==="warning"),L={valid:!0,errors:void 0,warnings:void 0};if(!B.length)return L;const X=N??"__n_no_path__",ce=new ne({[X]:D}),me=new ne({[X]:ue}),{validateMessages:re}=n?.props||{};re&&(ce.messages(re),me.messages(re));const ge=w=>{g.value=w.map(A=>{const R=A?.message||"";return{key:R,render:()=>R.startsWith("__renderMessage__")?G[R]():R}}),w.forEach(A=>{var R;!((R=A.message)===null||R===void 0)&&R.startsWith("__renderMessage__")&&(A.message=Q[A.message])})};if(D.length){const w=yield new Promise(A=>{ce.validate({[X]:Z},$,A)});w?.length&&(L.valid=!1,L.errors=w,ge(w))}if(ue.length&&!L.errors){const w=yield new Promise(A=>{me.validate({[X]:Z},$,A)});w?.length&&(ge(w),L.warnings=w)}return!L.errors&&!L.warnings?b():(s.value=!!L.errors,o.value=!!L.warnings),L});function _(){x("blur")}function W(){x("change")}function V(){x("focus")}function K(){x("input")}function le(k,j){return We(this,void 0,void 0,function*(){let T,$,N,U;return typeof k=="string"?(T=k,$=j):k!==null&&typeof k=="object"&&(T=k.trigger,$=k.callback,N=k.shouldRuleBeApplied,U=k.options),yield new Promise((Z,G)=>{x(T,N,U).then(({valid:Q,errors:B,warnings:D})=>{Q?($&&$(void 0,{warnings:D}),Z({warnings:D})):($&&$(B,{warnings:D}),G(B))})})})}Fe(rt,{path:pe(r,"path"),disabled:u,mergedSize:i.mergedSize,mergedValidationStatus:a.mergedValidationStatus,restoreValidation:b,handleContentBlur:_,handleContentChange:W,handleContentFocus:V,handleContentInput:K});const de={validate:le,restoreValidation:b,internalValidate:x,invalidateLabelWidth:h};tt(h);const I=S(()=>{var k;const{value:j}=f,{value:T}=c,$=T==="top"?"vertical":"horizontal",{common:{cubicBezierEaseInOut:N},self:{labelTextColor:U,asteriskColor:Z,lineHeight:G,feedbackTextColor:Q,feedbackTextColorWarning:B,feedbackTextColorError:D,feedbackPadding:ue,labelFontWeight:L,[H("labelHeight",j)]:X,[H("blankHeight",j)]:ce,[H("feedbackFontSize",j)]:me,[H("feedbackHeight",j)]:re,[H("labelPadding",$)]:ge,[H("labelTextAlign",$)]:w,[H(H("labelFontSize",T),j)]:A}}=P.value;let R=(k=p.value)!==null&&k!==void 0?k:w;return T==="top"&&(R=R==="right"?"flex-end":"flex-start"),{"--n-bezier":N,"--n-line-height":G,"--n-blank-height":ce,"--n-label-font-size":A,"--n-label-text-align":R,"--n-label-height":X,"--n-label-padding":ge,"--n-label-font-weight":L,"--n-asterisk-color":Z,"--n-label-text-color":U,"--n-feedback-padding":ue,"--n-feedback-font-size":me,"--n-feedback-height":re,"--n-feedback-text-color":Q,"--n-feedback-text-color-warning":B,"--n-feedback-text-color-error":D}}),O=t?nt("form-item",S(()=>{var k;return`${f.value[0]}${c.value[0]}${((k=p.value)===null||k===void 0?void 0:k[0])||""}`}),I,r):void 0,ke=S(()=>c.value==="left"&&F.value==="left"&&p.value==="left");return Object.assign(Object.assign(Object.assign(Object.assign({labelElementRef:y,mergedClsPrefix:e,mergedRequired:l,feedbackId:m,renderExplains:g,reverseColSpace:ke},a),i),de),{cssVars:t?void 0:I,themeClass:O?.themeClass,onRender:O?.onRender})},render(){const{$slots:r,mergedClsPrefix:e,mergedShowLabel:t,mergedShowRequireMark:n,mergedRequireMarkPlacement:i,onRender:a}=this,s=n!==void 0?n:this.mergedRequired;a?.();const o=()=>{const l=this.$slots.label?this.$slots.label():this.label;if(!l)return null;const d=E("span",{class:`${e}-form-item-label__text`},l),f=s?E("span",{class:`${e}-form-item-label__asterisk`},i!=="left"?" *":"* "):i==="right-hanging"&&E("span",{class:`${e}-form-item-label__asterisk-placeholder`}," *"),{labelProps:c}=this;return E("label",Object.assign({},c,{class:[c?.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"?[f,d]:[d,f])};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`,!t&&`${e}-form-item--no-label`],style:this.cssVars},t&&o(),E("div",{class:[`${e}-form-item-blank`,this.contentClass,this.mergedValidationStatus&&`${e}-form-item-blank--${this.mergedValidationStatus}`],style:this.contentStyle},r),this.mergedShowFeedback?E("div",{key:this.feedbackId,style:this.feedbackStyle,class:[`${e}-form-item-feedback-wrapper`,this.feedbackClass]},E(Xe,{name:"fade-down-transition",mode:"out-in"},{default:()=>{const{mergedValidationStatus:l}=this;return et(r.feedback,d=>{var f;const{feedback:c}=this,p=d||c?E("div",{key:"__feedback__",class:`${e}-form-item-feedback__line`},d||c):this.renderExplains.length?(f=this.renderExplains)===null||f===void 0?void 0:f.map(({key:F,render:g})=>E("div",{key:F,class:`${e}-form-item-feedback__line`},g())):null;return p?l==="warning"?E("div",{key:"controlled-warning",class:`${e}-form-item-feedback ${e}-form-item-feedback--warning`},p):l==="error"?E("div",{key:"controlled-error",class:`${e}-form-item-feedback ${e}-form-item-feedback--error`},p):l==="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{Yt as N,Kt as _,Je as a,Ut as f};