shadcn-zod-formkit 1.20.0 → 1.21.0

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,6 +5551,9 @@ 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) => {
5555
+ return !Array.isArray(f);
5556
+ };
5536
5557
  var FormFieldsGrid = ({
5537
5558
  fields,
5538
5559
  form,
@@ -5541,47 +5562,54 @@ var FormFieldsGrid = ({
5541
5562
  className = "",
5542
5563
  gap = "gap-2"
5543
5564
  }) => {
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
- ) });
5565
+ const renderField = (field) => {
5566
+ const fieldCopy = {
5567
+ ...field,
5568
+ disabled: readOnly ? true : field.disabled
5569
+ };
5570
+ const renderUp = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
5571
+ const renderDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
5572
+ const dirClass = fieldCopy.direction === "row" ? "flex flex-row items-center gap-4 w-full px-2" : "flex flex-col gap-2 w-full px-2";
5573
+ return /* @__PURE__ */ jsxs("div", { className: dirClass, children: [
5574
+ renderUp && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children }),
5575
+ InputFactory.create(fieldCopy, form, isPending),
5576
+ renderDown && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children })
5577
+ ] });
5578
+ };
5579
+ const renderGroup = (group, groupDirection = "row") => {
5580
+ const dirClass = groupDirection === "row" ? "flex flex-row items-start gap-4 py-3 w-full" : "flex flex-col gap-4 py-3 w-full";
5581
+ return /* @__PURE__ */ jsx("div", { className: dirClass, children: group.map(
5582
+ (f, idx) => isFieldProps(f) ? renderField(f) : Array.isArray(f) ? (
5583
+ // ⚠ Solo soportamos [[FieldProps]] como subgrupo
5584
+ /* @__PURE__ */ jsx("div", { className: "w-full flex flex-row items-start gap-4", children: f.map(
5585
+ (subField) => isFieldProps(subField) ? renderField(subField) : null
5586
+ ) }, idx)
5587
+ ) : null
5588
+ ) });
5589
+ };
5590
+ return /* @__PURE__ */ jsx("div", { className: `w-full grid grid-cols-1 ${gap} ${className}`, children: fields.map((f, idx) => {
5591
+ if (isFieldProps(f)) {
5592
+ return renderField(f);
5593
+ } else if (Array.isArray(f)) {
5594
+ if (f.length > 0 && Array.isArray(f[0])) {
5595
+ return /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-4 py-3", children: f.map((subGroup, subIdx) => /* @__PURE__ */ jsx(
5596
+ "div",
5597
+ {
5598
+ className: "w-full flex flex-row items-start gap-4",
5599
+ children: Array.isArray(subGroup) && subGroup.map(
5600
+ (subField) => isFieldProps(subField) ? renderField(subField) : null
5601
+ )
5602
+ },
5603
+ subIdx
5604
+ )) }, idx);
5605
+ } else {
5606
+ const firstField = f[0];
5607
+ const direction = firstField?.direction ?? "row";
5608
+ return /* @__PURE__ */ jsx("div", { children: renderGroup(f, direction) }, idx);
5609
+ }
5610
+ }
5611
+ return null;
5612
+ }) });
5585
5613
  };
5586
5614
  var DynamicForm = ({
5587
5615
  formTitle,
@@ -5604,7 +5632,10 @@ var DynamicForm = ({
5604
5632
  submitBtnLabel = "Guardar"
5605
5633
  }) => {
5606
5634
  const [isPending, startTransition] = useTransition();
5607
- const schema = useMemo(() => getDynamicSchema(fields, extraValidations), [fields, extraValidations]);
5635
+ const schema = useMemo(() => {
5636
+ const allFields = flattenFields(fields);
5637
+ return getDynamicSchema(allFields, extraValidations);
5638
+ }, [fields, extraValidations]);
5608
5639
  const resolver = zodResolver(schema);
5609
5640
  const initialValues = useMemo(() => getDefaultValues(record), [record]);
5610
5641
  const form = useForm({
@@ -5640,7 +5671,13 @@ var DynamicForm = ({
5640
5671
  ] }),
5641
5672
  childrenHeader && /* @__PURE__ */ jsx("div", { className: "flex flex-row items-center gap-2 w-full h-full", children: childrenHeader })
5642
5673
  ] }),
5643
- withErrorsAlert && errorAlertPosition === "up" && /* @__PURE__ */ jsx(FormErrorsAlert, { formState: form.formState, fields }),
5674
+ withErrorsAlert && errorAlertPosition === "up" && /* @__PURE__ */ jsx(
5675
+ FormErrorsAlert,
5676
+ {
5677
+ formState: form.formState,
5678
+ fields
5679
+ }
5680
+ ),
5644
5681
  /* @__PURE__ */ jsx(Form, { ...form, children: /* @__PURE__ */ jsxs(
5645
5682
  "form",
5646
5683
  {
@@ -5648,10 +5685,17 @@ var DynamicForm = ({
5648
5685
  className: `flex flex-col gap-2 ${readOnly ? "opacity-70 pointer-events-none select-none" : ""}`,
5649
5686
  children: [
5650
5687
  /* @__PURE__ */ jsxs("div", { className: "w-full grid grid-cols-1", children: [
5651
- /* @__PURE__ */ jsx(FormFieldsGrid, { fields, form, readOnly }),
5688
+ /* @__PURE__ */ jsx(
5689
+ FormFieldsGrid,
5690
+ {
5691
+ fields,
5692
+ form,
5693
+ readOnly
5694
+ }
5695
+ ),
5652
5696
  children && /* @__PURE__ */ jsx("div", { className: "flex flex-row items-center gap-2 w-full h-full", children })
5653
5697
  ] }),
5654
- /* @__PURE__ */ jsxs(ButtonGroup, { className: "flex flex-row w-full", children: [
5698
+ /* @__PURE__ */ jsxs(ButtonGroup, { className: "flex flex-row w-full", children: [
5655
5699
  listBtnConfig.map((btn, key) => /* @__PURE__ */ jsx(
5656
5700
  Button,
5657
5701
  {
@@ -5686,7 +5730,13 @@ var DynamicForm = ({
5686
5730
  ]
5687
5731
  }
5688
5732
  ) }),
5689
- withErrorsAlert && errorAlertPosition === "down" && /* @__PURE__ */ jsx(FormErrorsAlert, { formState: form.formState, fields })
5733
+ withErrorsAlert && errorAlertPosition === "down" && /* @__PURE__ */ jsx(
5734
+ FormErrorsAlert,
5735
+ {
5736
+ formState: form.formState,
5737
+ fields: fields.flatMap((f) => Array.isArray(f) ? f : [f])
5738
+ }
5739
+ )
5690
5740
  ] });
5691
5741
  if (!withCard) return formContent;
5692
5742
  return /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(CardContent, { children: formContent }) });
@@ -5866,6 +5916,6 @@ var InputList = ({ handleAddInput, inputsTypes }) => {
5866
5916
  }) });
5867
5917
  };
5868
5918
 
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 };
5919
+ 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
5920
  //# sourceMappingURL=index.mjs.map
5871
5921
  //# sourceMappingURL=index.mjs.map