pdyform 2.2.0 → 2.2.1
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/package.json +1 -1
- package/packages/core/dist/{chunk-KA6QUMVR.js → chunk-B7OMM2UC.js} +2 -0
- package/packages/core/dist/{chunk-REHKL5VH.js → chunk-J6ESJZ4U.js} +18 -12
- package/packages/core/dist/formState.cjs +19 -11
- package/packages/core/dist/formState.js +2 -2
- package/packages/core/dist/index.cjs +19 -11
- package/packages/core/dist/index.js +2 -2
- package/packages/core/dist/utils.cjs +2 -0
- package/packages/core/dist/utils.js +1 -1
- package/packages/react/dist/index.cjs +1 -1
- package/packages/react/dist/index.js +1 -1
- package/packages/vue/dist/index.js +1 -1
- package/packages/vue/dist/index.mjs +111 -106
package/package.json
CHANGED
|
@@ -133,6 +133,8 @@ async function validateForm(fields, values, resolver, customMessages) {
|
|
|
133
133
|
}
|
|
134
134
|
const validationPromises = fields.map(async (field) => {
|
|
135
135
|
if (errors[field.name]) return;
|
|
136
|
+
const isHidden = typeof field.hidden === "function" ? field.hidden(values) : field.hidden;
|
|
137
|
+
if (isHidden) return;
|
|
136
138
|
const error = await validateField(get(values, field.name), field, customMessages);
|
|
137
139
|
if (error) errors[field.name] = error;
|
|
138
140
|
});
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
set,
|
|
6
6
|
validateFieldByName,
|
|
7
7
|
validateForm
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-B7OMM2UC.js";
|
|
9
9
|
|
|
10
10
|
// src/formState.ts
|
|
11
11
|
import { createStore } from "zustand/vanilla";
|
|
@@ -19,20 +19,26 @@ function createFormStore(fields, resolver, errorMessages) {
|
|
|
19
19
|
const field = fields.find((f) => f.name === name);
|
|
20
20
|
const normalizedValue = field ? normalizeFieldValue(field, rawValue) : rawValue;
|
|
21
21
|
set2((state) => ({
|
|
22
|
-
values: set(state.values, name, normalizedValue)
|
|
23
|
-
validatingFields: [...state.validatingFields, name]
|
|
22
|
+
values: set(state.values, name, normalizedValue)
|
|
24
23
|
}));
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
const hasExistingError = !!getStore().errors[name];
|
|
25
|
+
const shouldValidateImmediately = field && ["select", "checkbox", "radio", "switch", "date"].includes(field.type);
|
|
26
|
+
if (shouldValidateImmediately || hasExistingError) {
|
|
28
27
|
set2((state) => ({
|
|
29
|
-
|
|
30
|
-
validatingFields: state.validatingFields.filter((f) => f !== name)
|
|
31
|
-
}));
|
|
32
|
-
} catch (err) {
|
|
33
|
-
set2((state) => ({
|
|
34
|
-
validatingFields: state.validatingFields.filter((f) => f !== name)
|
|
28
|
+
validatingFields: [...state.validatingFields, name]
|
|
35
29
|
}));
|
|
30
|
+
try {
|
|
31
|
+
const currentValues = getStore().values;
|
|
32
|
+
const error = await validateFieldByName(fields, name, normalizedValue, resolver, currentValues, errorMessages);
|
|
33
|
+
set2((state) => ({
|
|
34
|
+
errors: { ...state.errors, [name]: error || "" },
|
|
35
|
+
validatingFields: state.validatingFields.filter((f) => f !== name)
|
|
36
|
+
}));
|
|
37
|
+
} catch (err) {
|
|
38
|
+
set2((state) => ({
|
|
39
|
+
validatingFields: state.validatingFields.filter((f) => f !== name)
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
36
42
|
}
|
|
37
43
|
},
|
|
38
44
|
setFieldBlur: async (name) => {
|
|
@@ -160,6 +160,8 @@ async function validateForm(fields, values, resolver, customMessages) {
|
|
|
160
160
|
}
|
|
161
161
|
const validationPromises = fields.map(async (field) => {
|
|
162
162
|
if (errors[field.name]) return;
|
|
163
|
+
const isHidden = typeof field.hidden === "function" ? field.hidden(values) : field.hidden;
|
|
164
|
+
if (isHidden) return;
|
|
163
165
|
const error = await validateField(get(values, field.name), field, customMessages);
|
|
164
166
|
if (error) errors[field.name] = error;
|
|
165
167
|
});
|
|
@@ -184,20 +186,26 @@ function createFormStore(fields, resolver, errorMessages) {
|
|
|
184
186
|
const field = fields.find((f) => f.name === name);
|
|
185
187
|
const normalizedValue = field ? normalizeFieldValue(field, rawValue) : rawValue;
|
|
186
188
|
set2((state) => ({
|
|
187
|
-
values: set(state.values, name, normalizedValue)
|
|
188
|
-
validatingFields: [...state.validatingFields, name]
|
|
189
|
+
values: set(state.values, name, normalizedValue)
|
|
189
190
|
}));
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
set2((state) => ({
|
|
194
|
-
errors: { ...state.errors, [name]: error || "" },
|
|
195
|
-
validatingFields: state.validatingFields.filter((f) => f !== name)
|
|
196
|
-
}));
|
|
197
|
-
} catch (err) {
|
|
191
|
+
const hasExistingError = !!getStore().errors[name];
|
|
192
|
+
const shouldValidateImmediately = field && ["select", "checkbox", "radio", "switch", "date"].includes(field.type);
|
|
193
|
+
if (shouldValidateImmediately || hasExistingError) {
|
|
198
194
|
set2((state) => ({
|
|
199
|
-
validatingFields: state.validatingFields
|
|
195
|
+
validatingFields: [...state.validatingFields, name]
|
|
200
196
|
}));
|
|
197
|
+
try {
|
|
198
|
+
const currentValues = getStore().values;
|
|
199
|
+
const error = await validateFieldByName(fields, name, normalizedValue, resolver, currentValues, errorMessages);
|
|
200
|
+
set2((state) => ({
|
|
201
|
+
errors: { ...state.errors, [name]: error || "" },
|
|
202
|
+
validatingFields: state.validatingFields.filter((f) => f !== name)
|
|
203
|
+
}));
|
|
204
|
+
} catch (err) {
|
|
205
|
+
set2((state) => ({
|
|
206
|
+
validatingFields: state.validatingFields.filter((f) => f !== name)
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
201
209
|
}
|
|
202
210
|
},
|
|
203
211
|
setFieldBlur: async (name) => {
|
|
@@ -167,6 +167,8 @@ async function validateForm(fields, values, resolver, customMessages) {
|
|
|
167
167
|
}
|
|
168
168
|
const validationPromises = fields.map(async (field) => {
|
|
169
169
|
if (errors[field.name]) return;
|
|
170
|
+
const isHidden = typeof field.hidden === "function" ? field.hidden(values) : field.hidden;
|
|
171
|
+
if (isHidden) return;
|
|
170
172
|
const error = await validateField(get(values, field.name), field, customMessages);
|
|
171
173
|
if (error) errors[field.name] = error;
|
|
172
174
|
});
|
|
@@ -192,20 +194,26 @@ function createFormStore(fields, resolver, errorMessages) {
|
|
|
192
194
|
const field = fields.find((f) => f.name === name);
|
|
193
195
|
const normalizedValue = field ? normalizeFieldValue(field, rawValue) : rawValue;
|
|
194
196
|
set2((state) => ({
|
|
195
|
-
values: set(state.values, name, normalizedValue)
|
|
196
|
-
validatingFields: [...state.validatingFields, name]
|
|
197
|
+
values: set(state.values, name, normalizedValue)
|
|
197
198
|
}));
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
set2((state) => ({
|
|
202
|
-
errors: { ...state.errors, [name]: error || "" },
|
|
203
|
-
validatingFields: state.validatingFields.filter((f) => f !== name)
|
|
204
|
-
}));
|
|
205
|
-
} catch (err) {
|
|
199
|
+
const hasExistingError = !!getStore().errors[name];
|
|
200
|
+
const shouldValidateImmediately = field && ["select", "checkbox", "radio", "switch", "date"].includes(field.type);
|
|
201
|
+
if (shouldValidateImmediately || hasExistingError) {
|
|
206
202
|
set2((state) => ({
|
|
207
|
-
validatingFields: state.validatingFields
|
|
203
|
+
validatingFields: [...state.validatingFields, name]
|
|
208
204
|
}));
|
|
205
|
+
try {
|
|
206
|
+
const currentValues = getStore().values;
|
|
207
|
+
const error = await validateFieldByName(fields, name, normalizedValue, resolver, currentValues, errorMessages);
|
|
208
|
+
set2((state) => ({
|
|
209
|
+
errors: { ...state.errors, [name]: error || "" },
|
|
210
|
+
validatingFields: state.validatingFields.filter((f) => f !== name)
|
|
211
|
+
}));
|
|
212
|
+
} catch (err) {
|
|
213
|
+
set2((state) => ({
|
|
214
|
+
validatingFields: state.validatingFields.filter((f) => f !== name)
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
209
217
|
}
|
|
210
218
|
},
|
|
211
219
|
setFieldBlur: async (name) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createFormStore
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-J6ESJZ4U.js";
|
|
4
4
|
import "./chunk-6F4PWJZI.js";
|
|
5
5
|
import {
|
|
6
6
|
defaultErrorMessages,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
validateField,
|
|
12
12
|
validateFieldByName,
|
|
13
13
|
validateForm
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-B7OMM2UC.js";
|
|
15
15
|
export {
|
|
16
16
|
createFormStore,
|
|
17
17
|
defaultErrorMessages,
|
|
@@ -164,6 +164,8 @@ async function validateForm(fields, values, resolver, customMessages) {
|
|
|
164
164
|
}
|
|
165
165
|
const validationPromises = fields.map(async (field) => {
|
|
166
166
|
if (errors[field.name]) return;
|
|
167
|
+
const isHidden = typeof field.hidden === "function" ? field.hidden(values) : field.hidden;
|
|
168
|
+
if (isHidden) return;
|
|
167
169
|
const error = await validateField(get(values, field.name), field, customMessages);
|
|
168
170
|
if (error) errors[field.name] = error;
|
|
169
171
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Ve=Object.create;var q=Object.defineProperty;var Ge=Object.getOwnPropertyDescriptor;var Ee=Object.getOwnPropertyNames;var Le=Object.getPrototypeOf,Me=Object.prototype.hasOwnProperty;var Be=(e,t)=>{for(var r in t)q(e,r,{get:t[r],enumerable:!0})},le=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ee(t))!Me.call(e,o)&&o!==r&&q(e,o,{get:()=>t[o],enumerable:!(i=Ge(t,o))||i.enumerable});return e};var u=(e,t,r)=>(r=e!=null?Ve(Le(e)):{},le(t||!e||!e.__esModule?q(r,"default",{value:e,enumerable:!0}):r,e)),$e=e=>le(q({},"__esModule",{value:!0}),e);var Ke={};Be(Ke,{Checkbox:()=>G,CheckboxRenderer:()=>Y,DateRenderer:()=>_,DynamicForm:()=>Je,FormFieldRenderer:()=>ne,Input:()=>w,InputRenderer:()=>R,Label:()=>b,RadioGroup:()=>B,RadioGroupItem:()=>$,RadioRenderer:()=>Z,Select:()=>O,SelectContent:()=>A,SelectGroup:()=>J,SelectItem:()=>W,SelectRenderer:()=>X,SelectTrigger:()=>D,SelectValue:()=>K,Switch:()=>L,SwitchRenderer:()=>j,Textarea:()=>T,TextareaRenderer:()=>Q,defaultComponentMap:()=>ee,useForm:()=>se});module.exports=$e(Ke);var Ne=require("pdyform-core");var ce=u(require("react"),1);var de=require("clsx"),me=require("tailwind-merge");function l(...e){return(0,me.twMerge)((0,de.clsx)(e))}var pe=require("react/jsx-runtime"),w=ce.forwardRef(({className:e,type:t,...r},i)=>(0,pe.jsx)("input",{type:t,className:l("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:i,...r}));w.displayName="Input";var fe=u(require("react"),1);var ue=require("react/jsx-runtime"),T=fe.forwardRef(({className:e,...t},r)=>(0,ue.jsx)("textarea",{className:l("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:r,...t}));T.displayName="Textarea";var be=u(require("react"),1),V=u(require("@radix-ui/react-checkbox"),1),Re=require("lucide-react");var H=require("react/jsx-runtime"),G=be.forwardRef(({className:e,...t},r)=>(0,H.jsx)(V.Root,{ref:r,className:l("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",e),...t,children:(0,H.jsx)(V.Indicator,{className:l("flex items-center justify-center text-current"),children:(0,H.jsx)(Re.Check,{className:"h-4 w-4"})})}));G.displayName=V.Root.displayName;var ve=u(require("react"),1),E=u(require("@radix-ui/react-switch"),1);var re=require("react/jsx-runtime"),L=ve.forwardRef(({className:e,...t},r)=>(0,re.jsx)(E.Root,{className:l("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:r,children:(0,re.jsx)(E.Thumb,{className:l("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));L.displayName=E.Root.displayName;var oe=u(require("react"),1),x=u(require("@radix-ui/react-radio-group"),1),ge=require("lucide-react");var M=require("react/jsx-runtime"),B=oe.forwardRef(({className:e,...t},r)=>(0,M.jsx)(x.Root,{className:l("grid gap-2",e),...t,ref:r}));B.displayName=x.Root.displayName;var $=oe.forwardRef(({className:e,...t},r)=>(0,M.jsx)(x.Item,{ref:r,className:l("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:(0,M.jsx)(x.Indicator,{className:"flex items-center justify-center",children:(0,M.jsx)(ge.Circle,{className:"h-2.5 w-2.5 fill-current text-current"})})}));$.displayName=x.Item.displayName;var U=u(require("react"),1),a=u(require("@radix-ui/react-select"),1),z=require("lucide-react");var f=require("react/jsx-runtime"),O=a.Root,J=a.Group,K=a.Value,D=U.forwardRef(({className:e,children:t,...r},i)=>(0,f.jsxs)(a.Trigger,{ref:i,className:l("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),...r,children:[t,(0,f.jsx)(a.Icon,{asChild:!0,children:(0,f.jsx)(z.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));D.displayName=a.Trigger.displayName;var A=U.forwardRef(({className:e,children:t,position:r="popper",...i},o)=>(0,f.jsx)(a.Portal,{children:(0,f.jsx)(a.Content,{ref:o,className:l("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",r==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:r,...i,children:(0,f.jsx)(a.Viewport,{className:l("p-1",r==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t})})}));A.displayName=a.Content.displayName;var W=U.forwardRef(({className:e,children:t,...r},i)=>(0,f.jsxs)(a.Item,{ref:i,className:l("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...r,children:[(0,f.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,f.jsx)(a.ItemIndicator,{children:(0,f.jsx)(z.Check,{className:"h-4 w-4"})})}),(0,f.jsx)(a.ItemText,{children:t})]}));W.displayName=a.Item.displayName;var xe=u(require("react"),1),ie=u(require("@radix-ui/react-label"),1),ye=require("class-variance-authority");var he=require("react/jsx-runtime"),De=(0,ye.cva)("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),b=xe.forwardRef(({className:e,...t},r)=>(0,he.jsx)(ie.Root,{ref:r,className:l(De(),e),...t}));b.displayName=ie.Root.displayName;var Se=require("pdyform-core");var Ce=require("react/jsx-runtime"),Ae=({field:e,value:t,onChange:r,onBlur:i,fieldId:o,ariaInvalid:n,ariaRequired:s,ariaDescribedBy:d})=>{let c=p=>{r((0,Se.normalizeFieldValue)(e,p))};return(0,Ce.jsx)(w,{id:o,type:e.type,placeholder:e.placeholder,value:t??"",onChange:p=>c(p.target.value),onBlur:i,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,"aria-invalid":n,"aria-required":s,"aria-describedby":d})},R=Ae;var Fe=require("react/jsx-runtime"),We=({field:e,value:t,onChange:r,onBlur:i,fieldId:o})=>(0,Fe.jsx)(T,{id:o,placeholder:e.placeholder,value:t??"",onChange:n=>r(n.target.value),onBlur:i,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name}),Q=We;var y=require("react/jsx-runtime"),qe=({field:e,value:t,onChange:r,onBlur:i,fieldId:o})=>(0,y.jsxs)(O,{value:t!=null?String(t):"",onValueChange:r,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,children:[(0,y.jsx)(D,{id:o,onBlur:i,children:(0,y.jsx)(K,{placeholder:e.placeholder||"Select an option"})}),(0,y.jsx)(A,{children:(0,y.jsx)(J,{children:e.options?.map(n=>(0,y.jsx)(W,{value:String(n.value),children:n.label},n.value))})})]}),X=qe;var N=require("react/jsx-runtime"),He=({field:e,value:t,onChange:r,onBlur:i})=>(0,N.jsx)("div",{className:"flex flex-wrap gap-4",children:e.options?.map(o=>{let n=Array.isArray(t)&&t.includes(o.value);return(0,N.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,N.jsx)(G,{id:`checkbox-${e.name}-${o.value}`,checked:n,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,onCheckedChange:s=>{let d=Array.isArray(t)?[...t]:[];if(s)d.push(o.value);else{let c=d.indexOf(o.value);c>-1&&d.splice(c,1)}r(d)},onBlur:i}),(0,N.jsx)(b,{htmlFor:`checkbox-${e.name}-${o.value}`,className:"font-normal",children:o.label})]},o.value)})}),Y=He;var I=require("react/jsx-runtime"),Ue=({field:e,value:t,onChange:r,onBlur:i})=>(0,I.jsx)(B,{value:t!=null?String(t):"",onValueChange:r,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,className:"flex flex-wrap gap-4",children:e.options?.map(o=>(0,I.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,I.jsx)($,{value:String(o.value),id:`radio-${e.name}-${o.value}`,onBlur:i}),(0,I.jsx)(b,{htmlFor:`radio-${e.name}-${o.value}`,className:"font-normal",children:o.label})]},o.value))}),Z=Ue;var Pe=require("react/jsx-runtime"),ze=({field:e,value:t,onChange:r,onBlur:i,fieldId:o,ariaInvalid:n,ariaRequired:s,ariaDescribedBy:d})=>(0,Pe.jsx)(w,{id:o,type:"date",value:t??"",onChange:c=>r(c.target.value),onBlur:i,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,"aria-invalid":n,"aria-required":s,"aria-describedby":d}),_=ze;var ae=require("react/jsx-runtime"),Oe=({field:e,value:t,onChange:r,onBlur:i,fieldId:o,ariaInvalid:n,ariaRequired:s,ariaDescribedBy:d})=>(0,ae.jsx)("div",{className:"flex items-center space-x-2",children:(0,ae.jsx)(L,{id:o,checked:!!t,onCheckedChange:r,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,"aria-invalid":n,"aria-required":s,"aria-describedby":d})}),j=Oe;var ee={text:R,number:R,password:R,email:R,textarea:Q,select:X,checkbox:Y,radio:Z,date:_,switch:j};var h=require("react/jsx-runtime"),ne=({field:e,value:t,onChange:r,onBlur:i,error:o,componentMap:n})=>{let{label:s,description:d,name:c,type:p,validations:m}=e,v=`field-${c}`,F=`${v}-description`,P=`${v}-error`,g=m?.some(Te=>Te.type==="required"),Ie=(n?{...ee,...n}:ee)[p]??R,ke=[d?F:null,o?P:null].filter(Boolean).join(" ");return(0,h.jsxs)("div",{className:`space-y-2 ${e.className||""}`,children:[s&&(0,h.jsxs)(b,{htmlFor:v,className:g?"flex items-center gap-1":"",children:[s,g&&(0,h.jsx)("span",{className:"text-destructive",children:"*"})]}),(0,h.jsx)(Ie,{field:e,value:t,onChange:r,onBlur:i,fieldId:v,errorId:P,descriptionId:F,ariaInvalid:!!o,ariaRequired:g,ariaDescribedBy:ke||void 0}),d&&(0,h.jsx)("p",{id:F,className:"text-[0.8rem] text-muted-foreground",children:d}),o&&(0,h.jsx)("p",{id:P,className:"text-[0.8rem] font-medium text-destructive",children:o})]})};var S=require("react"),we=require("zustand"),te=require("pdyform-core");function se({schema:e}){let t=(0,S.useMemo)(()=>(0,te.createFormStore)(e.fields,e.resolver,e.errorMessages),[e]),r=(0,we.useStore)(t),i=(0,S.useCallback)(async(c,p)=>{await t.getState().setFieldValue(c,p)},[t]),o=(0,S.useCallback)(c=>(0,te.get)(t.getState().values,c),[t]),n=(0,S.useCallback)((c,p)=>{t.setState(m=>({errors:{...m.errors,[c]:p}}))},[t]),s=(0,S.useCallback)(async()=>{let{hasError:c,state:p}=await t.getState().runSubmitValidation();return{hasError:c,values:p.values,state:p}},[t]),d=(0,S.useCallback)(()=>{t.setState({values:{},errors:{},isSubmitting:!1})},[t]);return{store:t,state:r,setValue:i,getValue:o,setError:n,validate:s,reset:d}}var C=require("react/jsx-runtime"),Je=({schema:e,onSubmit:t,className:r,form:i})=>{let o=se({schema:e}),n=i||o,{state:s,store:d}=n,c=async m=>{m.preventDefault();let{hasError:v,values:F,state:P}=await n.validate();if(v){let g=e.fields.find(k=>P.errors[k.name]);if(g){let k=document.getElementById(`field-${g.name}`);k?.focus(),k?.scrollIntoView({behavior:"smooth",block:"center"})}return}t(F)},p=s.validatingFields.length>0;return(0,C.jsxs)("form",{onSubmit:c,className:`space-y-6 ${r||""}`,children:[e.title&&(0,C.jsx)("h2",{className:"text-2xl font-bold tracking-tight",children:e.title}),e.description&&(0,C.jsx)("p",{className:"text-muted-foreground",children:e.description}),(0,C.jsx)("div",{className:"space-y-4",children:e.fields.map(m=>{let v=typeof m.hidden=="function"?m.hidden(s.values):m.hidden,F=typeof m.disabled=="function"?m.disabled(s.values):m.disabled,P=s.validatingFields.includes(m.name);return!v&&(0,C.jsx)(ne,{field:{...m,disabled:F||P},value:(0,Ne.get)(s.values,m.name),onChange:g=>d.getState().setFieldValue(m.name,g),onBlur:()=>d.getState().setFieldBlur(m.name),error:s.errors[m.name]},m.name)})}),(0,C.jsx)("button",{type:"submit",disabled:s.isSubmitting||p,className:"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2 w-full",children:s.isSubmitting?"Submitting...":p?"Validating...":e.submitButtonText||"Submit"})]})};0&&(module.exports={Checkbox,CheckboxRenderer,DateRenderer,DynamicForm,FormFieldRenderer,Input,InputRenderer,Label,RadioGroup,RadioGroupItem,RadioRenderer,Select,SelectContent,SelectGroup,SelectItem,SelectRenderer,SelectTrigger,SelectValue,Switch,SwitchRenderer,Textarea,TextareaRenderer,defaultComponentMap,useForm});
|
|
1
|
+
"use strict";var Ve=Object.create;var W=Object.defineProperty;var Ge=Object.getOwnPropertyDescriptor;var Ee=Object.getOwnPropertyNames;var Le=Object.getPrototypeOf,Me=Object.prototype.hasOwnProperty;var Be=(e,t)=>{for(var r in t)W(e,r,{get:t[r],enumerable:!0})},de=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ee(t))!Me.call(e,o)&&o!==r&&W(e,o,{get:()=>t[o],enumerable:!(i=Ge(t,o))||i.enumerable});return e};var u=(e,t,r)=>(r=e!=null?Ve(Le(e)):{},de(t||!e||!e.__esModule?W(r,"default",{value:e,enumerable:!0}):r,e)),$e=e=>de(W({},"__esModule",{value:!0}),e);var Ke={};Be(Ke,{Checkbox:()=>G,CheckboxRenderer:()=>Y,DateRenderer:()=>_,DynamicForm:()=>Je,FormFieldRenderer:()=>ne,Input:()=>N,InputRenderer:()=>v,Label:()=>R,RadioGroup:()=>B,RadioGroupItem:()=>$,RadioRenderer:()=>Z,Select:()=>O,SelectContent:()=>A,SelectGroup:()=>J,SelectItem:()=>H,SelectRenderer:()=>X,SelectTrigger:()=>D,SelectValue:()=>K,Switch:()=>L,SwitchRenderer:()=>j,Textarea:()=>T,TextareaRenderer:()=>Q,defaultComponentMap:()=>ee,useForm:()=>se});module.exports=$e(Ke);var Ie=require("pdyform-core");var pe=u(require("react"),1);var me=require("clsx"),ce=require("tailwind-merge");function l(...e){return(0,ce.twMerge)((0,me.clsx)(e))}var fe=require("react/jsx-runtime"),N=pe.forwardRef(({className:e,type:t,...r},i)=>(0,fe.jsx)("input",{type:t,className:l("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:i,...r}));N.displayName="Input";var ue=u(require("react"),1);var be=require("react/jsx-runtime"),T=ue.forwardRef(({className:e,...t},r)=>(0,be.jsx)("textarea",{className:l("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:r,...t}));T.displayName="Textarea";var Re=u(require("react"),1),V=u(require("@radix-ui/react-checkbox"),1),ve=require("lucide-react");var q=require("react/jsx-runtime"),G=Re.forwardRef(({className:e,...t},r)=>(0,q.jsx)(V.Root,{ref:r,className:l("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",e),...t,children:(0,q.jsx)(V.Indicator,{className:l("flex items-center justify-center text-current"),children:(0,q.jsx)(ve.Check,{className:"h-4 w-4"})})}));G.displayName=V.Root.displayName;var ge=u(require("react"),1),E=u(require("@radix-ui/react-switch"),1);var re=require("react/jsx-runtime"),L=ge.forwardRef(({className:e,...t},r)=>(0,re.jsx)(E.Root,{className:l("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:r,children:(0,re.jsx)(E.Thumb,{className:l("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));L.displayName=E.Root.displayName;var oe=u(require("react"),1),S=u(require("@radix-ui/react-radio-group"),1),xe=require("lucide-react");var M=require("react/jsx-runtime"),B=oe.forwardRef(({className:e,...t},r)=>(0,M.jsx)(S.Root,{className:l("grid gap-2",e),...t,ref:r}));B.displayName=S.Root.displayName;var $=oe.forwardRef(({className:e,...t},r)=>(0,M.jsx)(S.Item,{ref:r,className:l("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:(0,M.jsx)(S.Indicator,{className:"flex items-center justify-center",children:(0,M.jsx)(xe.Circle,{className:"h-2.5 w-2.5 fill-current text-current"})})}));$.displayName=S.Item.displayName;var U=u(require("react"),1),a=u(require("@radix-ui/react-select"),1),z=require("lucide-react");var f=require("react/jsx-runtime"),O=a.Root,J=a.Group,K=a.Value,D=U.forwardRef(({className:e,children:t,...r},i)=>(0,f.jsxs)(a.Trigger,{ref:i,className:l("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),...r,children:[t,(0,f.jsx)(a.Icon,{asChild:!0,children:(0,f.jsx)(z.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));D.displayName=a.Trigger.displayName;var A=U.forwardRef(({className:e,children:t,position:r="popper",...i},o)=>(0,f.jsx)(a.Portal,{children:(0,f.jsx)(a.Content,{ref:o,className:l("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",r==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:r,...i,children:(0,f.jsx)(a.Viewport,{className:l("p-1",r==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t})})}));A.displayName=a.Content.displayName;var H=U.forwardRef(({className:e,children:t,...r},i)=>(0,f.jsxs)(a.Item,{ref:i,className:l("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...r,children:[(0,f.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,f.jsx)(a.ItemIndicator,{children:(0,f.jsx)(z.Check,{className:"h-4 w-4"})})}),(0,f.jsx)(a.ItemText,{children:t})]}));H.displayName=a.Item.displayName;var ye=u(require("react"),1),ie=u(require("@radix-ui/react-label"),1),he=require("class-variance-authority");var Se=require("react/jsx-runtime"),De=(0,he.cva)("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),R=ye.forwardRef(({className:e,...t},r)=>(0,Se.jsx)(ie.Root,{ref:r,className:l(De(),e),...t}));R.displayName=ie.Root.displayName;var Ce=require("pdyform-core");var Fe=require("react/jsx-runtime"),Ae=({field:e,value:t,onChange:r,onBlur:i,fieldId:o,ariaInvalid:s,ariaRequired:n,ariaDescribedBy:d})=>{let c=p=>{r((0,Ce.normalizeFieldValue)(e,p))};return(0,Fe.jsx)(N,{id:o,type:e.type,placeholder:e.placeholder,value:t??"",onChange:p=>c(p.target.value),onBlur:i,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,"aria-invalid":s,"aria-required":n,"aria-describedby":d})},v=Ae;var Pe=require("react/jsx-runtime"),He=({field:e,value:t,onChange:r,onBlur:i,fieldId:o})=>(0,Pe.jsx)(T,{id:o,placeholder:e.placeholder,value:t??"",onChange:s=>r(s.target.value),onBlur:i,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name}),Q=He;var C=require("react/jsx-runtime"),We=({field:e,value:t,onChange:r,onBlur:i,fieldId:o})=>(0,C.jsxs)(O,{value:t!=null?String(t):"",onValueChange:r,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,children:[(0,C.jsx)(D,{id:o,onBlur:i,children:(0,C.jsx)(K,{placeholder:e.placeholder||"Select an option"})}),(0,C.jsx)(A,{children:(0,C.jsx)(J,{children:e.options?.map(s=>(0,C.jsx)(H,{value:String(s.value),children:s.label},s.value))})})]}),X=We;var I=require("react/jsx-runtime"),qe=({field:e,value:t,onChange:r,onBlur:i})=>(0,I.jsx)("div",{className:"flex flex-wrap gap-4",children:e.options?.map(o=>{let s=Array.isArray(t)&&t.includes(o.value);return(0,I.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,I.jsx)(G,{id:`checkbox-${e.name}-${o.value}`,checked:s,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,onCheckedChange:n=>{let d=Array.isArray(t)?[...t]:[];if(n)d.push(o.value);else{let c=d.indexOf(o.value);c>-1&&d.splice(c,1)}r(d)},onBlur:i}),(0,I.jsx)(R,{htmlFor:`checkbox-${e.name}-${o.value}`,className:"font-normal",children:o.label})]},o.value)})}),Y=qe;var k=require("react/jsx-runtime"),Ue=({field:e,value:t,onChange:r,onBlur:i})=>(0,k.jsx)(B,{value:t!=null?String(t):"",onValueChange:r,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,className:"flex flex-wrap gap-4",children:e.options?.map(o=>(0,k.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,k.jsx)($,{value:String(o.value),id:`radio-${e.name}-${o.value}`,onBlur:i}),(0,k.jsx)(R,{htmlFor:`radio-${e.name}-${o.value}`,className:"font-normal",children:o.label})]},o.value))}),Z=Ue;var we=require("react/jsx-runtime"),ze=({field:e,value:t,onChange:r,onBlur:i,fieldId:o,ariaInvalid:s,ariaRequired:n,ariaDescribedBy:d})=>(0,we.jsx)(N,{id:o,type:"date",value:t??"",onChange:c=>r(c.target.value),onBlur:i,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,"aria-invalid":s,"aria-required":n,"aria-describedby":d}),_=ze;var ae=require("react/jsx-runtime"),Oe=({field:e,value:t,onChange:r,onBlur:i,fieldId:o,ariaInvalid:s,ariaRequired:n,ariaDescribedBy:d})=>(0,ae.jsx)("div",{className:"flex items-center space-x-2",children:(0,ae.jsx)(L,{id:o,checked:!!t,onCheckedChange:r,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,"aria-invalid":s,"aria-required":n,"aria-describedby":d})}),j=Oe;var ee={text:v,number:v,password:v,email:v,textarea:Q,select:X,checkbox:Y,radio:Z,date:_,switch:j};var F=require("react/jsx-runtime"),ne=({field:e,value:t,onChange:r,onBlur:i,error:o,componentMap:s})=>{let{label:n,description:d,name:c,type:p,validations:m}=e,b=`field-${c}`,g=`${b}-description`,x=`${b}-error`,y=m?.some(Te=>Te.type==="required"),le=(s?{...ee,...s}:ee)[p]??v,ke=[d?g:null,o?x:null].filter(Boolean).join(" ");return(0,F.jsxs)("div",{className:`space-y-2 ${e.className||""}`,children:[n&&(0,F.jsxs)(R,{htmlFor:b,className:y?"flex items-center gap-1":"",children:[n,y&&(0,F.jsx)("span",{className:"text-destructive",children:"*"})]}),(0,F.jsx)(le,{field:e,value:t,onChange:r,onBlur:i,fieldId:b,errorId:x,descriptionId:g,ariaInvalid:!!o,ariaRequired:y,ariaDescribedBy:ke||void 0}),d&&(0,F.jsx)("p",{id:g,className:"text-[0.8rem] text-muted-foreground",children:d}),o&&(0,F.jsx)("p",{id:x,className:"text-[0.8rem] font-medium text-destructive",children:o})]})};var P=require("react"),Ne=require("zustand"),te=require("pdyform-core");function se({schema:e}){let t=(0,P.useMemo)(()=>(0,te.createFormStore)(e.fields,e.resolver,e.errorMessages),[e]),r=(0,Ne.useStore)(t),i=(0,P.useCallback)(async(c,p)=>{await t.getState().setFieldValue(c,p)},[t]),o=(0,P.useCallback)(c=>(0,te.get)(t.getState().values,c),[t]),s=(0,P.useCallback)((c,p)=>{t.setState(m=>({errors:{...m.errors,[c]:p}}))},[t]),n=(0,P.useCallback)(async()=>{let{hasError:c,state:p}=await t.getState().runSubmitValidation();return{hasError:c,values:p.values,state:p}},[t]),d=(0,P.useCallback)(()=>{t.setState({values:{},errors:{},isSubmitting:!1})},[t]);return{store:t,state:r,setValue:i,getValue:o,setError:s,validate:n,reset:d}}var w=require("react/jsx-runtime"),Je=({schema:e,onSubmit:t,className:r,form:i})=>{let o=se({schema:e}),s=i||o,{state:n,store:d}=s,c=async m=>{m.preventDefault();try{let{hasError:b,values:g,state:x}=await s.validate();if(console.log("has error =>",b,g,x),b){let y=e.fields.find(h=>!(typeof h.hidden=="function"?h.hidden(n.values):h.hidden)&&x.errors[h.name]);if(y){let h=document.getElementById(`field-${y.name}`);h?.focus(),h?.scrollIntoView({behavior:"smooth",block:"center"})}return}await t(g)}catch(b){console.error("Submission error:",b)}},p=n.validatingFields.length>0;return(0,w.jsxs)("form",{onSubmit:c,className:`space-y-6 ${r||""}`,children:[e.title&&(0,w.jsx)("h2",{className:"text-2xl font-bold tracking-tight",children:e.title}),e.description&&(0,w.jsx)("p",{className:"text-muted-foreground",children:e.description}),(0,w.jsx)("div",{className:"space-y-4",children:e.fields.map(m=>{let b=typeof m.hidden=="function"?m.hidden(n.values):m.hidden,g=typeof m.disabled=="function"?m.disabled(n.values):m.disabled,x=n.validatingFields.includes(m.name);return!b&&(0,w.jsx)(ne,{field:{...m,disabled:g||x},value:(0,Ie.get)(n.values,m.name),onChange:y=>d.getState().setFieldValue(m.name,y),onBlur:()=>d.getState().setFieldBlur(m.name),error:n.errors[m.name]},m.name)})}),(0,w.jsx)("button",{type:"submit",disabled:n.isSubmitting||p,className:"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2 w-full",children:n.isSubmitting?"Submitting...":p?"Validating...":e.submitButtonText||"Submit"})]})};0&&(module.exports={Checkbox,CheckboxRenderer,DateRenderer,DynamicForm,FormFieldRenderer,Input,InputRenderer,Label,RadioGroup,RadioGroupItem,RadioRenderer,Select,SelectContent,SelectGroup,SelectItem,SelectRenderer,SelectTrigger,SelectValue,Switch,SwitchRenderer,Textarea,TextareaRenderer,defaultComponentMap,useForm});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{get as Ue}from"pdyform-core";import*as ee from"react";import{clsx as ue}from"clsx";import{twMerge as be}from"tailwind-merge";function l(...e){return be(ue(e))}import{jsx as Re}from"react/jsx-runtime";var h=ee.forwardRef(({className:e,type:t,...r},i)=>Re("input",{type:t,className:l("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:i,...r}));h.displayName="Input";import*as te from"react";import{jsx as ve}from"react/jsx-runtime";var I=te.forwardRef(({className:e,...t},r)=>ve("textarea",{className:l("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:r,...t}));I.displayName="Textarea";import*as re from"react";import*as C from"@radix-ui/react-checkbox";import{Check as ge}from"lucide-react";import{jsx as A}from"react/jsx-runtime";var k=re.forwardRef(({className:e,...t},r)=>A(C.Root,{ref:r,className:l("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",e),...t,children:A(C.Indicator,{className:l("flex items-center justify-center text-current"),children:A(ge,{className:"h-4 w-4"})})}));k.displayName=C.Root.displayName;import*as ie from"react";import*as F from"@radix-ui/react-switch";import{jsx as oe}from"react/jsx-runtime";var T=ie.forwardRef(({className:e,...t},r)=>oe(F.Root,{className:l("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:r,children:oe(F.Thumb,{className:l("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));T.displayName=F.Root.displayName;import*as W from"react";import*as R from"@radix-ui/react-radio-group";import{Circle as xe}from"lucide-react";import{jsx as V}from"react/jsx-runtime";var G=W.forwardRef(({className:e,...t},r)=>V(R.Root,{className:l("grid gap-2",e),...t,ref:r}));G.displayName=R.Root.displayName;var E=W.forwardRef(({className:e,...t},r)=>V(R.Item,{ref:r,className:l("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:V(R.Indicator,{className:"flex items-center justify-center",children:V(xe,{className:"h-2.5 w-2.5 fill-current text-current"})})}));E.displayName=R.Item.displayName;import*as L from"react";import*as a from"@radix-ui/react-select";import{Check as ye,ChevronDown as he}from"lucide-react";import{jsx as f,jsxs as ae}from"react/jsx-runtime";var q=a.Root,H=a.Group,U=a.Value,M=L.forwardRef(({className:e,children:t,...r},i)=>ae(a.Trigger,{ref:i,className:l("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),...r,children:[t,f(a.Icon,{asChild:!0,children:f(he,{className:"h-4 w-4 opacity-50"})})]}));M.displayName=a.Trigger.displayName;var B=L.forwardRef(({className:e,children:t,position:r="popper",...i},o)=>f(a.Portal,{children:f(a.Content,{ref:o,className:l("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",r==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:r,...i,children:f(a.Viewport,{className:l("p-1",r==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t})})}));B.displayName=a.Content.displayName;var $=L.forwardRef(({className:e,children:t,...r},i)=>ae(a.Item,{ref:i,className:l("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...r,children:[f("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:f(a.ItemIndicator,{children:f(ye,{className:"h-4 w-4"})})}),f(a.ItemText,{children:t})]}));$.displayName=a.Item.displayName;import*as ne from"react";import*as z from"@radix-ui/react-label";import{cva as Se}from"class-variance-authority";import{jsx as Fe}from"react/jsx-runtime";var Ce=Se("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),v=ne.forwardRef(({className:e,...t},r)=>Fe(z.Root,{ref:r,className:l(Ce(),e),...t}));v.displayName=z.Root.displayName;import{normalizeFieldValue as Pe}from"pdyform-core";import{jsx as Ne}from"react/jsx-runtime";var we=({field:e,value:t,onChange:r,onBlur:i,fieldId:o,ariaInvalid:n,ariaRequired:s,ariaDescribedBy:d})=>{let c=p=>{r(Pe(e,p))};return Ne(h,{id:o,type:e.type,placeholder:e.placeholder,value:t??"",onChange:p=>c(p.target.value),onBlur:i,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,"aria-invalid":n,"aria-required":s,"aria-describedby":d})},g=we;import{jsx as ke}from"react/jsx-runtime";var Ie=({field:e,value:t,onChange:r,onBlur:i,fieldId:o})=>ke(I,{id:o,placeholder:e.placeholder,value:t??"",onChange:n=>r(n.target.value),onBlur:i,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name}),O=Ie;import{jsx as P,jsxs as Ve}from"react/jsx-runtime";var Te=({field:e,value:t,onChange:r,onBlur:i,fieldId:o})=>Ve(q,{value:t!=null?String(t):"",onValueChange:r,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,children:[P(M,{id:o,onBlur:i,children:P(U,{placeholder:e.placeholder||"Select an option"})}),P(B,{children:P(H,{children:e.options?.map(n=>P($,{value:String(n.value),children:n.label},n.value))})})]}),J=Te;import{jsx as K,jsxs as Ee}from"react/jsx-runtime";var Ge=({field:e,value:t,onChange:r,onBlur:i})=>K("div",{className:"flex flex-wrap gap-4",children:e.options?.map(o=>{let n=Array.isArray(t)&&t.includes(o.value);return Ee("div",{className:"flex items-center space-x-2",children:[K(k,{id:`checkbox-${e.name}-${o.value}`,checked:n,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,onCheckedChange:s=>{let d=Array.isArray(t)?[...t]:[];if(s)d.push(o.value);else{let c=d.indexOf(o.value);c>-1&&d.splice(c,1)}r(d)},onBlur:i}),K(v,{htmlFor:`checkbox-${e.name}-${o.value}`,className:"font-normal",children:o.label})]},o.value)})}),Q=Ge;import{jsx as X,jsxs as Me}from"react/jsx-runtime";var Le=({field:e,value:t,onChange:r,onBlur:i})=>X(G,{value:t!=null?String(t):"",onValueChange:r,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,className:"flex flex-wrap gap-4",children:e.options?.map(o=>Me("div",{className:"flex items-center space-x-2",children:[X(E,{value:String(o.value),id:`radio-${e.name}-${o.value}`,onBlur:i}),X(v,{htmlFor:`radio-${e.name}-${o.value}`,className:"font-normal",children:o.label})]},o.value))}),Y=Le;import{jsx as $e}from"react/jsx-runtime";var Be=({field:e,value:t,onChange:r,onBlur:i,fieldId:o,ariaInvalid:n,ariaRequired:s,ariaDescribedBy:d})=>$e(h,{id:o,type:"date",value:t??"",onChange:c=>r(c.target.value),onBlur:i,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,"aria-invalid":n,"aria-required":s,"aria-describedby":d}),Z=Be;import{jsx as se}from"react/jsx-runtime";var De=({field:e,value:t,onChange:r,onBlur:i,fieldId:o,ariaInvalid:n,ariaRequired:s,ariaDescribedBy:d})=>se("div",{className:"flex items-center space-x-2",children:se(T,{id:o,checked:!!t,onCheckedChange:r,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,"aria-invalid":n,"aria-required":s,"aria-describedby":d})}),_=De;var j={text:g,number:g,password:g,email:g,textarea:O,select:J,checkbox:Q,radio:Y,date:Z,switch:_};import{jsx as D,jsxs as le}from"react/jsx-runtime";var de=({field:e,value:t,onChange:r,onBlur:i,error:o,componentMap:n})=>{let{label:s,description:d,name:c,type:p,validations:m}=e,u=`field-${c}`,x=`${u}-description`,y=`${u}-error`,b=m?.some(fe=>fe.type==="required"),ce=(n?{...j,...n}:j)[p]??g,pe=[d?x:null,o?y:null].filter(Boolean).join(" ");return le("div",{className:`space-y-2 ${e.className||""}`,children:[s&&le(v,{htmlFor:u,className:b?"flex items-center gap-1":"",children:[s,b&&D("span",{className:"text-destructive",children:"*"})]}),D(ce,{field:e,value:t,onChange:r,onBlur:i,fieldId:u,errorId:y,descriptionId:x,ariaInvalid:!!o,ariaRequired:b,ariaDescribedBy:pe||void 0}),d&&D("p",{id:x,className:"text-[0.8rem] text-muted-foreground",children:d}),o&&D("p",{id:y,className:"text-[0.8rem] font-medium text-destructive",children:o})]})};import{useMemo as Ae,useCallback as w}from"react";import{useStore as We}from"zustand";import{createFormStore as qe,get as He}from"pdyform-core";function me({schema:e}){let t=Ae(()=>qe(e.fields,e.resolver,e.errorMessages),[e]),r=We(t),i=w(async(c,p)=>{await t.getState().setFieldValue(c,p)},[t]),o=w(c=>He(t.getState().values,c),[t]),n=w((c,p)=>{t.setState(m=>({errors:{...m.errors,[c]:p}}))},[t]),s=w(async()=>{let{hasError:c,state:p}=await t.getState().runSubmitValidation();return{hasError:c,values:p.values,state:p}},[t]),d=w(()=>{t.setState({values:{},errors:{},isSubmitting:!1})},[t]);return{store:t,state:r,setValue:i,getValue:o,setError:n,validate:s,reset:d}}import{jsx as N,jsxs as ze}from"react/jsx-runtime";var Ir=({schema:e,onSubmit:t,className:r,form:i})=>{let o=me({schema:e}),n=i||o,{state:s,store:d}=n,c=async m=>{m.preventDefault();let{hasError:u,values:x,state:y}=await n.validate();if(u){let b=e.fields.find(S=>y.errors[S.name]);if(b){let S=document.getElementById(`field-${b.name}`);S?.focus(),S?.scrollIntoView({behavior:"smooth",block:"center"})}return}t(x)},p=s.validatingFields.length>0;return ze("form",{onSubmit:c,className:`space-y-6 ${r||""}`,children:[e.title&&N("h2",{className:"text-2xl font-bold tracking-tight",children:e.title}),e.description&&N("p",{className:"text-muted-foreground",children:e.description}),N("div",{className:"space-y-4",children:e.fields.map(m=>{let u=typeof m.hidden=="function"?m.hidden(s.values):m.hidden,x=typeof m.disabled=="function"?m.disabled(s.values):m.disabled,y=s.validatingFields.includes(m.name);return!u&&N(de,{field:{...m,disabled:x||y},value:Ue(s.values,m.name),onChange:b=>d.getState().setFieldValue(m.name,b),onBlur:()=>d.getState().setFieldBlur(m.name),error:s.errors[m.name]},m.name)})}),N("button",{type:"submit",disabled:s.isSubmitting||p,className:"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2 w-full",children:s.isSubmitting?"Submitting...":p?"Validating...":e.submitButtonText||"Submit"})]})};export{k as Checkbox,Q as CheckboxRenderer,Z as DateRenderer,Ir as DynamicForm,de as FormFieldRenderer,h as Input,g as InputRenderer,v as Label,G as RadioGroup,E as RadioGroupItem,Y as RadioRenderer,q as Select,B as SelectContent,H as SelectGroup,$ as SelectItem,J as SelectRenderer,M as SelectTrigger,U as SelectValue,T as Switch,_ as SwitchRenderer,I as Textarea,O as TextareaRenderer,j as defaultComponentMap,me as useForm};
|
|
1
|
+
import{get as Ue}from"pdyform-core";import*as te from"react";import{clsx as ue}from"clsx";import{twMerge as be}from"tailwind-merge";function l(...e){return be(ue(e))}import{jsx as Re}from"react/jsx-runtime";var S=te.forwardRef(({className:e,type:t,...r},i)=>Re("input",{type:t,className:l("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:i,...r}));S.displayName="Input";import*as re from"react";import{jsx as ve}from"react/jsx-runtime";var I=re.forwardRef(({className:e,...t},r)=>ve("textarea",{className:l("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:r,...t}));I.displayName="Textarea";import*as oe from"react";import*as C from"@radix-ui/react-checkbox";import{Check as ge}from"lucide-react";import{jsx as A}from"react/jsx-runtime";var k=oe.forwardRef(({className:e,...t},r)=>A(C.Root,{ref:r,className:l("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",e),...t,children:A(C.Indicator,{className:l("flex items-center justify-center text-current"),children:A(ge,{className:"h-4 w-4"})})}));k.displayName=C.Root.displayName;import*as ae from"react";import*as F from"@radix-ui/react-switch";import{jsx as ie}from"react/jsx-runtime";var T=ae.forwardRef(({className:e,...t},r)=>ie(F.Root,{className:l("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:r,children:ie(F.Thumb,{className:l("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));T.displayName=F.Root.displayName;import*as H from"react";import*as x from"@radix-ui/react-radio-group";import{Circle as xe}from"lucide-react";import{jsx as V}from"react/jsx-runtime";var G=H.forwardRef(({className:e,...t},r)=>V(x.Root,{className:l("grid gap-2",e),...t,ref:r}));G.displayName=x.Root.displayName;var E=H.forwardRef(({className:e,...t},r)=>V(x.Item,{ref:r,className:l("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:V(x.Indicator,{className:"flex items-center justify-center",children:V(xe,{className:"h-2.5 w-2.5 fill-current text-current"})})}));E.displayName=x.Item.displayName;import*as L from"react";import*as a from"@radix-ui/react-select";import{Check as ye,ChevronDown as he}from"lucide-react";import{jsx as u,jsxs as ne}from"react/jsx-runtime";var W=a.Root,q=a.Group,U=a.Value,M=L.forwardRef(({className:e,children:t,...r},i)=>ne(a.Trigger,{ref:i,className:l("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),...r,children:[t,u(a.Icon,{asChild:!0,children:u(he,{className:"h-4 w-4 opacity-50"})})]}));M.displayName=a.Trigger.displayName;var B=L.forwardRef(({className:e,children:t,position:r="popper",...i},o)=>u(a.Portal,{children:u(a.Content,{ref:o,className:l("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",r==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:r,...i,children:u(a.Viewport,{className:l("p-1",r==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t})})}));B.displayName=a.Content.displayName;var $=L.forwardRef(({className:e,children:t,...r},i)=>ne(a.Item,{ref:i,className:l("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...r,children:[u("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u(a.ItemIndicator,{children:u(ye,{className:"h-4 w-4"})})}),u(a.ItemText,{children:t})]}));$.displayName=a.Item.displayName;import*as se from"react";import*as z from"@radix-ui/react-label";import{cva as Se}from"class-variance-authority";import{jsx as Fe}from"react/jsx-runtime";var Ce=Se("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),y=se.forwardRef(({className:e,...t},r)=>Fe(z.Root,{ref:r,className:l(Ce(),e),...t}));y.displayName=z.Root.displayName;import{normalizeFieldValue as Pe}from"pdyform-core";import{jsx as Ne}from"react/jsx-runtime";var we=({field:e,value:t,onChange:r,onBlur:i,fieldId:o,ariaInvalid:s,ariaRequired:n,ariaDescribedBy:d})=>{let c=p=>{r(Pe(e,p))};return Ne(S,{id:o,type:e.type,placeholder:e.placeholder,value:t??"",onChange:p=>c(p.target.value),onBlur:i,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,"aria-invalid":s,"aria-required":n,"aria-describedby":d})},h=we;import{jsx as ke}from"react/jsx-runtime";var Ie=({field:e,value:t,onChange:r,onBlur:i,fieldId:o})=>ke(I,{id:o,placeholder:e.placeholder,value:t??"",onChange:s=>r(s.target.value),onBlur:i,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name}),O=Ie;import{jsx as P,jsxs as Ve}from"react/jsx-runtime";var Te=({field:e,value:t,onChange:r,onBlur:i,fieldId:o})=>Ve(W,{value:t!=null?String(t):"",onValueChange:r,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,children:[P(M,{id:o,onBlur:i,children:P(U,{placeholder:e.placeholder||"Select an option"})}),P(B,{children:P(q,{children:e.options?.map(s=>P($,{value:String(s.value),children:s.label},s.value))})})]}),J=Te;import{jsx as K,jsxs as Ee}from"react/jsx-runtime";var Ge=({field:e,value:t,onChange:r,onBlur:i})=>K("div",{className:"flex flex-wrap gap-4",children:e.options?.map(o=>{let s=Array.isArray(t)&&t.includes(o.value);return Ee("div",{className:"flex items-center space-x-2",children:[K(k,{id:`checkbox-${e.name}-${o.value}`,checked:s,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,onCheckedChange:n=>{let d=Array.isArray(t)?[...t]:[];if(n)d.push(o.value);else{let c=d.indexOf(o.value);c>-1&&d.splice(c,1)}r(d)},onBlur:i}),K(y,{htmlFor:`checkbox-${e.name}-${o.value}`,className:"font-normal",children:o.label})]},o.value)})}),Q=Ge;import{jsx as X,jsxs as Me}from"react/jsx-runtime";var Le=({field:e,value:t,onChange:r,onBlur:i})=>X(G,{value:t!=null?String(t):"",onValueChange:r,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,className:"flex flex-wrap gap-4",children:e.options?.map(o=>Me("div",{className:"flex items-center space-x-2",children:[X(E,{value:String(o.value),id:`radio-${e.name}-${o.value}`,onBlur:i}),X(y,{htmlFor:`radio-${e.name}-${o.value}`,className:"font-normal",children:o.label})]},o.value))}),Y=Le;import{jsx as $e}from"react/jsx-runtime";var Be=({field:e,value:t,onChange:r,onBlur:i,fieldId:o,ariaInvalid:s,ariaRequired:n,ariaDescribedBy:d})=>$e(S,{id:o,type:"date",value:t??"",onChange:c=>r(c.target.value),onBlur:i,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,"aria-invalid":s,"aria-required":n,"aria-describedby":d}),Z=Be;import{jsx as le}from"react/jsx-runtime";var De=({field:e,value:t,onChange:r,onBlur:i,fieldId:o,ariaInvalid:s,ariaRequired:n,ariaDescribedBy:d})=>le("div",{className:"flex items-center space-x-2",children:le(T,{id:o,checked:!!t,onCheckedChange:r,disabled:typeof e.disabled=="boolean"?e.disabled:void 0,name:e.name,"aria-invalid":s,"aria-required":n,"aria-describedby":d})}),_=De;var j={text:h,number:h,password:h,email:h,textarea:O,select:J,checkbox:Q,radio:Y,date:Z,switch:_};import{jsx as D,jsxs as de}from"react/jsx-runtime";var me=({field:e,value:t,onChange:r,onBlur:i,error:o,componentMap:s})=>{let{label:n,description:d,name:c,type:p,validations:m}=e,f=`field-${c}`,b=`${f}-description`,R=`${f}-error`,v=m?.some(fe=>fe.type==="required"),ee=(s?{...j,...s}:j)[p]??h,pe=[d?b:null,o?R:null].filter(Boolean).join(" ");return de("div",{className:`space-y-2 ${e.className||""}`,children:[n&&de(y,{htmlFor:f,className:v?"flex items-center gap-1":"",children:[n,v&&D("span",{className:"text-destructive",children:"*"})]}),D(ee,{field:e,value:t,onChange:r,onBlur:i,fieldId:f,errorId:R,descriptionId:b,ariaInvalid:!!o,ariaRequired:v,ariaDescribedBy:pe||void 0}),d&&D("p",{id:b,className:"text-[0.8rem] text-muted-foreground",children:d}),o&&D("p",{id:R,className:"text-[0.8rem] font-medium text-destructive",children:o})]})};import{useMemo as Ae,useCallback as w}from"react";import{useStore as He}from"zustand";import{createFormStore as We,get as qe}from"pdyform-core";function ce({schema:e}){let t=Ae(()=>We(e.fields,e.resolver,e.errorMessages),[e]),r=He(t),i=w(async(c,p)=>{await t.getState().setFieldValue(c,p)},[t]),o=w(c=>qe(t.getState().values,c),[t]),s=w((c,p)=>{t.setState(m=>({errors:{...m.errors,[c]:p}}))},[t]),n=w(async()=>{let{hasError:c,state:p}=await t.getState().runSubmitValidation();return{hasError:c,values:p.values,state:p}},[t]),d=w(()=>{t.setState({values:{},errors:{},isSubmitting:!1})},[t]);return{store:t,state:r,setValue:i,getValue:o,setError:s,validate:n,reset:d}}import{jsx as N,jsxs as ze}from"react/jsx-runtime";var Ir=({schema:e,onSubmit:t,className:r,form:i})=>{let o=ce({schema:e}),s=i||o,{state:n,store:d}=s,c=async m=>{m.preventDefault();try{let{hasError:f,values:b,state:R}=await s.validate();if(console.log("has error =>",f,b,R),f){let v=e.fields.find(g=>!(typeof g.hidden=="function"?g.hidden(n.values):g.hidden)&&R.errors[g.name]);if(v){let g=document.getElementById(`field-${v.name}`);g?.focus(),g?.scrollIntoView({behavior:"smooth",block:"center"})}return}await t(b)}catch(f){console.error("Submission error:",f)}},p=n.validatingFields.length>0;return ze("form",{onSubmit:c,className:`space-y-6 ${r||""}`,children:[e.title&&N("h2",{className:"text-2xl font-bold tracking-tight",children:e.title}),e.description&&N("p",{className:"text-muted-foreground",children:e.description}),N("div",{className:"space-y-4",children:e.fields.map(m=>{let f=typeof m.hidden=="function"?m.hidden(n.values):m.hidden,b=typeof m.disabled=="function"?m.disabled(n.values):m.disabled,R=n.validatingFields.includes(m.name);return!f&&N(me,{field:{...m,disabled:b||R},value:Ue(n.values,m.name),onChange:v=>d.getState().setFieldValue(m.name,v),onBlur:()=>d.getState().setFieldBlur(m.name),error:n.errors[m.name]},m.name)})}),N("button",{type:"submit",disabled:n.isSubmitting||p,className:"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2 w-full",children:n.isSubmitting?"Submitting...":p?"Validating...":e.submitButtonText||"Submit"})]})};export{k as Checkbox,Q as CheckboxRenderer,Z as DateRenderer,Ir as DynamicForm,me as FormFieldRenderer,S as Input,h as InputRenderer,y as Label,G as RadioGroup,E as RadioGroupItem,Y as RadioRenderer,W as Select,B as SelectContent,q as SelectGroup,$ as SelectItem,J as SelectRenderer,M as SelectTrigger,U as SelectValue,T as Switch,_ as SwitchRenderer,I as Textarea,O as TextareaRenderer,j as defaultComponentMap,ce as useForm};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),D=require("clsx"),j=require("tailwind-merge"),u=require("radix-vue"),V=require("lucide-vue-next");function C(t){if(typeof t=="number")return Number.isNaN(t)?null:t;if(typeof t!="string"||t.trim()==="")return null;const n=Number(t);return Number.isNaN(n)?null:n}var z={required:"{label} is required",min:"{label} must be at least {value}",max:"{label} must be at most {value}",email:"Invalid email address",pattern:"Invalid format",custom:"Invalid value"};function v(t,n,o){return t.replace("{label}",n.label).replace("{value}",String(o.value||""))}function w(t,n,o){if(!n)return o;const r=n.split(/[.[\]]/).filter(Boolean);let l=t;for(const a of r){if(l==null)return o;l=l[a]}return l===void 0?o:l}function M(t,n,o){if(Object(t)!==t)return t;const r=n.split(/[.[\]]/).filter(Boolean),l={...t};let a=l;for(let s=0;s<r.length-1;s++){const i=r[s],d=r[s+1],c=/^\d+$/.test(d);!(i in a)||a[i]===null||typeof a[i]!="object"?a[i]=c?[]:{}:a[i]=Array.isArray(a[i])?[...a[i]]:{...a[i]},a=a[i]}return a[r[r.length-1]]=o,l}function N(t,n){if(t.type!=="number")return n;if(n===""||n===void 0||n===null)return"";const o=C(n);return o===null?n:o}async function P(t,n,o){if(!n.validations)return null;const r={...z,...o};for(const l of n.validations)switch(l.type){case"required":if(t==null||t===""||Array.isArray(t)&&t.length===0)return l.message||v(r.required,n,l);break;case"min":if(n.type==="number"){const a=C(t);if(a!==null&&a<l.value){const s=n.type==="number"?r.min:typeof t=="string"?"{label} must be at least {value} characters":r.min;return l.message||v(s,n,l)}break}if(typeof t=="number"&&t<l.value)return l.message||v(r.min,n,l);if(typeof t=="string"&&t.length<l.value)return l.message||v("{label} must be at least {value} characters",n,l);break;case"max":if(n.type==="number"){const a=C(t);if(a!==null&&a>l.value)return l.message||v(r.max,n,l);break}if(typeof t=="number"&&t>l.value)return l.message||v(r.max,n,l);if(typeof t=="string"&&t.length>l.value)return l.message||v("{label} must be at most {value} characters",n,l);break;case"email":{if(t&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t))return l.message||v(r.email,n,l);break}case"pattern":if(t&&l.value&&!new RegExp(l.value).test(t))return l.message||v(r.pattern,n,l);break;case"custom":if(l.validator){const a=await l.validator(t);if(typeof a=="string")return a;if(a===!1)return l.message||v(r.custom,n,l)}break}return null}async function $(t,n,o,r,l,a){if(r&&l){const i=await r(l);if(i[n])return i[n]}const s=t.find(i=>i.name===n);return s?await P(o,s,a):null}async function T(t,n,o,r){let l={};o&&(l=await o(n));const a=t.map(async s=>{if(l[s.name])return;const i=await P(w(n,s.name),s,r);i&&(l[s.name]=i)});return await Promise.all(a),l}function U(t){return t.reduce((n,o)=>(n[o.name]=o.defaultValue!==void 0?o.defaultValue:o.type==="checkbox"?[]:"",n),{})}const I=t=>{let n;const o=new Set,r=(c,p)=>{const m=typeof c=="function"?c(n):c;if(!Object.is(m,n)){const b=n;n=p??(typeof m!="object"||m===null)?m:Object.assign({},n,m),o.forEach(k=>k(n,b))}},l=()=>n,i={setState:r,getState:l,getInitialState:()=>d,subscribe:c=>(o.add(c),()=>o.delete(c))},d=n=t(r,l,i);return i},O=t=>t?I(t):I;function A(t,n,o){return O()((r,l)=>({values:U(t),errors:{},validatingFields:[],isSubmitting:!1,setFieldValue:async(a,s)=>{const i=t.find(c=>c.name===a),d=i?N(i,s):s;r(c=>({values:M(c.values,a,d),validatingFields:[...c.validatingFields,a]}));try{const c=l().values,p=await $(t,a,d,n,c,o);r(m=>({errors:{...m.errors,[a]:p||""},validatingFields:m.validatingFields.filter(b=>b!==a)}))}catch{r(p=>({validatingFields:p.validatingFields.filter(m=>m!==a)}))}},setFieldBlur:async a=>{r(s=>({validatingFields:[...s.validatingFields,a]}));try{const s=l().values,i=w(s,a),d=await $(t,a,i,n,s,o);r(c=>({errors:{...c.errors,[a]:d||""},validatingFields:c.validatingFields.filter(p=>p!==a)}))}catch{r(i=>({validatingFields:i.validatingFields.filter(d=>d!==a)}))}},setSubmitting:a=>r({isSubmitting:a}),runSubmitValidation:async()=>{r({isSubmitting:!0});const a=l(),s=await T(t,a.values,n,o),i=Object.keys(s).length>0;return r({errors:s,isSubmitting:!1}),{state:l(),hasError:i}}}))}function y(...t){return j.twMerge(D.clsx(t))}const L=["type","value"],E=e.defineComponent({__name:"Input",props:{class:{},type:{},modelValue:{}},emits:["update:modelValue","blur"],setup(t,{emit:n}){const o=t,r=n;return(l,a)=>(e.openBlock(),e.createElementBlock("input",e.mergeProps(l.$attrs,{type:t.type,class:e.unref(y)("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",o.class),value:t.modelValue,onInput:a[0]||(a[0]=s=>r("update:modelValue",s.target.value)),onBlur:a[1]||(a[1]=s=>r("blur",s))}),null,16,L))}}),x=e.defineComponent({__name:"InputRenderer",props:{field:{},fieldId:{},modelValue:{},ariaInvalid:{type:Boolean},ariaRequired:{type:Boolean},ariaDescribedby:{}},emits:["update:modelValue","blur"],setup(t,{emit:n}){const o=t,r=n,l=a=>{r("update:modelValue",N(o.field,a))};return(a,s)=>(e.openBlock(),e.createBlock(E,{id:t.fieldId,type:t.field.type,placeholder:t.field.placeholder,disabled:typeof t.field.disabled=="boolean"?t.field.disabled:void 0,name:t.field.name,modelValue:t.modelValue??"","onUpdate:modelValue":l,onBlur:s[0]||(s[0]=i=>r("blur",i))},null,8,["id","type","placeholder","disabled","name","modelValue"]))}}),G=["value"],K=e.defineComponent({__name:"Textarea",props:{class:{},modelValue:{}},emits:["update:modelValue","blur"],setup(t,{emit:n}){const o=t,r=n;return(l,a)=>(e.openBlock(),e.createElementBlock("textarea",e.mergeProps(l.$attrs,{class:e.unref(y)("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",o.class),value:t.modelValue,onInput:a[0]||(a[0]=s=>r("update:modelValue",s.target.value)),onBlur:a[1]||(a[1]=s=>r("blur",s))}),null,16,G))}}),W=e.defineComponent({__name:"TextareaRenderer",props:{field:{},fieldId:{},modelValue:{},ariaInvalid:{type:Boolean},ariaRequired:{type:Boolean},ariaDescribedby:{}},emits:["update:modelValue"],setup(t,{emit:n}){const o=n;return(r,l)=>(e.openBlock(),e.createBlock(K,{id:t.fieldId,placeholder:t.field.placeholder,disabled:typeof t.field.disabled=="boolean"?t.field.disabled:void 0,name:t.field.name,modelValue:t.modelValue??"","onUpdate:modelValue":l[0]||(l[0]=a=>o("update:modelValue",a))},null,8,["id","placeholder","disabled","name","modelValue"]))}}),H=e.defineComponent({__name:"SelectTrigger",props:{disabled:{type:Boolean},asChild:{type:Boolean},as:{},class:{}},setup(t){const n=t,o=e.computed(()=>{const{class:l,...a}=n;return a}),r=u.useForwardProps(o);return(l,a)=>(e.openBlock(),e.createBlock(e.unref(u.SelectTrigger),e.mergeProps(e.unref(r),{class:e.unref(y)("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",n.class)}),{default:e.withCtx(()=>[e.renderSlot(l.$slots,"default"),e.createVNode(e.unref(u.SelectIcon),{"as-child":""},{default:e.withCtx(()=>[e.createVNode(e.unref(V.ChevronDown),{class:"h-4 w-4 opacity-50"})]),_:1})]),_:3},16,["class"]))}}),J=e.defineComponent({__name:"SelectContent",props:{forceMount:{type:Boolean},position:{default:"popper"},bodyLock:{type:Boolean},side:{},sideOffset:{},align:{},alignOffset:{},avoidCollisions:{type:Boolean},collisionBoundary:{},collisionPadding:{},arrowPadding:{},sticky:{},hideWhenDetached:{type:Boolean},updatePositionStrategy:{},prioritizePosition:{type:Boolean},asChild:{type:Boolean},as:{},class:{}},setup(t){const n=t,o=e.computed(()=>{const{class:l,...a}=n;return a}),r=u.useForwardProps(o);return(l,a)=>(e.openBlock(),e.createBlock(e.unref(u.SelectPortal),null,{default:e.withCtx(()=>[e.createVNode(e.unref(u.SelectContent),e.mergeProps(e.unref(r),{class:e.unref(y)("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t.position==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",n.class)}),{default:e.withCtx(()=>[e.createVNode(e.unref(u.SelectViewport),{class:e.normalizeClass(e.unref(y)("p-1",t.position==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"))},{default:e.withCtx(()=>[e.renderSlot(l.$slots,"default")]),_:3},8,["class"])]),_:3},16,["class"])]),_:3}))}}),Q={class:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center"},X=e.defineComponent({__name:"SelectItem",props:{value:{},disabled:{type:Boolean},textValue:{},asChild:{type:Boolean},as:{},class:{}},setup(t){const n=t,o=e.computed(()=>{const{class:l,...a}=n;return a}),r=u.useForwardProps(o);return(l,a)=>(e.openBlock(),e.createBlock(e.unref(u.SelectItem),e.mergeProps(e.unref(r),{class:e.unref(y)("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",n.class)}),{default:e.withCtx(()=>[e.createElementVNode("span",Q,[e.createVNode(e.unref(u.SelectItemIndicator),null,{default:e.withCtx(()=>[e.createVNode(e.unref(V.Check),{class:"h-4 w-4"})]),_:1})]),e.createVNode(e.unref(u.SelectItemText),null,{default:e.withCtx(()=>[e.renderSlot(l.$slots,"default")]),_:3})]),_:3},16,["class"]))}}),Y=e.defineComponent({__name:"Select",props:{open:{type:Boolean},defaultOpen:{type:Boolean},defaultValue:{},modelValue:{},dir:{},name:{},autocomplete:{},disabled:{type:Boolean},required:{type:Boolean}},emits:["update:modelValue","update:open"],setup(t,{emit:n}){const o=t,r=n,l=u.useForwardPropsEmits(o,r);return(a,s)=>(e.openBlock(),e.createBlock(e.unref(u.SelectRoot),e.normalizeProps(e.guardReactiveProps(e.unref(l))),{default:e.withCtx(()=>[e.renderSlot(a.$slots,"default")]),_:3},16))}}),Z=e.defineComponent({__name:"SelectRenderer",props:{field:{},fieldId:{},modelValue:{},ariaInvalid:{type:Boolean},ariaRequired:{type:Boolean},ariaDescribedby:{}},emits:["update:modelValue"],setup(t,{emit:n}){const o=n;return(r,l)=>(e.openBlock(),e.createBlock(Y,{disabled:typeof t.field.disabled=="boolean"?t.field.disabled:void 0,name:t.field.name,modelValue:t.modelValue!=null?String(t.modelValue):"","onUpdate:modelValue":l[0]||(l[0]=a=>o("update:modelValue",a))},{default:e.withCtx(()=>[e.createVNode(H,{id:t.fieldId},{default:e.withCtx(()=>[e.createVNode(e.unref(u.SelectValue),{placeholder:t.field.placeholder||"Select an option"},null,8,["placeholder"])]),_:1},8,["id"]),e.createVNode(J,null,{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.field.options,a=>(e.openBlock(),e.createBlock(X,{key:a.value,value:String(a.value)},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(a.label),1)]),_:2},1032,["value"]))),128))]),_:1})]),_:1},8,["disabled","name","modelValue"]))}}),_=e.defineComponent({__name:"Checkbox",props:{defaultChecked:{type:Boolean},checked:{type:[Boolean,String]},disabled:{type:Boolean},required:{type:Boolean},name:{},value:{},id:{},asChild:{type:Boolean},as:{},class:{}},emits:["update:checked","blur"],setup(t,{emit:n}){const o=t,r=n,l=e.computed(()=>{const{class:s,...i}=o;return i}),a=u.useForwardPropsEmits(l,r);return(s,i)=>(e.openBlock(),e.createBlock(e.unref(u.CheckboxRoot),e.mergeProps(e.unref(a),{class:e.unref(y)("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",o.class),onBlur:i[0]||(i[0]=d=>r("blur"))}),{default:e.withCtx(()=>[e.createVNode(e.unref(u.CheckboxIndicator),{class:"flex h-full w-full items-center justify-center text-current"},{default:e.withCtx(()=>[e.createVNode(e.unref(V.Check),{class:"h-4 w-4"})]),_:1})]),_:1},16,["class"]))}}),F=e.defineComponent({__name:"Label",props:{for:{},asChild:{type:Boolean},as:{},class:{}},setup(t){const n=t,o=e.computed(()=>{const{class:r,...l}=n;return l});return(r,l)=>(e.openBlock(),e.createBlock(e.unref(u.Label),e.mergeProps(o.value,{class:e.unref(y)("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",n.class)}),{default:e.withCtx(()=>[e.renderSlot(r.$slots,"default")]),_:3},16,["class"]))}}),ee={class:"flex flex-wrap gap-4"},te=e.defineComponent({__name:"CheckboxRenderer",props:{field:{},fieldId:{},modelValue:{},ariaInvalid:{type:Boolean},ariaRequired:{type:Boolean},ariaDescribedby:{}},emits:["update:modelValue"],setup(t,{emit:n}){const o=t,r=n,l=(a,s)=>{const i=Array.isArray(o.modelValue)?[...o.modelValue]:[];if(s)i.push(a);else{const d=i.indexOf(a);d>-1&&i.splice(d,1)}r("update:modelValue",i)};return(a,s)=>(e.openBlock(),e.createElementBlock("div",ee,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.field.options,i=>(e.openBlock(),e.createElementBlock("div",{key:i.value,class:"flex items-center space-x-2"},[e.createVNode(_,{id:`checkbox-${t.field.name}-${i.value}`,disabled:typeof t.field.disabled=="boolean"?t.field.disabled:void 0,checked:Array.isArray(t.modelValue)&&t.modelValue.includes(i.value),"onUpdate:checked":d=>l(i.value,!!d)},null,8,["id","disabled","checked","onUpdate:checked"]),e.createVNode(F,{for:`checkbox-${t.field.name}-${i.value}`,class:"font-normal"},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(i.label),1)]),_:2},1032,["for"])]))),128))]))}}),ae=e.defineComponent({__name:"RadioGroupItem",props:{id:{},value:{},disabled:{type:Boolean},required:{type:Boolean},name:{},asChild:{type:Boolean},as:{},class:{}},setup(t){const n=t,o=e.computed(()=>{const{class:l,...a}=n;return a}),r=u.useForwardProps(o);return(l,a)=>(e.openBlock(),e.createBlock(e.unref(u.RadioGroupItem),e.mergeProps(e.unref(r),{class:e.unref(y)("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",n.class)}),{default:e.withCtx(()=>[e.createVNode(e.unref(u.RadioGroupIndicator),{class:"flex items-center justify-center"},{default:e.withCtx(()=>[e.createVNode(e.unref(V.Circle),{class:"h-2.5 w-2.5 fill-current text-current"})]),_:1})]),_:1},16,["class"]))}}),le=e.defineComponent({__name:"RadioGroup",props:{modelValue:{},defaultValue:{},disabled:{type:Boolean},name:{},required:{type:Boolean},orientation:{},dir:{},loop:{type:Boolean},asChild:{type:Boolean},as:{},class:{}},emits:["update:modelValue"],setup(t,{emit:n}){const o=t,r=n,l=e.computed(()=>{const{class:s,...i}=o;return i}),a=u.useForwardPropsEmits(l,r);return(s,i)=>(e.openBlock(),e.createBlock(e.unref(u.RadioGroupRoot),e.mergeProps(e.unref(a),{class:e.unref(y)("grid gap-2",o.class)}),{default:e.withCtx(()=>[e.renderSlot(s.$slots,"default")]),_:3},16,["class"]))}}),ne=e.defineComponent({__name:"RadioRenderer",props:{field:{},fieldId:{},modelValue:{},ariaInvalid:{type:Boolean},ariaRequired:{type:Boolean},ariaDescribedby:{}},emits:["update:modelValue"],setup(t,{emit:n}){const o=n;return(r,l)=>(e.openBlock(),e.createBlock(le,{class:"flex flex-wrap gap-4",disabled:typeof t.field.disabled=="boolean"?t.field.disabled:void 0,name:t.field.name,modelValue:t.modelValue!=null?String(t.modelValue):"","onUpdate:modelValue":l[0]||(l[0]=a=>o("update:modelValue",a))},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.field.options,a=>(e.openBlock(),e.createElementBlock("div",{key:a.value,class:"flex items-center space-x-2"},[e.createVNode(ae,{id:`radio-${t.field.name}-${a.value}`,value:String(a.value)},null,8,["id","value"]),e.createVNode(F,{for:`radio-${t.field.name}-${a.value}`,class:"font-normal"},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(a.label),1)]),_:2},1032,["for"])]))),128))]),_:1},8,["disabled","name","modelValue"]))}}),oe=e.defineComponent({__name:"DateRenderer",props:{field:{},modelValue:{},fieldId:{},ariaInvalid:{type:Boolean},ariaRequired:{type:Boolean},ariaDescribedby:{}},emits:["update:modelValue","blur"],setup(t,{emit:n}){const o=n;return(r,l)=>(e.openBlock(),e.createBlock(E,{id:t.fieldId,type:"date",modelValue:t.modelValue,placeholder:t.field.placeholder,disabled:typeof t.field.disabled=="boolean"?t.field.disabled:void 0,name:t.field.name,"aria-invalid":t.ariaInvalid,"aria-required":t.ariaRequired,"aria-describedby":t.ariaDescribedby,"onUpdate:modelValue":l[0]||(l[0]=a=>o("update:modelValue",a)),onBlur:l[1]||(l[1]=a=>o("blur",a))},null,8,["id","modelValue","placeholder","disabled","name","aria-invalid","aria-required","aria-describedby"]))}}),re=e.defineComponent({__name:"Switch",props:{defaultChecked:{type:Boolean},checked:{type:Boolean},disabled:{type:Boolean},required:{type:Boolean},name:{},id:{},value:{},asChild:{type:Boolean},as:{},class:{}},emits:["update:checked"],setup(t,{emit:n}){const o=t,r=n,l=e.computed(()=>{const{class:s,...i}=o;return i}),a=u.useForwardPropsEmits(l,r);return(s,i)=>(e.openBlock(),e.createBlock(e.unref(u.SwitchRoot),e.mergeProps(e.unref(a),{class:e.unref(y)("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",o.class)}),{default:e.withCtx(()=>[e.createVNode(e.unref(u.SwitchThumb),{class:e.normalizeClass(e.unref(y)("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0"))},null,8,["class"])]),_:1},16,["class"]))}}),ie={class:"flex items-center space-x-2"},se=e.defineComponent({__name:"SwitchRenderer",props:{field:{},modelValue:{type:Boolean},fieldId:{},ariaInvalid:{type:Boolean},ariaRequired:{type:Boolean},ariaDescribedby:{}},emits:["update:modelValue","blur"],setup(t,{emit:n}){const o=n;return(r,l)=>(e.openBlock(),e.createElementBlock("div",ie,[e.createVNode(re,{id:t.fieldId,checked:t.modelValue,disabled:typeof t.field.disabled=="boolean"?t.field.disabled:void 0,"aria-invalid":t.ariaInvalid,"aria-required":t.ariaRequired,"aria-describedby":t.ariaDescribedby,"onUpdate:checked":l[0]||(l[0]=a=>o("update:modelValue",a))},null,8,["id","checked","disabled","aria-invalid","aria-required","aria-describedby"])]))}}),S={text:x,number:x,password:x,email:x,textarea:W,select:Z,checkbox:te,radio:ne,date:oe,switch:se},de={key:0,class:"text-destructive"},ce=["id"],ue=["id"],R=e.defineComponent({__name:"FormFieldRenderer",props:{field:{},modelValue:{},error:{},componentMap:{}},emits:["update:modelValue","blur"],setup(t,{emit:n}){const o=t,r=n,l=e.computed(()=>`field-${o.field.name}`),a=e.computed(()=>`${l.value}-description`),s=e.computed(()=>`${l.value}-error`),i=e.computed(()=>{var m;return(m=o.field.validations)==null?void 0:m.some(b=>b.type==="required")}),d=e.computed(()=>{const m=[];return o.field.description&&m.push(a.value),o.error&&m.push(s.value),m.length>0?m.join(" "):void 0}),c=e.computed(()=>o.componentMap?{...S,...o.componentMap}:S),p=e.computed(()=>c.value[o.field.type]??x);return(m,b)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["space-y-2",t.field.className])},[t.field.label?(e.openBlock(),e.createBlock(F,{key:0,for:l.value,class:e.normalizeClass(i.value?"flex items-center gap-1":"")},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(t.field.label)+" ",1),i.value?(e.openBlock(),e.createElementBlock("span",de,"*")):e.createCommentVNode("",!0)]),_:1},8,["for","class"])):e.createCommentVNode("",!0),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(p.value),{field:t.field,fieldId:l.value,modelValue:t.modelValue,"aria-invalid":!!t.error,"aria-required":i.value,"aria-describedby":d.value,"onUpdate:modelValue":b[0]||(b[0]=k=>r("update:modelValue",k)),onBlur:b[1]||(b[1]=k=>r("blur",k))},null,40,["field","fieldId","modelValue","aria-invalid","aria-required","aria-describedby"])),t.field.description?(e.openBlock(),e.createElementBlock("p",{key:1,id:a.value,class:"text-[0.8rem] text-muted-foreground"},e.toDisplayString(t.field.description),9,ce)):e.createCommentVNode("",!0),t.error?(e.openBlock(),e.createElementBlock("p",{key:2,id:s.value,class:"text-[0.8rem] font-medium text-destructive"},e.toDisplayString(t.error),9,ue)):e.createCommentVNode("",!0)],2))}});function q({schema:t}){const n=A(t.fields,t.resolver,t.errorMessages),o=e.ref(n.getState()),r=n.subscribe(d=>{o.value=d});return e.onUnmounted(()=>{r()}),{store:n,state:o,setValue:async(d,c)=>{await n.getState().setFieldValue(d,c)},getValue:d=>w(o.value.values,d),validate:async()=>{const{hasError:d,state:c}=await n.getState().runSubmitValidation();return{hasError:d,values:c.values}},reset:()=>{n.setState({values:{},errors:{},isSubmitting:!1})}}}const me={key:0,class:"space-y-1"},fe={key:0,class:"text-2xl font-bold tracking-tight"},pe={key:1,class:"text-muted-foreground"},be={class:"space-y-4"},ge=["disabled"],ye=e.defineComponent({__name:"DynamicForm",props:{schema:{},className:{},form:{}},emits:["submit"],setup(t,{emit:n}){const o=t,r=n,l=q({schema:o.schema}),a=o.form||l,{store:s,state:i}=a,d=async(f,B)=>{await s.getState().setFieldValue(f,B)},c=async f=>{await s.getState().setFieldBlur(f)},p=f=>typeof f.hidden=="function"?f.hidden(i.value.values):!!f.hidden,m=f=>{const B=typeof f.disabled=="function"?f.disabled(i.value.values):!!f.disabled,g=i.value.validatingFields.includes(f.name);return{...f,disabled:B||g}},b=async()=>{const{hasError:f,values:B}=await a.validate();if(f){const g=o.schema.fields.find(h=>i.value.errors[h.name]);if(g){const h=document.getElementById(`field-${g.name}`);h==null||h.focus(),h==null||h.scrollIntoView({behavior:"smooth",block:"center"})}return}r("submit",B)},k=e.computed(()=>i.value.validatingFields.length>0);return(f,B)=>(e.openBlock(),e.createElementBlock("form",{class:e.normalizeClass(["space-y-6",t.className]),onSubmit:e.withModifiers(b,["prevent"])},[t.schema.title||t.schema.description?(e.openBlock(),e.createElementBlock("div",me,[t.schema.title?(e.openBlock(),e.createElementBlock("h2",fe,e.toDisplayString(t.schema.title),1)):e.createCommentVNode("",!0),t.schema.description?(e.openBlock(),e.createElementBlock("p",pe,e.toDisplayString(t.schema.description),1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),e.createElementVNode("div",be,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.schema.fields,g=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:g.id},[p(g)?e.createCommentVNode("",!0):(e.openBlock(),e.createBlock(R,{key:0,field:m(g),"model-value":e.unref(w)(e.unref(i).values,g.name),error:e.unref(i).errors[g.name],"onUpdate:modelValue":h=>d(g.name,h),onBlur:h=>c(g.name)},null,8,["field","model-value","error","onUpdate:modelValue","onBlur"]))],64))),128))]),e.createElementVNode("button",{type:"submit",disabled:e.unref(i).isSubmitting||k.value,class:"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2 w-full"},e.toDisplayString(e.unref(i).isSubmitting?"Submitting...":k.value?"Validating...":t.schema.submitButtonText||"Submit"),9,ge)],34))}});exports.DynamicForm=ye;exports.FormFieldRenderer=R;exports.defaultComponentMap=S;exports.useForm=q;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),D=require("clsx"),j=require("tailwind-merge"),c=require("radix-vue"),V=require("lucide-vue-next");function C(t){if(typeof t=="number")return Number.isNaN(t)?null:t;if(typeof t!="string"||t.trim()==="")return null;const o=Number(t);return Number.isNaN(o)?null:o}var z={required:"{label} is required",min:"{label} must be at least {value}",max:"{label} must be at most {value}",email:"Invalid email address",pattern:"Invalid format",custom:"Invalid value"};function v(t,o,l){return t.replace("{label}",o.label).replace("{value}",String(l.value||""))}function w(t,o,l){if(!o)return l;const r=o.split(/[.[\]]/).filter(Boolean);let n=t;for(const a of r){if(n==null)return l;n=n[a]}return n===void 0?l:n}function M(t,o,l){if(Object(t)!==t)return t;const r=o.split(/[.[\]]/).filter(Boolean),n={...t};let a=n;for(let s=0;s<r.length-1;s++){const i=r[s],d=r[s+1],m=/^\d+$/.test(d);!(i in a)||a[i]===null||typeof a[i]!="object"?a[i]=m?[]:{}:a[i]=Array.isArray(a[i])?[...a[i]]:{...a[i]},a=a[i]}return a[r[r.length-1]]=l,n}function N(t,o){if(t.type!=="number")return o;if(o===""||o===void 0||o===null)return"";const l=C(o);return l===null?o:l}async function P(t,o,l){if(!o.validations)return null;const r={...z,...l};for(const n of o.validations)switch(n.type){case"required":if(t==null||t===""||Array.isArray(t)&&t.length===0)return n.message||v(r.required,o,n);break;case"min":if(o.type==="number"){const a=C(t);if(a!==null&&a<n.value){const s=o.type==="number"?r.min:typeof t=="string"?"{label} must be at least {value} characters":r.min;return n.message||v(s,o,n)}break}if(typeof t=="number"&&t<n.value)return n.message||v(r.min,o,n);if(typeof t=="string"&&t.length<n.value)return n.message||v("{label} must be at least {value} characters",o,n);break;case"max":if(o.type==="number"){const a=C(t);if(a!==null&&a>n.value)return n.message||v(r.max,o,n);break}if(typeof t=="number"&&t>n.value)return n.message||v(r.max,o,n);if(typeof t=="string"&&t.length>n.value)return n.message||v("{label} must be at most {value} characters",o,n);break;case"email":{if(t&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t))return n.message||v(r.email,o,n);break}case"pattern":if(t&&n.value&&!new RegExp(n.value).test(t))return n.message||v(r.pattern,o,n);break;case"custom":if(n.validator){const a=await n.validator(t);if(typeof a=="string")return a;if(a===!1)return n.message||v(r.custom,o,n)}break}return null}async function I(t,o,l,r,n,a){if(r&&n){const i=await r(n);if(i[o])return i[o]}const s=t.find(i=>i.name===o);return s?await P(l,s,a):null}async function T(t,o,l,r){let n={};l&&(n=await l(o));const a=t.map(async s=>{if(n[s.name]||(typeof s.hidden=="function"?s.hidden(o):s.hidden))return;const d=await P(w(o,s.name),s,r);d&&(n[s.name]=d)});return await Promise.all(a),n}function U(t){return t.reduce((o,l)=>(o[l.name]=l.defaultValue!==void 0?l.defaultValue:l.type==="checkbox"?[]:"",o),{})}const $=t=>{let o;const l=new Set,r=(m,k)=>{const u=typeof m=="function"?m(o):m;if(!Object.is(u,o)){const p=o;o=k??(typeof u!="object"||u===null)?u:Object.assign({},o,u),l.forEach(b=>b(o,p))}},n=()=>o,i={setState:r,getState:n,getInitialState:()=>d,subscribe:m=>(l.add(m),()=>l.delete(m))},d=o=t(r,n,i);return i},O=t=>t?$(t):$;function A(t,o,l){return O()((r,n)=>({values:U(t),errors:{},validatingFields:[],isSubmitting:!1,setFieldValue:async(a,s)=>{const i=t.find(u=>u.name===a),d=i?N(i,s):s;r(u=>({values:M(u.values,a,d)}));const m=!!n().errors[a];if(i&&["select","checkbox","radio","switch","date"].includes(i.type)||m){r(u=>({validatingFields:[...u.validatingFields,a]}));try{const u=n().values,p=await I(t,a,d,o,u,l);r(b=>({errors:{...b.errors,[a]:p||""},validatingFields:b.validatingFields.filter(f=>f!==a)}))}catch{r(p=>({validatingFields:p.validatingFields.filter(b=>b!==a)}))}}},setFieldBlur:async a=>{r(s=>({validatingFields:[...s.validatingFields,a]}));try{const s=n().values,i=w(s,a),d=await I(t,a,i,o,s,l);r(m=>({errors:{...m.errors,[a]:d||""},validatingFields:m.validatingFields.filter(k=>k!==a)}))}catch{r(i=>({validatingFields:i.validatingFields.filter(d=>d!==a)}))}},setSubmitting:a=>r({isSubmitting:a}),runSubmitValidation:async()=>{r({isSubmitting:!0});const a=n(),s=await T(t,a.values,o,l),i=Object.keys(s).length>0;return r({errors:s,isSubmitting:!1}),{state:n(),hasError:i}}}))}function y(...t){return j.twMerge(D.clsx(t))}const L=["type","value"],E=e.defineComponent({__name:"Input",props:{class:{},type:{},modelValue:{}},emits:["update:modelValue","blur"],setup(t,{emit:o}){const l=t,r=o;return(n,a)=>(e.openBlock(),e.createElementBlock("input",e.mergeProps(n.$attrs,{type:t.type,class:e.unref(y)("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",l.class),value:t.modelValue,onInput:a[0]||(a[0]=s=>r("update:modelValue",s.target.value)),onBlur:a[1]||(a[1]=s=>r("blur",s))}),null,16,L))}}),x=e.defineComponent({__name:"InputRenderer",props:{field:{},fieldId:{},modelValue:{},ariaInvalid:{type:Boolean},ariaRequired:{type:Boolean},ariaDescribedby:{}},emits:["update:modelValue","blur"],setup(t,{emit:o}){const l=t,r=o,n=a=>{r("update:modelValue",N(l.field,a))};return(a,s)=>(e.openBlock(),e.createBlock(E,{id:t.fieldId,type:t.field.type,placeholder:t.field.placeholder,disabled:typeof t.field.disabled=="boolean"?t.field.disabled:void 0,name:t.field.name,modelValue:t.modelValue??"","onUpdate:modelValue":n,onBlur:s[0]||(s[0]=i=>r("blur",i))},null,8,["id","type","placeholder","disabled","name","modelValue"]))}}),G=["value"],H=e.defineComponent({__name:"Textarea",props:{class:{},modelValue:{}},emits:["update:modelValue","blur"],setup(t,{emit:o}){const l=t,r=o;return(n,a)=>(e.openBlock(),e.createElementBlock("textarea",e.mergeProps(n.$attrs,{class:e.unref(y)("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",l.class),value:t.modelValue,onInput:a[0]||(a[0]=s=>r("update:modelValue",s.target.value)),onBlur:a[1]||(a[1]=s=>r("blur",s))}),null,16,G))}}),K=e.defineComponent({__name:"TextareaRenderer",props:{field:{},fieldId:{},modelValue:{},ariaInvalid:{type:Boolean},ariaRequired:{type:Boolean},ariaDescribedby:{}},emits:["update:modelValue"],setup(t,{emit:o}){const l=o;return(r,n)=>(e.openBlock(),e.createBlock(H,{id:t.fieldId,placeholder:t.field.placeholder,disabled:typeof t.field.disabled=="boolean"?t.field.disabled:void 0,name:t.field.name,modelValue:t.modelValue??"","onUpdate:modelValue":n[0]||(n[0]=a=>l("update:modelValue",a))},null,8,["id","placeholder","disabled","name","modelValue"]))}}),W=e.defineComponent({__name:"SelectTrigger",props:{disabled:{type:Boolean},asChild:{type:Boolean},as:{},class:{}},setup(t){const o=t,l=e.computed(()=>{const{class:n,...a}=o;return a}),r=c.useForwardProps(l);return(n,a)=>(e.openBlock(),e.createBlock(e.unref(c.SelectTrigger),e.mergeProps(e.unref(r),{class:e.unref(y)("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",o.class)}),{default:e.withCtx(()=>[e.renderSlot(n.$slots,"default"),e.createVNode(e.unref(c.SelectIcon),{"as-child":""},{default:e.withCtx(()=>[e.createVNode(e.unref(V.ChevronDown),{class:"h-4 w-4 opacity-50"})]),_:1})]),_:3},16,["class"]))}}),J=e.defineComponent({__name:"SelectContent",props:{forceMount:{type:Boolean},position:{default:"popper"},bodyLock:{type:Boolean},side:{},sideOffset:{},align:{},alignOffset:{},avoidCollisions:{type:Boolean},collisionBoundary:{},collisionPadding:{},arrowPadding:{},sticky:{},hideWhenDetached:{type:Boolean},updatePositionStrategy:{},prioritizePosition:{type:Boolean},asChild:{type:Boolean},as:{},class:{}},setup(t){const o=t,l=e.computed(()=>{const{class:n,...a}=o;return a}),r=c.useForwardProps(l);return(n,a)=>(e.openBlock(),e.createBlock(e.unref(c.SelectPortal),null,{default:e.withCtx(()=>[e.createVNode(e.unref(c.SelectContent),e.mergeProps(e.unref(r),{class:e.unref(y)("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t.position==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",o.class)}),{default:e.withCtx(()=>[e.createVNode(e.unref(c.SelectViewport),{class:e.normalizeClass(e.unref(y)("p-1",t.position==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"))},{default:e.withCtx(()=>[e.renderSlot(n.$slots,"default")]),_:3},8,["class"])]),_:3},16,["class"])]),_:3}))}}),Q={class:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center"},X=e.defineComponent({__name:"SelectItem",props:{value:{},disabled:{type:Boolean},textValue:{},asChild:{type:Boolean},as:{},class:{}},setup(t){const o=t,l=e.computed(()=>{const{class:n,...a}=o;return a}),r=c.useForwardProps(l);return(n,a)=>(e.openBlock(),e.createBlock(e.unref(c.SelectItem),e.mergeProps(e.unref(r),{class:e.unref(y)("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",o.class)}),{default:e.withCtx(()=>[e.createElementVNode("span",Q,[e.createVNode(e.unref(c.SelectItemIndicator),null,{default:e.withCtx(()=>[e.createVNode(e.unref(V.Check),{class:"h-4 w-4"})]),_:1})]),e.createVNode(e.unref(c.SelectItemText),null,{default:e.withCtx(()=>[e.renderSlot(n.$slots,"default")]),_:3})]),_:3},16,["class"]))}}),Y=e.defineComponent({__name:"Select",props:{open:{type:Boolean},defaultOpen:{type:Boolean},defaultValue:{},modelValue:{},dir:{},name:{},autocomplete:{},disabled:{type:Boolean},required:{type:Boolean}},emits:["update:modelValue","update:open"],setup(t,{emit:o}){const l=t,r=o,n=c.useForwardPropsEmits(l,r);return(a,s)=>(e.openBlock(),e.createBlock(e.unref(c.SelectRoot),e.normalizeProps(e.guardReactiveProps(e.unref(n))),{default:e.withCtx(()=>[e.renderSlot(a.$slots,"default")]),_:3},16))}}),Z=e.defineComponent({__name:"SelectRenderer",props:{field:{},fieldId:{},modelValue:{},ariaInvalid:{type:Boolean},ariaRequired:{type:Boolean},ariaDescribedby:{}},emits:["update:modelValue"],setup(t,{emit:o}){const l=o;return(r,n)=>(e.openBlock(),e.createBlock(Y,{disabled:typeof t.field.disabled=="boolean"?t.field.disabled:void 0,name:t.field.name,modelValue:t.modelValue!=null?String(t.modelValue):"","onUpdate:modelValue":n[0]||(n[0]=a=>l("update:modelValue",a))},{default:e.withCtx(()=>[e.createVNode(W,{id:t.fieldId},{default:e.withCtx(()=>[e.createVNode(e.unref(c.SelectValue),{placeholder:t.field.placeholder||"Select an option"},null,8,["placeholder"])]),_:1},8,["id"]),e.createVNode(J,null,{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.field.options,a=>(e.openBlock(),e.createBlock(X,{key:a.value,value:String(a.value)},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(a.label),1)]),_:2},1032,["value"]))),128))]),_:1})]),_:1},8,["disabled","name","modelValue"]))}}),_=e.defineComponent({__name:"Checkbox",props:{defaultChecked:{type:Boolean},checked:{type:[Boolean,String]},disabled:{type:Boolean},required:{type:Boolean},name:{},value:{},id:{},asChild:{type:Boolean},as:{},class:{}},emits:["update:checked","blur"],setup(t,{emit:o}){const l=t,r=o,n=e.computed(()=>{const{class:s,...i}=l;return i}),a=c.useForwardPropsEmits(n,r);return(s,i)=>(e.openBlock(),e.createBlock(e.unref(c.CheckboxRoot),e.mergeProps(e.unref(a),{class:e.unref(y)("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",l.class),onBlur:i[0]||(i[0]=d=>r("blur"))}),{default:e.withCtx(()=>[e.createVNode(e.unref(c.CheckboxIndicator),{class:"flex h-full w-full items-center justify-center text-current"},{default:e.withCtx(()=>[e.createVNode(e.unref(V.Check),{class:"h-4 w-4"})]),_:1})]),_:1},16,["class"]))}}),F=e.defineComponent({__name:"Label",props:{for:{},asChild:{type:Boolean},as:{},class:{}},setup(t){const o=t,l=e.computed(()=>{const{class:r,...n}=o;return n});return(r,n)=>(e.openBlock(),e.createBlock(e.unref(c.Label),e.mergeProps(l.value,{class:e.unref(y)("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",o.class)}),{default:e.withCtx(()=>[e.renderSlot(r.$slots,"default")]),_:3},16,["class"]))}}),ee={class:"flex flex-wrap gap-4"},te=e.defineComponent({__name:"CheckboxRenderer",props:{field:{},fieldId:{},modelValue:{},ariaInvalid:{type:Boolean},ariaRequired:{type:Boolean},ariaDescribedby:{}},emits:["update:modelValue"],setup(t,{emit:o}){const l=t,r=o,n=(a,s)=>{const i=Array.isArray(l.modelValue)?[...l.modelValue]:[];if(s)i.push(a);else{const d=i.indexOf(a);d>-1&&i.splice(d,1)}r("update:modelValue",i)};return(a,s)=>(e.openBlock(),e.createElementBlock("div",ee,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.field.options,i=>(e.openBlock(),e.createElementBlock("div",{key:i.value,class:"flex items-center space-x-2"},[e.createVNode(_,{id:`checkbox-${t.field.name}-${i.value}`,disabled:typeof t.field.disabled=="boolean"?t.field.disabled:void 0,checked:Array.isArray(t.modelValue)&&t.modelValue.includes(i.value),"onUpdate:checked":d=>n(i.value,!!d)},null,8,["id","disabled","checked","onUpdate:checked"]),e.createVNode(F,{for:`checkbox-${t.field.name}-${i.value}`,class:"font-normal"},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(i.label),1)]),_:2},1032,["for"])]))),128))]))}}),ae=e.defineComponent({__name:"RadioGroupItem",props:{id:{},value:{},disabled:{type:Boolean},required:{type:Boolean},name:{},asChild:{type:Boolean},as:{},class:{}},setup(t){const o=t,l=e.computed(()=>{const{class:n,...a}=o;return a}),r=c.useForwardProps(l);return(n,a)=>(e.openBlock(),e.createBlock(e.unref(c.RadioGroupItem),e.mergeProps(e.unref(r),{class:e.unref(y)("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",o.class)}),{default:e.withCtx(()=>[e.createVNode(e.unref(c.RadioGroupIndicator),{class:"flex items-center justify-center"},{default:e.withCtx(()=>[e.createVNode(e.unref(V.Circle),{class:"h-2.5 w-2.5 fill-current text-current"})]),_:1})]),_:1},16,["class"]))}}),ne=e.defineComponent({__name:"RadioGroup",props:{modelValue:{},defaultValue:{},disabled:{type:Boolean},name:{},required:{type:Boolean},orientation:{},dir:{},loop:{type:Boolean},asChild:{type:Boolean},as:{},class:{}},emits:["update:modelValue"],setup(t,{emit:o}){const l=t,r=o,n=e.computed(()=>{const{class:s,...i}=l;return i}),a=c.useForwardPropsEmits(n,r);return(s,i)=>(e.openBlock(),e.createBlock(e.unref(c.RadioGroupRoot),e.mergeProps(e.unref(a),{class:e.unref(y)("grid gap-2",l.class)}),{default:e.withCtx(()=>[e.renderSlot(s.$slots,"default")]),_:3},16,["class"]))}}),oe=e.defineComponent({__name:"RadioRenderer",props:{field:{},fieldId:{},modelValue:{},ariaInvalid:{type:Boolean},ariaRequired:{type:Boolean},ariaDescribedby:{}},emits:["update:modelValue"],setup(t,{emit:o}){const l=o;return(r,n)=>(e.openBlock(),e.createBlock(ne,{class:"flex flex-wrap gap-4",disabled:typeof t.field.disabled=="boolean"?t.field.disabled:void 0,name:t.field.name,modelValue:t.modelValue!=null?String(t.modelValue):"","onUpdate:modelValue":n[0]||(n[0]=a=>l("update:modelValue",a))},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.field.options,a=>(e.openBlock(),e.createElementBlock("div",{key:a.value,class:"flex items-center space-x-2"},[e.createVNode(ae,{id:`radio-${t.field.name}-${a.value}`,value:String(a.value)},null,8,["id","value"]),e.createVNode(F,{for:`radio-${t.field.name}-${a.value}`,class:"font-normal"},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(a.label),1)]),_:2},1032,["for"])]))),128))]),_:1},8,["disabled","name","modelValue"]))}}),le=e.defineComponent({__name:"DateRenderer",props:{field:{},modelValue:{},fieldId:{},ariaInvalid:{type:Boolean},ariaRequired:{type:Boolean},ariaDescribedby:{}},emits:["update:modelValue","blur"],setup(t,{emit:o}){const l=o;return(r,n)=>(e.openBlock(),e.createBlock(E,{id:t.fieldId,type:"date",modelValue:t.modelValue,placeholder:t.field.placeholder,disabled:typeof t.field.disabled=="boolean"?t.field.disabled:void 0,name:t.field.name,"aria-invalid":t.ariaInvalid,"aria-required":t.ariaRequired,"aria-describedby":t.ariaDescribedby,"onUpdate:modelValue":n[0]||(n[0]=a=>l("update:modelValue",a)),onBlur:n[1]||(n[1]=a=>l("blur",a))},null,8,["id","modelValue","placeholder","disabled","name","aria-invalid","aria-required","aria-describedby"]))}}),re=e.defineComponent({__name:"Switch",props:{defaultChecked:{type:Boolean},checked:{type:Boolean},disabled:{type:Boolean},required:{type:Boolean},name:{},id:{},value:{},asChild:{type:Boolean},as:{},class:{}},emits:["update:checked"],setup(t,{emit:o}){const l=t,r=o,n=e.computed(()=>{const{class:s,...i}=l;return i}),a=c.useForwardPropsEmits(n,r);return(s,i)=>(e.openBlock(),e.createBlock(e.unref(c.SwitchRoot),e.mergeProps(e.unref(a),{class:e.unref(y)("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",l.class)}),{default:e.withCtx(()=>[e.createVNode(e.unref(c.SwitchThumb),{class:e.normalizeClass(e.unref(y)("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0"))},null,8,["class"])]),_:1},16,["class"]))}}),ie={class:"flex items-center space-x-2"},se=e.defineComponent({__name:"SwitchRenderer",props:{field:{},modelValue:{type:Boolean},fieldId:{},ariaInvalid:{type:Boolean},ariaRequired:{type:Boolean},ariaDescribedby:{}},emits:["update:modelValue","blur"],setup(t,{emit:o}){const l=o;return(r,n)=>(e.openBlock(),e.createElementBlock("div",ie,[e.createVNode(re,{id:t.fieldId,checked:t.modelValue,disabled:typeof t.field.disabled=="boolean"?t.field.disabled:void 0,"aria-invalid":t.ariaInvalid,"aria-required":t.ariaRequired,"aria-describedby":t.ariaDescribedby,"onUpdate:checked":n[0]||(n[0]=a=>l("update:modelValue",a))},null,8,["id","checked","disabled","aria-invalid","aria-required","aria-describedby"])]))}}),S={text:x,number:x,password:x,email:x,textarea:K,select:Z,checkbox:te,radio:oe,date:le,switch:se},de={key:0,class:"text-destructive"},ce=["id"],ue=["id"],R=e.defineComponent({__name:"FormFieldRenderer",props:{field:{},modelValue:{},error:{},componentMap:{}},emits:["update:modelValue","blur"],setup(t,{emit:o}){const l=t,r=o,n=e.computed(()=>`field-${l.field.name}`),a=e.computed(()=>`${n.value}-description`),s=e.computed(()=>`${n.value}-error`),i=e.computed(()=>{var u;return(u=l.field.validations)==null?void 0:u.some(p=>p.type==="required")}),d=e.computed(()=>{const u=[];return l.field.description&&u.push(a.value),l.error&&u.push(s.value),u.length>0?u.join(" "):void 0}),m=e.computed(()=>l.componentMap?{...S,...l.componentMap}:S),k=e.computed(()=>m.value[l.field.type]??x);return(u,p)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["space-y-2",t.field.className])},[t.field.label?(e.openBlock(),e.createBlock(F,{key:0,for:n.value,class:e.normalizeClass(i.value?"flex items-center gap-1":"")},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(t.field.label)+" ",1),i.value?(e.openBlock(),e.createElementBlock("span",de,"*")):e.createCommentVNode("",!0)]),_:1},8,["for","class"])):e.createCommentVNode("",!0),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(k.value),{field:t.field,fieldId:n.value,modelValue:t.modelValue,"aria-invalid":!!t.error,"aria-required":i.value,"aria-describedby":d.value,"onUpdate:modelValue":p[0]||(p[0]=b=>r("update:modelValue",b)),onBlur:p[1]||(p[1]=b=>r("blur",b))},null,40,["field","fieldId","modelValue","aria-invalid","aria-required","aria-describedby"])),t.field.description?(e.openBlock(),e.createElementBlock("p",{key:1,id:a.value,class:"text-[0.8rem] text-muted-foreground"},e.toDisplayString(t.field.description),9,ce)):e.createCommentVNode("",!0),t.error?(e.openBlock(),e.createElementBlock("p",{key:2,id:s.value,class:"text-[0.8rem] font-medium text-destructive"},e.toDisplayString(t.error),9,ue)):e.createCommentVNode("",!0)],2))}});function q({schema:t}){const o=A(t.fields,t.resolver,t.errorMessages),l=e.ref(o.getState()),r=o.subscribe(d=>{l.value=d});return e.onUnmounted(()=>{r()}),{store:o,state:l,setValue:async(d,m)=>{await o.getState().setFieldValue(d,m)},getValue:d=>w(l.value.values,d),validate:async()=>{const{hasError:d,state:m}=await o.getState().runSubmitValidation();return{hasError:d,values:m.values}},reset:()=>{o.setState({values:{},errors:{},isSubmitting:!1})}}}const me={key:0,class:"space-y-1"},fe={key:0,class:"text-2xl font-bold tracking-tight"},pe={key:1,class:"text-muted-foreground"},be={class:"space-y-4"},ge=["disabled"],ye=e.defineComponent({__name:"DynamicForm",props:{schema:{},className:{},form:{}},emits:["submit"],setup(t,{emit:o}){const l=t,r=o,n=q({schema:l.schema}),a=l.form||n,{store:s,state:i}=a,d=async(f,B)=>{await s.getState().setFieldValue(f,B)},m=async f=>{await s.getState().setFieldBlur(f)},k=f=>typeof f.hidden=="function"?f.hidden(i.value.values):!!f.hidden,u=f=>{const B=typeof f.disabled=="function"?f.disabled(i.value.values):!!f.disabled,g=i.value.validatingFields.includes(f.name);return{...f,disabled:B||g}},p=async()=>{const{hasError:f,values:B}=await a.validate();if(f){const g=l.schema.fields.find(h=>i.value.errors[h.name]);if(g){const h=document.getElementById(`field-${g.name}`);h==null||h.focus(),h==null||h.scrollIntoView({behavior:"smooth",block:"center"})}return}await r("submit",B)},b=e.computed(()=>i.value.validatingFields.length>0);return(f,B)=>(e.openBlock(),e.createElementBlock("form",{class:e.normalizeClass(["space-y-6",t.className]),onSubmit:e.withModifiers(p,["prevent"])},[t.schema.title||t.schema.description?(e.openBlock(),e.createElementBlock("div",me,[t.schema.title?(e.openBlock(),e.createElementBlock("h2",fe,e.toDisplayString(t.schema.title),1)):e.createCommentVNode("",!0),t.schema.description?(e.openBlock(),e.createElementBlock("p",pe,e.toDisplayString(t.schema.description),1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),e.createElementVNode("div",be,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.schema.fields,g=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:g.id},[k(g)?e.createCommentVNode("",!0):(e.openBlock(),e.createBlock(R,{key:0,field:u(g),"model-value":e.unref(w)(e.unref(i).values,g.name),error:e.unref(i).errors[g.name],"onUpdate:modelValue":h=>d(g.name,h),onBlur:h=>m(g.name)},null,8,["field","model-value","error","onUpdate:modelValue","onBlur"]))],64))),128))]),e.createElementVNode("button",{type:"submit",disabled:e.unref(i).isSubmitting||b.value,class:"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2 w-full"},e.toDisplayString(e.unref(i).isSubmitting?"Submitting...":b.value?"Validating...":t.schema.submitButtonText||"Submit"),9,ge)],34))}});exports.DynamicForm=ye;exports.FormFieldRenderer=R;exports.defaultComponentMap=S;exports.useForm=q;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { defineComponent as p, openBlock as d, createElementBlock as g, mergeProps as
|
|
1
|
+
import { defineComponent as p, openBlock as d, createElementBlock as g, mergeProps as I, unref as o, createBlock as v, computed as h, withCtx as m, renderSlot as q, createVNode as b, normalizeClass as D, createElementVNode as O, normalizeProps as X, guardReactiveProps as Y, Fragment as N, renderList as E, createTextVNode as U, toDisplayString as F, createCommentVNode as R, resolveDynamicComponent as Z, ref as _, onUnmounted as ee, withModifiers as te } from "vue";
|
|
2
2
|
import { clsx as ae } from "clsx";
|
|
3
3
|
import { twMerge as le } from "tailwind-merge";
|
|
4
4
|
import { useForwardProps as j, SelectTrigger as ie, SelectIcon as ne, SelectPortal as se, SelectContent as re, SelectViewport as oe, SelectItem as de, SelectItemIndicator as ue, SelectItemText as ce, useForwardPropsEmits as A, SelectRoot as me, SelectValue as fe, CheckboxRoot as be, CheckboxIndicator as pe, Label as ge, RadioGroupItem as ye, RadioGroupIndicator as ve, RadioGroupRoot as he, SwitchRoot as xe, SwitchThumb as Ve } from "radix-vue";
|
|
5
|
-
import { ChevronDown as ke, Check as
|
|
5
|
+
import { ChevronDown as ke, Check as K, Circle as we } from "lucide-vue-next";
|
|
6
6
|
function z(e) {
|
|
7
7
|
if (typeof e == "number") return Number.isNaN(e) ? null : e;
|
|
8
8
|
if (typeof e != "string" || e.trim() === "") return null;
|
|
@@ -35,12 +35,12 @@ function Se(e, l, i) {
|
|
|
35
35
|
const n = l.split(/[.[\]]/).filter(Boolean), a = { ...e };
|
|
36
36
|
let t = a;
|
|
37
37
|
for (let r = 0; r < n.length - 1; r++) {
|
|
38
|
-
const s = n[r], u = n[r + 1],
|
|
39
|
-
!(s in t) || t[s] === null || typeof t[s] != "object" ? t[s] =
|
|
38
|
+
const s = n[r], u = n[r + 1], f = /^\d+$/.test(u);
|
|
39
|
+
!(s in t) || t[s] === null || typeof t[s] != "object" ? t[s] = f ? [] : {} : t[s] = Array.isArray(t[s]) ? [...t[s]] : { ...t[s] }, t = t[s];
|
|
40
40
|
}
|
|
41
41
|
return t[n[n.length - 1]] = i, a;
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function W(e, l) {
|
|
44
44
|
if (e.type !== "number") return l;
|
|
45
45
|
if (l === "" || l === void 0 || l === null) return "";
|
|
46
46
|
const i = z(l);
|
|
@@ -108,52 +108,57 @@ async function G(e, l, i, n, a, t) {
|
|
|
108
108
|
const r = e.find((s) => s.name === l);
|
|
109
109
|
return r ? await J(i, r, t) : null;
|
|
110
110
|
}
|
|
111
|
-
async function
|
|
111
|
+
async function Ie(e, l, i, n) {
|
|
112
112
|
let a = {};
|
|
113
113
|
i && (a = await i(l));
|
|
114
114
|
const t = e.map(async (r) => {
|
|
115
|
-
if (a[r.name]) return;
|
|
116
|
-
const
|
|
117
|
-
|
|
115
|
+
if (a[r.name] || (typeof r.hidden == "function" ? r.hidden(l) : r.hidden)) return;
|
|
116
|
+
const u = await J(M(l, r.name), r, n);
|
|
117
|
+
u && (a[r.name] = u);
|
|
118
118
|
});
|
|
119
119
|
return await Promise.all(t), a;
|
|
120
120
|
}
|
|
121
|
-
function
|
|
121
|
+
function $e(e) {
|
|
122
122
|
return e.reduce((l, i) => (l[i.name] = i.defaultValue !== void 0 ? i.defaultValue : i.type === "checkbox" ? [] : "", l), {});
|
|
123
123
|
}
|
|
124
124
|
const L = (e) => {
|
|
125
125
|
let l;
|
|
126
|
-
const i = /* @__PURE__ */ new Set(), n = (
|
|
127
|
-
const
|
|
128
|
-
if (!Object.is(
|
|
129
|
-
const
|
|
130
|
-
l =
|
|
126
|
+
const i = /* @__PURE__ */ new Set(), n = (f, $) => {
|
|
127
|
+
const c = typeof f == "function" ? f(l) : f;
|
|
128
|
+
if (!Object.is(c, l)) {
|
|
129
|
+
const x = l;
|
|
130
|
+
l = $ ?? (typeof c != "object" || c === null) ? c : Object.assign({}, l, c), i.forEach((V) => V(l, x));
|
|
131
131
|
}
|
|
132
|
-
}, a = () => l, s = { setState: n, getState: a, getInitialState: () => u, subscribe: (
|
|
132
|
+
}, a = () => l, s = { setState: n, getState: a, getInitialState: () => u, subscribe: (f) => (i.add(f), () => i.delete(f)) }, u = l = e(n, a, s);
|
|
133
133
|
return s;
|
|
134
134
|
}, Fe = (e) => e ? L(e) : L;
|
|
135
135
|
function Re(e, l, i) {
|
|
136
136
|
return Fe()((n, a) => ({
|
|
137
|
-
values:
|
|
137
|
+
values: $e(e),
|
|
138
138
|
errors: {},
|
|
139
139
|
validatingFields: [],
|
|
140
140
|
isSubmitting: !1,
|
|
141
141
|
setFieldValue: async (t, r) => {
|
|
142
|
-
const s = e.find((c) => c.name === t), u = s ?
|
|
142
|
+
const s = e.find((c) => c.name === t), u = s ? W(s, r) : r;
|
|
143
143
|
n((c) => ({
|
|
144
|
-
values: Se(c.values, t, u)
|
|
145
|
-
validatingFields: [...c.validatingFields, t]
|
|
144
|
+
values: Se(c.values, t, u)
|
|
146
145
|
}));
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
n((
|
|
150
|
-
|
|
151
|
-
validatingFields: f.validatingFields.filter((V) => V !== t)
|
|
152
|
-
}));
|
|
153
|
-
} catch {
|
|
154
|
-
n((x) => ({
|
|
155
|
-
validatingFields: x.validatingFields.filter((f) => f !== t)
|
|
146
|
+
const f = !!a().errors[t];
|
|
147
|
+
if (s && ["select", "checkbox", "radio", "switch", "date"].includes(s.type) || f) {
|
|
148
|
+
n((c) => ({
|
|
149
|
+
validatingFields: [...c.validatingFields, t]
|
|
156
150
|
}));
|
|
151
|
+
try {
|
|
152
|
+
const c = a().values, x = await G(e, t, u, l, c, i);
|
|
153
|
+
n((V) => ({
|
|
154
|
+
errors: { ...V.errors, [t]: x || "" },
|
|
155
|
+
validatingFields: V.validatingFields.filter((y) => y !== t)
|
|
156
|
+
}));
|
|
157
|
+
} catch {
|
|
158
|
+
n((x) => ({
|
|
159
|
+
validatingFields: x.validatingFields.filter((V) => V !== t)
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
157
162
|
}
|
|
158
163
|
},
|
|
159
164
|
setFieldBlur: async (t) => {
|
|
@@ -162,9 +167,9 @@ function Re(e, l, i) {
|
|
|
162
167
|
}));
|
|
163
168
|
try {
|
|
164
169
|
const r = a().values, s = M(r, t), u = await G(e, t, s, l, r, i);
|
|
165
|
-
n((
|
|
166
|
-
errors: { ...
|
|
167
|
-
validatingFields:
|
|
170
|
+
n((f) => ({
|
|
171
|
+
errors: { ...f.errors, [t]: u || "" },
|
|
172
|
+
validatingFields: f.validatingFields.filter(($) => $ !== t)
|
|
168
173
|
}));
|
|
169
174
|
} catch {
|
|
170
175
|
n((s) => ({
|
|
@@ -175,7 +180,7 @@ function Re(e, l, i) {
|
|
|
175
180
|
setSubmitting: (t) => n({ isSubmitting: t }),
|
|
176
181
|
runSubmitValidation: async () => {
|
|
177
182
|
n({ isSubmitting: !0 });
|
|
178
|
-
const t = a(), r = await
|
|
183
|
+
const t = a(), r = await Ie(e, t.values, l, i), s = Object.keys(r).length > 0;
|
|
179
184
|
return n({
|
|
180
185
|
errors: r,
|
|
181
186
|
isSubmitting: !1
|
|
@@ -199,7 +204,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
199
204
|
emits: ["update:modelValue", "blur"],
|
|
200
205
|
setup(e, { emit: l }) {
|
|
201
206
|
const i = e, n = l;
|
|
202
|
-
return (a, t) => (d(), g("input",
|
|
207
|
+
return (a, t) => (d(), g("input", I(a.$attrs, {
|
|
203
208
|
type: e.type,
|
|
204
209
|
class: o(w)("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", i.class),
|
|
205
210
|
value: e.modelValue,
|
|
@@ -220,9 +225,9 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
220
225
|
emits: ["update:modelValue", "blur"],
|
|
221
226
|
setup(e, { emit: l }) {
|
|
222
227
|
const i = e, n = l, a = (t) => {
|
|
223
|
-
n("update:modelValue",
|
|
228
|
+
n("update:modelValue", W(i.field, t));
|
|
224
229
|
};
|
|
225
|
-
return (t, r) => (d(),
|
|
230
|
+
return (t, r) => (d(), v(Q, {
|
|
226
231
|
id: e.fieldId,
|
|
227
232
|
type: e.field.type,
|
|
228
233
|
placeholder: e.field.placeholder,
|
|
@@ -242,7 +247,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
242
247
|
emits: ["update:modelValue", "blur"],
|
|
243
248
|
setup(e, { emit: l }) {
|
|
244
249
|
const i = e, n = l;
|
|
245
|
-
return (a, t) => (d(), g("textarea",
|
|
250
|
+
return (a, t) => (d(), g("textarea", I(a.$attrs, {
|
|
246
251
|
class: o(w)("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", i.class),
|
|
247
252
|
value: e.modelValue,
|
|
248
253
|
onInput: t[0] || (t[0] = (r) => n("update:modelValue", r.target.value)),
|
|
@@ -262,7 +267,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
262
267
|
emits: ["update:modelValue"],
|
|
263
268
|
setup(e, { emit: l }) {
|
|
264
269
|
const i = l;
|
|
265
|
-
return (n, a) => (d(),
|
|
270
|
+
return (n, a) => (d(), v(Pe, {
|
|
266
271
|
id: e.fieldId,
|
|
267
272
|
placeholder: e.field.placeholder,
|
|
268
273
|
disabled: typeof e.field.disabled == "boolean" ? e.field.disabled : void 0,
|
|
@@ -284,7 +289,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
284
289
|
const { class: a, ...t } = l;
|
|
285
290
|
return t;
|
|
286
291
|
}), n = j(i);
|
|
287
|
-
return (a, t) => (d(),
|
|
292
|
+
return (a, t) => (d(), v(o(ie), I(o(n), {
|
|
288
293
|
class: o(w)("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", l.class)
|
|
289
294
|
}), {
|
|
290
295
|
default: m(() => [
|
|
@@ -326,9 +331,9 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
326
331
|
const { class: a, ...t } = l;
|
|
327
332
|
return t;
|
|
328
333
|
}), n = j(i);
|
|
329
|
-
return (a, t) => (d(),
|
|
334
|
+
return (a, t) => (d(), v(o(se), null, {
|
|
330
335
|
default: m(() => [
|
|
331
|
-
b(o(re),
|
|
336
|
+
b(o(re), I(o(n), {
|
|
332
337
|
class: o(w)("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", e.position === "popper" && "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1", l.class)
|
|
333
338
|
}), {
|
|
334
339
|
default: m(() => [
|
|
@@ -362,7 +367,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
362
367
|
const { class: a, ...t } = l;
|
|
363
368
|
return t;
|
|
364
369
|
}), n = j(i);
|
|
365
|
-
return (a, t) => (d(),
|
|
370
|
+
return (a, t) => (d(), v(o(de), I(o(n), {
|
|
366
371
|
class: o(w)(
|
|
367
372
|
"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
368
373
|
l.class
|
|
@@ -372,7 +377,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
372
377
|
O("span", Ue, [
|
|
373
378
|
b(o(ue), null, {
|
|
374
379
|
default: m(() => [
|
|
375
|
-
b(o(
|
|
380
|
+
b(o(K), { class: "h-4 w-4" })
|
|
376
381
|
]),
|
|
377
382
|
_: 1
|
|
378
383
|
})
|
|
@@ -403,7 +408,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
403
408
|
emits: ["update:modelValue", "update:open"],
|
|
404
409
|
setup(e, { emit: l }) {
|
|
405
410
|
const a = A(e, l);
|
|
406
|
-
return (t, r) => (d(),
|
|
411
|
+
return (t, r) => (d(), v(o(me), X(Y(o(a))), {
|
|
407
412
|
default: m(() => [
|
|
408
413
|
q(t.$slots, "default")
|
|
409
414
|
]),
|
|
@@ -423,7 +428,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
423
428
|
emits: ["update:modelValue"],
|
|
424
429
|
setup(e, { emit: l }) {
|
|
425
430
|
const i = l;
|
|
426
|
-
return (n, a) => (d(),
|
|
431
|
+
return (n, a) => (d(), v(Ae, {
|
|
427
432
|
disabled: typeof e.field.disabled == "boolean" ? e.field.disabled : void 0,
|
|
428
433
|
name: e.field.name,
|
|
429
434
|
modelValue: e.modelValue != null ? String(e.modelValue) : "",
|
|
@@ -440,12 +445,12 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
440
445
|
}, 8, ["id"]),
|
|
441
446
|
b(Ee, null, {
|
|
442
447
|
default: m(() => [
|
|
443
|
-
(d(!0), g(N, null, E(e.field.options, (t) => (d(),
|
|
448
|
+
(d(!0), g(N, null, E(e.field.options, (t) => (d(), v(je, {
|
|
444
449
|
key: t.value,
|
|
445
450
|
value: String(t.value)
|
|
446
451
|
}, {
|
|
447
452
|
default: m(() => [
|
|
448
|
-
U(
|
|
453
|
+
U(F(t.label), 1)
|
|
449
454
|
]),
|
|
450
455
|
_: 2
|
|
451
456
|
}, 1032, ["value"]))), 128))
|
|
@@ -476,14 +481,14 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
476
481
|
const { class: r, ...s } = i;
|
|
477
482
|
return s;
|
|
478
483
|
}), t = A(a, n);
|
|
479
|
-
return (r, s) => (d(),
|
|
484
|
+
return (r, s) => (d(), v(o(be), I(o(t), {
|
|
480
485
|
class: o(w)("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground", i.class),
|
|
481
486
|
onBlur: s[0] || (s[0] = (u) => n("blur"))
|
|
482
487
|
}), {
|
|
483
488
|
default: m(() => [
|
|
484
489
|
b(o(pe), { class: "flex h-full w-full items-center justify-center text-current" }, {
|
|
485
490
|
default: m(() => [
|
|
486
|
-
b(o(
|
|
491
|
+
b(o(K), { class: "h-4 w-4" })
|
|
487
492
|
]),
|
|
488
493
|
_: 1
|
|
489
494
|
})
|
|
@@ -504,7 +509,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
504
509
|
const { class: n, ...a } = l;
|
|
505
510
|
return a;
|
|
506
511
|
});
|
|
507
|
-
return (n, a) => (d(),
|
|
512
|
+
return (n, a) => (d(), v(o(ge), I(i.value, {
|
|
508
513
|
class: o(w)("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70", l.class)
|
|
509
514
|
}), {
|
|
510
515
|
default: m(() => [
|
|
@@ -551,7 +556,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
551
556
|
class: "font-normal"
|
|
552
557
|
}, {
|
|
553
558
|
default: m(() => [
|
|
554
|
-
U(
|
|
559
|
+
U(F(s.label), 1)
|
|
555
560
|
]),
|
|
556
561
|
_: 2
|
|
557
562
|
}, 1032, ["for"])
|
|
@@ -575,7 +580,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
575
580
|
const { class: a, ...t } = l;
|
|
576
581
|
return t;
|
|
577
582
|
}), n = j(i);
|
|
578
|
-
return (a, t) => (d(),
|
|
583
|
+
return (a, t) => (d(), v(o(ye), I(o(n), {
|
|
579
584
|
class: o(w)("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", l.class)
|
|
580
585
|
}), {
|
|
581
586
|
default: m(() => [
|
|
@@ -610,7 +615,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
610
615
|
const { class: r, ...s } = i;
|
|
611
616
|
return s;
|
|
612
617
|
}), t = A(a, n);
|
|
613
|
-
return (r, s) => (d(),
|
|
618
|
+
return (r, s) => (d(), v(o(he), I(o(t), {
|
|
614
619
|
class: o(w)("grid gap-2", i.class)
|
|
615
620
|
}), {
|
|
616
621
|
default: m(() => [
|
|
@@ -619,7 +624,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
619
624
|
_: 3
|
|
620
625
|
}, 16, ["class"]));
|
|
621
626
|
}
|
|
622
|
-
}),
|
|
627
|
+
}), He = /* @__PURE__ */ p({
|
|
623
628
|
__name: "RadioRenderer",
|
|
624
629
|
props: {
|
|
625
630
|
field: {},
|
|
@@ -632,7 +637,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
632
637
|
emits: ["update:modelValue"],
|
|
633
638
|
setup(e, { emit: l }) {
|
|
634
639
|
const i = l;
|
|
635
|
-
return (n, a) => (d(),
|
|
640
|
+
return (n, a) => (d(), v(Le, {
|
|
636
641
|
class: "flex flex-wrap gap-4",
|
|
637
642
|
disabled: typeof e.field.disabled == "boolean" ? e.field.disabled : void 0,
|
|
638
643
|
name: e.field.name,
|
|
@@ -653,7 +658,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
653
658
|
class: "font-normal"
|
|
654
659
|
}, {
|
|
655
660
|
default: m(() => [
|
|
656
|
-
U(
|
|
661
|
+
U(F(t.label), 1)
|
|
657
662
|
]),
|
|
658
663
|
_: 2
|
|
659
664
|
}, 1032, ["for"])
|
|
@@ -662,7 +667,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
662
667
|
_: 1
|
|
663
668
|
}, 8, ["disabled", "name", "modelValue"]));
|
|
664
669
|
}
|
|
665
|
-
}),
|
|
670
|
+
}), Ke = /* @__PURE__ */ p({
|
|
666
671
|
__name: "DateRenderer",
|
|
667
672
|
props: {
|
|
668
673
|
field: {},
|
|
@@ -675,7 +680,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
675
680
|
emits: ["update:modelValue", "blur"],
|
|
676
681
|
setup(e, { emit: l }) {
|
|
677
682
|
const i = l;
|
|
678
|
-
return (n, a) => (d(),
|
|
683
|
+
return (n, a) => (d(), v(Q, {
|
|
679
684
|
id: e.fieldId,
|
|
680
685
|
type: "date",
|
|
681
686
|
modelValue: e.modelValue,
|
|
@@ -689,7 +694,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
689
694
|
onBlur: a[1] || (a[1] = (t) => i("blur", t))
|
|
690
695
|
}, null, 8, ["id", "modelValue", "placeholder", "disabled", "name", "aria-invalid", "aria-required", "aria-describedby"]));
|
|
691
696
|
}
|
|
692
|
-
}),
|
|
697
|
+
}), We = /* @__PURE__ */ p({
|
|
693
698
|
__name: "Switch",
|
|
694
699
|
props: {
|
|
695
700
|
defaultChecked: { type: Boolean },
|
|
@@ -709,7 +714,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
709
714
|
const { class: r, ...s } = i;
|
|
710
715
|
return s;
|
|
711
716
|
}), t = A(a, n);
|
|
712
|
-
return (r, s) => (d(),
|
|
717
|
+
return (r, s) => (d(), v(o(xe), I(o(t), {
|
|
713
718
|
class: o(w)(
|
|
714
719
|
"peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",
|
|
715
720
|
i.class
|
|
@@ -739,7 +744,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
739
744
|
setup(e, { emit: l }) {
|
|
740
745
|
const i = l;
|
|
741
746
|
return (n, a) => (d(), g("div", Je, [
|
|
742
|
-
b(
|
|
747
|
+
b(We, {
|
|
743
748
|
id: e.fieldId,
|
|
744
749
|
checked: e.modelValue,
|
|
745
750
|
disabled: typeof e.field.disabled == "boolean" ? e.field.disabled : void 0,
|
|
@@ -750,7 +755,7 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
750
755
|
}, null, 8, ["id", "checked", "disabled", "aria-invalid", "aria-required", "aria-describedby"])
|
|
751
756
|
]));
|
|
752
757
|
}
|
|
753
|
-
}),
|
|
758
|
+
}), H = {
|
|
754
759
|
text: P,
|
|
755
760
|
number: P,
|
|
756
761
|
password: P,
|
|
@@ -758,8 +763,8 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
758
763
|
textarea: De,
|
|
759
764
|
select: Me,
|
|
760
765
|
checkbox: Te,
|
|
761
|
-
radio:
|
|
762
|
-
date:
|
|
766
|
+
radio: He,
|
|
767
|
+
date: Ke,
|
|
763
768
|
switch: Qe
|
|
764
769
|
}, Xe = {
|
|
765
770
|
key: 0,
|
|
@@ -775,50 +780,50 @@ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
|
|
|
775
780
|
emits: ["update:modelValue", "blur"],
|
|
776
781
|
setup(e, { emit: l }) {
|
|
777
782
|
const i = e, n = l, a = h(() => `field-${i.field.name}`), t = h(() => `${a.value}-description`), r = h(() => `${a.value}-error`), s = h(() => {
|
|
778
|
-
var
|
|
779
|
-
return (
|
|
783
|
+
var c;
|
|
784
|
+
return (c = i.field.validations) == null ? void 0 : c.some((x) => x.type === "required");
|
|
780
785
|
}), u = h(() => {
|
|
781
|
-
const
|
|
782
|
-
return i.field.description &&
|
|
783
|
-
}),
|
|
784
|
-
() => i.componentMap ? { ...
|
|
785
|
-
),
|
|
786
|
-
() =>
|
|
786
|
+
const c = [];
|
|
787
|
+
return i.field.description && c.push(t.value), i.error && c.push(r.value), c.length > 0 ? c.join(" ") : void 0;
|
|
788
|
+
}), f = h(
|
|
789
|
+
() => i.componentMap ? { ...H, ...i.componentMap } : H
|
|
790
|
+
), $ = h(
|
|
791
|
+
() => f.value[i.field.type] ?? P
|
|
787
792
|
);
|
|
788
|
-
return (
|
|
793
|
+
return (c, x) => (d(), g("div", {
|
|
789
794
|
class: D(["space-y-2", e.field.className])
|
|
790
795
|
}, [
|
|
791
|
-
e.field.label ? (d(),
|
|
796
|
+
e.field.label ? (d(), v(T, {
|
|
792
797
|
key: 0,
|
|
793
798
|
for: a.value,
|
|
794
799
|
class: D(s.value ? "flex items-center gap-1" : "")
|
|
795
800
|
}, {
|
|
796
801
|
default: m(() => [
|
|
797
|
-
U(
|
|
802
|
+
U(F(e.field.label) + " ", 1),
|
|
798
803
|
s.value ? (d(), g("span", Xe, "*")) : R("", !0)
|
|
799
804
|
]),
|
|
800
805
|
_: 1
|
|
801
806
|
}, 8, ["for", "class"])) : R("", !0),
|
|
802
|
-
(d(),
|
|
807
|
+
(d(), v(Z($.value), {
|
|
803
808
|
field: e.field,
|
|
804
809
|
fieldId: a.value,
|
|
805
810
|
modelValue: e.modelValue,
|
|
806
811
|
"aria-invalid": !!e.error,
|
|
807
812
|
"aria-required": s.value,
|
|
808
813
|
"aria-describedby": u.value,
|
|
809
|
-
"onUpdate:modelValue":
|
|
810
|
-
onBlur:
|
|
814
|
+
"onUpdate:modelValue": x[0] || (x[0] = (V) => n("update:modelValue", V)),
|
|
815
|
+
onBlur: x[1] || (x[1] = (V) => n("blur", V))
|
|
811
816
|
}, null, 40, ["field", "fieldId", "modelValue", "aria-invalid", "aria-required", "aria-describedby"])),
|
|
812
817
|
e.field.description ? (d(), g("p", {
|
|
813
818
|
key: 1,
|
|
814
819
|
id: t.value,
|
|
815
820
|
class: "text-[0.8rem] text-muted-foreground"
|
|
816
|
-
},
|
|
821
|
+
}, F(e.field.description), 9, Ye)) : R("", !0),
|
|
817
822
|
e.error ? (d(), g("p", {
|
|
818
823
|
key: 2,
|
|
819
824
|
id: r.value,
|
|
820
825
|
class: "text-[0.8rem] font-medium text-destructive"
|
|
821
|
-
},
|
|
826
|
+
}, F(e.error), 9, Ze)) : R("", !0)
|
|
822
827
|
], 2));
|
|
823
828
|
}
|
|
824
829
|
});
|
|
@@ -832,13 +837,13 @@ function et({ schema: e }) {
|
|
|
832
837
|
store: l,
|
|
833
838
|
state: i,
|
|
834
839
|
// This is a Ref
|
|
835
|
-
setValue: async (u,
|
|
836
|
-
await l.getState().setFieldValue(u,
|
|
840
|
+
setValue: async (u, f) => {
|
|
841
|
+
await l.getState().setFieldValue(u, f);
|
|
837
842
|
},
|
|
838
843
|
getValue: (u) => M(i.value.values, u),
|
|
839
844
|
validate: async () => {
|
|
840
|
-
const { hasError: u, state:
|
|
841
|
-
return { hasError: u, values:
|
|
845
|
+
const { hasError: u, state: f } = await l.getState().runSubmitValidation();
|
|
846
|
+
return { hasError: u, values: f.values };
|
|
842
847
|
},
|
|
843
848
|
reset: () => {
|
|
844
849
|
l.setState({
|
|
@@ -867,16 +872,16 @@ const tt = {
|
|
|
867
872
|
},
|
|
868
873
|
emits: ["submit"],
|
|
869
874
|
setup(e, { emit: l }) {
|
|
870
|
-
const i = e, n = l, a = et({ schema: i.schema }), t = i.form || a, { store: r, state: s } = t, u = async (
|
|
871
|
-
await r.getState().setFieldValue(
|
|
872
|
-
},
|
|
873
|
-
await r.getState().setFieldBlur(
|
|
874
|
-
},
|
|
875
|
-
const C = typeof
|
|
876
|
-
return { ...
|
|
877
|
-
},
|
|
878
|
-
const { hasError:
|
|
879
|
-
if (
|
|
875
|
+
const i = e, n = l, a = et({ schema: i.schema }), t = i.form || a, { store: r, state: s } = t, u = async (y, C) => {
|
|
876
|
+
await r.getState().setFieldValue(y, C);
|
|
877
|
+
}, f = async (y) => {
|
|
878
|
+
await r.getState().setFieldBlur(y);
|
|
879
|
+
}, $ = (y) => typeof y.hidden == "function" ? y.hidden(s.value.values) : !!y.hidden, c = (y) => {
|
|
880
|
+
const C = typeof y.disabled == "function" ? y.disabled(s.value.values) : !!y.disabled, k = s.value.validatingFields.includes(y.name);
|
|
881
|
+
return { ...y, disabled: C || k };
|
|
882
|
+
}, x = async () => {
|
|
883
|
+
const { hasError: y, values: C } = await t.validate();
|
|
884
|
+
if (y) {
|
|
880
885
|
const k = i.schema.fields.find((B) => s.value.errors[B.name]);
|
|
881
886
|
if (k) {
|
|
882
887
|
const B = document.getElementById(`field-${k.name}`);
|
|
@@ -884,41 +889,41 @@ const tt = {
|
|
|
884
889
|
}
|
|
885
890
|
return;
|
|
886
891
|
}
|
|
887
|
-
n("submit", C);
|
|
888
|
-
},
|
|
889
|
-
return (
|
|
892
|
+
await n("submit", C);
|
|
893
|
+
}, V = h(() => s.value.validatingFields.length > 0);
|
|
894
|
+
return (y, C) => (d(), g("form", {
|
|
890
895
|
class: D(["space-y-6", e.className]),
|
|
891
|
-
onSubmit: te(
|
|
896
|
+
onSubmit: te(x, ["prevent"])
|
|
892
897
|
}, [
|
|
893
898
|
e.schema.title || e.schema.description ? (d(), g("div", tt, [
|
|
894
|
-
e.schema.title ? (d(), g("h2", at,
|
|
895
|
-
e.schema.description ? (d(), g("p", lt,
|
|
899
|
+
e.schema.title ? (d(), g("h2", at, F(e.schema.title), 1)) : R("", !0),
|
|
900
|
+
e.schema.description ? (d(), g("p", lt, F(e.schema.description), 1)) : R("", !0)
|
|
896
901
|
])) : R("", !0),
|
|
897
902
|
O("div", it, [
|
|
898
903
|
(d(!0), g(N, null, E(e.schema.fields, (k) => (d(), g(N, {
|
|
899
904
|
key: k.id
|
|
900
905
|
}, [
|
|
901
|
-
|
|
906
|
+
$(k) ? R("", !0) : (d(), v(_e, {
|
|
902
907
|
key: 0,
|
|
903
|
-
field:
|
|
908
|
+
field: c(k),
|
|
904
909
|
"model-value": o(M)(o(s).values, k.name),
|
|
905
910
|
error: o(s).errors[k.name],
|
|
906
911
|
"onUpdate:modelValue": (B) => u(k.name, B),
|
|
907
|
-
onBlur: (B) =>
|
|
912
|
+
onBlur: (B) => f(k.name)
|
|
908
913
|
}, null, 8, ["field", "model-value", "error", "onUpdate:modelValue", "onBlur"]))
|
|
909
914
|
], 64))), 128))
|
|
910
915
|
]),
|
|
911
916
|
O("button", {
|
|
912
917
|
type: "submit",
|
|
913
|
-
disabled: o(s).isSubmitting ||
|
|
918
|
+
disabled: o(s).isSubmitting || V.value,
|
|
914
919
|
class: "inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2 w-full"
|
|
915
|
-
},
|
|
920
|
+
}, F(o(s).isSubmitting ? "Submitting..." : V.value ? "Validating..." : e.schema.submitButtonText || "Submit"), 9, nt)
|
|
916
921
|
], 34));
|
|
917
922
|
}
|
|
918
923
|
});
|
|
919
924
|
export {
|
|
920
925
|
ct as DynamicForm,
|
|
921
926
|
_e as FormFieldRenderer,
|
|
922
|
-
|
|
927
|
+
H as defaultComponentMap,
|
|
923
928
|
et as useForm
|
|
924
929
|
};
|