shadcn-zod-formkit 1.26.1 → 1.27.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 +38 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.mjs +39 -28
- package/dist/index.mjs.map +1 -1
- package/dist/shadcn-zod-formkit-1.27.0.tgz +0 -0
- package/package.json +1 -1
- package/dist/shadcn-zod-formkit-1.26.1.tgz +0 -0
package/dist/index.cjs
CHANGED
|
@@ -234,7 +234,9 @@ var entitiesToGroupedOption = (data, optionValue = "name") => {
|
|
|
234
234
|
};
|
|
235
235
|
var handleOnChage = (event, input, field) => {
|
|
236
236
|
if (event) field?.onChange(event);
|
|
237
|
-
|
|
237
|
+
const data = input.form?.getValues();
|
|
238
|
+
input.onChange?.(event, data);
|
|
239
|
+
if (input.onAnyFieldChange) input.onAnyFieldChange?.(data);
|
|
238
240
|
};
|
|
239
241
|
var isValidField = (input, form, defaultValue) => {
|
|
240
242
|
const value = defaultValue ?? form.getValues(input.name);
|
|
@@ -247,7 +249,7 @@ var isValidField = (input, form, defaultValue) => {
|
|
|
247
249
|
};
|
|
248
250
|
|
|
249
251
|
// src/components/custom/form/inputs/base/definitions.ts
|
|
250
|
-
var flattenFields = (fields) => {
|
|
252
|
+
var flattenFields = (fields, onAnyFieldChange) => {
|
|
251
253
|
const result = [];
|
|
252
254
|
for (const field of fields) {
|
|
253
255
|
if (Array.isArray(field)) {
|
|
@@ -255,6 +257,7 @@ var flattenFields = (fields) => {
|
|
|
255
257
|
} else if (field.fields) {
|
|
256
258
|
result.push(...flattenFields(field.fields));
|
|
257
259
|
} else {
|
|
260
|
+
if (onAnyFieldChange) field.onAnyFieldChange = (data) => onAnyFieldChange(data);
|
|
258
261
|
result.push(field);
|
|
259
262
|
}
|
|
260
263
|
}
|
|
@@ -4561,34 +4564,40 @@ var FieldKeyValueList = ({ form, input, isSubmitting }) => {
|
|
|
4561
4564
|
return /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: input.className, children: [
|
|
4562
4565
|
/* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
|
|
4563
4566
|
/* @__PURE__ */ jsxRuntime.jsx(FormMessage, {}),
|
|
4564
|
-
/* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 rounded-xl
|
|
4567
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 rounded-xl ", children: [
|
|
4565
4568
|
pairs.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "No pairs have been added yet." }),
|
|
4566
4569
|
pairs.map((pair, index) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4567
4570
|
"div",
|
|
4568
4571
|
{
|
|
4569
|
-
className: "flex gap-2 items-center",
|
|
4572
|
+
className: "flex flex-row w-full gap-2 items-center py-0.5",
|
|
4570
4573
|
children: [
|
|
4571
|
-
/* @__PURE__ */ jsxRuntime.
|
|
4572
|
-
|
|
4573
|
-
{
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4574
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ButtonGroup, { className: "w-full", children: [
|
|
4575
|
+
/* @__PURE__ */ jsxRuntime.jsx(ButtonGroupText, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(LabelPrimitive.Label, { htmlFor: "key", children: "Key" }) }),
|
|
4576
|
+
/* @__PURE__ */ jsxRuntime.jsx(InputGroup, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4577
|
+
InputGroupInput,
|
|
4578
|
+
{
|
|
4579
|
+
placeholder: "Key",
|
|
4580
|
+
value: pair.key,
|
|
4581
|
+
disabled: isSubmitting,
|
|
4582
|
+
onChange: (e) => handleChange(index, "key", e.target.value),
|
|
4583
|
+
className: "flex-1"
|
|
4584
|
+
}
|
|
4585
|
+
) })
|
|
4586
|
+
] }),
|
|
4587
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ButtonGroup, { className: "w-full", children: [
|
|
4588
|
+
/* @__PURE__ */ jsxRuntime.jsx(ButtonGroupText, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(LabelPrimitive.Label, { htmlFor: "value", children: "Value" }) }),
|
|
4589
|
+
/* @__PURE__ */ jsxRuntime.jsx(InputGroup, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4590
|
+
InputGroupInput,
|
|
4591
|
+
{
|
|
4592
|
+
placeholder: "Value",
|
|
4593
|
+
value: pair.value,
|
|
4594
|
+
disabled: isSubmitting,
|
|
4595
|
+
onChange: (e) => handleChange(index, "value", e.target.value),
|
|
4596
|
+
className: "flex-1"
|
|
4597
|
+
}
|
|
4598
|
+
) })
|
|
4599
|
+
] }),
|
|
4600
|
+
input.isRemovebleOption && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4592
4601
|
Button,
|
|
4593
4602
|
{
|
|
4594
4603
|
type: "button",
|
|
@@ -4925,7 +4934,7 @@ var FieldRepeater = ({ form, input, isSubmitting }) => {
|
|
|
4925
4934
|
fields.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4926
4935
|
"div",
|
|
4927
4936
|
{
|
|
4928
|
-
className: "border p-3 rounded-md flex flex-col gap-3",
|
|
4937
|
+
className: "border p-3 rounded-md flex flex-col gap-4 py-3",
|
|
4929
4938
|
children: [
|
|
4930
4939
|
input.repeaterFields?.map((fieldGroup, groupIndex) => {
|
|
4931
4940
|
const group = Array.isArray(fieldGroup) ? fieldGroup : [fieldGroup];
|
|
@@ -5587,7 +5596,7 @@ var FieldStringValueList = ({ form, input, isSubmitting }) => {
|
|
|
5587
5596
|
items.map((value, index) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
5588
5597
|
"div",
|
|
5589
5598
|
{
|
|
5590
|
-
className: "flex gap-
|
|
5599
|
+
className: "flex items-center gap-4 py-2",
|
|
5591
5600
|
children: [
|
|
5592
5601
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
5593
5602
|
Input,
|
|
@@ -6109,6 +6118,7 @@ var DynamicForm = ({
|
|
|
6109
6118
|
fields,
|
|
6110
6119
|
readOnly = false,
|
|
6111
6120
|
record = {},
|
|
6121
|
+
onAnyFieldChange,
|
|
6112
6122
|
onSubmit,
|
|
6113
6123
|
onClick,
|
|
6114
6124
|
extraValidations,
|
|
@@ -6129,7 +6139,7 @@ var DynamicForm = ({
|
|
|
6129
6139
|
}) => {
|
|
6130
6140
|
const [isPending, startTransition] = React3.useTransition();
|
|
6131
6141
|
const schema = React3.useMemo(() => {
|
|
6132
|
-
const allFields = flattenFields(fields);
|
|
6142
|
+
const allFields = flattenFields(fields, onAnyFieldChange);
|
|
6133
6143
|
return getDynamicSchema(allFields, extraValidations);
|
|
6134
6144
|
}, [fields, extraValidations]);
|
|
6135
6145
|
const resolver = zod.zodResolver(schema);
|