@moonmangit/vue-autoform 0.1.6 → 0.1.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/dist/style.css +1 -1
- package/dist/vue-autoform.cjs.js +4 -4
- package/dist/vue-autoform.cjs.js.map +1 -1
- package/dist/vue-autoform.d.ts +1 -61
- package/dist/vue-autoform.es.js +135 -240
- package/dist/vue-autoform.es.js.map +1 -1
- package/package.json +1 -1
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.autoform{width:100
|
|
1
|
+
.autoform{width:100%}.autoform-flat-grid{display:grid;grid-template-columns:repeat(1,minmax(0,1fr));column-gap:var(--autoform-gap, 1rem);row-gap:var(--autoform-row-gap, 1rem);width:100%}.autoform-flat-grid .autoform-cell{min-width:0}.autoform-default-input{width:100%;padding:.5rem .75rem;border:1px solid #d1d5db;border-radius:.375rem;font-size:1rem;outline:none;box-sizing:border-box}.autoform-default-input:focus{border-color:#6366f1;box-shadow:0 0 0 2px #6366f133}
|
package/dist/vue-autoform.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue")
|
|
2
|
-
`):
|
|
3
|
-
`)};t.push(
|
|
4
|
-
`)});return v({validateAll:
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue");function j(a,v,F,n){const d=e.reactive({}),$=e.computed(()=>Object.keys(a.shape));function m(o,s){var t;const i=a.shape;if(!(o in i))return;const u=i[o].safeParse(s);if(!u.success)return((t=u.error.errors[0])==null?void 0:t.message)??"Invalid value"}function E(){const o=a.safeParse(v.value);return o.success?(Object.keys(d).forEach(s=>delete d[s]),!0):(o.error.errors.forEach(s=>{const i=String(s.path[0]);d[i]=s.message}),!1)}const p={};function g(o,s){p[o]=s;const i={...v.value,[o]:s};if(F("update:modelValue",i),n.value==="input"){const r=m(o,s);r?d[o]=r:delete d[o]}}function V(o){if(n.value==="blur"){const s=o in p?p[o]:v.value[o],i=m(o,s);i?d[o]=i:delete d[o]}}return{errors:d,schemaKeys:$,onFieldInput:g,onFieldBlur:V,validateAll:E}}const C={sm:640,md:768,lg:1024,xl:1280,"2xl":1536};function O(a){return typeof a.default=="number"}function x(a){return Array.isArray(a.default)}const N=["data-autoform-id"],w={class:"autoform-flat-grid"},D=["data-field-key"],R=["value","onInput","onBlur"],U=e.defineComponent({__name:"AutoForm",props:{schema:{},layout:{},fields:{},modelValue:{},validateOn:{default:"blur"},breakpoints:{}},emits:["update:modelValue"],setup(a,{expose:v,emit:F}){const n=a,d=F,$=e.ref(`autoform-${Math.random().toString(36).slice(2,9)}`),{errors:m,schemaKeys:E,onFieldInput:p,onFieldBlur:g,validateAll:V}=j(n.schema,e.toRef(n,"modelValue"),(r,u)=>d(r,u),e.toRef(n,"validateOn")),o=e.computed(()=>n.layout?x(n.layout):!0);function s(r){const u=n.fields[r];if(!u)return{};const t=u.props;return typeof t=="function"?t():t??{}}const i=e.computed(()=>{if(!n.layout)return"";const r={...C,...n.breakpoints},u=$.value,t=[];if(O(n.layout)){const l=n.layout;t.push(`[data-autoform-id="${u}"] .autoform-flat-grid {`,` grid-template-columns: repeat(${l.default}, minmax(0, 1fr));`,"}");const S=Object.keys(l).filter(B=>B!=="default");for(const B of S){const b=r[B],c=l[B];b&&c&&t.push(`@media (min-width: ${b}px) {`,` [data-autoform-id="${u}"] .autoform-flat-grid {`,` grid-template-columns: repeat(${c}, minmax(0, 1fr));`," }","}")}}else if(x(n.layout)){const l=n.layout,S=(c,h)=>{const y=Math.max(...c.map(f=>f.length)),L=E.value,P=new Set(c.flat()),k=[];k.push(`[data-autoform-id="${u}"] .autoform-flat-grid { grid-template-columns: repeat(${y}, minmax(0, 1fr)); }`),L.forEach(f=>{P.has(f)||k.push(`[data-autoform-id="${u}"] [data-field-key="${f}"] { display: none; }`)});let A=1;return c.forEach(f=>{let I=1;f.forEach(T=>{k.push(`[data-autoform-id="${u}"] [data-field-key="${T}"] { display: block; grid-row: ${A}; grid-column: ${I}; }`),I++}),A++}),h?[`@media (min-width: ${h}px) {`,...k.map(f=>` ${f}`),"}"].join(`
|
|
2
|
+
`):k.join(`
|
|
3
|
+
`)};t.push(S(l.default));const b=Object.keys(l).filter(c=>c!=="default").sort((c,h)=>(r[c]??0)-(r[h]??0));for(const c of b){const h=r[c],y=l[c];h&&y&&t.push(S(y,String(h)))}}return t.join(`
|
|
4
|
+
`)});return v({validateAll:V,errors:m}),(r,u)=>(e.openBlock(),e.createElementBlock("div",{class:"autoform","data-autoform-id":$.value},[i.value?(e.openBlock(),e.createBlock(e.resolveDynamicComponent("style"),{key:0},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(i.value),1)]),_:1})):e.createCommentVNode("",!0),e.createElementVNode("div",w,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(E),t=>(e.openBlock(),e.createElementBlock("div",{key:t,class:"autoform-cell","data-field-key":o.value?t:void 0},[a.fields[t]?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(a.fields[t].component),e.mergeProps({modelValue:a.modelValue[t],error:e.unref(m)[t]},{ref_for:!0},s(t),{"onUpdate:modelValue":l=>e.unref(p)(t,l),onBlur:()=>e.unref(g)(t)}),null,16,["modelValue","error","onUpdate:modelValue","onBlur"])),e.renderSlot(r.$slots,"error",{fieldKey:t,error:e.unref(m)[t]})],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.renderSlot(r.$slots,`field-${t}`,{fieldKey:t,value:a.modelValue[t],error:e.unref(m)[t],onUpdate:l=>e.unref(p)(t,l),onBlur:()=>e.unref(g)(t)},()=>[e.createElementVNode("input",{class:"autoform-default-input",value:String(a.modelValue[t]??""),onInput:l=>e.unref(p)(t,l.target.value),onBlur:()=>e.unref(g)(t)},null,40,R)]),e.renderSlot(r.$slots,"error",{fieldKey:t,error:e.unref(m)[t]})],64))],8,D))),128))])],8,N))}});exports.AutoForm=U;exports.DEFAULT_BREAKPOINTS=C;exports.isExplicitLayout=x;exports.isShorthandLayout=O;exports.useAutoForm=j;
|
|
5
5
|
//# sourceMappingURL=vue-autoform.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue-autoform.cjs.js","sources":["../src/types.ts","../src/composables/useAutoForm.ts","../src/components/AutoForm.vue","../src/components/AutoFormRow.vue"],"sourcesContent":["import type { Component } from 'vue'\nimport type { ZodObject, ZodRawShape } from 'zod'\n\nexport type BreakpointKey = 'sm' | 'md' | 'lg' | 'xl' | '2xl'\n\nexport type BreakpointMap = Record<BreakpointKey, number>\n\nexport const DEFAULT_BREAKPOINTS: BreakpointMap = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n '2xl': 1536,\n}\n\nexport interface FieldConfig {\n component: Component\n props?: Record<string, unknown> | (() => Record<string, unknown>)\n [key: string]: unknown\n}\n\nexport type LayoutRow = string[]\n\nexport type LayoutGrid = LayoutRow[]\n\nexport type ShorthandLayout = { default: number } & Partial<Record<BreakpointKey, number>>\n\nexport type ExplicitLayout = { default: LayoutGrid } & Partial<Record<BreakpointKey, LayoutGrid>>\n\nexport type AutoFormLayout = ShorthandLayout | ExplicitLayout\n\nexport function isShorthandLayout(layout: AutoFormLayout): layout is ShorthandLayout {\n return typeof layout.default === 'number'\n}\n\nexport function isExplicitLayout(layout: AutoFormLayout): layout is ExplicitLayout {\n return Array.isArray(layout.default)\n}\n\nexport interface AutoFormProps {\n schema: ZodObject<ZodRawShape>\n layout?: AutoFormLayout\n fields: Record<string, FieldConfig>\n modelValue: Record<string, unknown>\n validateOn?: 'blur' | 'input' | 'submit'\n breakpoints?: Partial<BreakpointMap>\n}\n\nexport interface FieldRenderInfo {\n key: string\n config: FieldConfig | undefined\n value: unknown\n error: string | undefined\n}\n","import { reactive, computed } from 'vue'\nimport type { Ref } from 'vue'\nimport type { ZodObject, ZodRawShape } from 'zod'\nimport type { BreakpointMap, AutoFormLayout, LayoutGrid } from '../types'\nimport {\n DEFAULT_BREAKPOINTS,\n isShorthandLayout,\n isExplicitLayout,\n} from '../types'\n\nexport function useAutoForm(\n schema: ZodObject<ZodRawShape>,\n modelValue: Ref<Record<string, unknown>>,\n emit: (event: 'update:modelValue', value: Record<string, unknown>) => void,\n validateOn: Ref<'blur' | 'input' | 'submit'>,\n layout: Ref<AutoFormLayout | undefined>,\n breakpointsOverride: Ref<Partial<BreakpointMap> | undefined>,\n) {\n const errors = reactive<Record<string, string>>({})\n\n const breakpoints = computed<BreakpointMap>(() => ({\n ...DEFAULT_BREAKPOINTS,\n ...breakpointsOverride.value,\n }))\n\n const schemaKeys = computed<string[]>(() => Object.keys(schema.shape))\n\n const resolvedLayout = computed<LayoutGrid>(() => {\n const l = layout.value\n if (!l) {\n return schemaKeys.value.map((key: string) => [key])\n }\n if (isExplicitLayout(l)) {\n return l.default\n }\n if (isShorthandLayout(l)) {\n const cols = l.default\n const keys = schemaKeys.value\n const rows: LayoutGrid = []\n for (let i = 0; i < keys.length; i += cols) {\n rows.push(keys.slice(i, i + cols))\n }\n return rows\n }\n return schemaKeys.value.map((key: string) => [key])\n })\n\n function validateField(key: string, value: unknown): string | undefined {\n const shape = schema.shape\n if (!shape[key]) return undefined\n const fieldSchema = shape[key]\n const result = fieldSchema.safeParse(value)\n if (!result.success) {\n return result.error.errors[0]?.message ?? 'Invalid value'\n }\n return undefined\n }\n\n function validateAll(): boolean {\n const result = schema.safeParse(modelValue.value)\n if (!result.success) {\n result.error.errors.forEach((err) => {\n const key = String(err.path[0])\n errors[key] = err.message\n })\n return false\n }\n Object.keys(errors).forEach((k: string) => delete errors[k])\n return true\n }\n\n function onFieldInput(key: string, value: unknown) {\n const updated = { ...modelValue.value, [key]: value }\n emit('update:modelValue', updated)\n if (validateOn.value === 'input') {\n const msg = validateField(key, value)\n if (msg) {\n errors[key] = msg\n } else {\n delete errors[key]\n }\n }\n }\n\n function onFieldBlur(key: string) {\n if (validateOn.value === 'blur') {\n const msg = validateField(key, modelValue.value[key])\n if (msg) {\n errors[key] = msg\n } else {\n delete errors[key]\n }\n }\n }\n\n function getBreakpointLayouts(): Array<{ minWidth: number; grid: LayoutGrid; key: string }> {\n const l = layout.value\n if (!l) return []\n\n const bps = breakpoints.value\n const result: Array<{ minWidth: number; grid: LayoutGrid; key: string }> = []\n\n if (isExplicitLayout(l)) {\n const bpKeys = Object.keys(l).filter((k) => k !== 'default') as Array<keyof typeof l>\n for (const bpKey of bpKeys) {\n const minWidth = bps[bpKey as keyof BreakpointMap]\n const grid = l[bpKey as keyof typeof l] as LayoutGrid\n if (minWidth && grid) {\n result.push({ minWidth, grid, key: bpKey })\n }\n }\n } else if (isShorthandLayout(l)) {\n const bpKeys = Object.keys(l).filter((k) => k !== 'default') as Array<keyof typeof l>\n for (const bpKey of bpKeys) {\n const minWidth = bps[bpKey as keyof BreakpointMap]\n const cols = l[bpKey as keyof typeof l] as number\n if (minWidth && cols) {\n const keys = schemaKeys.value\n const rows: LayoutGrid = []\n for (let i = 0; i < keys.length; i += cols) {\n rows.push(keys.slice(i, i + cols))\n }\n result.push({ minWidth, grid: rows, key: bpKey })\n }\n }\n }\n\n return result.sort((a, b) => a.minWidth - b.minWidth)\n }\n\n return {\n errors,\n resolvedLayout,\n schemaKeys,\n onFieldInput,\n onFieldBlur,\n validateAll,\n getBreakpointLayouts,\n }\n}\n","<template>\n <div class=\"autoform\" :data-autoform-id=\"formId\">\n <component :is=\"'style'\" v-if=\"mediaQueryCss\">{{\n mediaQueryCss\n }}</component>\n\n <!-- Shorthand layout: single flat grid, CSS handles column count per breakpoint -->\n <div v-if=\"isShorthand\" class=\"autoform-flat-grid\">\n <div v-for=\"fieldKey in flatKeys\" :key=\"fieldKey\" class=\"autoform-cell\">\n <template v-if=\"fields[fieldKey]\">\n <component\n :is=\"fields[fieldKey].component\"\n :modelValue=\"modelValue[fieldKey]\"\n :error=\"errors[fieldKey]\"\n v-bind=\"resolveProps(fieldKey)\"\n @update:modelValue=\"(val: unknown) => onFieldInput(fieldKey, val)\"\n @blur=\"() => onFieldBlur(fieldKey)\"\n />\n <slot name=\"error\" :fieldKey=\"fieldKey\" :error=\"errors[fieldKey]\" />\n </template>\n <template v-else>\n <slot\n :name=\"`field-${fieldKey}`\"\n :fieldKey=\"fieldKey\"\n :value=\"modelValue[fieldKey]\"\n :error=\"errors[fieldKey]\"\n :onUpdate=\"(val: unknown) => onFieldInput(fieldKey, val)\"\n :onBlur=\"() => onFieldBlur(fieldKey)\"\n >\n <input\n class=\"autoform-default-input\"\n :value=\"String(modelValue[fieldKey] ?? '')\"\n @input=\"\n (e: Event) =>\n onFieldInput(fieldKey, (e.target as HTMLInputElement).value)\n \"\n @blur=\"() => onFieldBlur(fieldKey)\"\n />\n </slot>\n <slot name=\"error\" :fieldKey=\"fieldKey\" :error=\"errors[fieldKey]\" />\n </template>\n </div>\n </div>\n\n <!-- Explicit layout / no layout: flat grid, CSS positions each field per breakpoint -->\n <div v-else class=\"autoform-flat-grid\">\n <div\n v-for=\"fieldKey in flatKeys\"\n :key=\"fieldKey\"\n class=\"autoform-cell\"\n :data-field-key=\"fieldKey\"\n >\n <template v-if=\"fields[fieldKey]\">\n <component\n :is=\"fields[fieldKey].component\"\n :modelValue=\"modelValue[fieldKey]\"\n :error=\"errors[fieldKey]\"\n v-bind=\"resolveProps(fieldKey)\"\n @update:modelValue=\"(val: unknown) => onFieldInput(fieldKey, val)\"\n @blur=\"() => onFieldBlur(fieldKey)\"\n />\n <slot name=\"error\" :fieldKey=\"fieldKey\" :error=\"errors[fieldKey]\" />\n </template>\n <template v-else>\n <slot\n :name=\"`field-${fieldKey}`\"\n :fieldKey=\"fieldKey\"\n :value=\"modelValue[fieldKey]\"\n :error=\"errors[fieldKey]\"\n :onUpdate=\"(val: unknown) => onFieldInput(fieldKey, val)\"\n :onBlur=\"() => onFieldBlur(fieldKey)\"\n >\n <input\n class=\"autoform-default-input\"\n :value=\"String(modelValue[fieldKey] ?? '')\"\n @input=\"\n (e: Event) =>\n onFieldInput(fieldKey, (e.target as HTMLInputElement).value)\n \"\n @blur=\"() => onFieldBlur(fieldKey)\"\n />\n </slot>\n <slot name=\"error\" :fieldKey=\"fieldKey\" :error=\"errors[fieldKey]\" />\n </template>\n </div>\n </div>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, ref, toRef } from \"vue\";\nimport type { ZodObject, ZodRawShape } from \"zod\";\nimport { useAutoForm } from \"../composables/useAutoForm\";\nimport type {\n AutoFormLayout,\n BreakpointMap,\n FieldConfig,\n LayoutGrid,\n} from \"../types\";\nimport {\n isExplicitLayout,\n isShorthandLayout,\n DEFAULT_BREAKPOINTS,\n} from \"../types\";\n\nconst props = withDefaults(\n defineProps<{\n schema: ZodObject<ZodRawShape>;\n layout?: AutoFormLayout;\n fields: Record<string, FieldConfig>;\n modelValue: Record<string, unknown>;\n validateOn?: \"blur\" | \"input\" | \"submit\";\n breakpoints?: Partial<BreakpointMap>;\n }>(),\n {\n validateOn: \"blur\",\n },\n);\n\nconst emit = defineEmits<{\n (e: \"update:modelValue\", value: Record<string, unknown>): void;\n}>();\n\nconst formId = ref(`autoform-${Math.random().toString(36).slice(2, 9)}`);\n\nconst { errors, schemaKeys, onFieldInput, onFieldBlur, validateAll } =\n useAutoForm(\n props.schema,\n toRef(props, \"modelValue\"),\n (_, val) => emit(\"update:modelValue\", val),\n toRef(props, \"validateOn\"),\n toRef(props, \"layout\"),\n toRef(props, \"breakpoints\"),\n );\n\nconst isShorthand = computed(() =>\n props.layout ? isShorthandLayout(props.layout) : false,\n);\n\nconst flatKeys = computed(() => schemaKeys.value);\n\nfunction resolveProps(fieldKey: string): Record<string, unknown> {\n const cfg = props.fields[fieldKey];\n if (!cfg) return {};\n const p = cfg.props;\n return typeof p === \"function\" ? p() : (p ?? {});\n}\n\nconst mediaQueryCss = computed<string>(() => {\n if (!props.layout) return \"\";\n\n const bps: BreakpointMap = { ...DEFAULT_BREAKPOINTS, ...props.breakpoints };\n const id = formId.value;\n const lines: string[] = [];\n\n if (isShorthandLayout(props.layout)) {\n const layout = props.layout;\n // Base columns for the flat grid\n lines.push(\n `[data-autoform-id=\"${id}\"] .autoform-flat-grid {`,\n ` grid-template-columns: repeat(${layout.default}, minmax(0, 1fr));`,\n `}`,\n );\n const bpKeys = Object.keys(layout).filter((k) => k !== \"default\") as Array<\n keyof typeof layout\n >;\n for (const bpKey of bpKeys) {\n const minWidth = bps[bpKey as keyof BreakpointMap];\n const cols = layout[bpKey as keyof typeof layout] as number;\n if (minWidth && cols) {\n lines.push(\n `@media (min-width: ${minWidth}px) {`,\n ` [data-autoform-id=\"${id}\"] .autoform-flat-grid {`,\n ` grid-template-columns: repeat(${cols}, minmax(0, 1fr));`,\n ` }`,\n `}`,\n );\n }\n }\n } else if (isExplicitLayout(props.layout)) {\n const layout = props.layout;\n // Helper: build CSS rules for a given grid at a given scope (media query or base)\n const gridToCss = (grid: LayoutGrid, wrap?: string): string => {\n const maxCols = Math.max(...grid.map((r: string[]) => r.length));\n const allKeys = schemaKeys.value;\n const keysInGrid = new Set(grid.flat());\n const fieldRules: string[] = [];\n\n // Set grid column count\n fieldRules.push(\n `[data-autoform-id=\"${id}\"] .autoform-flat-grid { grid-template-columns: repeat(${maxCols}, minmax(0, 1fr)); }`,\n );\n\n // Hide fields not in this layout\n allKeys.forEach((key: string) => {\n if (!keysInGrid.has(key)) {\n fieldRules.push(\n `[data-autoform-id=\"${id}\"] [data-field-key=\"${key}\"] { display: none; }`,\n );\n }\n });\n\n // Position each field\n let rowStart = 1;\n grid.forEach((row: string[]) => {\n let colStart = 1;\n row.forEach((key: string) => {\n fieldRules.push(\n `[data-autoform-id=\"${id}\"] [data-field-key=\"${key}\"] { display: block; grid-row: ${rowStart}; grid-column: ${colStart}; }`,\n );\n colStart++;\n });\n rowStart++;\n });\n\n if (wrap) {\n return [\n `@media (min-width: ${wrap}px) {`,\n ...fieldRules.map((r) => ` ${r}`),\n `}`,\n ].join(\"\\n\");\n }\n return fieldRules.join(\"\\n\");\n };\n\n // Default layout base styles\n lines.push(gridToCss(layout.default));\n\n // Per-breakpoint overrides\n const bpKeys = Object.keys(layout).filter((k) => k !== \"default\") as Array<\n keyof typeof layout\n >;\n const sortedBpKeys = bpKeys.sort(\n (a, b) =>\n (bps[a as keyof BreakpointMap] ?? 0) -\n (bps[b as keyof BreakpointMap] ?? 0),\n );\n for (const bpKey of sortedBpKeys) {\n const minWidth = bps[bpKey as keyof BreakpointMap];\n const grid = layout[bpKey as keyof typeof layout] as LayoutGrid;\n if (minWidth && grid) {\n lines.push(gridToCss(grid, String(minWidth)));\n }\n }\n }\n\n return lines.join(\"\\n\");\n});\n\ndefineExpose({ validateAll, errors });\n</script>\n\n<style>\n.autoform {\n width: 100%;\n display: flex;\n flex-direction: column;\n gap: var(--autoform-row-gap, 1rem);\n}\n\n.autoform-flat-grid {\n display: grid;\n grid-template-columns: repeat(1, minmax(0, 1fr));\n gap: var(--autoform-gap, 1rem);\n width: 100%;\n}\n\n.autoform-flat-grid .autoform-cell {\n min-width: 0;\n}\n\n.autoform-default-input {\n width: 100%;\n padding: 0.5rem 0.75rem;\n border: 1px solid #d1d5db;\n border-radius: 0.375rem;\n font-size: 1rem;\n outline: none;\n box-sizing: border-box;\n}\n\n.autoform-default-input:focus {\n border-color: #6366f1;\n box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);\n}\n</style>\n","<template>\n <div\n class=\"autoform-row\"\n :style=\"{ '--autoform-cols': row.length }\"\n >\n <div\n v-for=\"fieldKey in row\"\n :key=\"fieldKey\"\n class=\"autoform-cell\"\n >\n <slot :fieldKey=\"fieldKey\" />\n </div>\n </div>\n</template>\n\n<script setup lang=\"ts\">\ndefineProps<{\n row: string[]\n}>()\n</script>\n\n<style>\n.autoform-row {\n display: grid;\n grid-template-columns: repeat(var(--autoform-cols, 1), minmax(0, 1fr));\n gap: var(--autoform-gap, 1rem);\n width: 100%;\n}\n\n.autoform-cell {\n min-width: 0;\n}\n</style>\n"],"names":["DEFAULT_BREAKPOINTS","isShorthandLayout","layout","isExplicitLayout","useAutoForm","schema","modelValue","emit","validateOn","breakpointsOverride","errors","reactive","breakpoints","computed","schemaKeys","resolvedLayout","l","key","cols","keys","rows","i","validateField","value","shape","result","_a","validateAll","k","err","onFieldInput","updated","msg","onFieldBlur","getBreakpointLayouts","bps","bpKeys","bpKey","minWidth","grid","a","b","props","__props","__emit","formId","ref","toRef","_","val","isShorthand","flatKeys","resolveProps","fieldKey","cfg","p","mediaQueryCss","id","lines","gridToCss","wrap","maxCols","r","allKeys","keysInGrid","fieldRules","rowStart","row","colStart","sortedBpKeys","__expose","_createElementBlock","_openBlock","_createBlock","_resolveDynamicComponent","_hoisted_2","_Fragment","_renderList","_mergeProps","_unref","_renderSlot","_ctx","_createElementVNode","e","_hoisted_4","_normalizeStyle"],"mappings":"uGAOaA,EAAqC,CAChD,GAAI,IACJ,GAAI,IACJ,GAAI,KACJ,GAAI,KACJ,MAAO,IACT,EAkBO,SAASC,EAAkBC,EAAmD,CACnF,OAAO,OAAOA,EAAO,SAAY,QACnC,CAEO,SAASC,EAAiBD,EAAkD,CACjF,OAAO,MAAM,QAAQA,EAAO,OAAO,CACrC,CC3BO,SAASE,EACdC,EACAC,EACAC,EACAC,EACAN,EACAO,EACA,CACA,MAAMC,EAASC,EAAAA,SAAiC,EAAE,EAE5CC,EAAcC,EAAAA,SAAwB,KAAO,CACjD,GAAGb,EACH,GAAGS,EAAoB,KAAA,EACvB,EAEIK,EAAaD,EAAAA,SAAmB,IAAM,OAAO,KAAKR,EAAO,KAAK,CAAC,EAE/DU,EAAiBF,EAAAA,SAAqB,IAAM,CAChD,MAAMG,EAAId,EAAO,MACjB,GAAI,CAACc,EACH,OAAOF,EAAW,MAAM,IAAKG,GAAgB,CAACA,CAAG,CAAC,EAEpD,GAAId,EAAiBa,CAAC,EACpB,OAAOA,EAAE,QAEX,GAAIf,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ables/useAutoForm.ts","../src/types.ts","../src/components/AutoForm.vue"],"sourcesContent":["import { reactive, computed } from 'vue'\nimport type { Ref } from 'vue'\nimport type { ZodObject, ZodRawShape } from 'zod'\n\nexport function useAutoForm(\n schema: ZodObject<ZodRawShape>,\n modelValue: Ref<Record<string, unknown>>,\n emit: (event: 'update:modelValue', value: Record<string, unknown>) => void,\n validateOn: Ref<'blur' | 'input' | 'submit'>,\n) {\n const errors = reactive<Record<string, string>>({})\n\n const schemaKeys = computed<string[]>(() => Object.keys(schema.shape))\n\n function validateField(key: string, value: unknown): string | undefined {\n const shape = schema.shape\n if (!(key in shape)) return undefined\n const fieldSchema = shape[key]\n const result = fieldSchema.safeParse(value)\n if (!result.success) {\n return result.error.errors[0]?.message ?? 'Invalid value'\n }\n return undefined\n }\n\n function validateAll(): boolean {\n const result = schema.safeParse(modelValue.value)\n if (!result.success) {\n result.error.errors.forEach((err) => {\n const key = String(err.path[0])\n errors[key] = err.message\n })\n return false\n }\n Object.keys(errors).forEach((k: string) => delete errors[k])\n return true\n }\n\n const lastValue: Record<string, unknown> = {}\n\n function onFieldInput(key: string, value: unknown) {\n lastValue[key] = value\n const updated = { ...modelValue.value, [key]: value }\n emit('update:modelValue', updated)\n if (validateOn.value === 'input') {\n const msg = validateField(key, value)\n if (msg) {\n errors[key] = msg\n } else {\n delete errors[key]\n }\n }\n }\n\n function onFieldBlur(key: string) {\n if (validateOn.value === 'blur') {\n // Use lastValue if available — modelValue prop may not have propagated yet\n // when blur fires immediately after update:modelValue (e.g. checkbox toggles)\n const value = key in lastValue ? lastValue[key] : modelValue.value[key]\n const msg = validateField(key, value)\n if (msg) {\n errors[key] = msg\n } else {\n delete errors[key]\n }\n }\n }\n\n return {\n errors,\n schemaKeys,\n onFieldInput,\n onFieldBlur,\n validateAll,\n }\n}\n","import type { Component } from 'vue'\n\nexport type BreakpointKey = 'sm' | 'md' | 'lg' | 'xl' | '2xl'\n\nexport type BreakpointMap = Record<BreakpointKey, number>\n\nexport const DEFAULT_BREAKPOINTS: BreakpointMap = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n '2xl': 1536,\n}\n\nexport interface FieldConfig {\n component: Component\n props?: Record<string, unknown> | (() => Record<string, unknown>)\n}\n\nexport type LayoutRow = string[]\n\nexport type LayoutGrid = LayoutRow[]\n\nexport type ShorthandLayout = { default: number } & Partial<Record<BreakpointKey, number>>\n\nexport type ExplicitLayout = { default: LayoutGrid } & Partial<Record<BreakpointKey, LayoutGrid>>\n\nexport type AutoFormLayout = ShorthandLayout | ExplicitLayout\n\nexport function isShorthandLayout(layout: AutoFormLayout): layout is ShorthandLayout {\n return typeof layout.default === 'number'\n}\n\nexport function isExplicitLayout(layout: AutoFormLayout): layout is ExplicitLayout {\n return Array.isArray(layout.default)\n}\n\nexport interface FieldRenderInfo {\n key: string\n config: FieldConfig | undefined\n value: unknown\n error: string | undefined\n}\n","<template>\n <div class=\"autoform\" :data-autoform-id=\"formId\">\n <component :is=\"'style'\" v-if=\"mediaQueryCss\">{{\n mediaQueryCss\n }}</component>\n\n <!-- Flat grid: CSS handles column count (shorthand) or per-field position (explicit/none) -->\n <div class=\"autoform-flat-grid\">\n <div\n v-for=\"fieldKey in schemaKeys\"\n :key=\"fieldKey\"\n class=\"autoform-cell\"\n :data-field-key=\"isExplicit ? fieldKey : undefined\"\n >\n <template v-if=\"fields[fieldKey]\">\n <component\n :is=\"fields[fieldKey].component\"\n :modelValue=\"modelValue[fieldKey]\"\n :error=\"errors[fieldKey]\"\n v-bind=\"resolveProps(fieldKey)\"\n @update:modelValue=\"(val: unknown) => onFieldInput(fieldKey, val)\"\n @blur=\"() => onFieldBlur(fieldKey)\"\n />\n <slot name=\"error\" :fieldKey=\"fieldKey\" :error=\"errors[fieldKey]\" />\n </template>\n <template v-else>\n <slot\n :name=\"`field-${fieldKey}`\"\n :fieldKey=\"fieldKey\"\n :value=\"modelValue[fieldKey]\"\n :error=\"errors[fieldKey]\"\n :onUpdate=\"(val: unknown) => onFieldInput(fieldKey, val)\"\n :onBlur=\"() => onFieldBlur(fieldKey)\"\n >\n <input\n class=\"autoform-default-input\"\n :value=\"String(modelValue[fieldKey] ?? '')\"\n @input=\"\n (e: Event) =>\n onFieldInput(fieldKey, (e.target as HTMLInputElement).value)\n \"\n @blur=\"() => onFieldBlur(fieldKey)\"\n />\n </slot>\n <slot name=\"error\" :fieldKey=\"fieldKey\" :error=\"errors[fieldKey]\" />\n </template>\n </div>\n </div>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, ref, toRef } from \"vue\";\nimport type { ZodObject, ZodRawShape } from \"zod\";\nimport { useAutoForm } from \"../composables/useAutoForm\";\nimport type {\n AutoFormLayout,\n BreakpointMap,\n FieldConfig,\n LayoutGrid,\n} from \"../types\";\nimport {\n isExplicitLayout,\n isShorthandLayout,\n DEFAULT_BREAKPOINTS,\n} from \"../types\";\n\nconst props = withDefaults(\n defineProps<{\n schema: ZodObject<ZodRawShape>;\n layout?: AutoFormLayout;\n fields: Record<string, FieldConfig>;\n modelValue: Record<string, unknown>;\n validateOn?: \"blur\" | \"input\" | \"submit\";\n breakpoints?: Partial<BreakpointMap>;\n }>(),\n {\n validateOn: \"blur\",\n },\n);\n\nconst emit = defineEmits<{\n (e: \"update:modelValue\", value: Record<string, unknown>): void;\n}>();\n\nconst formId = ref(`autoform-${Math.random().toString(36).slice(2, 9)}`);\n\nconst { errors, schemaKeys, onFieldInput, onFieldBlur, validateAll } =\n useAutoForm(\n props.schema,\n toRef(props, \"modelValue\"),\n (event, val) => emit(event, val),\n toRef(props, \"validateOn\"),\n );\n\nconst isExplicit = computed(() =>\n props.layout ? isExplicitLayout(props.layout) : true,\n);\n\nfunction resolveProps(fieldKey: string): Record<string, unknown> {\n const cfg = props.fields[fieldKey];\n if (!cfg) return {};\n const p = cfg.props;\n return typeof p === \"function\" ? p() : (p ?? {});\n}\n\nconst mediaQueryCss = computed<string>(() => {\n if (!props.layout) return \"\";\n\n const bps: BreakpointMap = { ...DEFAULT_BREAKPOINTS, ...props.breakpoints };\n const id = formId.value;\n const lines: string[] = [];\n\n if (isShorthandLayout(props.layout)) {\n const layout = props.layout;\n // Base columns for the flat grid\n lines.push(\n `[data-autoform-id=\"${id}\"] .autoform-flat-grid {`,\n ` grid-template-columns: repeat(${layout.default}, minmax(0, 1fr));`,\n `}`,\n );\n const bpKeys = Object.keys(layout).filter((k) => k !== \"default\") as Array<\n keyof typeof layout\n >;\n for (const bpKey of bpKeys) {\n const minWidth = bps[bpKey as keyof BreakpointMap];\n const cols = layout[bpKey as keyof typeof layout] as number;\n if (minWidth && cols) {\n lines.push(\n `@media (min-width: ${minWidth}px) {`,\n ` [data-autoform-id=\"${id}\"] .autoform-flat-grid {`,\n ` grid-template-columns: repeat(${cols}, minmax(0, 1fr));`,\n ` }`,\n `}`,\n );\n }\n }\n } else if (isExplicitLayout(props.layout)) {\n const layout = props.layout;\n // Helper: build CSS rules for a given grid at a given scope (media query or base)\n const gridToCss = (grid: LayoutGrid, wrap?: string): string => {\n const maxCols = Math.max(...grid.map((r: string[]) => r.length));\n const allKeys = schemaKeys.value;\n const keysInGrid = new Set(grid.flat());\n const fieldRules: string[] = [];\n\n // Set grid column count\n fieldRules.push(\n `[data-autoform-id=\"${id}\"] .autoform-flat-grid { grid-template-columns: repeat(${maxCols}, minmax(0, 1fr)); }`,\n );\n\n // Hide fields not in this layout\n allKeys.forEach((key: string) => {\n if (!keysInGrid.has(key)) {\n fieldRules.push(\n `[data-autoform-id=\"${id}\"] [data-field-key=\"${key}\"] { display: none; }`,\n );\n }\n });\n\n // Position each field\n let rowStart = 1;\n grid.forEach((row: string[]) => {\n let colStart = 1;\n row.forEach((key: string) => {\n fieldRules.push(\n `[data-autoform-id=\"${id}\"] [data-field-key=\"${key}\"] { display: block; grid-row: ${rowStart}; grid-column: ${colStart}; }`,\n );\n colStart++;\n });\n rowStart++;\n });\n\n if (wrap) {\n return [\n `@media (min-width: ${wrap}px) {`,\n ...fieldRules.map((r) => ` ${r}`),\n `}`,\n ].join(\"\\n\");\n }\n return fieldRules.join(\"\\n\");\n };\n\n // Default layout base styles\n lines.push(gridToCss(layout.default));\n\n // Per-breakpoint overrides\n const bpKeys = Object.keys(layout).filter((k) => k !== \"default\") as Array<\n keyof typeof layout\n >;\n const sortedBpKeys = bpKeys.sort(\n (a, b) =>\n (bps[a as keyof BreakpointMap] ?? 0) -\n (bps[b as keyof BreakpointMap] ?? 0),\n );\n for (const bpKey of sortedBpKeys) {\n const minWidth = bps[bpKey as keyof BreakpointMap];\n const grid = layout[bpKey as keyof typeof layout] as LayoutGrid;\n if (minWidth && grid) {\n lines.push(gridToCss(grid, String(minWidth)));\n }\n }\n }\n\n return lines.join(\"\\n\");\n});\n\ndefineExpose({ validateAll, errors });\n</script>\n\n<style>\n.autoform {\n width: 100%;\n}\n\n.autoform-flat-grid {\n display: grid;\n grid-template-columns: repeat(1, minmax(0, 1fr));\n column-gap: var(--autoform-gap, 1rem);\n row-gap: var(--autoform-row-gap, 1rem);\n width: 100%;\n}\n\n.autoform-flat-grid .autoform-cell {\n min-width: 0;\n}\n\n.autoform-default-input {\n width: 100%;\n padding: 0.5rem 0.75rem;\n border: 1px solid #d1d5db;\n border-radius: 0.375rem;\n font-size: 1rem;\n outline: none;\n box-sizing: border-box;\n}\n\n.autoform-default-input:focus {\n border-color: #6366f1;\n box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);\n}\n</style>\n"],"names":["useAutoForm","schema","modelValue","emit","validateOn","errors","reactive","schemaKeys","computed","validateField","key","value","shape","result","_a","validateAll","k","err","lastValue","onFieldInput","updated","msg","onFieldBlur","DEFAULT_BREAKPOINTS","isShorthandLayout","layout","isExplicitLayout","props","__props","__emit","formId","ref","toRef","event","val","isExplicit","resolveProps","fieldKey","cfg","p","mediaQueryCss","bps","id","lines","bpKeys","bpKey","minWidth","cols","gridToCss","grid","wrap","maxCols","r","allKeys","keysInGrid","fieldRules","rowStart","row","colStart","sortedBpKeys","a","b","__expose","_createElementBlock","_openBlock","_createBlock","_resolveDynamicComponent","_createElementVNode","_hoisted_2","_Fragment","_renderList","_unref","_mergeProps","_renderSlot","_ctx","e"],"mappings":"uGAIO,SAASA,EACdC,EACAC,EACAC,EACAC,EACA,CACA,MAAMC,EAASC,EAAAA,SAAiC,EAAE,EAE5CC,EAAaC,EAAAA,SAAmB,IAAM,OAAO,KAAKP,EAAO,KAAK,CAAC,EAErE,SAASQ,EAAcC,EAAaC,EAAoC,OACtE,MAAMC,EAAQX,EAAO,MACrB,GAAI,EAAES,KAAOE,GAAQ,OAErB,MAAMC,EADcD,EAAMF,CAAG,EACF,UAAUC,CAAK,EAC1C,GAAI,CAACE,EAAO,QACV,QAAOC,EAAAD,EAAO,MAAM,OAAO,CAAC,IAArB,YAAAC,EAAwB,UAAW,eAG9C,CAEA,SAASC,GAAuB,CAC9B,MAAMF,EAASZ,EAAO,UAAUC,EAAW,KAAK,EAChD,OAAKW,EAAO,SAOZ,OAAO,KAAKR,CAAM,EAAE,QAASW,GAAc,OAAOX,EAAOW,CAAC,CAAC,EACpD,KAPLH,EAAO,MAAM,OAAO,QAASI,GAAQ,CACnC,MAAMP,EAAM,OAAOO,EAAI,KAAK,CAAC,CAAC,EAC9BZ,EAAOK,CAAG,EAAIO,EAAI,OACpB,CAAC,EACM,GAIX,CAEA,MAAMC,EAAqC,CAAA,EAE3C,SAASC,EAAaT,EAAaC,EAAgB,CACjDO,EAAUR,CAAG,EAAIC,EACjB,MAAMS,EAAU,CAAE,GAAGlB,EAAW,MAAO,CAACQ,CAAG,EAAGC,CAAA,EAE9C,GADAR,EAAK,oBAAqBiB,CAAO,EAC7BhB,EAAW,QAAU,QAAS,CAChC,MAAMiB,EAAMZ,EAAcC,EAAKC,CAAK,EAChCU,EACFhB,EAAOK,CAAG,EAAIW,EAEd,OAAOhB,EAAOK,CAAG,CAErB,CACF,CAEA,SAASY,EAAYZ,EAAa,CAChC,GAAIN,EAAW,QAAU,OAAQ,CAG/B,MAAMO,EAAQ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Y5C,EAAA,WAAWS,CAAQ,EAC/B,MAAOkC,EAAAA,MAAAlE,CAAA,EAAOgC,CAAQ,CAAA,EACf,CAAA,QAAA,IAAAD,EAAaC,CAAQ,EAAA,CAC5B,sBAAoBH,GAAiBqC,EAAAA,SAAalC,EAAUH,CAAG,EAC/D,OAAI,IAAQqC,EAAAA,MAAAjD,CAAA,EAAYe,CAAQ,CAAA,mEAEnCoC,aAAoEC,EAAA,OAAA,QAAA,CAAhD,SAAArC,EAAqB,MAAOkC,EAAAA,MAAAlE,CAAA,EAAOgC,CAAQ,CAAA,wBAEjE0B,EAAAA,mBAoBWM,EAAAA,SAAA,CAAA,IAAA,GAAA,CAnBTI,EAAAA,WAiBOC,kBAhBWrC,CAAQ,GAAA,CACvB,SAAAA,EACA,MAAOT,EAAA,WAAWS,CAAQ,EAC1B,MAAOkC,EAAAA,MAAAlE,CAAA,EAAOgC,CAAQ,EACtB,SAAWH,GAAiBqC,EAAAA,SAAalC,EAAUH,CAAG,EACtD,OAAM,IAAQqC,EAAAA,MAAAjD,CAAA,EAAYe,CAAQ,CAAA,EANrC,IAiBO,CATL8B,EAAAA,mBAQE,QAAA,CAPA,MAAM,yBACL,MAAO,OAAOvC,EAAA,WAAWS,CAAQ,GAAA,EAAA,EACjC,QAAyBsC,GAA+BJ,QAAApD,CAAA,EAAakB,EAAWsC,EAAE,OAA4B,KAAK,EAInH,OAAI,IAAQJ,EAAAA,MAAAjD,CAAA,EAAYe,CAAQ,CAAA,eAGrCoC,aAAoEC,EAAA,OAAA,QAAA,CAAhD,SAAArC,EAAqB,MAAOkC,EAAAA,MAAAlE,CAAA,EAAOgC,CAAQ,CAAA"}
|
package/dist/vue-autoform.d.ts
CHANGED
|
@@ -39,16 +39,8 @@ validateOn: string;
|
|
|
39
39
|
validateOn: "blur" | "input" | "submit";
|
|
40
40
|
}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
|
|
41
41
|
|
|
42
|
-
declare const __VLS_component_2: DefineComponent<ExtractPropTypes<__VLS_TypePropsToRuntimeProps_2<{
|
|
43
|
-
row: string[];
|
|
44
|
-
}>>, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps_2<{
|
|
45
|
-
row: string[];
|
|
46
|
-
}>>> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
|
|
47
|
-
|
|
48
42
|
declare type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
49
43
|
|
|
50
|
-
declare type __VLS_NonUndefinedable_2<T> = T extends undefined ? never : T;
|
|
51
|
-
|
|
52
44
|
declare type __VLS_Prettify<T> = {
|
|
53
45
|
[K in keyof T]: T[K];
|
|
54
46
|
} & {};
|
|
@@ -59,12 +51,6 @@ declare function __VLS_template(): Partial<Record<`field-${string}`, (_: {
|
|
|
59
51
|
error: string;
|
|
60
52
|
onUpdate: (val: unknown) => void;
|
|
61
53
|
onBlur: () => void;
|
|
62
|
-
}) => any>> & Partial<Record<`field-${string}`, (_: {
|
|
63
|
-
fieldKey: string;
|
|
64
|
-
value: unknown;
|
|
65
|
-
error: string;
|
|
66
|
-
onUpdate: (val: unknown) => void;
|
|
67
|
-
onBlur: () => void;
|
|
68
54
|
}) => any>> & {
|
|
69
55
|
error?(_: {
|
|
70
56
|
fieldKey: string;
|
|
@@ -72,12 +58,6 @@ declare function __VLS_template(): Partial<Record<`field-${string}`, (_: {
|
|
|
72
58
|
}): any;
|
|
73
59
|
};
|
|
74
60
|
|
|
75
|
-
declare function __VLS_template_2(): {
|
|
76
|
-
default?(_: {
|
|
77
|
-
fieldKey: string;
|
|
78
|
-
}): any;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
61
|
declare type __VLS_TypePropsToRuntimeProps<T> = {
|
|
82
62
|
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
83
63
|
type: PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
@@ -87,15 +67,6 @@ declare type __VLS_TypePropsToRuntimeProps<T> = {
|
|
|
87
67
|
};
|
|
88
68
|
};
|
|
89
69
|
|
|
90
|
-
declare type __VLS_TypePropsToRuntimeProps_2<T> = {
|
|
91
|
-
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
92
|
-
type: PropType<__VLS_NonUndefinedable_2<T[K]>>;
|
|
93
|
-
} : {
|
|
94
|
-
type: PropType<T[K]>;
|
|
95
|
-
required: true;
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
|
|
99
70
|
declare type __VLS_WithDefaults<P, D> = {
|
|
100
71
|
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
|
|
101
72
|
default: D[K];
|
|
@@ -108,27 +79,10 @@ declare type __VLS_WithTemplateSlots<T, S> = T & {
|
|
|
108
79
|
};
|
|
109
80
|
};
|
|
110
81
|
|
|
111
|
-
declare type __VLS_WithTemplateSlots_2<T, S> = T & {
|
|
112
|
-
new (): {
|
|
113
|
-
$slots: S;
|
|
114
|
-
};
|
|
115
|
-
};
|
|
116
|
-
|
|
117
82
|
export declare const AutoForm: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
|
|
118
83
|
|
|
119
84
|
export declare type AutoFormLayout = ShorthandLayout | ExplicitLayout;
|
|
120
85
|
|
|
121
|
-
export declare interface AutoFormProps {
|
|
122
|
-
schema: ZodObject<ZodRawShape>;
|
|
123
|
-
layout?: AutoFormLayout;
|
|
124
|
-
fields: Record<string, FieldConfig>;
|
|
125
|
-
modelValue: Record<string, unknown>;
|
|
126
|
-
validateOn?: 'blur' | 'input' | 'submit';
|
|
127
|
-
breakpoints?: Partial<BreakpointMap>;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export declare const AutoFormRow: __VLS_WithTemplateSlots_2<typeof __VLS_component_2, ReturnType<typeof __VLS_template_2>>;
|
|
131
|
-
|
|
132
86
|
export declare type BreakpointKey = 'sm' | 'md' | 'lg' | 'xl' | '2xl';
|
|
133
87
|
|
|
134
88
|
export declare type BreakpointMap = Record<BreakpointKey, number>;
|
|
@@ -142,14 +96,6 @@ export declare type ExplicitLayout = {
|
|
|
142
96
|
export declare interface FieldConfig {
|
|
143
97
|
component: Component;
|
|
144
98
|
props?: Record<string, unknown> | (() => Record<string, unknown>);
|
|
145
|
-
[key: string]: unknown;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export declare interface FieldRenderInfo {
|
|
149
|
-
key: string;
|
|
150
|
-
config: FieldConfig | undefined;
|
|
151
|
-
value: unknown;
|
|
152
|
-
error: string | undefined;
|
|
153
99
|
}
|
|
154
100
|
|
|
155
101
|
export declare function isExplicitLayout(layout: AutoFormLayout): layout is ExplicitLayout;
|
|
@@ -164,18 +110,12 @@ export declare type ShorthandLayout = {
|
|
|
164
110
|
default: number;
|
|
165
111
|
} & Partial<Record<BreakpointKey, number>>;
|
|
166
112
|
|
|
167
|
-
export declare function useAutoForm(schema: ZodObject<ZodRawShape>, modelValue: Ref<Record<string, unknown>>, emit: (event: 'update:modelValue', value: Record<string, unknown>) => void, validateOn: Ref<'blur' | 'input' | 'submit'
|
|
113
|
+
export declare function useAutoForm(schema: ZodObject<ZodRawShape>, modelValue: Ref<Record<string, unknown>>, emit: (event: 'update:modelValue', value: Record<string, unknown>) => void, validateOn: Ref<'blur' | 'input' | 'submit'>): {
|
|
168
114
|
errors: Record<string, string>;
|
|
169
|
-
resolvedLayout: ComputedRef<LayoutGrid>;
|
|
170
115
|
schemaKeys: ComputedRef<string[]>;
|
|
171
116
|
onFieldInput: (key: string, value: unknown) => void;
|
|
172
117
|
onFieldBlur: (key: string) => void;
|
|
173
118
|
validateAll: () => boolean;
|
|
174
|
-
getBreakpointLayouts: () => Array<{
|
|
175
|
-
minWidth: number;
|
|
176
|
-
grid: LayoutGrid;
|
|
177
|
-
key: string;
|
|
178
|
-
}>;
|
|
179
119
|
};
|
|
180
120
|
|
|
181
121
|
export { }
|
package/dist/vue-autoform.es.js
CHANGED
|
@@ -1,104 +1,58 @@
|
|
|
1
|
-
import { reactive as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
function R(n) {
|
|
13
|
-
return Array.isArray(n.default);
|
|
14
|
-
}
|
|
15
|
-
function ot(n, $, S, s, w, F) {
|
|
16
|
-
const l = J({}), A = B(() => ({
|
|
17
|
-
...G,
|
|
18
|
-
...F.value
|
|
19
|
-
})), f = B(() => Object.keys(n.shape)), g = B(() => {
|
|
20
|
-
const o = w.value;
|
|
21
|
-
if (!o)
|
|
22
|
-
return f.value.map((e) => [e]);
|
|
23
|
-
if (R(o))
|
|
24
|
-
return o.default;
|
|
25
|
-
if (C(o)) {
|
|
26
|
-
const e = o.default, t = f.value, r = [];
|
|
27
|
-
for (let a = 0; a < t.length; a += e)
|
|
28
|
-
r.push(t.slice(a, a + e));
|
|
29
|
-
return r;
|
|
30
|
-
}
|
|
31
|
-
return f.value.map((e) => [e]);
|
|
32
|
-
});
|
|
33
|
-
function E(o, e) {
|
|
34
|
-
var m;
|
|
35
|
-
const t = n.shape;
|
|
36
|
-
if (!t[o]) return;
|
|
37
|
-
const a = t[o].safeParse(e);
|
|
38
|
-
if (!a.success)
|
|
39
|
-
return ((m = a.error.errors[0]) == null ? void 0 : m.message) ?? "Invalid value";
|
|
1
|
+
import { reactive as M, computed as C, defineComponent as W, ref as G, toRef as P, openBlock as v, createElementBlock as y, createBlock as L, resolveDynamicComponent as N, withCtx as Q, createTextVNode as q, toDisplayString as z, createCommentVNode as H, createElementVNode as T, Fragment as I, renderList as J, unref as c, mergeProps as X, renderSlot as j } from "vue";
|
|
2
|
+
function Y(a, g, k, r) {
|
|
3
|
+
const d = M({}), S = C(() => Object.keys(a.shape));
|
|
4
|
+
function m(o, n) {
|
|
5
|
+
var t;
|
|
6
|
+
const i = a.shape;
|
|
7
|
+
if (!(o in i)) return;
|
|
8
|
+
const s = i[o].safeParse(n);
|
|
9
|
+
if (!s.success)
|
|
10
|
+
return ((t = s.error.errors[0]) == null ? void 0 : t.message) ?? "Invalid value";
|
|
40
11
|
}
|
|
41
|
-
function
|
|
42
|
-
const o =
|
|
43
|
-
return o.success ? (Object.keys(
|
|
44
|
-
const
|
|
45
|
-
|
|
12
|
+
function V() {
|
|
13
|
+
const o = a.safeParse(g.value);
|
|
14
|
+
return o.success ? (Object.keys(d).forEach((n) => delete d[n]), !0) : (o.error.errors.forEach((n) => {
|
|
15
|
+
const i = String(n.path[0]);
|
|
16
|
+
d[i] = n.message;
|
|
46
17
|
}), !1);
|
|
47
18
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
19
|
+
const p = {};
|
|
20
|
+
function $(o, n) {
|
|
21
|
+
p[o] = n;
|
|
22
|
+
const i = { ...g.value, [o]: n };
|
|
23
|
+
if (k("update:modelValue", i), r.value === "input") {
|
|
24
|
+
const e = m(o, n);
|
|
25
|
+
e ? d[o] = e : delete d[o];
|
|
53
26
|
}
|
|
54
27
|
}
|
|
55
|
-
function
|
|
56
|
-
if (
|
|
57
|
-
const
|
|
58
|
-
|
|
28
|
+
function A(o) {
|
|
29
|
+
if (r.value === "blur") {
|
|
30
|
+
const n = o in p ? p[o] : g.value[o], i = m(o, n);
|
|
31
|
+
i ? d[o] = i : delete d[o];
|
|
59
32
|
}
|
|
60
33
|
}
|
|
61
|
-
function x() {
|
|
62
|
-
const o = w.value;
|
|
63
|
-
if (!o) return [];
|
|
64
|
-
const e = A.value, t = [];
|
|
65
|
-
if (R(o)) {
|
|
66
|
-
const r = Object.keys(o).filter((a) => a !== "default");
|
|
67
|
-
for (const a of r) {
|
|
68
|
-
const m = e[a], p = o[a];
|
|
69
|
-
m && p && t.push({ minWidth: m, grid: p, key: a });
|
|
70
|
-
}
|
|
71
|
-
} else if (C(o)) {
|
|
72
|
-
const r = Object.keys(o).filter((a) => a !== "default");
|
|
73
|
-
for (const a of r) {
|
|
74
|
-
const m = e[a], p = o[a];
|
|
75
|
-
if (m && p) {
|
|
76
|
-
const i = f.value, h = [];
|
|
77
|
-
for (let v = 0; v < i.length; v += p)
|
|
78
|
-
h.push(i.slice(v, v + p));
|
|
79
|
-
t.push({ minWidth: m, grid: h, key: a });
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return t.sort((r, a) => r.minWidth - a.minWidth);
|
|
84
|
-
}
|
|
85
34
|
return {
|
|
86
|
-
errors:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
validateAll: U,
|
|
92
|
-
getBreakpointLayouts: x
|
|
35
|
+
errors: d,
|
|
36
|
+
schemaKeys: S,
|
|
37
|
+
onFieldInput: $,
|
|
38
|
+
onFieldBlur: A,
|
|
39
|
+
validateAll: V
|
|
93
40
|
};
|
|
94
41
|
}
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
42
|
+
const Z = {
|
|
43
|
+
sm: 640,
|
|
44
|
+
md: 768,
|
|
45
|
+
lg: 1024,
|
|
46
|
+
xl: 1280,
|
|
47
|
+
"2xl": 1536
|
|
48
|
+
};
|
|
49
|
+
function K(a) {
|
|
50
|
+
return typeof a.default == "number";
|
|
51
|
+
}
|
|
52
|
+
function U(a) {
|
|
53
|
+
return Array.isArray(a.default);
|
|
54
|
+
}
|
|
55
|
+
const tt = ["data-autoform-id"], ot = { class: "autoform-flat-grid" }, et = ["data-field-key"], rt = ["value", "onInput", "onBlur"], nt = /* @__PURE__ */ W({
|
|
102
56
|
__name: "AutoForm",
|
|
103
57
|
props: {
|
|
104
58
|
schema: {},
|
|
@@ -109,197 +63,138 @@ const et = ["data-autoform-id"], rt = {
|
|
|
109
63
|
breakpoints: {}
|
|
110
64
|
},
|
|
111
65
|
emits: ["update:modelValue"],
|
|
112
|
-
setup(
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
if (!e) return {};
|
|
126
|
-
const t = e.props;
|
|
66
|
+
setup(a, { expose: g, emit: k }) {
|
|
67
|
+
const r = a, d = k, S = G(`autoform-${Math.random().toString(36).slice(2, 9)}`), { errors: m, schemaKeys: V, onFieldInput: p, onFieldBlur: $, validateAll: A } = Y(
|
|
68
|
+
r.schema,
|
|
69
|
+
P(r, "modelValue"),
|
|
70
|
+
(e, s) => d(e, s),
|
|
71
|
+
P(r, "validateOn")
|
|
72
|
+
), o = C(
|
|
73
|
+
() => r.layout ? U(r.layout) : !0
|
|
74
|
+
);
|
|
75
|
+
function n(e) {
|
|
76
|
+
const s = r.fields[e];
|
|
77
|
+
if (!s) return {};
|
|
78
|
+
const t = s.props;
|
|
127
79
|
return typeof t == "function" ? t() : t ?? {};
|
|
128
80
|
}
|
|
129
|
-
const
|
|
130
|
-
if (!
|
|
131
|
-
const
|
|
132
|
-
if (
|
|
133
|
-
const
|
|
81
|
+
const i = C(() => {
|
|
82
|
+
if (!r.layout) return "";
|
|
83
|
+
const e = { ...Z, ...r.breakpoints }, s = S.value, t = [];
|
|
84
|
+
if (K(r.layout)) {
|
|
85
|
+
const u = r.layout;
|
|
134
86
|
t.push(
|
|
135
|
-
`[data-autoform-id="${
|
|
136
|
-
` grid-template-columns: repeat(${
|
|
87
|
+
`[data-autoform-id="${s}"] .autoform-flat-grid {`,
|
|
88
|
+
` grid-template-columns: repeat(${u.default}, minmax(0, 1fr));`,
|
|
137
89
|
"}"
|
|
138
90
|
);
|
|
139
|
-
const
|
|
140
|
-
for (const
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
`@media (min-width: ${
|
|
144
|
-
` [data-autoform-id="${
|
|
145
|
-
` grid-template-columns: repeat(${
|
|
91
|
+
const B = Object.keys(u).filter((b) => b !== "default");
|
|
92
|
+
for (const b of B) {
|
|
93
|
+
const E = e[b], l = u[b];
|
|
94
|
+
E && l && t.push(
|
|
95
|
+
`@media (min-width: ${E}px) {`,
|
|
96
|
+
` [data-autoform-id="${s}"] .autoform-flat-grid {`,
|
|
97
|
+
` grid-template-columns: repeat(${l}, minmax(0, 1fr));`,
|
|
146
98
|
" }",
|
|
147
99
|
"}"
|
|
148
100
|
);
|
|
149
101
|
}
|
|
150
|
-
} else if (
|
|
151
|
-
const
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
`[data-autoform-id="${
|
|
155
|
-
),
|
|
156
|
-
|
|
157
|
-
`[data-autoform-id="${
|
|
102
|
+
} else if (U(r.layout)) {
|
|
103
|
+
const u = r.layout, B = (l, h) => {
|
|
104
|
+
const F = Math.max(...l.map((f) => f.length)), _ = V.value, D = new Set(l.flat()), x = [];
|
|
105
|
+
x.push(
|
|
106
|
+
`[data-autoform-id="${s}"] .autoform-flat-grid { grid-template-columns: repeat(${F}, minmax(0, 1fr)); }`
|
|
107
|
+
), _.forEach((f) => {
|
|
108
|
+
D.has(f) || x.push(
|
|
109
|
+
`[data-autoform-id="${s}"] [data-field-key="${f}"] { display: none; }`
|
|
158
110
|
);
|
|
159
111
|
});
|
|
160
|
-
let
|
|
161
|
-
return
|
|
162
|
-
let
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
`[data-autoform-id="${
|
|
166
|
-
),
|
|
167
|
-
}),
|
|
112
|
+
let O = 1;
|
|
113
|
+
return l.forEach((f) => {
|
|
114
|
+
let w = 1;
|
|
115
|
+
f.forEach((R) => {
|
|
116
|
+
x.push(
|
|
117
|
+
`[data-autoform-id="${s}"] [data-field-key="${R}"] { display: block; grid-row: ${O}; grid-column: ${w}; }`
|
|
118
|
+
), w++;
|
|
119
|
+
}), O++;
|
|
168
120
|
}), h ? [
|
|
169
121
|
`@media (min-width: ${h}px) {`,
|
|
170
|
-
...
|
|
122
|
+
...x.map((f) => ` ${f}`),
|
|
171
123
|
"}"
|
|
172
124
|
].join(`
|
|
173
|
-
`) :
|
|
125
|
+
`) : x.join(`
|
|
174
126
|
`);
|
|
175
127
|
};
|
|
176
|
-
t.push(
|
|
177
|
-
const
|
|
178
|
-
(
|
|
128
|
+
t.push(B(u.default));
|
|
129
|
+
const E = Object.keys(u).filter((l) => l !== "default").sort(
|
|
130
|
+
(l, h) => (e[l] ?? 0) - (e[h] ?? 0)
|
|
179
131
|
);
|
|
180
|
-
for (const
|
|
181
|
-
const h =
|
|
182
|
-
h &&
|
|
132
|
+
for (const l of E) {
|
|
133
|
+
const h = e[l], F = u[l];
|
|
134
|
+
h && F && t.push(B(F, String(h)));
|
|
183
135
|
}
|
|
184
136
|
}
|
|
185
137
|
return t.join(`
|
|
186
138
|
`);
|
|
187
139
|
});
|
|
188
|
-
return
|
|
140
|
+
return g({ validateAll: A, errors: m }), (e, s) => (v(), y("div", {
|
|
189
141
|
class: "autoform",
|
|
190
|
-
"data-autoform-id":
|
|
142
|
+
"data-autoform-id": S.value
|
|
191
143
|
}, [
|
|
192
|
-
|
|
193
|
-
default:
|
|
194
|
-
|
|
144
|
+
i.value ? (v(), L(N("style"), { key: 0 }, {
|
|
145
|
+
default: Q(() => [
|
|
146
|
+
q(z(i.value), 1)
|
|
195
147
|
]),
|
|
196
148
|
_: 1
|
|
197
|
-
})) :
|
|
198
|
-
|
|
199
|
-
(
|
|
200
|
-
key: t,
|
|
201
|
-
class: "autoform-cell"
|
|
202
|
-
}, [
|
|
203
|
-
n.fields[t] ? (c(), d(b, { key: 0 }, [
|
|
204
|
-
(c(), L(W(n.fields[t].component), D({
|
|
205
|
-
modelValue: n.modelValue[t],
|
|
206
|
-
error: u(l)[t]
|
|
207
|
-
}, { ref_for: !0 }, j(t), {
|
|
208
|
-
"onUpdate:modelValue": (r) => u(f)(t, r),
|
|
209
|
-
onBlur: () => u(g)(t)
|
|
210
|
-
}), null, 16, ["modelValue", "error", "onUpdate:modelValue", "onBlur"])),
|
|
211
|
-
V(o.$slots, "error", {
|
|
212
|
-
fieldKey: t,
|
|
213
|
-
error: u(l)[t]
|
|
214
|
-
})
|
|
215
|
-
], 64)) : (c(), d(b, { key: 1 }, [
|
|
216
|
-
V(o.$slots, `field-${t}`, {
|
|
217
|
-
fieldKey: t,
|
|
218
|
-
value: n.modelValue[t],
|
|
219
|
-
error: u(l)[t],
|
|
220
|
-
onUpdate: (r) => u(f)(t, r),
|
|
221
|
-
onBlur: () => u(g)(t)
|
|
222
|
-
}, () => [
|
|
223
|
-
M("input", {
|
|
224
|
-
class: "autoform-default-input",
|
|
225
|
-
value: String(n.modelValue[t] ?? ""),
|
|
226
|
-
onInput: (r) => u(f)(t, r.target.value),
|
|
227
|
-
onBlur: () => u(g)(t)
|
|
228
|
-
}, null, 40, at)
|
|
229
|
-
]),
|
|
230
|
-
V(o.$slots, "error", {
|
|
231
|
-
fieldKey: t,
|
|
232
|
-
error: u(l)[t]
|
|
233
|
-
})
|
|
234
|
-
], 64))
|
|
235
|
-
]))), 128))
|
|
236
|
-
])) : (c(), d("div", nt, [
|
|
237
|
-
(c(!0), d(b, null, P(I.value, (t) => (c(), d("div", {
|
|
149
|
+
})) : H("", !0),
|
|
150
|
+
T("div", ot, [
|
|
151
|
+
(v(!0), y(I, null, J(c(V), (t) => (v(), y("div", {
|
|
238
152
|
key: t,
|
|
239
153
|
class: "autoform-cell",
|
|
240
|
-
"data-field-key": t
|
|
154
|
+
"data-field-key": o.value ? t : void 0
|
|
241
155
|
}, [
|
|
242
|
-
|
|
243
|
-
(
|
|
244
|
-
modelValue:
|
|
245
|
-
error:
|
|
246
|
-
}, { ref_for: !0 },
|
|
247
|
-
"onUpdate:modelValue": (
|
|
248
|
-
onBlur: () =>
|
|
156
|
+
a.fields[t] ? (v(), y(I, { key: 0 }, [
|
|
157
|
+
(v(), L(N(a.fields[t].component), X({
|
|
158
|
+
modelValue: a.modelValue[t],
|
|
159
|
+
error: c(m)[t]
|
|
160
|
+
}, { ref_for: !0 }, n(t), {
|
|
161
|
+
"onUpdate:modelValue": (u) => c(p)(t, u),
|
|
162
|
+
onBlur: () => c($)(t)
|
|
249
163
|
}), null, 16, ["modelValue", "error", "onUpdate:modelValue", "onBlur"])),
|
|
250
|
-
|
|
164
|
+
j(e.$slots, "error", {
|
|
251
165
|
fieldKey: t,
|
|
252
|
-
error:
|
|
166
|
+
error: c(m)[t]
|
|
253
167
|
})
|
|
254
|
-
], 64)) : (
|
|
255
|
-
|
|
168
|
+
], 64)) : (v(), y(I, { key: 1 }, [
|
|
169
|
+
j(e.$slots, `field-${t}`, {
|
|
256
170
|
fieldKey: t,
|
|
257
|
-
value:
|
|
258
|
-
error:
|
|
259
|
-
onUpdate: (
|
|
260
|
-
onBlur: () =>
|
|
171
|
+
value: a.modelValue[t],
|
|
172
|
+
error: c(m)[t],
|
|
173
|
+
onUpdate: (u) => c(p)(t, u),
|
|
174
|
+
onBlur: () => c($)(t)
|
|
261
175
|
}, () => [
|
|
262
|
-
|
|
176
|
+
T("input", {
|
|
263
177
|
class: "autoform-default-input",
|
|
264
|
-
value: String(
|
|
265
|
-
onInput: (
|
|
266
|
-
onBlur: () =>
|
|
267
|
-
}, null, 40,
|
|
178
|
+
value: String(a.modelValue[t] ?? ""),
|
|
179
|
+
onInput: (u) => c(p)(t, u.target.value),
|
|
180
|
+
onBlur: () => c($)(t)
|
|
181
|
+
}, null, 40, rt)
|
|
268
182
|
]),
|
|
269
|
-
|
|
183
|
+
j(e.$slots, "error", {
|
|
270
184
|
fieldKey: t,
|
|
271
|
-
error:
|
|
185
|
+
error: c(m)[t]
|
|
272
186
|
})
|
|
273
187
|
], 64))
|
|
274
|
-
], 8,
|
|
275
|
-
])
|
|
276
|
-
], 8,
|
|
277
|
-
}
|
|
278
|
-
}), it = /* @__PURE__ */ z({
|
|
279
|
-
__name: "AutoFormRow",
|
|
280
|
-
props: {
|
|
281
|
-
row: {}
|
|
282
|
-
},
|
|
283
|
-
setup(n) {
|
|
284
|
-
return ($, S) => (c(), d("div", {
|
|
285
|
-
class: "autoform-row",
|
|
286
|
-
style: tt({ "--autoform-cols": n.row.length })
|
|
287
|
-
}, [
|
|
288
|
-
(c(!0), d(b, null, P(n.row, (s) => (c(), d("div", {
|
|
289
|
-
key: s,
|
|
290
|
-
class: "autoform-cell"
|
|
291
|
-
}, [
|
|
292
|
-
V($.$slots, "default", { fieldKey: s })
|
|
293
|
-
]))), 128))
|
|
294
|
-
], 4));
|
|
188
|
+
], 8, et))), 128))
|
|
189
|
+
])
|
|
190
|
+
], 8, tt));
|
|
295
191
|
}
|
|
296
192
|
});
|
|
297
193
|
export {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
ot as useAutoForm
|
|
194
|
+
nt as AutoForm,
|
|
195
|
+
Z as DEFAULT_BREAKPOINTS,
|
|
196
|
+
U as isExplicitLayout,
|
|
197
|
+
K as isShorthandLayout,
|
|
198
|
+
Y as useAutoForm
|
|
304
199
|
};
|
|
305
200
|
//# sourceMappingURL=vue-autoform.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue-autoform.es.js","sources":["../src/types.ts","../src/composables/useAutoForm.ts","../src/components/AutoForm.vue","../src/components/AutoFormRow.vue"],"sourcesContent":["import type { Component } from 'vue'\nimport type { ZodObject, ZodRawShape } from 'zod'\n\nexport type BreakpointKey = 'sm' | 'md' | 'lg' | 'xl' | '2xl'\n\nexport type BreakpointMap = Record<BreakpointKey, number>\n\nexport const DEFAULT_BREAKPOINTS: BreakpointMap = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n '2xl': 1536,\n}\n\nexport interface FieldConfig {\n component: Component\n props?: Record<string, unknown> | (() => Record<string, unknown>)\n [key: string]: unknown\n}\n\nexport type LayoutRow = string[]\n\nexport type LayoutGrid = LayoutRow[]\n\nexport type ShorthandLayout = { default: number } & Partial<Record<BreakpointKey, number>>\n\nexport type ExplicitLayout = { default: LayoutGrid } & Partial<Record<BreakpointKey, LayoutGrid>>\n\nexport type AutoFormLayout = ShorthandLayout | ExplicitLayout\n\nexport function isShorthandLayout(layout: AutoFormLayout): layout is ShorthandLayout {\n return typeof layout.default === 'number'\n}\n\nexport function isExplicitLayout(layout: AutoFormLayout): layout is ExplicitLayout {\n return Array.isArray(layout.default)\n}\n\nexport interface AutoFormProps {\n schema: ZodObject<ZodRawShape>\n layout?: AutoFormLayout\n fields: Record<string, FieldConfig>\n modelValue: Record<string, unknown>\n validateOn?: 'blur' | 'input' | 'submit'\n breakpoints?: Partial<BreakpointMap>\n}\n\nexport interface FieldRenderInfo {\n key: string\n config: FieldConfig | undefined\n value: unknown\n error: string | undefined\n}\n","import { reactive, computed } from 'vue'\nimport type { Ref } from 'vue'\nimport type { ZodObject, ZodRawShape } from 'zod'\nimport type { BreakpointMap, AutoFormLayout, LayoutGrid } from '../types'\nimport {\n DEFAULT_BREAKPOINTS,\n isShorthandLayout,\n isExplicitLayout,\n} from '../types'\n\nexport function useAutoForm(\n schema: ZodObject<ZodRawShape>,\n modelValue: Ref<Record<string, unknown>>,\n emit: (event: 'update:modelValue', value: Record<string, unknown>) => void,\n validateOn: Ref<'blur' | 'input' | 'submit'>,\n layout: Ref<AutoFormLayout | undefined>,\n breakpointsOverride: Ref<Partial<BreakpointMap> | undefined>,\n) {\n const errors = reactive<Record<string, string>>({})\n\n const breakpoints = computed<BreakpointMap>(() => ({\n ...DEFAULT_BREAKPOINTS,\n ...breakpointsOverride.value,\n }))\n\n const schemaKeys = computed<string[]>(() => Object.keys(schema.shape))\n\n const resolvedLayout = computed<LayoutGrid>(() => {\n const l = layout.value\n if (!l) {\n return schemaKeys.value.map((key: string) => [key])\n }\n if (isExplicitLayout(l)) {\n return l.default\n }\n if (isShorthandLayout(l)) {\n const cols = l.default\n const keys = schemaKeys.value\n const rows: LayoutGrid = []\n for (let i = 0; i < keys.length; i += cols) {\n rows.push(keys.slice(i, i + cols))\n }\n return rows\n }\n return schemaKeys.value.map((key: string) => [key])\n })\n\n function validateField(key: string, value: unknown): string | undefined {\n const shape = schema.shape\n if (!shape[key]) return undefined\n const fieldSchema = shape[key]\n const result = fieldSchema.safeParse(value)\n if (!result.success) {\n return result.error.errors[0]?.message ?? 'Invalid value'\n }\n return undefined\n }\n\n function validateAll(): boolean {\n const result = schema.safeParse(modelValue.value)\n if (!result.success) {\n result.error.errors.forEach((err) => {\n const key = String(err.path[0])\n errors[key] = err.message\n })\n return false\n }\n Object.keys(errors).forEach((k: string) => delete errors[k])\n return true\n }\n\n function onFieldInput(key: string, value: unknown) {\n const updated = { ...modelValue.value, [key]: value }\n emit('update:modelValue', updated)\n if (validateOn.value === 'input') {\n const msg = validateField(key, value)\n if (msg) {\n errors[key] = msg\n } else {\n delete errors[key]\n }\n }\n }\n\n function onFieldBlur(key: string) {\n if (validateOn.value === 'blur') {\n const msg = validateField(key, modelValue.value[key])\n if (msg) {\n errors[key] = msg\n } else {\n delete errors[key]\n }\n }\n }\n\n function getBreakpointLayouts(): Array<{ minWidth: number; grid: LayoutGrid; key: string }> {\n const l = layout.value\n if (!l) return []\n\n const bps = breakpoints.value\n const result: Array<{ minWidth: number; grid: LayoutGrid; key: string }> = []\n\n if (isExplicitLayout(l)) {\n const bpKeys = Object.keys(l).filter((k) => k !== 'default') as Array<keyof typeof l>\n for (const bpKey of bpKeys) {\n const minWidth = bps[bpKey as keyof BreakpointMap]\n const grid = l[bpKey as keyof typeof l] as LayoutGrid\n if (minWidth && grid) {\n result.push({ minWidth, grid, key: bpKey })\n }\n }\n } else if (isShorthandLayout(l)) {\n const bpKeys = Object.keys(l).filter((k) => k !== 'default') as Array<keyof typeof l>\n for (const bpKey of bpKeys) {\n const minWidth = bps[bpKey as keyof BreakpointMap]\n const cols = l[bpKey as keyof typeof l] as number\n if (minWidth && cols) {\n const keys = schemaKeys.value\n const rows: LayoutGrid = []\n for (let i = 0; i < keys.length; i += cols) {\n rows.push(keys.slice(i, i + cols))\n }\n result.push({ minWidth, grid: rows, key: bpKey })\n }\n }\n }\n\n return result.sort((a, b) => a.minWidth - b.minWidth)\n }\n\n return {\n errors,\n resolvedLayout,\n schemaKeys,\n onFieldInput,\n onFieldBlur,\n validateAll,\n getBreakpointLayouts,\n }\n}\n","<template>\n <div class=\"autoform\" :data-autoform-id=\"formId\">\n <component :is=\"'style'\" v-if=\"mediaQueryCss\">{{\n mediaQueryCss\n }}</component>\n\n <!-- Shorthand layout: single flat grid, CSS handles column count per breakpoint -->\n <div v-if=\"isShorthand\" class=\"autoform-flat-grid\">\n <div v-for=\"fieldKey in flatKeys\" :key=\"fieldKey\" class=\"autoform-cell\">\n <template v-if=\"fields[fieldKey]\">\n <component\n :is=\"fields[fieldKey].component\"\n :modelValue=\"modelValue[fieldKey]\"\n :error=\"errors[fieldKey]\"\n v-bind=\"resolveProps(fieldKey)\"\n @update:modelValue=\"(val: unknown) => onFieldInput(fieldKey, val)\"\n @blur=\"() => onFieldBlur(fieldKey)\"\n />\n <slot name=\"error\" :fieldKey=\"fieldKey\" :error=\"errors[fieldKey]\" />\n </template>\n <template v-else>\n <slot\n :name=\"`field-${fieldKey}`\"\n :fieldKey=\"fieldKey\"\n :value=\"modelValue[fieldKey]\"\n :error=\"errors[fieldKey]\"\n :onUpdate=\"(val: unknown) => onFieldInput(fieldKey, val)\"\n :onBlur=\"() => onFieldBlur(fieldKey)\"\n >\n <input\n class=\"autoform-default-input\"\n :value=\"String(modelValue[fieldKey] ?? '')\"\n @input=\"\n (e: Event) =>\n onFieldInput(fieldKey, (e.target as HTMLInputElement).value)\n \"\n @blur=\"() => onFieldBlur(fieldKey)\"\n />\n </slot>\n <slot name=\"error\" :fieldKey=\"fieldKey\" :error=\"errors[fieldKey]\" />\n </template>\n </div>\n </div>\n\n <!-- Explicit layout / no layout: flat grid, CSS positions each field per breakpoint -->\n <div v-else class=\"autoform-flat-grid\">\n <div\n v-for=\"fieldKey in flatKeys\"\n :key=\"fieldKey\"\n class=\"autoform-cell\"\n :data-field-key=\"fieldKey\"\n >\n <template v-if=\"fields[fieldKey]\">\n <component\n :is=\"fields[fieldKey].component\"\n :modelValue=\"modelValue[fieldKey]\"\n :error=\"errors[fieldKey]\"\n v-bind=\"resolveProps(fieldKey)\"\n @update:modelValue=\"(val: unknown) => onFieldInput(fieldKey, val)\"\n @blur=\"() => onFieldBlur(fieldKey)\"\n />\n <slot name=\"error\" :fieldKey=\"fieldKey\" :error=\"errors[fieldKey]\" />\n </template>\n <template v-else>\n <slot\n :name=\"`field-${fieldKey}`\"\n :fieldKey=\"fieldKey\"\n :value=\"modelValue[fieldKey]\"\n :error=\"errors[fieldKey]\"\n :onUpdate=\"(val: unknown) => onFieldInput(fieldKey, val)\"\n :onBlur=\"() => onFieldBlur(fieldKey)\"\n >\n <input\n class=\"autoform-default-input\"\n :value=\"String(modelValue[fieldKey] ?? '')\"\n @input=\"\n (e: Event) =>\n onFieldInput(fieldKey, (e.target as HTMLInputElement).value)\n \"\n @blur=\"() => onFieldBlur(fieldKey)\"\n />\n </slot>\n <slot name=\"error\" :fieldKey=\"fieldKey\" :error=\"errors[fieldKey]\" />\n </template>\n </div>\n </div>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, ref, toRef } from \"vue\";\nimport type { ZodObject, ZodRawShape } from \"zod\";\nimport { useAutoForm } from \"../composables/useAutoForm\";\nimport type {\n AutoFormLayout,\n BreakpointMap,\n FieldConfig,\n LayoutGrid,\n} from \"../types\";\nimport {\n isExplicitLayout,\n isShorthandLayout,\n DEFAULT_BREAKPOINTS,\n} from \"../types\";\n\nconst props = withDefaults(\n defineProps<{\n schema: ZodObject<ZodRawShape>;\n layout?: AutoFormLayout;\n fields: Record<string, FieldConfig>;\n modelValue: Record<string, unknown>;\n validateOn?: \"blur\" | \"input\" | \"submit\";\n breakpoints?: Partial<BreakpointMap>;\n }>(),\n {\n validateOn: \"blur\",\n },\n);\n\nconst emit = defineEmits<{\n (e: \"update:modelValue\", value: Record<string, unknown>): void;\n}>();\n\nconst formId = ref(`autoform-${Math.random().toString(36).slice(2, 9)}`);\n\nconst { errors, schemaKeys, onFieldInput, onFieldBlur, validateAll } =\n useAutoForm(\n props.schema,\n toRef(props, \"modelValue\"),\n (_, val) => emit(\"update:modelValue\", val),\n toRef(props, \"validateOn\"),\n toRef(props, \"layout\"),\n toRef(props, \"breakpoints\"),\n );\n\nconst isShorthand = computed(() =>\n props.layout ? isShorthandLayout(props.layout) : false,\n);\n\nconst flatKeys = computed(() => schemaKeys.value);\n\nfunction resolveProps(fieldKey: string): Record<string, unknown> {\n const cfg = props.fields[fieldKey];\n if (!cfg) return {};\n const p = cfg.props;\n return typeof p === \"function\" ? p() : (p ?? {});\n}\n\nconst mediaQueryCss = computed<string>(() => {\n if (!props.layout) return \"\";\n\n const bps: BreakpointMap = { ...DEFAULT_BREAKPOINTS, ...props.breakpoints };\n const id = formId.value;\n const lines: string[] = [];\n\n if (isShorthandLayout(props.layout)) {\n const layout = props.layout;\n // Base columns for the flat grid\n lines.push(\n `[data-autoform-id=\"${id}\"] .autoform-flat-grid {`,\n ` grid-template-columns: repeat(${layout.default}, minmax(0, 1fr));`,\n `}`,\n );\n const bpKeys = Object.keys(layout).filter((k) => k !== \"default\") as Array<\n keyof typeof layout\n >;\n for (const bpKey of bpKeys) {\n const minWidth = bps[bpKey as keyof BreakpointMap];\n const cols = layout[bpKey as keyof typeof layout] as number;\n if (minWidth && cols) {\n lines.push(\n `@media (min-width: ${minWidth}px) {`,\n ` [data-autoform-id=\"${id}\"] .autoform-flat-grid {`,\n ` grid-template-columns: repeat(${cols}, minmax(0, 1fr));`,\n ` }`,\n `}`,\n );\n }\n }\n } else if (isExplicitLayout(props.layout)) {\n const layout = props.layout;\n // Helper: build CSS rules for a given grid at a given scope (media query or base)\n const gridToCss = (grid: LayoutGrid, wrap?: string): string => {\n const maxCols = Math.max(...grid.map((r: string[]) => r.length));\n const allKeys = schemaKeys.value;\n const keysInGrid = new Set(grid.flat());\n const fieldRules: string[] = [];\n\n // Set grid column count\n fieldRules.push(\n `[data-autoform-id=\"${id}\"] .autoform-flat-grid { grid-template-columns: repeat(${maxCols}, minmax(0, 1fr)); }`,\n );\n\n // Hide fields not in this layout\n allKeys.forEach((key: string) => {\n if (!keysInGrid.has(key)) {\n fieldRules.push(\n `[data-autoform-id=\"${id}\"] [data-field-key=\"${key}\"] { display: none; }`,\n );\n }\n });\n\n // Position each field\n let rowStart = 1;\n grid.forEach((row: string[]) => {\n let colStart = 1;\n row.forEach((key: string) => {\n fieldRules.push(\n `[data-autoform-id=\"${id}\"] [data-field-key=\"${key}\"] { display: block; grid-row: ${rowStart}; grid-column: ${colStart}; }`,\n );\n colStart++;\n });\n rowStart++;\n });\n\n if (wrap) {\n return [\n `@media (min-width: ${wrap}px) {`,\n ...fieldRules.map((r) => ` ${r}`),\n `}`,\n ].join(\"\\n\");\n }\n return fieldRules.join(\"\\n\");\n };\n\n // Default layout base styles\n lines.push(gridToCss(layout.default));\n\n // Per-breakpoint overrides\n const bpKeys = Object.keys(layout).filter((k) => k !== \"default\") as Array<\n keyof typeof layout\n >;\n const sortedBpKeys = bpKeys.sort(\n (a, b) =>\n (bps[a as keyof BreakpointMap] ?? 0) -\n (bps[b as keyof BreakpointMap] ?? 0),\n );\n for (const bpKey of sortedBpKeys) {\n const minWidth = bps[bpKey as keyof BreakpointMap];\n const grid = layout[bpKey as keyof typeof layout] as LayoutGrid;\n if (minWidth && grid) {\n lines.push(gridToCss(grid, String(minWidth)));\n }\n }\n }\n\n return lines.join(\"\\n\");\n});\n\ndefineExpose({ validateAll, errors });\n</script>\n\n<style>\n.autoform {\n width: 100%;\n display: flex;\n flex-direction: column;\n gap: var(--autoform-row-gap, 1rem);\n}\n\n.autoform-flat-grid {\n display: grid;\n grid-template-columns: repeat(1, minmax(0, 1fr));\n gap: var(--autoform-gap, 1rem);\n width: 100%;\n}\n\n.autoform-flat-grid .autoform-cell {\n min-width: 0;\n}\n\n.autoform-default-input {\n width: 100%;\n padding: 0.5rem 0.75rem;\n border: 1px solid #d1d5db;\n border-radius: 0.375rem;\n font-size: 1rem;\n outline: none;\n box-sizing: border-box;\n}\n\n.autoform-default-input:focus {\n border-color: #6366f1;\n box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);\n}\n</style>\n","<template>\n <div\n class=\"autoform-row\"\n :style=\"{ '--autoform-cols': row.length }\"\n >\n <div\n v-for=\"fieldKey in row\"\n :key=\"fieldKey\"\n class=\"autoform-cell\"\n >\n <slot :fieldKey=\"fieldKey\" />\n </div>\n </div>\n</template>\n\n<script setup lang=\"ts\">\ndefineProps<{\n row: string[]\n}>()\n</script>\n\n<style>\n.autoform-row {\n display: grid;\n grid-template-columns: repeat(var(--autoform-cols, 1), minmax(0, 1fr));\n gap: var(--autoform-gap, 1rem);\n width: 100%;\n}\n\n.autoform-cell {\n min-width: 0;\n}\n</style>\n"],"names":["DEFAULT_BREAKPOINTS","isShorthandLayout","layout","isExplicitLayout","useAutoForm","schema","modelValue","emit","validateOn","breakpointsOverride","errors","reactive","breakpoints","computed","schemaKeys","resolvedLayout","l","key","cols","keys","rows","i","validateField","value","shape","result","_a","validateAll","k","err","onFieldInput","updated","msg","onFieldBlur","getBreakpointLayouts","bps","bpKeys","bpKey","minWidth","grid","a","b","props","__props","__emit","formId","ref","toRef","_","val","isShorthand","flatKeys","resolveProps","fieldKey","cfg","p","mediaQueryCss","id","lines","gridToCss","wrap","maxCols","r","allKeys","keysInGrid","fieldRules","rowStart","row","colStart","sortedBpKeys","__expose","_createElementBlock","_openBlock","_createBlock","_resolveDynamicComponent","_hoisted_2","_Fragment","_renderList","_mergeProps","_unref","_renderSlot","_ctx","_createElementVNode","e","_hoisted_4","_normalizeStyle"],"mappings":";AAOO,MAAMA,IAAqC;AAAA,EAChD,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,OAAO;AACT;AAkBO,SAASC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AAhD,UAAA5B;AAAA,cAAqB,OAAO0B,EAAArE,CAAA,EAAO2C,CAAQ;AAAA,YAAA;0BAEjEkB,EAoBWK,GAAA,EAAA,KAAA,KAAA;AAAA,YAnBTI,EAiBOC,mBAhBW5B,CAAQ,IAAA;AAAA,cACvB,UAAAA;AAAA,cACA,OAAOV,EAAA,WAAWU,CAAQ;AAAA,cAC1B,OAAO0B,EAAArE,CAAA,EAAO2C,CAAQ;AAAA,cACtB,WAAWJ,MAAiB8B,KAAa1B,GAAUJ,CAAG;AAAA,cACtD,QAAM,MAAQ8B,EAAA9C,CAAA,EAAYoB,CAAQ;AAAA,YAAA,GANrC,MAiBO;AAAA,cATL6B,EAQE,SAAA;AAAA,gBAPA,OAAM;AAAA,gBACL,OAAO,OAAOvC,EAAA,WAAWU,CAAQ,KAAA,EAAA;AAAA,gBACjC,UAAyB8B,MAA+BJ,EAAAjD,CAAA,EAAauB,GAAW8B,EAAE,OAA4B,KAAK;AAAA,gBAInH,QAAI,MAAQJ,EAAA9C,CAAA,EAAYoB,CAAQ;AAAA,cAAA;;YAGrC2B,EAAoEC,EAAA,QAAA,SAAA;AAAA,cAAhD,UAAA5B;AAAA,cAAqB,OAAO0B,EAAArE,CAAA,EAAO2C,CAAQ;AAAA,YAAA;;;;;;;;;;;;2BCjFvEkB,EAWM,OAAA;AAAA,MAVJ,OAAM;AAAA,MACL,OAAKc,GAAA,EAAA,mBAAuB1C,EAAA,IAAI,QAAM;AAAA,IAAA;cAEvC4B,EAMMK,GAAA,MAAAC,EALelC,EAAA,KAAG,CAAfU,YADTkB,EAMM,OAAA;AAAA,QAJH,KAAKlB;AAAA,QACN,OAAM;AAAA,MAAA;QAEN2B,EAA6BC,EAAA,QAAA,WAAA,EAAtB,UAAA5B,GAAkB;AAAA,MAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"vue-autoform.es.js","sources":["../src/composables/useAutoForm.ts","../src/types.ts","../src/components/AutoForm.vue"],"sourcesContent":["import { reactive, computed } from 'vue'\nimport type { Ref } from 'vue'\nimport type { ZodObject, ZodRawShape } from 'zod'\n\nexport function useAutoForm(\n schema: ZodObject<ZodRawShape>,\n modelValue: Ref<Record<string, unknown>>,\n emit: (event: 'update:modelValue', value: Record<string, unknown>) => void,\n validateOn: Ref<'blur' | 'input' | 'submit'>,\n) {\n const errors = reactive<Record<string, string>>({})\n\n const schemaKeys = computed<string[]>(() => Object.keys(schema.shape))\n\n function validateField(key: string, value: unknown): string | undefined {\n const shape = schema.shape\n if (!(key in shape)) return undefined\n const fieldSchema = shape[key]\n const result = fieldSchema.safeParse(value)\n if (!result.success) {\n return result.error.errors[0]?.message ?? 'Invalid value'\n }\n return undefined\n }\n\n function validateAll(): boolean {\n const result = schema.safeParse(modelValue.value)\n if (!result.success) {\n result.error.errors.forEach((err) => {\n const key = String(err.path[0])\n errors[key] = err.message\n })\n return false\n }\n Object.keys(errors).forEach((k: string) => delete errors[k])\n return true\n }\n\n const lastValue: Record<string, unknown> = {}\n\n function onFieldInput(key: string, value: unknown) {\n lastValue[key] = value\n const updated = { ...modelValue.value, [key]: value }\n emit('update:modelValue', updated)\n if (validateOn.value === 'input') {\n const msg = validateField(key, value)\n if (msg) {\n errors[key] = msg\n } else {\n delete errors[key]\n }\n }\n }\n\n function onFieldBlur(key: string) {\n if (validateOn.value === 'blur') {\n // Use lastValue if available — modelValue prop may not have propagated yet\n // when blur fires immediately after update:modelValue (e.g. checkbox toggles)\n const value = key in lastValue ? lastValue[key] : modelValue.value[key]\n const msg = validateField(key, value)\n if (msg) {\n errors[key] = msg\n } else {\n delete errors[key]\n }\n }\n }\n\n return {\n errors,\n schemaKeys,\n onFieldInput,\n onFieldBlur,\n validateAll,\n }\n}\n","import type { Component } from 'vue'\n\nexport type BreakpointKey = 'sm' | 'md' | 'lg' | 'xl' | '2xl'\n\nexport type BreakpointMap = Record<BreakpointKey, number>\n\nexport const DEFAULT_BREAKPOINTS: BreakpointMap = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n '2xl': 1536,\n}\n\nexport interface FieldConfig {\n component: Component\n props?: Record<string, unknown> | (() => Record<string, unknown>)\n}\n\nexport type LayoutRow = string[]\n\nexport type LayoutGrid = LayoutRow[]\n\nexport type ShorthandLayout = { default: number } & Partial<Record<BreakpointKey, number>>\n\nexport type ExplicitLayout = { default: LayoutGrid } & Partial<Record<BreakpointKey, LayoutGrid>>\n\nexport type AutoFormLayout = ShorthandLayout | ExplicitLayout\n\nexport function isShorthandLayout(layout: AutoFormLayout): layout is ShorthandLayout {\n return typeof layout.default === 'number'\n}\n\nexport function isExplicitLayout(layout: AutoFormLayout): layout is ExplicitLayout {\n return Array.isArray(layout.default)\n}\n\nexport interface FieldRenderInfo {\n key: string\n config: FieldConfig | undefined\n value: unknown\n error: string | undefined\n}\n","<template>\n <div class=\"autoform\" :data-autoform-id=\"formId\">\n <component :is=\"'style'\" v-if=\"mediaQueryCss\">{{\n mediaQueryCss\n }}</component>\n\n <!-- Flat grid: CSS handles column count (shorthand) or per-field position (explicit/none) -->\n <div class=\"autoform-flat-grid\">\n <div\n v-for=\"fieldKey in schemaKeys\"\n :key=\"fieldKey\"\n class=\"autoform-cell\"\n :data-field-key=\"isExplicit ? fieldKey : undefined\"\n >\n <template v-if=\"fields[fieldKey]\">\n <component\n :is=\"fields[fieldKey].component\"\n :modelValue=\"modelValue[fieldKey]\"\n :error=\"errors[fieldKey]\"\n v-bind=\"resolveProps(fieldKey)\"\n @update:modelValue=\"(val: unknown) => onFieldInput(fieldKey, val)\"\n @blur=\"() => onFieldBlur(fieldKey)\"\n />\n <slot name=\"error\" :fieldKey=\"fieldKey\" :error=\"errors[fieldKey]\" />\n </template>\n <template v-else>\n <slot\n :name=\"`field-${fieldKey}`\"\n :fieldKey=\"fieldKey\"\n :value=\"modelValue[fieldKey]\"\n :error=\"errors[fieldKey]\"\n :onUpdate=\"(val: unknown) => onFieldInput(fieldKey, val)\"\n :onBlur=\"() => onFieldBlur(fieldKey)\"\n >\n <input\n class=\"autoform-default-input\"\n :value=\"String(modelValue[fieldKey] ?? '')\"\n @input=\"\n (e: Event) =>\n onFieldInput(fieldKey, (e.target as HTMLInputElement).value)\n \"\n @blur=\"() => onFieldBlur(fieldKey)\"\n />\n </slot>\n <slot name=\"error\" :fieldKey=\"fieldKey\" :error=\"errors[fieldKey]\" />\n </template>\n </div>\n </div>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, ref, toRef } from \"vue\";\nimport type { ZodObject, ZodRawShape } from \"zod\";\nimport { useAutoForm } from \"../composables/useAutoForm\";\nimport type {\n AutoFormLayout,\n BreakpointMap,\n FieldConfig,\n LayoutGrid,\n} from \"../types\";\nimport {\n isExplicitLayout,\n isShorthandLayout,\n DEFAULT_BREAKPOINTS,\n} from \"../types\";\n\nconst props = withDefaults(\n defineProps<{\n schema: ZodObject<ZodRawShape>;\n layout?: AutoFormLayout;\n fields: Record<string, FieldConfig>;\n modelValue: Record<string, unknown>;\n validateOn?: \"blur\" | \"input\" | \"submit\";\n breakpoints?: Partial<BreakpointMap>;\n }>(),\n {\n validateOn: \"blur\",\n },\n);\n\nconst emit = defineEmits<{\n (e: \"update:modelValue\", value: Record<string, unknown>): void;\n}>();\n\nconst formId = ref(`autoform-${Math.random().toString(36).slice(2, 9)}`);\n\nconst { errors, schemaKeys, onFieldInput, onFieldBlur, validateAll } =\n useAutoForm(\n props.schema,\n toRef(props, \"modelValue\"),\n (event, val) => emit(event, val),\n toRef(props, \"validateOn\"),\n );\n\nconst isExplicit = computed(() =>\n props.layout ? isExplicitLayout(props.layout) : true,\n);\n\nfunction resolveProps(fieldKey: string): Record<string, unknown> {\n const cfg = props.fields[fieldKey];\n if (!cfg) return {};\n const p = cfg.props;\n return typeof p === \"function\" ? p() : (p ?? {});\n}\n\nconst mediaQueryCss = computed<string>(() => {\n if (!props.layout) return \"\";\n\n const bps: BreakpointMap = { ...DEFAULT_BREAKPOINTS, ...props.breakpoints };\n const id = formId.value;\n const lines: string[] = [];\n\n if (isShorthandLayout(props.layout)) {\n const layout = props.layout;\n // Base columns for the flat grid\n lines.push(\n `[data-autoform-id=\"${id}\"] .autoform-flat-grid {`,\n ` grid-template-columns: repeat(${layout.default}, minmax(0, 1fr));`,\n `}`,\n );\n const bpKeys = Object.keys(layout).filter((k) => k !== \"default\") as Array<\n keyof typeof layout\n >;\n for (const bpKey of bpKeys) {\n const minWidth = bps[bpKey as keyof BreakpointMap];\n const cols = layout[bpKey as keyof typeof layout] as number;\n if (minWidth && cols) {\n lines.push(\n `@media (min-width: ${minWidth}px) {`,\n ` [data-autoform-id=\"${id}\"] .autoform-flat-grid {`,\n ` grid-template-columns: repeat(${cols}, minmax(0, 1fr));`,\n ` }`,\n `}`,\n );\n }\n }\n } else if (isExplicitLayout(props.layout)) {\n const layout = props.layout;\n // Helper: build CSS rules for a given grid at a given scope (media query or base)\n const gridToCss = (grid: LayoutGrid, wrap?: string): string => {\n const maxCols = Math.max(...grid.map((r: string[]) => r.length));\n const allKeys = schemaKeys.value;\n const keysInGrid = new Set(grid.flat());\n const fieldRules: string[] = [];\n\n // Set grid column count\n fieldRules.push(\n `[data-autoform-id=\"${id}\"] .autoform-flat-grid { grid-template-columns: repeat(${maxCols}, minmax(0, 1fr)); }`,\n );\n\n // Hide fields not in this layout\n allKeys.forEach((key: string) => {\n if (!keysInGrid.has(key)) {\n fieldRules.push(\n `[data-autoform-id=\"${id}\"] [data-field-key=\"${key}\"] { display: none; }`,\n );\n }\n });\n\n // Position each field\n let rowStart = 1;\n grid.forEach((row: string[]) => {\n let colStart = 1;\n row.forEach((key: string) => {\n fieldRules.push(\n `[data-autoform-id=\"${id}\"] [data-field-key=\"${key}\"] { display: block; grid-row: ${rowStart}; grid-column: ${colStart}; }`,\n );\n colStart++;\n });\n rowStart++;\n });\n\n if (wrap) {\n return [\n `@media (min-width: ${wrap}px) {`,\n ...fieldRules.map((r) => ` ${r}`),\n `}`,\n ].join(\"\\n\");\n }\n return fieldRules.join(\"\\n\");\n };\n\n // Default layout base styles\n lines.push(gridToCss(layout.default));\n\n // Per-breakpoint overrides\n const bpKeys = Object.keys(layout).filter((k) => k !== \"default\") as Array<\n keyof typeof layout\n >;\n const sortedBpKeys = bpKeys.sort(\n (a, b) =>\n (bps[a as keyof BreakpointMap] ?? 0) -\n (bps[b as keyof BreakpointMap] ?? 0),\n );\n for (const bpKey of sortedBpKeys) {\n const minWidth = bps[bpKey as keyof BreakpointMap];\n const grid = layout[bpKey as keyof typeof layout] as LayoutGrid;\n if (minWidth && grid) {\n lines.push(gridToCss(grid, String(minWidth)));\n }\n }\n }\n\n return lines.join(\"\\n\");\n});\n\ndefineExpose({ validateAll, errors });\n</script>\n\n<style>\n.autoform {\n width: 100%;\n}\n\n.autoform-flat-grid {\n display: grid;\n grid-template-columns: repeat(1, minmax(0, 1fr));\n column-gap: var(--autoform-gap, 1rem);\n row-gap: var(--autoform-row-gap, 1rem);\n width: 100%;\n}\n\n.autoform-flat-grid .autoform-cell {\n min-width: 0;\n}\n\n.autoform-default-input {\n width: 100%;\n padding: 0.5rem 0.75rem;\n border: 1px solid #d1d5db;\n border-radius: 0.375rem;\n font-size: 1rem;\n outline: none;\n box-sizing: border-box;\n}\n\n.autoform-default-input:focus {\n border-color: #6366f1;\n box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);\n}\n</style>\n"],"names":["useAutoForm","schema","modelValue","emit","validateOn","errors","reactive","schemaKeys","computed","validateField","key","value","shape","result","_a","validateAll","k","err","lastValue","onFieldInput","updated","msg","onFieldBlur","DEFAULT_BREAKPOINTS","isShorthandLayout","layout","isExplicitLayout","props","__props","__emit","formId","ref","toRef","event","val","isExplicit","resolveProps","fieldKey","cfg","p","mediaQueryCss","bps","id","lines","bpKeys","bpKey","minWidth","cols","gridToCss","grid","wrap","maxCols","r","allKeys","keysInGrid","fieldRules","rowStart","row","colStart","sortedBpKeys","a","b","__expose","_createElementBlock","_openBlock","_createBlock","_resolveDynamicComponent","_createElementVNode","_hoisted_2","_Fragment","_renderList","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