shadcn-zod-formkit 1.26.0 → 1.26.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 +97 -69
- 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 +96 -69
- package/dist/index.mjs.map +1 -1
- package/dist/shadcn-zod-formkit-1.26.1.tgz +0 -0
- package/package.json +1 -1
- package/dist/shadcn-zod-formkit-1.26.0.tgz +0 -0
package/dist/index.cjs
CHANGED
|
@@ -233,9 +233,17 @@ var entitiesToGroupedOption = (data, optionValue = "name") => {
|
|
|
233
233
|
return entities;
|
|
234
234
|
};
|
|
235
235
|
var handleOnChage = (event, input, field) => {
|
|
236
|
-
console.log("\u{1F680} ~ handleOnChage ~ event:", event);
|
|
237
236
|
if (event) field?.onChange(event);
|
|
238
|
-
input.onChange?.(event);
|
|
237
|
+
input.onChange?.(event, input.form?.getValues());
|
|
238
|
+
};
|
|
239
|
+
var isValidField = (input, form, defaultValue) => {
|
|
240
|
+
const value = defaultValue ?? form.getValues(input.name);
|
|
241
|
+
const fieldState = form.getFieldState(input.name);
|
|
242
|
+
if (input.zodType) {
|
|
243
|
+
const result = input.zodType.safeParse(value);
|
|
244
|
+
return result.success;
|
|
245
|
+
}
|
|
246
|
+
return !fieldState.error && value !== void 0 && value !== "";
|
|
239
247
|
};
|
|
240
248
|
|
|
241
249
|
// src/components/custom/form/inputs/base/definitions.ts
|
|
@@ -4204,60 +4212,82 @@ function cleanEscapedString(input) {
|
|
|
4204
4212
|
var DateInput = class extends BaseInput {
|
|
4205
4213
|
render() {
|
|
4206
4214
|
const { input, form, isSubmitting } = this;
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4215
|
+
return /* @__PURE__ */ jsxRuntime.jsx(FieldTimeInput, { input, form, isSubmitting });
|
|
4216
|
+
}
|
|
4217
|
+
};
|
|
4218
|
+
var FieldTimeInput = ({ form, input, isSubmitting }) => {
|
|
4219
|
+
const [isValid2, setIsValid] = React3.useState(isValidField(input, form));
|
|
4220
|
+
const groupConfig = input.inputGroupConfig;
|
|
4221
|
+
const autoValidate = groupConfig?.autoValidIcons ?? input.zodType ? true : false;
|
|
4222
|
+
const iconValidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleCheck, { style: { color: "#00bf3e" } });
|
|
4223
|
+
const iconInvalidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleX, { style: { color: "#ff8080" } });
|
|
4224
|
+
const iconLoadingState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "animate-spin", style: { color: "#1e90ff" } });
|
|
4225
|
+
const iconsRight = groupConfig?.iconsRight ?? [];
|
|
4226
|
+
groupConfig?.iconsLeft ?? [];
|
|
4227
|
+
groupConfig?.textLeft;
|
|
4228
|
+
const textRight = groupConfig?.textRight;
|
|
4229
|
+
const formField = /* @__PURE__ */ jsxRuntime.jsx(
|
|
4230
|
+
FormField,
|
|
4231
|
+
{
|
|
4232
|
+
control: form.control,
|
|
4233
|
+
name: input.name,
|
|
4234
|
+
render: ({ field }) => {
|
|
4235
|
+
setIsValid(isValidField(input, form));
|
|
4236
|
+
const [date, setDate] = React3__namespace.useState(
|
|
4237
|
+
field.value ? new Date(field.value) : void 0
|
|
4238
|
+
);
|
|
4239
|
+
React3__namespace.useEffect(() => {
|
|
4240
|
+
if (field.value && !date) {
|
|
4241
|
+
setDate(new Date(field.value));
|
|
4242
|
+
setIsValid(isValidField(input, form));
|
|
4243
|
+
}
|
|
4244
|
+
}, [field.value]);
|
|
4245
|
+
const handleSelect = (selectedDate) => {
|
|
4246
|
+
setDate(selectedDate);
|
|
4247
|
+
handleOnChage(selectedDate, input, field);
|
|
4248
|
+
};
|
|
4249
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { children: [
|
|
4250
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
|
|
4251
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Popover, { children: [
|
|
4252
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(InputGroup, { className: "flex flex-row gap-1", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4253
|
+
Button,
|
|
4254
|
+
{
|
|
4255
|
+
variant: "outline",
|
|
4256
|
+
className: cn(
|
|
4257
|
+
"w-full justify-start text-left py-0.5 ",
|
|
4258
|
+
!date && "text-muted-foreground"
|
|
4259
|
+
),
|
|
4260
|
+
children: [
|
|
4261
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 items-center gap-1 justify-start text-left ", children: [
|
|
4237
4262
|
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.CalendarIcon, {}),
|
|
4238
4263
|
date ? format(date, "PPP") : /* @__PURE__ */ jsxRuntime.jsx("span", { children: input.placeHolder ?? "Fecha" })
|
|
4239
|
-
]
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4264
|
+
] }),
|
|
4265
|
+
(iconsRight.length > 0 || textRight || autoValidate) && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4266
|
+
textRight && /* @__PURE__ */ jsxRuntime.jsx(InputGroupText, { children: textRight }),
|
|
4267
|
+
iconsRight.map((IconComponent, index) => /* @__PURE__ */ jsxRuntime.jsx(IconComponent, { size: 24, className: "w-6! h-6!" }, index)),
|
|
4268
|
+
autoValidate && /* @__PURE__ */ jsxRuntime.jsx("div", { children: isSubmitting ? iconLoadingState : isValid2 ? iconValidState : iconInvalidState })
|
|
4269
|
+
] })
|
|
4270
|
+
]
|
|
4271
|
+
}
|
|
4272
|
+
) }) }) }),
|
|
4273
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverContent, { className: "w-auto p-0", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4274
|
+
Calendar,
|
|
4275
|
+
{
|
|
4276
|
+
mode: "single",
|
|
4277
|
+
selected: date,
|
|
4278
|
+
onSelect: handleSelect,
|
|
4279
|
+
initialFocus: true
|
|
4280
|
+
}
|
|
4281
|
+
) })
|
|
4282
|
+
] }),
|
|
4283
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormDescription, { children: input.description }),
|
|
4284
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormMessage, {})
|
|
4285
|
+
] });
|
|
4286
|
+
}
|
|
4287
|
+
},
|
|
4288
|
+
input.name
|
|
4289
|
+
);
|
|
4290
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: formField });
|
|
4261
4291
|
};
|
|
4262
4292
|
var DateTimeInput = class extends BaseInput {
|
|
4263
4293
|
render() {
|
|
@@ -4267,7 +4297,7 @@ var DateTimeInput = class extends BaseInput {
|
|
|
4267
4297
|
};
|
|
4268
4298
|
var FieldDateTimeInput = ({ form, input, isSubmitting }) => {
|
|
4269
4299
|
const groupConfig = input.inputGroupConfig;
|
|
4270
|
-
const autoValidate = groupConfig?.autoValidIcons;
|
|
4300
|
+
const autoValidate = groupConfig?.autoValidIcons ?? input.zodType ? true : false;
|
|
4271
4301
|
const iconValidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleCheck, { style: { color: "#00bf3e" } });
|
|
4272
4302
|
const iconInvalidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleX, { style: { color: "#ff8080" } });
|
|
4273
4303
|
const iconLoadingState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "animate-spin", style: { color: "#1e90ff" } });
|
|
@@ -4318,7 +4348,7 @@ var FieldDateTimeInput = ({ form, input, isSubmitting }) => {
|
|
|
4318
4348
|
),
|
|
4319
4349
|
(iconsRight.length > 0 || textRight || autoValidate) && /* @__PURE__ */ jsxRuntime.jsxs(InputGroupAddon, { align: "inline-end", children: [
|
|
4320
4350
|
textRight && /* @__PURE__ */ jsxRuntime.jsx(InputGroupText, { children: textRight }),
|
|
4321
|
-
iconsRight.map((IconComponent, index) => /* @__PURE__ */ jsxRuntime.jsx(IconComponent, { size:
|
|
4351
|
+
iconsRight.map((IconComponent, index) => /* @__PURE__ */ jsxRuntime.jsx(IconComponent, { size: 24 }, index)),
|
|
4322
4352
|
autoValidate && /* @__PURE__ */ jsxRuntime.jsx("div", { children: isSubmitting ? iconLoadingState : isValid2 ? iconValidState : iconInvalidState })
|
|
4323
4353
|
] })
|
|
4324
4354
|
] }) }),
|
|
@@ -4696,7 +4726,7 @@ var TextInputGroup = class extends BaseInput {
|
|
|
4696
4726
|
var FieldTextGroup = ({ form, input, isSubmitting }) => {
|
|
4697
4727
|
const groupConfig = input.inputGroupConfig;
|
|
4698
4728
|
const infoTooltip = input?.infoTooltip;
|
|
4699
|
-
const autoValidate = groupConfig?.autoValidIcons;
|
|
4729
|
+
const autoValidate = groupConfig?.autoValidIcons ?? input.zodType ? true : false;
|
|
4700
4730
|
const iconValidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleCheck, { style: { color: "#00bf3e" } });
|
|
4701
4731
|
const iconInvalidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleX, { style: { color: "#ff8080" } });
|
|
4702
4732
|
const iconLoadingState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "animate-spin", style: { color: "#1e90ff" } });
|
|
@@ -4704,11 +4734,7 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
|
|
|
4704
4734
|
const iconsLeft = groupConfig?.iconsLeft ?? [];
|
|
4705
4735
|
const textLeft = groupConfig?.textLeft;
|
|
4706
4736
|
const textRight = groupConfig?.textRight;
|
|
4707
|
-
const [isValid2, setIsValid] = React3.useState(()
|
|
4708
|
-
const value = form.getValues(input.name);
|
|
4709
|
-
const fieldState = form.getFieldState(input.name);
|
|
4710
|
-
return !fieldState.error && value !== void 0 && value !== "";
|
|
4711
|
-
});
|
|
4737
|
+
const [isValid2, setIsValid] = React3.useState(isValidField(input, form));
|
|
4712
4738
|
const [showPassword, setShowPassword] = React3.useState(false);
|
|
4713
4739
|
const isPasswordField = input.keyboardType === "password" /* PASSWORD */;
|
|
4714
4740
|
const isNumberField = input.keyboardType === "number" /* NUMBER */;
|
|
@@ -4718,9 +4744,8 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
|
|
|
4718
4744
|
{
|
|
4719
4745
|
control: form.control,
|
|
4720
4746
|
name: input.name,
|
|
4721
|
-
render: ({ field
|
|
4722
|
-
|
|
4723
|
-
if (validNow !== isValid2) setIsValid(validNow);
|
|
4747
|
+
render: ({ field }) => {
|
|
4748
|
+
setIsValid(isValidField(input, form));
|
|
4724
4749
|
return /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: input.className, children: [
|
|
4725
4750
|
/* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
|
|
4726
4751
|
/* @__PURE__ */ jsxRuntime.jsx(FormControl, { className: "shadow-lg", children: /* @__PURE__ */ jsxRuntime.jsxs(InputGroup, { children: [
|
|
@@ -4745,6 +4770,7 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
|
|
|
4745
4770
|
}
|
|
4746
4771
|
handleOnChage(value, input, field);
|
|
4747
4772
|
field.onChange(value);
|
|
4773
|
+
isValidField(input, form);
|
|
4748
4774
|
}
|
|
4749
4775
|
}
|
|
4750
4776
|
),
|
|
@@ -5822,10 +5848,10 @@ var FieldText = ({ input, form, isSubmitting }) => {
|
|
|
5822
5848
|
var TimeInput = class extends BaseInput {
|
|
5823
5849
|
render() {
|
|
5824
5850
|
const { input, form, isSubmitting } = this;
|
|
5825
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
5851
|
+
return /* @__PURE__ */ jsxRuntime.jsx(FieldTimeInput2, { input, form, isSubmitting });
|
|
5826
5852
|
}
|
|
5827
5853
|
};
|
|
5828
|
-
var
|
|
5854
|
+
var FieldTimeInput2 = ({ form, input, isSubmitting }) => {
|
|
5829
5855
|
const groupConfig = input.inputGroupConfig;
|
|
5830
5856
|
const autoValidate = groupConfig?.autoValidIcons;
|
|
5831
5857
|
const iconValidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleCheck, { style: { color: "#00bf3e" } });
|
|
@@ -5933,6 +5959,7 @@ var inputMap = {
|
|
|
5933
5959
|
};
|
|
5934
5960
|
var InputFactory = class {
|
|
5935
5961
|
static create(input, form, isSubmitting = false) {
|
|
5962
|
+
input.form = form;
|
|
5936
5963
|
const inputType = input.inputType ?? "text" /* TEXT */;
|
|
5937
5964
|
const InputClass = inputMap[inputType] ?? TextInput;
|
|
5938
5965
|
const instance = new InputClass(input, form, isSubmitting);
|
|
@@ -6113,7 +6140,7 @@ var DynamicForm = ({
|
|
|
6113
6140
|
});
|
|
6114
6141
|
React3.useEffect(() => {
|
|
6115
6142
|
form.reset(initialValues);
|
|
6116
|
-
}, [
|
|
6143
|
+
}, []);
|
|
6117
6144
|
const handleSubmit = (data) => {
|
|
6118
6145
|
if (readOnly) return;
|
|
6119
6146
|
startTransition(() => {
|
|
@@ -6585,7 +6612,7 @@ exports.FieldSimpleCheckList = FieldSimpleCheckList;
|
|
|
6585
6612
|
exports.FieldSlider = FieldSlider;
|
|
6586
6613
|
exports.FieldStringValueList = FieldStringValueList;
|
|
6587
6614
|
exports.FieldTextGroup = FieldTextGroup;
|
|
6588
|
-
exports.FieldTimeInput =
|
|
6615
|
+
exports.FieldTimeInput = FieldTimeInput2;
|
|
6589
6616
|
exports.FieldTitle = FieldTitle;
|
|
6590
6617
|
exports.FileInput = FileInput;
|
|
6591
6618
|
exports.FileMultiUploadInput = FileMultiUploadInput;
|
|
@@ -6683,6 +6710,7 @@ exports.getDynamicSchema = getDynamicSchema;
|
|
|
6683
6710
|
exports.getFieldLabel = getFieldLabel;
|
|
6684
6711
|
exports.handleOnChage = handleOnChage;
|
|
6685
6712
|
exports.inputFieldComp = inputFieldComp;
|
|
6713
|
+
exports.isValidField = isValidField;
|
|
6686
6714
|
exports.mockFields = mockFields;
|
|
6687
6715
|
exports.useFormField = useFormField;
|
|
6688
6716
|
exports.validationMessages = validationMessages;
|