shadcn-zod-formkit 1.26.1 → 1.27.1
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 +39 -29
- 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 +40 -29
- package/dist/index.mjs.map +1 -1
- package/dist/shadcn-zod-formkit-1.27.1.tgz +0 -0
- package/package.json +1 -1
- package/dist/shadcn-zod-formkit-1.26.1.tgz +0 -0
package/dist/index.d.mts
CHANGED
|
@@ -83,7 +83,7 @@ declare enum InputTypes {
|
|
|
83
83
|
}
|
|
84
84
|
declare const inputFieldComp: InputTypes[];
|
|
85
85
|
|
|
86
|
-
declare const flattenFields: <T extends Record<string, any>>(fields: FieldConfig<T>[]) => FieldProps<T>[];
|
|
86
|
+
declare const flattenFields: <T extends Record<string, any>>(fields: FieldConfig<T>[], onAnyFieldChange?: (data: any) => void) => FieldProps<T>[];
|
|
87
87
|
type FieldConfig<T, RT = Record<string, any>> = FieldProps<T, RT> | FieldConfig<T, RT>[];
|
|
88
88
|
interface FieldProps<T = Record<string, any>, RT = Record<string, any>> {
|
|
89
89
|
name: keyof T;
|
|
@@ -102,6 +102,7 @@ interface FieldProps<T = Record<string, any>, RT = Record<string, any>> {
|
|
|
102
102
|
maxItems?: number;
|
|
103
103
|
currencyFormat?: Intl.NumberFormatOptions;
|
|
104
104
|
mask?: string | RegExp;
|
|
105
|
+
onAnyFieldChange?: (data: Record<string, any>) => void;
|
|
105
106
|
wrapInCard?: boolean;
|
|
106
107
|
placeHolder?: string;
|
|
107
108
|
description?: string;
|
|
@@ -223,6 +224,7 @@ interface Props$h<T extends Record<string, any>> {
|
|
|
223
224
|
readOnly?: boolean;
|
|
224
225
|
fields: FieldConfig<T>[];
|
|
225
226
|
record?: Partial<T>;
|
|
227
|
+
onAnyFieldChange?: (data: Record<string, any>) => void;
|
|
226
228
|
onSubmit?: (resp: FormResp<T>) => void;
|
|
227
229
|
onClick?: (resp: FormResp<T>) => void;
|
|
228
230
|
extraValidations?: ((schema: ZodObject<any>) => ZodObject<any>)[];
|
|
@@ -239,7 +241,7 @@ interface Props$h<T extends Record<string, any>> {
|
|
|
239
241
|
childrenHeader?: ReactNode;
|
|
240
242
|
listBtnConfig?: BtnConfig[];
|
|
241
243
|
}
|
|
242
|
-
declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onSubmit, onClick, extraValidations, children, childrenHeader, showIcon, showFormHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, listBtnConfig, submitBtnLabel, submitBtnLabelSubmiting, withFormWrapper, btnGroupDirection, withSubmitBtn }: Props$h<T>) => react_jsx_runtime.JSX.Element;
|
|
244
|
+
declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onAnyFieldChange, onSubmit, onClick, extraValidations, children, childrenHeader, showIcon, showFormHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, listBtnConfig, submitBtnLabel, submitBtnLabelSubmiting, withFormWrapper, btnGroupDirection, withSubmitBtn }: Props$h<T>) => react_jsx_runtime.JSX.Element;
|
|
243
245
|
|
|
244
246
|
declare const DynamicFormExample: () => react_jsx_runtime.JSX.Element;
|
|
245
247
|
declare const mockFields: Array<FieldProps | FieldProps[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -83,7 +83,7 @@ declare enum InputTypes {
|
|
|
83
83
|
}
|
|
84
84
|
declare const inputFieldComp: InputTypes[];
|
|
85
85
|
|
|
86
|
-
declare const flattenFields: <T extends Record<string, any>>(fields: FieldConfig<T>[]) => FieldProps<T>[];
|
|
86
|
+
declare const flattenFields: <T extends Record<string, any>>(fields: FieldConfig<T>[], onAnyFieldChange?: (data: any) => void) => FieldProps<T>[];
|
|
87
87
|
type FieldConfig<T, RT = Record<string, any>> = FieldProps<T, RT> | FieldConfig<T, RT>[];
|
|
88
88
|
interface FieldProps<T = Record<string, any>, RT = Record<string, any>> {
|
|
89
89
|
name: keyof T;
|
|
@@ -102,6 +102,7 @@ interface FieldProps<T = Record<string, any>, RT = Record<string, any>> {
|
|
|
102
102
|
maxItems?: number;
|
|
103
103
|
currencyFormat?: Intl.NumberFormatOptions;
|
|
104
104
|
mask?: string | RegExp;
|
|
105
|
+
onAnyFieldChange?: (data: Record<string, any>) => void;
|
|
105
106
|
wrapInCard?: boolean;
|
|
106
107
|
placeHolder?: string;
|
|
107
108
|
description?: string;
|
|
@@ -223,6 +224,7 @@ interface Props$h<T extends Record<string, any>> {
|
|
|
223
224
|
readOnly?: boolean;
|
|
224
225
|
fields: FieldConfig<T>[];
|
|
225
226
|
record?: Partial<T>;
|
|
227
|
+
onAnyFieldChange?: (data: Record<string, any>) => void;
|
|
226
228
|
onSubmit?: (resp: FormResp<T>) => void;
|
|
227
229
|
onClick?: (resp: FormResp<T>) => void;
|
|
228
230
|
extraValidations?: ((schema: ZodObject<any>) => ZodObject<any>)[];
|
|
@@ -239,7 +241,7 @@ interface Props$h<T extends Record<string, any>> {
|
|
|
239
241
|
childrenHeader?: ReactNode;
|
|
240
242
|
listBtnConfig?: BtnConfig[];
|
|
241
243
|
}
|
|
242
|
-
declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onSubmit, onClick, extraValidations, children, childrenHeader, showIcon, showFormHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, listBtnConfig, submitBtnLabel, submitBtnLabelSubmiting, withFormWrapper, btnGroupDirection, withSubmitBtn }: Props$h<T>) => react_jsx_runtime.JSX.Element;
|
|
244
|
+
declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onAnyFieldChange, onSubmit, onClick, extraValidations, children, childrenHeader, showIcon, showFormHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, listBtnConfig, submitBtnLabel, submitBtnLabelSubmiting, withFormWrapper, btnGroupDirection, withSubmitBtn }: Props$h<T>) => react_jsx_runtime.JSX.Element;
|
|
243
245
|
|
|
244
246
|
declare const DynamicFormExample: () => react_jsx_runtime.JSX.Element;
|
|
245
247
|
declare const mockFields: Array<FieldProps | FieldProps[]>;
|
package/dist/index.mjs
CHANGED
|
@@ -15,6 +15,7 @@ import * as PopoverPrimitive from '@radix-ui/react-popover';
|
|
|
15
15
|
import 'react-color-palette/css';
|
|
16
16
|
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
|
17
17
|
import * as LabelPrimitive from '@radix-ui/react-label';
|
|
18
|
+
import { Label as Label$1 } from '@radix-ui/react-label';
|
|
18
19
|
import * as SeparatorPrimitive from '@radix-ui/react-separator';
|
|
19
20
|
import { OTPInput, OTPInputContext } from 'input-otp';
|
|
20
21
|
import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
|
|
@@ -196,7 +197,9 @@ var entitiesToGroupedOption = (data, optionValue = "name") => {
|
|
|
196
197
|
};
|
|
197
198
|
var handleOnChage = (event, input, field) => {
|
|
198
199
|
if (event) field?.onChange(event);
|
|
199
|
-
|
|
200
|
+
const data = input.form?.getValues();
|
|
201
|
+
input.onChange?.(event, data);
|
|
202
|
+
if (input.onAnyFieldChange) input.onAnyFieldChange?.(data);
|
|
200
203
|
};
|
|
201
204
|
var isValidField = (input, form, defaultValue) => {
|
|
202
205
|
const value = defaultValue ?? form.getValues(input.name);
|
|
@@ -209,7 +212,7 @@ var isValidField = (input, form, defaultValue) => {
|
|
|
209
212
|
};
|
|
210
213
|
|
|
211
214
|
// src/components/custom/form/inputs/base/definitions.ts
|
|
212
|
-
var flattenFields = (fields) => {
|
|
215
|
+
var flattenFields = (fields, onAnyFieldChange) => {
|
|
213
216
|
const result = [];
|
|
214
217
|
for (const field of fields) {
|
|
215
218
|
if (Array.isArray(field)) {
|
|
@@ -217,6 +220,7 @@ var flattenFields = (fields) => {
|
|
|
217
220
|
} else if (field.fields) {
|
|
218
221
|
result.push(...flattenFields(field.fields));
|
|
219
222
|
} else {
|
|
223
|
+
if (onAnyFieldChange) field.onAnyFieldChange = (data) => onAnyFieldChange(data);
|
|
220
224
|
result.push(field);
|
|
221
225
|
}
|
|
222
226
|
}
|
|
@@ -4523,34 +4527,40 @@ var FieldKeyValueList = ({ form, input, isSubmitting }) => {
|
|
|
4523
4527
|
return /* @__PURE__ */ jsxs(FormItem, { className: input.className, children: [
|
|
4524
4528
|
/* @__PURE__ */ jsx(FormLabel, { children: /* @__PURE__ */ jsx("b", { children: input.label }) }),
|
|
4525
4529
|
/* @__PURE__ */ jsx(FormMessage, {}),
|
|
4526
|
-
/* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 rounded-xl
|
|
4530
|
+
/* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 rounded-xl ", children: [
|
|
4527
4531
|
pairs.length === 0 && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "No pairs have been added yet." }),
|
|
4528
4532
|
pairs.map((pair, index) => /* @__PURE__ */ jsxs(
|
|
4529
4533
|
"div",
|
|
4530
4534
|
{
|
|
4531
|
-
className: "flex gap-2 items-center",
|
|
4535
|
+
className: "flex flex-row w-full gap-2 items-center py-0.5",
|
|
4532
4536
|
children: [
|
|
4533
|
-
/* @__PURE__ */
|
|
4534
|
-
|
|
4535
|
-
{
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4537
|
+
/* @__PURE__ */ jsxs(ButtonGroup, { className: "w-full", children: [
|
|
4538
|
+
/* @__PURE__ */ jsx(ButtonGroupText, { asChild: true, children: /* @__PURE__ */ jsx(Label$1, { htmlFor: "key", children: "Key" }) }),
|
|
4539
|
+
/* @__PURE__ */ jsx(InputGroup, { children: /* @__PURE__ */ jsx(
|
|
4540
|
+
InputGroupInput,
|
|
4541
|
+
{
|
|
4542
|
+
placeholder: "Key",
|
|
4543
|
+
value: pair.key,
|
|
4544
|
+
disabled: isSubmitting,
|
|
4545
|
+
onChange: (e) => handleChange(index, "key", e.target.value),
|
|
4546
|
+
className: "flex-1"
|
|
4547
|
+
}
|
|
4548
|
+
) })
|
|
4549
|
+
] }),
|
|
4550
|
+
/* @__PURE__ */ jsxs(ButtonGroup, { className: "w-full", children: [
|
|
4551
|
+
/* @__PURE__ */ jsx(ButtonGroupText, { asChild: true, children: /* @__PURE__ */ jsx(Label$1, { htmlFor: "value", children: "Value" }) }),
|
|
4552
|
+
/* @__PURE__ */ jsx(InputGroup, { children: /* @__PURE__ */ jsx(
|
|
4553
|
+
InputGroupInput,
|
|
4554
|
+
{
|
|
4555
|
+
placeholder: "Value",
|
|
4556
|
+
value: pair.value,
|
|
4557
|
+
disabled: isSubmitting,
|
|
4558
|
+
onChange: (e) => handleChange(index, "value", e.target.value),
|
|
4559
|
+
className: "flex-1"
|
|
4560
|
+
}
|
|
4561
|
+
) })
|
|
4562
|
+
] }),
|
|
4563
|
+
input.isRemovebleOption && /* @__PURE__ */ jsx(
|
|
4554
4564
|
Button,
|
|
4555
4565
|
{
|
|
4556
4566
|
type: "button",
|
|
@@ -4730,9 +4740,9 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
|
|
|
4730
4740
|
if (isNumberField) {
|
|
4731
4741
|
value = e.target.value === "" ? "" : Number(e.target.value);
|
|
4732
4742
|
}
|
|
4733
|
-
handleOnChage(value, input, field);
|
|
4734
4743
|
field.onChange(value);
|
|
4735
4744
|
isValidField(input, form);
|
|
4745
|
+
handleOnChage(value.trimStart(), input, field);
|
|
4736
4746
|
}
|
|
4737
4747
|
}
|
|
4738
4748
|
),
|
|
@@ -4887,7 +4897,7 @@ var FieldRepeater = ({ form, input, isSubmitting }) => {
|
|
|
4887
4897
|
fields.map((item, index) => /* @__PURE__ */ jsxs(
|
|
4888
4898
|
"div",
|
|
4889
4899
|
{
|
|
4890
|
-
className: "border p-3 rounded-md flex flex-col gap-3",
|
|
4900
|
+
className: "border p-3 rounded-md flex flex-col gap-4 py-3",
|
|
4891
4901
|
children: [
|
|
4892
4902
|
input.repeaterFields?.map((fieldGroup, groupIndex) => {
|
|
4893
4903
|
const group = Array.isArray(fieldGroup) ? fieldGroup : [fieldGroup];
|
|
@@ -5549,7 +5559,7 @@ var FieldStringValueList = ({ form, input, isSubmitting }) => {
|
|
|
5549
5559
|
items.map((value, index) => /* @__PURE__ */ jsxs(
|
|
5550
5560
|
"div",
|
|
5551
5561
|
{
|
|
5552
|
-
className: "flex gap-
|
|
5562
|
+
className: "flex items-center gap-4 py-2",
|
|
5553
5563
|
children: [
|
|
5554
5564
|
/* @__PURE__ */ jsx(
|
|
5555
5565
|
Input,
|
|
@@ -6071,6 +6081,7 @@ var DynamicForm = ({
|
|
|
6071
6081
|
fields,
|
|
6072
6082
|
readOnly = false,
|
|
6073
6083
|
record = {},
|
|
6084
|
+
onAnyFieldChange,
|
|
6074
6085
|
onSubmit,
|
|
6075
6086
|
onClick,
|
|
6076
6087
|
extraValidations,
|
|
@@ -6091,7 +6102,7 @@ var DynamicForm = ({
|
|
|
6091
6102
|
}) => {
|
|
6092
6103
|
const [isPending, startTransition] = useTransition();
|
|
6093
6104
|
const schema = useMemo(() => {
|
|
6094
|
-
const allFields = flattenFields(fields);
|
|
6105
|
+
const allFields = flattenFields(fields, onAnyFieldChange);
|
|
6095
6106
|
return getDynamicSchema(allFields, extraValidations);
|
|
6096
6107
|
}, [fields, extraValidations]);
|
|
6097
6108
|
const resolver = zodResolver(schema);
|