@volverjs/form-vue 1.0.0-beta.6 → 1.0.0-beta.8
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.es.js +312 -271
- package/dist/index.umd.js +1 -1
- package/dist/src/VvForm.d.ts +99 -110
- package/dist/src/VvFormField.d.ts +11 -1
- package/dist/src/VvFormTemplate.d.ts +22 -54
- package/dist/src/VvFormWrapper.d.ts +45 -80
- package/dist/src/index.d.ts +569 -773
- package/dist/src/types.d.ts +2 -0
- package/package.json +22 -22
- package/src/VvForm.ts +56 -7
- package/src/VvFormField.ts +14 -0
- package/src/index.ts +2 -0
- package/src/types.ts +12 -10
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,B,k){"use strict";function R(e){return Array.isArray(e)}function J(e){return typeof e<"u"}function G(e){return e===null}function L(e){return typeof e=="object"}function Z(e){return typeof e=="string"}function A(e){return typeof e>"u"}const M=/^[0-9]+$/,P=["__proto__","prototype","constructor"];function E(e,u,a){const d=J(a)?a:void 0;if(!L(e)||!Z(u))return d;const i=q(u);if(i.length!==0){for(const t of i){if(t==="*")continue;const s=function(n){return n.map(f=>A(f)||G(f)?f:R(f)?s(f):f[t])};if(R(e)&&!M.test(t)?e=s(e):e=e[t],A(e)||G(e))break}return A(e)?d:e}}function K(e,u,a){if(!L(e)||!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){e[s]=a;return}if(s==="*"&&R(e)){const n=d.slice(t+1).join(".");for(const f of e)K(f,n,a);return}A(e[s])&&(e[s]={}),e=e[s]}}function q(e){const u=e.split(/[.]|(?:\[(\d|\*)\])/).filter(a=>!!a);return u.some(a=>P.indexOf(a)!==-1)?[]:u}var c=(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))(c||{}),w=(e=>(e.invalid="invalid",e.valid="valid",e.submitting="submitting",e.updated="updated",e.unknown="unknown",e))(w||{});const z=(e,u,a,d)=>r.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}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(i,{slots:t,emit:s}){const n=r.computed({get(){if(l!=null&&l.formData)return E(Object(l.formData.value),String(i.name))},set(o){l!=null&&l.formData&&(K(Object(l.formData.value),String(i.name),o),s("update:modelValue",{newValue:n.value,formData:l==null?void 0:l.formData}))}});r.onMounted(()=>{n.value===void 0&&i.defaultValue!==void 0&&(n.value=i.defaultValue)}),r.onBeforeUnmount(()=>{b(),V()});const f=r.inject(u,void 0);f&&f.fields.value.add(i.name);const l=r.inject(e),{props:v,name:y}=r.toRefs(i),g=r.computed(()=>{if(l!=null&&l.errors.value)return E(l.errors.value,String(i.name))}),h=r.computed(()=>{var o;return(o=g.value)==null?void 0:o._errors}),m=r.computed(()=>g.value!==void 0),b=r.watch(m,()=>{m.value?(s("invalid",h.value),f&&f.errors.value.set(i.name,{_errors:h.value})):(s("valid",n.value),f&&f.errors.value.delete(i.name))}),V=r.watch(()=>l==null?void 0:l.formData,()=>{s("update:formData",l==null?void 0:l.formData)},{deep:!0}),x=o=>{n.value=o},O=r.computed(()=>{let o=v.value;return typeof o=="function"&&(o=o(l==null?void 0:l.formData)),Object.keys(o).reduce((I,U)=>(I[U]=r.unref(o[U]),I),{})}),S=r.computed(()=>({...O.value,name:O.value.name??i.name,invalid:m.value,valid:i.showValid?!!(!m.value&&n.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:h.value,modelValue:n.value,"onUpdate:modelValue":x}));return r.provide(a,{name:r.readonly(y),errors:r.readonly(g)}),{component:r.computed(()=>{if(i.type===c.custom)return{render(){var o;return((o=t.default)==null?void 0:o.call(t,{modelValue:n.value,onUpdate:x,submit:l==null?void 0:l.submit,validate:l==null?void 0:l.validate,invalid:m.value,invalidLabel:h.value,formData:l==null?void 0:l.formData.value,formErrors:l==null?void 0:l.errors.value,errors:g.value}))??t.defalut}};if(!((d==null?void 0:d.lazyLoad)??i.lazyLoad)){let o;switch(i.type){case c.select:o=r.resolveComponent("VvSelect");break;case c.checkbox:o=r.resolveComponent("VvCheckbox");break;case c.radio:o=r.resolveComponent("VvRadio");break;case c.textarea:o=r.resolveComponent("VvTextarea");break;case c.radioGroup:o=r.resolveComponent("VvRadioGroup");break;case c.checkboxGroup:o=r.resolveComponent("VvCheckboxGroup");break;case c.combobox:o=r.resolveComponent("VvCombobox");break;default:o=r.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 r.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:S,invalid:m}},render(){return this.is?r.h(this.is,this.hasProps,this.$slots):this.type===c.custom?r.h(this.component,null,this.$slots):r.h(this.component,this.hasProps,this.$slots)}}),W=(e,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(e);return{...(d instanceof k.ZodObject?d._def.unknownKeys==="passthrough":!1)?u:{},...Object.fromEntries(Object.entries(d.shape).map(([t,s])=>{const n=u[t];let f=a(s),l;if(f instanceof k.ZodDefault&&(l=f._def.defaultValue(),f=f._def.innerType),n===null&&f instanceof k.ZodNullable)return[t,n];if(f instanceof k.ZodSchema){const v=s.safeParse(n);if(v.success)return[t,v.data??l]}if(f instanceof k.ZodArray&&Array.isArray(n)&&n.length){const v=a(f._def.type);if(v instanceof k.ZodObject)return[t,n.map(y=>W(v,y&&typeof y=="object"?y:void 0))??l]}return f instanceof k.ZodObject?[t,W(f,n&&typeof n=="object"?n:l)]:[t,l]}))}},T=(e,u,a,d)=>{const i=r.ref(),t=r.ref(),s=r.computed(()=>t.value===w.invalid),n=r.ref(),f=async(h=n.value)=>{const m=await e.safeParseAsync(h);return m.success?(i.value=void 0,t.value=w.valid,n.value=m.data,!0):(i.value=m.error.format(),t.value=w.invalid,!1)},l=async()=>await f()?(t.value=w.submitting,!0):!1,{ignoreUpdates:v,stop:y}=B.watchIgnorable(n,()=>{t.value=w.updated},{deep:!0,eventFilter:B.throttleFilter((a==null?void 0:a.updateThrottle)??500)}),g=r.defineComponent({name:"VvForm",props:{continuosValidation:{type:Boolean,default:!1},modelValue:{type:Object,default:()=>({})},tag:{type:String,default:"form"},template:{type:[Array,Function],default:void 0}},emits:["invalid","valid","submit","update:modelValue"],expose:["submit","validate","errors","status","valid","invalid"],setup(h,{emit:m}){return n.value=W(e,r.toRaw(h.modelValue)),r.watch(()=>h.modelValue,b=>{if(b){const V=r.isProxy(b)?r.toRaw(b):b;if(JSON.stringify(V)===JSON.stringify(r.toRaw(n.value)))return;n.value=typeof(V==null?void 0:V.clone)=="function"?V.clone():JSON.parse(JSON.stringify(V))}},{deep:!0}),r.watch(t,async b=>{var V,x,O,S,C;if(b===w.invalid){const o=r.toRaw(i.value);m("invalid",o),(V=a==null?void 0:a.onInvalid)==null||V.call(a,o);return}if(b===w.valid){const o=r.toRaw(n.value);m("valid",o),(x=a==null?void 0:a.onValid)==null||x.call(a,o),m("update:modelValue",o),(O=a==null?void 0:a.onUpdate)==null||O.call(a,o);return}if(b===w.submitting){const o=r.toRaw(n.value);m("submit",o),(S=a==null?void 0:a.onSubmit)==null||S.call(a,o)}if(b===w.updated){if((i.value||a!=null&&a.continuosValidation||h.continuosValidation)&&await f(),!n.value||!h.modelValue||JSON.stringify(n.value)!==JSON.stringify(h.modelValue)){const o=r.toRaw(n.value);m("update:modelValue",o),(C=a==null?void 0:a.onUpdate)==null||C.call(a,o)}t.value===w.updated&&(t.value=w.unknown)}}),r.provide(u,{formData:n,submit:l,validate:f,ignoreUpdates:v,stopUpdatesWatch:y,errors:r.readonly(i),status:r.readonly(t),invalid:s}),{formData:n,submit:l,validate:f,ignoreUpdates:v,stopUpdatesWatch:y,errors:r.readonly(i),status:r.readonly(t),invalid:s}},render(){const h=()=>{var m,b;return((b=(m=this.$slots)==null?void 0:m.default)==null?void 0:b.call(m,{formData:this.formData,submit:this.submit,validate:this.validate,ignoreUpdates:this.ignoreUpdates,stopUpdatesWatch:this.stopUpdatesWatch,errors:this.errors,status:this.status,invalid:this.invalid}))??this.$slots.default};return r.h(this.tag,{onSubmit:r.withModifiers(this.submit,["prevent"])},(this.template??(a==null?void 0:a.template))&&d?[r.h(d,{schema:this.template??(a==null?void 0:a.template)},{default:h})]:{default:h})}});return{errors:i,status:t,invalid:s,formData:n,validate:f,submit:l,ignoreUpdates:v,stopUpdatesWatch:y,VvForm:g}},H=(e,u)=>r.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=r.inject(e),s=r.inject(u,void 0),n=r.ref(new Set),f=r.ref(new Map),{name:l}=r.toRefs(d);r.provide(u,{name:r.readonly(l),errors:f,fields:n}),r.watch(n,y=>{s!=null&&s.fields&&y.forEach(g=>{s==null||s.fields.value.add(g)})},{deep:!0}),r.watch(()=>new Map(f.value),(y,g)=>{s!=null&&s.errors&&(Array.from(g.keys()).forEach(h=>{s.errors.value.delete(h)}),Array.from(y.keys()).forEach(h=>{const m=y.get(h);m&&s.errors.value.set(h,m)}))},{deep:!0});const v=r.computed(()=>t!=null&&t.invalid.value?f.value.size>0:!1);return r.watch(v,()=>{v.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:v,fields:n,fieldsErrors:f}},render(){var d,i;return this.tag?r.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=(e,u)=>{const a=r.defineComponent({name:"VvFormTemplate",props:{schema:{type:[Array,Function],required:!0}},setup(d,{slots:i}){const t=r.inject(e);if(t!=null&&t.formData)return()=>{var l;const s=typeof d.schema=="function"?d.schema(t):d.schema;let n;const f=s.reduce((v,y)=>{const g=typeof y=="function"?y(t):y,{vvIs:h,vvName:m,vvSlots:b,vvChildren:V,vvIf:x,vvElseIf:O,vvType:S,vvDefaultValue:C,vvShowValid:o,vvContent:I,...U}=g;if(x!==void 0){if(typeof x=="string"?n=!!E(Object(t.formData.value),x):typeof x=="function"?n=r.unref(x(t)):n=r.unref(x),!n)return v}else if(O!==void 0&&n!==void 0){if(n||(typeof O=="string"?n=!!E(Object(t.formData.value),O):typeof O=="function"?n=r.unref(O(t)):n=r.unref(O),!n))return v}else n=void 0;const $=V?r.h(a,{schema:V}):void 0;return m?(v.push(r.h(u,{name:m,is:h,type:S,defaultValue:C,showValid:o,props:U},b??$??I)),v):h?(v.push(r.h(h,U,b??$??I)),v):(V&&v.push($),v)},[]);return f.push((l=i==null?void 0:i.default)==null?void 0:l.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},N=(e,u={})=>{const a=Symbol(),d=Symbol(),i=Symbol(),t=H(a,d),s=z(a,d,i,u),n=Q(a,s),{VvForm:f,errors:l,status:v,invalid:y,formData:g,validate:h,submit:m,ignoreUpdates:b,stopUpdatesWatch:V}=T(e,a,u,n);return{VvForm:f,VvFormWrapper:t,VvFormField:s,VvFormTemplate:n,formInjectionKey:a,formWrapperInjectionKey:d,formFieldInjectionKey:i,errors:l,status:v,invalid:y,formData:g,validate:h,submit:m,ignoreUpdates:b,stopUpdatesWatch:V}},_=Symbol(),X=e=>{let u={};return e.schema&&(u=N(e.schema,e)),{...u,install(a,{global:d=!1}={}){a.provide(_,e),d&&(a.config.globalProperties.$vvForm=e,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=(e,u={})=>r.getCurrentInstance()?N(e,{...r.inject(_,{}),...u}):N(e,u),D=(e,u={})=>N(e,u);p.FormFieldType=c,p.createForm=X,p.defaultObjectBySchema=W,p.formFactory=D,p.pluginInjectionKey=_,p.useForm=Y,Object.defineProperty(p,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(o=>A(o)||G(o)?o:N(o)?s(o):o[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 o of r)K(o,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(f){n!=null&&n.formData&&(K(Object(n.formData.value),String(i.name),f),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 o=e.inject(u,void 0);o&&o.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 f;return(f=p.value)==null?void 0:f._errors}),v=e.computed(()=>p.value!==void 0),y=e.watch(v,()=>{v.value?(s("invalid",g.value),o&&o.errors.value.set(i.name,{_errors:g.value})):(s("valid",l.value),o&&o.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=f=>{l.value=f},x=e.computed(()=>{let f=m.value;return typeof f=="function"&&(f=f(n==null?void 0:n.formData)),Object.keys(f).reduce((U,I)=>(U[I]=e.unref(f[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:(f=>{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(f))return f})(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 f;return((f=t.default)==null?void 0:f.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 f;switch(i.type){case c.select:f=e.resolveComponent("VvSelect");break;case c.checkbox:f=e.resolveComponent("VvCheckbox");break;case c.radio:f=e.resolveComponent("VvRadio");break;case c.textarea:f=e.resolveComponent("VvTextarea");break;case c.radioGroup:f=e.resolveComponent("VvRadioGroup");break;case c.checkboxGroup:f=e.resolveComponent("VvCheckboxGroup");break;case c.combobox:f=e.resolveComponent("VvCombobox");break;default:f=e.resolveComponent("VvInputText")}if(typeof f!="string")return f;console.warn(`[form-vue warn]: ${f} 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 o=a(s),n;if(o instanceof k.ZodDefault&&(n=o._def.defaultValue(),o=o._def.innerType),l===null&&o instanceof k.ZodNullable)return[t,l];if(o instanceof k.ZodSchema){const m=s.safeParse(l);if(m.success)return[t,m.data??n]}if(o instanceof k.ZodArray&&Array.isArray(l)&&l.length){const m=a(o._def.type);if(m instanceof k.ZodObject)return[t,l.map(V=>W(m,V&&typeof V=="object"?V:void 0))??n]}return o instanceof k.ZodObject?[t,W(o,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(),o=e.ref(!1),n=async(v=l.value)=>{if(o.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()=>o.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 f=e.toRaw(i.value);y("invalid",f),(b=a==null?void 0:a.onInvalid)==null||b.call(a,f);return}if(h===O.valid){const f=e.toRaw(l.value);y("valid",f),(x=a==null?void 0:a.onValid)==null||x.call(a,f),y("update:modelValue",f),(S=a==null?void 0:a.onUpdate)==null||S.call(a,f);return}if(h===O.submitting){const f=e.toRaw(l.value);y("submit",f),(C=a==null?void 0:a.onSubmit)==null||C.call(a,f)}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 f=e.toRaw(l.value);y("update:modelValue",f),(R=a==null?void 0:a.onUpdate)==null||R.call(a,f)}t.value===O.updated&&(t.value=O.unknown)}}),e.onMounted(()=>{v.readonly&&!o.value&&(o.value=v.readonly)}),e.watch(()=>v.readonly,h=>{o.value=h}),e.watch(o,h=>{h!==v.readonly&&y("update:readonly",o.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:o}),{formData:l,submit:m,validate:n,ignoreUpdates:V,stopUpdatesWatch:p,errors:e.readonly(i),status:e.readonly(t),invalid:s,isReadonly:o}},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:o,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),o=e.ref(new Map),{name:n}=e.toRefs(d);e.provide(u,{name:e.readonly(n),errors:o,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(o.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?o.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:o}},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 o=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:f,...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??f)),m):g?(m.push(e.h(g,U,y??I??f)),m):(h&&m.push(I),m)},[]);return o.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})),o}}});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:o,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:o,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
|
@@ -7,6 +7,7 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
7
7
|
errors: Ref<z.inferFormattedError<Schema, string> | undefined>;
|
|
8
8
|
status: Ref<FormStatus | undefined>;
|
|
9
9
|
invalid: import("vue").ComputedRef<boolean>;
|
|
10
|
+
readonly: Ref<boolean>;
|
|
10
11
|
formData: Ref<Partial<z.TypeOf<Schema> | undefined>>;
|
|
11
12
|
validate: (value?: Partial<z.TypeOf<Schema> | undefined>) => Promise<boolean>;
|
|
12
13
|
submit: () => Promise<boolean>;
|
|
@@ -16,116 +17,84 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
16
17
|
* An hack to add types to the default slot
|
|
17
18
|
*/
|
|
18
19
|
VvForm: {
|
|
19
|
-
new (...args: any[]): {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
template: FormTemplate<Schema>;
|
|
24
|
-
modelValue: Record<string, any>;
|
|
25
|
-
continuosValidation: boolean;
|
|
26
|
-
tag: string;
|
|
27
|
-
}> & Omit<{
|
|
28
|
-
readonly modelValue: Record<string, any>;
|
|
29
|
-
readonly continuosValidation: boolean;
|
|
30
|
-
readonly tag: string;
|
|
31
|
-
readonly template?: FormTemplate<Schema> | undefined;
|
|
32
|
-
onInvalid?: ((...args: any[]) => any) | undefined;
|
|
33
|
-
onValid?: ((...args: any[]) => any) | undefined;
|
|
34
|
-
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
35
|
-
onSubmit?: ((...args: any[]) => any) | undefined;
|
|
36
|
-
} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & Readonly<import("vue").ExtractPropTypes<{
|
|
37
|
-
continuosValidation: {
|
|
38
|
-
type: BooleanConstructor;
|
|
39
|
-
default: boolean;
|
|
40
|
-
};
|
|
41
|
-
modelValue: {
|
|
42
|
-
type: ObjectConstructor;
|
|
43
|
-
default: () => {};
|
|
44
|
-
};
|
|
45
|
-
tag: {
|
|
46
|
-
type: StringConstructor;
|
|
47
|
-
default: string;
|
|
48
|
-
};
|
|
49
|
-
template: {
|
|
50
|
-
type: PropType<FormTemplate<Schema>>;
|
|
51
|
-
default: undefined;
|
|
52
|
-
};
|
|
53
|
-
}>> & {
|
|
54
|
-
onInvalid?: ((...args: any[]) => any) | undefined;
|
|
55
|
-
onValid?: ((...args: any[]) => any) | undefined;
|
|
56
|
-
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
57
|
-
onSubmit?: ((...args: any[]) => any) | undefined;
|
|
58
|
-
}, "template" | "modelValue" | "continuosValidation" | "tag">;
|
|
59
|
-
$attrs: {
|
|
60
|
-
[x: string]: unknown;
|
|
20
|
+
new (...args: any[]): import("vue").CreateComponentPublicInstance<Readonly<import("vue").ExtractPropTypes<{
|
|
21
|
+
continuosValidation: {
|
|
22
|
+
type: BooleanConstructor;
|
|
23
|
+
default: boolean;
|
|
61
24
|
};
|
|
62
|
-
|
|
63
|
-
|
|
25
|
+
modelValue: {
|
|
26
|
+
type: ObjectConstructor;
|
|
27
|
+
default: () => {};
|
|
64
28
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
beforeCreate?: ((() => void) | (() => void)[]) | undefined;
|
|
110
|
-
created?: ((() => void) | (() => void)[]) | undefined;
|
|
111
|
-
beforeMount?: ((() => void) | (() => void)[]) | undefined;
|
|
112
|
-
mounted?: ((() => void) | (() => void)[]) | undefined;
|
|
113
|
-
beforeUpdate?: ((() => void) | (() => void)[]) | undefined;
|
|
114
|
-
updated?: ((() => void) | (() => void)[]) | undefined;
|
|
115
|
-
activated?: ((() => void) | (() => void)[]) | undefined;
|
|
116
|
-
deactivated?: ((() => void) | (() => void)[]) | undefined;
|
|
117
|
-
beforeDestroy?: ((() => void) | (() => void)[]) | undefined;
|
|
118
|
-
beforeUnmount?: ((() => void) | (() => void)[]) | undefined;
|
|
119
|
-
destroyed?: ((() => void) | (() => void)[]) | undefined;
|
|
120
|
-
unmounted?: ((() => void) | (() => void)[]) | undefined;
|
|
121
|
-
renderTracked?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
|
|
122
|
-
renderTriggered?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
|
|
123
|
-
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;
|
|
36
|
+
};
|
|
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;
|
|
124
73
|
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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<{
|
|
129
98
|
continuosValidation: {
|
|
130
99
|
type: BooleanConstructor;
|
|
131
100
|
default: boolean;
|
|
@@ -134,6 +103,10 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
134
103
|
type: ObjectConstructor;
|
|
135
104
|
default: () => {};
|
|
136
105
|
};
|
|
106
|
+
readonly: {
|
|
107
|
+
type: BooleanConstructor;
|
|
108
|
+
default: boolean;
|
|
109
|
+
};
|
|
137
110
|
tag: {
|
|
138
111
|
type: StringConstructor;
|
|
139
112
|
default: string;
|
|
@@ -147,7 +120,8 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
147
120
|
onValid?: ((...args: any[]) => any) | undefined;
|
|
148
121
|
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
149
122
|
onSubmit?: ((...args: any[]) => any) | undefined;
|
|
150
|
-
|
|
123
|
+
"onUpdate:readonly"?: ((...args: any[]) => any) | undefined;
|
|
124
|
+
}, {
|
|
151
125
|
formData: Ref<Partial<z.TypeOf<Schema> | undefined>>;
|
|
152
126
|
submit: () => Promise<boolean>;
|
|
153
127
|
validate: (value?: Partial<z.TypeOf<Schema> | undefined>) => Promise<boolean>;
|
|
@@ -156,7 +130,14 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
156
130
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>> | undefined>>;
|
|
157
131
|
status: Readonly<Ref<FormStatus | undefined>>;
|
|
158
132
|
invalid: import("vue").ComputedRef<boolean>;
|
|
159
|
-
|
|
133
|
+
isReadonly: Ref<boolean>;
|
|
134
|
+
}, {}, {}, {}, {
|
|
135
|
+
readonly: boolean;
|
|
136
|
+
template: FormTemplate<Schema>;
|
|
137
|
+
modelValue: Record<string, any>;
|
|
138
|
+
continuosValidation: boolean;
|
|
139
|
+
tag: string;
|
|
140
|
+
}>;
|
|
160
141
|
__isFragment?: undefined;
|
|
161
142
|
__isTeleport?: undefined;
|
|
162
143
|
__isSuspense?: undefined;
|
|
@@ -169,6 +150,10 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
169
150
|
type: ObjectConstructor;
|
|
170
151
|
default: () => {};
|
|
171
152
|
};
|
|
153
|
+
readonly: {
|
|
154
|
+
type: BooleanConstructor;
|
|
155
|
+
default: boolean;
|
|
156
|
+
};
|
|
172
157
|
tag: {
|
|
173
158
|
type: StringConstructor;
|
|
174
159
|
default: string;
|
|
@@ -182,6 +167,7 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
182
167
|
onValid?: ((...args: any[]) => any) | undefined;
|
|
183
168
|
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
184
169
|
onSubmit?: ((...args: any[]) => any) | undefined;
|
|
170
|
+
"onUpdate:readonly"?: ((...args: any[]) => any) | undefined;
|
|
185
171
|
}, {
|
|
186
172
|
formData: Ref<Partial<z.TypeOf<Schema> | undefined>>;
|
|
187
173
|
submit: () => Promise<boolean>;
|
|
@@ -191,7 +177,9 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
191
177
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>> | undefined>>;
|
|
192
178
|
status: Readonly<Ref<FormStatus | undefined>>;
|
|
193
179
|
invalid: import("vue").ComputedRef<boolean>;
|
|
194
|
-
|
|
180
|
+
isReadonly: Ref<boolean>;
|
|
181
|
+
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("invalid" | "valid" | "update:modelValue" | "submit" | "update:readonly")[], "invalid" | "valid" | "update:modelValue" | "submit" | "update:readonly", {
|
|
182
|
+
readonly: boolean;
|
|
195
183
|
template: FormTemplate<Schema>;
|
|
196
184
|
modelValue: Record<string, any>;
|
|
197
185
|
continuosValidation: boolean;
|
|
@@ -207,6 +195,7 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
207
195
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>>>>;
|
|
208
196
|
status: Ref<DeepReadonly<`${FormStatus}` | undefined>>;
|
|
209
197
|
invalid: Ref<DeepReadonly<boolean>>;
|
|
198
|
+
readonly: Ref<boolean>;
|
|
210
199
|
}) => any;
|
|
211
200
|
};
|
|
212
201
|
});
|
|
@@ -32,6 +32,10 @@ export declare const defineFormField: <Schema extends FormSchema>(formProvideKey
|
|
|
32
32
|
type: BooleanConstructor;
|
|
33
33
|
default: boolean;
|
|
34
34
|
};
|
|
35
|
+
readonly: {
|
|
36
|
+
type: BooleanConstructor;
|
|
37
|
+
default: undefined;
|
|
38
|
+
};
|
|
35
39
|
}, {
|
|
36
40
|
component: import("vue").ComputedRef<{
|
|
37
41
|
new (...args: any[]): any;
|
|
@@ -52,10 +56,11 @@ export declare const defineFormField: <Schema extends FormSchema>(formProvideKey
|
|
|
52
56
|
type: FormFieldType | undefined;
|
|
53
57
|
invalidLabel: any;
|
|
54
58
|
modelValue: any;
|
|
59
|
+
readonly: {} | undefined;
|
|
55
60
|
'onUpdate:modelValue': (value: unknown) => void;
|
|
56
61
|
}>;
|
|
57
62
|
invalid: import("vue").ComputedRef<boolean>;
|
|
58
|
-
}, 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<{
|
|
59
64
|
type: {
|
|
60
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">;
|
|
61
66
|
validator: (value: FormFieldType) => boolean;
|
|
@@ -85,6 +90,10 @@ export declare const defineFormField: <Schema extends FormSchema>(formProvideKey
|
|
|
85
90
|
type: BooleanConstructor;
|
|
86
91
|
default: boolean;
|
|
87
92
|
};
|
|
93
|
+
readonly: {
|
|
94
|
+
type: BooleanConstructor;
|
|
95
|
+
default: undefined;
|
|
96
|
+
};
|
|
88
97
|
}>> & {
|
|
89
98
|
onInvalid?: ((...args: any[]) => any) | undefined;
|
|
90
99
|
onValid?: ((...args: any[]) => any) | undefined;
|
|
@@ -103,4 +112,5 @@ export declare const defineFormField: <Schema extends FormSchema>(formProvideKey
|
|
|
103
112
|
showValid: boolean;
|
|
104
113
|
defaultValue: string | number | boolean | unknown[] | Record<string, any>;
|
|
105
114
|
lazyLoad: boolean;
|
|
115
|
+
readonly: boolean;
|
|
106
116
|
}, {}>;
|
|
@@ -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;
|