UNPKG

vexip-ui

Version:

A Vue 3 UI library, Highly customizability, full TypeScript, performance pretty good

3 lines (2 loc) 2.47 kB
"use strict";const r=require("vue");require("../row/index.cjs");const u=require("@vexip-ui/config"),S=require("./props.cjs"),o=require("./symbol.cjs"),_=require("../row/row.cjs"),F=r.defineComponent({name:"Form",inheritAttrs:!0,__name:"form",props:S.formProps,setup(v,{expose:A}){const y=v,t=u.useProps("form",y,{method:{default:"post",validator:e=>o.submitMethods.includes(e)},action:null,model:{default:()=>({}),static:!0},rules:()=>({}),labelWidth:"auto",labelAlign:{default:"right",validator:e=>o.labelAligns.includes(e)},allRequired:!1,labelSuffix:"",hideAsterisk:!1,validateAll:!1,hideLabel:!1,disabled:!1,loading:!1,size:u.createSizeProp(),inline:!1,gap:[8,0],justify:"start",align:"top"}),n=u.useNameHelper("form"),l=r.reactive(new Set),E=r.computed(()=>[n.b(),n.bs("vars"),n.bm(`label-${t.labelAlign}`),{[n.bm("inherit")]:t.inherit,[n.bm("disabled")]:t.disabled,[n.bm("loading")]:t.loading,[n.bm(t.size)]:t.size!=="default",[n.bm("inline")]:t.inline}]),M=r.computed(()=>Math.max(...Array.from(l).map(e=>e.labelWidth.value)));r.provide(o.FORM_PROPS,t),r.provide(o.FORM_FIELDS,l),r.provide(o.FORM_ACTIONS,{getLabelWidth:P,validate:c,validateFields:d,reset:h,resetFields:b,clearError:p,clearFieldsError:g}),A({validate:c,validateFields:d,reset:h,resetFields:b,clearError:p,clearFieldsError:g});function P(){return typeof t.labelWidth=="number"?t.labelWidth:M.value}function f(){const e={};for(const i of l)i.prop.value&&(e[i.prop.value]=i);return e}function c(){return m(l)}function d(e){Array.isArray(e)||(e=[e]);const i=f(),a=new Set;return e.forEach(s=>{i[s]&&a.add(i[s])}),m(a)}function m(e){const i=[];return e.forEach(a=>{i.push(a.validate())}),new Promise(a=>{Promise.all(i).then(s=>{a(s.flat().filter(Boolean))})})}function h(){l.forEach(e=>{e.reset()})}function b(e){Array.isArray(e)||(e=[e]);const i=f();e.forEach(a=>{i[a]&&i[a].reset()})}function p(){l.forEach(e=>{e.clearError()})}function g(e){Array.isArray(e)||(e=[e]);const i=f();e.forEach(a=>{i[a]&&i[a].clearError()})}return(e,i)=>(r.openBlock(),r.createBlock(r.unref(_),r.mergeProps(e.$attrs,{class:E.value,inherit:r.unref(t).inherit,tag:"form",method:r.unref(t).action&&r.unref(t).method,action:r.unref(t).action,gap:r.unref(t).gap,justify:r.unref(t).justify,align:r.unref(t).align,"column-flex":void 0}),{default:r.withCtx(()=>[r.renderSlot(e.$slots,"default")]),_:3},16,["class","inherit","method","action","gap","justify","align"]))}});module.exports=F; //# sourceMappingURL=form.vue2.cjs.map