@volverjs/form-vue 1.1.0-beta.3 → 1.1.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -1,3 +1 @@
1
- (function(N,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("vue"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core"],a):(N=typeof globalThis<"u"?globalThis:N||self,a(N["@volverjs/form-vue"]={},N.Vue,N.VueUseCore))})(this,function(N,a,q){"use strict";var S=(e=>(e.text="text",e.number="number",e.email="email",e.password="password",e.tel="tel",e.url="url",e.search="search",e.date="date",e.time="time",e.datetimeLocal="datetime-local",e.month="month",e.week="week",e.color="color",e.select="select",e.checkbox="checkbox",e.radio="radio",e.textarea="textarea",e.radioGroup="radioGroup",e.checkboxGroup="checkboxGroup",e.combobox="combobox",e.custom="custom",e))(S||{}),D=(e=>(e.invalid="invalid",e.valid="valid",e.submitting="submitting",e.reset="reset",e.updated="updated",e.unknown="unknown",e))(D||{}),z;(function(e){e.assertEqual=t=>{};function r(t){}e.assertIs=r;function n(t){throw new Error}e.assertNever=n,e.arrayToEnum=t=>{const i={};for(const s of t)i[s]=s;return i},e.getValidEnumValues=t=>{const i=e.objectKeys(t).filter(l=>typeof t[t[l]]!="number"),s={};for(const l of i)s[l]=t[l];return e.objectValues(s)},e.objectValues=t=>e.objectKeys(t).map(function(i){return t[i]}),e.objectKeys=typeof Object.keys=="function"?t=>Object.keys(t):t=>{const i=[];for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&i.push(s);return i},e.find=(t,i)=>{for(const s of t)if(i(s))return s},e.isInteger=typeof Number.isInteger=="function"?t=>Number.isInteger(t):t=>typeof t=="number"&&Number.isFinite(t)&&Math.floor(t)===t;function u(t,i=" | "){return t.map(s=>typeof s=="string"?`'${s}'`:s).join(i)}e.joinValues=u,e.jsonStringifyReplacer=(t,i)=>typeof i=="bigint"?i.toString():i})(z||(z={}));var H;(function(e){e.mergeShapes=(r,n)=>({...r,...n})})(H||(H={})),z.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),z.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class A extends Error{get errors(){return this.issues}constructor(r){super(),this.issues=[],this.addIssue=u=>{this.issues=[...this.issues,u]},this.addIssues=(u=[])=>{this.issues=[...this.issues,...u]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=r}format(r){const n=r||function(i){return i.message},u={_errors:[]},t=i=>{for(const s of i.issues)if(s.code==="invalid_union")s.unionErrors.map(t);else if(s.code==="invalid_return_type")t(s.returnTypeError);else if(s.code==="invalid_arguments")t(s.argumentsError);else if(s.path.length===0)u._errors.push(n(s));else{let l=u,d=0;for(;d<s.path.length;){const h=s.path[d];d===s.path.length-1?(l[h]=l[h]||{_errors:[]},l[h]._errors.push(n(s))):l[h]=l[h]||{_errors:[]},l=l[h],d++}}};return t(this),u}static assert(r){if(!(r instanceof A))throw new Error(`Not a ZodError: ${r}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,z.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(r=n=>n.message){const n={},u=[];for(const t of this.issues)if(t.path.length>0){const i=t.path[0];n[i]=n[i]||[],n[i].push(r(t))}else u.push(r(t));return{formErrors:u,fieldErrors:n}}get formErrors(){return this.flatten()}}A.create=e=>new A(e);function Q(e,r,n){function u(l,d){var h;Object.defineProperty(l,"_zod",{value:l._zod??{},enumerable:!1}),(h=l._zod).traits??(h.traits=new Set),l._zod.traits.add(e),r(l,d);for(const p in s.prototype)p in l||Object.defineProperty(l,p,{value:s.prototype[p].bind(l)});l._zod.constr=s,l._zod.def=d}const t=n?.Parent??Object;class i extends t{}Object.defineProperty(i,"name",{value:e});function s(l){var d;const h=n?.Parent?new i:this;u(h,l),(d=h._zod).deferred??(d.deferred=[]);for(const p of h._zod.deferred)p();return h}return Object.defineProperty(s,"init",{value:u}),Object.defineProperty(s,Symbol.hasInstance,{value:l=>n?.Parent&&l instanceof n.Parent?!0:l?._zod?.traits?.has(e)}),Object.defineProperty(s,"name",{value:e}),s}class me extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}const he={};function X(e){return he}function ye(e){const r=Object.values(e).filter(u=>typeof u=="number");return Object.entries(e).filter(([u,t])=>r.indexOf(+u)===-1).map(([u,t])=>t)}function ve(e,r){return typeof r=="bigint"?r.toString():r}function J(e){return typeof e=="string"?e:e?.message}function Y(e,r,n){const u={...e,path:e.path??[]};if(!e.message){const t=J(e.inst?._zod.def?.error?.(e))??J(r?.error?.(e))??J(n.customError?.(e))??J(n.localeError?.(e))??"Invalid input";u.message=t}return delete u.inst,delete u.continue,r?.reportInput||delete u.input,u}const ee=(e,r)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:r,enumerable:!1}),e.message=JSON.stringify(r,ve,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},te=Q("$ZodError",ee),re=Q("$ZodError",ee,{Parent:Error});function ne(e,r){const n=function(i){return i.message},u={_errors:[]},t=i=>{for(const s of i.issues)if(s.code==="invalid_union"&&s.errors.length)s.errors.map(l=>t({issues:l}));else if(s.code==="invalid_key")t({issues:s.issues});else if(s.code==="invalid_element")t({issues:s.issues});else if(s.path.length===0)u._errors.push(n(s));else{let l=u,d=0;for(;d<s.path.length;){const h=s.path[d];d===s.path.length-1?(l[h]=l[h]||{_errors:[]},l[h]._errors.push(n(s))):l[h]=l[h]||{_errors:[]},l=l[h],d++}}};return t(e),u}const be=(e=>(r,n,u)=>{const t=u?{...u,async:!1}:{async:!1},i=r._zod.run({value:n,issues:[]},t);if(i instanceof Promise)throw new me;return i.issues.length?{success:!1,error:new(e??te)(i.issues.map(s=>Y(s,t,X())))}:{success:!0,data:i.value}})(re),ge=(e=>async(r,n,u)=>{const t=u?Object.assign(u,{async:!0}):{async:!0};let i=r._zod.run({value:n,issues:[]},t);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new e(i.issues.map(s=>Y(s,t,X())))}:{success:!0,data:i.value}})(re);class se{constructor(){this._map=new Map,this._idmap=new Map}add(r,...n){const u=n[0];if(this._map.set(r,u),u&&typeof u=="object"&&"id"in u){if(this._idmap.has(u.id))throw new Error(`ID ${u.id} already exists in the registry`);this._idmap.set(u.id,r)}return this}clear(){return this._map=new Map,this._idmap=new Map,this}remove(r){const n=this._map.get(r);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(r),this}get(r){const n=r._zod.parent;if(n){const u={...this.get(n)??{}};delete u.id;const t={...u,...this._map.get(r)};return Object.keys(t).length?t:void 0}return this._map.get(r)}has(r){return this._map.has(r)}}function we(){return new se}const Oe=we();class ae{constructor(r){this.counter=0,this.metadataRegistry=r?.metadata??Oe,this.target=r?.target??"draft-2020-12",this.unrepresentable=r?.unrepresentable??"throw",this.override=r?.override??(()=>{}),this.io=r?.io??"output",this.seen=new Map}process(r,n={path:[],schemaPath:[]}){var u;const t=r._zod.def,i={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},s=this.seen.get(r);if(s)return s.count++,n.schemaPath.includes(r)&&(s.cycle=n.path),s.schema;const l={schema:{},count:1,cycle:void 0,path:n.path};this.seen.set(r,l);const d=r._zod.toJSONSchema?.();if(d)l.schema=d;else{const f={...n,schemaPath:[...n.schemaPath,r],path:n.path},w=r._zod.parent;if(w)l.ref=w,this.process(w,f),this.seen.get(w).isParent=!0;else{const v=l.schema;switch(t.type){case"string":{const o=v;o.type="string";const{minimum:c,maximum:m,format:b,patterns:O,contentEncoding:j}=r._zod.bag;if(typeof c=="number"&&(o.minLength=c),typeof m=="number"&&(o.maxLength=m),b&&(o.format=i[b]??b,o.format===""&&delete o.format),j&&(o.contentEncoding=j),O&&O.size>0){const V=[...O];V.length===1?o.pattern=V[0].source:V.length>1&&(l.schema.allOf=[...V.map(k=>({...this.target==="draft-7"?{type:"string"}:{},pattern:k.source}))])}break}case"number":{const o=v,{minimum:c,maximum:m,format:b,multipleOf:O,exclusiveMaximum:j,exclusiveMinimum:V}=r._zod.bag;typeof b=="string"&&b.includes("int")?o.type="integer":o.type="number",typeof V=="number"&&(o.exclusiveMinimum=V),typeof c=="number"&&(o.minimum=c,typeof V=="number"&&(V>=c?delete o.minimum:delete o.exclusiveMinimum)),typeof j=="number"&&(o.exclusiveMaximum=j),typeof m=="number"&&(o.maximum=m,typeof j=="number"&&(j<=m?delete o.maximum:delete o.exclusiveMaximum)),typeof O=="number"&&(o.multipleOf=O);break}case"boolean":{const o=v;o.type="boolean";break}case"bigint":{if(this.unrepresentable==="throw")throw new Error("BigInt cannot be represented in JSON Schema");break}case"symbol":{if(this.unrepresentable==="throw")throw new Error("Symbols cannot be represented in JSON Schema");break}case"null":{v.type="null";break}case"any":break;case"unknown":break;case"undefined":{if(this.unrepresentable==="throw")throw new Error("Undefined cannot be represented in JSON Schema");break}case"void":{if(this.unrepresentable==="throw")throw new Error("Void cannot be represented in JSON Schema");break}case"never":{v.not={};break}case"date":{if(this.unrepresentable==="throw")throw new Error("Date cannot be represented in JSON Schema");break}case"array":{const o=v,{minimum:c,maximum:m}=r._zod.bag;typeof c=="number"&&(o.minItems=c),typeof m=="number"&&(o.maxItems=m),o.type="array",o.items=this.process(t.element,{...f,path:[...f.path,"items"]});break}case"object":{const o=v;o.type="object",o.properties={};const c=t.shape;for(const O in c)o.properties[O]=this.process(c[O],{...f,path:[...f.path,"properties",O]});const m=new Set(Object.keys(c)),b=new Set([...m].filter(O=>{const j=t.shape[O]._zod;return this.io==="input"?j.optin===void 0:j.optout===void 0}));b.size>0&&(o.required=Array.from(b)),t.catchall?._zod.def.type==="never"?o.additionalProperties=!1:t.catchall?t.catchall&&(o.additionalProperties=this.process(t.catchall,{...f,path:[...f.path,"additionalProperties"]})):this.io==="output"&&(o.additionalProperties=!1);break}case"union":{const o=v;o.anyOf=t.options.map((c,m)=>this.process(c,{...f,path:[...f.path,"anyOf",m]}));break}case"intersection":{const o=v,c=this.process(t.left,{...f,path:[...f.path,"allOf",0]}),m=this.process(t.right,{...f,path:[...f.path,"allOf",1]}),b=j=>"allOf"in j&&Object.keys(j).length===1,O=[...b(c)?c.allOf:[c],...b(m)?m.allOf:[m]];o.allOf=O;break}case"tuple":{const o=v;o.type="array";const c=t.items.map((O,j)=>this.process(O,{...f,path:[...f.path,"prefixItems",j]}));if(this.target==="draft-2020-12"?o.prefixItems=c:o.items=c,t.rest){const O=this.process(t.rest,{...f,path:[...f.path,"items"]});this.target==="draft-2020-12"?o.items=O:o.additionalItems=O}t.rest&&(o.items=this.process(t.rest,{...f,path:[...f.path,"items"]}));const{minimum:m,maximum:b}=r._zod.bag;typeof m=="number"&&(o.minItems=m),typeof b=="number"&&(o.maxItems=b);break}case"record":{const o=v;o.type="object",o.propertyNames=this.process(t.keyType,{...f,path:[...f.path,"propertyNames"]}),o.additionalProperties=this.process(t.valueType,{...f,path:[...f.path,"additionalProperties"]});break}case"map":{if(this.unrepresentable==="throw")throw new Error("Map cannot be represented in JSON Schema");break}case"set":{if(this.unrepresentable==="throw")throw new Error("Set cannot be represented in JSON Schema");break}case"enum":{const o=v,c=ye(t.entries);c.every(m=>typeof m=="number")&&(o.type="number"),c.every(m=>typeof m=="string")&&(o.type="string"),o.enum=c;break}case"literal":{const o=v,c=[];for(const m of t.values)if(m===void 0){if(this.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof m=="bigint"){if(this.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");c.push(Number(m))}else c.push(m);if(c.length!==0)if(c.length===1){const m=c[0];o.type=m===null?"null":typeof m,o.const=m}else c.every(m=>typeof m=="number")&&(o.type="number"),c.every(m=>typeof m=="string")&&(o.type="string"),c.every(m=>typeof m=="boolean")&&(o.type="string"),c.every(m=>m===null)&&(o.type="null"),o.enum=c;break}case"file":{const o=v,c={type:"string",format:"binary",contentEncoding:"binary"},{minimum:m,maximum:b,mime:O}=r._zod.bag;m!==void 0&&(c.minLength=m),b!==void 0&&(c.maxLength=b),O?O.length===1?(c.contentMediaType=O[0],Object.assign(o,c)):o.anyOf=O.map(j=>({...c,contentMediaType:j})):Object.assign(o,c);break}case"transform":{if(this.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema");break}case"nullable":{const o=this.process(t.innerType,f);v.anyOf=[o,{type:"null"}];break}case"nonoptional":{this.process(t.innerType,f),l.ref=t.innerType;break}case"success":{const o=v;o.type="boolean";break}case"default":{this.process(t.innerType,f),l.ref=t.innerType,v.default=JSON.parse(JSON.stringify(t.defaultValue));break}case"prefault":{this.process(t.innerType,f),l.ref=t.innerType,this.io==="input"&&(v._prefault=JSON.parse(JSON.stringify(t.defaultValue)));break}case"catch":{this.process(t.innerType,f),l.ref=t.innerType;let o;try{o=t.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}v.default=o;break}case"nan":{if(this.unrepresentable==="throw")throw new Error("NaN cannot be represented in JSON Schema");break}case"template_literal":{const o=v,c=r._zod.pattern;if(!c)throw new Error("Pattern not found in template literal");o.type="string",o.pattern=c.source;break}case"pipe":{const o=this.io==="input"?t.in._zod.def.type==="transform"?t.out:t.in:t.out;this.process(o,f),l.ref=o;break}case"readonly":{this.process(t.innerType,f),l.ref=t.innerType,v.readOnly=!0;break}case"promise":{this.process(t.innerType,f),l.ref=t.innerType;break}case"optional":{this.process(t.innerType,f),l.ref=t.innerType;break}case"lazy":{const o=r._zod.innerType;this.process(o,f),l.ref=o;break}case"custom":{if(this.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema");break}}}}const h=this.metadataRegistry.get(r);return h&&Object.assign(l.schema,h),this.io==="input"&&I(r)&&(delete l.schema.examples,delete l.schema.default),this.io==="input"&&l.schema._prefault&&((u=l.schema).default??(u.default=l.schema._prefault)),delete l.schema._prefault,this.seen.get(r).schema}emit(r,n){const u={cycles:n?.cycles??"ref",reused:n?.reused??"inline",external:n?.external??void 0},t=this.seen.get(r);if(!t)throw new Error("Unprocessed schema. This is a bug in Zod.");const i=p=>{const f=this.target==="draft-2020-12"?"$defs":"definitions";if(u.external){const c=u.external.registry.get(p[0])?.id,m=u.external.uri??(O=>O);if(c)return{ref:m(c)};const b=p[1].defId??p[1].schema.id??`schema${this.counter++}`;return p[1].defId=b,{defId:b,ref:`${m("__shared")}#/${f}/${b}`}}if(p[1]===t)return{ref:"#"};const v=`#/${f}/`,o=p[1].schema.id??`__schema${this.counter++}`;return{defId:o,ref:v+o}},s=p=>{if(p[1].schema.$ref)return;const f=p[1],{ref:w,defId:v}=i(p);f.def={...f.schema},v&&(f.defId=v);const o=f.schema;for(const c in o)delete o[c];o.$ref=w};if(u.cycles==="throw")for(const p of this.seen.entries()){const f=p[1];if(f.cycle)throw new Error(`Cycle detected: #/${f.cycle?.join("/")}/<root>
2
-
3
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const p of this.seen.entries()){const f=p[1];if(r===p[0]){s(p);continue}if(u.external){const v=u.external.registry.get(p[0])?.id;if(r!==p[0]&&v){s(p);continue}}if(this.metadataRegistry.get(p[0])?.id){s(p);continue}if(f.cycle){s(p);continue}if(f.count>1&&u.reused==="ref"){s(p);continue}}const l=(p,f)=>{const w=this.seen.get(p),v=w.def??w.schema,o={...v};if(w.ref===null)return;const c=w.ref;if(w.ref=null,c){l(c,f);const m=this.seen.get(c).schema;m.$ref&&f.target==="draft-7"?(v.allOf=v.allOf??[],v.allOf.push(m)):(Object.assign(v,m),Object.assign(v,o))}w.isParent||this.override({zodSchema:p,jsonSchema:v,path:w.path??[]})};for(const p of[...this.seen.entries()].reverse())l(p[0],{target:this.target});const d={};if(this.target==="draft-2020-12"?d.$schema="https://json-schema.org/draft/2020-12/schema":this.target==="draft-7"?d.$schema="http://json-schema.org/draft-07/schema#":console.warn(`Invalid target: ${this.target}`),u.external?.uri){const p=u.external.registry.get(r)?.id;if(!p)throw new Error("Schema is missing an `id` property");d.$id=u.external.uri(p)}Object.assign(d,t.def);const h=u.external?.defs??{};for(const p of this.seen.entries()){const f=p[1];f.def&&f.defId&&(h[f.defId]=f.def)}u.external||Object.keys(h).length>0&&(this.target==="draft-2020-12"?d.$defs=h:d.definitions=h);try{return JSON.parse(JSON.stringify(d))}catch{throw new Error("Error converting schema to JSON.")}}}function je(e,r){if(e instanceof se){const u=new ae(r),t={};for(const l of e._idmap.entries()){const[d,h]=l;u.process(h)}const i={},s={registry:e,uri:r?.uri,defs:t};for(const l of e._idmap.entries()){const[d,h]=l;i[d]=u.emit(h,{...r,external:s})}if(Object.keys(t).length>0){const l=u.target==="draft-2020-12"?"$defs":"definitions";i.__shared={[l]:t}}return{schemas:i}}const n=new ae(r);return n.process(e),n.emit(e,r)}function I(e,r){const n=r??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);const t=e._zod.def;switch(t.type){case"string":case"number":case"bigint":case"boolean":case"date":case"symbol":case"undefined":case"null":case"any":case"unknown":case"never":case"void":case"literal":case"enum":case"nan":case"file":case"template_literal":return!1;case"array":return I(t.element,n);case"object":{for(const i in t.shape)if(I(t.shape[i],n))return!0;return!1}case"union":{for(const i of t.options)if(I(i,n))return!0;return!1}case"intersection":return I(t.left,n)||I(t.right,n);case"tuple":{for(const i of t.items)if(I(i,n))return!0;return!!(t.rest&&I(t.rest,n))}case"record":return I(t.keyType,n)||I(t.valueType,n);case"map":return I(t.keyType,n)||I(t.valueType,n);case"set":return I(t.valueType,n);case"promise":case"optional":case"nonoptional":case"nullable":case"readonly":return I(t.innerType,n);case"lazy":return I(t.getter(),n);case"default":return I(t.innerType,n);case"prefault":return I(t.innerType,n);case"custom":return!1;case"transform":return!0;case"pipe":return I(t.in,n)||I(t.out,n);case"success":return!1;case"catch":return!1}throw new Error(`Unknown schema type: ${t.type}`)}const M=e=>e._def.typeName==="ZodObject",_e=e=>e._def.typeName==="ZodDefault",Se=e=>e._def.typeName==="ZodNullable",ke=e=>e._def.typeName==="ZodRecord",Ee=e=>e._def.typeName==="ZodArray",oe=e=>e._def.typeName==="ZodEffects",ie=e=>e._def.typeName==="ZodOptional",C=e=>{let r=e;for(;oe(r);)r=r.innerType();return ie(r)&&(r=r._def.innerType),r},Ve=e=>{let r=e;for(;oe(r);)r=r.innerType();return!!ie(r)};function xe(e){return Array.isArray(e)?"array":e===null?"null":typeof e}function Ie(e,r){const n=xe(e);return r.type?r.type===n||r.type==="integer"&&n==="number"&&Number.isInteger(e):!0}function T(e,r){if(e.anyOf&&Array.isArray(e.anyOf)){if(r!==void 0){for(const s of e.anyOf)if(Ie(r,s))return T(s,r);for(const s of e.anyOf){const l=s;if(!l.type||l.type==="object")return T(l,r)}}return T(e.anyOf[0],r)}if(e.type!=="object"||!e.properties)switch(e.type){case"string":return typeof r=="string"?r:e.default;case"number":case"integer":return typeof r=="number"?r:e.default;case"boolean":return typeof r=="boolean"?r:e.default;case"null":return r===null?r:e.default;case"array":return Array.isArray(r)&&e.items?r.map(s=>T(e.items,s)):e.default;default:return e.default}const n=e.properties,t=r&&typeof r=="object"&&!Array.isArray(r)?r:void 0,i={};for(const s in n){const l=t?.[s];i[s]=T(n[s],l)}if(t&&e.additionalProperties!==!1){const s=new Set(Object.keys(n));for(const[l,d]of Object.entries(t))s.has(l)||(i[l]=d)}return i}const U=e=>"_zod"in e;function F(e,r={}){if(U(e)){const t=je(e);if(t.type!=="object"||!t.properties)return r;const i=be(e,r);return T(t,i.success?i.data:r)}const n=C(e);return M(n)?{...n._def.unknownKeys==="passthrough"?r:{},...Object.fromEntries(("shape"in n?Object.entries(n.shape):[]).map(([t,i])=>{const s=r[t],l=Ve(i);let d=C(i),h;if(_e(d)&&(h=d._def.defaultValue(),d=d._def.innerType),s===null&&Se(d))return[t,s];if(s==null&&l)return[t,h];if(d){const p=i.safeParse(s);if(p.success)return[t,p.data??h]}if(Ee(d)&&Array.isArray(s)&&s.length){const p=C(d._def.type);if(M(p))return[t,s.map(f=>F(p,f&&typeof f=="object"?f:void 0))]}if(ke(d)&&s){const p=C(d._def.valueType);if(M(p))return[t,Object.keys(s).reduce((f,w)=>(f[w]=F(p,s[w]),f),{})]}return M(d)?[t,F(d,s&&typeof s=="object"?s:h)]:[t,h]}))}:r}const De=(e,r)=>U(e)?ge(e,r):e.safeParseAsync(r),Ne=(e,r)=>U(e)?ne(r):r.format(),Pe=(e,r)=>U(e)?ne(new te(r)):new A(r).format();function Re(e,r,n,u,t){const i=a.ref(),s=a.ref(),l=a.computed(()=>s.value===D.invalid),d=a.ref(),h=a.ref(!1);let p;const f=k=>{const x=F(e,k);if(n?.class){const y=n.class;return new y(x)}return x},w=async(k=d.value,x)=>{if(p=x?.fields,h.value)return!0;const y=await De(e,k);if(!y.success){if(s.value=D.invalid,!p?.size)return i.value=Ne(e,y.error),!1;const E=y.error.issues.filter(R=>p?.has(R.path.join(".")));return E.length?(i.value=Pe(e,E),!1):(i.value=void 0,!0)}return i.value=void 0,s.value=D.valid,d.value=f(y.data),!0},v=()=>{i.value=void 0,s.value=void 0,p=void 0},o=()=>{d.value=f(),v(),s.value=D.reset},c=async k=>h.value||!await w(void 0,k)?!1:(s.value=D.submitting,!0),{ignoreUpdates:m,stop:b}=q.watchIgnorable(d,()=>{s.value=D.updated},{deep:!0,eventFilter:q.throttleFilter(n?.updateThrottle??500)}),O=a.readonly(i),j=a.readonly(s),V=a.defineComponent({name:"VvForm",props:{continuousValidation:{type:Boolean,default:!1},modelValue:{type:Object,default:()=>({})},readonly:{type:Boolean,default:n?.readonly},tag:{type:String,default:"form"},template:{type:[Array,Function],default:void 0},superRefine:{type:Function,default:void 0},validateFields:{type:Array,default:void 0}},emits:["invalid","submit","update:modelValue","update:readonly","valid","reset"],expose:["errors","invalid","readonly","status","submit","tag","template","valid","validate","clear","reset"],slots:Object,setup(k,{emit:x}){return d.value=f(a.toRaw(k.modelValue)),a.watch(()=>k.modelValue,y=>{if(y){const E=a.isProxy(y)?a.toRaw(y):y;if(JSON.stringify(E)===JSON.stringify(a.toRaw(d.value)))return;d.value=typeof E?.clone=="function"?E.clone():JSON.parse(JSON.stringify(E))}},{deep:!0}),a.watch(s,async y=>{if(y===D.invalid){const E=a.toRaw(i.value);x("invalid",E),n?.onInvalid?.(E);return}if(y===D.valid){const E=a.toRaw(d.value);x("valid",E),n?.onValid?.(E),x("update:modelValue",E),n?.onUpdate?.(E);return}if(y===D.submitting){const E=a.toRaw(d.value);x("submit",E),n?.onSubmit?.(E);return}if(y===D.reset){const E=a.toRaw(d.value);x("reset",E),n?.onReset?.(E);return}if(y===D.updated){if((i.value||n?.continuousValidation||k.continuousValidation)&&await w(void 0,{superRefine:k.superRefine,fields:p??new Set(k.validateFields)}),!d.value||!k.modelValue||JSON.stringify(d.value)!==JSON.stringify(k.modelValue)){const E=a.toRaw(d.value);x("update:modelValue",E),n?.onUpdate?.(E)}s.value===D.updated&&(s.value=D.unknown)}}),a.onMounted(()=>{k.readonly!==void 0&&(h.value=k.readonly)}),a.watch(()=>k.readonly,y=>{h.value=y}),a.watch(h,y=>{y!==k.readonly&&x("update:readonly",h.value)}),a.provide(r,{clear:v,errors:O,formData:d,ignoreUpdates:m,invalid:l,readonly:h,reset:o,status:j,stopUpdatesWatch:b,submit:c,validate:w,wrappers:t}),{clear:v,errors:O,formData:d,ignoreUpdates:m,invalid:l,isReadonly:h,reset:o,status:j,stopUpdatesWatch:b,submit:()=>c({superRefine:k.superRefine,fields:new Set(k.validateFields)}),validate:w,wrappers:t}},render(){const k=()=>this.$slots?.default?.({errors:O.value,formData:d.value,invalid:l.value,readonly:h.value,status:j.value,wrappers:t,clear:v,ignoreUpdates:m,reset:o,stopUpdatesWatch:b,submit:c,validate:w})??this.$slots.default;return a.h(this.tag,{onSubmit:a.withModifiers(this.submit,["prevent"]),onReset:a.withModifiers(this.reset,["prevent"])},(this.template??n?.template)&&u?[a.h(u,{schema:this.template??n?.template},{default:k})]:{default:k})}});return{clear:v,errors:i,formData:d,ignoreUpdates:m,invalid:l,readonly:h,reset:o,status:s,wrappers:t,stopUpdatesWatch:b,submit:c,validate:w,VvForm:V}}function K(e){return Array.isArray(e)}function Te(e){return!1}function le(e){return e===null}function ue(e){return typeof e=="object"}function ce(e){return typeof e=="string"}function Z(e){return typeof e>"u"}const $e=/^[0-9]+$/,ze=["__proto__","prototype","constructor"];function $(e,r,n){const u=Te()?n:void 0;if(!ue(e)||!ce(r))return u;const t=fe(r);if(t.length!==0){for(const i of t){if(i==="*")continue;const s=function(l){return l.map(d=>Z(d)||le(d)?d:K(d)?s(d):d[i])};if(K(e)&&!$e.test(i)?e=s(e):e=e[i],Z(e)||le(e))break}return Z(e)?u:e}}function L(e,r,n){if(!ue(e)||!ce(r))return;const u=fe(r);if(u.length===0)return;const t=u.length;for(let i=0;i<t;i++){const s=u[i];if(i===t-1){e[s]=n;return}if(s==="*"&&K(e)){const l=u.slice(i+1).join(".");for(const d of e)L(d,l,n);return}Z(e[s])&&(e[s]={}),e=e[s]}}function fe(e){const r=e.split(/[.]|(?:\[(\d|\*)\])/).filter(n=>!!n);return r.some(n=>ze.indexOf(n)!==-1)?[]:r}function Ae(e,r,n,u){return a.defineComponent({name:"VvFormField",props:{type:{type:String,validator:t=>Object.values(S).includes(t),default:S.custom},is:{type:[Object,String],default:void 0},name:{type:[String,Number,Boolean,Symbol],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValue:{type:[String,Number,Boolean,Array,Object],default:void 0},lazyLoad:{type:Boolean,default:!1},readonly:{type:Boolean,default:void 0}},emits:["invalid","update:formData","update:modelValue","valid"],expose:["component","errors","hasProps","invalid","invalidLabel","is","type"],slots:Object,setup(t,{slots:i,emit:s}){const{props:l,name:d}=a.toRefs(t),h=a.useId(),p=a.inject(r,void 0);p&&p.fields.value.set(h,t.name);const f=a.inject(e),w=a.computed({get(){if(f?.formData)return $(new Object(f.formData.value),String(t.name))},set(y){f?.formData&&(L(new Object(f.formData.value),String(t.name),y),s("update:modelValue",{newValue:w.value,formData:f?.formData}))}});a.onMounted(()=>{w.value===void 0&&t.defaultValue!==void 0&&(w.value=t.defaultValue)}),a.onBeforeUnmount(()=>{p&&p.fields.value.delete(h)});const v=a.computed(()=>{if(f?.errors.value)return $(f.errors.value,String(t.name))}),o=a.computed(()=>v.value?._errors),c=a.computed(()=>v.value!==void 0),m=a.watch(c,y=>{if(y){s("invalid",v.value),p&&p.errors.value.set(String(t.name),v.value);return}s("valid",w.value),p&&p.errors.value.delete(t.name)}),b=a.watch(()=>f?.formData,()=>{s("update:formData",f?.formData)},{deep:!0});a.onBeforeUnmount(()=>{m(),b()});const O=y=>{y instanceof InputEvent&&(y=y.target.value),w.value=y},j=a.computed(()=>{let y=l.value;return typeof y=="function"&&(y=y(f?.formData)),Object.keys(y).reduce((E,R)=>(E[R]=a.unref(y[R]),E),{})}),V=a.computed(()=>f?.readonly.value||p?.readonly.value?!0:j.value.readonly??t.readonly),k=a.computed(()=>({...j.value,name:j.value.name??t.name,invalid:c.value,valid:t.showValid?!!(!c.value&&w.value):void 0,type:(y=>{if([S.color,S.date,S.datetimeLocal,S.email,S.month,S.number,S.password,S.search,S.tel,S.text,S.time,S.url,S.week].includes(y))return y})(t.type),invalidLabel:o.value,modelValue:w.value,readonly:V.value,"onUpdate:modelValue":O}));return a.provide(n,{name:a.readonly(d),errors:a.readonly(v)}),{component:a.computed(()=>{if(t.type===S.custom)return{render(){return i.default?.({errors:v.value,formData:f?.formData.value,formErrors:f?.errors.value,invalid:c.value,invalidLabel:o.value,modelValue:w.value,readonly:V.value,onUpdate:O,submit:f?.submit,validate:f?.validate})??i.default}};if(!(u?.lazyLoad??t.lazyLoad)){let y;switch(t.type){case S.select:y=a.resolveComponent("VvSelect");break;case S.checkbox:y=a.resolveComponent("VvCheckbox");break;case S.radio:y=a.resolveComponent("VvRadio");break;case S.textarea:y=a.resolveComponent("VvTextarea");break;case S.radioGroup:y=a.resolveComponent("VvRadioGroup");break;case S.checkboxGroup:y=a.resolveComponent("VvCheckboxGroup");break;case S.combobox:y=a.resolveComponent("VvCombobox");break;default:y=a.resolveComponent("VvInputText")}if(typeof y!="string")return y;console.warn(`[@volverjs/form-vue]: ${y} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return a.defineAsyncComponent(async()=>{switch(u?.sideEffects&&await Promise.resolve(u.sideEffects(t.type)),t.type){case S.textarea:return import("@volverjs/ui-vue/vv-textarea");case S.radio:return import("@volverjs/ui-vue/vv-radio");case S.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case S.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case S.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case S.select:return import("@volverjs/ui-vue/vv-select");case S.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:k,invalid:c}},render(){return this.is?a.h(this.is,this.hasProps,this.$slots):this.type===S.custom?a.h(this.component,null,this.$slots):a.h(this.component,this.hasProps,this.$slots)}})}function Fe(e,r,n){return a.defineComponent({name:"VvFormFieldsGroup",props:{is:{type:[Object,String],default:void 0},names:{type:[Array,Object],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValues:{type:[Object],default:void 0},readonly:{type:Boolean,default:void 0}},emits:["invalid","update:formData","update:modelValue","valid"],expose:["component","errors","hasProps","invalid","invalidLabels","is"],slots:Object,setup(u,{slots:t,emit:i}){const{props:s,names:l,defaultValues:d}=a.toRefs(u),h=a.useId(),p=a.computed(()=>Array.isArray(l.value)?l.value:Object.values(l.value)),f=a.computed(()=>Array.isArray(l.value)?l.value:Object.keys(l.value)),w=a.computed(()=>Array.isArray(l.value)?l.value.reduce((g,_)=>(g[String(_)]=_,g),{}):l.value),v=a.computed(()=>Object.keys(w.value).reduce((g,_)=>(g[String(w.value[_])]=_,g),{})),o=a.inject(r,void 0);o&&p.value.forEach(g=>{o.fields.value.set(`${h}-${g}`,g)});const c=a.inject(e),m=a.computed({get(){return c?.formData?f.value.reduce((g,_)=>(g[_]=$(new Object(c.formData.value),w.value[_]),g),{}):{}},set(g){c?.formData&&(f.value.forEach(_=>{L(new Object(c.formData.value),w.value[_],g?.[_])}),i("update:modelValue",{newValue:m.value,formData:c?.formData}))}});a.onMounted(()=>{d.value&&p.value.forEach(g=>{d.value?.[g]!==void 0&&m.value[g]===void 0&&(m.value={...m.value,[g]:d.value?.[g]})})}),a.onBeforeUnmount(()=>{o&&p.value.forEach(g=>{o.fields.value.delete(`${h}-${g}`)})});const b=a.computed(()=>{if(!c?.errors.value)return;const g=p.value.reduce((_,P)=>{if(!c.errors.value)return _;const pe=$(c.errors.value,String(P));return pe===void 0||(_[String(P)]=pe),_},{});if(Object.keys(g).length!==0)return g}),O=a.computed(()=>{if(!b.value)return;const g=Object.keys(b.value).reduce((_,P)=>(b.value?.[P]&&(_[v.value[P]]=b.value[P]._errors),_),{});if(Object.keys(g).length!==0)return g}),j=a.computed(()=>b.value!==void 0),V=a.computed(()=>f.value.reduce((g,_)=>(g[_]=!!b.value?.[v.value[_]],g),{})),k=a.watch(j,()=>{if(j.value){i("invalid",b.value),o&&p.value.forEach(g=>{if(!b.value?.[g]){o.errors.value.delete(g);return}o.errors.value.set(g,b.value?.[g])});return}i("valid",m.value),o&&p.value.forEach(g=>{o.errors.value.delete(g)})}),x=a.watch(()=>c?.formData,()=>{i("update:formData",c?.formData)},{deep:!0});a.onBeforeUnmount(()=>{k(),x()});const y=g=>{m.value=g},E=(g,_)=>{_ instanceof InputEvent&&(_=_.target.value),f.value.includes(g)&&(m.value={...m.value,[g]:_})},R=a.computed(()=>{let g=s.value;return typeof g=="function"&&(g=g(c?.formData)),Object.keys(g).reduce((_,P)=>(_[P]=a.unref(g[P]),_),{})}),de=a.computed(()=>c?.readonly.value?!0:R.value.readonly??u.readonly),Be=a.computed(()=>f.value.reduce((g,_)=>(g[`onUpdate:${_}`]=P=>{E(_,P)},g),{"onUpdate:modelValue":y})),Ge=a.computed(()=>({...Be.value,...R.value,...m.value,modelValue:m.value,names:R.value.name??p.value,invalid:j.value,invalids:V.value,valid:u.showValid?!!(!j.value&&m.value):void 0,invalidLabels:O.value,readonly:de.value}));return a.provide(n,{names:a.readonly(l),errors:a.readonly(b)}),{component:a.computed(()=>({render(){return t.default?.({errors:b.value,formData:c?.formData.value,formErrors:c?.errors.value,invalid:j.value,invalids:V.value,invalidLabels:O.value,modelValue:m.value,onUpdate:y,onUpdateField:E,readonly:de.value,submit:c?.submit,validate:c?.validate})??t.default}})),hasProps:Ge,invalid:j}},render(){return this.is?a.h(this.is,this.hasProps,this.$slots):a.h(this.component,null,this.$slots)}})}function Je(e,r){return a.defineComponent({name:"VvFormWrapper",props:{name:{type:String,required:!0},tag:{type:String,default:void 0},readonly:{type:Boolean,default:!1}},emits:["invalid","valid"],expose:["clear","errors","fields","fieldsErrors","formData","invalid","readonly","reset","submit","tag","validate","validateWrapper"],slots:Object,setup(n,{emit:u}){const t=a.inject(e),i=a.inject(r,void 0),s=a.ref(new Map),l=a.ref(new Map),{name:d}=a.toRefs(n),h=a.computed(()=>t?.invalid.value?l.value.size>0:!1);a.watch(h,o=>{if(o){u("invalid");return}u("valid")});const p=a.computed(()=>t?.readonly.value||n.readonly),f={name:a.readonly(d),errors:l,invalid:a.readonly(h),readonly:a.readonly(p),fields:s};a.provide(r,f);const w=a.computed(()=>new Map(s.value));a.watch(w,(o,c)=>{i?.fields&&(c.forEach((m,b)=>{o.has(b)||i?.fields.value.delete(b)}),o.forEach((m,b)=>{i?.fields.value.has(b)||i?.fields.value.set(b,m)}))},{deep:!0}),a.watch(l,o=>{i?.errors&&s.value.forEach(c=>{if(o.has(c)||i.errors.value.delete(c),o.has(c)){const m=o.get(c);m&&i.errors.value.set(c,m)}})},{deep:!0}),a.onMounted(()=>{if(!t?.wrappers||!d.value){console.warn("[@volverjs/form-vue]: Invalid wrapper registration state");return}if(t.wrappers.has(d.value)){console.warn(`[@volverjs/form-vue]: wrapper name "${d.value}" is already used`);return}t.wrappers.set(d.value,f)}),a.onBeforeUnmount(()=>{t?.wrappers&&d.value&&t.wrappers.delete(d.value)});const v=()=>t?.validate(void 0,{fields:new Set(s.value.values())})??Promise.resolve(!0);return{errors:t?.errors,fields:s,fieldsErrors:l,formData:t?.formData,invalid:h,readonly:p,clear:t?.clear,reset:t?.reset,submit:t?.submit,validate:t?.validate,validateWrapper:v}},render(){const n=()=>this.$slots.default?.({errors:this.errors,fieldsErrors:this.fieldsErrors,formData:this.formData,invalid:this.invalid,readonly:this.readonly,clear:this.clear,reset:this.reset,submit:this.submit,validate:this.validate,validateWrapper:this.validateWrapper});return this.tag?a.h(this.tag,null,{default:n}):n()}})}function Me(e,r){const n=a.defineComponent({name:"VvFormTemplate",props:{schema:{type:[Array,Function],required:!0},scope:{type:Object,default:()=>({})}},slots:Object,setup(u,{slots:t}){const i=a.inject(e);if(i?.formData)return()=>{const s=typeof u.schema=="function"?u.schema(i,u.scope):u.schema;let l;const d=s.reduce((h,p)=>{const f=typeof p=="function"?p(i,u.scope):p,{vvIs:w,vvName:v,vvSlots:o,vvChildren:c,vvIf:m,vvElseIf:b,vvType:O,vvDefaultValue:j,vvShowValid:V,vvContent:k,...x}=f;if(m!==void 0){if(typeof m=="string"?l=!!$(new Object(i.formData.value),m):typeof m=="function"?l=a.unref(m(i)):l=a.unref(m),!l)return h}else if(b!==void 0&&l!==void 0){if(l||(typeof b=="string"?l=!!$(new Object(i.formData.value),b):typeof b=="function"?l=a.unref(b(i)):l=a.unref(b),!l))return h}else l=void 0;let y;return c&&(typeof w=="string"?y=a.h(n,{schema:c}):y={default:E=>a.h(n,{schema:c,scope:E})}),v?(h.push(a.h(r,{name:v,is:w,type:O,defaultValue:j,showValid:V,props:x},o??y??k)),h):w?(h.push(a.h(w,x,o??y??k)),h):(y&&("default"in y?h.push(y.default(u.scope)):h.push(y)),h)},[]);return d.push(t?.default?.({errors:i?.errors.value,formData:i?.formData.value,invalid:i?.invalid.value,status:i?.status.value,submit:i?.submit,validate:i?.validate,clear:i?.clear,reset:i?.reset})),d}}});return n}function B(e,r={}){const n=Symbol("formInjectionKey"),u=Symbol("formWrapperInjectionKey"),t=Symbol("formFieldInjectionKey"),i=Symbol("formFieldsGroupInjectionKey"),s=Je(n,u),l=Ae(n,u,t,r),d=Fe(n,u,i),h=Me(n,l),p=new Map,{clear:f,errors:w,formData:v,ignoreUpdates:o,invalid:c,readonly:m,reset:b,status:O,stopUpdatesWatch:j,submit:V,validate:k,VvForm:x}=Re(e,n,r,h,p);return{clear:f,errors:w,formData:v,formFieldInjectionKey:t,formInjectionKey:n,formWrapperInjectionKey:u,ignoreUpdates:o,invalid:c,readonly:m,reset:b,status:O,stopUpdatesWatch:j,submit:V,validate:k,wrappers:p,VvForm:x,VvFormField:l,VvFormFieldsGroup:d,VvFormTemplate:h,VvFormWrapper:s}}const W=Symbol("pluginInjectionKey");function Ce(e){let r={};return e.schema&&(r=B(e.schema,e)),{...r,install(n,{global:u=!1}={}){n.provide(W,e),u&&(n.config.globalProperties.$vvForm=e,r?.VvForm&&n.component("VvForm",r.VvForm),r?.VvFormWrapper&&n.component("VvFormWrapper",r.VvFormWrapper),r?.VvFormField&&n.component("VvFormField",r.VvFormField),r?.VvFormFieldsGroup&&n.component("VvFormFieldsGroup",r.VvFormFieldsGroup),r?.VvFormTemplate&&n.component("VvFormTemplate",r.VvFormTemplate))}}}const G=new Map;function Ue(e,r={}){if(r.scope&&G.has(r.scope))return G.get(r.scope);if(!a.getCurrentInstance()){const u=B(e,r);return r.scope&&G.set(r.scope,u),u}const n=B(e,{...a.inject(W,{}),...r});return r.scope&&G.set(r.scope,n),n}function Ze(e,r={}){return B(e,r)}N.FormFieldType=S,N.createForm=Ce,N.defaultObjectBySchema=F,N.formType=Ze,N.pluginInjectionKey=W,N.useForm=Ue,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})});
1
+ (function(S,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@vueuse/core"),require("zod/v3"),require("zod/v4/core"),require("ts-dot-prop")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod/v3","zod/v4/core","ts-dot-prop"],e):(S=typeof globalThis<"u"?globalThis:S||self,e(S["@volverjs/form-vue"]={},S.Vue,S.VueUseCore,S.zodV3,S.zodV4Core,S.tsDotProp))})(this,function(S,e,L,X,A,Z){"use strict";var j=(t=>(t.text="text",t.number="number",t.email="email",t.password="password",t.tel="tel",t.url="url",t.search="search",t.date="date",t.time="time",t.datetimeLocal="datetime-local",t.month="month",t.week="week",t.color="color",t.select="select",t.checkbox="checkbox",t.radio="radio",t.textarea="textarea",t.radioGroup="radioGroup",t.checkboxGroup="checkboxGroup",t.combobox="combobox",t.custom="custom",t))(j||{}),z=(t=>(t.invalid="invalid",t.valid="valid",t.submitting="submitting",t.reset="reset",t.updated="updated",t.unknown="unknown",t))(z||{});const B=t=>t._def.typeName==="ZodObject",N=t=>t._zod.def.type==="object",Y=t=>t._def.typeName==="ZodDefault",ee=t=>t._zod.def.type==="default",te=t=>t._def.typeName==="ZodNullable",re=t=>t._zod.def.type==="nullable",ae=t=>t._def.typeName==="ZodRecord",ne=t=>t._zod.def.type==="record",oe=t=>t._def.typeName==="ZodArray",le=t=>t._zod.def.type==="array",M=t=>t._def.typeName==="ZodEffects",K=t=>t._def.typeName==="ZodOptional",P=t=>t._zod.def.type==="optional",q=t=>t._zod.def.type==="pipe",J=t=>t._zod.def.type==="transform",G=t=>{let r=t;for(;M(r);)r=r.innerType();return K(r)&&(r=r._def.innerType),r},U=t=>{let r=t;for(;q(r);)J(r._zod.def.out)?r=r._zod.def.in:r=r._zod.def.out;return P(r)&&(r=r._zod.def.innerType),r},ie=t=>{let r=t;for(;M(r);)r=r.innerType();return!!K(r)},se=t=>{let r=t;for(;q(r);)J(r._zod.def.out)?r=r._zod.def.in:r=r._zod.def.out;return!!P(r)},k=t=>"_zod"in t;function x(t,r={}){if(k(t)){const n=U(t);return N(n)?{...!(!n._zod.def.catchall||n._zod.def.catchall?._zod.def.type==="never")?r:{},...Object.fromEntries(("shape"in n._zod.def?Object.entries(n._zod.def.shape):[]).map(([i,c])=>{const a=r[i],v=se(c);let l=U(c),f;if(ee(l)&&(f=l._zod.def.defaultValue,l=l._zod.def.innerType),a===null&&re(l))return[i,a];if(a==null&&v)return[i,f];if(l){const m=A.safeParse(c,a);if(m.success)return[i,m.data??f]}if(le(l)&&Array.isArray(a)&&a.length){const m=U(l._zod.def.element);if(N(m))return[i,a.map(D=>x(m,D&&typeof D=="object"?D:void 0))]}if(ne(l)&&a){const m=U(l._zod.def.valueType);if(N(m))return[i,Object.keys(a).reduce((D,y)=>(D[y]=x(m,a[y]),D),{})]}return N(l)?[i,x(l,a&&typeof a=="object"?a:f)]:[i,f]}))}:r}const s=G(t);return B(s)?{...s._def.unknownKeys==="passthrough"?r:{},...Object.fromEntries(("shape"in s?Object.entries(s.shape):[]).map(([n,d])=>{const i=r[n],c=ie(d);let a=G(d),v;if(Y(a)&&(v=a._def.defaultValue(),a=a._def.innerType),i===null&&te(a))return[n,i];if(i==null&&c)return[n,v];if(a){const l=d.safeParse(i);if(l.success)return[n,l.data??v]}if(oe(a)&&Array.isArray(i)&&i.length){const l=G(a._def.type);if(B(l))return[n,i.map(f=>x(l,f&&typeof f=="object"?f:void 0))]}if(ae(a)&&i){const l=G(a._def.valueType);if(B(l))return[n,Object.keys(i).reduce((f,m)=>(f[m]=x(l,i[m]),f),{})]}return B(a)?[n,x(a,i&&typeof i=="object"?i:v)]:[n,v]}))}:r}const ue=(t,r)=>k(t)?A.safeParseAsync(t,r):t.safeParseAsync(r),de=(t,r)=>k(t)?A.formatError(r):r.format(),fe=(t,r)=>k(t)?A.formatError(new A.$ZodError(r)):new X.ZodError(r).format();function ce(t,r,s,g,n){const d=e.ref(),i=e.ref(),c=e.computed(()=>i.value===z.invalid),a=e.ref(),v=e.ref(!1);let l;const f=O=>{const R=x(t,O);if(s?.class){const o=s.class;return new o(R)}return R},m=async(O=a.value,R)=>{if(l=R?.fields,v.value)return!0;const o=await ue(t,O);if(!o.success){if(i.value=z.invalid,!l?.size)return d.value=de(t,o.error),!1;const V=o.error.issues.filter(C=>l?.has(C.path.join(".")));return V.length?(d.value=fe(t,V),!1):(d.value=void 0,!0)}return d.value=void 0,i.value=z.valid,a.value=f(o.data),!0},D=()=>{d.value=void 0,i.value=void 0,l=void 0},y=()=>{a.value=f(),D(),i.value=z.reset},p=async O=>v.value||!await m(void 0,O)?!1:(i.value=z.submitting,!0),{ignoreUpdates:h,stop:w}=L.watchIgnorable(a,()=>{i.value=z.updated},{deep:!0,eventFilter:L.throttleFilter(s?.updateThrottle??500)}),I=e.readonly(d),_=e.readonly(i),E=e.defineComponent({name:"VvForm",props:{continuousValidation:{type:Boolean,default:!1},modelValue:{type:Object,default:()=>({})},readonly:{type:Boolean,default:s?.readonly},tag:{type:String,default:"form"},template:{type:[Array,Function],default:void 0},superRefine:{type:Function,default:void 0},validateFields:{type:Array,default:void 0}},emits:["invalid","submit","update:modelValue","update:readonly","valid","reset"],expose:["errors","invalid","readonly","status","submit","tag","template","valid","validate","clear","reset"],slots:Object,setup(O,{emit:R}){return a.value=f(e.toRaw(O.modelValue)),e.watch(()=>O.modelValue,o=>{if(o){const V=e.isProxy(o)?e.toRaw(o):o;if(JSON.stringify(V)===JSON.stringify(e.toRaw(a.value)))return;a.value=typeof V?.clone=="function"?V.clone():JSON.parse(JSON.stringify(V))}},{deep:!0}),e.watch(i,async o=>{if(o===z.invalid){const V=e.toRaw(d.value);R("invalid",V),s?.onInvalid?.(V);return}if(o===z.valid){const V=e.toRaw(a.value);R("valid",V),s?.onValid?.(V),R("update:modelValue",V),s?.onUpdate?.(V);return}if(o===z.submitting){const V=e.toRaw(a.value);R("submit",V),s?.onSubmit?.(V);return}if(o===z.reset){const V=e.toRaw(a.value);R("reset",V),s?.onReset?.(V);return}if(o===z.updated){if((d.value||s?.continuousValidation||O.continuousValidation)&&await m(void 0,{superRefine:O.superRefine,fields:l??new Set(O.validateFields)}),!a.value||!O.modelValue||JSON.stringify(a.value)!==JSON.stringify(O.modelValue)){const V=e.toRaw(a.value);R("update:modelValue",V),s?.onUpdate?.(V)}i.value===z.updated&&(i.value=z.unknown)}}),e.onMounted(()=>{O.readonly!==void 0&&(v.value=O.readonly)}),e.watch(()=>O.readonly,o=>{v.value=o}),e.watch(v,o=>{o!==O.readonly&&R("update:readonly",v.value)}),e.provide(r,{clear:D,errors:I,formData:a,ignoreUpdates:h,invalid:c,readonly:v,reset:y,status:_,stopUpdatesWatch:w,submit:p,validate:m,wrappers:n}),{clear:D,errors:I,formData:a,ignoreUpdates:h,invalid:c,isReadonly:v,reset:y,status:_,stopUpdatesWatch:w,submit:()=>p({superRefine:O.superRefine,fields:new Set(O.validateFields)}),validate:m,wrappers:n}},render(){const O=()=>this.$slots?.default?.({errors:I.value,formData:a.value,invalid:c.value,readonly:v.value,status:_.value,wrappers:n,clear:D,ignoreUpdates:h,reset:y,stopUpdatesWatch:w,submit:p,validate:m})??this.$slots.default;return e.h(this.tag,{onSubmit:e.withModifiers(this.submit,["prevent"]),onReset:e.withModifiers(this.reset,["prevent"])},(this.template??s?.template)&&g?[e.h(g,{schema:this.template??s?.template},{default:O})]:{default:O})}});return{clear:D,errors:d,formData:a,ignoreUpdates:h,invalid:c,readonly:v,reset:y,status:i,wrappers:n,stopUpdatesWatch:w,submit:p,validate:m,VvForm:E}}function ve(t,r,s,g){return e.defineComponent({name:"VvFormField",props:{type:{type:String,validator:n=>Object.values(j).includes(n),default:j.custom},is:{type:[Object,String],default:void 0},name:{type:[String,Number,Boolean,Symbol],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValue:{type:[String,Number,Boolean,Array,Object],default:void 0},lazyLoad:{type:Boolean,default:!1},readonly:{type:Boolean,default:void 0}},emits:["invalid","update:formData","update:modelValue","valid"],expose:["component","errors","hasProps","invalid","invalidLabel","is","type"],slots:Object,setup(n,{slots:d,emit:i}){const{props:c,name:a}=e.toRefs(n),v=e.useId(),l=e.inject(r,void 0);l&&l.fields.value.set(v,n.name);const f=e.inject(t),m=e.computed({get(){if(f?.formData)return Z.get(new Object(f.formData.value),String(n.name))},set(o){f?.formData&&(Z.set(new Object(f.formData.value),String(n.name),o),i("update:modelValue",{newValue:m.value,formData:f?.formData}))}});e.onMounted(()=>{m.value===void 0&&n.defaultValue!==void 0&&(m.value=n.defaultValue)}),e.onBeforeUnmount(()=>{l&&l.fields.value.delete(v)});const D=e.computed(()=>{if(f?.errors.value)return Z.get(f.errors.value,String(n.name))}),y=e.computed(()=>D.value?._errors),p=e.computed(()=>D.value!==void 0),h=e.watch(p,o=>{if(o){i("invalid",D.value),l&&l.errors.value.set(String(n.name),D.value);return}i("valid",m.value),l&&l.errors.value.delete(n.name)}),w=e.watch(()=>f?.formData,()=>{i("update:formData",f?.formData)},{deep:!0});e.onBeforeUnmount(()=>{h(),w()});const I=o=>{o instanceof InputEvent&&(o=o.target.value),m.value=o},_=e.computed(()=>{let o=c.value;return typeof o=="function"&&(o=o(f?.formData)),Object.keys(o).reduce((V,C)=>(V[C]=e.unref(o[C]),V),{})}),E=e.computed(()=>f?.readonly.value||l?.readonly.value?!0:_.value.readonly??n.readonly),O=e.computed(()=>({..._.value,name:_.value.name??n.name,invalid:p.value,valid:n.showValid?!!(!p.value&&m.value):void 0,type:(o=>{if([j.color,j.date,j.datetimeLocal,j.email,j.month,j.number,j.password,j.search,j.tel,j.text,j.time,j.url,j.week].includes(o))return o})(n.type),invalidLabel:y.value,modelValue:m.value,readonly:E.value,"onUpdate:modelValue":I}));return e.provide(s,{name:e.readonly(a),errors:e.readonly(D)}),{component:e.computed(()=>{if(n.type===j.custom)return{render(){return d.default?.({errors:D.value,formData:f?.formData.value,formErrors:f?.errors.value,invalid:p.value,invalidLabel:y.value,modelValue:m.value,readonly:E.value,onUpdate:I,submit:f?.submit,validate:f?.validate})??d.default}};if(!(g?.lazyLoad??n.lazyLoad)){let o;switch(n.type){case j.select:o=e.resolveComponent("VvSelect");break;case j.checkbox:o=e.resolveComponent("VvCheckbox");break;case j.radio:o=e.resolveComponent("VvRadio");break;case j.textarea:o=e.resolveComponent("VvTextarea");break;case j.radioGroup:o=e.resolveComponent("VvRadioGroup");break;case j.checkboxGroup:o=e.resolveComponent("VvCheckboxGroup");break;case j.combobox:o=e.resolveComponent("VvCombobox");break;default:o=e.resolveComponent("VvInputText")}if(typeof o!="string")return o;console.warn(`[@volverjs/form-vue]: ${o} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return e.defineAsyncComponent(async()=>{switch(g?.sideEffects&&await Promise.resolve(g.sideEffects(n.type)),n.type){case j.textarea:return import("@volverjs/ui-vue/vv-textarea");case j.radio:return import("@volverjs/ui-vue/vv-radio");case j.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case j.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case j.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case j.select:return import("@volverjs/ui-vue/vv-select");case j.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:O,invalid:p}},render(){return this.is?e.h(this.is,this.hasProps,this.$slots):this.type===j.custom?e.h(this.component,null,this.$slots):e.h(this.component,this.hasProps,this.$slots)}})}function me(t,r,s){return e.defineComponent({name:"VvFormFieldsGroup",props:{is:{type:[Object,String],default:void 0},names:{type:[Array,Object],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValues:{type:[Object],default:void 0},readonly:{type:Boolean,default:void 0}},emits:["invalid","update:formData","update:modelValue","valid"],expose:["component","errors","hasProps","invalid","invalidLabels","is"],slots:Object,setup(g,{slots:n,emit:d}){const{props:i,names:c,defaultValues:a}=e.toRefs(g),v=e.useId(),l=e.computed(()=>Array.isArray(c.value)?c.value:Object.values(c.value)),f=e.computed(()=>Array.isArray(c.value)?c.value:Object.keys(c.value)),m=e.computed(()=>Array.isArray(c.value)?c.value.reduce((u,b)=>(u[String(b)]=b,u),{}):c.value),D=e.computed(()=>Object.keys(m.value).reduce((u,b)=>(u[String(m.value[b])]=b,u),{})),y=e.inject(r,void 0);y&&l.value.forEach(u=>{y.fields.value.set(`${v}-${u}`,u)});const p=e.inject(t),h=e.computed({get(){return p?.formData?f.value.reduce((u,b)=>(u[b]=Z.get(new Object(p.formData.value),m.value[b]),u),{}):{}},set(u){p?.formData&&(f.value.forEach(b=>{Z.set(new Object(p.formData.value),m.value[b],u?.[b])}),d("update:modelValue",{newValue:h.value,formData:p?.formData}))}});e.onMounted(()=>{a.value&&l.value.forEach(u=>{a.value?.[u]!==void 0&&h.value[u]===void 0&&(h.value={...h.value,[u]:a.value?.[u]})})}),e.onBeforeUnmount(()=>{y&&l.value.forEach(u=>{y.fields.value.delete(`${v}-${u}`)})});const w=e.computed(()=>{if(!p?.errors.value)return;const u=l.value.reduce((b,F)=>{if(!p.errors.value)return b;const Q=Z.get(p.errors.value,String(F));return Q===void 0||(b[String(F)]=Q),b},{});if(Object.keys(u).length!==0)return u}),I=e.computed(()=>{if(!w.value)return;const u=Object.keys(w.value).reduce((b,F)=>(w.value?.[F]&&(b[D.value[F]]=w.value[F]._errors),b),{});if(Object.keys(u).length!==0)return u}),_=e.computed(()=>w.value!==void 0),E=e.computed(()=>f.value.reduce((u,b)=>(u[b]=!!w.value?.[D.value[b]],u),{})),O=e.watch(_,()=>{if(_.value){d("invalid",w.value),y&&l.value.forEach(u=>{if(!w.value?.[u]){y.errors.value.delete(u);return}y.errors.value.set(u,w.value?.[u])});return}d("valid",h.value),y&&l.value.forEach(u=>{y.errors.value.delete(u)})}),R=e.watch(()=>p?.formData,()=>{d("update:formData",p?.formData)},{deep:!0});e.onBeforeUnmount(()=>{O(),R()});const o=u=>{h.value=u},V=(u,b)=>{b instanceof InputEvent&&(b=b.target.value),f.value.includes(u)&&(h.value={...h.value,[u]:b})},C=e.computed(()=>{let u=i.value;return typeof u=="function"&&(u=u(p?.formData)),Object.keys(u).reduce((b,F)=>(b[F]=e.unref(u[F]),b),{})}),H=e.computed(()=>p?.readonly.value?!0:C.value.readonly??g.readonly),we=e.computed(()=>f.value.reduce((u,b)=>(u[`onUpdate:${b}`]=F=>{V(b,F)},u),{"onUpdate:modelValue":o})),Ve=e.computed(()=>({...we.value,...C.value,...h.value,modelValue:h.value,names:C.value.name??l.value,invalid:_.value,invalids:E.value,valid:g.showValid?!!(!_.value&&h.value):void 0,invalidLabels:I.value,readonly:H.value}));return e.provide(s,{names:e.readonly(c),errors:e.readonly(w)}),{component:e.computed(()=>({render(){return n.default?.({errors:w.value,formData:p?.formData.value,formErrors:p?.errors.value,invalid:_.value,invalids:E.value,invalidLabels:I.value,modelValue:h.value,onUpdate:o,onUpdateField:V,readonly:H.value,submit:p?.submit,validate:p?.validate})??n.default}})),hasProps:Ve,invalid:_}},render(){return this.is?e.h(this.is,this.hasProps,this.$slots):e.h(this.component,null,this.$slots)}})}function pe(t,r){return e.defineComponent({name:"VvFormWrapper",props:{name:{type:String,required:!0},tag:{type:String,default:void 0},readonly:{type:Boolean,default:!1}},emits:["invalid","valid"],expose:["clear","errors","fields","fieldsErrors","formData","invalid","readonly","reset","submit","tag","validate","validateWrapper"],slots:Object,setup(s,{emit:g}){const n=e.inject(t),d=e.inject(r,void 0),i=e.ref(new Map),c=e.ref(new Map),{name:a}=e.toRefs(s),v=e.computed(()=>n?.invalid.value?c.value.size>0:!1);e.watch(v,y=>{if(y){g("invalid");return}g("valid")});const l=e.computed(()=>n?.readonly.value||s.readonly),f={name:e.readonly(a),errors:c,invalid:e.readonly(v),readonly:e.readonly(l),fields:i};e.provide(r,f);const m=e.computed(()=>new Map(i.value));e.watch(m,(y,p)=>{d?.fields&&(p.forEach((h,w)=>{y.has(w)||d?.fields.value.delete(w)}),y.forEach((h,w)=>{d?.fields.value.has(w)||d?.fields.value.set(w,h)}))},{deep:!0}),e.watch(c,y=>{d?.errors&&i.value.forEach(p=>{if(y.has(p)||d.errors.value.delete(p),y.has(p)){const h=y.get(p);h&&d.errors.value.set(p,h)}})},{deep:!0}),e.onMounted(()=>{if(!n?.wrappers||!a.value){console.warn("[@volverjs/form-vue]: Invalid wrapper registration state");return}if(n.wrappers.has(a.value)){console.warn(`[@volverjs/form-vue]: wrapper name "${a.value}" is already used`);return}n.wrappers.set(a.value,f)}),e.onBeforeUnmount(()=>{n?.wrappers&&a.value&&n.wrappers.delete(a.value)});const D=()=>n?.validate(void 0,{fields:new Set(i.value.values())})??Promise.resolve(!0);return{errors:n?.errors,fields:i,fieldsErrors:c,formData:n?.formData,invalid:v,readonly:l,clear:n?.clear,reset:n?.reset,submit:n?.submit,validate:n?.validate,validateWrapper:D}},render(){const s=()=>this.$slots.default?.({errors:this.errors,fieldsErrors:this.fieldsErrors,formData:this.formData,invalid:this.invalid,readonly:this.readonly,clear:this.clear,reset:this.reset,submit:this.submit,validate:this.validate,validateWrapper:this.validateWrapper});return this.tag?e.h(this.tag,null,{default:s}):s()}})}function ye(t,r){const s=e.defineComponent({name:"VvFormTemplate",props:{schema:{type:[Array,Function],required:!0},scope:{type:Object,default:()=>({})}},slots:Object,setup(g,{slots:n}){const d=e.inject(t);if(d?.formData)return()=>{const i=typeof g.schema=="function"?g.schema(d,g.scope):g.schema;let c;const a=i.reduce((v,l)=>{const f=typeof l=="function"?l(d,g.scope):l,{vvIs:m,vvName:D,vvSlots:y,vvChildren:p,vvIf:h,vvElseIf:w,vvType:I,vvDefaultValue:_,vvShowValid:E,vvContent:O,...R}=f;if(h!==void 0){if(typeof h=="string"?c=!!Z.get(new Object(d.formData.value),h):typeof h=="function"?c=e.unref(h(d)):c=e.unref(h),!c)return v}else if(w!==void 0&&c!==void 0){if(c||(typeof w=="string"?c=!!Z.get(new Object(d.formData.value),w):typeof w=="function"?c=e.unref(w(d)):c=e.unref(w),!c))return v}else c=void 0;let o;return p&&(typeof m=="string"?o=e.h(s,{schema:p}):o={default:V=>e.h(s,{schema:p,scope:V})}),D?(v.push(e.h(r,{name:D,is:m,type:I,defaultValue:_,showValid:E,props:R},y??o??O)),v):m?(v.push(e.h(m,R,y??o??O)),v):(o&&("default"in o?v.push(o.default(g.scope)):v.push(o)),v)},[]);return a.push(n?.default?.({errors:d?.errors.value,formData:d?.formData.value,invalid:d?.invalid.value,status:d?.status.value,submit:d?.submit,validate:d?.validate,clear:d?.clear,reset:d?.reset})),a}}});return s}function T(t,r={}){const s=Symbol("formInjectionKey"),g=Symbol("formWrapperInjectionKey"),n=Symbol("formFieldInjectionKey"),d=Symbol("formFieldsGroupInjectionKey"),i=pe(s,g),c=ve(s,g,n,r),a=me(s,g,d),v=ye(s,c),l=new Map,{clear:f,errors:m,formData:D,ignoreUpdates:y,invalid:p,readonly:h,reset:w,status:I,stopUpdatesWatch:_,submit:E,validate:O,VvForm:R}=ce(t,s,r,v,l);return{clear:f,errors:m,formData:D,formFieldInjectionKey:n,formInjectionKey:s,formWrapperInjectionKey:g,ignoreUpdates:y,invalid:p,readonly:h,reset:w,status:I,stopUpdatesWatch:_,submit:E,validate:O,wrappers:l,VvForm:R,VvFormField:c,VvFormFieldsGroup:a,VvFormTemplate:v,VvFormWrapper:i}}const $=Symbol("pluginInjectionKey");function he(t){let r={};return t.schema&&(r=T(t.schema,t)),{...r,install(s,{global:g=!1}={}){s.provide($,t),g&&(s.config.globalProperties.$vvForm=t,r?.VvForm&&s.component("VvForm",r.VvForm),r?.VvFormWrapper&&s.component("VvFormWrapper",r.VvFormWrapper),r?.VvFormField&&s.component("VvFormField",r.VvFormField),r?.VvFormFieldsGroup&&s.component("VvFormFieldsGroup",r.VvFormFieldsGroup),r?.VvFormTemplate&&s.component("VvFormTemplate",r.VvFormTemplate))}}}const W=new Map;function be(t,r={}){if(r.scope&&W.has(r.scope))return W.get(r.scope);if(!e.getCurrentInstance()){const g=T(t,r);return r.scope&&W.set(r.scope,g),g}const s=T(t,{...e.inject($,{}),...r});return r.scope&&W.set(r.scope,s),s}function je(t,r={}){return T(t,r)}S.FormFieldType=j,S.createForm=he,S.defaultObjectBySchema=x,S.formType=je,S.pluginInjectionKey=$,S.useForm=be,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
package/dist/utils.d.ts CHANGED
@@ -2,12 +2,24 @@ import { FormSchema, InferSchema, VvZodError, ZodIssue } from './types';
2
2
  import type * as z3 from 'zod/v3';
3
3
  import type * as z4 from 'zod/v4/core';
4
4
  export declare const isZod3Object: (value: z3.ZodTypeAny) => value is z3.ZodObject<any>;
5
+ export declare const isZod4Object: (value: z4.$ZodType) => value is z4.$ZodObject<any>;
5
6
  export declare const isZod3Default: (value: z3.ZodTypeAny) => value is z3.ZodDefault<any>;
7
+ export declare const isZod4Default: (value: z4.$ZodType) => value is z4.$ZodDefault<any>;
6
8
  export declare const isZod3Nullable: (value: z3.ZodTypeAny) => value is z3.ZodNullable<any>;
9
+ export declare const isZod4Nullable: (value: z4.$ZodType) => value is z4.$ZodNullable<any>;
7
10
  export declare const isZod3Record: (value: z3.ZodTypeAny) => value is z3.ZodRecord<any, any>;
11
+ export declare const isZod4Record: (value: z4.$ZodType) => value is z4.$ZodRecord<any, any>;
8
12
  export declare const isZod3Array: (value: z3.ZodTypeAny) => value is z3.ZodArray<any>;
13
+ export declare const isZod4Array: (value: z4.$ZodType) => value is z4.$ZodArray<any>;
9
14
  export declare const isZod3Effects: (value: z3.ZodTypeAny) => value is z3.ZodEffects<any>;
10
15
  export declare const isZod3Optional: (value: z3.ZodTypeAny) => value is z3.ZodOptional<any>;
16
+ export declare const isZod4Optional: (value: z4.$ZodType) => value is z4.$ZodOptional<any>;
17
+ export declare const isZod4Pipe: (value: z4.$ZodType) => value is z4.$ZodPipe<any>;
18
+ export declare const isZod4Transform: (value: z4.$ZodType) => value is z4.$ZodTransform<any>;
19
+ export declare const getZod3SchemaInnerType: <Type extends z3.ZodTypeAny>(schema: Type | z3.ZodEffects<Type> | z3.ZodEffects<z3.ZodEffects<Type>> | z3.ZodOptional<Type>) => Type;
20
+ export declare const getZod4SchemaInnerType: <Type extends z4.$ZodType>(schema: Type | z4.$ZodPipe<Type> | z4.$ZodPipe<any, Type> | z4.$ZodOptional<Type>) => Type;
21
+ export declare const isZod3SchemaOptional: <Type extends z3.ZodTypeAny>(schema: Type | z3.ZodEffects<Type> | z3.ZodEffects<z3.ZodEffects<Type>> | z3.ZodOptional<Type>) => boolean;
22
+ export declare const isZod4SchemaOptional: <Type extends z4.$ZodType>(schema: Type | z4.$ZodPipe<Type> | z4.$ZodPipe<any, Type> | z4.$ZodOptional<Type>) => boolean;
11
23
  export declare function defaultObjectByJSONSchema(schema: z4.JSONSchema.JSONSchema, original?: unknown): unknown;
12
24
  export declare const isZod4Schema: (schema: z3.ZodTypeAny | z4.$ZodType) => schema is z4.$ZodType;
13
25
  export declare function defaultObjectBySchema<Schema extends FormSchema>(schema: Schema, original?: Partial<InferSchema<Schema>> & Record<string, unknown>): Partial<InferSchema<Schema>>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@volverjs/form-vue",
3
3
  "type": "module",
4
- "version": "1.1.0-beta.3",
4
+ "version": "1.1.0-beta.5",
5
5
  "description": "Vue 3 Forms with @volverjs/ui-vue",
6
6
  "author": "8 Wave S.r.l.",
7
7
  "license": "MIT",
@@ -52,24 +52,24 @@
52
52
  "peerDependencies": {
53
53
  "@volverjs/ui-vue": "^0.0.9",
54
54
  "@vueuse/core": "^13.0.0",
55
- "ts-dot-prop": "^2.1.4",
56
- "vue": "^3.5.13",
55
+ "ts-dot-prop": "^2.1.0",
56
+ "vue": "^3.5.0",
57
57
  "zod": "^3.25.0 || ^4.0.0"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@antfu/eslint-config": "^5.0.0",
61
- "@nabla/vite-plugin-eslint": "^2.0.5",
61
+ "@nabla/vite-plugin-eslint": "^2.0.6",
62
62
  "@playwright/experimental-ct-vue": "^1.54.1",
63
63
  "@testing-library/vue": "^8.1.0",
64
- "@vitejs/plugin-vue": "^6.0.0",
65
- "@volverjs/style": "^0.1.20",
64
+ "@vitejs/plugin-vue": "^6.0.1",
65
+ "@volverjs/style": "^0.1.21",
66
66
  "@volverjs/ui-vue": "^0.0.9",
67
67
  "@vue/compiler-sfc": "^3.5.18",
68
68
  "@vue/runtime-core": "^3.5.18",
69
69
  "@vue/test-utils": "^2.4.6",
70
- "@vueuse/core": "^13.5.0",
70
+ "@vueuse/core": "^13.6.0",
71
71
  "copy": "^0.3.2",
72
- "eslint": "^9.31.0",
72
+ "eslint": "^9.32.0",
73
73
  "happy-dom": "^18.0.1",
74
74
  "ts-dot-prop": "^2.1.4",
75
75
  "typescript": "^5.8.3",
@@ -78,7 +78,7 @@
78
78
  "vite-plugin-externalize-deps": "^0.9.0",
79
79
  "vitest": "^3.2.4",
80
80
  "vue": "^3.5.18",
81
- "zod": "^4.0.10"
81
+ "zod": "^4.0.14"
82
82
  },
83
83
  "scripts": {
84
84
  "lint": "eslint .",
package/src/utils.ts CHANGED
@@ -7,31 +7,74 @@ import {
7
7
  safeParseAsync as z4SafeParseAsync,
8
8
  formatError as z4FormatError,
9
9
  } from 'zod/v4/core'
10
- import { toJSONSchema as z4toJSONSchema } from 'zod/v4'
11
10
  import type * as z3 from 'zod/v3'
12
11
  import type * as z4 from 'zod/v4/core'
13
12
  import type { FormSchema, InferSchema, VvZodError, ZodIssue } from './types'
14
13
 
14
+ // Helper function to determine the type of a value
15
+ function _getValueType(value: unknown) {
16
+ if (Array.isArray(value)) {
17
+ return 'array'
18
+ }
19
+ if (value === null) {
20
+ return 'null'
21
+ }
22
+ return typeof value
23
+ }
24
+
25
+ // Helper function to check if a value matches a schema type
26
+ function _isValueCompatibleWithSchema(value: unknown, subSchema: z4.JSONSchema.JSONSchema): boolean {
27
+ const valueType = _getValueType(value)
28
+
29
+ if (subSchema.type) {
30
+ return subSchema.type === valueType
31
+ || (subSchema.type === 'integer' && valueType === 'number' && Number.isInteger(value as number))
32
+ }
33
+
34
+ // If no type specified, assume compatibility
35
+ return true
36
+ }
37
+
15
38
  export const isZod3Object = (value: z3.ZodTypeAny): value is z3.ZodObject<any> => {
16
39
  return value._def.typeName === 'ZodObject'
17
40
  }
18
41
 
42
+ export const isZod4Object = (value: z4.$ZodType): value is z4.$ZodObject<any> => {
43
+ return value._zod.def.type === 'object'
44
+ }
45
+
19
46
  export const isZod3Default = (value: z3.ZodTypeAny): value is z3.ZodDefault<any> => {
20
47
  return value._def.typeName === 'ZodDefault'
21
48
  }
22
49
 
50
+ export const isZod4Default = (value: z4.$ZodType): value is z4.$ZodDefault<any> => {
51
+ return value._zod.def.type === 'default'
52
+ }
53
+
23
54
  export const isZod3Nullable = (value: z3.ZodTypeAny): value is z3.ZodNullable<any> => {
24
55
  return value._def.typeName === 'ZodNullable'
25
56
  }
26
57
 
58
+ export const isZod4Nullable = (value: z4.$ZodType): value is z4.$ZodNullable<any> => {
59
+ return value._zod.def.type === 'nullable'
60
+ }
61
+
27
62
  export const isZod3Record = (value: z3.ZodTypeAny): value is z3.ZodRecord<any, any> => {
28
63
  return value._def.typeName === 'ZodRecord'
29
64
  }
30
65
 
66
+ export const isZod4Record = (value: z4.$ZodType): value is z4.$ZodRecord<any, any> => {
67
+ return value._zod.def.type === 'record'
68
+ }
69
+
31
70
  export const isZod3Array = (value: z3.ZodTypeAny): value is z3.ZodArray<any> => {
32
71
  return value._def.typeName === 'ZodArray'
33
72
  }
34
73
 
74
+ export const isZod4Array = (value: z4.$ZodType): value is z4.$ZodArray<any> => {
75
+ return value._zod.def.type === 'array'
76
+ }
77
+
35
78
  export const isZod3Effects = (value: z3.ZodTypeAny): value is z3.ZodEffects<any> => {
36
79
  return value._def.typeName === 'ZodEffects'
37
80
  }
@@ -40,8 +83,21 @@ export const isZod3Optional = (value: z3.ZodTypeAny): value is z3.ZodOptional<an
40
83
  return value._def.typeName === 'ZodOptional'
41
84
  }
42
85
 
43
- // Helper function to get the inner type of a Zod v3 schema
44
- const getZod3SchemaInnerType = <Type extends z3.ZodTypeAny>(
86
+ export const isZod4Optional = (value: z4.$ZodType): value is z4.$ZodOptional<any> => {
87
+ return value._zod.def.type === 'optional'
88
+ }
89
+
90
+ // replace of effercts
91
+ export const isZod4Pipe = (value: z4.$ZodType): value is z4.$ZodPipe<any> => {
92
+ return value._zod.def.type === 'pipe'
93
+ }
94
+
95
+ export const isZod4Transform = (value: z4.$ZodType): value is z4.$ZodTransform<any> => {
96
+ return value._zod.def.type === 'transform'
97
+ }
98
+
99
+ // Helper function to get the inner type of a Zod schema
100
+ export const getZod3SchemaInnerType = <Type extends z3.ZodTypeAny>(
45
101
  schema:
46
102
  | Type
47
103
  | z3.ZodEffects<Type>
@@ -58,8 +114,30 @@ const getZod3SchemaInnerType = <Type extends z3.ZodTypeAny>(
58
114
  return toReturn
59
115
  }
60
116
 
61
- // Helper function to check if a Zod v3 schema is optional
62
- const isZod3SchemaOptional = <Type extends z3.ZodTypeAny>(
117
+ export const getZod4SchemaInnerType = <Type extends z4.$ZodType>(
118
+ schema:
119
+ | Type
120
+ | z4.$ZodPipe<Type>
121
+ | z4.$ZodPipe<any, Type>
122
+ | z4.$ZodOptional<Type>,
123
+ ) => {
124
+ let toReturn = schema
125
+ while (isZod4Pipe(toReturn)) {
126
+ if (isZod4Transform(toReturn._zod.def.out)) {
127
+ toReturn = toReturn._zod.def.in
128
+ }
129
+ else {
130
+ toReturn = toReturn._zod.def.out as Type
131
+ }
132
+ }
133
+ if (isZod4Optional(toReturn)) {
134
+ toReturn = toReturn._zod.def.innerType
135
+ }
136
+ return toReturn
137
+ }
138
+
139
+ // Helper function to check if a Zod schema is optional
140
+ export const isZod3SchemaOptional = <Type extends z3.ZodTypeAny>(
63
141
  schema:
64
142
  | Type
65
143
  | z3.ZodEffects<Type>
@@ -76,28 +154,26 @@ const isZod3SchemaOptional = <Type extends z3.ZodTypeAny>(
76
154
  return false
77
155
  }
78
156
 
79
- // Helper function to determine the type of a value
80
- function getValueType(value: unknown) {
81
- if (Array.isArray(value)) {
82
- return 'array'
83
- }
84
- if (value === null) {
85
- return 'null'
157
+ export const isZod4SchemaOptional = <Type extends z4.$ZodType>(
158
+ schema:
159
+ | Type
160
+ | z4.$ZodPipe<Type>
161
+ | z4.$ZodPipe<any, Type>
162
+ | z4.$ZodOptional<Type>,
163
+ ) => {
164
+ let toReturn = schema
165
+ while (isZod4Pipe(toReturn)) {
166
+ if (isZod4Transform(toReturn._zod.def.out)) {
167
+ toReturn = toReturn._zod.def.in
168
+ }
169
+ else {
170
+ toReturn = toReturn._zod.def.out as Type
171
+ }
86
172
  }
87
- return typeof value
88
- }
89
-
90
- // Helper function to check if a value matches a schema type
91
- function isValueCompatibleWithSchema(value: unknown, subSchema: z4.JSONSchema.JSONSchema): boolean {
92
- const valueType = getValueType(value)
93
-
94
- if (subSchema.type) {
95
- return subSchema.type === valueType
96
- || (subSchema.type === 'integer' && valueType === 'number' && Number.isInteger(value as number))
173
+ if (isZod4Optional(toReturn)) {
174
+ return true
97
175
  }
98
-
99
- // If no type specified, assume compatibility
100
- return true
176
+ return false
101
177
  }
102
178
 
103
179
  export function defaultObjectByJSONSchema(schema: z4.JSONSchema.JSONSchema, original?: unknown): unknown {
@@ -106,7 +182,7 @@ export function defaultObjectByJSONSchema(schema: z4.JSONSchema.JSONSchema, orig
106
182
  if (original !== undefined) {
107
183
  // First pass: find exact type match
108
184
  for (const subSchema of schema.anyOf) {
109
- if (isValueCompatibleWithSchema(original, subSchema as z4.JSONSchema.JSONSchema)) {
185
+ if (_isValueCompatibleWithSchema(original, subSchema as z4.JSONSchema.JSONSchema)) {
110
186
  return defaultObjectByJSONSchema(subSchema as z4.JSONSchema.JSONSchema, original)
111
187
  }
112
188
  }
@@ -183,12 +259,88 @@ export const isZod4Schema = (schema: z3.ZodTypeAny | z4.$ZodType): schema is z4.
183
259
  export function defaultObjectBySchema<Schema extends FormSchema>(schema: Schema, original: Partial<InferSchema<Schema>> & Record<string, unknown> = {}): Partial<InferSchema<Schema>> {
184
260
  // zod v4
185
261
  if (isZod4Schema(schema)) {
186
- const jsonSchema = z4toJSONSchema(schema)
187
- if (jsonSchema.type !== 'object' || !jsonSchema.properties) {
262
+ const innerType = getZod4SchemaInnerType(schema)
263
+ if (!isZod4Object(innerType)) {
188
264
  return original
189
265
  }
190
- const parse = z4SafeParse(schema, original)
191
- return defaultObjectByJSONSchema(jsonSchema, parse.success ? parse.data : original) as Partial<InferSchema<Schema>>
266
+ const unknownKeys = !(!innerType._zod.def.catchall || innerType._zod.def.catchall?._zod.def.type === 'never')
267
+
268
+ return {
269
+ ...(unknownKeys ? original : {}),
270
+ ...Object.fromEntries(
271
+ ('shape' in innerType._zod.def ? Object.entries(innerType._zod.def.shape) as [string, z4.$ZodType][] : []).map(
272
+ ([key, subSchema]) => {
273
+ const originalValue = original[key]
274
+ const isOptional = isZod4SchemaOptional(subSchema)
275
+ let innerType = getZod4SchemaInnerType(subSchema)
276
+ let defaultValue: Partial<InferSchema<Schema>> | undefined
277
+ if (isZod4Default(innerType)) {
278
+ defaultValue = innerType._zod.def.defaultValue
279
+ innerType = innerType._zod.def.innerType
280
+ }
281
+ if (
282
+ originalValue === null
283
+ && isZod4Nullable(innerType)
284
+ ) {
285
+ return [key, originalValue]
286
+ }
287
+ if ((originalValue === undefined || originalValue === null) && isOptional) {
288
+ return [key, defaultValue]
289
+ }
290
+ if (innerType) {
291
+ const parse = z4SafeParse(subSchema, originalValue)
292
+ if (parse.success) {
293
+ return [key, parse.data ?? defaultValue]
294
+ }
295
+ }
296
+ if (
297
+ isZod4Array(innerType)
298
+ && Array.isArray(originalValue)
299
+ && originalValue.length
300
+ ) {
301
+ const arrayType = getZod4SchemaInnerType(innerType._zod.def.element)
302
+ if (isZod4Object(arrayType)) {
303
+ return [
304
+ key,
305
+ originalValue.map((element: unknown) =>
306
+ defaultObjectBySchema(
307
+ arrayType,
308
+ (element && typeof element === 'object'
309
+ ? element
310
+ : undefined) as Partial<
311
+ typeof arrayType
312
+ >,
313
+ ),
314
+ ),
315
+ ]
316
+ }
317
+ }
318
+ if (isZod4Record(innerType) && originalValue) {
319
+ const valueType = getZod4SchemaInnerType(innerType._zod.def.valueType)
320
+ if (isZod4Object(valueType)) {
321
+ return [key, Object.keys(originalValue).reduce((acc: Record<string, unknown>, recordKey: string) => {
322
+ acc[recordKey] = defaultObjectBySchema(valueType, originalValue[recordKey])
323
+ return acc
324
+ }, {})]
325
+ }
326
+ }
327
+ if (isZod4Object(innerType)) {
328
+ return [
329
+ key,
330
+ defaultObjectBySchema(
331
+ innerType,
332
+ originalValue
333
+ && typeof originalValue === 'object'
334
+ ? originalValue
335
+ : defaultValue,
336
+ ),
337
+ ]
338
+ }
339
+ return [key, defaultValue]
340
+ },
341
+ ),
342
+ ),
343
+ } as Partial<InferSchema<Schema>>
192
344
  }
193
345
 
194
346
  // zod v3