shadcn-zod-formkit 1.19.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,13 +78,17 @@ 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
+ onChange?: (...event: any[]) => void;
84
87
  tabLabelField?: string;
85
88
  childrenPosition?: 'up' | 'down';
86
89
  children?: ReactNode | ((item: any, index: number) => ReactNode);
87
90
  defaultValue?: any;
91
+ direction?: 'row' | 'col';
88
92
  repeaterFields?: Array<FieldProps | FieldProps[]>;
89
93
  minItems?: number;
90
94
  maxItems?: number;
@@ -207,7 +211,7 @@ interface Props$4<T extends Record<string, any>> {
207
211
  formTitle: string;
208
212
  formSubTitle?: string;
209
213
  readOnly?: boolean;
210
- fields: Array<FieldProps<T> | FieldProps<T>[]>;
214
+ fields: FieldConfig<T>[];
211
215
  record?: Partial<T>;
212
216
  onSubmit?: (resp: FormResp<T>) => void;
213
217
  onClick?: (resp: FormResp<T>) => void;
@@ -228,16 +232,16 @@ declare const mockFields: Array<FieldProps | FieldProps[]>;
228
232
 
229
233
  interface Props$3<T extends FieldValues = Record<string, any>> {
230
234
  formState: FormState<any>;
231
- fields: Array<FieldProps<T> | FieldProps<T>[]>;
235
+ fields: FieldConfig<T>[];
232
236
  }
233
- 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;
234
238
  declare const getFieldLabel: <T extends FieldValues>(fieldErrorKey: string, fields: ReadonlyArray<FieldProps<T>>) => string;
235
239
 
236
240
  declare class InputFactory {
237
241
  static create<T extends Record<string, any> = Record<string, any>>(input: FieldProps<T>, form: UseFormReturn<T>, isSubmitting?: boolean): JSX.Element;
238
242
  }
239
- declare function getDefaultValues<T extends Record<string, any>>(entity?: Partial<T>, fields?: Array<FieldProps<T> | FieldProps<T>[]>): Record<string, any>;
240
- 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>>;
241
245
 
242
246
  declare class CheckListInput extends BaseInput {
243
247
  render(): JSX.Element;
@@ -446,4 +450,4 @@ declare function TooltipContent({ className, sideOffset, children, ...props }: R
446
450
 
447
451
  declare function cn(...inputs: ClassValue[]): string;
448
452
 
449
- 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,13 +78,17 @@ 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
+ onChange?: (...event: any[]) => void;
84
87
  tabLabelField?: string;
85
88
  childrenPosition?: 'up' | 'down';
86
89
  children?: ReactNode | ((item: any, index: number) => ReactNode);
87
90
  defaultValue?: any;
91
+ direction?: 'row' | 'col';
88
92
  repeaterFields?: Array<FieldProps | FieldProps[]>;
89
93
  minItems?: number;
90
94
  maxItems?: number;
@@ -207,7 +211,7 @@ interface Props$4<T extends Record<string, any>> {
207
211
  formTitle: string;
208
212
  formSubTitle?: string;
209
213
  readOnly?: boolean;
210
- fields: Array<FieldProps<T> | FieldProps<T>[]>;
214
+ fields: FieldConfig<T>[];
211
215
  record?: Partial<T>;
212
216
  onSubmit?: (resp: FormResp<T>) => void;
213
217
  onClick?: (resp: FormResp<T>) => void;
@@ -228,16 +232,16 @@ declare const mockFields: Array<FieldProps | FieldProps[]>;
228
232
 
229
233
  interface Props$3<T extends FieldValues = Record<string, any>> {
230
234
  formState: FormState<any>;
231
- fields: Array<FieldProps<T> | FieldProps<T>[]>;
235
+ fields: FieldConfig<T>[];
232
236
  }
233
- 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;
234
238
  declare const getFieldLabel: <T extends FieldValues>(fieldErrorKey: string, fields: ReadonlyArray<FieldProps<T>>) => string;
235
239
 
236
240
  declare class InputFactory {
237
241
  static create<T extends Record<string, any> = Record<string, any>>(input: FieldProps<T>, form: UseFormReturn<T>, isSubmitting?: boolean): JSX.Element;
238
242
  }
239
- declare function getDefaultValues<T extends Record<string, any>>(entity?: Partial<T>, fields?: Array<FieldProps<T> | FieldProps<T>[]>): Record<string, any>;
240
- 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>>;
241
245
 
242
246
  declare class CheckListInput extends BaseInput {
243
247
  render(): JSX.Element;
@@ -446,4 +450,4 @@ declare function TooltipContent({ className, sideOffset, children, ...props }: R
446
450
 
447
451
  declare function cn(...inputs: ClassValue[]): string;
448
452
 
449
- 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";
@@ -1768,25 +1781,28 @@ function ButtonGroup({
1768
1781
  var ButtonGroupInput = class extends BaseInput {
1769
1782
  render() {
1770
1783
  const { input, form, isSubmitting } = this;
1771
- return /* @__PURE__ */ jsx(FieldButtonGroup, { input, form, isSubmitting });
1784
+ const className = input.className;
1785
+ return /* @__PURE__ */ jsx(FieldButtonGroup, { input, form, isSubmitting, className });
1772
1786
  }
1773
1787
  };
1774
- var FieldButtonGroup = ({ input, form, isSubmitting }) => {
1788
+ var FieldButtonGroup = ({ input, form, isSubmitting, className = "w-full flex-1" }) => {
1775
1789
  const options = (input.listConfig?.list ?? []).filter((option) => "name" in option);
1776
1790
  const handleSelect = (value) => {
1777
1791
  form.setValue(input.name, value, { shouldValidate: true });
1792
+ if (input.listConfig?.onOptionChange) input.listConfig.onOptionChange(value);
1778
1793
  };
1779
1794
  const selectedValue = form.watch(input.name);
1780
- return /* @__PURE__ */ jsx(ButtonGroup, { children: options.map((option) => /* @__PURE__ */ jsx(
1795
+ return /* @__PURE__ */ jsx(ButtonGroup, { className: "flex flex-row w-full", children: options.map((option, key) => /* @__PURE__ */ jsx(
1781
1796
  Button,
1782
1797
  {
1783
1798
  type: "button",
1799
+ className,
1784
1800
  variant: selectedValue === option.value ? "default" : "outline",
1785
1801
  onClick: () => handleSelect(option.value),
1786
1802
  disabled: isSubmitting,
1787
1803
  children: option.label ?? option.name
1788
1804
  },
1789
- option.value
1805
+ key
1790
1806
  )) });
1791
1807
  };
1792
1808
  var CheckListInput = class extends BaseInput {
@@ -3977,7 +3993,6 @@ var FieldFile = ({ form, input, isSubmitting }) => {
3977
3993
  if (file) {
3978
3994
  const objectUrl = URL.createObjectURL(file);
3979
3995
  setPreview(objectUrl);
3980
- console.log("\u{1F680} ~ handleFileChange ~ objectUrl:", objectUrl);
3981
3996
  } else {
3982
3997
  setPreview(null);
3983
3998
  }
@@ -5453,32 +5468,12 @@ var InputFactory = class {
5453
5468
  function getDefaultValues(entity, fields) {
5454
5469
  const defaults = {};
5455
5470
  if (entity) {
5456
- for (const key in entity) {
5457
- const value = entity[key];
5458
- if (value === null || value === void 0) {
5459
- defaults[key] = "";
5460
- continue;
5461
- }
5462
- switch (typeof value) {
5463
- case "string":
5464
- defaults[key] = value;
5465
- break;
5466
- case "number":
5467
- defaults[key] = value;
5468
- break;
5469
- case "boolean":
5470
- defaults[key] = value;
5471
- break;
5472
- case "object":
5473
- defaults[key] = Array.isArray(value) ? [...value] : { ...value };
5474
- break;
5475
- default:
5476
- defaults[key] = value;
5477
- }
5478
- }
5471
+ Object.entries(entity).forEach(([key, value]) => {
5472
+ defaults[key] = value ?? "";
5473
+ });
5479
5474
  }
5480
5475
  if (fields) {
5481
- const flatFields = fields.flat();
5476
+ const flatFields = flattenFields2(fields);
5482
5477
  for (const field of flatFields) {
5483
5478
  const key = field.name;
5484
5479
  if (defaults[key] === void 0) {
@@ -5488,10 +5483,21 @@ function getDefaultValues(entity, fields) {
5488
5483
  }
5489
5484
  return defaults;
5490
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
+ };
5491
5499
  var getDynamicSchema = (fields, extraValidations) => {
5492
- const flatFields = fields.flatMap(
5493
- (f) => Array.isArray(f) ? f : [f]
5494
- );
5500
+ const flatFields = flattenFields2(fields);
5495
5501
  const shape = flatFields.reduce((acc, f) => {
5496
5502
  acc[f.name] = f.zodType ?? z2.any();
5497
5503
  return acc;
@@ -5504,12 +5510,26 @@ var getDynamicSchema = (fields, extraValidations) => {
5504
5510
  }
5505
5511
  return schema;
5506
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
+ };
5507
5526
  var FormErrorsAlert = ({
5508
5527
  formState,
5509
5528
  fields
5510
5529
  }) => {
5511
- const flatFields = fields.flatMap((f) => Array.isArray(f) ? f : [f]);
5512
- 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(
5513
5533
  CustomAlert,
5514
5534
  {
5515
5535
  title: "Revisar los siguientes criterios",
@@ -5531,6 +5551,9 @@ var getFieldLabel = (fieldErrorKey, fields) => {
5531
5551
  return foundField?.label ?? fieldErrorKey;
5532
5552
  };
5533
5553
  var isRenderableChild = (c) => c !== void 0 && c !== null && typeof c !== "function";
5554
+ var isFieldProps = (f) => {
5555
+ return !Array.isArray(f);
5556
+ };
5534
5557
  var FormFieldsGrid = ({
5535
5558
  fields,
5536
5559
  form,
@@ -5539,47 +5562,54 @@ var FormFieldsGrid = ({
5539
5562
  className = "",
5540
5563
  gap = "gap-2"
5541
5564
  }) => {
5542
- return /* @__PURE__ */ jsx("div", { className: `w-full grid grid-cols-1 ${gap} ${className}`, children: fields.map(
5543
- (inputOrGroup, idx) => Array.isArray(inputOrGroup) ? /* @__PURE__ */ jsx(
5544
- "div",
5545
- {
5546
- className: "w-full flex flex-row items-start gap-4 py-3",
5547
- children: inputOrGroup.map((field, subIdx) => {
5548
- const fieldCopy = {
5549
- ...field,
5550
- disabled: readOnly ? true : field.disabled
5551
- };
5552
- const renderInlineChild = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
5553
- const renderInlineChildDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
5554
- return /* @__PURE__ */ jsxs("div", { className: "w-full px-2", children: [
5555
- renderInlineChild && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children }),
5556
- InputFactory.create(fieldCopy, form, isPending),
5557
- renderInlineChildDown && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children })
5558
- ] }, `field-${idx}-${subIdx}`);
5559
- })
5560
- },
5561
- `field-group-${idx}`
5562
- ) : /* @__PURE__ */ jsx(
5563
- "div",
5564
- {
5565
- className: "flex flex-col justify-between py-3 w-full px-2",
5566
- children: (() => {
5567
- const fieldCopy = {
5568
- ...inputOrGroup,
5569
- disabled: readOnly ? true : inputOrGroup.disabled
5570
- };
5571
- const renderUp = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
5572
- const renderDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
5573
- return /* @__PURE__ */ jsxs(Fragment, { 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
- },
5580
- `field-single-${idx}`
5581
- )
5582
- ) });
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
+ }) });
5583
5613
  };
5584
5614
  var DynamicForm = ({
5585
5615
  formTitle,
@@ -5602,7 +5632,10 @@ var DynamicForm = ({
5602
5632
  submitBtnLabel = "Guardar"
5603
5633
  }) => {
5604
5634
  const [isPending, startTransition] = useTransition();
5605
- 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]);
5606
5639
  const resolver = zodResolver(schema);
5607
5640
  const initialValues = useMemo(() => getDefaultValues(record), [record]);
5608
5641
  const form = useForm({
@@ -5638,7 +5671,13 @@ var DynamicForm = ({
5638
5671
  ] }),
5639
5672
  childrenHeader && /* @__PURE__ */ jsx("div", { className: "flex flex-row items-center gap-2 w-full h-full", children: childrenHeader })
5640
5673
  ] }),
5641
- 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
+ ),
5642
5681
  /* @__PURE__ */ jsx(Form, { ...form, children: /* @__PURE__ */ jsxs(
5643
5682
  "form",
5644
5683
  {
@@ -5646,10 +5685,17 @@ var DynamicForm = ({
5646
5685
  className: `flex flex-col gap-2 ${readOnly ? "opacity-70 pointer-events-none select-none" : ""}`,
5647
5686
  children: [
5648
5687
  /* @__PURE__ */ jsxs("div", { className: "w-full grid grid-cols-1", children: [
5649
- /* @__PURE__ */ jsx(FormFieldsGrid, { fields, form, readOnly }),
5688
+ /* @__PURE__ */ jsx(
5689
+ FormFieldsGrid,
5690
+ {
5691
+ fields,
5692
+ form,
5693
+ readOnly
5694
+ }
5695
+ ),
5650
5696
  children && /* @__PURE__ */ jsx("div", { className: "flex flex-row items-center gap-2 w-full h-full", children })
5651
5697
  ] }),
5652
- /* @__PURE__ */ jsxs(ButtonGroup, { className: "flex flex-row w-full", children: [
5698
+ /* @__PURE__ */ jsxs(ButtonGroup, { className: "flex flex-row w-full", children: [
5653
5699
  listBtnConfig.map((btn, key) => /* @__PURE__ */ jsx(
5654
5700
  Button,
5655
5701
  {
@@ -5684,7 +5730,13 @@ var DynamicForm = ({
5684
5730
  ]
5685
5731
  }
5686
5732
  ) }),
5687
- 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
+ )
5688
5740
  ] });
5689
5741
  if (!withCard) return formContent;
5690
5742
  return /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(CardContent, { children: formContent }) });
@@ -5864,6 +5916,6 @@ var InputList = ({ handleAddInput, inputsTypes }) => {
5864
5916
  }) });
5865
5917
  };
5866
5918
 
5867
- 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 };
5868
5920
  //# sourceMappingURL=index.mjs.map
5869
5921
  //# sourceMappingURL=index.mjs.map