shadcn-zod-formkit 1.12.0 → 1.14.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 +2 -0
- package/dist/index.cjs +130 -110
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +130 -110
- package/dist/index.mjs.map +1 -1
- package/dist/shadcn-zod-formkit-1.14.0.tgz +0 -0
- package/package.json +1 -1
- package/dist/shadcn-zod-formkit-1.12.0.tgz +0 -0
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
|
|
|
@@ -3997,105 +3997,6 @@ var FieldDateTimeInput = ({ form, input, isSubmitting }) => {
|
|
|
3997
3997
|
input.name
|
|
3998
3998
|
);
|
|
3999
3999
|
};
|
|
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
4000
|
var FileInput = class extends BaseInput {
|
|
4100
4001
|
render() {
|
|
4101
4002
|
const { input, form, isSubmitting } = this;
|
|
@@ -5006,6 +4907,103 @@ var FieldSlider = ({ input, form, isSubmitting }) => {
|
|
|
5006
4907
|
input.name
|
|
5007
4908
|
);
|
|
5008
4909
|
};
|
|
4910
|
+
var SortableListInput = class extends BaseInput {
|
|
4911
|
+
render() {
|
|
4912
|
+
const { input, form, isSubmitting } = this;
|
|
4913
|
+
const children = input.listConfig?.children ?? void 0;
|
|
4914
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4915
|
+
FieldSortableList,
|
|
4916
|
+
{
|
|
4917
|
+
form,
|
|
4918
|
+
input,
|
|
4919
|
+
isSubmitting,
|
|
4920
|
+
children
|
|
4921
|
+
}
|
|
4922
|
+
);
|
|
4923
|
+
}
|
|
4924
|
+
};
|
|
4925
|
+
function FieldSortableList({
|
|
4926
|
+
form,
|
|
4927
|
+
input,
|
|
4928
|
+
isSubmitting,
|
|
4929
|
+
children
|
|
4930
|
+
}) {
|
|
4931
|
+
const [items, setItems] = React3.useState(() => input.listConfig?.list ?? []);
|
|
4932
|
+
const sortableEnabled = input.listConfig?.sortable ?? true;
|
|
4933
|
+
core.useSensors(
|
|
4934
|
+
core.useSensor(core.PointerSensor),
|
|
4935
|
+
core.useSensor(core.KeyboardSensor, { coordinateGetter: sortable.sortableKeyboardCoordinates })
|
|
4936
|
+
);
|
|
4937
|
+
const handleDragEnd = (event) => {
|
|
4938
|
+
if (!sortableEnabled) return;
|
|
4939
|
+
const { active, over } = event;
|
|
4940
|
+
if (!over || active.id === over.id) return;
|
|
4941
|
+
const oldIndex = items.findIndex((i) => i.id === active.id);
|
|
4942
|
+
const newIndex = items.findIndex((i) => i.id === over.id);
|
|
4943
|
+
const newList = sortable.arrayMove(items, oldIndex, newIndex);
|
|
4944
|
+
setItems(newList);
|
|
4945
|
+
form.setValue(input.name, newList);
|
|
4946
|
+
input.listConfig?.onOptionChange?.(newList);
|
|
4947
|
+
};
|
|
4948
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4949
|
+
FormField,
|
|
4950
|
+
{
|
|
4951
|
+
control: form.control,
|
|
4952
|
+
name: input.name,
|
|
4953
|
+
render: () => /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: cn("space-y-2", input.className), children: [
|
|
4954
|
+
input.label && /* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
|
|
4955
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: sortableEnabled ? /* @__PURE__ */ jsxRuntime.jsx(core.DndContext, { collisionDetection: core.closestCenter, onDragEnd: handleDragEnd, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4956
|
+
sortable.SortableContext,
|
|
4957
|
+
{
|
|
4958
|
+
items: items.map((i) => i.id),
|
|
4959
|
+
strategy: sortable.verticalListSortingStrategy,
|
|
4960
|
+
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)) })
|
|
4961
|
+
}
|
|
4962
|
+
) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: items.map(
|
|
4963
|
+
(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)
|
|
4964
|
+
) }) }),
|
|
4965
|
+
input.description && /* @__PURE__ */ jsxRuntime.jsx(FormDescription, { children: input.description }),
|
|
4966
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormMessage, {})
|
|
4967
|
+
] })
|
|
4968
|
+
},
|
|
4969
|
+
input.name
|
|
4970
|
+
);
|
|
4971
|
+
}
|
|
4972
|
+
function SortableWrapper({
|
|
4973
|
+
id,
|
|
4974
|
+
children,
|
|
4975
|
+
disabled
|
|
4976
|
+
}) {
|
|
4977
|
+
const {
|
|
4978
|
+
attributes,
|
|
4979
|
+
listeners,
|
|
4980
|
+
setNodeRef,
|
|
4981
|
+
transform,
|
|
4982
|
+
transition,
|
|
4983
|
+
isDragging
|
|
4984
|
+
} = sortable.useSortable({ id, disabled });
|
|
4985
|
+
const style = {
|
|
4986
|
+
transform: utilities.CSS.Transform.toString(transform),
|
|
4987
|
+
transition
|
|
4988
|
+
};
|
|
4989
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4990
|
+
"div",
|
|
4991
|
+
{
|
|
4992
|
+
ref: setNodeRef,
|
|
4993
|
+
style,
|
|
4994
|
+
...attributes,
|
|
4995
|
+
...listeners,
|
|
4996
|
+
className: cn(
|
|
4997
|
+
"flex items-center gap-2 p-2 border rounded-md mb-1 bg-muted/30 cursor-grab select-none transition-all",
|
|
4998
|
+
isDragging && "opacity-60 bg-muted/50 scale-[0.98]"
|
|
4999
|
+
),
|
|
5000
|
+
children: [
|
|
5001
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.GripVertical, { className: "w-4 h-4 opacity-70" }),
|
|
5002
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children })
|
|
5003
|
+
]
|
|
5004
|
+
}
|
|
5005
|
+
);
|
|
5006
|
+
}
|
|
5009
5007
|
var SwitchInput = class extends BaseInput {
|
|
5010
5008
|
render() {
|
|
5011
5009
|
const { input, form, isSubmitting } = this;
|
|
@@ -5404,6 +5402,7 @@ var getFieldLabel = (fieldErrorKey, fields) => {
|
|
|
5404
5402
|
const foundField = fields.find((field) => field.name === fieldErrorKey);
|
|
5405
5403
|
return foundField?.label ?? fieldErrorKey;
|
|
5406
5404
|
};
|
|
5405
|
+
var isRenderableChild = (c) => c !== void 0 && c !== null && typeof c !== "function";
|
|
5407
5406
|
var FormFieldsGrid = ({
|
|
5408
5407
|
fields,
|
|
5409
5408
|
form,
|
|
@@ -5413,23 +5412,44 @@ var FormFieldsGrid = ({
|
|
|
5413
5412
|
gap = "gap-2"
|
|
5414
5413
|
}) => {
|
|
5415
5414
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: `w-full grid grid-cols-1 ${gap} ${className}`, children: fields.map(
|
|
5416
|
-
(
|
|
5417
|
-
"
|
|
5415
|
+
(inputOrGroup, idx) => Array.isArray(inputOrGroup) ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
5416
|
+
"div",
|
|
5418
5417
|
{
|
|
5419
|
-
className: "w-full flex flex-row
|
|
5420
|
-
children:
|
|
5421
|
-
|
|
5422
|
-
|
|
5418
|
+
className: "w-full flex flex-row items-start gap-4 py-3",
|
|
5419
|
+
children: inputOrGroup.map((field, subIdx) => {
|
|
5420
|
+
const fieldCopy = {
|
|
5421
|
+
...field,
|
|
5422
|
+
disabled: readOnly ? true : field.disabled
|
|
5423
|
+
};
|
|
5424
|
+
const renderInlineChild = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
|
|
5425
|
+
const renderInlineChildDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
|
|
5426
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full px-2", children: [
|
|
5427
|
+
renderInlineChild && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children }),
|
|
5428
|
+
InputFactory.create(fieldCopy, form, isPending),
|
|
5429
|
+
renderInlineChildDown && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children })
|
|
5430
|
+
] }, `field-${idx}-${subIdx}`);
|
|
5423
5431
|
})
|
|
5424
5432
|
},
|
|
5425
5433
|
`field-group-${idx}`
|
|
5426
5434
|
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
5427
|
-
"
|
|
5435
|
+
"div",
|
|
5428
5436
|
{
|
|
5429
5437
|
className: "flex flex-col justify-between py-3 w-full px-2",
|
|
5430
|
-
children:
|
|
5438
|
+
children: (() => {
|
|
5439
|
+
const fieldCopy = {
|
|
5440
|
+
...inputOrGroup,
|
|
5441
|
+
disabled: readOnly ? true : inputOrGroup.disabled
|
|
5442
|
+
};
|
|
5443
|
+
const renderUp = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
|
|
5444
|
+
const renderDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
|
|
5445
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
5446
|
+
renderUp && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children }),
|
|
5447
|
+
InputFactory.create(fieldCopy, form, isPending),
|
|
5448
|
+
renderDown && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children })
|
|
5449
|
+
] });
|
|
5450
|
+
})()
|
|
5431
5451
|
},
|
|
5432
|
-
`field-
|
|
5452
|
+
`field-single-${idx}`
|
|
5433
5453
|
)
|
|
5434
5454
|
) });
|
|
5435
5455
|
};
|