form-atoms
Version:
Form primitives for Jotai
2 lines (1 loc) • 1.2 kB
JavaScript
var c=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var E=(i,a)=>{for(var r in a)c(i,r,{get:a[r],enumerable:!0})},v=(i,a,r,l)=>{if(a&&typeof a=="object"||typeof a=="function")for(let o of b(a))!g.call(i,o)&&o!==r&&c(i,o,{get:()=>a[o],enumerable:!(l=h(a,o))||l.enumerable});return i};var S=i=>v(c({},"__esModule",{value:!0}),i);var x={};E(x,{createValibotValidator:()=>w});module.exports=S(x);var m=require("valibot");function w(i){return function a(r,l={}){let{on:o,when:s,formatError:f=t=>t.issues.map(e=>e.message)}=l,u=[],p=!!(s!=null&&s.includes("dirty")),y=!!(s!=null&&s.includes("touched")),V=Object.assign(async t=>{let e;if((t.event==="user"||t.event==="submit"||!!(o!=null&&o.includes(t.event)))&&(s===void 0||p&&t.dirty||y&&t.touched)){let d=typeof r=="function"?r(t.get):r;try{await i(d,t.value),e=[]}catch(n){if((0,m.isValiError)(n))return f(n);throw n}}if(u.length>0)for(let d of u){let n=await d(t);if((n!=null&&n.length||n)&&(e=e?e.concat(n):n),e)return e}return e},{or(t){let e=a(r,{formatError:f,...t});return u.push(e),V}});return V}}0&&(module.exports={createValibotValidator});
;