shadcn-zod-formkit 1.7.0 → 1.9.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
@@ -70,12 +70,13 @@ declare enum InputTypes {
70
70
  BUTTON_GROUP = "button_group",
71
71
  CURRENCY = "currency",
72
72
  KEY_VALUE = "key_value",
73
- REPEATER = "repeater"
73
+ REPEATER = "repeater",
74
+ MULTI_SELECT = "multi_select"
74
75
  }
75
76
  declare const inputFieldComp: InputTypes[];
76
77
 
77
- interface FieldProps {
78
- name: string;
78
+ interface FieldProps<T = Record<string, any>> {
79
+ name: keyof T;
79
80
  label: string;
80
81
  repeaterFields?: Array<FieldProps | FieldProps[]>;
81
82
  minItems?: number;
@@ -181,14 +182,14 @@ declare const entitiesToGroupedOption: (data: any[], optionValue?: string) => Gr
181
182
 
182
183
  type alertPositionType = 'up' | 'down';
183
184
  interface FormResp<T> {
184
- form?: UseFormReturn;
185
+ form?: UseFormReturn<any>;
185
186
  data: T;
186
187
  }
187
188
  interface Props$4<T extends Record<string, any>> {
188
189
  formTitle: string;
189
190
  formSubTitle?: string;
190
191
  readOnly?: boolean;
191
- fields: Array<FieldProps | FieldProps[]>;
192
+ fields: Array<FieldProps<T> | FieldProps<T>[]>;
192
193
  record?: Partial<T>;
193
194
  onSubmit?: (resp: FormResp<T>) => void;
194
195
  extraValidations?: ((schema: ZodObject<any>) => ZodObject<any>)[];
@@ -203,17 +204,18 @@ declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubT
203
204
  declare const DynamicFormExample: () => react_jsx_runtime.JSX.Element;
204
205
  declare const mockFields: Array<FieldProps | FieldProps[]>;
205
206
 
206
- interface Props$3<T extends FieldValues> {
207
- formState: FormState<T>;
208
- fields: Array<FieldProps | FieldProps[]>;
207
+ interface Props$3<T extends FieldValues = Record<string, any>> {
208
+ formState: FormState<any>;
209
+ fields: Array<FieldProps<T> | FieldProps<T>[]>;
209
210
  }
210
- declare const FormErrorsAlert: <T extends FieldValues>({ formState, fields }: Props$3<T>) => react_jsx_runtime.JSX.Element;
211
+ declare const FormErrorsAlert: <T extends FieldValues = Record<string, any>>({ formState, fields }: Props$3<T>) => react_jsx_runtime.JSX.Element;
212
+ declare const getFieldLabel: <T extends FieldValues>(fieldErrorKey: string, fields: ReadonlyArray<FieldProps<T>>) => string;
211
213
 
212
214
  declare class InputFactory {
213
- static create(input: FieldProps, form: UseFormReturn, isSubmitting?: boolean): JSX.Element;
215
+ static create<T extends Record<string, any> = Record<string, any>>(input: FieldProps<T>, form: UseFormReturn<T>, isSubmitting?: boolean): JSX.Element;
214
216
  }
215
- declare function getDefaultValues<T extends Record<string, any>>(entity: T): Record<string, any>;
216
- declare const getDynamicSchema: (fields: Array<FieldProps | FieldProps[]>, extraValidations?: ((schema: ZodObject<any>) => ZodObject<any>)[]) => ZodObject<any>;
217
+ declare function getDefaultValues<T extends Record<string, any>>(entity?: Partial<T>): Record<string, any>;
218
+ 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>>;
217
219
 
218
220
  declare class CheckListInput extends BaseInput {
219
221
  render(): JSX.Element;
@@ -422,4 +424,4 @@ declare function TooltipContent({ className, sideOffset, children, ...props }: R
422
424
 
423
425
  declare function cn(...inputs: ClassValue[]): string;
424
426
 
425
- export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, 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, inputFieldComp, mockFields, useFormField, validationMessages };
427
+ export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, 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 };
package/dist/index.d.ts CHANGED
@@ -70,12 +70,13 @@ declare enum InputTypes {
70
70
  BUTTON_GROUP = "button_group",
71
71
  CURRENCY = "currency",
72
72
  KEY_VALUE = "key_value",
73
- REPEATER = "repeater"
73
+ REPEATER = "repeater",
74
+ MULTI_SELECT = "multi_select"
74
75
  }
75
76
  declare const inputFieldComp: InputTypes[];
76
77
 
77
- interface FieldProps {
78
- name: string;
78
+ interface FieldProps<T = Record<string, any>> {
79
+ name: keyof T;
79
80
  label: string;
80
81
  repeaterFields?: Array<FieldProps | FieldProps[]>;
81
82
  minItems?: number;
@@ -181,14 +182,14 @@ declare const entitiesToGroupedOption: (data: any[], optionValue?: string) => Gr
181
182
 
182
183
  type alertPositionType = 'up' | 'down';
183
184
  interface FormResp<T> {
184
- form?: UseFormReturn;
185
+ form?: UseFormReturn<any>;
185
186
  data: T;
186
187
  }
187
188
  interface Props$4<T extends Record<string, any>> {
188
189
  formTitle: string;
189
190
  formSubTitle?: string;
190
191
  readOnly?: boolean;
191
- fields: Array<FieldProps | FieldProps[]>;
192
+ fields: Array<FieldProps<T> | FieldProps<T>[]>;
192
193
  record?: Partial<T>;
193
194
  onSubmit?: (resp: FormResp<T>) => void;
194
195
  extraValidations?: ((schema: ZodObject<any>) => ZodObject<any>)[];
@@ -203,17 +204,18 @@ declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubT
203
204
  declare const DynamicFormExample: () => react_jsx_runtime.JSX.Element;
204
205
  declare const mockFields: Array<FieldProps | FieldProps[]>;
205
206
 
206
- interface Props$3<T extends FieldValues> {
207
- formState: FormState<T>;
208
- fields: Array<FieldProps | FieldProps[]>;
207
+ interface Props$3<T extends FieldValues = Record<string, any>> {
208
+ formState: FormState<any>;
209
+ fields: Array<FieldProps<T> | FieldProps<T>[]>;
209
210
  }
210
- declare const FormErrorsAlert: <T extends FieldValues>({ formState, fields }: Props$3<T>) => react_jsx_runtime.JSX.Element;
211
+ declare const FormErrorsAlert: <T extends FieldValues = Record<string, any>>({ formState, fields }: Props$3<T>) => react_jsx_runtime.JSX.Element;
212
+ declare const getFieldLabel: <T extends FieldValues>(fieldErrorKey: string, fields: ReadonlyArray<FieldProps<T>>) => string;
211
213
 
212
214
  declare class InputFactory {
213
- static create(input: FieldProps, form: UseFormReturn, isSubmitting?: boolean): JSX.Element;
215
+ static create<T extends Record<string, any> = Record<string, any>>(input: FieldProps<T>, form: UseFormReturn<T>, isSubmitting?: boolean): JSX.Element;
214
216
  }
215
- declare function getDefaultValues<T extends Record<string, any>>(entity: T): Record<string, any>;
216
- declare const getDynamicSchema: (fields: Array<FieldProps | FieldProps[]>, extraValidations?: ((schema: ZodObject<any>) => ZodObject<any>)[]) => ZodObject<any>;
217
+ declare function getDefaultValues<T extends Record<string, any>>(entity?: Partial<T>): Record<string, any>;
218
+ 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>>;
217
219
 
218
220
  declare class CheckListInput extends BaseInput {
219
221
  render(): JSX.Element;
@@ -422,4 +424,4 @@ declare function TooltipContent({ className, sideOffset, children, ...props }: R
422
424
 
423
425
  declare function cn(...inputs: ClassValue[]): string;
424
426
 
425
- export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, 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, inputFieldComp, mockFields, useFormField, validationMessages };
427
+ export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, 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 };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, CheckIcon, XIcon, MinusIcon, GripVerticalIcon, ChevronUpIcon, CalendarIcon, EyeOff, Eye, Pencil, Loader2, Save, Plus, MessageCircleWarning, Info, CircleCheck, CircleX, Trash2, Upload, CircleIcon } from 'lucide-react';
1
+ import { ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, CheckIcon, XIcon, MinusIcon, GripVerticalIcon, ChevronUpIcon, CalendarIcon, EyeOff, Eye, Pencil, Loader2, Save, Plus, MessageCircleWarning, Info, CircleCheck, CircleX, ChevronsUpDown, Check, Trash2, Upload, SearchIcon, CircleIcon } from 'lucide-react';
2
2
  import { InfoCircledIcon } from '@radix-ui/react-icons';
3
3
  import { cva } from 'class-variance-authority';
4
4
  import { twMerge } from 'tailwind-merge';
@@ -25,6 +25,7 @@ import { useTheme } from 'next-themes';
25
25
  import { Toaster as Toaster$1 } from 'sonner';
26
26
  import * as SwitchPrimitive from '@radix-ui/react-switch';
27
27
  import * as TooltipPrimitive from '@radix-ui/react-tooltip';
28
+ import { Command as Command$1 } from 'cmdk';
28
29
  import * as SliderPrimitive from '@radix-ui/react-slider';
29
30
  import z2 from 'zod';
30
31
  import { zodResolver } from '@hookform/resolvers/zod';
@@ -229,9 +230,11 @@ var InputTypes = /* @__PURE__ */ ((InputTypes2) => {
229
230
  InputTypes2["CURRENCY"] = "currency";
230
231
  InputTypes2["KEY_VALUE"] = "key_value";
231
232
  InputTypes2["REPEATER"] = "repeater";
233
+ InputTypes2["MULTI_SELECT"] = "multi_select";
232
234
  return InputTypes2;
233
235
  })(InputTypes || {});
234
236
  var inputFieldComp = [
237
+ "multi_select" /* MULTI_SELECT */,
235
238
  "repeater" /* REPEATER */,
236
239
  "key_value" /* KEY_VALUE */,
237
240
  "currency" /* CURRENCY */,
@@ -4007,6 +4010,201 @@ var FieldKeyValueList = ({ form, input, isSubmitting }) => {
4007
4010
  }
4008
4011
  );
4009
4012
  };
4013
+ function Command({
4014
+ className,
4015
+ ...props
4016
+ }) {
4017
+ return /* @__PURE__ */ jsx(
4018
+ Command$1,
4019
+ {
4020
+ "data-slot": "command",
4021
+ className: cn(
4022
+ "bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md",
4023
+ className
4024
+ ),
4025
+ ...props
4026
+ }
4027
+ );
4028
+ }
4029
+ function CommandInput({
4030
+ className,
4031
+ ...props
4032
+ }) {
4033
+ return /* @__PURE__ */ jsxs(
4034
+ "div",
4035
+ {
4036
+ "data-slot": "command-input-wrapper",
4037
+ className: "flex h-9 items-center gap-2 border-b px-3",
4038
+ children: [
4039
+ /* @__PURE__ */ jsx(SearchIcon, { className: "size-4 shrink-0 opacity-50" }),
4040
+ /* @__PURE__ */ jsx(
4041
+ Command$1.Input,
4042
+ {
4043
+ "data-slot": "command-input",
4044
+ className: cn(
4045
+ "placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50",
4046
+ className
4047
+ ),
4048
+ ...props
4049
+ }
4050
+ )
4051
+ ]
4052
+ }
4053
+ );
4054
+ }
4055
+ function CommandList({
4056
+ className,
4057
+ ...props
4058
+ }) {
4059
+ return /* @__PURE__ */ jsx(
4060
+ Command$1.List,
4061
+ {
4062
+ "data-slot": "command-list",
4063
+ className: cn(
4064
+ "max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",
4065
+ className
4066
+ ),
4067
+ ...props
4068
+ }
4069
+ );
4070
+ }
4071
+ function CommandEmpty({
4072
+ ...props
4073
+ }) {
4074
+ return /* @__PURE__ */ jsx(
4075
+ Command$1.Empty,
4076
+ {
4077
+ "data-slot": "command-empty",
4078
+ className: "py-6 text-center text-sm",
4079
+ ...props
4080
+ }
4081
+ );
4082
+ }
4083
+ function CommandGroup({
4084
+ className,
4085
+ ...props
4086
+ }) {
4087
+ return /* @__PURE__ */ jsx(
4088
+ Command$1.Group,
4089
+ {
4090
+ "data-slot": "command-group",
4091
+ className: cn(
4092
+ "text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium",
4093
+ className
4094
+ ),
4095
+ ...props
4096
+ }
4097
+ );
4098
+ }
4099
+ function CommandItem({
4100
+ className,
4101
+ ...props
4102
+ }) {
4103
+ return /* @__PURE__ */ jsx(
4104
+ Command$1.Item,
4105
+ {
4106
+ "data-slot": "command-item",
4107
+ className: cn(
4108
+ "data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
4109
+ className
4110
+ ),
4111
+ ...props
4112
+ }
4113
+ );
4114
+ }
4115
+ var MultiSelectInput = class extends BaseInput {
4116
+ render() {
4117
+ const { input, form, isSubmitting } = this;
4118
+ return /* @__PURE__ */ jsx(FieldMultiSelect, { input, form, isSubmitting });
4119
+ }
4120
+ };
4121
+ var FieldMultiSelect = ({ form, input, isSubmitting }) => {
4122
+ const mockInputOptions = [
4123
+ { id: 1, name: "PERMISO 1" },
4124
+ { id: 2, name: "PERMISO 2" },
4125
+ { id: 3, name: "PERMISO 3" },
4126
+ { id: 4, name: "PERMISO 4" }
4127
+ ];
4128
+ const lista = input?.listConfig?.list ?? mockInputOptions;
4129
+ const optionValue = input?.listConfig?.optionValue ?? input.optionValue ?? "id";
4130
+ const getValue = (item) => {
4131
+ if (optionValue === "name") return item[optionValue];
4132
+ return item.value ?? item.id;
4133
+ };
4134
+ const [open, setOpen] = useState(false);
4135
+ return /* @__PURE__ */ jsx(
4136
+ FormField,
4137
+ {
4138
+ control: form.control,
4139
+ name: input.name,
4140
+ render: ({ field }) => {
4141
+ const selectedValues = Array.isArray(field.value) ? field.value : [];
4142
+ const toggleOption = (value) => {
4143
+ const newValues = selectedValues.includes(value) ? selectedValues.filter((v) => v !== value) : [...selectedValues, value];
4144
+ field.onChange(newValues);
4145
+ };
4146
+ return /* @__PURE__ */ jsxs(FormItem, { className: "flex flex-col rounded-lg border p-3 shadow bg-blue-100/20", children: [
4147
+ /* @__PURE__ */ jsx(FormLabel, { children: /* @__PURE__ */ jsx("b", { children: input.label }) }),
4148
+ input.description && /* @__PURE__ */ jsx(FormDescription, { children: input.description }),
4149
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: setOpen, children: [
4150
+ /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
4151
+ Button,
4152
+ {
4153
+ variant: "outline",
4154
+ role: "combobox",
4155
+ disabled: input.disabled || isSubmitting,
4156
+ className: cn(
4157
+ "justify-between w-full bg-black/10 dark:bg-white/10",
4158
+ !selectedValues.length && "text-muted-foreground"
4159
+ ),
4160
+ children: [
4161
+ selectedValues.length > 0 ? /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1", children: selectedValues.map((val) => {
4162
+ const option = lista.find(
4163
+ (item) => getValue(item).toString() === val
4164
+ );
4165
+ return /* @__PURE__ */ jsx(Badge, { variant: "secondary", children: option?.name ?? val }, val);
4166
+ }) }) : /* @__PURE__ */ jsx("span", { children: input.placeHolder ?? "Selecciona..." }),
4167
+ /* @__PURE__ */ jsx(ChevronsUpDown, { className: "ml-2 h-4 w-4 opacity-50" })
4168
+ ]
4169
+ }
4170
+ ) }),
4171
+ /* @__PURE__ */ jsx(PopoverContent, { className: "p-0 w-[var(--radix-popover-trigger-width)]", children: /* @__PURE__ */ jsxs(Command, { children: [
4172
+ /* @__PURE__ */ jsx(CommandInput, { placeholder: "Buscar..." }),
4173
+ /* @__PURE__ */ jsxs(CommandList, { children: [
4174
+ /* @__PURE__ */ jsx(CommandEmpty, { children: "No hay resultados." }),
4175
+ /* @__PURE__ */ jsx(CommandGroup, { children: lista.map((item) => {
4176
+ const value = getValue(item).toString();
4177
+ const selected = selectedValues.includes(value);
4178
+ return /* @__PURE__ */ jsxs(
4179
+ CommandItem,
4180
+ {
4181
+ onSelect: () => toggleOption(value),
4182
+ children: [
4183
+ /* @__PURE__ */ jsx(
4184
+ Check,
4185
+ {
4186
+ className: cn(
4187
+ "mr-2 h-4 w-4",
4188
+ selected ? "opacity-100" : "opacity-0"
4189
+ )
4190
+ }
4191
+ ),
4192
+ item.name
4193
+ ]
4194
+ },
4195
+ value
4196
+ );
4197
+ }) })
4198
+ ] })
4199
+ ] }) })
4200
+ ] }) }),
4201
+ /* @__PURE__ */ jsx(FormMessage, {})
4202
+ ] });
4203
+ }
4204
+ },
4205
+ input.name
4206
+ );
4207
+ };
4010
4208
  var TextInputGroup = class extends BaseInput {
4011
4209
  render() {
4012
4210
  const { input, form, isSubmitting } = this;
@@ -4804,6 +5002,7 @@ var inputMap = {
4804
5002
  ["currency" /* CURRENCY */]: CurrencyInput,
4805
5003
  ["key_value" /* KEY_VALUE */]: KeyValueListInput,
4806
5004
  ["repeater" /* REPEATER */]: RepeaterInput,
5005
+ ["multi_select" /* MULTI_SELECT */]: MultiSelectInput,
4807
5006
  //ToDos: ============================================================
4808
5007
  ["slider" /* SLIDER */]: SliderInput,
4809
5008
  //ToDo: // PENDIENTE ... VISUALMENTE NO SE VE BIEN.!!!
@@ -4829,6 +5028,7 @@ var InputFactory = class {
4829
5028
  };
4830
5029
  function getDefaultValues(entity) {
4831
5030
  const defaults = {};
5031
+ if (!entity) return defaults;
4832
5032
  for (const key in entity) {
4833
5033
  const value = entity[key];
4834
5034
  if (value === null || value === void 0) {
@@ -4859,26 +5059,31 @@ function getDefaultValues(entity) {
4859
5059
  return defaults;
4860
5060
  }
4861
5061
  var getDynamicSchema = (fields, extraValidations) => {
4862
- const flatFields = fields.flatMap((f) => Array.isArray(f) ? f : [f]);
4863
- const shape = {};
4864
- flatFields.forEach((f) => {
4865
- shape[f.name] = f.zodType ?? z2.any();
4866
- });
5062
+ const flatFields = fields.flatMap(
5063
+ (f) => Array.isArray(f) ? f : [f]
5064
+ );
5065
+ const shape = flatFields.reduce((acc, f) => {
5066
+ acc[f.name] = f.zodType ?? z2.any();
5067
+ return acc;
5068
+ }, {});
4867
5069
  let schema = z2.object(shape);
4868
- if (extraValidations && extraValidations.length > 0) {
4869
- extraValidations.forEach((fn) => {
5070
+ if (extraValidations?.length) {
5071
+ for (const fn of extraValidations) {
4870
5072
  schema = fn(schema);
4871
- });
5073
+ }
4872
5074
  }
4873
5075
  return schema;
4874
5076
  };
4875
- var FormErrorsAlert = ({ formState, fields }) => {
5077
+ var FormErrorsAlert = ({
5078
+ formState,
5079
+ fields
5080
+ }) => {
4876
5081
  const flatFields = fields.flatMap((f) => Array.isArray(f) ? f : [f]);
4877
5082
  return /* @__PURE__ */ jsx("div", { style: { marginTop: 4 }, children: Object.entries(formState.errors).length > 0 && /* @__PURE__ */ jsx(
4878
5083
  CustomAlert,
4879
5084
  {
4880
5085
  title: "Revisar los siguientes criterios",
4881
- description: /* @__PURE__ */ jsx("ul", { children: Object.entries(formState?.errors).map(([key, value]) => /* @__PURE__ */ jsxs("li", { children: [
5086
+ description: /* @__PURE__ */ jsx("ul", { children: Object.entries(formState.errors).map(([key, value]) => /* @__PURE__ */ jsxs("li", { children: [
4882
5087
  /* @__PURE__ */ jsxs("strong", { children: [
4883
5088
  getFieldLabel(key, flatFields),
4884
5089
  ":"
@@ -4892,15 +5097,36 @@ var FormErrorsAlert = ({ formState, fields }) => {
4892
5097
  ) });
4893
5098
  };
4894
5099
  var getFieldLabel = (fieldErrorKey, fields) => {
4895
- const findedField = fields.find((field) => field.name == fieldErrorKey);
4896
- return findedField?.label ?? fieldErrorKey;
5100
+ const foundField = fields.find((field) => field.name === fieldErrorKey);
5101
+ return foundField?.label ?? fieldErrorKey;
4897
5102
  };
4898
- var FormFieldsGrid = ({ fields, form, isPending, readOnly, className = "", gap = "gap-2" }) => {
4899
- return /* @__PURE__ */ jsx(Fragment, { children: fields.map(
4900
- (input, idx) => Array.isArray(input) ? /* @__PURE__ */ jsx("span", { className: "w-full flex flex-row justify-between py-3", children: input.map((field, subIdx) => {
4901
- if (readOnly) field.disabled = readOnly;
4902
- return /* @__PURE__ */ jsx("div", { className: "w-full px-2", children: InputFactory.create(field, form, isPending) }, subIdx);
4903
- }) }, `field-group-${idx}`) : /* @__PURE__ */ jsx("span", { className: "flex flex-col justify-between py-3 w-full px-2", children: InputFactory.create(input, form, isPending) }, `field-group-${idx}`)
5103
+ var FormFieldsGrid = ({
5104
+ fields,
5105
+ form,
5106
+ isPending,
5107
+ readOnly,
5108
+ className = "",
5109
+ gap = "gap-2"
5110
+ }) => {
5111
+ return /* @__PURE__ */ jsx("div", { className: `w-full grid grid-cols-1 ${gap} ${className}`, children: fields.map(
5112
+ (input, idx) => Array.isArray(input) ? /* @__PURE__ */ jsx(
5113
+ "span",
5114
+ {
5115
+ className: "w-full flex flex-row justify-between py-3",
5116
+ children: input.map((field, subIdx) => {
5117
+ if (readOnly) field.disabled = true;
5118
+ return /* @__PURE__ */ jsx("div", { className: "w-full px-2", children: InputFactory.create(field, form, isPending) }, subIdx);
5119
+ })
5120
+ },
5121
+ `field-group-${idx}`
5122
+ ) : /* @__PURE__ */ jsx(
5123
+ "span",
5124
+ {
5125
+ className: "flex flex-col justify-between py-3 w-full px-2",
5126
+ children: InputFactory.create(input, form, isPending)
5127
+ },
5128
+ `field-group-${idx}`
5129
+ )
4904
5130
  ) });
4905
5131
  };
4906
5132
  var DynamicForm = ({
@@ -4919,14 +5145,15 @@ var DynamicForm = ({
4919
5145
  }) => {
4920
5146
  const [isPending, startTransition] = useTransition();
4921
5147
  const schema = useMemo(() => getDynamicSchema(fields, extraValidations), [fields, extraValidations]);
4922
- const defaultValues = useMemo(() => getDefaultValues(record), [record]);
5148
+ const resolver = zodResolver(schema);
5149
+ const initialValues = useMemo(() => getDefaultValues(record), [record]);
4923
5150
  const form = useForm({
4924
- resolver: zodResolver(schema),
4925
- defaultValues
5151
+ resolver,
5152
+ defaultValues: initialValues
4926
5153
  });
4927
5154
  useEffect(() => {
4928
- form.reset(defaultValues);
4929
- }, [defaultValues, form]);
5155
+ form.reset(initialValues);
5156
+ }, [initialValues, form]);
4930
5157
  const handleSubmit = (data) => {
4931
5158
  if (readOnly) return;
4932
5159
  try {
@@ -4935,7 +5162,7 @@ var DynamicForm = ({
4935
5162
  onSubmit?.(resp);
4936
5163
  });
4937
5164
  } catch (error) {
4938
- console.error("Ocurri\xF3 un error al enviar el formulario.");
5165
+ console.error("Ocurri\xF3 un error al enviar el formulario.", error);
4939
5166
  }
4940
5167
  };
4941
5168
  const formContent = /* @__PURE__ */ jsxs("div", { children: [
@@ -4963,8 +5190,7 @@ var DynamicForm = ({
4963
5190
  ] }) }) })
4964
5191
  ]
4965
5192
  }
4966
- ) }),
4967
- withErrorsAlert && errorAlertPosition === "down" && /* @__PURE__ */ jsx(FormErrorsAlert, { formState: form.formState, fields })
5193
+ ) })
4968
5194
  ] });
4969
5195
  if (!withCard) return formContent;
4970
5196
  return /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(CardContent, { children: formContent }) });
@@ -5144,6 +5370,6 @@ var InputList = ({ handleAddInput, inputsTypes }) => {
5144
5370
  }) });
5145
5371
  };
5146
5372
 
5147
- 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, inputFieldComp, mockFields, useFormField, validationMessages };
5373
+ 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 };
5148
5374
  //# sourceMappingURL=index.mjs.map
5149
5375
  //# sourceMappingURL=index.mjs.map