@volverjs/form-vue 1.0.0-beta.7 → 1.0.0-beta.9
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/LICENSE +1 -1
- package/README.md +2 -2
- package/dist/index.es.js +161 -164
- package/dist/index.umd.js +1 -1
- package/dist/src/VvForm.d.ts +86 -127
- package/dist/src/VvFormField.d.ts +5 -5
- package/dist/src/VvFormTemplate.d.ts +23 -55
- package/dist/src/VvFormWrapper.d.ts +46 -81
- package/dist/src/index.d.ts +491 -815
- package/dist/src/utils.d.ts +1 -1
- package/package.json +24 -24
- package/src/VvForm.ts +4 -6
- package/src/VvFormField.ts +5 -6
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(w,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],e):(w=typeof globalThis<"u"?globalThis:w||self,e(w["@volverjs/form-vue"]={},w.Vue,w.VueUseCore,w.zod))})(this,function(w,e,$,k){"use strict";function N(r){return Array.isArray(r)}function J(r){return typeof r<"u"}function G(r){return r===null}function L(r){return typeof r=="object"}function Z(r){return typeof r=="string"}function A(r){return typeof r>"u"}const M=/^[0-9]+$/,P=["__proto__","prototype","constructor"];function E(r,o,a){const d=J(a)?a:void 0;if(!L(r)||!Z(o))return d;const i=q(o);if(i.length!==0){for(const t of i){if(t==="*")continue;const u=function(l){return l.map(f=>A(f)||G(f)?f:N(f)?u(f):f[t])};if(N(r)&&!M.test(t)?r=u(r):r=r[t],A(r)||G(r))break}return A(r)?d:r}}function K(r,o,a){if(!L(r)||!Z(o))return;const d=q(o);if(d.length===0)return;const i=d.length;for(let t=0;t<i;t++){const u=d[t];if(t===i-1){r[u]=a;return}if(u==="*"&&N(r)){const l=d.slice(t+1).join(".");for(const f of r)K(f,l,a);return}A(r[u])&&(r[u]={}),r=r[u]}}function q(r){const o=r.split(/[.]|(?:\[(\d|\*)\])/).filter(a=>!!a);return o.some(a=>P.indexOf(a)!==-1)?[]:o}var c=(r=>(r.text="text",r.number="number",r.email="email",r.password="password",r.tel="tel",r.url="url",r.search="search",r.date="date",r.time="time",r.datetimeLocal="datetime-local",r.month="month",r.week="week",r.color="color",r.select="select",r.checkbox="checkbox",r.radio="radio",r.textarea="textarea",r.radioGroup="radioGroup",r.checkboxGroup="checkboxGroup",r.combobox="combobox",r.custom="custom",r))(c||{}),O=(r=>(r.invalid="invalid",r.valid="valid",r.submitting="submitting",r.updated="updated",r.unknown="unknown",r))(O||{});const z=(r,o,a,d)=>e.defineComponent({name:"VvFormField",props:{type:{type:String,validator:i=>Object.values(c).includes(i),default:c.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","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(i,{slots:t,emit:u}){const l=e.computed({get(){if(n!=null&&n.formData)return E(Object(n.formData.value),String(i.name))},set(s){n!=null&&n.formData&&(K(Object(n.formData.value),String(i.name),s),u("update:modelValue",{newValue:l.value,formData:n==null?void 0:n.formData}))}});e.onMounted(()=>{l.value===void 0&&i.defaultValue!==void 0&&(l.value=i.defaultValue)}),e.onBeforeUnmount(()=>{y(),h()});const f=e.inject(o,void 0);f&&f.fields.value.add(i.name);const n=e.inject(r),{props:m,name:V}=e.toRefs(i),p=e.computed(()=>{if(n!=null&&n.errors.value)return E(n.errors.value,String(i.name))}),g=e.computed(()=>{var s;return(s=p.value)==null?void 0:s._errors}),v=e.computed(()=>p.value!==void 0),y=e.watch(v,()=>{v.value?(u("invalid",g.value),f&&f.errors.value.set(i.name,{_errors:g.value})):(u("valid",l.value),f&&f.errors.value.delete(i.name))}),h=e.watch(()=>n==null?void 0:n.formData,()=>{u("update:formData",n==null?void 0:n.formData)},{deep:!0}),b=s=>{l.value=s},x=e.computed(()=>{let s=m.value;return typeof s=="function"&&(s=s(n==null?void 0:n.formData)),Object.keys(s).reduce((U,I)=>(U[I]=e.unref(s[I]),U),{})}),S=e.computed(()=>{const s=x.value.readonly??i.readonly;return s===void 0?n==null?void 0:n.readonly.value:s}),C=e.computed(()=>({...x.value,name:x.value.name??i.name,invalid:v.value,valid:i.showValid?!!(!v.value&&l.value):void 0,type:(s=>{if([c.text,c.number,c.email,c.password,c.tel,c.url,c.search,c.date,c.time,c.datetimeLocal,c.month,c.week,c.color].includes(s))return s})(i.type),invalidLabel:g.value,modelValue:l.value,readonly:S.value,"onUpdate:modelValue":b}));return e.provide(a,{name:e.readonly(V),errors:e.readonly(p)}),{component:e.computed(()=>{if(i.type===c.custom)return{render(){var s;return((s=t.default)==null?void 0:s.call(t,{modelValue:l.value,onUpdate:b,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,invalid:v.value,invalidLabel:g.value,formData:n==null?void 0:n.formData.value,formErrors:n==null?void 0:n.errors.value,errors:p.value,readonly:S.value}))??t.defalut}};if(!((d==null?void 0:d.lazyLoad)??i.lazyLoad)){let s;switch(i.type){case c.select:s=e.resolveComponent("VvSelect");break;case c.checkbox:s=e.resolveComponent("VvCheckbox");break;case c.radio:s=e.resolveComponent("VvRadio");break;case c.textarea:s=e.resolveComponent("VvTextarea");break;case c.radioGroup:s=e.resolveComponent("VvRadioGroup");break;case c.checkboxGroup:s=e.resolveComponent("VvCheckboxGroup");break;case c.combobox:s=e.resolveComponent("VvCombobox");break;default:s=e.resolveComponent("VvInputText")}if(typeof s!="string")return s;console.warn(`[form-vue warn]: ${s} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return e.defineAsyncComponent(async()=>{switch(d!=null&&d.sideEffects&&await Promise.resolve(d.sideEffects(i.type)),i.type){case c.textarea:return import("@volverjs/ui-vue/vv-textarea");case c.radio:return import("@volverjs/ui-vue/vv-radio");case c.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case c.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case c.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case c.select:return import("@volverjs/ui-vue/vv-select");case c.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:C,invalid:v}},render(){return this.is?e.h(this.is,this.hasProps,this.$slots):this.type===c.custom?e.h(this.component,null,this.$slots):e.h(this.component,this.hasProps,this.$slots)}}),W=(r,o={})=>{const a=t=>{let u=t;for(;u instanceof k.ZodEffects;)u=u.innerType();return u instanceof k.ZodOptional&&(u=u._def.innerType),u},d=a(r);return{...(d instanceof k.ZodObject?d._def.unknownKeys==="passthrough":!1)?o:{},...Object.fromEntries(Object.entries(d.shape).map(([t,u])=>{const l=o[t];let f=a(u),n;if(f instanceof k.ZodDefault&&(n=f._def.defaultValue(),f=f._def.innerType),l===null&&f instanceof k.ZodNullable)return[t,l];if(f instanceof k.ZodSchema){const m=u.safeParse(l);if(m.success)return[t,m.data??n]}if(f instanceof k.ZodArray&&Array.isArray(l)&&l.length){const m=a(f._def.type);if(m instanceof k.ZodObject)return[t,l.map(V=>W(m,V&&typeof V=="object"?V:void 0))??n]}return f instanceof k.ZodObject?[t,W(f,l&&typeof l=="object"?l:n)]:[t,n]}))}},T=(r,o,a,d)=>{const i=e.ref(),t=e.ref(),u=e.computed(()=>t.value===O.invalid),l=e.ref(),f=e.ref(!1),n=async(v=l.value)=>{if(f.value)return!0;const y=await r.safeParseAsync(v);return y.success?(i.value=void 0,t.value=O.valid,l.value=y.data,!0):(i.value=y.error.format(),t.value=O.invalid,!1)},m=async()=>f.value||!await n()?!1:(t.value=O.submitting,!0),{ignoreUpdates:V,stop:p}=$.watchIgnorable(l,()=>{t.value=O.updated},{deep:!0,eventFilter:$.throttleFilter((a==null?void 0:a.updateThrottle)??500)}),g=e.defineComponent({name:"VvForm",props:{continuosValidation:{type:Boolean,default:!1},modelValue:{type:Object,default:()=>({})},readonly:{type:Boolean,default:(a==null?void 0:a.readonly)??!1},tag:{type:String,default:"form"},template:{type:[Array,Function],default:void 0}},emits:["invalid","valid","submit","update:modelValue","update:readonly"],expose:["submit","validate","errors","status","valid","invalid","readonly"],setup(v,{emit:y}){return l.value=W(r,e.toRaw(v.modelValue)),e.watch(()=>v.modelValue,h=>{if(h){const b=e.isProxy(h)?e.toRaw(h):h;if(JSON.stringify(b)===JSON.stringify(e.toRaw(l.value)))return;l.value=typeof(b==null?void 0:b.clone)=="function"?b.clone():JSON.parse(JSON.stringify(b))}},{deep:!0}),e.watch(t,async h=>{var b,x,S,C,R;if(h===O.invalid){const s=e.toRaw(i.value);y("invalid",s),(b=a==null?void 0:a.onInvalid)==null||b.call(a,s);return}if(h===O.valid){const s=e.toRaw(l.value);y("valid",s),(x=a==null?void 0:a.onValid)==null||x.call(a,s),y("update:modelValue",s),(S=a==null?void 0:a.onUpdate)==null||S.call(a,s);return}if(h===O.submitting){const s=e.toRaw(l.value);y("submit",s),(C=a==null?void 0:a.onSubmit)==null||C.call(a,s)}if(h===O.updated){if((i.value||a!=null&&a.continuosValidation||v.continuosValidation)&&await n(),!l.value||!v.modelValue||JSON.stringify(l.value)!==JSON.stringify(v.modelValue)){const s=e.toRaw(l.value);y("update:modelValue",s),(R=a==null?void 0:a.onUpdate)==null||R.call(a,s)}t.value===O.updated&&(t.value=O.unknown)}}),e.onMounted(()=>{v.readonly&&!f.value&&(f.value=v.readonly)}),e.watch(()=>v.readonly,h=>{f.value=h}),e.watch(f,h=>{h!==v.readonly&&y("update:readonly",f.value)}),e.provide(o,{formData:l,submit:m,validate:n,ignoreUpdates:V,stopUpdatesWatch:p,errors:e.readonly(i),status:e.readonly(t),invalid:u,readonly:f}),{formData:l,submit:m,validate:n,ignoreUpdates:V,stopUpdatesWatch:p,errors:e.readonly(i),status:e.readonly(t),invalid:u,isReadonly:f}},render(){const v=()=>{var y,h;return((h=(y=this.$slots)==null?void 0:y.default)==null?void 0:h.call(y,{formData:this.formData,submit:this.submit,validate:this.validate,ignoreUpdates:this.ignoreUpdates,stopUpdatesWatch:this.stopUpdatesWatch,errors:this.errors,status:this.status,invalid:this.invalid,readonly:this.isReadonly}))??this.$slots.default};return e.h(this.tag,{onSubmit:e.withModifiers(this.submit,["prevent"])},(this.template??(a==null?void 0:a.template))&&d?[e.h(d,{schema:this.template??(a==null?void 0:a.template)},{default:v})]:{default:v})}});return{errors:i,status:t,invalid:u,readonly:f,formData:l,validate:n,submit:m,ignoreUpdates:V,stopUpdatesWatch:p,VvForm:g}},H=(r,o)=>e.defineComponent({name:"VvFormWrapper",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(d,{emit:i}){const t=e.inject(r),u=e.inject(o,void 0),l=e.ref(new Set),f=e.ref(new Map),{name:n}=e.toRefs(d);e.provide(o,{name:e.readonly(n),errors:f,fields:l}),e.watch(l,V=>{u!=null&&u.fields&&V.forEach(p=>{u==null||u.fields.value.add(p)})},{deep:!0}),e.watch(()=>new Map(f.value),(V,p)=>{u!=null&&u.errors&&(Array.from(p.keys()).forEach(g=>{u.errors.value.delete(g)}),Array.from(V.keys()).forEach(g=>{const v=V.get(g);v&&u.errors.value.set(g,v)}))},{deep:!0});const m=e.computed(()=>t!=null&&t.invalid.value?f.value.size>0:!1);return e.watch(m,()=>{m.value?i("invalid"):i("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:m,fields:l,fieldsErrors:f}},render(){var d,i;return this.tag?e.h(this.tag,null,{default:()=>{var t,u;return((u=(t=this.$slots).default)==null?void 0:u.call(t,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((i=(d=this.$slots).default)==null?void 0:i.call(d,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),Q=(r,o)=>{const a=e.defineComponent({name:"VvFormTemplate",props:{schema:{type:[Array,Function],required:!0}},setup(d,{slots:i}){const t=e.inject(r);if(t!=null&&t.formData)return()=>{var n;const u=typeof d.schema=="function"?d.schema(t):d.schema;let l;const f=u.reduce((m,V)=>{const p=typeof V=="function"?V(t):V,{vvIs:g,vvName:v,vvSlots:y,vvChildren:h,vvIf:b,vvElseIf:x,vvType:S,vvDefaultValue:C,vvShowValid:R,vvContent:s,...U}=p;if(b!==void 0){if(typeof b=="string"?l=!!E(Object(t.formData.value),b):typeof b=="function"?l=e.unref(b(t)):l=e.unref(b),!l)return m}else if(x!==void 0&&l!==void 0){if(l||(typeof x=="string"?l=!!E(Object(t.formData.value),x):typeof x=="function"?l=e.unref(x(t)):l=e.unref(x),!l))return m}else l=void 0;const I=h?e.h(a,{schema:h}):void 0;return v?(m.push(e.h(o,{name:v,is:g,type:S,defaultValue:C,showValid:R,props:U},y??I??s)),m):g?(m.push(e.h(g,U,y??I??s)),m):(h&&m.push(I),m)},[]);return f.push((n=i==null?void 0:i.default)==null?void 0:n.call(i,{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})),f}}});return a},B=(r,o={})=>{const a=Symbol(),d=Symbol(),i=Symbol(),t=H(a,d),u=z(a,d,i,o),l=Q(a,u),{VvForm:f,errors:n,status:m,invalid:V,readonly:p,formData:g,validate:v,submit:y,ignoreUpdates:h,stopUpdatesWatch:b}=T(r,a,o,l);return{VvForm:f,VvFormWrapper:t,VvFormField:u,VvFormTemplate:l,formInjectionKey:a,formWrapperInjectionKey:d,formFieldInjectionKey:i,errors:n,status:m,invalid:V,readonly:p,formData:g,validate:v,submit:y,ignoreUpdates:h,stopUpdatesWatch:b}},_=Symbol(),X=r=>{let o={};return r.schema&&(o=B(r.schema,r)),{...o,install(a,{global:d=!1}={}){a.provide(_,r),d&&(a.config.globalProperties.$vvForm=r,o!=null&&o.VvForm&&a.component("VvForm",o.VvForm),o!=null&&o.VvFormWrapper&&a.component("VvFormWrapper",o.VvFormWrapper),o!=null&&o.VvFormField&&a.component("VvFormField",o.VvFormField),o!=null&&o.VvFormTemplate&&a.component("VvFormTemplate",o.VvFormTemplate))}}},Y=(r,o={})=>e.getCurrentInstance()?B(r,{...e.inject(_,{}),...o}):B(r,o),D=(r,o={})=>B(r,o);w.FormFieldType=c,w.createForm=X,w.defaultObjectBySchema=W,w.formFactory=D,w.pluginInjectionKey=_,w.useForm=Y,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(w,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],e):(w=typeof globalThis<"u"?globalThis:w||self,e(w["@volverjs/form-vue"]={},w.Vue,w.VueUseCore,w.zod))})(this,function(w,e,$,k){"use strict";function N(r){return Array.isArray(r)}function J(r){return typeof r<"u"}function G(r){return r===null}function L(r){return typeof r=="object"}function Z(r){return typeof r=="string"}function A(r){return typeof r>"u"}const M=/^[0-9]+$/,P=["__proto__","prototype","constructor"];function E(r,u,a){const d=J(a)?a:void 0;if(!L(r)||!Z(u))return d;const i=q(u);if(i.length!==0){for(const t of i){if(t==="*")continue;const s=function(l){return l.map(f=>A(f)||G(f)?f:N(f)?s(f):f[t])};if(N(r)&&!M.test(t)?r=s(r):r=r[t],A(r)||G(r))break}return A(r)?d:r}}function K(r,u,a){if(!L(r)||!Z(u))return;const d=q(u);if(d.length===0)return;const i=d.length;for(let t=0;t<i;t++){const s=d[t];if(t===i-1){r[s]=a;return}if(s==="*"&&N(r)){const l=d.slice(t+1).join(".");for(const f of r)K(f,l,a);return}A(r[s])&&(r[s]={}),r=r[s]}}function q(r){const u=r.split(/[.]|(?:\[(\d|\*)\])/).filter(a=>!!a);return u.some(a=>P.indexOf(a)!==-1)?[]:u}var c=(r=>(r.text="text",r.number="number",r.email="email",r.password="password",r.tel="tel",r.url="url",r.search="search",r.date="date",r.time="time",r.datetimeLocal="datetime-local",r.month="month",r.week="week",r.color="color",r.select="select",r.checkbox="checkbox",r.radio="radio",r.textarea="textarea",r.radioGroup="radioGroup",r.checkboxGroup="checkboxGroup",r.combobox="combobox",r.custom="custom",r))(c||{}),O=(r=>(r.invalid="invalid",r.valid="valid",r.submitting="submitting",r.updated="updated",r.unknown="unknown",r))(O||{});const z=(r,u,a,d)=>e.defineComponent({name:"VvFormField",props:{type:{type:String,validator:i=>Object.values(c).includes(i),default:c.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","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(i,{slots:t,emit:s}){const l=e.computed({get(){if(n!=null&&n.formData)return E(Object(n.formData.value),String(i.name))},set(o){n!=null&&n.formData&&(K(Object(n.formData.value),String(i.name),o),s("update:modelValue",{newValue:l.value,formData:n==null?void 0:n.formData}))}});e.onMounted(()=>{l.value===void 0&&i.defaultValue!==void 0&&(l.value=i.defaultValue)}),e.onBeforeUnmount(()=>{y(),h()});const f=e.inject(u,void 0);f&&f.fields.value.add(i.name);const n=e.inject(r),{props:m,name:V}=e.toRefs(i),p=e.computed(()=>{if(n!=null&&n.errors.value)return E(n.errors.value,String(i.name))}),g=e.computed(()=>{var o;return(o=p.value)==null?void 0:o._errors}),v=e.computed(()=>p.value!==void 0),y=e.watch(v,()=>{v.value?(s("invalid",g.value),f&&f.errors.value.set(i.name,{_errors:g.value})):(s("valid",l.value),f&&f.errors.value.delete(i.name))}),h=e.watch(()=>n==null?void 0:n.formData,()=>{s("update:formData",n==null?void 0:n.formData)},{deep:!0}),b=o=>{l.value=o},x=e.computed(()=>{let o=m.value;return typeof o=="function"&&(o=o(n==null?void 0:n.formData)),Object.keys(o).reduce((U,I)=>(U[I]=e.unref(o[I]),U),{})}),S=e.computed(()=>n!=null&&n.readonly.value?!0:x.value.readonly??i.readonly),C=e.computed(()=>({...x.value,name:x.value.name??i.name,invalid:v.value,valid:i.showValid?!!(!v.value&&l.value):void 0,type:(o=>{if([c.text,c.number,c.email,c.password,c.tel,c.url,c.search,c.date,c.time,c.datetimeLocal,c.month,c.week,c.color].includes(o))return o})(i.type),invalidLabel:g.value,modelValue:l.value,readonly:S.value,"onUpdate:modelValue":b}));return e.provide(a,{name:e.readonly(V),errors:e.readonly(p)}),{component:e.computed(()=>{if(i.type===c.custom)return{render(){var o;return((o=t.default)==null?void 0:o.call(t,{modelValue:l.value,onUpdate:b,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,invalid:v.value,invalidLabel:g.value,formData:n==null?void 0:n.formData.value,formErrors:n==null?void 0:n.errors.value,errors:p.value,readonly:S.value}))??t.defalut}};if(!((d==null?void 0:d.lazyLoad)??i.lazyLoad)){let o;switch(i.type){case c.select:o=e.resolveComponent("VvSelect");break;case c.checkbox:o=e.resolveComponent("VvCheckbox");break;case c.radio:o=e.resolveComponent("VvRadio");break;case c.textarea:o=e.resolveComponent("VvTextarea");break;case c.radioGroup:o=e.resolveComponent("VvRadioGroup");break;case c.checkboxGroup:o=e.resolveComponent("VvCheckboxGroup");break;case c.combobox:o=e.resolveComponent("VvCombobox");break;default:o=e.resolveComponent("VvInputText")}if(typeof o!="string")return o;console.warn(`[form-vue warn]: ${o} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return e.defineAsyncComponent(async()=>{switch(d!=null&&d.sideEffects&&await Promise.resolve(d.sideEffects(i.type)),i.type){case c.textarea:return import("@volverjs/ui-vue/vv-textarea");case c.radio:return import("@volverjs/ui-vue/vv-radio");case c.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case c.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case c.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case c.select:return import("@volverjs/ui-vue/vv-select");case c.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:C,invalid:v}},render(){return this.is?e.h(this.is,this.hasProps,this.$slots):this.type===c.custom?e.h(this.component,null,this.$slots):e.h(this.component,this.hasProps,this.$slots)}}),W=(r,u={})=>{const a=t=>{let s=t;for(;s instanceof k.ZodEffects;)s=s.innerType();return s instanceof k.ZodOptional&&(s=s._def.innerType),s},d=a(r);return{...(d instanceof k.ZodObject?d._def.unknownKeys==="passthrough":!1)?u:{},...Object.fromEntries(Object.entries(d.shape).map(([t,s])=>{const l=u[t];let f=a(s),n;if(f instanceof k.ZodDefault&&(n=f._def.defaultValue(),f=f._def.innerType),l===null&&f instanceof k.ZodNullable)return[t,l];if(f instanceof k.ZodSchema){const m=s.safeParse(l);if(m.success)return[t,m.data??n]}if(f instanceof k.ZodArray&&Array.isArray(l)&&l.length){const m=a(f._def.type);if(m instanceof k.ZodObject)return[t,l.map(V=>W(m,V&&typeof V=="object"?V:void 0))??n]}return f instanceof k.ZodObject?[t,W(f,l&&typeof l=="object"?l:n)]:[t,n]}))}},T=(r,u,a,d)=>{const i=e.ref(),t=e.ref(),s=e.computed(()=>t.value===O.invalid),l=e.ref(),f=e.ref(!1),n=async(v=l.value)=>{if(f.value)return!0;const y=await r.safeParseAsync(v);return y.success?(i.value=void 0,t.value=O.valid,l.value=y.data,!0):(i.value=y.error.format(),t.value=O.invalid,!1)},m=async()=>f.value||!await n()?!1:(t.value=O.submitting,!0),{ignoreUpdates:V,stop:p}=$.watchIgnorable(l,()=>{t.value=O.updated},{deep:!0,eventFilter:$.throttleFilter((a==null?void 0:a.updateThrottle)??500)}),g=e.defineComponent({name:"VvForm",props:{continuosValidation:{type:Boolean,default:!1},modelValue:{type:Object,default:()=>({})},readonly:{type:Boolean,default:(a==null?void 0:a.readonly)??!1},tag:{type:String,default:"form"},template:{type:[Array,Function],default:void 0}},emits:["invalid","valid","submit","update:modelValue","update:readonly"],expose:["submit","validate","errors","status","valid","invalid","readonly"],setup(v,{emit:y}){return l.value=W(r,e.toRaw(v.modelValue)),e.watch(()=>v.modelValue,h=>{if(h){const b=e.isProxy(h)?e.toRaw(h):h;if(JSON.stringify(b)===JSON.stringify(e.toRaw(l.value)))return;l.value=typeof(b==null?void 0:b.clone)=="function"?b.clone():JSON.parse(JSON.stringify(b))}},{deep:!0}),e.watch(t,async h=>{var b,x,S,C,R;if(h===O.invalid){const o=e.toRaw(i.value);y("invalid",o),(b=a==null?void 0:a.onInvalid)==null||b.call(a,o);return}if(h===O.valid){const o=e.toRaw(l.value);y("valid",o),(x=a==null?void 0:a.onValid)==null||x.call(a,o),y("update:modelValue",o),(S=a==null?void 0:a.onUpdate)==null||S.call(a,o);return}if(h===O.submitting){const o=e.toRaw(l.value);y("submit",o),(C=a==null?void 0:a.onSubmit)==null||C.call(a,o)}if(h===O.updated){if((i.value||a!=null&&a.continuosValidation||v.continuosValidation)&&await n(),!l.value||!v.modelValue||JSON.stringify(l.value)!==JSON.stringify(v.modelValue)){const o=e.toRaw(l.value);y("update:modelValue",o),(R=a==null?void 0:a.onUpdate)==null||R.call(a,o)}t.value===O.updated&&(t.value=O.unknown)}}),e.onMounted(()=>{f.value=v.readonly}),e.watch(()=>v.readonly,h=>{f.value=h}),e.watch(f,h=>{h!==v.readonly&&y("update:readonly",f.value)}),e.provide(u,{formData:l,submit:m,validate:n,ignoreUpdates:V,stopUpdatesWatch:p,errors:e.readonly(i),status:e.readonly(t),invalid:s,readonly:f}),{formData:l,submit:m,validate:n,ignoreUpdates:V,stopUpdatesWatch:p,errors:e.readonly(i),status:e.readonly(t),invalid:s,isReadonly:f}},render(){const v=()=>{var y,h;return((h=(y=this.$slots)==null?void 0:y.default)==null?void 0:h.call(y,{formData:this.formData,submit:this.submit,validate:this.validate,ignoreUpdates:this.ignoreUpdates,stopUpdatesWatch:this.stopUpdatesWatch,errors:this.errors,status:this.status,invalid:this.invalid,readonly:this.isReadonly}))??this.$slots.default};return e.h(this.tag,{onSubmit:e.withModifiers(this.submit,["prevent"])},(this.template??(a==null?void 0:a.template))&&d?[e.h(d,{schema:this.template??(a==null?void 0:a.template)},{default:v})]:{default:v})}});return{errors:i,status:t,invalid:s,readonly:f,formData:l,validate:n,submit:m,ignoreUpdates:V,stopUpdatesWatch:p,VvForm:g}},H=(r,u)=>e.defineComponent({name:"VvFormWrapper",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(d,{emit:i}){const t=e.inject(r),s=e.inject(u,void 0),l=e.ref(new Set),f=e.ref(new Map),{name:n}=e.toRefs(d);e.provide(u,{name:e.readonly(n),errors:f,fields:l}),e.watch(l,V=>{s!=null&&s.fields&&V.forEach(p=>{s==null||s.fields.value.add(p)})},{deep:!0}),e.watch(()=>new Map(f.value),(V,p)=>{s!=null&&s.errors&&(Array.from(p.keys()).forEach(g=>{s.errors.value.delete(g)}),Array.from(V.keys()).forEach(g=>{const v=V.get(g);v&&s.errors.value.set(g,v)}))},{deep:!0});const m=e.computed(()=>t!=null&&t.invalid.value?f.value.size>0:!1);return e.watch(m,()=>{m.value?i("invalid"):i("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:m,fields:l,fieldsErrors:f}},render(){var d,i;return this.tag?e.h(this.tag,null,{default:()=>{var t,s;return((s=(t=this.$slots).default)==null?void 0:s.call(t,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((i=(d=this.$slots).default)==null?void 0:i.call(d,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),Q=(r,u)=>{const a=e.defineComponent({name:"VvFormTemplate",props:{schema:{type:[Array,Function],required:!0}},setup(d,{slots:i}){const t=e.inject(r);if(t!=null&&t.formData)return()=>{var n;const s=typeof d.schema=="function"?d.schema(t):d.schema;let l;const f=s.reduce((m,V)=>{const p=typeof V=="function"?V(t):V,{vvIs:g,vvName:v,vvSlots:y,vvChildren:h,vvIf:b,vvElseIf:x,vvType:S,vvDefaultValue:C,vvShowValid:R,vvContent:o,...U}=p;if(b!==void 0){if(typeof b=="string"?l=!!E(Object(t.formData.value),b):typeof b=="function"?l=e.unref(b(t)):l=e.unref(b),!l)return m}else if(x!==void 0&&l!==void 0){if(l||(typeof x=="string"?l=!!E(Object(t.formData.value),x):typeof x=="function"?l=e.unref(x(t)):l=e.unref(x),!l))return m}else l=void 0;const I=h?e.h(a,{schema:h}):void 0;return v?(m.push(e.h(u,{name:v,is:g,type:S,defaultValue:C,showValid:R,props:U},y??I??o)),m):g?(m.push(e.h(g,U,y??I??o)),m):(h&&m.push(I),m)},[]);return f.push((n=i==null?void 0:i.default)==null?void 0:n.call(i,{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})),f}}});return a},B=(r,u={})=>{const a=Symbol(),d=Symbol(),i=Symbol(),t=H(a,d),s=z(a,d,i,u),l=Q(a,s),{VvForm:f,errors:n,status:m,invalid:V,readonly:p,formData:g,validate:v,submit:y,ignoreUpdates:h,stopUpdatesWatch:b}=T(r,a,u,l);return{VvForm:f,VvFormWrapper:t,VvFormField:s,VvFormTemplate:l,formInjectionKey:a,formWrapperInjectionKey:d,formFieldInjectionKey:i,errors:n,status:m,invalid:V,readonly:p,formData:g,validate:v,submit:y,ignoreUpdates:h,stopUpdatesWatch:b}},_=Symbol(),X=r=>{let u={};return r.schema&&(u=B(r.schema,r)),{...u,install(a,{global:d=!1}={}){a.provide(_,r),d&&(a.config.globalProperties.$vvForm=r,u!=null&&u.VvForm&&a.component("VvForm",u.VvForm),u!=null&&u.VvFormWrapper&&a.component("VvFormWrapper",u.VvFormWrapper),u!=null&&u.VvFormField&&a.component("VvFormField",u.VvFormField),u!=null&&u.VvFormTemplate&&a.component("VvFormTemplate",u.VvFormTemplate))}}},Y=(r,u={})=>e.getCurrentInstance()?B(r,{...e.inject(_,{}),...u}):B(r,u),D=(r,u={})=>B(r,u);w.FormFieldType=c,w.createForm=X,w.defaultObjectBySchema=W,w.formFactory=D,w.pluginInjectionKey=_,w.useForm=Y,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|
package/dist/src/VvForm.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type IgnoredUpdater } from '@vueuse/core';
|
|
|
3
3
|
import { type z, type TypeOf } from 'zod';
|
|
4
4
|
import type { FormComponentOptions, FormSchema, FormTemplate, InjectedFormData } from './types';
|
|
5
5
|
import { FormStatus } from './enums';
|
|
6
|
-
export declare const defineForm: <Schema extends FormSchema>(schema: Schema, provideKey: InjectionKey<InjectedFormData<Schema>>, options?: FormComponentOptions<Schema
|
|
6
|
+
export declare const defineForm: <Schema extends FormSchema>(schema: Schema, provideKey: InjectionKey<InjectedFormData<Schema>>, options?: FormComponentOptions<Schema>, VvFormTemplate?: Component) => {
|
|
7
7
|
errors: Ref<z.inferFormattedError<Schema, string> | undefined>;
|
|
8
8
|
status: Ref<FormStatus | undefined>;
|
|
9
9
|
invalid: import("vue").ComputedRef<boolean>;
|
|
@@ -17,131 +17,84 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
17
17
|
* An hack to add types to the default slot
|
|
18
18
|
*/
|
|
19
19
|
VvForm: {
|
|
20
|
-
new (...args: any[]): {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
readonly: boolean;
|
|
25
|
-
template: FormTemplate<Schema>;
|
|
26
|
-
modelValue: Record<string, any>;
|
|
27
|
-
continuosValidation: boolean;
|
|
28
|
-
tag: string;
|
|
29
|
-
}> & Omit<{
|
|
30
|
-
readonly readonly: boolean;
|
|
31
|
-
readonly modelValue: Record<string, any>;
|
|
32
|
-
readonly continuosValidation: boolean;
|
|
33
|
-
readonly tag: string;
|
|
34
|
-
readonly template?: FormTemplate<Schema> | undefined;
|
|
35
|
-
onInvalid?: ((...args: any[]) => any) | undefined;
|
|
36
|
-
onValid?: ((...args: any[]) => any) | undefined;
|
|
37
|
-
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
38
|
-
onSubmit?: ((...args: any[]) => any) | undefined;
|
|
39
|
-
"onUpdate:readonly"?: ((...args: any[]) => any) | undefined;
|
|
40
|
-
} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & Readonly<import("vue").ExtractPropTypes<{
|
|
41
|
-
continuosValidation: {
|
|
42
|
-
type: BooleanConstructor;
|
|
43
|
-
default: boolean;
|
|
44
|
-
};
|
|
45
|
-
modelValue: {
|
|
46
|
-
type: ObjectConstructor;
|
|
47
|
-
default: () => {};
|
|
48
|
-
};
|
|
49
|
-
readonly: {
|
|
50
|
-
type: BooleanConstructor;
|
|
51
|
-
default: boolean;
|
|
52
|
-
};
|
|
53
|
-
tag: {
|
|
54
|
-
type: StringConstructor;
|
|
55
|
-
default: string;
|
|
56
|
-
};
|
|
57
|
-
template: {
|
|
58
|
-
type: PropType<FormTemplate<Schema>>;
|
|
59
|
-
default: undefined;
|
|
60
|
-
};
|
|
61
|
-
}>> & {
|
|
62
|
-
onInvalid?: ((...args: any[]) => any) | undefined;
|
|
63
|
-
onValid?: ((...args: any[]) => any) | undefined;
|
|
64
|
-
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
65
|
-
onSubmit?: ((...args: any[]) => any) | undefined;
|
|
66
|
-
"onUpdate:readonly"?: ((...args: any[]) => any) | undefined;
|
|
67
|
-
}, "readonly" | "template" | "modelValue" | "continuosValidation" | "tag">;
|
|
68
|
-
$attrs: {
|
|
69
|
-
[x: string]: unknown;
|
|
20
|
+
new (...args: any[]): import("vue").CreateComponentPublicInstance<Readonly<import("vue").ExtractPropTypes<{
|
|
21
|
+
continuosValidation: {
|
|
22
|
+
type: BooleanConstructor;
|
|
23
|
+
default: boolean;
|
|
70
24
|
};
|
|
71
|
-
|
|
72
|
-
|
|
25
|
+
modelValue: {
|
|
26
|
+
type: ObjectConstructor;
|
|
27
|
+
default: () => {};
|
|
73
28
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
$options: import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
|
|
82
|
-
continuosValidation: {
|
|
83
|
-
type: BooleanConstructor;
|
|
84
|
-
default: boolean;
|
|
85
|
-
};
|
|
86
|
-
modelValue: {
|
|
87
|
-
type: ObjectConstructor;
|
|
88
|
-
default: () => {};
|
|
89
|
-
};
|
|
90
|
-
readonly: {
|
|
91
|
-
type: BooleanConstructor;
|
|
92
|
-
default: boolean;
|
|
93
|
-
};
|
|
94
|
-
tag: {
|
|
95
|
-
type: StringConstructor;
|
|
96
|
-
default: string;
|
|
97
|
-
};
|
|
98
|
-
template: {
|
|
99
|
-
type: PropType<FormTemplate<Schema>>;
|
|
100
|
-
default: undefined;
|
|
101
|
-
};
|
|
102
|
-
}>> & {
|
|
103
|
-
onInvalid?: ((...args: any[]) => any) | undefined;
|
|
104
|
-
onValid?: ((...args: any[]) => any) | undefined;
|
|
105
|
-
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
106
|
-
onSubmit?: ((...args: any[]) => any) | undefined;
|
|
107
|
-
"onUpdate:readonly"?: ((...args: any[]) => any) | undefined;
|
|
108
|
-
}, {
|
|
109
|
-
formData: Ref<Partial<z.TypeOf<Schema> | undefined>>;
|
|
110
|
-
submit: () => Promise<boolean>;
|
|
111
|
-
validate: (value?: Partial<z.TypeOf<Schema> | undefined>) => Promise<boolean>;
|
|
112
|
-
ignoreUpdates: IgnoredUpdater;
|
|
113
|
-
stopUpdatesWatch: WatchStopHandle;
|
|
114
|
-
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>> | undefined>>;
|
|
115
|
-
status: Readonly<Ref<FormStatus | undefined>>;
|
|
116
|
-
invalid: import("vue").ComputedRef<boolean>;
|
|
117
|
-
isReadonly: Ref<boolean>;
|
|
118
|
-
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("invalid" | "valid" | "update:modelValue" | "submit" | "update:readonly")[], string, {
|
|
119
|
-
readonly: boolean;
|
|
120
|
-
template: FormTemplate<Schema>;
|
|
121
|
-
modelValue: Record<string, any>;
|
|
122
|
-
continuosValidation: boolean;
|
|
123
|
-
tag: string;
|
|
124
|
-
}, {}, string, {}> & {
|
|
125
|
-
beforeCreate?: ((() => void) | (() => void)[]) | undefined;
|
|
126
|
-
created?: ((() => void) | (() => void)[]) | undefined;
|
|
127
|
-
beforeMount?: ((() => void) | (() => void)[]) | undefined;
|
|
128
|
-
mounted?: ((() => void) | (() => void)[]) | undefined;
|
|
129
|
-
beforeUpdate?: ((() => void) | (() => void)[]) | undefined;
|
|
130
|
-
updated?: ((() => void) | (() => void)[]) | undefined;
|
|
131
|
-
activated?: ((() => void) | (() => void)[]) | undefined;
|
|
132
|
-
deactivated?: ((() => void) | (() => void)[]) | undefined;
|
|
133
|
-
beforeDestroy?: ((() => void) | (() => void)[]) | undefined;
|
|
134
|
-
beforeUnmount?: ((() => void) | (() => void)[]) | undefined;
|
|
135
|
-
destroyed?: ((() => void) | (() => void)[]) | undefined;
|
|
136
|
-
unmounted?: ((() => void) | (() => void)[]) | undefined;
|
|
137
|
-
renderTracked?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
|
|
138
|
-
renderTriggered?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
|
|
139
|
-
errorCaptured?: (((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}>, {}, {}> | null, info: string) => boolean | void) | ((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}>, {}, {}> | null, info: string) => boolean | void)[]) | undefined;
|
|
29
|
+
readonly: {
|
|
30
|
+
type: BooleanConstructor;
|
|
31
|
+
default: boolean;
|
|
32
|
+
};
|
|
33
|
+
tag: {
|
|
34
|
+
type: StringConstructor;
|
|
35
|
+
default: string;
|
|
140
36
|
};
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
37
|
+
template: {
|
|
38
|
+
type: PropType<FormTemplate<Schema>>;
|
|
39
|
+
default: undefined;
|
|
40
|
+
};
|
|
41
|
+
}>> & {
|
|
42
|
+
onInvalid?: ((...args: any[]) => any) | undefined;
|
|
43
|
+
onValid?: ((...args: any[]) => any) | undefined;
|
|
44
|
+
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
45
|
+
onSubmit?: ((...args: any[]) => any) | undefined;
|
|
46
|
+
"onUpdate:readonly"?: ((...args: any[]) => any) | undefined;
|
|
47
|
+
}, {
|
|
48
|
+
formData: Ref<Partial<z.TypeOf<Schema> | undefined>>;
|
|
49
|
+
submit: () => Promise<boolean>;
|
|
50
|
+
validate: (value?: Partial<z.TypeOf<Schema> | undefined>) => Promise<boolean>;
|
|
51
|
+
ignoreUpdates: IgnoredUpdater;
|
|
52
|
+
stopUpdatesWatch: WatchStopHandle;
|
|
53
|
+
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>> | undefined>>;
|
|
54
|
+
status: Readonly<Ref<FormStatus | undefined>>;
|
|
55
|
+
invalid: import("vue").ComputedRef<boolean>;
|
|
56
|
+
isReadonly: Ref<boolean>;
|
|
57
|
+
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("invalid" | "valid" | "update:modelValue" | "submit" | "update:readonly")[], import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & Readonly<import("vue").ExtractPropTypes<{
|
|
58
|
+
continuosValidation: {
|
|
59
|
+
type: BooleanConstructor;
|
|
60
|
+
default: boolean;
|
|
61
|
+
};
|
|
62
|
+
modelValue: {
|
|
63
|
+
type: ObjectConstructor;
|
|
64
|
+
default: () => {};
|
|
65
|
+
};
|
|
66
|
+
readonly: {
|
|
67
|
+
type: BooleanConstructor;
|
|
68
|
+
default: boolean;
|
|
69
|
+
};
|
|
70
|
+
tag: {
|
|
71
|
+
type: StringConstructor;
|
|
72
|
+
default: string;
|
|
73
|
+
};
|
|
74
|
+
template: {
|
|
75
|
+
type: PropType<FormTemplate<Schema>>;
|
|
76
|
+
default: undefined;
|
|
77
|
+
};
|
|
78
|
+
}>> & {
|
|
79
|
+
onInvalid?: ((...args: any[]) => any) | undefined;
|
|
80
|
+
onValid?: ((...args: any[]) => any) | undefined;
|
|
81
|
+
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
82
|
+
onSubmit?: ((...args: any[]) => any) | undefined;
|
|
83
|
+
"onUpdate:readonly"?: ((...args: any[]) => any) | undefined;
|
|
84
|
+
}, {
|
|
85
|
+
readonly: boolean;
|
|
86
|
+
template: FormTemplate<Schema>;
|
|
87
|
+
modelValue: Record<string, any>;
|
|
88
|
+
continuosValidation: boolean;
|
|
89
|
+
tag: string;
|
|
90
|
+
}, true, {}, {}, {
|
|
91
|
+
P: {};
|
|
92
|
+
B: {};
|
|
93
|
+
D: {};
|
|
94
|
+
C: {};
|
|
95
|
+
M: {};
|
|
96
|
+
Defaults: {};
|
|
97
|
+
}, Readonly<import("vue").ExtractPropTypes<{
|
|
145
98
|
continuosValidation: {
|
|
146
99
|
type: BooleanConstructor;
|
|
147
100
|
default: boolean;
|
|
@@ -168,7 +121,7 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
168
121
|
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
169
122
|
onSubmit?: ((...args: any[]) => any) | undefined;
|
|
170
123
|
"onUpdate:readonly"?: ((...args: any[]) => any) | undefined;
|
|
171
|
-
}
|
|
124
|
+
}, {
|
|
172
125
|
formData: Ref<Partial<z.TypeOf<Schema> | undefined>>;
|
|
173
126
|
submit: () => Promise<boolean>;
|
|
174
127
|
validate: (value?: Partial<z.TypeOf<Schema> | undefined>) => Promise<boolean>;
|
|
@@ -178,7 +131,13 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
178
131
|
status: Readonly<Ref<FormStatus | undefined>>;
|
|
179
132
|
invalid: import("vue").ComputedRef<boolean>;
|
|
180
133
|
isReadonly: Ref<boolean>;
|
|
181
|
-
}
|
|
134
|
+
}, {}, {}, {}, {
|
|
135
|
+
readonly: boolean;
|
|
136
|
+
template: FormTemplate<Schema>;
|
|
137
|
+
modelValue: Record<string, any>;
|
|
138
|
+
continuosValidation: boolean;
|
|
139
|
+
tag: string;
|
|
140
|
+
}>;
|
|
182
141
|
__isFragment?: undefined;
|
|
183
142
|
__isTeleport?: undefined;
|
|
184
143
|
__isSuspense?: undefined;
|
|
@@ -228,12 +187,12 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
228
187
|
}, {}, string, {}> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
|
|
229
188
|
$slots: {
|
|
230
189
|
default: (_: {
|
|
231
|
-
formData: unknown extends Partial<
|
|
190
|
+
formData: unknown extends Partial<TypeOf<Schema>> | undefined ? undefined : Partial<TypeOf<Schema>> | undefined;
|
|
232
191
|
submit: () => Promise<boolean>;
|
|
233
192
|
validate: () => Promise<boolean>;
|
|
234
193
|
ignoreUpdates: IgnoredUpdater;
|
|
235
194
|
stopUpdatesWatch: WatchStopHandle;
|
|
236
|
-
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema
|
|
195
|
+
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema>>>>;
|
|
237
196
|
status: Ref<DeepReadonly<`${FormStatus}` | undefined>>;
|
|
238
197
|
invalid: Ref<DeepReadonly<boolean>>;
|
|
239
198
|
readonly: Ref<boolean>;
|
|
@@ -17,7 +17,7 @@ export declare const defineFormField: <Schema extends FormSchema>(formProvideKey
|
|
|
17
17
|
required: true;
|
|
18
18
|
};
|
|
19
19
|
props: {
|
|
20
|
-
type: PropType<Partial<z.TypeOf<Schema> | ((formData?: Ref<ObjectConstructor>) => Partial<z.
|
|
20
|
+
type: PropType<Partial<z.TypeOf<Schema> | ((formData?: Ref<ObjectConstructor>) => Partial<z.infer<Schema>> | undefined) | undefined>>;
|
|
21
21
|
default: () => {};
|
|
22
22
|
};
|
|
23
23
|
showValid: {
|
|
@@ -60,7 +60,7 @@ export declare const defineFormField: <Schema extends FormSchema>(formProvideKey
|
|
|
60
60
|
'onUpdate:modelValue': (value: unknown) => void;
|
|
61
61
|
}>;
|
|
62
62
|
invalid: import("vue").ComputedRef<boolean>;
|
|
63
|
-
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("invalid" | "valid" | "update:formData" | "update:modelValue")[], "invalid" | "valid" | "update:formData" | "update:modelValue", import("vue").
|
|
63
|
+
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("invalid" | "valid" | "update:formData" | "update:modelValue")[], "invalid" | "valid" | "update:formData" | "update:modelValue", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
64
64
|
type: {
|
|
65
65
|
type: PropType<"number" | "text" | "email" | "password" | "tel" | "url" | "search" | "date" | "time" | "datetime-local" | "month" | "week" | "color" | "select" | "checkbox" | "radio" | "textarea" | "radioGroup" | "checkboxGroup" | "combobox" | "custom">;
|
|
66
66
|
validator: (value: FormFieldType) => boolean;
|
|
@@ -75,7 +75,7 @@ export declare const defineFormField: <Schema extends FormSchema>(formProvideKey
|
|
|
75
75
|
required: true;
|
|
76
76
|
};
|
|
77
77
|
props: {
|
|
78
|
-
type: PropType<Partial<z.TypeOf<Schema> | ((formData?: Ref<ObjectConstructor>) => Partial<z.
|
|
78
|
+
type: PropType<Partial<z.TypeOf<Schema> | ((formData?: Ref<ObjectConstructor>) => Partial<z.infer<Schema>> | undefined) | undefined>>;
|
|
79
79
|
default: () => {};
|
|
80
80
|
};
|
|
81
81
|
showValid: {
|
|
@@ -102,10 +102,10 @@ export declare const defineFormField: <Schema extends FormSchema>(formProvideKey
|
|
|
102
102
|
}, {
|
|
103
103
|
type: "number" | "text" | "email" | "password" | "tel" | "url" | "search" | "date" | "time" | "datetime-local" | "month" | "week" | "color" | "select" | "checkbox" | "radio" | "textarea" | "radioGroup" | "checkboxGroup" | "combobox" | "custom";
|
|
104
104
|
props: [{
|
|
105
|
-
type: PropType<Partial<z.TypeOf<Schema> | ((formData?: Ref<ObjectConstructor>) => Partial<z.
|
|
105
|
+
type: PropType<Partial<z.TypeOf<Schema> | ((formData?: Ref<ObjectConstructor>) => Partial<z.infer<Schema>> | undefined) | undefined>>;
|
|
106
106
|
default: () => {};
|
|
107
107
|
}] extends [import("vue").Prop<infer V, infer D>] ? unknown extends V ? import("@vue/shared").IfAny<V, V, D> : V : {
|
|
108
|
-
type: PropType<Partial<z.TypeOf<Schema> | ((formData?: Ref<ObjectConstructor>) => Partial<z.
|
|
108
|
+
type: PropType<Partial<z.TypeOf<Schema> | ((formData?: Ref<ObjectConstructor>) => Partial<z.infer<Schema>> | undefined) | undefined>>;
|
|
109
109
|
default: () => {};
|
|
110
110
|
};
|
|
111
111
|
is: Component;
|
|
@@ -3,69 +3,37 @@ import type { TypeOf, z } from 'zod';
|
|
|
3
3
|
import type { FormSchema, InjectedFormData, FormTemplate } from './types';
|
|
4
4
|
import type { FormStatus } from './enums';
|
|
5
5
|
export declare const defineFormTemplate: <Schema extends FormSchema>(formProvideKey: InjectionKey<InjectedFormData<Schema>>, VvFormField: Component) => {
|
|
6
|
-
new (...args: any[]): {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
readonly schema: FormTemplate<Schema>;
|
|
11
|
-
} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & Readonly<import("vue").ExtractPropTypes<{
|
|
12
|
-
schema: {
|
|
13
|
-
type: PropType<FormTemplate<Schema>>;
|
|
14
|
-
required: true;
|
|
15
|
-
};
|
|
16
|
-
}>>, never>;
|
|
17
|
-
$attrs: {
|
|
18
|
-
[x: string]: unknown;
|
|
19
|
-
};
|
|
20
|
-
$refs: {
|
|
21
|
-
[x: string]: unknown;
|
|
6
|
+
new (...args: any[]): import("vue").CreateComponentPublicInstance<Readonly<import("vue").ExtractPropTypes<{
|
|
7
|
+
schema: {
|
|
8
|
+
type: PropType<FormTemplate<Schema>>;
|
|
9
|
+
required: true;
|
|
22
10
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
schema: {
|
|
32
|
-
type: PropType<FormTemplate<Schema>>;
|
|
33
|
-
required: true;
|
|
34
|
-
};
|
|
35
|
-
}>>, (() => (VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
36
|
-
[key: string]: any;
|
|
37
|
-
}> | VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
38
|
-
[key: string]: any;
|
|
39
|
-
}>[] | undefined)[]) | undefined, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, {}, {}, string, {}> & {
|
|
40
|
-
beforeCreate?: ((() => void) | (() => void)[]) | undefined;
|
|
41
|
-
created?: ((() => void) | (() => void)[]) | undefined;
|
|
42
|
-
beforeMount?: ((() => void) | (() => void)[]) | undefined;
|
|
43
|
-
mounted?: ((() => void) | (() => void)[]) | undefined;
|
|
44
|
-
beforeUpdate?: ((() => void) | (() => void)[]) | undefined;
|
|
45
|
-
updated?: ((() => void) | (() => void)[]) | undefined;
|
|
46
|
-
activated?: ((() => void) | (() => void)[]) | undefined;
|
|
47
|
-
deactivated?: ((() => void) | (() => void)[]) | undefined;
|
|
48
|
-
beforeDestroy?: ((() => void) | (() => void)[]) | undefined;
|
|
49
|
-
beforeUnmount?: ((() => void) | (() => void)[]) | undefined;
|
|
50
|
-
destroyed?: ((() => void) | (() => void)[]) | undefined;
|
|
51
|
-
unmounted?: ((() => void) | (() => void)[]) | undefined;
|
|
52
|
-
renderTracked?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
|
|
53
|
-
renderTriggered?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
|
|
54
|
-
errorCaptured?: (((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}>, {}, {}> | null, info: string) => boolean | void) | ((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}>, {}, {}> | null, info: string) => boolean | void)[]) | undefined;
|
|
11
|
+
}>>, (() => (VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}> | VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}>[] | undefined)[]) | undefined, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & Readonly<import("vue").ExtractPropTypes<{
|
|
16
|
+
schema: {
|
|
17
|
+
type: PropType<FormTemplate<Schema>>;
|
|
18
|
+
required: true;
|
|
55
19
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
20
|
+
}>>, {}, true, {}, {}, {
|
|
21
|
+
P: {};
|
|
22
|
+
B: {};
|
|
23
|
+
D: {};
|
|
24
|
+
C: {};
|
|
25
|
+
M: {};
|
|
26
|
+
Defaults: {};
|
|
27
|
+
}, Readonly<import("vue").ExtractPropTypes<{
|
|
60
28
|
schema: {
|
|
61
29
|
type: PropType<FormTemplate<Schema>>;
|
|
62
30
|
required: true;
|
|
63
31
|
};
|
|
64
|
-
}
|
|
32
|
+
}>>, {} | (() => (VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
65
33
|
[key: string]: any;
|
|
66
34
|
}> | VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
67
35
|
[key: string]: any;
|
|
68
|
-
}>[] | undefined)[])
|
|
36
|
+
}>[] | undefined)[]), {}, {}, {}, {}>;
|
|
69
37
|
__isFragment?: undefined;
|
|
70
38
|
__isTeleport?: undefined;
|
|
71
39
|
__isSuspense?: undefined;
|
|
@@ -84,7 +52,7 @@ export declare const defineFormTemplate: <Schema extends FormSchema>(formProvide
|
|
|
84
52
|
formData: unknown extends Partial<TypeOf<Schema>> | undefined ? undefined : Partial<TypeOf<Schema>> | undefined;
|
|
85
53
|
submit: () => Promise<boolean>;
|
|
86
54
|
validate: () => Promise<boolean>;
|
|
87
|
-
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema
|
|
55
|
+
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema>>>>;
|
|
88
56
|
status: Ref<DeepReadonly<`${FormStatus}` | undefined>>;
|
|
89
57
|
invalid: Ref<DeepReadonly<boolean>>;
|
|
90
58
|
}) => any;
|