shadcn-zod-formkit 1.20.0 → 1.21.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/dist/index.d.mts CHANGED
@@ -78,6 +78,8 @@ declare enum InputTypes {
78
78
  }
79
79
  declare const inputFieldComp: InputTypes[];
80
80
 
81
+ declare const flattenFields: <T extends Record<string, any>>(fields: FieldConfig<T>[]) => FieldProps<T>[];
82
+ type FieldConfig<T> = FieldProps<T> | FieldConfig<T>[];
81
83
  interface FieldProps<T = Record<string, any>> {
82
84
  name: keyof T;
83
85
  label: string;
@@ -86,6 +88,7 @@ interface FieldProps<T = Record<string, any>> {
86
88
  childrenPosition?: 'up' | 'down';
87
89
  children?: ReactNode | ((item: any, index: number) => ReactNode);
88
90
  defaultValue?: any;
91
+ direction?: 'row' | 'col';
89
92
  repeaterFields?: Array<FieldProps | FieldProps[]>;
90
93
  minItems?: number;
91
94
  maxItems?: number;
@@ -208,7 +211,7 @@ interface Props$4<T extends Record<string, any>> {
208
211
  formTitle: string;
209
212
  formSubTitle?: string;
210
213
  readOnly?: boolean;
211
- fields: Array<FieldProps<T> | FieldProps<T>[]>;
214
+ fields: FieldConfig<T>[];
212
215
  record?: Partial<T>;
213
216
  onSubmit?: (resp: FormResp<T>) => void;
214
217
  onClick?: (resp: FormResp<T>) => void;
@@ -229,16 +232,16 @@ declare const mockFields: Array<FieldProps | FieldProps[]>;
229
232
 
230
233
  interface Props$3<T extends FieldValues = Record<string, any>> {
231
234
  formState: FormState<any>;
232
- fields: Array<FieldProps<T> | FieldProps<T>[]>;
235
+ fields: FieldConfig<T>[];
233
236
  }
234
- declare const FormErrorsAlert: <T extends FieldValues = Record<string, any>>({ formState, fields }: Props$3<T>) => react_jsx_runtime.JSX.Element;
237
+ declare const FormErrorsAlert: <T extends FieldValues = Record<string, any>>({ formState, fields, }: Props$3<T>) => react_jsx_runtime.JSX.Element;
235
238
  declare const getFieldLabel: <T extends FieldValues>(fieldErrorKey: string, fields: ReadonlyArray<FieldProps<T>>) => string;
236
239
 
237
240
  declare class InputFactory {
238
241
  static create<T extends Record<string, any> = Record<string, any>>(input: FieldProps<T>, form: UseFormReturn<T>, isSubmitting?: boolean): JSX.Element;
239
242
  }
240
- declare function getDefaultValues<T extends Record<string, any>>(entity?: Partial<T>, fields?: Array<FieldProps<T> | FieldProps<T>[]>): Record<string, any>;
241
- declare const getDynamicSchema: <T extends Record<string, any>>(fields: Array<FieldProps<T> | FieldProps<T>[]>, extraValidations?: ((schema: ZodObject<any>) => ZodObject<any>)[]) => ZodObject<Record<keyof T, ZodTypeAny>>;
243
+ declare function getDefaultValues<T extends Record<string, any>>(entity?: Partial<T>, fields?: FieldConfig<T>[]): Record<string, any>;
244
+ declare const getDynamicSchema: <T extends Record<string, any>>(fields: FieldConfig<T>[], extraValidations?: ((schema: ZodObject<any>) => ZodObject<any>)[]) => ZodObject<Record<keyof T, ZodTypeAny>>;
242
245
 
243
246
  declare class CheckListInput extends BaseInput {
244
247
  render(): JSX.Element;
@@ -447,4 +450,4 @@ declare function TooltipContent({ className, sideOffset, children, ...props }: R
447
450
 
448
451
  declare function cn(...inputs: ClassValue[]): string;
449
452
 
450
- export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, type BtnConfig, Button, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CheckListInput, Checkbox, ColorCnInput, type ColorCompProps, ColorInput, CustomAlert, DateInput, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DynamicForm, DynamicFormExample, type FieldProps, FileInput, Form, FormControl, FormDescription, FormErrorsAlert, FormField, FormItem, FormLabel, FormMessage, type FormResp, type GroupedOption, GroupedSwitchInput, GroupedSwitches, Input, InputFactory, InputList, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, type InputOption, type InputSetup, InputTypes, Label, NumberInput, OTPInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, type Props, ResizableHandle, ResizablePanel, ResizablePanelGroup, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectInput, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Switch, SwitchInput, TextAreaInput, TextInput, TextInputType, Textarea, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, buttonVariants, cn, entitiesToGroupedOption, entitiesToInputOption, entityToGroupedOption, entityToInputOption, getDefaultValues, getDynamicSchema, getFieldLabel, inputFieldComp, mockFields, useFormField, validationMessages };
453
+ export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, type BtnConfig, Button, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CheckListInput, Checkbox, ColorCnInput, type ColorCompProps, ColorInput, CustomAlert, DateInput, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DynamicForm, DynamicFormExample, type FieldConfig, type FieldProps, FileInput, Form, FormControl, FormDescription, FormErrorsAlert, FormField, FormItem, FormLabel, FormMessage, type FormResp, type GroupedOption, GroupedSwitchInput, GroupedSwitches, Input, InputFactory, InputList, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, type InputOption, type InputSetup, InputTypes, Label, NumberInput, OTPInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, type Props, ResizableHandle, ResizablePanel, ResizablePanelGroup, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectInput, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Switch, SwitchInput, TextAreaInput, TextInput, TextInputType, Textarea, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, buttonVariants, cn, entitiesToGroupedOption, entitiesToInputOption, entityToGroupedOption, entityToInputOption, flattenFields, getDefaultValues, getDynamicSchema, getFieldLabel, inputFieldComp, mockFields, useFormField, validationMessages };
package/dist/index.d.ts CHANGED
@@ -78,6 +78,8 @@ declare enum InputTypes {
78
78
  }
79
79
  declare const inputFieldComp: InputTypes[];
80
80
 
81
+ declare const flattenFields: <T extends Record<string, any>>(fields: FieldConfig<T>[]) => FieldProps<T>[];
82
+ type FieldConfig<T> = FieldProps<T> | FieldConfig<T>[];
81
83
  interface FieldProps<T = Record<string, any>> {
82
84
  name: keyof T;
83
85
  label: string;
@@ -86,6 +88,7 @@ interface FieldProps<T = Record<string, any>> {
86
88
  childrenPosition?: 'up' | 'down';
87
89
  children?: ReactNode | ((item: any, index: number) => ReactNode);
88
90
  defaultValue?: any;
91
+ direction?: 'row' | 'col';
89
92
  repeaterFields?: Array<FieldProps | FieldProps[]>;
90
93
  minItems?: number;
91
94
  maxItems?: number;
@@ -208,7 +211,7 @@ interface Props$4<T extends Record<string, any>> {
208
211
  formTitle: string;
209
212
  formSubTitle?: string;
210
213
  readOnly?: boolean;
211
- fields: Array<FieldProps<T> | FieldProps<T>[]>;
214
+ fields: FieldConfig<T>[];
212
215
  record?: Partial<T>;
213
216
  onSubmit?: (resp: FormResp<T>) => void;
214
217
  onClick?: (resp: FormResp<T>) => void;
@@ -229,16 +232,16 @@ declare const mockFields: Array<FieldProps | FieldProps[]>;
229
232
 
230
233
  interface Props$3<T extends FieldValues = Record<string, any>> {
231
234
  formState: FormState<any>;
232
- fields: Array<FieldProps<T> | FieldProps<T>[]>;
235
+ fields: FieldConfig<T>[];
233
236
  }
234
- declare const FormErrorsAlert: <T extends FieldValues = Record<string, any>>({ formState, fields }: Props$3<T>) => react_jsx_runtime.JSX.Element;
237
+ declare const FormErrorsAlert: <T extends FieldValues = Record<string, any>>({ formState, fields, }: Props$3<T>) => react_jsx_runtime.JSX.Element;
235
238
  declare const getFieldLabel: <T extends FieldValues>(fieldErrorKey: string, fields: ReadonlyArray<FieldProps<T>>) => string;
236
239
 
237
240
  declare class InputFactory {
238
241
  static create<T extends Record<string, any> = Record<string, any>>(input: FieldProps<T>, form: UseFormReturn<T>, isSubmitting?: boolean): JSX.Element;
239
242
  }
240
- declare function getDefaultValues<T extends Record<string, any>>(entity?: Partial<T>, fields?: Array<FieldProps<T> | FieldProps<T>[]>): Record<string, any>;
241
- declare const getDynamicSchema: <T extends Record<string, any>>(fields: Array<FieldProps<T> | FieldProps<T>[]>, extraValidations?: ((schema: ZodObject<any>) => ZodObject<any>)[]) => ZodObject<Record<keyof T, ZodTypeAny>>;
243
+ declare function getDefaultValues<T extends Record<string, any>>(entity?: Partial<T>, fields?: FieldConfig<T>[]): Record<string, any>;
244
+ declare const getDynamicSchema: <T extends Record<string, any>>(fields: FieldConfig<T>[], extraValidations?: ((schema: ZodObject<any>) => ZodObject<any>)[]) => ZodObject<Record<keyof T, ZodTypeAny>>;
242
245
 
243
246
  declare class CheckListInput extends BaseInput {
244
247
  render(): JSX.Element;
@@ -447,4 +450,4 @@ declare function TooltipContent({ className, sideOffset, children, ...props }: R
447
450
 
448
451
  declare function cn(...inputs: ClassValue[]): string;
449
452
 
450
- export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, type BtnConfig, Button, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CheckListInput, Checkbox, ColorCnInput, type ColorCompProps, ColorInput, CustomAlert, DateInput, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DynamicForm, DynamicFormExample, type FieldProps, FileInput, Form, FormControl, FormDescription, FormErrorsAlert, FormField, FormItem, FormLabel, FormMessage, type FormResp, type GroupedOption, GroupedSwitchInput, GroupedSwitches, Input, InputFactory, InputList, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, type InputOption, type InputSetup, InputTypes, Label, NumberInput, OTPInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, type Props, ResizableHandle, ResizablePanel, ResizablePanelGroup, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectInput, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Switch, SwitchInput, TextAreaInput, TextInput, TextInputType, Textarea, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, buttonVariants, cn, entitiesToGroupedOption, entitiesToInputOption, entityToGroupedOption, entityToInputOption, getDefaultValues, getDynamicSchema, getFieldLabel, inputFieldComp, mockFields, useFormField, validationMessages };
453
+ export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, type BtnConfig, Button, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CheckListInput, Checkbox, ColorCnInput, type ColorCompProps, ColorInput, CustomAlert, DateInput, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DynamicForm, DynamicFormExample, type FieldConfig, type FieldProps, FileInput, Form, FormControl, FormDescription, FormErrorsAlert, FormField, FormItem, FormLabel, FormMessage, type FormResp, type GroupedOption, GroupedSwitchInput, GroupedSwitches, Input, InputFactory, InputList, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, type InputOption, type InputSetup, InputTypes, Label, NumberInput, OTPInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, type Props, ResizableHandle, ResizablePanel, ResizablePanelGroup, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectInput, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Switch, SwitchInput, TextAreaInput, TextInput, TextInputType, Textarea, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, buttonVariants, cn, entitiesToGroupedOption, entitiesToInputOption, entityToGroupedOption, entityToInputOption, flattenFields, getDefaultValues, getDynamicSchema, getFieldLabel, inputFieldComp, mockFields, useFormField, validationMessages };
package/dist/index.mjs CHANGED
@@ -196,6 +196,19 @@ var entitiesToGroupedOption = (data, optionValue = "name") => {
196
196
  };
197
197
 
198
198
  // src/components/custom/form/inputs/base/definitions.ts
199
+ var flattenFields = (fields) => {
200
+ const result = [];
201
+ for (const field of fields) {
202
+ if (Array.isArray(field)) {
203
+ result.push(...flattenFields(field));
204
+ } else if (field.fields) {
205
+ result.push(...flattenFields(field.fields));
206
+ } else {
207
+ result.push(field);
208
+ }
209
+ }
210
+ return result;
211
+ };
199
212
  var TextInputType = /* @__PURE__ */ ((TextInputType2) => {
200
213
  TextInputType2["DEFAULT"] = "default";
201
214
  TextInputType2["NUMBER"] = "number";
@@ -1779,7 +1792,7 @@ var FieldButtonGroup = ({ input, form, isSubmitting, className = "w-full flex-1"
1779
1792
  if (input.listConfig?.onOptionChange) input.listConfig.onOptionChange(value);
1780
1793
  };
1781
1794
  const selectedValue = form.watch(input.name);
1782
- return /* @__PURE__ */ jsx(ButtonGroup, { className: "flex flex-row w-full", children: options.map((option) => /* @__PURE__ */ jsx(
1795
+ return /* @__PURE__ */ jsx(ButtonGroup, { className: "flex flex-row w-full", children: options.map((option, key) => /* @__PURE__ */ jsx(
1783
1796
  Button,
1784
1797
  {
1785
1798
  type: "button",
@@ -1789,7 +1802,7 @@ var FieldButtonGroup = ({ input, form, isSubmitting, className = "w-full flex-1"
1789
1802
  disabled: isSubmitting,
1790
1803
  children: option.label ?? option.name
1791
1804
  },
1792
- option.value
1805
+ key
1793
1806
  )) });
1794
1807
  };
1795
1808
  var CheckListInput = class extends BaseInput {
@@ -5455,32 +5468,12 @@ var InputFactory = class {
5455
5468
  function getDefaultValues(entity, fields) {
5456
5469
  const defaults = {};
5457
5470
  if (entity) {
5458
- for (const key in entity) {
5459
- const value = entity[key];
5460
- if (value === null || value === void 0) {
5461
- defaults[key] = "";
5462
- continue;
5463
- }
5464
- switch (typeof value) {
5465
- case "string":
5466
- defaults[key] = value;
5467
- break;
5468
- case "number":
5469
- defaults[key] = value;
5470
- break;
5471
- case "boolean":
5472
- defaults[key] = value;
5473
- break;
5474
- case "object":
5475
- defaults[key] = Array.isArray(value) ? [...value] : { ...value };
5476
- break;
5477
- default:
5478
- defaults[key] = value;
5479
- }
5480
- }
5471
+ Object.entries(entity).forEach(([key, value]) => {
5472
+ defaults[key] = value ?? "";
5473
+ });
5481
5474
  }
5482
5475
  if (fields) {
5483
- const flatFields = fields.flat();
5476
+ const flatFields = flattenFields2(fields);
5484
5477
  for (const field of flatFields) {
5485
5478
  const key = field.name;
5486
5479
  if (defaults[key] === void 0) {
@@ -5490,10 +5483,21 @@ function getDefaultValues(entity, fields) {
5490
5483
  }
5491
5484
  return defaults;
5492
5485
  }
5486
+ var flattenFields2 = (fields) => {
5487
+ const result = [];
5488
+ for (const field of fields) {
5489
+ if (Array.isArray(field)) {
5490
+ result.push(...flattenFields2(field));
5491
+ } else if (field.fields) {
5492
+ result.push(...flattenFields2(field.fields));
5493
+ } else {
5494
+ result.push(field);
5495
+ }
5496
+ }
5497
+ return result;
5498
+ };
5493
5499
  var getDynamicSchema = (fields, extraValidations) => {
5494
- const flatFields = fields.flatMap(
5495
- (f) => Array.isArray(f) ? f : [f]
5496
- );
5500
+ const flatFields = flattenFields2(fields);
5497
5501
  const shape = flatFields.reduce((acc, f) => {
5498
5502
  acc[f.name] = f.zodType ?? z2.any();
5499
5503
  return acc;
@@ -5506,12 +5510,26 @@ var getDynamicSchema = (fields, extraValidations) => {
5506
5510
  }
5507
5511
  return schema;
5508
5512
  };
5513
+ var flattenFields3 = (fields) => {
5514
+ const result = [];
5515
+ for (const field of fields) {
5516
+ if (Array.isArray(field)) {
5517
+ result.push(...flattenFields3(field));
5518
+ } else if (field.fields) {
5519
+ result.push(...flattenFields3(field.fields));
5520
+ } else {
5521
+ result.push(field);
5522
+ }
5523
+ }
5524
+ return result;
5525
+ };
5509
5526
  var FormErrorsAlert = ({
5510
5527
  formState,
5511
5528
  fields
5512
5529
  }) => {
5513
- const flatFields = fields.flatMap((f) => Array.isArray(f) ? f : [f]);
5514
- return /* @__PURE__ */ jsx("div", { style: { marginTop: 4 }, children: Object.entries(formState.errors).length > 0 && /* @__PURE__ */ jsx(
5530
+ const flatFields = flattenFields3(fields);
5531
+ const hasErrors = Object.keys(formState.errors).length > 0;
5532
+ return /* @__PURE__ */ jsx("div", { style: { marginTop: 4 }, children: hasErrors && /* @__PURE__ */ jsx(
5515
5533
  CustomAlert,
5516
5534
  {
5517
5535
  title: "Revisar los siguientes criterios",
@@ -5533,55 +5551,48 @@ var getFieldLabel = (fieldErrorKey, fields) => {
5533
5551
  return foundField?.label ?? fieldErrorKey;
5534
5552
  };
5535
5553
  var isRenderableChild = (c) => c !== void 0 && c !== null && typeof c !== "function";
5554
+ var isFieldProps = (f) => !Array.isArray(f);
5536
5555
  var FormFieldsGrid = ({
5537
5556
  fields,
5538
5557
  form,
5539
5558
  isPending,
5540
5559
  readOnly,
5541
5560
  className = "",
5542
- gap = "gap-2"
5561
+ gap = "gap-4"
5543
5562
  }) => {
5544
- return /* @__PURE__ */ jsx("div", { className: `w-full grid grid-cols-1 ${gap} ${className}`, children: fields.map(
5545
- (inputOrGroup, idx) => Array.isArray(inputOrGroup) ? /* @__PURE__ */ jsx(
5546
- "div",
5547
- {
5548
- className: "w-full flex flex-row items-start gap-4 py-3",
5549
- children: inputOrGroup.map((field, subIdx) => {
5550
- const fieldCopy = {
5551
- ...field,
5552
- disabled: readOnly ? true : field.disabled
5553
- };
5554
- const renderInlineChild = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
5555
- const renderInlineChildDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
5556
- return /* @__PURE__ */ jsxs("div", { className: "w-full px-2", children: [
5557
- renderInlineChild && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children }),
5558
- InputFactory.create(fieldCopy, form, isPending),
5559
- renderInlineChildDown && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children })
5560
- ] }, `field-${idx}-${subIdx}`);
5561
- })
5562
- },
5563
- `field-group-${idx}`
5564
- ) : /* @__PURE__ */ jsx(
5565
- "div",
5566
- {
5567
- className: "flex flex-col justify-between py-3 w-full px-2",
5568
- children: (() => {
5569
- const fieldCopy = {
5570
- ...inputOrGroup,
5571
- disabled: readOnly ? true : inputOrGroup.disabled
5572
- };
5573
- const renderUp = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
5574
- const renderDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
5575
- return /* @__PURE__ */ jsxs(Fragment, { children: [
5576
- renderUp && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children }),
5577
- InputFactory.create(fieldCopy, form, isPending),
5578
- renderDown && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children })
5579
- ] });
5580
- })()
5581
- },
5582
- `field-single-${idx}`
5583
- )
5584
- ) });
5563
+ const renderField = (field) => {
5564
+ const fieldCopy = { ...field, disabled: readOnly ? true : field.disabled };
5565
+ const renderUp = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
5566
+ const renderDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
5567
+ const dirClass = fieldCopy.direction === "row" ? "flex flex-row items-center gap-4" : "flex flex-col gap-2";
5568
+ return /* @__PURE__ */ jsxs("div", { className: `${dirClass} w-full`, children: [
5569
+ renderUp && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children }),
5570
+ InputFactory.create(fieldCopy, form, isPending),
5571
+ renderDown && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children })
5572
+ ] });
5573
+ };
5574
+ const renderColumn = (col) => {
5575
+ if (col.length === 0) return null;
5576
+ const colDirection = isFieldProps(col[0]) && col[0].direction === "row" ? "flex flex-row gap-4" : "flex flex-col gap-2";
5577
+ return /* @__PURE__ */ jsx("div", { className: `${colDirection} flex-1`, children: col.map((item, idx) => {
5578
+ if (isFieldProps(item)) return renderField(item);
5579
+ if (Array.isArray(item)) return renderColumn(item);
5580
+ return null;
5581
+ }) });
5582
+ };
5583
+ const renderRow = (row) => {
5584
+ if (row.length === 0) return null;
5585
+ return /* @__PURE__ */ jsx("div", { className: "w-full flex flex-row gap-4 py-2", children: row.map((col, idx) => {
5586
+ if (isFieldProps(col)) return renderColumn([col]);
5587
+ if (Array.isArray(col)) return renderColumn(col);
5588
+ return null;
5589
+ }) });
5590
+ };
5591
+ return /* @__PURE__ */ jsx("div", { className: `w-full flex flex-col gap-4 ${className}`, children: fields.map((f, idx) => {
5592
+ if (isFieldProps(f)) return /* @__PURE__ */ jsx("div", { children: renderField(f) }, idx);
5593
+ if (Array.isArray(f)) return /* @__PURE__ */ jsx("div", { children: renderRow(f) }, idx);
5594
+ return null;
5595
+ }) });
5585
5596
  };
5586
5597
  var DynamicForm = ({
5587
5598
  formTitle,
@@ -5604,7 +5615,10 @@ var DynamicForm = ({
5604
5615
  submitBtnLabel = "Guardar"
5605
5616
  }) => {
5606
5617
  const [isPending, startTransition] = useTransition();
5607
- const schema = useMemo(() => getDynamicSchema(fields, extraValidations), [fields, extraValidations]);
5618
+ const schema = useMemo(() => {
5619
+ const allFields = flattenFields(fields);
5620
+ return getDynamicSchema(allFields, extraValidations);
5621
+ }, [fields, extraValidations]);
5608
5622
  const resolver = zodResolver(schema);
5609
5623
  const initialValues = useMemo(() => getDefaultValues(record), [record]);
5610
5624
  const form = useForm({
@@ -5640,7 +5654,13 @@ var DynamicForm = ({
5640
5654
  ] }),
5641
5655
  childrenHeader && /* @__PURE__ */ jsx("div", { className: "flex flex-row items-center gap-2 w-full h-full", children: childrenHeader })
5642
5656
  ] }),
5643
- withErrorsAlert && errorAlertPosition === "up" && /* @__PURE__ */ jsx(FormErrorsAlert, { formState: form.formState, fields }),
5657
+ withErrorsAlert && errorAlertPosition === "up" && /* @__PURE__ */ jsx(
5658
+ FormErrorsAlert,
5659
+ {
5660
+ formState: form.formState,
5661
+ fields
5662
+ }
5663
+ ),
5644
5664
  /* @__PURE__ */ jsx(Form, { ...form, children: /* @__PURE__ */ jsxs(
5645
5665
  "form",
5646
5666
  {
@@ -5648,10 +5668,17 @@ var DynamicForm = ({
5648
5668
  className: `flex flex-col gap-2 ${readOnly ? "opacity-70 pointer-events-none select-none" : ""}`,
5649
5669
  children: [
5650
5670
  /* @__PURE__ */ jsxs("div", { className: "w-full grid grid-cols-1", children: [
5651
- /* @__PURE__ */ jsx(FormFieldsGrid, { fields, form, readOnly }),
5671
+ /* @__PURE__ */ jsx(
5672
+ FormFieldsGrid,
5673
+ {
5674
+ fields,
5675
+ form,
5676
+ readOnly
5677
+ }
5678
+ ),
5652
5679
  children && /* @__PURE__ */ jsx("div", { className: "flex flex-row items-center gap-2 w-full h-full", children })
5653
5680
  ] }),
5654
- /* @__PURE__ */ jsxs(ButtonGroup, { className: "flex flex-row w-full", children: [
5681
+ /* @__PURE__ */ jsxs(ButtonGroup, { className: "flex flex-row w-full", children: [
5655
5682
  listBtnConfig.map((btn, key) => /* @__PURE__ */ jsx(
5656
5683
  Button,
5657
5684
  {
@@ -5686,7 +5713,13 @@ var DynamicForm = ({
5686
5713
  ]
5687
5714
  }
5688
5715
  ) }),
5689
- withErrorsAlert && errorAlertPosition === "down" && /* @__PURE__ */ jsx(FormErrorsAlert, { formState: form.formState, fields })
5716
+ withErrorsAlert && errorAlertPosition === "down" && /* @__PURE__ */ jsx(
5717
+ FormErrorsAlert,
5718
+ {
5719
+ formState: form.formState,
5720
+ fields: fields.flatMap((f) => Array.isArray(f) ? f : [f])
5721
+ }
5722
+ )
5690
5723
  ] });
5691
5724
  if (!withCard) return formContent;
5692
5725
  return /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(CardContent, { children: formContent }) });
@@ -5866,6 +5899,6 @@ var InputList = ({ handleAddInput, inputsTypes }) => {
5866
5899
  }) });
5867
5900
  };
5868
5901
 
5869
- export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, Button, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CheckListInput, Checkbox, ColorCnInput, ColorInput, CustomAlert, DateInput, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DynamicForm, DynamicFormExample, FileInput, Form, FormControl, FormDescription, FormErrorsAlert, FormField, FormItem, FormLabel, FormMessage, GroupedSwitchInput, GroupedSwitches, Input, InputFactory, InputList, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, InputTypes, Label, NumberInput, OTPInput2 as OTPInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, ResizableHandle, ResizablePanel, ResizablePanelGroup, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectInput, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Switch, SwitchInput, TextAreaInput, TextInput, TextInputType, Textarea, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, buttonVariants, cn, entitiesToGroupedOption, entitiesToInputOption, entityToGroupedOption, entityToInputOption, getDefaultValues, getDynamicSchema, getFieldLabel, inputFieldComp, mockFields, useFormField, validationMessages };
5902
+ export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, Button, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CheckListInput, Checkbox, ColorCnInput, ColorInput, CustomAlert, DateInput, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DynamicForm, DynamicFormExample, FileInput, Form, FormControl, FormDescription, FormErrorsAlert, FormField, FormItem, FormLabel, FormMessage, GroupedSwitchInput, GroupedSwitches, Input, InputFactory, InputList, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, InputTypes, Label, NumberInput, OTPInput2 as OTPInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, ResizableHandle, ResizablePanel, ResizablePanelGroup, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectInput, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Switch, SwitchInput, TextAreaInput, TextInput, TextInputType, Textarea, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, buttonVariants, cn, entitiesToGroupedOption, entitiesToInputOption, entityToGroupedOption, entityToInputOption, flattenFields, getDefaultValues, getDynamicSchema, getFieldLabel, inputFieldComp, mockFields, useFormField, validationMessages };
5870
5903
  //# sourceMappingURL=index.mjs.map
5871
5904
  //# sourceMappingURL=index.mjs.map