shadcn-zod-formkit 1.11.0 → 1.13.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
@@ -72,7 +72,8 @@ declare enum InputTypes {
72
72
  KEY_VALUE = "key_value",
73
73
  REPEATER = "repeater",
74
74
  MULTI_SELECT = "multi_select",
75
- COMBOBOX = "COMBO_BOX"
75
+ COMBOBOX = "COMBO_BOX",
76
+ SORTABLE_LIST = "sortable_list"
76
77
  }
77
78
  declare const inputFieldComp: InputTypes[];
78
79
 
@@ -123,12 +124,14 @@ interface inputGroudConfig {
123
124
  textRight?: string;
124
125
  }
125
126
  interface ListConfig {
127
+ children?: ReactNode | ((item: any, index: number) => ReactNode);
126
128
  list: InputOption[] | GroupedOption[];
127
129
  optionLabel?: string;
128
130
  optionValue?: InputOption | string | number | object;
129
131
  onOptionChange: (item?: InputOption | InputOption[] | GroupedOption) => void;
130
132
  optionDescription?: string;
131
133
  selectedList?: InputOption[];
134
+ sortable?: boolean;
132
135
  }
133
136
  interface InputOption {
134
137
  id: number | string;
@@ -170,11 +173,12 @@ declare enum TextInputType {
170
173
  PASSWORD = "password"
171
174
  }
172
175
 
173
- declare abstract class BaseInput {
176
+ declare abstract class BaseInput<T = unknown> {
174
177
  protected readonly input: FieldProps;
175
178
  protected readonly form: UseFormReturn;
176
179
  protected readonly isSubmitting?: boolean | undefined;
177
- constructor(input: FieldProps, form: UseFormReturn, isSubmitting?: boolean | undefined);
180
+ protected readonly children?: ReactNode | ((item: T, index: number) => ReactNode);
181
+ constructor(input: FieldProps, form: UseFormReturn, isSubmitting?: boolean | undefined, children?: ReactNode | ((item: T, index: number) => ReactNode));
178
182
  abstract render(): JSX.Element;
179
183
  }
180
184
  declare const entityToInputOption: (entitiy: any, name?: string, description?: string, groupedLabel?: string) => InputOption;
package/dist/index.d.ts CHANGED
@@ -72,7 +72,8 @@ declare enum InputTypes {
72
72
  KEY_VALUE = "key_value",
73
73
  REPEATER = "repeater",
74
74
  MULTI_SELECT = "multi_select",
75
- COMBOBOX = "COMBO_BOX"
75
+ COMBOBOX = "COMBO_BOX",
76
+ SORTABLE_LIST = "sortable_list"
76
77
  }
77
78
  declare const inputFieldComp: InputTypes[];
78
79
 
@@ -123,12 +124,14 @@ interface inputGroudConfig {
123
124
  textRight?: string;
124
125
  }
125
126
  interface ListConfig {
127
+ children?: ReactNode | ((item: any, index: number) => ReactNode);
126
128
  list: InputOption[] | GroupedOption[];
127
129
  optionLabel?: string;
128
130
  optionValue?: InputOption | string | number | object;
129
131
  onOptionChange: (item?: InputOption | InputOption[] | GroupedOption) => void;
130
132
  optionDescription?: string;
131
133
  selectedList?: InputOption[];
134
+ sortable?: boolean;
132
135
  }
133
136
  interface InputOption {
134
137
  id: number | string;
@@ -170,11 +173,12 @@ declare enum TextInputType {
170
173
  PASSWORD = "password"
171
174
  }
172
175
 
173
- declare abstract class BaseInput {
176
+ declare abstract class BaseInput<T = unknown> {
174
177
  protected readonly input: FieldProps;
175
178
  protected readonly form: UseFormReturn;
176
179
  protected readonly isSubmitting?: boolean | undefined;
177
- constructor(input: FieldProps, form: UseFormReturn, isSubmitting?: boolean | undefined);
180
+ protected readonly children?: ReactNode | ((item: T, index: number) => ReactNode);
181
+ constructor(input: FieldProps, form: UseFormReturn, isSubmitting?: boolean | undefined, children?: ReactNode | ((item: T, index: number) => ReactNode));
178
182
  abstract render(): JSX.Element;
179
183
  }
180
184
  declare const entityToInputOption: (entitiy: any, name?: string, description?: string, groupedLabel?: string) => InputOption;
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, ChevronsUpDown, Check, Trash2, Upload, SearchIcon, 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, GripVertical, 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';
@@ -27,6 +27,9 @@ import * as SwitchPrimitive from '@radix-ui/react-switch';
27
27
  import * as TooltipPrimitive from '@radix-ui/react-tooltip';
28
28
  import { Command as Command$1 } from 'cmdk';
29
29
  import * as SliderPrimitive from '@radix-ui/react-slider';
30
+ import { useSensors, useSensor, PointerSensor, KeyboardSensor, DndContext, closestCenter } from '@dnd-kit/core';
31
+ import { sortableKeyboardCoordinates, SortableContext, verticalListSortingStrategy, arrayMove, useSortable } from '@dnd-kit/sortable';
32
+ import { CSS } from '@dnd-kit/utilities';
30
33
  import z2 from 'zod';
31
34
  import { zodResolver } from '@hookform/resolvers/zod';
32
35
 
@@ -156,10 +159,11 @@ var validationMessages = {
156
159
 
157
160
  // src/components/custom/form/inputs/base/base-input.ts
158
161
  var BaseInput = class {
159
- constructor(input, form, isSubmitting) {
162
+ constructor(input, form, isSubmitting, children) {
160
163
  this.input = input;
161
164
  this.form = form;
162
165
  this.isSubmitting = isSubmitting;
166
+ this.children = children;
163
167
  }
164
168
  };
165
169
  var entityToInputOption = (entitiy, name = "name", description = "description", groupedLabel) => ({
@@ -232,9 +236,11 @@ var InputTypes = /* @__PURE__ */ ((InputTypes2) => {
232
236
  InputTypes2["REPEATER"] = "repeater";
233
237
  InputTypes2["MULTI_SELECT"] = "multi_select";
234
238
  InputTypes2["COMBOBOX"] = "COMBO_BOX";
239
+ InputTypes2["SORTABLE_LIST"] = "sortable_list";
235
240
  return InputTypes2;
236
241
  })(InputTypes || {});
237
242
  var inputFieldComp = [
243
+ "sortable_list" /* SORTABLE_LIST */,
238
244
  "COMBO_BOX" /* COMBOBOX */,
239
245
  "multi_select" /* MULTI_SELECT */,
240
246
  "repeater" /* REPEATER */,
@@ -4865,6 +4871,103 @@ var FieldSlider = ({ input, form, isSubmitting }) => {
4865
4871
  input.name
4866
4872
  );
4867
4873
  };
4874
+ var SortableListInput = class extends BaseInput {
4875
+ render() {
4876
+ const { input, form, isSubmitting } = this;
4877
+ const children = input.listConfig?.children ?? void 0;
4878
+ return /* @__PURE__ */ jsx(
4879
+ FieldSortableList,
4880
+ {
4881
+ form,
4882
+ input,
4883
+ isSubmitting,
4884
+ children
4885
+ }
4886
+ );
4887
+ }
4888
+ };
4889
+ function FieldSortableList({
4890
+ form,
4891
+ input,
4892
+ isSubmitting,
4893
+ children
4894
+ }) {
4895
+ const [items, setItems] = useState(() => input.listConfig?.list ?? []);
4896
+ const sortableEnabled = input.listConfig?.sortable ?? true;
4897
+ useSensors(
4898
+ useSensor(PointerSensor),
4899
+ useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates })
4900
+ );
4901
+ const handleDragEnd = (event) => {
4902
+ if (!sortableEnabled) return;
4903
+ const { active, over } = event;
4904
+ if (!over || active.id === over.id) return;
4905
+ const oldIndex = items.findIndex((i) => i.id === active.id);
4906
+ const newIndex = items.findIndex((i) => i.id === over.id);
4907
+ const newList = arrayMove(items, oldIndex, newIndex);
4908
+ setItems(newList);
4909
+ form.setValue(input.name, newList);
4910
+ input.listConfig?.onOptionChange?.(newList);
4911
+ };
4912
+ return /* @__PURE__ */ jsx(
4913
+ FormField,
4914
+ {
4915
+ control: form.control,
4916
+ name: input.name,
4917
+ render: () => /* @__PURE__ */ jsxs(FormItem, { className: cn("space-y-2", input.className), children: [
4918
+ input.label && /* @__PURE__ */ jsx(FormLabel, { children: /* @__PURE__ */ jsx("b", { children: input.label }) }),
4919
+ /* @__PURE__ */ jsx(FormControl, { children: sortableEnabled ? /* @__PURE__ */ jsx(DndContext, { collisionDetection: closestCenter, onDragEnd: handleDragEnd, children: /* @__PURE__ */ jsx(
4920
+ SortableContext,
4921
+ {
4922
+ items: items.map((i) => i.id),
4923
+ strategy: verticalListSortingStrategy,
4924
+ children: /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: items.map((item, index) => /* @__PURE__ */ jsx(SortableWrapper, { id: item.id, children: typeof children === "function" ? children(item, index) : /* @__PURE__ */ jsx("div", { className: "p-3 border rounded-md bg-white", children: item.name }) }, item.id)) })
4925
+ }
4926
+ ) }) : /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: items.map(
4927
+ (item, index) => typeof children === "function" ? children(item, index) : /* @__PURE__ */ jsx("div", { className: "p-3 border rounded-md bg-gray-50", children: item.name }, item.id)
4928
+ ) }) }),
4929
+ input.description && /* @__PURE__ */ jsx(FormDescription, { children: input.description }),
4930
+ /* @__PURE__ */ jsx(FormMessage, {})
4931
+ ] })
4932
+ },
4933
+ input.name
4934
+ );
4935
+ }
4936
+ function SortableWrapper({
4937
+ id,
4938
+ children,
4939
+ disabled
4940
+ }) {
4941
+ const {
4942
+ attributes,
4943
+ listeners,
4944
+ setNodeRef,
4945
+ transform,
4946
+ transition,
4947
+ isDragging
4948
+ } = useSortable({ id, disabled });
4949
+ const style = {
4950
+ transform: CSS.Transform.toString(transform),
4951
+ transition
4952
+ };
4953
+ return /* @__PURE__ */ jsxs(
4954
+ "div",
4955
+ {
4956
+ ref: setNodeRef,
4957
+ style,
4958
+ ...attributes,
4959
+ ...listeners,
4960
+ className: cn(
4961
+ "flex items-center gap-2 p-2 border rounded-md mb-1 bg-muted/30 cursor-grab select-none transition-all",
4962
+ isDragging && "opacity-60 bg-muted/50 scale-[0.98]"
4963
+ ),
4964
+ children: [
4965
+ /* @__PURE__ */ jsx(GripVertical, { className: "w-4 h-4 opacity-70" }),
4966
+ /* @__PURE__ */ jsx("div", { className: "flex-1", children })
4967
+ ]
4968
+ }
4969
+ );
4970
+ }
4868
4971
  var SwitchInput = class extends BaseInput {
4869
4972
  render() {
4870
4973
  const { input, form, isSubmitting } = this;
@@ -5159,6 +5262,7 @@ var inputMap = {
5159
5262
  ["repeater" /* REPEATER */]: RepeaterInput,
5160
5263
  ["multi_select" /* MULTI_SELECT */]: MultiSelectInput,
5161
5264
  ["COMBO_BOX" /* COMBOBOX */]: ComboboxInput,
5265
+ ["sortable_list" /* SORTABLE_LIST */]: SortableListInput,
5162
5266
  //ToDos: ============================================================
5163
5267
  ["slider" /* SLIDER */]: SliderInput,
5164
5268
  //ToDo: // PENDIENTE ... VISUALMENTE NO SE VE BIEN.!!!
@@ -5309,7 +5413,6 @@ var DynamicForm = ({
5309
5413
  const schema = useMemo(() => getDynamicSchema(fields, extraValidations), [fields, extraValidations]);
5310
5414
  const resolver = zodResolver(schema);
5311
5415
  const initialValues = useMemo(() => getDefaultValues(record), [record]);
5312
- console.log("initialValues", initialValues);
5313
5416
  const form = useForm({
5314
5417
  resolver,
5315
5418
  defaultValues: initialValues