wd-form.NSjLwpNU.js 3.0 KB

1
  1. var I=Object.defineProperty,N=Object.defineProperties;var A=Object.getOwnPropertyDescriptors;var C=Object.getOwnPropertySymbols;var x=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var O=(s,r,a)=>r in s?I(s,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[r]=a,R=(s,r)=>{for(var a in r||(r={}))x.call(r,a)&&O(s,a,r[a]);if(C)for(var a of C(r))B.call(r,a)&&O(s,a,r[a]);return s},S=(s,r)=>N(s,A(r));var V=(s,r)=>{var a={};for(var t in s)x.call(s,t)&&r.indexOf(t)<0&&(a[t]=s[t]);if(s!=null&&C)for(var t of C(s))r.indexOf(t)<0&&B.call(s,t)&&(a[t]=s[t]);return a};var j=(s,r,a)=>new Promise((t,m)=>{var T=c=>{try{h(a.next(c))}catch(g){m(g)}},u=c=>{try{h(a.throw(c))}catch(g){m(g)}},h=c=>c.done?t(c.value):Promise.resolve(c.value).then(T,u);h((a=a.apply(s,r)).next())});import{d as D,bE as H,bF as J,aM as K,ah as W,t as X,w as Y,f as $,o as q,g as L,k as Q,J as U,bG as Z,n as ee,a4 as se,ak as ae,an as y,aX as oe,bh as te,b9 as re,bB as ne,j as le,q as pe}from"./index-q8TQmcfk.js";const ie={name:"wd-form",options:{addGlobalClass:!0,virtualHost:!0,styleIsolation:"shared"}},ce=D(S(R({},ie),{props:H,setup(s,{expose:r}){const{show:a}=J("wd-form-toast"),t=s,{children:m,linkChildren:T}=K(W);let u=X({});T({props:t,errorMessages:u}),Y(()=>t.model,()=>{t.resetOnChange&&w()},{immediate:!0,deep:!0});function h(o){return j(this,null,function*(){const n=[];let e=!0;const l=[],_=c(),b=ae(o)?o:y(o)?[o]:[],E=b.length>0?b.reduce((p,d)=>(_[d]&&(p[d]=_[d]),p),{}):_;for(const p in E){const d=E[p],v=oe(t.model,p);if(d&&d.length>0)for(const i of d){if(i.required&&(!y(v)||v==="")){n.push({prop:p,message:i.message}),e=!1;break}if(i.pattern&&!i.pattern.test(v)){n.push({prop:p,message:i.message}),e=!1;break}const P=i,{validator:M}=P,F=V(P,["validator"]);if(M){const k=M(v,F);te(k)?l.push(k.then(f=>{typeof f=="string"?(n.push({prop:p,message:f}),e=!1):typeof f=="boolean"&&!f&&(n.push({prop:p,message:i.message}),e=!1)}).catch(f=>{const G=y(f)?re(f)?f:f.message||i.message:i.message;n.push({prop:p,message:G}),e=!1})):k||(n.push({prop:p,message:i.message}),e=!1)}}}return yield Promise.all(l),g(n),e&&(b.length?b.forEach(w):w()),{valid:e,errors:n}})}function c(){const o=ne(t.rules),n=m.map(e=>e.prop);return Object.keys(o).forEach(e=>{n.includes(e)||delete o[e]}),m.forEach(e=>{y(e.prop)&&y(e.rules)&&e.rules.length&&(o[e.prop]?o[e.prop]=[...o[e.prop],...e.rules]:o[e.prop]=e.rules)}),o}function g(o){const n=m.map(l=>l.prop).filter(Boolean),e=o.filter(l=>l.message&&n.includes(l.prop));e.length&&(e.sort((l,_)=>n.indexOf(l.prop)-n.indexOf(_.prop)),t.errorType==="toast"?a(e[0].message):t.errorType==="message"&&e.forEach(l=>{u[l.prop]=l.message}))}function w(o){o?u[o]="":Object.keys(u).forEach(n=>{u[n]=""})}function z(){w()}return r({validate:h,reset:z}),(o,n)=>{const e=le;return q(),$(e,{class:se(`wd-form ${o.customClass}`),style:ee(o.customStyle)},{default:L(()=>[Q(o.$slots,"default",{},void 0,!0),t.errorType==="toast"?(q(),$(Z,{key:0,selector:"wd-form-toast"})):U("",!0)]),_:3},8,["class","style"])}}})),de=pe(ce,[["__scopeId","data-v-e513a788"]]);export{de as _};