shadcn-zod-formkit 1.22.3 → 1.23.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 +110 -90
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.mjs +111 -91
- package/dist/index.mjs.map +1 -1
- package/dist/shadcn-zod-formkit-1.23.0.tgz +0 -0
- package/package.json +1 -1
- package/dist/shadcn-zod-formkit-1.22.3.tgz +0 -0
package/dist/index.cjs
CHANGED
|
@@ -5589,49 +5589,55 @@ var getFieldLabel = (fieldErrorKey, fields) => {
|
|
|
5589
5589
|
return foundField?.label ?? fieldErrorKey;
|
|
5590
5590
|
};
|
|
5591
5591
|
var isRenderableChild = (c) => c !== void 0 && c !== null && typeof c !== "function";
|
|
5592
|
-
var isFieldProps = (f) => !Array.isArray(f);
|
|
5593
5592
|
var FormFieldsGrid = ({
|
|
5594
5593
|
fields,
|
|
5595
5594
|
form,
|
|
5596
5595
|
isPending,
|
|
5597
5596
|
readOnly,
|
|
5598
5597
|
className = "",
|
|
5599
|
-
gap = "gap-
|
|
5598
|
+
gap = "gap-2"
|
|
5600
5599
|
}) => {
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
5613
|
-
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
|
|
5630
|
-
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
|
|
5634
|
-
|
|
5600
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: `w-full grid grid-cols-1 ${gap} ${className}`, children: fields.map(
|
|
5601
|
+
(inputOrGroup, idx) => Array.isArray(inputOrGroup) ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
5602
|
+
"div",
|
|
5603
|
+
{
|
|
5604
|
+
className: "w-full flex flex-row items-start gap-4 py-3",
|
|
5605
|
+
children: inputOrGroup.map((field, subIdx) => {
|
|
5606
|
+
const fieldCopy = {
|
|
5607
|
+
...field,
|
|
5608
|
+
disabled: readOnly ? true : field.disabled
|
|
5609
|
+
};
|
|
5610
|
+
const renderInlineChild = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
|
|
5611
|
+
const renderInlineChildDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
|
|
5612
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full px-2", children: [
|
|
5613
|
+
renderInlineChild && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children }),
|
|
5614
|
+
InputFactory.create(fieldCopy, form, isPending),
|
|
5615
|
+
renderInlineChildDown && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children })
|
|
5616
|
+
] }, `field-${idx}-${subIdx}`);
|
|
5617
|
+
})
|
|
5618
|
+
},
|
|
5619
|
+
`field-group-${idx}`
|
|
5620
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
5621
|
+
"div",
|
|
5622
|
+
{
|
|
5623
|
+
className: "flex flex-col justify-between py-3 w-full px-2",
|
|
5624
|
+
children: (() => {
|
|
5625
|
+
const fieldCopy = {
|
|
5626
|
+
...inputOrGroup,
|
|
5627
|
+
disabled: readOnly ? true : inputOrGroup.disabled
|
|
5628
|
+
};
|
|
5629
|
+
const renderUp = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
|
|
5630
|
+
const renderDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
|
|
5631
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
5632
|
+
renderUp && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children }),
|
|
5633
|
+
InputFactory.create(fieldCopy, form, isPending),
|
|
5634
|
+
renderDown && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children })
|
|
5635
|
+
] });
|
|
5636
|
+
})()
|
|
5637
|
+
},
|
|
5638
|
+
`field-single-${idx}`
|
|
5639
|
+
)
|
|
5640
|
+
) });
|
|
5635
5641
|
};
|
|
5636
5642
|
var DynamicForm = ({
|
|
5637
5643
|
formTitle,
|
|
@@ -5649,9 +5655,13 @@ var DynamicForm = ({
|
|
|
5649
5655
|
withErrorsAlert = true,
|
|
5650
5656
|
errorAlertPosition = "up",
|
|
5651
5657
|
withCard = false,
|
|
5652
|
-
submitBtnClass
|
|
5658
|
+
submitBtnClass,
|
|
5653
5659
|
listBtnConfig = [],
|
|
5654
|
-
submitBtnLabel = "Guardar"
|
|
5660
|
+
submitBtnLabel = "Guardar",
|
|
5661
|
+
submitBtnLabelSubmiting = "Guardando...",
|
|
5662
|
+
withFormWrapper = true,
|
|
5663
|
+
btnGroupDirection = "flex-end",
|
|
5664
|
+
withSubmitBtn = true
|
|
5655
5665
|
}) => {
|
|
5656
5666
|
const [isPending, startTransition] = React3.useTransition();
|
|
5657
5667
|
const schema = React3.useMemo(() => {
|
|
@@ -5682,6 +5692,56 @@ var DynamicForm = ({
|
|
|
5682
5692
|
const resp = { data, form };
|
|
5683
5693
|
onClick(resp);
|
|
5684
5694
|
};
|
|
5695
|
+
const formBody = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
5696
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full grid grid-cols-1", children: [
|
|
5697
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
5698
|
+
FormFieldsGrid,
|
|
5699
|
+
{
|
|
5700
|
+
fields,
|
|
5701
|
+
form,
|
|
5702
|
+
readOnly
|
|
5703
|
+
}
|
|
5704
|
+
),
|
|
5705
|
+
children && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row items-center gap-2 w-full h-full", children })
|
|
5706
|
+
] }),
|
|
5707
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ButtonGroup, { className: "flex flex-row w-full h-full", style: {
|
|
5708
|
+
justifyContent: btnGroupDirection,
|
|
5709
|
+
// Alinea horizontalmente a la derecha
|
|
5710
|
+
alignItems: "center"
|
|
5711
|
+
// Centra verticalmente (opcional)
|
|
5712
|
+
}, children: [
|
|
5713
|
+
listBtnConfig.map((btn, key) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
5714
|
+
Button,
|
|
5715
|
+
{
|
|
5716
|
+
type: btn.btnType,
|
|
5717
|
+
size: "icon-lg",
|
|
5718
|
+
className: submitBtnClass,
|
|
5719
|
+
variant: btn.variant,
|
|
5720
|
+
onClick: btn.onClick,
|
|
5721
|
+
disabled: btn.disabled,
|
|
5722
|
+
children: btn.label
|
|
5723
|
+
},
|
|
5724
|
+
key
|
|
5725
|
+
)),
|
|
5726
|
+
!readOnly && withSubmitBtn && /* @__PURE__ */ jsxRuntime.jsx(
|
|
5727
|
+
Button,
|
|
5728
|
+
{
|
|
5729
|
+
type: onClick ? "button" : "submit",
|
|
5730
|
+
size: "icon-lg",
|
|
5731
|
+
className: cn("text-lg", submitBtnClass),
|
|
5732
|
+
disabled: isPending,
|
|
5733
|
+
onClick: onClick ? handleClick : void 0,
|
|
5734
|
+
children: isPending ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
5735
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-5 w-5 mr-2 animate-spin" }),
|
|
5736
|
+
submitBtnLabelSubmiting
|
|
5737
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
5738
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Save, { className: "h-5 w-5 mr-2" }),
|
|
5739
|
+
submitBtnLabel
|
|
5740
|
+
] })
|
|
5741
|
+
}
|
|
5742
|
+
)
|
|
5743
|
+
] })
|
|
5744
|
+
] });
|
|
5685
5745
|
const formContent = /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
5686
5746
|
showFormHeader && /* @__PURE__ */ jsxRuntime.jsxs(CardTitle, { className: "flex flex-row items-center gap-2 p-2 border-b", children: [
|
|
5687
5747
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-row items-center gap-2 w-full", children: [
|
|
@@ -5700,58 +5760,8 @@ var DynamicForm = ({
|
|
|
5700
5760
|
fields
|
|
5701
5761
|
}
|
|
5702
5762
|
),
|
|
5703
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
5704
|
-
|
|
5705
|
-
{
|
|
5706
|
-
onSubmit: form.handleSubmit(handleSubmit),
|
|
5707
|
-
className: `flex flex-col gap-2 ${readOnly ? "opacity-70 pointer-events-none select-none" : ""}`,
|
|
5708
|
-
children: [
|
|
5709
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full grid grid-cols-1", children: [
|
|
5710
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
5711
|
-
FormFieldsGrid,
|
|
5712
|
-
{
|
|
5713
|
-
fields,
|
|
5714
|
-
form,
|
|
5715
|
-
readOnly
|
|
5716
|
-
}
|
|
5717
|
-
),
|
|
5718
|
-
children && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row items-center gap-2 w-full h-full", children })
|
|
5719
|
-
] }),
|
|
5720
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ButtonGroup, { className: "flex flex-row w-full", children: [
|
|
5721
|
-
listBtnConfig.map((btn, key) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
5722
|
-
Button,
|
|
5723
|
-
{
|
|
5724
|
-
type: btn.btnType,
|
|
5725
|
-
size: "lg",
|
|
5726
|
-
className: submitBtnClass,
|
|
5727
|
-
variant: btn.variant,
|
|
5728
|
-
onClick: btn.onClick,
|
|
5729
|
-
disabled: btn.disabled,
|
|
5730
|
-
children: btn.label
|
|
5731
|
-
},
|
|
5732
|
-
key
|
|
5733
|
-
)),
|
|
5734
|
-
!readOnly && /* @__PURE__ */ jsxRuntime.jsx(
|
|
5735
|
-
Button,
|
|
5736
|
-
{
|
|
5737
|
-
type: onClick ? "button" : "submit",
|
|
5738
|
-
size: "lg",
|
|
5739
|
-
className: submitBtnClass,
|
|
5740
|
-
disabled: isPending,
|
|
5741
|
-
onClick: onClick ? handleClick : void 0,
|
|
5742
|
-
children: isPending ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
5743
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-4 w-4 mr-2 animate-spin" }),
|
|
5744
|
-
"Guardando..."
|
|
5745
|
-
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
5746
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Save, { className: "h-4 w-4 mr-2" }),
|
|
5747
|
-
submitBtnLabel
|
|
5748
|
-
] })
|
|
5749
|
-
}
|
|
5750
|
-
)
|
|
5751
|
-
] })
|
|
5752
|
-
]
|
|
5753
|
-
}
|
|
5754
|
-
) }),
|
|
5763
|
+
withFormWrapper && /* @__PURE__ */ jsxRuntime.jsx(FormWrapper, { form, handleSubmit, children: formBody }),
|
|
5764
|
+
!withFormWrapper && formBody,
|
|
5755
5765
|
withErrorsAlert && errorAlertPosition === "down" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
5756
5766
|
FormErrorsAlert,
|
|
5757
5767
|
{
|
|
@@ -5763,6 +5773,16 @@ var DynamicForm = ({
|
|
|
5763
5773
|
if (!withCard) return formContent;
|
|
5764
5774
|
return /* @__PURE__ */ jsxRuntime.jsx(Card, { children: /* @__PURE__ */ jsxRuntime.jsx(CardContent, { children: formContent }) });
|
|
5765
5775
|
};
|
|
5776
|
+
var FormWrapper = ({ form, handleSubmit, children, readOnly }) => {
|
|
5777
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
5778
|
+
"form",
|
|
5779
|
+
{
|
|
5780
|
+
onSubmit: form.handleSubmit(handleSubmit),
|
|
5781
|
+
className: `flex flex-col gap-2 ${readOnly ? "opacity-70 pointer-events-none select-none" : ""}`,
|
|
5782
|
+
children
|
|
5783
|
+
}
|
|
5784
|
+
) });
|
|
5785
|
+
};
|
|
5766
5786
|
var DynamicFormExample = () => {
|
|
5767
5787
|
const record = {
|
|
5768
5788
|
username: "John Doe ",
|