shadcn-zod-formkit 1.12.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
@@ -27,10 +27,10 @@ var sonner = require('sonner');
27
27
  var SwitchPrimitive = require('@radix-ui/react-switch');
28
28
  var TooltipPrimitive = require('@radix-ui/react-tooltip');
29
29
  var cmdk = require('cmdk');
30
+ var SliderPrimitive = require('@radix-ui/react-slider');
31
+ var core = require('@dnd-kit/core');
30
32
  var sortable = require('@dnd-kit/sortable');
31
33
  var utilities = require('@dnd-kit/utilities');
32
- var core = require('@dnd-kit/core');
33
- var SliderPrimitive = require('@radix-ui/react-slider');
34
34
  var z2 = require('zod');
35
35
  var zod = require('@hookform/resolvers/zod');
36
36
 
@@ -196,10 +196,11 @@ var validationMessages = {
196
196
 
197
197
  // src/components/custom/form/inputs/base/base-input.ts
198
198
  var BaseInput = class {
199
- constructor(input, form, isSubmitting) {
199
+ constructor(input, form, isSubmitting, children) {
200
200
  this.input = input;
201
201
  this.form = form;
202
202
  this.isSubmitting = isSubmitting;
203
+ this.children = children;
203
204
  }
204
205
  };
205
206
  var entityToInputOption = (entitiy, name = "name", description = "description", groupedLabel) => ({
@@ -3997,105 +3998,6 @@ var FieldDateTimeInput = ({ form, input, isSubmitting }) => {
3997
3998
  input.name
3998
3999
  );
3999
4000
  };
4000
- var SortableListInput = class extends BaseInput {
4001
- render() {
4002
- const { input, form, isSubmitting } = this;
4003
- return /* @__PURE__ */ jsxRuntime.jsx(FieldSortableList, { form, input, isSubmitting });
4004
- }
4005
- };
4006
- var FieldSortableList = ({ form, input, isSubmitting }) => {
4007
- const [items, setItems] = React3.useState((input.listConfig?.list ?? []).filter((item) => "name" in item));
4008
- const sensors = core.useSensors(
4009
- core.useSensor(core.PointerSensor),
4010
- core.useSensor(core.KeyboardSensor, {
4011
- coordinateGetter: sortable.sortableKeyboardCoordinates
4012
- })
4013
- );
4014
- const handleDragEnd = (event) => {
4015
- const { active, over } = event;
4016
- if (!over || active.id === over.id) return;
4017
- const oldIndex = items.findIndex((i) => i.id === active.id);
4018
- const newIndex = items.findIndex((i) => i.id === over.id);
4019
- const newList = sortable.arrayMove(items, oldIndex, newIndex);
4020
- setItems(newList);
4021
- form.setValue(input.name, newList);
4022
- if (input.listConfig?.onOptionChange) {
4023
- input.listConfig.onOptionChange(newList);
4024
- }
4025
- };
4026
- return /* @__PURE__ */ jsxRuntime.jsx(
4027
- FormField,
4028
- {
4029
- control: form.control,
4030
- name: input.name,
4031
- render: () => /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: cn("space-y-2", input.className), children: [
4032
- /* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
4033
- /* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border rounded-md p-3 bg-white", children: /* @__PURE__ */ jsxRuntime.jsx(
4034
- core.DndContext,
4035
- {
4036
- sensors,
4037
- collisionDetection: core.closestCenter,
4038
- onDragEnd: handleDragEnd,
4039
- children: /* @__PURE__ */ jsxRuntime.jsx(
4040
- sortable.SortableContext,
4041
- {
4042
- items: items.map((i) => i.id),
4043
- strategy: sortable.verticalListSortingStrategy,
4044
- children: items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
4045
- SortableItem,
4046
- {
4047
- id: item.id,
4048
- name: item.name,
4049
- disabled: isSubmitting
4050
- },
4051
- item.id
4052
- ))
4053
- }
4054
- )
4055
- }
4056
- ) }) }),
4057
- input.description && /* @__PURE__ */ jsxRuntime.jsx(FormDescription, { children: input.description }),
4058
- /* @__PURE__ */ jsxRuntime.jsx(FormMessage, {})
4059
- ] })
4060
- },
4061
- input.name
4062
- );
4063
- };
4064
- function SortableItem({
4065
- id,
4066
- name,
4067
- disabled
4068
- }) {
4069
- const {
4070
- attributes,
4071
- listeners,
4072
- setNodeRef,
4073
- transform,
4074
- transition,
4075
- isDragging
4076
- } = sortable.useSortable({ id });
4077
- const style = {
4078
- transform: utilities.CSS.Transform.toString(transform),
4079
- transition
4080
- };
4081
- return /* @__PURE__ */ jsxRuntime.jsx(
4082
- "div",
4083
- {
4084
- ref: setNodeRef,
4085
- style,
4086
- ...attributes,
4087
- ...listeners,
4088
- className: cn(
4089
- "flex items-center justify-between p-2 border rounded-md mb-1 bg-muted/30 cursor-grab select-none",
4090
- isDragging && "opacity-60 bg-muted/50"
4091
- ),
4092
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
4093
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.GripVertical, { className: "w-4 h-4 opacity-70" }),
4094
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: name })
4095
- ] })
4096
- }
4097
- );
4098
- }
4099
4001
  var FileInput = class extends BaseInput {
4100
4002
  render() {
4101
4003
  const { input, form, isSubmitting } = this;
@@ -5006,6 +4908,103 @@ var FieldSlider = ({ input, form, isSubmitting }) => {
5006
4908
  input.name
5007
4909
  );
5008
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
+ }
5009
5008
  var SwitchInput = class extends BaseInput {
5010
5009
  render() {
5011
5010
  const { input, form, isSubmitting } = this;