@volverjs/form-vue 0.0.13 → 0.0.14-beta.2

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 +1 @@
1
- (function(p,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],r):(p=typeof globalThis<"u"?globalThis:p||self,r(p["@volverjs/form-vue"]={},p.Vue,p.VueUseCore,p.zod))})(this,function(p,r,M,x){"use strict";function $(e){return Array.isArray(e)}function U(e){return typeof e<"u"}function L(e){return e===null}function W(e){return typeof e=="object"}function _(e){return typeof e=="string"}function k(e){return typeof e>"u"}const z=/^[0-9]+$/,J=["__proto__","prototype","constructor"];function C(e,s,f){const l=U(f)?f:void 0;if(!W(e)||!_(s))return l;const a=K(s);if(a.length!==0){for(const t of a){if(t==="*")continue;const i=function(o){return o.map(u=>k(u)||L(u)?u:$(u)?i(u):u[t])};if($(e)&&!z.test(t)?e=i(e):e=e[t],k(e)||L(e))break}return k(e)?l:e}}function A(e,s,f){if(!W(e)||!_(s))return;const l=K(s);if(l.length===0)return;const a=l.length;for(let t=0;t<a;t++){const i=l[t];if(t===a-1){e[i]=f;return}if(i==="*"&&$(e)){const o=l.slice(t+1).join(".");for(const u of e)A(u,o,f);return}k(e[i])&&(e[i]={}),e=e[i]}}function K(e){const s=e.split(/[.]|(?:\[(\d|\*)\])/).filter(f=>!!f);return s.some(f=>J.indexOf(f)!==-1)?[]:s}var d=(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))(d||{}),S=(e=>(e.invalid="invalid",e.valid="valid",e))(S||{});const P=(e,s,f,l)=>r.defineComponent({name:"FieldComponent",props:{type:{type:String,validator:a=>Object.values(d).includes(a),default:d.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}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(a,{slots:t,emit:i}){const o=r.computed({get(){if(n!=null&&n.formData)return C(Object(n.formData.value),String(a.name))},set(c){n!=null&&n.formData&&(A(Object(n.formData.value),String(a.name),c),i("update:modelValue",{newValue:o.value,formData:n==null?void 0:n.formData}))}});r.onMounted(()=>{o.value===void 0&&a.defaultValue!==void 0&&(o.value=a.defaultValue)}),r.onBeforeUnmount(()=>{O(),g()});const u=r.inject(s,void 0);u&&u.fields.value.add(a.name);const n=r.inject(e),{props:h,name:y}=r.toRefs(a),m=r.computed(()=>{if(n!=null&&n.errors.value)return C(n.errors.value,String(a.name))}),v=r.computed(()=>{var c;return(c=m.value)==null?void 0:c._errors}),b=r.computed(()=>m.value!==void 0),O=r.watch(b,()=>{b.value?(i("invalid",v.value),u&&u.errors.value.set(a.name,{_errors:v.value})):(i("valid",o.value),u&&u.errors.value.delete(a.name))}),g=r.watch(()=>n==null?void 0:n.formData,()=>{i("update:formData",n==null?void 0:n.formData)},{deep:!0}),V=c=>{o.value=c},I=r.computed(()=>{let c=h.value;return typeof c=="function"&&(c=c(n==null?void 0:n.formData)),Object.keys(c).reduce((w,q)=>(w[q]=r.unref(c[q]),w),{})}),G=r.computed(()=>({...I.value,name:I.value.name??a.name,invalid:b.value,valid:a.showValid?!!(!b.value&&o.value):void 0,type:(c=>{if([d.text,d.number,d.email,d.password,d.tel,d.url,d.search,d.date,d.time,d.datetimeLocal,d.month,d.week,d.color].includes(c))return c})(a.type),invalidLabel:v.value,modelValue:o.value,"onUpdate:modelValue":V}));return r.provide(f,{name:r.readonly(y),errors:r.readonly(m)}),{component:r.computed(()=>{if(a.type===d.custom)return{render(){var c;return((c=t.default)==null?void 0:c.call(t,{modelValue:o.value,onUpdate:V,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,invalid:b.value,invalidLabel:v.value,formData:n==null?void 0:n.formData.value,formErrors:n==null?void 0:n.errors.value,errors:m.value}))??t.defalut}};if(!((l==null?void 0:l.lazyLoad)??a.lazyLoad)){let c;switch(a.type){case d.select:c=r.resolveComponent("VvSelect");break;case d.checkbox:c=r.resolveComponent("VvCheckbox");break;case d.radio:c=r.resolveComponent("VvRadio");break;case d.textarea:c=r.resolveComponent("VvTextarea");break;case d.radioGroup:c=r.resolveComponent("VvRadioGroup");break;case d.checkboxGroup:c=r.resolveComponent("VvCheckboxGroup");break;case d.combobox:c=r.resolveComponent("VvCombobox");break;default:c=r.resolveComponent("VvInputText")}if(typeof c!="string")return c;console.warn(`[form-vue warn]: ${c} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return r.defineAsyncComponent(async()=>{switch(l!=null&&l.sideEffects&&await Promise.resolve(l.sideEffects(a.type)),a.type){case d.textarea:return import("@volverjs/ui-vue/vv-textarea");case d.radio:return import("@volverjs/ui-vue/vv-radio");case d.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case d.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case d.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case d.select:return import("@volverjs/ui-vue/vv-select");case d.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:G,invalid:b}},render(){return this.is?r.h(this.is,this.hasProps,this.$slots):this.type===d.custom?r.h(this.component,null,this.$slots):r.h(this.component,this.hasProps,this.$slots)}}),B=(e,s={})=>{const f=t=>{let i=t;for(;i instanceof x.ZodEffects;)i=i.innerType();for(;i instanceof x.ZodOptional;)i=i._def.innerType;return i},l=f(e);return{...(l instanceof x.ZodObject?l._def.unknownKeys==="passthrough":!1)?s:{},...Object.fromEntries(Object.entries(l.shape).map(([t,i])=>{const o=s[t],u=f(i);let n;if(u instanceof x.ZodDefault&&(n=u._def.defaultValue()),o===null&&u instanceof x.ZodNullable)return[t,o];if(u instanceof x.ZodSchema){const h=i.safeParse(o);if(h.success)return[t,h.data??n]}return u instanceof x.ZodObject?[t,B(u,o&&typeof o=="object"?o:{})]:[t,n]}))}},T=(e,s,f)=>{const l=r.ref(),a=r.ref(),t=r.ref(),i=r.defineComponent({name:"FormComponent",props:{modelValue:{type:Object,default:()=>({})},updateThrottle:{type:Number,default:500},continuosValidation:{type:Boolean,default:!1}},emits:["invalid","valid","submit","update:modelValue"],expose:["submit","validate","errors","status","valid","invalid"],setup(o,{emit:u}){t.value=B(e,r.toRaw(o.modelValue)),r.watch(()=>o.modelValue,m=>{if(m){const v=r.isProxy(m)?r.toRaw(m):m;t.value=typeof(v==null?void 0:v.clone)=="function"?v.clone():JSON.parse(JSON.stringify(v))}},{deep:!0}),M.watchThrottled(t,m=>{((l.value||(f==null?void 0:f.continuosValidation))??o.continuosValidation)&&n(),(!m||!o.modelValue||JSON.stringify(m)!==JSON.stringify(o.modelValue))&&u("update:modelValue",m)},{deep:!0,throttle:(f==null?void 0:f.updateThrottle)??o.updateThrottle});const n=(m=t.value)=>{const v=e.safeParse(m);return v.success?(l.value=void 0,a.value=S.valid,t.value=v.data,u("update:modelValue",t.value),u("valid",v.data),!0):(l.value=v.error.format(),a.value=S.invalid,u("invalid",l.value),!1)},h=()=>n()?(u("submit",t.value),!0):!1,y=r.computed(()=>a.value===S.invalid);return r.provide(s,{formData:t,submit:h,validate:n,errors:r.readonly(l),status:r.readonly(a),invalid:y}),{formData:t,submit:h,validate:n,errors:r.readonly(l),status:r.readonly(a),invalid:y}},render(){return r.h("form",{onSubmit:r.withModifiers(this.submit,["prevent"])},{default:()=>{var o,u;return((u=(o=this.$slots)==null?void 0:o.default)==null?void 0:u.call(o,{formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,status:this.status,invalid:this.invalid}))??this.$slots.default}})}});return{errors:l,status:a,formData:t,VvForm:i}},R=(e,s)=>r.defineComponent({name:"WrapperComponent",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(l,{emit:a}){const t=r.inject(e),i=r.inject(s,void 0),o=r.ref(new Set),u=r.ref(new Map),{name:n}=r.toRefs(l);r.provide(s,{name:r.readonly(n),errors:u,fields:o}),r.watch(o,y=>{i!=null&&i.fields&&y.forEach(m=>{i==null||i.fields.value.add(m)})},{deep:!0}),r.watch(()=>new Map(u.value),(y,m)=>{i!=null&&i.errors&&(Array.from(m.keys()).forEach(v=>{i.errors.value.delete(v)}),Array.from(y.keys()).forEach(v=>{const b=y.get(v);b&&i.errors.value.set(v,b)}))},{deep:!0});const h=r.computed(()=>t!=null&&t.invalid.value?u.value.size>0:!1);return r.watch(h,()=>{h.value?a("invalid"):a("valid")}),{formData:t==null?void 0:t.formData,errors:t==null?void 0:t.errors,submit:t==null?void 0:t.submit,validate:t==null?void 0:t.validate,invalid:h,fields:o,fieldsErrors:u}},render(){var l,a;return this.tag?r.h(this.tag,null,{default:()=>{var t,i;return((i=(t=this.$slots).default)==null?void 0:i.call(t,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((a=(l=this.$slots).default)==null?void 0:a.call(l,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),H=(e,s)=>{const f=r.defineComponent({props:{schema:{type:[Array,Function],required:!0}},setup(l,{slots:a}){const t=r.inject(e);if(!(t!=null&&t.formData))return;const i=typeof l.schema=="function"?l.schema(t):l.schema;let o;return()=>{var u;return i.reduce((n,h)=>{const y=typeof h=="function"?h(t):h,{vvIs:m,vvName:v,vvSlots:b,vvChildren:O,vvIf:g,vvElseIf:V,vvType:I,vvDefaultValue:G,vvShowValid:Z,...c}=y;if(g!==void 0){if(typeof g=="string"?o=!!C(Object(t.formData.value),g):typeof g=="function"?o=r.unref(g(t)):o=r.unref(g),!o)return n}else if(V!==void 0&&o!==void 0){if(o||(typeof V=="string"?o=!!C(Object(t.formData.value),V):typeof V=="function"?o=r.unref(V(t)):o=r.unref(V),!o))return n}else o=void 0;const w=O?r.h(f,{schema:O}):void 0;return v?(n.push(r.h(s,{name:v,is:m,type:I,defaultValue:G,showValid:Z,props:c},b??w)),n):m?(n.push(r.h(m,c,b??w)),n):(O&&n.push(w),n)},[(u=a==null?void 0:a.default)==null?void 0:u.call(a,{formData:t==null?void 0:t.formData.value,submit:t==null?void 0:t.submit,validate:t==null?void 0:t.validate,errors:t==null?void 0:t.errors.value,status:t==null?void 0:t.status.value,invalid:t==null?void 0:t.invalid.value})])}}});return f},E=(e,s={})=>{const f=Symbol(),l=Symbol(),a=Symbol(),{VvForm:t,errors:i,status:o,formData:u}=T(e,f,s),n=R(f,l),h=P(f,l,a,s),y=H(f,h);return{VvForm:t,VvFormWrapper:n,VvFormField:h,VvFormTemplate:y,formInjectionKey:f,formWrapperInjectionKey:l,formFieldInjectionKey:a,errors:i,status:o,formData:u}},N=Symbol(),Q=e=>{let s={};return e.schema&&(s=E(e.schema,e)),{...s,install(f,{global:l=!1}={}){f.provide(N,e),l&&(f.config.globalProperties.$vvForm=e,s!=null&&s.VvForm&&f.component("VvForm",s.VvForm),s!=null&&s.VvFormWrapper&&f.component("VvFormWrapper",s.VvFormWrapper),s!=null&&s.VvFormField&&f.component("VvFormField",s.VvFormField),s!=null&&s.VvFormTemplate&&f.component("VvFormTemplate",s.VvFormTemplate))}}},X=(e,s={})=>r.getCurrentInstance()?E(e,{...r.inject(N,{}),...s}):E(e,s),Y=(e,s={})=>E(e,s);p.FormFieldType=d,p.createForm=Q,p.defaultObjectBySchema=B,p.formFactory=Y,p.pluginInjectionKey=N,p.useForm=X,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
1
+ (function(y,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],r):(y=typeof globalThis<"u"?globalThis:y||self,r(y["@volverjs/form-vue"]={},y.Vue,y.VueUseCore,y.zod))})(this,function(y,r,M,V){"use strict";function _(e){return Array.isArray(e)}function T(e){return typeof e<"u"}function N(e){return e===null}function G(e){return typeof e=="object"}function L(e){return typeof e=="string"}function C(e){return typeof e>"u"}const U=/^[0-9]+$/,J=["__proto__","prototype","constructor"];function k(e,s,f){const u=T(f)?f:void 0;if(!G(e)||!L(s))return u;const o=Z(s);if(o.length!==0){for(const t of o){if(t==="*")continue;const i=function(a){return a.map(l=>C(l)||N(l)?l:_(l)?i(l):l[t])};if(_(e)&&!U.test(t)?e=i(e):e=e[t],C(e)||N(e))break}return C(e)?u:e}}function W(e,s,f){if(!G(e)||!L(s))return;const u=Z(s);if(u.length===0)return;const o=u.length;for(let t=0;t<o;t++){const i=u[t];if(t===o-1){e[i]=f;return}if(i==="*"&&_(e)){const a=u.slice(t+1).join(".");for(const l of e)W(l,a,f);return}C(e[i])&&(e[i]={}),e=e[i]}}function Z(e){const s=e.split(/[.]|(?:\[(\d|\*)\])/).filter(f=>!!f);return s.some(f=>J.indexOf(f)!==-1)?[]:s}var d=(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))(d||{}),S=(e=>(e.invalid="invalid",e.valid="valid",e))(S||{});const P=(e,s,f,u)=>r.defineComponent({name:"FieldComponent",props:{type:{type:String,validator:o=>Object.values(d).includes(o),default:d.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}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(o,{slots:t,emit:i}){const a=r.computed({get(){if(n!=null&&n.formData)return k(Object(n.formData.value),String(o.name))},set(c){n!=null&&n.formData&&(W(Object(n.formData.value),String(o.name),c),i("update:modelValue",{newValue:a.value,formData:n==null?void 0:n.formData}))}});r.onMounted(()=>{a.value===void 0&&o.defaultValue!==void 0&&(a.value=o.defaultValue)}),r.onBeforeUnmount(()=>{O(),x()});const l=r.inject(s,void 0);l&&l.fields.value.add(o.name);const n=r.inject(e),{props:h,name:p}=r.toRefs(o),m=r.computed(()=>{if(n!=null&&n.errors.value)return k(n.errors.value,String(o.name))}),v=r.computed(()=>{var c;return(c=m.value)==null?void 0:c._errors}),b=r.computed(()=>m.value!==void 0),O=r.watch(b,()=>{b.value?(i("invalid",v.value),l&&l.errors.value.set(o.name,{_errors:v.value})):(i("valid",a.value),l&&l.errors.value.delete(o.name))}),x=r.watch(()=>n==null?void 0:n.formData,()=>{i("update:formData",n==null?void 0:n.formData)},{deep:!0}),g=c=>{a.value=c},A=r.computed(()=>{let c=h.value;return typeof c=="function"&&(c=c(n==null?void 0:n.formData)),Object.keys(c).reduce((w,q)=>(w[q]=r.unref(c[q]),w),{})}),B=r.computed(()=>({...A.value,name:A.value.name??o.name,invalid:b.value,valid:o.showValid?!!(!b.value&&a.value):void 0,type:(c=>{if([d.text,d.number,d.email,d.password,d.tel,d.url,d.search,d.date,d.time,d.datetimeLocal,d.month,d.week,d.color].includes(c))return c})(o.type),invalidLabel:v.value,modelValue:a.value,"onUpdate:modelValue":g}));return r.provide(f,{name:r.readonly(p),errors:r.readonly(m)}),{component:r.computed(()=>{if(o.type===d.custom)return{render(){var c;return((c=t.default)==null?void 0:c.call(t,{modelValue:a.value,onUpdate:g,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,invalid:b.value,invalidLabel:v.value,formData:n==null?void 0:n.formData.value,formErrors:n==null?void 0:n.errors.value,errors:m.value}))??t.defalut}};if(!((u==null?void 0:u.lazyLoad)??o.lazyLoad)){let c;switch(o.type){case d.select:c=r.resolveComponent("VvSelect");break;case d.checkbox:c=r.resolveComponent("VvCheckbox");break;case d.radio:c=r.resolveComponent("VvRadio");break;case d.textarea:c=r.resolveComponent("VvTextarea");break;case d.radioGroup:c=r.resolveComponent("VvRadioGroup");break;case d.checkboxGroup:c=r.resolveComponent("VvCheckboxGroup");break;case d.combobox:c=r.resolveComponent("VvCombobox");break;default:c=r.resolveComponent("VvInputText")}if(typeof c!="string")return c;console.warn(`[form-vue warn]: ${c} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return r.defineAsyncComponent(async()=>{switch(u!=null&&u.sideEffects&&await Promise.resolve(u.sideEffects(o.type)),o.type){case d.textarea:return import("@volverjs/ui-vue/vv-textarea");case d.radio:return import("@volverjs/ui-vue/vv-radio");case d.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case d.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case d.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case d.select:return import("@volverjs/ui-vue/vv-select");case d.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:B,invalid:b}},render(){return this.is?r.h(this.is,this.hasProps,this.$slots):this.type===d.custom?r.h(this.component,null,this.$slots):r.h(this.component,this.hasProps,this.$slots)}}),E=(e,s={})=>{const f=t=>{let i=t;for(;i instanceof V.ZodEffects;)i=i.innerType();return i instanceof V.ZodOptional&&(i=i._def.innerType),i},u=f(e);return{...(u instanceof V.ZodObject?u._def.unknownKeys==="passthrough":!1)?s:{},...Object.fromEntries(Object.entries(u.shape).map(([t,i])=>{const a=s[t];let l=f(i),n;if(l instanceof V.ZodDefault&&(n=l._def.defaultValue(),l=l._def.innerType),a===null&&l instanceof V.ZodNullable)return[t,a];if(l instanceof V.ZodSchema){const h=i.safeParse(a);if(h.success)return[t,h.data??n]}if(l instanceof V.ZodArray&&Array.isArray(a)&&a.length){const h=f(l._def.type);if(h instanceof V.ZodObject)return[t,a.map(p=>E(h,p&&typeof p=="object"?p:void 0))??n]}return l instanceof V.ZodObject?[t,E(l,a&&typeof a=="object"?a:n)]:[t,n]}))}},z=(e,s,f)=>{const u=r.ref(),o=r.ref(),t=r.ref(),i=r.defineComponent({name:"FormComponent",props:{modelValue:{type:Object,default:()=>({})},updateThrottle:{type:Number,default:500},continuosValidation:{type:Boolean,default:!1}},emits:["invalid","valid","submit","update:modelValue"],expose:["submit","validate","errors","status","valid","invalid"],setup(a,{emit:l}){t.value=E(e,r.toRaw(a.modelValue)),r.watch(()=>a.modelValue,m=>{if(m){const v=r.isProxy(m)?r.toRaw(m):m;t.value=typeof(v==null?void 0:v.clone)=="function"?v.clone():JSON.parse(JSON.stringify(v))}},{deep:!0}),M.watchThrottled(t,m=>{((u.value||(f==null?void 0:f.continuosValidation))??a.continuosValidation)&&n(),(!m||!a.modelValue||JSON.stringify(m)!==JSON.stringify(a.modelValue))&&l("update:modelValue",m)},{deep:!0,throttle:(f==null?void 0:f.updateThrottle)??a.updateThrottle});const n=(m=t.value)=>{const v=e.safeParse(m);return v.success?(u.value=void 0,o.value=S.valid,t.value=v.data,l("update:modelValue",t.value),l("valid",v.data),!0):(u.value=v.error.format(),o.value=S.invalid,l("invalid",u.value),!1)},h=()=>n()?(l("submit",t.value),!0):!1,p=r.computed(()=>o.value===S.invalid);return r.provide(s,{formData:t,submit:h,validate:n,errors:r.readonly(u),status:r.readonly(o),invalid:p}),{formData:t,submit:h,validate:n,errors:r.readonly(u),status:r.readonly(o),invalid:p}},render(){return r.h("form",{onSubmit:r.withModifiers(this.submit,["prevent"])},{default:()=>{var a,l;return((l=(a=this.$slots)==null?void 0:a.default)==null?void 0:l.call(a,{formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,status:this.status,invalid:this.invalid}))??this.$slots.default}})}});return{errors:u,status:o,formData:t,VvForm:i}},R=(e,s)=>r.defineComponent({name:"WrapperComponent",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(u,{emit:o}){const t=r.inject(e),i=r.inject(s,void 0),a=r.ref(new Set),l=r.ref(new Map),{name:n}=r.toRefs(u);r.provide(s,{name:r.readonly(n),errors:l,fields:a}),r.watch(a,p=>{i!=null&&i.fields&&p.forEach(m=>{i==null||i.fields.value.add(m)})},{deep:!0}),r.watch(()=>new Map(l.value),(p,m)=>{i!=null&&i.errors&&(Array.from(m.keys()).forEach(v=>{i.errors.value.delete(v)}),Array.from(p.keys()).forEach(v=>{const b=p.get(v);b&&i.errors.value.set(v,b)}))},{deep:!0});const h=r.computed(()=>t!=null&&t.invalid.value?l.value.size>0:!1);return r.watch(h,()=>{h.value?o("invalid"):o("valid")}),{formData:t==null?void 0:t.formData,errors:t==null?void 0:t.errors,submit:t==null?void 0:t.submit,validate:t==null?void 0:t.validate,invalid:h,fields:a,fieldsErrors:l}},render(){var u,o;return this.tag?r.h(this.tag,null,{default:()=>{var t,i;return((i=(t=this.$slots).default)==null?void 0:i.call(t,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((o=(u=this.$slots).default)==null?void 0:o.call(u,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),H=(e,s)=>{const f=r.defineComponent({props:{schema:{type:[Array,Function],required:!0}},setup(u,{slots:o}){const t=r.inject(e);if(!(t!=null&&t.formData))return;const i=typeof u.schema=="function"?u.schema(t):u.schema;let a;return()=>{var l;return i.reduce((n,h)=>{const p=typeof h=="function"?h(t):h,{vvIs:m,vvName:v,vvSlots:b,vvChildren:O,vvIf:x,vvElseIf:g,vvType:A,vvDefaultValue:B,vvShowValid:K,...c}=p;if(x!==void 0){if(typeof x=="string"?a=!!k(Object(t.formData.value),x):typeof x=="function"?a=r.unref(x(t)):a=r.unref(x),!a)return n}else if(g!==void 0&&a!==void 0){if(a||(typeof g=="string"?a=!!k(Object(t.formData.value),g):typeof g=="function"?a=r.unref(g(t)):a=r.unref(g),!a))return n}else a=void 0;const w=O?r.h(f,{schema:O}):void 0;return v?(n.push(r.h(s,{name:v,is:m,type:A,defaultValue:B,showValid:K,props:c},b??w)),n):m?(n.push(r.h(m,c,b??w)),n):(O&&n.push(w),n)},[(l=o==null?void 0:o.default)==null?void 0:l.call(o,{formData:t==null?void 0:t.formData.value,submit:t==null?void 0:t.submit,validate:t==null?void 0:t.validate,errors:t==null?void 0:t.errors.value,status:t==null?void 0:t.status.value,invalid:t==null?void 0:t.invalid.value})])}}});return f},I=(e,s={})=>{const f=Symbol(),u=Symbol(),o=Symbol(),{VvForm:t,errors:i,status:a,formData:l}=z(e,f,s),n=R(f,u),h=P(f,u,o,s),p=H(f,h);return{VvForm:t,VvFormWrapper:n,VvFormField:h,VvFormTemplate:p,formInjectionKey:f,formWrapperInjectionKey:u,formFieldInjectionKey:o,errors:i,status:a,formData:l}},$=Symbol(),Q=e=>{let s={};return e.schema&&(s=I(e.schema,e)),{...s,install(f,{global:u=!1}={}){f.provide($,e),u&&(f.config.globalProperties.$vvForm=e,s!=null&&s.VvForm&&f.component("VvForm",s.VvForm),s!=null&&s.VvFormWrapper&&f.component("VvFormWrapper",s.VvFormWrapper),s!=null&&s.VvFormField&&f.component("VvFormField",s.VvFormField),s!=null&&s.VvFormTemplate&&f.component("VvFormTemplate",s.VvFormTemplate))}}},X=(e,s={})=>r.getCurrentInstance()?I(e,{...r.inject($,{}),...s}):I(e,s),Y=(e,s={})=>I(e,s);y.FormFieldType=d,y.createForm=Q,y.defaultObjectBySchema=E,y.formFactory=Y,y.pluginInjectionKey=$,y.useForm=X,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
package/dist/types.d.ts CHANGED
@@ -1,131 +1,58 @@
1
- import type { Ref } from 'vue'
2
- import type { z, AnyZodObject, ZodEffects } from 'zod'
3
- import type { FormFieldType, FormStatus } from './enums'
4
-
5
- export type FormSchema =
6
- | AnyZodObject
7
- | ZodEffects<AnyZodObject>
8
- | ZodEffects<ZodEffects<AnyZodObject>>
9
-
1
+ import type { Component, DeepReadonly, Ref } from 'vue';
2
+ import type { z, AnyZodObject, ZodEffects } from 'zod';
3
+ import type { FormFieldType, FormStatus } from './enums';
4
+ export type FormSchema = AnyZodObject | ZodEffects<AnyZodObject> | ZodEffects<ZodEffects<AnyZodObject>>;
10
5
  export type FormFieldComponentOptions = {
11
- lazyLoad?: boolean
12
- sideEffects?: (type: `${FormFieldType}`) => Promise | void
13
- }
14
-
6
+ lazyLoad?: boolean;
7
+ sideEffects?: (type: `${FormFieldType}`) => Promise<void> | void;
8
+ };
15
9
  export type FormComponentOptions = {
16
- updateThrottle?: number
17
- continuosValidation?: boolean
18
- }
19
-
20
- export type FormComposableOptions = FormFieldComponentOptions &
21
- FormComponentOptions
22
-
10
+ updateThrottle?: number;
11
+ continuosValidation?: boolean;
12
+ };
13
+ export type FormComposableOptions = FormFieldComponentOptions & FormComponentOptions;
23
14
  export type FormPluginOptions = {
24
- schema?: ZodSchema
25
- } & FormComposableOptions
26
-
15
+ schema?: FormSchema;
16
+ } & FormComposableOptions;
27
17
  export type InjectedFormData<Schema extends FormSchema> = {
28
- formData: Ref<Partial<z.infer<Schema>> | undefined>
29
- errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema>>>>
30
- submit: () => boolean
31
- validate: () => boolean
32
- status: Readonly<Ref<FormStatus | undefined>>
33
- invalid: Readonly<Ref<boolean>>
34
- }
35
-
18
+ formData: Ref<Partial<z.infer<Schema>> | undefined>;
19
+ errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema>> | undefined>>;
20
+ submit: () => boolean;
21
+ validate: () => boolean;
22
+ status: Readonly<Ref<FormStatus | undefined>>;
23
+ invalid: Readonly<Ref<boolean>>;
24
+ };
36
25
  export type InjectedFormWrapperData<Schema extends FormSchema> = {
37
- name: Ref<string>
38
- fields: Ref<Set<string>>
39
- errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema>>>>
40
- }
41
-
26
+ name: Ref<string>;
27
+ fields: Ref<Set<string>>;
28
+ errors: Ref<Map<string, z.inferFormattedError<Schema, string>>>;
29
+ };
42
30
  export type InjectedFormFieldData<Schema extends FormSchema> = {
43
- name: Ref<string>
44
- errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema>>>>
45
- }
46
-
47
- export type Primitive =
48
- | null
49
- | undefined
50
- | string
51
- | number
52
- | boolean
53
- | symbol
54
- | bigint
55
-
56
- type ArrayKey = number
57
-
58
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
- type IsTuple<T extends readonly any[]> = number extends T['length']
60
- ? false
61
- : true
62
-
63
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
- type TupleKeys<T extends readonly any[]> = Exclude<keyof T, keyof any[]>
65
-
66
- export type PathConcat<
67
- TKey extends string | number,
68
- TValue,
69
- > = TValue extends Primitive ? `${TKey}` : `${TKey}` | `${TKey}.${Path<TValue>}`
70
-
71
- export type Path<T> = T extends readonly (infer V)[]
72
- ? IsTuple<T> extends true
73
- ? {
74
- [K in TupleKeys<T>]-?: PathConcat<K & string, T[K]>
75
- }[TupleKeys<T>]
76
- : PathConcat<ArrayKey, V>
77
- : {
78
- [K in keyof T]-?: PathConcat<K & string, T[K]>
79
- }[keyof T]
80
-
81
- export type PathValue<T, TPath extends Path<T> | ArrayPath<T>> = T extends any
82
- ? TPath extends `${infer K}.${infer R}`
83
- ? K extends keyof T
84
- ? R extends Path<T[K]>
85
- ? undefined extends T[K]
86
- ? PathValue<T[K], R> | undefined
87
- : PathValue<T[K], R>
88
- : never
89
- : K extends `${ArrayKey}`
90
- ? T extends readonly (infer V)[]
91
- ? PathValue<V, R & Path<V>>
92
- : never
93
- : never
94
- : TPath extends keyof T
95
- ? T[TPath]
96
- : TPath extends `${ArrayKey}`
97
- ? T extends readonly (infer V)[]
98
- ? V
99
- : never
100
- : never
101
- : never
102
-
103
- export type AnyBoolean<Schema> =
104
- | boolean
105
- | Ref<boolean>
106
- | ((data?: InjectedFormData<Schema>) => boolean | Ref<boolean>)
107
-
108
- export type SimpleFormTemplateItem<Schema extends FormSchema> = Record<
109
- string,
110
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
111
- any
112
- > & {
113
- vvIs?: string | Component
114
- vvName?: Path<z.infer<Schema>>
115
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
116
- vvSlots?: Record<string, any>
117
- vvChildren?: Array<
118
- | SimpleFormTemplateItem<Schema>
119
- | ((data?: InjectedFormData<Schema>) => SimpleFormTemplateItem<Schema>)
120
- >
121
- vvIf?: AnyBoolean<Schema> | Path<z.infer<Schema>>
122
- vvElseIf?: AnyBoolean<Schema> | Path<z.infer<Schema>>
123
- vvType?: `${FormFieldType}`
124
- vvShowValid?: boolean
125
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
126
- vvDefaultValue?: any
127
- }
128
-
129
- export type FormTemplateItem<Schema extends FormSchema> =
130
- | SimpleFormTemplateItem<Schema>
131
- | ((data?: InjectedFormData<Schema>) => SimpleFormTemplateItem<Schema>)
31
+ name: Ref<string>;
32
+ errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema>>>>;
33
+ };
34
+ export type Primitive = null | undefined | string | number | boolean | symbol | bigint;
35
+ type ArrayKey = number;
36
+ type IsTuple<T extends readonly any[]> = number extends T['length'] ? false : true;
37
+ type TupleKeys<T extends readonly any[]> = Exclude<keyof T, keyof any[]>;
38
+ export type PathConcat<TKey extends string | number, TValue> = TValue extends Primitive ? `${TKey}` : `${TKey}` | `${TKey}.${Path<TValue>}`;
39
+ export type Path<T> = T extends readonly (infer V)[] ? IsTuple<T> extends true ? {
40
+ [K in TupleKeys<T>]-?: PathConcat<K & string, T[K]>;
41
+ }[TupleKeys<T>] : PathConcat<ArrayKey, V> : {
42
+ [K in keyof T]-?: PathConcat<K & string, T[K]>;
43
+ }[keyof T];
44
+ export type PathValue<T, TPath extends Path<T> | Path<T>[]> = T extends any ? TPath extends `${infer K}.${infer R}` ? K extends keyof T ? R extends Path<T[K]> ? undefined extends T[K] ? PathValue<T[K], R> | undefined : PathValue<T[K], R> : never : K extends `${ArrayKey}` ? T extends readonly (infer V)[] ? PathValue<V, R & Path<V>> : never : never : TPath extends keyof T ? T[TPath] : TPath extends `${ArrayKey}` ? T extends readonly (infer V)[] ? V : never : never : never;
45
+ export type AnyBoolean<Schema extends FormSchema> = boolean | Ref<boolean> | ((data?: InjectedFormData<Schema>) => boolean | Ref<boolean>);
46
+ export type SimpleFormTemplateItem<Schema extends FormSchema> = Record<string, any> & {
47
+ vvIs?: string | Component;
48
+ vvName?: Path<z.infer<Schema>>;
49
+ vvSlots?: Record<string, any>;
50
+ vvChildren?: Array<SimpleFormTemplateItem<Schema> | ((data?: InjectedFormData<Schema>) => SimpleFormTemplateItem<Schema>)>;
51
+ vvIf?: AnyBoolean<Schema> | Path<z.infer<Schema>>;
52
+ vvElseIf?: AnyBoolean<Schema> | Path<z.infer<Schema>>;
53
+ vvType?: `${FormFieldType}`;
54
+ vvShowValid?: boolean;
55
+ vvDefaultValue?: any;
56
+ };
57
+ export type FormTemplateItem<Schema extends FormSchema> = SimpleFormTemplateItem<Schema> | ((data?: InjectedFormData<Schema>) => SimpleFormTemplateItem<Schema>);
58
+ export {};
package/package.json CHANGED
@@ -19,11 +19,11 @@
19
19
  "bugs": {
20
20
  "url": "https://github.com/volverjs/form-vue/issues"
21
21
  },
22
- "version": "0.0.13",
22
+ "version": "0.0.14-beta.2",
23
23
  "engines": {
24
24
  "node": ">= 16.x"
25
25
  },
26
- "packageManager": "pnpm@7.8.0",
26
+ "packageManager": "pnpm@8.6.12",
27
27
  "type": "module",
28
28
  "main": "./dist/index.js",
29
29
  "module": "./dist/index.js",
@@ -36,33 +36,33 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "@volverjs/ui-vue": "^0.0.8",
39
- "@vueuse/core": "^10.2.1",
39
+ "@vueuse/core": "^10.3.0",
40
40
  "ts-dot-prop": "^2.1.3",
41
41
  "vue": "^3.3.4",
42
42
  "zod": "^3.21.4"
43
43
  },
44
44
  "devDependencies": {
45
- "@playwright/experimental-ct-vue": "1.35.1",
45
+ "@playwright/experimental-ct-vue": "1.36.2",
46
46
  "@testing-library/vue": "^7.0.0",
47
- "@typescript-eslint/eslint-plugin": "^5.60.1",
48
- "@typescript-eslint/parser": "^5.60.1",
47
+ "@typescript-eslint/eslint-plugin": "^6.3.0",
48
+ "@typescript-eslint/parser": "^6.3.0",
49
49
  "@vitejs/plugin-vue": "^4.2.3",
50
50
  "@volverjs/style": "^0.1.11",
51
51
  "@vue/compiler-sfc": "^3.3.4",
52
52
  "@vue/runtime-core": "^3.3.4",
53
- "@vue/test-utils": "^2.4.0",
53
+ "@vue/test-utils": "^2.4.1",
54
54
  "copy": "^0.3.2",
55
- "eslint": "^8.44.0",
56
- "eslint-config-prettier": "^8.8.0",
57
- "eslint-plugin-prettier": "^4.2.1",
58
- "happy-dom": "^9.20.3",
59
- "prettier": "^2.8.8",
55
+ "eslint": "^8.46.0",
56
+ "eslint-config-prettier": "^9.0.0",
57
+ "eslint-plugin-prettier": "^5.0.0",
58
+ "happy-dom": "^10.9.0",
59
+ "prettier": "^3.0.1",
60
60
  "typescript": "^5.1.6",
61
- "vite": "^4.3.9",
61
+ "vite": "^4.4.9",
62
+ "vite-plugin-dts": "^3.5.1",
62
63
  "vite-plugin-eslint": "^1.8.1",
63
64
  "vite-plugin-externalize-deps": "^0.7.0",
64
- "vitest": "^0.32.4",
65
- "vue-tsc": "^1.8.3"
65
+ "vitest": "^0.34.1"
66
66
  },
67
67
  "typesVersions": {
68
68
  "*": {
@@ -83,7 +83,8 @@
83
83
  "scripts": {
84
84
  "lint": "eslint . --ext .js,.jsx,.ts,.tsx",
85
85
  "type-check": "tsc --noEmit",
86
- "build": "vite build && vue-tsc --declaration --emitDeclarationOnly && copy src/**/types.d.ts dist",
86
+ "build": "vite build",
87
+ "dev": "vite build --watch",
87
88
  "test": "pnpm run test-vitest && pnpm run test-playwright",
88
89
  "test-vitest": "vitest run",
89
90
  "test-vitest-watch": "vitest",
package/src/VvForm.ts CHANGED
@@ -28,7 +28,7 @@ export const defineForm = <Schema extends FormSchema>(
28
28
  provideKey: InjectionKey<InjectedFormData<Schema>>,
29
29
  options?: FormComponentOptions,
30
30
  ) => {
31
- const errors = ref<ZodFormattedError<z.infer<Schema>>>()
31
+ const errors = ref<z.inferFormattedError<Schema> | undefined>()
32
32
  const status = ref<FormStatus | undefined>()
33
33
  const formData = ref<Partial<z.infer<Schema> | undefined>>()
34
34
  const component = defineComponent({
@@ -151,7 +151,7 @@ export const defineFormField = <Schema extends FormSchema>(
151
151
  props.name as string,
152
152
  {
153
153
  _errors: invalidLabel.value,
154
- },
154
+ } as z.inferFormattedError<Schema>,
155
155
  )
156
156
  }
157
157
  } else {
@@ -42,7 +42,7 @@ export const defineFormWrapper = <Schema extends FormSchema>(
42
42
  const wrapperProvided = inject(wrapperProvideKey, undefined)
43
43
  const fields = ref(new Set<string>())
44
44
  const fieldsErrors: Ref<
45
- Map<string, Record<string, { _errors: string[] }>>
45
+ Map<string, z.inferFormattedError<Schema>>
46
46
  > = ref(new Map())
47
47
  const { name } = toRefs(props)
48
48
 
@@ -1,4 +1,4 @@
1
- import type { Ref } from 'vue'
1
+ import type { Component, DeepReadonly, Ref } from 'vue'
2
2
  import type { z, AnyZodObject, ZodEffects } from 'zod'
3
3
  import type { FormFieldType, FormStatus } from './enums'
4
4
 
@@ -9,7 +9,7 @@ export type FormSchema =
9
9
 
10
10
  export type FormFieldComponentOptions = {
11
11
  lazyLoad?: boolean
12
- sideEffects?: (type: `${FormFieldType}`) => Promise | void
12
+ sideEffects?: (type: `${FormFieldType}`) => Promise<void> | void
13
13
  }
14
14
 
15
15
  export type FormComponentOptions = {
@@ -21,12 +21,14 @@ export type FormComposableOptions = FormFieldComponentOptions &
21
21
  FormComponentOptions
22
22
 
23
23
  export type FormPluginOptions = {
24
- schema?: ZodSchema
24
+ schema?: FormSchema
25
25
  } & FormComposableOptions
26
26
 
27
27
  export type InjectedFormData<Schema extends FormSchema> = {
28
28
  formData: Ref<Partial<z.infer<Schema>> | undefined>
29
- errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema>>>>
29
+ errors: Readonly<
30
+ Ref<DeepReadonly<z.inferFormattedError<Schema>> | undefined>
31
+ >
30
32
  submit: () => boolean
31
33
  validate: () => boolean
32
34
  status: Readonly<Ref<FormStatus | undefined>>
@@ -36,7 +38,7 @@ export type InjectedFormData<Schema extends FormSchema> = {
36
38
  export type InjectedFormWrapperData<Schema extends FormSchema> = {
37
39
  name: Ref<string>
38
40
  fields: Ref<Set<string>>
39
- errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema>>>>
41
+ errors: Ref<Map<string, z.inferFormattedError<Schema, string>>>
40
42
  }
41
43
 
42
44
  export type InjectedFormFieldData<Schema extends FormSchema> = {
@@ -78,7 +80,8 @@ export type Path<T> = T extends readonly (infer V)[]
78
80
  [K in keyof T]-?: PathConcat<K & string, T[K]>
79
81
  }[keyof T]
80
82
 
81
- export type PathValue<T, TPath extends Path<T> | ArrayPath<T>> = T extends any
83
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
+ export type PathValue<T, TPath extends Path<T> | Path<T>[]> = T extends any
82
85
  ? TPath extends `${infer K}.${infer R}`
83
86
  ? K extends keyof T
84
87
  ? R extends Path<T[K]>
@@ -100,7 +103,7 @@ export type PathValue<T, TPath extends Path<T> | ArrayPath<T>> = T extends any
100
103
  : never
101
104
  : never
102
105
 
103
- export type AnyBoolean<Schema> =
106
+ export type AnyBoolean<Schema extends FormSchema> =
104
107
  | boolean
105
108
  | Ref<boolean>
106
109
  | ((data?: InjectedFormData<Schema>) => boolean | Ref<boolean>)
package/src/utils.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  ZodSchema,
9
9
  ZodNullable,
10
10
  ZodOptional,
11
+ ZodArray,
11
12
  } from 'zod'
12
13
  import type { FormSchema } from './types'
13
14
 
@@ -26,7 +27,7 @@ export const defaultObjectBySchema = <Schema extends FormSchema>(
26
27
  while (toReturn instanceof ZodEffects) {
27
28
  toReturn = toReturn.innerType()
28
29
  }
29
- while (toReturn instanceof ZodOptional) {
30
+ if (toReturn instanceof ZodOptional) {
30
31
  toReturn = toReturn._def.innerType
31
32
  }
32
33
  return toReturn
@@ -42,10 +43,12 @@ export const defaultObjectBySchema = <Schema extends FormSchema>(
42
43
  (Object.entries(innerType.shape) as [string, ZodTypeAny][]).map(
43
44
  ([key, subSchema]) => {
44
45
  const originalValue = original[key]
45
- const innerType = getInnerType(subSchema)
46
- let defaultValue = undefined
46
+ let innerType = getInnerType(subSchema)
47
+ let defaultValue: Partial<z.infer<Schema>> | undefined =
48
+ undefined
47
49
  if (innerType instanceof ZodDefault) {
48
50
  defaultValue = innerType._def.defaultValue()
51
+ innerType = innerType._def.innerType
49
52
  }
50
53
  if (
51
54
  originalValue === null &&
@@ -59,6 +62,26 @@ export const defaultObjectBySchema = <Schema extends FormSchema>(
59
62
  return [key, parse.data ?? defaultValue]
60
63
  }
61
64
  }
65
+ if (
66
+ innerType instanceof ZodArray &&
67
+ Array.isArray(originalValue) &&
68
+ originalValue.length
69
+ ) {
70
+ const arrayType = getInnerType(innerType._def.type)
71
+ if (arrayType instanceof ZodObject) {
72
+ return [
73
+ key,
74
+ originalValue.map((element: unknown) =>
75
+ defaultObjectBySchema(
76
+ arrayType,
77
+ element && typeof element === 'object'
78
+ ? element
79
+ : undefined,
80
+ ),
81
+ ) ?? defaultValue,
82
+ ]
83
+ }
84
+ }
62
85
  if (innerType instanceof ZodObject) {
63
86
  return [
64
87
  key,
@@ -67,7 +90,7 @@ export const defaultObjectBySchema = <Schema extends FormSchema>(
67
90
  originalValue &&
68
91
  typeof originalValue === 'object'
69
92
  ? originalValue
70
- : {},
93
+ : defaultValue,
71
94
  ),
72
95
  ]
73
96
  }