shadcn-zod-formkit 1.11.0 → 1.12.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.cjs +105 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +106 -2
- package/dist/index.mjs.map +1 -1
- package/dist/shadcn-zod-formkit-1.12.0.tgz +0 -0
- package/package.json +4 -1
- package/dist/shadcn-zod-formkit-1.11.0.tgz +0 -0
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
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';
|
|
@@ -26,6 +26,9 @@ import { Toaster as Toaster$1 } from 'sonner';
|
|
|
26
26
|
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
|
+
import { sortableKeyboardCoordinates, SortableContext, verticalListSortingStrategy, arrayMove, useSortable } from '@dnd-kit/sortable';
|
|
30
|
+
import { CSS } from '@dnd-kit/utilities';
|
|
31
|
+
import { useSensors, useSensor, PointerSensor, KeyboardSensor, DndContext, closestCenter } from '@dnd-kit/core';
|
|
29
32
|
import * as SliderPrimitive from '@radix-ui/react-slider';
|
|
30
33
|
import z2 from 'zod';
|
|
31
34
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
@@ -232,9 +235,11 @@ var InputTypes = /* @__PURE__ */ ((InputTypes2) => {
|
|
|
232
235
|
InputTypes2["REPEATER"] = "repeater";
|
|
233
236
|
InputTypes2["MULTI_SELECT"] = "multi_select";
|
|
234
237
|
InputTypes2["COMBOBOX"] = "COMBO_BOX";
|
|
238
|
+
InputTypes2["SORTABLE_LIST"] = "sortable_list";
|
|
235
239
|
return InputTypes2;
|
|
236
240
|
})(InputTypes || {});
|
|
237
241
|
var inputFieldComp = [
|
|
242
|
+
"sortable_list" /* SORTABLE_LIST */,
|
|
238
243
|
"COMBO_BOX" /* COMBOBOX */,
|
|
239
244
|
"multi_select" /* MULTI_SELECT */,
|
|
240
245
|
"repeater" /* REPEATER */,
|
|
@@ -3955,6 +3960,105 @@ var FieldDateTimeInput = ({ form, input, isSubmitting }) => {
|
|
|
3955
3960
|
input.name
|
|
3956
3961
|
);
|
|
3957
3962
|
};
|
|
3963
|
+
var SortableListInput = class extends BaseInput {
|
|
3964
|
+
render() {
|
|
3965
|
+
const { input, form, isSubmitting } = this;
|
|
3966
|
+
return /* @__PURE__ */ jsx(FieldSortableList, { form, input, isSubmitting });
|
|
3967
|
+
}
|
|
3968
|
+
};
|
|
3969
|
+
var FieldSortableList = ({ form, input, isSubmitting }) => {
|
|
3970
|
+
const [items, setItems] = useState((input.listConfig?.list ?? []).filter((item) => "name" in item));
|
|
3971
|
+
const sensors = useSensors(
|
|
3972
|
+
useSensor(PointerSensor),
|
|
3973
|
+
useSensor(KeyboardSensor, {
|
|
3974
|
+
coordinateGetter: sortableKeyboardCoordinates
|
|
3975
|
+
})
|
|
3976
|
+
);
|
|
3977
|
+
const handleDragEnd = (event) => {
|
|
3978
|
+
const { active, over } = event;
|
|
3979
|
+
if (!over || active.id === over.id) return;
|
|
3980
|
+
const oldIndex = items.findIndex((i) => i.id === active.id);
|
|
3981
|
+
const newIndex = items.findIndex((i) => i.id === over.id);
|
|
3982
|
+
const newList = arrayMove(items, oldIndex, newIndex);
|
|
3983
|
+
setItems(newList);
|
|
3984
|
+
form.setValue(input.name, newList);
|
|
3985
|
+
if (input.listConfig?.onOptionChange) {
|
|
3986
|
+
input.listConfig.onOptionChange(newList);
|
|
3987
|
+
}
|
|
3988
|
+
};
|
|
3989
|
+
return /* @__PURE__ */ jsx(
|
|
3990
|
+
FormField,
|
|
3991
|
+
{
|
|
3992
|
+
control: form.control,
|
|
3993
|
+
name: input.name,
|
|
3994
|
+
render: () => /* @__PURE__ */ jsxs(FormItem, { className: cn("space-y-2", input.className), children: [
|
|
3995
|
+
/* @__PURE__ */ jsx(FormLabel, { children: /* @__PURE__ */ jsx("b", { children: input.label }) }),
|
|
3996
|
+
/* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx("div", { className: "border rounded-md p-3 bg-white", children: /* @__PURE__ */ jsx(
|
|
3997
|
+
DndContext,
|
|
3998
|
+
{
|
|
3999
|
+
sensors,
|
|
4000
|
+
collisionDetection: closestCenter,
|
|
4001
|
+
onDragEnd: handleDragEnd,
|
|
4002
|
+
children: /* @__PURE__ */ jsx(
|
|
4003
|
+
SortableContext,
|
|
4004
|
+
{
|
|
4005
|
+
items: items.map((i) => i.id),
|
|
4006
|
+
strategy: verticalListSortingStrategy,
|
|
4007
|
+
children: items.map((item) => /* @__PURE__ */ jsx(
|
|
4008
|
+
SortableItem,
|
|
4009
|
+
{
|
|
4010
|
+
id: item.id,
|
|
4011
|
+
name: item.name,
|
|
4012
|
+
disabled: isSubmitting
|
|
4013
|
+
},
|
|
4014
|
+
item.id
|
|
4015
|
+
))
|
|
4016
|
+
}
|
|
4017
|
+
)
|
|
4018
|
+
}
|
|
4019
|
+
) }) }),
|
|
4020
|
+
input.description && /* @__PURE__ */ jsx(FormDescription, { children: input.description }),
|
|
4021
|
+
/* @__PURE__ */ jsx(FormMessage, {})
|
|
4022
|
+
] })
|
|
4023
|
+
},
|
|
4024
|
+
input.name
|
|
4025
|
+
);
|
|
4026
|
+
};
|
|
4027
|
+
function SortableItem({
|
|
4028
|
+
id,
|
|
4029
|
+
name,
|
|
4030
|
+
disabled
|
|
4031
|
+
}) {
|
|
4032
|
+
const {
|
|
4033
|
+
attributes,
|
|
4034
|
+
listeners,
|
|
4035
|
+
setNodeRef,
|
|
4036
|
+
transform,
|
|
4037
|
+
transition,
|
|
4038
|
+
isDragging
|
|
4039
|
+
} = useSortable({ id });
|
|
4040
|
+
const style = {
|
|
4041
|
+
transform: CSS.Transform.toString(transform),
|
|
4042
|
+
transition
|
|
4043
|
+
};
|
|
4044
|
+
return /* @__PURE__ */ jsx(
|
|
4045
|
+
"div",
|
|
4046
|
+
{
|
|
4047
|
+
ref: setNodeRef,
|
|
4048
|
+
style,
|
|
4049
|
+
...attributes,
|
|
4050
|
+
...listeners,
|
|
4051
|
+
className: cn(
|
|
4052
|
+
"flex items-center justify-between p-2 border rounded-md mb-1 bg-muted/30 cursor-grab select-none",
|
|
4053
|
+
isDragging && "opacity-60 bg-muted/50"
|
|
4054
|
+
),
|
|
4055
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
4056
|
+
/* @__PURE__ */ jsx(GripVertical, { className: "w-4 h-4 opacity-70" }),
|
|
4057
|
+
/* @__PURE__ */ jsx("span", { children: name })
|
|
4058
|
+
] })
|
|
4059
|
+
}
|
|
4060
|
+
);
|
|
4061
|
+
}
|
|
3958
4062
|
var FileInput = class extends BaseInput {
|
|
3959
4063
|
render() {
|
|
3960
4064
|
const { input, form, isSubmitting } = this;
|
|
@@ -5159,6 +5263,7 @@ var inputMap = {
|
|
|
5159
5263
|
["repeater" /* REPEATER */]: RepeaterInput,
|
|
5160
5264
|
["multi_select" /* MULTI_SELECT */]: MultiSelectInput,
|
|
5161
5265
|
["COMBO_BOX" /* COMBOBOX */]: ComboboxInput,
|
|
5266
|
+
["sortable_list" /* SORTABLE_LIST */]: SortableListInput,
|
|
5162
5267
|
//ToDos: ============================================================
|
|
5163
5268
|
["slider" /* SLIDER */]: SliderInput,
|
|
5164
5269
|
//ToDo: // PENDIENTE ... VISUALMENTE NO SE VE BIEN.!!!
|
|
@@ -5309,7 +5414,6 @@ var DynamicForm = ({
|
|
|
5309
5414
|
const schema = useMemo(() => getDynamicSchema(fields, extraValidations), [fields, extraValidations]);
|
|
5310
5415
|
const resolver = zodResolver(schema);
|
|
5311
5416
|
const initialValues = useMemo(() => getDefaultValues(record), [record]);
|
|
5312
|
-
console.log("initialValues", initialValues);
|
|
5313
5417
|
const form = useForm({
|
|
5314
5418
|
resolver,
|
|
5315
5419
|
defaultValues: initialValues
|