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/README.md CHANGED
@@ -119,6 +119,8 @@ const mockFields: Array<FieldProps |FieldProps[]> = [
119
119
  | **Input Key Value** | `InputTypes.KEY_VALUE` |
120
120
  | **Input Repeater** | `InputTypes.REPEATER` |
121
121
  | **Input Multi Select** | `InputTypes.MULTI_SELECT` |
122
+ | **Select With Search** | `InputTypes.COMBOBOX` |
123
+ | **Input Drag Drop List** | `InputTypes.SORTABLE_LIST` |
122
124
 
123
125
 
124
126
 
package/dist/index.cjs CHANGED
@@ -28,6 +28,9 @@ var SwitchPrimitive = require('@radix-ui/react-switch');
28
28
  var TooltipPrimitive = require('@radix-ui/react-tooltip');
29
29
  var cmdk = require('cmdk');
30
30
  var SliderPrimitive = require('@radix-ui/react-slider');
31
+ var core = require('@dnd-kit/core');
32
+ var sortable = require('@dnd-kit/sortable');
33
+ var utilities = require('@dnd-kit/utilities');
31
34
  var z2 = require('zod');
32
35
  var zod = require('@hookform/resolvers/zod');
33
36
 
@@ -193,10 +196,11 @@ var validationMessages = {
193
196
 
194
197
  // src/components/custom/form/inputs/base/base-input.ts
195
198
  var BaseInput = class {
196
- constructor(input, form, isSubmitting) {
199
+ constructor(input, form, isSubmitting, children) {
197
200
  this.input = input;
198
201
  this.form = form;
199
202
  this.isSubmitting = isSubmitting;
203
+ this.children = children;
200
204
  }
201
205
  };
202
206
  var entityToInputOption = (entitiy, name = "name", description = "description", groupedLabel) => ({
@@ -269,9 +273,11 @@ var InputTypes = /* @__PURE__ */ ((InputTypes2) => {
269
273
  InputTypes2["REPEATER"] = "repeater";
270
274
  InputTypes2["MULTI_SELECT"] = "multi_select";
271
275
  InputTypes2["COMBOBOX"] = "COMBO_BOX";
276
+ InputTypes2["SORTABLE_LIST"] = "sortable_list";
272
277
  return InputTypes2;
273
278
  })(InputTypes || {});
274
279
  var inputFieldComp = [
280
+ "sortable_list" /* SORTABLE_LIST */,
275
281
  "COMBO_BOX" /* COMBOBOX */,
276
282
  "multi_select" /* MULTI_SELECT */,
277
283
  "repeater" /* REPEATER */,
@@ -4902,6 +4908,103 @@ var FieldSlider = ({ input, form, isSubmitting }) => {
4902
4908
  input.name
4903
4909
  );
4904
4910
  };
4911
+ var SortableListInput = class extends BaseInput {
4912
+ render() {
4913
+ const { input, form, isSubmitting } = this;
4914
+ const children = input.listConfig?.children ?? void 0;
4915
+ return /* @__PURE__ */ jsxRuntime.jsx(
4916
+ FieldSortableList,
4917
+ {
4918
+ form,
4919
+ input,
4920
+ isSubmitting,
4921
+ children
4922
+ }
4923
+ );
4924
+ }
4925
+ };
4926
+ function FieldSortableList({
4927
+ form,
4928
+ input,
4929
+ isSubmitting,
4930
+ children
4931
+ }) {
4932
+ const [items, setItems] = React3.useState(() => input.listConfig?.list ?? []);
4933
+ const sortableEnabled = input.listConfig?.sortable ?? true;
4934
+ core.useSensors(
4935
+ core.useSensor(core.PointerSensor),
4936
+ core.useSensor(core.KeyboardSensor, { coordinateGetter: sortable.sortableKeyboardCoordinates })
4937
+ );
4938
+ const handleDragEnd = (event) => {
4939
+ if (!sortableEnabled) return;
4940
+ const { active, over } = event;
4941
+ if (!over || active.id === over.id) return;
4942
+ const oldIndex = items.findIndex((i) => i.id === active.id);
4943
+ const newIndex = items.findIndex((i) => i.id === over.id);
4944
+ const newList = sortable.arrayMove(items, oldIndex, newIndex);
4945
+ setItems(newList);
4946
+ form.setValue(input.name, newList);
4947
+ input.listConfig?.onOptionChange?.(newList);
4948
+ };
4949
+ return /* @__PURE__ */ jsxRuntime.jsx(
4950
+ FormField,
4951
+ {
4952
+ control: form.control,
4953
+ name: input.name,
4954
+ render: () => /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: cn("space-y-2", input.className), children: [
4955
+ input.label && /* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
4956
+ /* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: sortableEnabled ? /* @__PURE__ */ jsxRuntime.jsx(core.DndContext, { collisionDetection: core.closestCenter, onDragEnd: handleDragEnd, children: /* @__PURE__ */ jsxRuntime.jsx(
4957
+ sortable.SortableContext,
4958
+ {
4959
+ items: items.map((i) => i.id),
4960
+ strategy: sortable.verticalListSortingStrategy,
4961
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsx(SortableWrapper, { id: item.id, children: typeof children === "function" ? children(item, index) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-3 border rounded-md bg-white", children: item.name }) }, item.id)) })
4962
+ }
4963
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: items.map(
4964
+ (item, index) => typeof children === "function" ? children(item, index) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-3 border rounded-md bg-gray-50", children: item.name }, item.id)
4965
+ ) }) }),
4966
+ input.description && /* @__PURE__ */ jsxRuntime.jsx(FormDescription, { children: input.description }),
4967
+ /* @__PURE__ */ jsxRuntime.jsx(FormMessage, {})
4968
+ ] })
4969
+ },
4970
+ input.name
4971
+ );
4972
+ }
4973
+ function SortableWrapper({
4974
+ id,
4975
+ children,
4976
+ disabled
4977
+ }) {
4978
+ const {
4979
+ attributes,
4980
+ listeners,
4981
+ setNodeRef,
4982
+ transform,
4983
+ transition,
4984
+ isDragging
4985
+ } = sortable.useSortable({ id, disabled });
4986
+ const style = {
4987
+ transform: utilities.CSS.Transform.toString(transform),
4988
+ transition
4989
+ };
4990
+ return /* @__PURE__ */ jsxRuntime.jsxs(
4991
+ "div",
4992
+ {
4993
+ ref: setNodeRef,
4994
+ style,
4995
+ ...attributes,
4996
+ ...listeners,
4997
+ className: cn(
4998
+ "flex items-center gap-2 p-2 border rounded-md mb-1 bg-muted/30 cursor-grab select-none transition-all",
4999
+ isDragging && "opacity-60 bg-muted/50 scale-[0.98]"
5000
+ ),
5001
+ children: [
5002
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.GripVertical, { className: "w-4 h-4 opacity-70" }),
5003
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children })
5004
+ ]
5005
+ }
5006
+ );
5007
+ }
4905
5008
  var SwitchInput = class extends BaseInput {
4906
5009
  render() {
4907
5010
  const { input, form, isSubmitting } = this;
@@ -5196,6 +5299,7 @@ var inputMap = {
5196
5299
  ["repeater" /* REPEATER */]: RepeaterInput,
5197
5300
  ["multi_select" /* MULTI_SELECT */]: MultiSelectInput,
5198
5301
  ["COMBO_BOX" /* COMBOBOX */]: ComboboxInput,
5302
+ ["sortable_list" /* SORTABLE_LIST */]: SortableListInput,
5199
5303
  //ToDos: ============================================================
5200
5304
  ["slider" /* SLIDER */]: SliderInput,
5201
5305
  //ToDo: // PENDIENTE ... VISUALMENTE NO SE VE BIEN.!!!
@@ -5346,7 +5450,6 @@ var DynamicForm = ({
5346
5450
  const schema = React3.useMemo(() => getDynamicSchema(fields, extraValidations), [fields, extraValidations]);
5347
5451
  const resolver = zod.zodResolver(schema);
5348
5452
  const initialValues = React3.useMemo(() => getDefaultValues(record), [record]);
5349
- console.log("initialValues", initialValues);
5350
5453
  const form = reactHookForm.useForm({
5351
5454
  resolver,
5352
5455
  defaultValues: initialValues