shadcn-zod-formkit 1.0.5 → 1.1.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/README.md CHANGED
@@ -44,6 +44,8 @@ import {
44
44
  TextInputType
45
45
  } from "shadcn-zod-formkit";
46
46
 
47
+ import { Mail, User } from 'lucide-react';
48
+
47
49
  export default function Home() {
48
50
  // Record From DB example (User),
49
51
  // record is used for define default values
@@ -69,14 +71,26 @@ export default function Home() {
69
71
  const mockFields: Array<FieldProps |FieldProps[]> = [
70
72
  {
71
73
  name: "username",
72
- label: "Nombre de usuario",
73
- inputType: InputTypes.TEXT,
74
- ZodTypeAny: z .string().min(3).max(20),
74
+ label: "Username",
75
+ inputType: InputTypes.TEXT_GROUP,
76
+ inputGroupConfig:{
77
+ autoValidIcons: true,
78
+ iconsLeft: [User]
79
+ },
80
+ zodType: z.string().min(3).max(20),
75
81
  },
76
82
  {
77
83
  name: "email",
78
- label: "Correo electrónico",
79
- inputType: InputTypes.TEXT,
84
+ label: "Email",
85
+ inputType: InputTypes.TEXT_GROUP,
86
+ inputGroupConfig:{
87
+ autoValidIcons: true,
88
+ iconsLeft: [Mail],
89
+ },
90
+ zodType: z
91
+ .string()
92
+ .email("Invalid Email")
93
+ .optional(),
80
94
  },
81
95
  ]
82
96
  ```
@@ -117,8 +131,8 @@ const mockFields: Array<FieldProps |FieldProps[]> = [
117
131
  - Combine multiple FieldProps in arrays for grouped fields (like age + color).
118
132
 
119
133
  ## 🧠 Acknowledgements
120
- React - A JavaScript library for building user interfaces.
121
- Next.js - The React framework for production.
122
- Tailwind CSS - A utility-first CSS framework for creating custom designs.
123
- Zod - TypeScript-first schema declaration and validation.
134
+ - React - A JavaScript library for building user interfaces.
135
+ - Next.js - The React framework for production.
136
+ - Tailwind CSS - A utility-first CSS framework for creating custom designs.
137
+ - Zod - TypeScript-first schema declaration and validation.
124
138
 
package/dist/index.cjs CHANGED
@@ -5,7 +5,7 @@ var reactIcons = require('@radix-ui/react-icons');
5
5
  var classVarianceAuthority = require('class-variance-authority');
6
6
  var tailwindMerge = require('tailwind-merge');
7
7
  var jsxRuntime = require('react/jsx-runtime');
8
- var React8 = require('react');
8
+ var React3 = require('react');
9
9
  var reactHookForm = require('react-hook-form');
10
10
  var AccordionPrimitive = require('@radix-ui/react-accordion');
11
11
  var reactSlot = require('@radix-ui/react-slot');
@@ -50,7 +50,7 @@ function _interopNamespace(e) {
50
50
  return Object.freeze(n);
51
51
  }
52
52
 
53
- var React8__namespace = /*#__PURE__*/_interopNamespace(React8);
53
+ var React3__namespace = /*#__PURE__*/_interopNamespace(React3);
54
54
  var AccordionPrimitive__namespace = /*#__PURE__*/_interopNamespace(AccordionPrimitive);
55
55
  var CheckboxPrimitive__namespace = /*#__PURE__*/_interopNamespace(CheckboxPrimitive);
56
56
  var PopoverPrimitive__namespace = /*#__PURE__*/_interopNamespace(PopoverPrimitive);
@@ -573,8 +573,8 @@ function CalendarDayButton({
573
573
  ...props
574
574
  }) {
575
575
  const defaultClassNames = reactDayPicker.getDefaultClassNames();
576
- const ref = React8__namespace.useRef(null);
577
- React8__namespace.useEffect(() => {
576
+ const ref = React3__namespace.useRef(null);
577
+ React3__namespace.useEffect(() => {
578
578
  if (modifiers.focused) ref.current?.focus();
579
579
  }, [modifiers.focused]);
580
580
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -735,11 +735,11 @@ function PopoverAnchor({
735
735
  }) {
736
736
  return /* @__PURE__ */ jsxRuntime.jsx(PopoverPrimitive__namespace.Anchor, { "data-slot": "popover-anchor", ...props });
737
737
  }
738
- var ColorCnInput = React8__namespace.forwardRef(
738
+ var ColorCnInput = React3__namespace.forwardRef(
739
739
  ({ value = "#000000", onChange, onBlur, disabled, className }, ref) => {
740
740
  const [color, setColor] = reactColorPalette.useColor(value);
741
- const [open, setOpen] = React8__namespace.useState(false);
742
- React8__namespace.useEffect(() => {
741
+ const [open, setOpen] = React3__namespace.useState(false);
742
+ React3__namespace.useEffect(() => {
743
743
  if (value !== color.hex) {
744
744
  setColor({ ...color, hex: value });
745
745
  }
@@ -953,7 +953,7 @@ classVarianceAuthority.cva(
953
953
  }
954
954
  );
955
955
  var Form = reactHookForm.FormProvider;
956
- var FormFieldContext = React8__namespace.createContext(
956
+ var FormFieldContext = React3__namespace.createContext(
957
957
  {}
958
958
  );
959
959
  var FormField = ({
@@ -962,8 +962,8 @@ var FormField = ({
962
962
  return /* @__PURE__ */ jsxRuntime.jsx(FormFieldContext.Provider, { value: { name: props.name }, children: /* @__PURE__ */ jsxRuntime.jsx(reactHookForm.Controller, { ...props }) });
963
963
  };
964
964
  var useFormField = () => {
965
- const fieldContext = React8__namespace.useContext(FormFieldContext);
966
- const itemContext = React8__namespace.useContext(FormItemContext);
965
+ const fieldContext = React3__namespace.useContext(FormFieldContext);
966
+ const itemContext = React3__namespace.useContext(FormItemContext);
967
967
  const { getFieldState } = reactHookForm.useFormContext();
968
968
  const formState = reactHookForm.useFormState({ name: fieldContext.name });
969
969
  const fieldState = getFieldState(fieldContext.name, formState);
@@ -980,11 +980,11 @@ var useFormField = () => {
980
980
  ...fieldState
981
981
  };
982
982
  };
983
- var FormItemContext = React8__namespace.createContext(
983
+ var FormItemContext = React3__namespace.createContext(
984
984
  {}
985
985
  );
986
986
  function FormItem({ className, ...props }) {
987
- const id = React8__namespace.useId();
987
+ const id = React3__namespace.useId();
988
988
  return /* @__PURE__ */ jsxRuntime.jsx(FormItemContext.Provider, { value: { id }, children: /* @__PURE__ */ jsxRuntime.jsx(
989
989
  "div",
990
990
  {
@@ -1220,7 +1220,7 @@ function InputOTPSlot({
1220
1220
  className,
1221
1221
  ...props
1222
1222
  }) {
1223
- const inputOTPContext = React8__namespace.useContext(inputOtp.OTPInputContext);
1223
+ const inputOTPContext = React3__namespace.useContext(inputOtp.OTPInputContext);
1224
1224
  const { char, hasFakeCaret, isActive } = inputOTPContext?.slots[index] ?? {};
1225
1225
  return /* @__PURE__ */ jsxRuntime.jsxs(
1226
1226
  "div",
@@ -1625,9 +1625,9 @@ var GroupedSwitches = ({ options, onChange, input, isSubmitting }) => {
1625
1625
  { id: 4, name: "MOCK OPTION - DELETE ", checked: false }
1626
1626
  ];
1627
1627
  const initialSwitches = options ? options.length > 0 ? options : input.listConfig?.list ?? [] : mockInputOptions;
1628
- const [switches, setSwitches] = React8.useState(initialSwitches);
1629
- const [allChecked, setAllChecked] = React8.useState(initialSwitches.every((opt) => opt.checked));
1630
- const [bgColor, setBgColor] = React8.useState("bg-green-500/5 border-green-400/10");
1628
+ const [switches, setSwitches] = React3.useState(initialSwitches);
1629
+ const [allChecked, setAllChecked] = React3.useState(initialSwitches.every((opt) => opt.checked));
1630
+ const [bgColor, setBgColor] = React3.useState("bg-green-500/5 border-green-400/10");
1631
1631
  const handleMainToggle = (checked) => {
1632
1632
  const updated = switches.map((opt) => ({ ...opt, checked }));
1633
1633
  setSwitches(updated);
@@ -1681,9 +1681,9 @@ var AccordionGroupedSwitchInput = class extends BaseInput {
1681
1681
  }
1682
1682
  };
1683
1683
  var AccordionGroupedSwitches = ({ form, input, groups = [], onChange, isSubmitting }) => {
1684
- const [groupsState, setGroupsState] = React8.useState([]);
1685
- const [selectedOptions, setSelectedOptions] = React8.useState([]);
1686
- React8.useEffect(() => {
1684
+ const [groupsState, setGroupsState] = React3.useState([]);
1685
+ const [selectedOptions, setSelectedOptions] = React3.useState([]);
1686
+ React3.useEffect(() => {
1687
1687
  const selected = input.listConfig?.selectedList ?? [];
1688
1688
  const updatedGroups = groups.map((group) => ({
1689
1689
  ...group,
@@ -1905,7 +1905,7 @@ var ColorInput = class extends BaseInput {
1905
1905
  }
1906
1906
  };
1907
1907
  var FieldColor = ({ form, input, isSubmitting }) => {
1908
- const [ColorCmp, _setColorCmp] = React8.useState(ColorComp);
1908
+ const [ColorCmp, _setColorCmp] = React3.useState(ColorComp);
1909
1909
  return /* @__PURE__ */ jsxRuntime.jsx(
1910
1910
  FormField,
1911
1911
  {
@@ -1940,11 +1940,11 @@ var FieldColor = ({ form, input, isSubmitting }) => {
1940
1940
  }
1941
1941
  );
1942
1942
  };
1943
- var ColorComp = React8__namespace.default.forwardRef(
1943
+ var ColorComp = React3__namespace.default.forwardRef(
1944
1944
  ({ value = "#000000", onChange, onBlur, disabled, className, hideInput = ["hsv"] }, ref) => {
1945
1945
  const [color, setColor] = reactColorPalette.useColor(value);
1946
- const [open, setOpen] = React8__namespace.default.useState(false);
1947
- React8__namespace.default.useEffect(() => {
1946
+ const [open, setOpen] = React3__namespace.default.useState(false);
1947
+ React3__namespace.default.useEffect(() => {
1948
1948
  if (value !== color.hex) {
1949
1949
  setColor({ ...color, hex: value });
1950
1950
  }
@@ -3542,10 +3542,10 @@ var DateInput = class extends BaseInput {
3542
3542
  control: form.control,
3543
3543
  name: input.name,
3544
3544
  render: ({ field }) => {
3545
- const [date, setDate] = React8__namespace.useState(
3545
+ const [date, setDate] = React3__namespace.useState(
3546
3546
  field.value ? new Date(field.value) : void 0
3547
3547
  );
3548
- React8__namespace.useEffect(() => {
3548
+ React3__namespace.useEffect(() => {
3549
3549
  if (field.value && !date) {
3550
3550
  setDate(new Date(field.value));
3551
3551
  }
@@ -3607,13 +3607,13 @@ var FieldDateTimeInput = ({ form, input, isSubmitting }) => {
3607
3607
  const iconsLeft = groupConfig?.iconsLeft ?? [];
3608
3608
  const textLeft = groupConfig?.textLeft;
3609
3609
  const textRight = groupConfig?.textRight;
3610
- const [isValid2, setIsValid] = React8.useState(() => {
3610
+ const [isValid2, setIsValid] = React3.useState(() => {
3611
3611
  const value = form.getValues(input.name);
3612
3612
  const fieldState = form.getFieldState(input.name);
3613
3613
  return !fieldState.error && value !== void 0 && value !== "";
3614
3614
  });
3615
- const [dateTime, setDateTime] = React8.useState(() => form.getValues(input.name) ?? "");
3616
- React8.useEffect(() => {
3615
+ const [dateTime, setDateTime] = React3.useState(() => form.getValues(input.name) ?? "");
3616
+ React3.useEffect(() => {
3617
3617
  const fieldValue = form.getValues(input.name) ?? "";
3618
3618
  if (fieldValue !== dateTime) setDateTime(fieldValue);
3619
3619
  }, [form.getValues(input.name)]);
@@ -3666,11 +3666,11 @@ var FileInput = class extends BaseInput {
3666
3666
  }
3667
3667
  };
3668
3668
  var FieldFile = ({ form, input, isSubmitting }) => {
3669
- const [preview, setPreview] = React8.useState(form.getValues(input.name) ?? null);
3670
- const [showPreview, setShowPreview] = React8.useState(input.fileConfig?.showPreview ?? false);
3669
+ const [preview, setPreview] = React3.useState(form.getValues(input.name) ?? null);
3670
+ const [showPreview, setShowPreview] = React3.useState(input.fileConfig?.showPreview ?? false);
3671
3671
  const accept = input.fileConfig?.accept || "*/*";
3672
3672
  const multiple = input.fileConfig?.multiple || false;
3673
- React8.useEffect(() => {
3673
+ React3.useEffect(() => {
3674
3674
  setPreview(form.getValues(input.name) || null);
3675
3675
  }, [input]);
3676
3676
  const handleFileChange = (e) => {
@@ -3725,9 +3725,9 @@ var FileMultiUploadInput = class extends BaseInput {
3725
3725
  }
3726
3726
  };
3727
3727
  var FieldFileMultiUpload = ({ input, form, isSubmitting }) => {
3728
- const inputRef = React8.useRef(null);
3729
- const [files, setFiles] = React8.useState(form.getValues(input.name) || []);
3730
- const [dragOver, setDragOver] = React8.useState(false);
3728
+ const inputRef = React3.useRef(null);
3729
+ const [files, setFiles] = React3.useState(form.getValues(input.name) || []);
3730
+ const [dragOver, setDragOver] = React3.useState(false);
3731
3731
  const autoValidate = input.inputGroupConfig?.autoValidIcons;
3732
3732
  const iconValidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleCheck, { style: { color: "#00bf3e" } });
3733
3733
  const iconInvalidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleX, { style: { color: "#ff8080" } });
@@ -3821,6 +3821,7 @@ var TextInputGroup = class extends BaseInput {
3821
3821
  };
3822
3822
  var FieldTextGroup = ({ form, input, isSubmitting }) => {
3823
3823
  const groupConfig = input.inputGroupConfig;
3824
+ const infoTooltip = input?.infoTooltip;
3824
3825
  const autoValidate = groupConfig?.autoValidIcons;
3825
3826
  const iconValidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleCheck, { style: { color: "#00bf3e" } });
3826
3827
  const iconInvalidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleX, { style: { color: "#ff8080" } });
@@ -3829,7 +3830,7 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
3829
3830
  const iconsLeft = groupConfig?.iconsLeft ?? [];
3830
3831
  const textLeft = groupConfig?.textLeft;
3831
3832
  const textRight = groupConfig?.textRight;
3832
- const [isValid2, setIsValid] = React8.useState(() => {
3833
+ const [isValid2, setIsValid] = React3.useState(() => {
3833
3834
  const value = form.getValues(input.name);
3834
3835
  const fieldState = form.getFieldState(input.name);
3835
3836
  return !fieldState.error && value !== void 0 && value !== "";
@@ -3858,7 +3859,11 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
3858
3859
  type: input.keyboardType
3859
3860
  }
3860
3861
  ),
3861
- (iconsRight.length > 0 || textRight || autoValidate) && /* @__PURE__ */ jsxRuntime.jsxs(InputGroupAddon, { align: "inline-end", children: [
3862
+ (iconsRight.length > 0 || textRight || autoValidate || infoTooltip) && /* @__PURE__ */ jsxRuntime.jsxs(InputGroupAddon, { align: "inline-end", children: [
3863
+ infoTooltip && /* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { children: [
3864
+ /* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Info, { size: 20 }) }),
3865
+ /* @__PURE__ */ jsxRuntime.jsx(TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: infoTooltip }) })
3866
+ ] }),
3862
3867
  textRight && /* @__PURE__ */ jsxRuntime.jsx(InputGroupText, { children: textRight }),
3863
3868
  iconsRight.map((IconComponent, index) => /* @__PURE__ */ jsxRuntime.jsx(IconComponent, { size: 20 }, index)),
3864
3869
  autoValidate && /* @__PURE__ */ jsxRuntime.jsx("div", { children: isSubmitting ? iconLoadingState : isValid2 ? iconValidState : iconInvalidState })
@@ -4050,7 +4055,7 @@ var FieldSimpleCheckList = ({ input, value, onChange, isSubmitting }) => {
4050
4055
  { id: 4, name: "MOCK OPTION - DELETE", checked: false }
4051
4056
  ];
4052
4057
  const initialOptions = input.listConfig?.list ?? mockInputOptions;
4053
- const [options, setOptions] = React8.useState(
4058
+ const [options, setOptions] = React3.useState(
4054
4059
  value.length > 0 ? value : initialOptions
4055
4060
  );
4056
4061
  const allChecked = options.every((opt) => opt.checked);
@@ -4115,7 +4120,7 @@ function Slider({
4115
4120
  max = 100,
4116
4121
  ...props
4117
4122
  }) {
4118
- const _values = React8__namespace.useMemo(
4123
+ const _values = React3__namespace.useMemo(
4119
4124
  () => Array.isArray(value) ? value : Array.isArray(defaultValue) ? defaultValue : [min, max],
4120
4125
  [value, defaultValue, min, max]
4121
4126
  );
@@ -4171,7 +4176,7 @@ var SliderInput = class extends BaseInput {
4171
4176
  };
4172
4177
  var FieldSlider = ({ input, form, isSubmitting }) => {
4173
4178
  const initialValue = form.getValues(input.name) ?? input.value ?? 0;
4174
- const [value, setValue] = React8.useState(initialValue);
4179
+ const [value, setValue] = React3.useState(initialValue);
4175
4180
  const handleChange = (val) => {
4176
4181
  setValue(val);
4177
4182
  form.setValue(input.name, val);
@@ -4271,252 +4276,80 @@ var FieldTags = ({ input, form, isSubmitting }) => {
4271
4276
  };
4272
4277
  var SPLITTER_REGEX = /[\n#?=&\t,./-]+/;
4273
4278
  var FORMATTING_REGEX = /^[^a-zA-Z0-9]*|[^a-zA-Z0-9]*$/g;
4274
- var TagInputContext = React8__namespace.default.createContext(null);
4275
- var TagsInput = React8__namespace.default.forwardRef(
4279
+ var TagsInput = React3__namespace.default.forwardRef(
4276
4280
  ({
4277
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
4278
- children,
4279
4281
  value,
4280
4282
  onValueChange,
4281
4283
  placeholder,
4282
4284
  maxItems,
4283
4285
  minItems,
4286
+ tagsPosition = "bottom",
4284
4287
  className,
4285
4288
  dir,
4286
4289
  ...props
4287
4290
  }, ref) => {
4288
- const [activeIndex, setActiveIndex] = React8__namespace.default.useState(-1);
4289
- const [inputValue, setInputValue] = React8__namespace.default.useState("");
4290
- const [disableInput, setDisableInput] = React8__namespace.default.useState(false);
4291
- const [disableButton, setDisableButton] = React8__namespace.default.useState(false);
4292
- const [isValueSelected, setIsValueSelected] = React8__namespace.default.useState(false);
4293
- const [selectedValue, setSelectedValue] = React8__namespace.default.useState("");
4291
+ const [inputValue, setInputValue] = React3__namespace.default.useState("");
4294
4292
  const parseMinItems = minItems ?? 0;
4295
4293
  const parseMaxItems = maxItems ?? Infinity;
4296
- const onValueChangeHandler = React8__namespace.default.useCallback(
4297
- (val) => {
4298
- if (!value.includes(val) && value.length < parseMaxItems) {
4299
- onValueChange([...value, val]);
4300
- }
4301
- },
4302
- [value]
4303
- );
4304
- const RemoveValue = React8__namespace.default.useCallback(
4305
- (val) => {
4306
- if (value.includes(val) && value.length > parseMinItems) {
4307
- onValueChange(value.filter((item) => item !== val));
4308
- }
4309
- },
4310
- [value]
4311
- );
4312
- const handlePaste = React8__namespace.default.useCallback(
4313
- (e) => {
4294
+ const addTag = (val) => {
4295
+ if (!value.includes(val) && value.length < parseMaxItems) {
4296
+ onValueChange([...value, val]);
4297
+ }
4298
+ };
4299
+ const removeTag = (val) => {
4300
+ if (value.includes(val) && value.length > parseMinItems) {
4301
+ onValueChange(value.filter((v) => v !== val));
4302
+ }
4303
+ };
4304
+ const handleKeyDown = (e) => {
4305
+ if (e.key === "Enter" && inputValue.trim() !== "") {
4314
4306
  e.preventDefault();
4315
- const tags = e.clipboardData.getData("text").split(SPLITTER_REGEX);
4316
- const newValue = [...value];
4317
- tags.forEach((item) => {
4318
- const parsedItem = item.replaceAll(FORMATTING_REGEX, "").trim();
4319
- if (parsedItem.length > 0 && !newValue.includes(parsedItem) && newValue.length < parseMaxItems) {
4320
- newValue.push(parsedItem);
4321
- }
4322
- });
4323
- onValueChange(newValue);
4307
+ addTag(inputValue.trim());
4324
4308
  setInputValue("");
4325
- },
4326
- [value]
4327
- );
4328
- const handleSelect = React8__namespace.default.useCallback(
4329
- (e) => {
4330
- e.preventDefault();
4331
- const target = e.currentTarget;
4332
- const selection = target.value.substring(
4333
- target.selectionStart ?? 0,
4334
- target.selectionEnd ?? 0
4335
- );
4336
- setSelectedValue(selection);
4337
- setIsValueSelected(selection === inputValue);
4338
- },
4339
- [inputValue]
4340
- );
4341
- React8__namespace.default.useEffect(() => {
4342
- const VerifyDisable = () => {
4343
- if (value.length - 1 >= parseMinItems) {
4344
- setDisableButton(false);
4345
- } else {
4346
- setDisableButton(true);
4347
- }
4348
- if (value.length + 1 <= parseMaxItems) {
4349
- setDisableInput(false);
4350
- } else {
4351
- setDisableInput(true);
4352
- }
4353
- };
4354
- VerifyDisable();
4355
- }, [value]);
4356
- const handleKeyDown = React8__namespace.default.useCallback(
4357
- async (e) => {
4358
- e.stopPropagation();
4359
- const moveNext = () => {
4360
- const nextIndex = activeIndex + 1 > value.length - 1 ? -1 : activeIndex + 1;
4361
- setActiveIndex(nextIndex);
4362
- };
4363
- const movePrev = () => {
4364
- const prevIndex = activeIndex - 1 < 0 ? value.length - 1 : activeIndex - 1;
4365
- setActiveIndex(prevIndex);
4366
- };
4367
- const moveCurrent = () => {
4368
- const newIndex = activeIndex - 1 <= 0 ? value.length - 1 === 0 ? -1 : 0 : activeIndex - 1;
4369
- setActiveIndex(newIndex);
4370
- };
4371
- const target = e.currentTarget;
4372
- switch (e.key) {
4373
- case "ArrowLeft":
4374
- if (dir === "rtl") {
4375
- if (value.length > 0 && activeIndex !== -1) {
4376
- moveNext();
4377
- }
4378
- } else {
4379
- if (value.length > 0 && target.selectionStart === 0) {
4380
- movePrev();
4381
- }
4382
- }
4383
- break;
4384
- case "ArrowRight":
4385
- if (dir === "rtl") {
4386
- if (value.length > 0 && target.selectionStart === 0) {
4387
- movePrev();
4388
- }
4389
- } else {
4390
- if (value.length > 0 && activeIndex !== -1) {
4391
- moveNext();
4392
- }
4393
- }
4394
- break;
4395
- case "Backspace":
4396
- case "Delete":
4397
- if (value.length > 0) {
4398
- if (activeIndex !== -1 && activeIndex < value.length) {
4399
- RemoveValue(value[activeIndex]);
4400
- moveCurrent();
4401
- } else {
4402
- if (target.selectionStart === 0) {
4403
- if (selectedValue === inputValue || isValueSelected) {
4404
- RemoveValue(value[value.length - 1]);
4405
- }
4406
- }
4407
- }
4408
- }
4409
- break;
4410
- case "Escape":
4411
- const newIndex = activeIndex === -1 ? value.length - 1 : -1;
4412
- setActiveIndex(newIndex);
4413
- break;
4414
- case "Enter":
4415
- if (inputValue.trim() !== "") {
4416
- e.preventDefault();
4417
- onValueChangeHandler(inputValue);
4418
- setInputValue("");
4419
- }
4420
- break;
4421
- }
4422
- },
4423
- [activeIndex, value, inputValue, RemoveValue]
4424
- );
4425
- const mousePreventDefault = React8__namespace.default.useCallback((e) => {
4309
+ }
4310
+ if (e.key === "Backspace" && inputValue === "" && value.length > 0) {
4311
+ removeTag(value[value.length - 1]);
4312
+ }
4313
+ };
4314
+ const handlePaste = (e) => {
4426
4315
  e.preventDefault();
4427
- e.stopPropagation();
4428
- }, []);
4429
- const handleChange = React8__namespace.default.useCallback(
4430
- (e) => {
4431
- setInputValue(e.currentTarget.value);
4432
- },
4433
- []
4434
- );
4435
- return /* @__PURE__ */ jsxRuntime.jsx(
4436
- TagInputContext.Provider,
4316
+ const tags = e.clipboardData.getData("text").split(SPLITTER_REGEX).map((t) => t.replace(FORMATTING_REGEX, "").trim()).filter((t) => t && !value.includes(t)).slice(0, parseMaxItems - value.length);
4317
+ if (tags.length) onValueChange([...value, ...tags]);
4318
+ };
4319
+ const renderTags = () => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-1 mb-1 mt-1", children: value.map((tag) => /* @__PURE__ */ jsxRuntime.jsxs(
4320
+ Badge,
4437
4321
  {
4438
- value: {
4439
- value,
4440
- onValueChange,
4441
- inputValue,
4442
- setInputValue,
4443
- activeIndex,
4444
- setActiveIndex
4445
- },
4446
- children: /* @__PURE__ */ jsxRuntime.jsxs(
4447
- "div",
4448
- {
4449
- ...props,
4450
- ref,
4451
- dir,
4452
- className: cn(
4453
- "flex items-center flex-wrap gap-1 p-1 rounded-lg bg-background overflow-hidden ring-1 ring-muted ",
4454
- {
4455
- "focus-within:ring-ring": activeIndex === -1
4456
- },
4457
- className
4458
- ),
4459
- children: [
4460
- value.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs(
4461
- Badge,
4462
- {
4463
- tabIndex: activeIndex !== -1 ? 0 : activeIndex,
4464
- "aria-disabled": disableButton,
4465
- "data-active": activeIndex === index,
4466
- className: cn(
4467
- "relative px-1 rounded flex items-center gap-1 data-[active='true']:ring-2 data-[active='true']:ring-muted-foreground truncate aria-disabled:opacity-50 aria-disabled:cursor-not-allowed"
4468
- ),
4469
- variant: "secondary",
4470
- children: [
4471
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs", children: item }),
4472
- /* @__PURE__ */ jsxRuntime.jsxs(
4473
- "button",
4474
- {
4475
- type: "button",
4476
- "aria-label": `Remove ${item} option`,
4477
- "aria-roledescription": "button to remove option",
4478
- disabled: disableButton,
4479
- onMouseDown: mousePreventDefault,
4480
- onClick: () => RemoveValue(item),
4481
- className: "disabled:cursor-not-allowed",
4482
- children: [
4483
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sr-only", children: [
4484
- "Remove ",
4485
- item,
4486
- " option"
4487
- ] }),
4488
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "h-4 w-4 hover:stroke-destructive" })
4489
- ]
4490
- }
4491
- )
4492
- ]
4493
- },
4494
- item
4495
- )),
4496
- /* @__PURE__ */ jsxRuntime.jsx(
4497
- Input,
4498
- {
4499
- tabIndex: 0,
4500
- "aria-label": "input tag",
4501
- disabled: disableInput,
4502
- onKeyDown: handleKeyDown,
4503
- onPaste: handlePaste,
4504
- value: inputValue,
4505
- onSelect: handleSelect,
4506
- onChange: activeIndex === -1 ? handleChange : void 0,
4507
- placeholder,
4508
- onClick: () => setActiveIndex(-1),
4509
- className: cn(
4510
- "outline-0 border-none h-7 min-w-fit flex-1 focus-visible:outline-0 focus-visible:ring-0 focus-visible:ring-offset-0 focus-visible:border-0 placeholder:text-muted-foreground px-1",
4511
- activeIndex !== -1 && "caret-transparent"
4512
- )
4513
- }
4514
- )
4515
- ]
4516
- }
4517
- )
4518
- }
4519
- );
4322
+ className: "flex items-center gap-1 px-2 py-0.5 rounded bg-muted text-muted-foreground text-xs",
4323
+ children: [
4324
+ tag,
4325
+ /* @__PURE__ */ jsxRuntime.jsx(
4326
+ "button",
4327
+ {
4328
+ type: "button",
4329
+ onClick: () => removeTag(tag),
4330
+ className: "ml-1 text-xs hover:text-destructive",
4331
+ children: "\xD7"
4332
+ }
4333
+ )
4334
+ ]
4335
+ },
4336
+ tag
4337
+ )) });
4338
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { ...props, ref, className: cn("w-full", className), children: [
4339
+ tagsPosition === "top" && renderTags(),
4340
+ /* @__PURE__ */ jsxRuntime.jsx(
4341
+ "input",
4342
+ {
4343
+ value: inputValue,
4344
+ onChange: (e) => setInputValue(e.target.value),
4345
+ onKeyDown: handleKeyDown,
4346
+ onPaste: handlePaste,
4347
+ placeholder,
4348
+ className: "w-full px-2 py-1 border rounded focus:outline-none focus:ring focus:ring-primary"
4349
+ }
4350
+ ),
4351
+ tagsPosition === "bottom" && renderTags()
4352
+ ] });
4520
4353
  }
4521
4354
  );
4522
4355
  TagsInput.displayName = "TagsInput";
@@ -4593,13 +4426,13 @@ var FieldTimeInput = ({ form, input, isSubmitting }) => {
4593
4426
  const iconsLeft = groupConfig?.iconsLeft ?? [];
4594
4427
  const textLeft = groupConfig?.textLeft;
4595
4428
  const textRight = groupConfig?.textRight;
4596
- const [isValid2, setIsValid] = React8.useState(() => {
4429
+ const [isValid2, setIsValid] = React3.useState(() => {
4597
4430
  const value = form.getValues(input.name);
4598
4431
  const fieldState = form.getFieldState(input.name);
4599
4432
  return !fieldState.error && value !== void 0 && value !== "";
4600
4433
  });
4601
- const [time, setTime] = React8.useState(() => form.getValues(input.name) ?? "");
4602
- React8.useEffect(() => {
4434
+ const [time, setTime] = React3.useState(() => form.getValues(input.name) ?? "");
4435
+ React3.useEffect(() => {
4603
4436
  const fieldValue = form.getValues(input.name) ?? "";
4604
4437
  if (fieldValue !== time) setTime(fieldValue);
4605
4438
  }, [form.getValues(input.name)]);
@@ -4771,14 +4604,14 @@ var DynamicForm = ({
4771
4604
  submitBtnClass = "",
4772
4605
  submitBtnLabel = "Submit"
4773
4606
  }) => {
4774
- const [isPending, startTransition] = React8.useTransition();
4775
- const schema = React8.useMemo(() => getDynamicSchema(fields, extraValidations), [fields, extraValidations]);
4776
- const defaultValues = React8.useMemo(() => getDefaultValues(record), [record]);
4607
+ const [isPending, startTransition] = React3.useTransition();
4608
+ const schema = React3.useMemo(() => getDynamicSchema(fields, extraValidations), [fields, extraValidations]);
4609
+ const defaultValues = React3.useMemo(() => getDefaultValues(record), [record]);
4777
4610
  const form = reactHookForm.useForm({
4778
4611
  resolver: zod.zodResolver(schema),
4779
4612
  defaultValues
4780
4613
  });
4781
- React8.useEffect(() => {
4614
+ React3.useEffect(() => {
4782
4615
  console.log("\u{1F501} Redibuja cuando cambian los fields o los valores por defecto");
4783
4616
  form.reset(defaultValues);
4784
4617
  }, []);
@@ -4940,7 +4773,7 @@ var mockFields = [
4940
4773
  }
4941
4774
  ];
4942
4775
  var InputList = ({ handleAddInput, inputsTypes }) => {
4943
- const [inputSetups, setInputSetups] = React8.useState(
4776
+ const [inputSetups, setInputSetups] = React3.useState(
4944
4777
  () => Object.fromEntries(
4945
4778
  inputsTypes.map((type) => [type, { required: false, disabled: false }])
4946
4779
  )