index-8b2a5852.js 1.8 KB

1
  1. import{c as V,u as y,n as A,t as h,y as T,w as C}from"./index-80824ce0.js";import{u as M}from"./use-expose-d86bad54.js";import{F as N}from"./constant-eba5e2d8.js";import{d as _,c as q}from"./index-4869ce1e.js";const[x,I]=V("form"),O={colon:Boolean,disabled:Boolean,readonly:Boolean,required:[Boolean,String],showError:Boolean,labelWidth:A,labelAlign:String,inputAlign:String,scrollToError:Boolean,validateFirst:Boolean,submitOnEnter:h,showErrorMessage:h,errorMessageAlign:String,validateTrigger:{type:[String,Array],default:"onBlur"}};var j=_({name:x,props:O,emits:["submit","failed"],setup(i,{emit:s,slots:u}){const{children:a,linkChildren:v}=y(N),l=e=>e?a.filter(t=>e.includes(t.name)):a,p=e=>new Promise((t,n)=>{const r=[];l(e).reduce((w,E)=>w.then(()=>{if(!r.length)return E.validate().then(g=>{g&&r.push(g)})}),Promise.resolve()).then(()=>{r.length?n(r):t()})}),b=e=>new Promise((t,n)=>{const r=l(e);Promise.all(r.map(o=>o.validate())).then(o=>{o=o.filter(Boolean),o.length?n(o):t()})}),B=e=>{const t=a.find(n=>n.name===e);return t?new Promise((n,r)=>{t.validate().then(o=>{o?r(o):n()})}):Promise.reject()},c=e=>typeof e=="string"?B(e):i.validateFirst?p(e):b(e),S=e=>{typeof e=="string"&&(e=[e]),l(e).forEach(n=>{n.resetValidation()})},F=()=>a.reduce((e,t)=>(e[t.name]=t.getValidationStatus(),e),{}),d=(e,t)=>{a.some(n=>n.name===e?(n.$el.scrollIntoView(t),!0):!1)},f=()=>a.reduce((e,t)=>(t.name!==void 0&&(e[t.name]=t.formValue.value),e),{}),m=()=>{const e=f();c().then(()=>s("submit",e)).catch(t=>{s("failed",{values:e,errors:t}),i.scrollToError&&t[0].name&&d(t[0].name)})},P=e=>{T(e),m()};return v({props:i}),M({submit:m,validate:c,getValues:f,scrollToField:d,resetValidation:S,getValidationStatus:F}),()=>{var e;return q("form",{class:I(),onSubmit:P},[(e=u.default)==null?void 0:e.call(u)])}}});const W=C(j);export{W as F};