@rachelallyson/hero-hook-form 2.1.3 → 2.2.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/CHANGELOG.md +46 -4
- package/dist/index.d.ts +1073 -16
- package/dist/index.js +238 -137
- package/dist/react/index.d.ts +1073 -16
- package/dist/react/index.js +238 -137
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
// src/components/Form.tsx
|
|
9
|
-
import
|
|
9
|
+
import React17 from "react";
|
|
10
10
|
import { Button as Button3 } from "@heroui/react";
|
|
11
11
|
|
|
12
12
|
// src/hooks/useFormHelper.ts
|
|
@@ -75,7 +75,7 @@ function useFormHelper({
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
// src/components/FormField.tsx
|
|
78
|
-
import
|
|
78
|
+
import React16 from "react";
|
|
79
79
|
import { useWatch as useWatch3 } from "react-hook-form";
|
|
80
80
|
|
|
81
81
|
// src/fields/CheckboxField.tsx
|
|
@@ -246,13 +246,30 @@ function ConditionalField({
|
|
|
246
246
|
));
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
// src/fields/
|
|
249
|
+
// src/fields/ContentField.tsx
|
|
250
250
|
import React4 from "react";
|
|
251
|
+
function ContentField({
|
|
252
|
+
config,
|
|
253
|
+
form,
|
|
254
|
+
submissionState
|
|
255
|
+
}) {
|
|
256
|
+
if (config.render) {
|
|
257
|
+
return /* @__PURE__ */ React4.createElement("div", { className: config.className }, config.render({
|
|
258
|
+
errors: form.formState.errors,
|
|
259
|
+
form,
|
|
260
|
+
isSubmitting: submissionState.isSubmitting
|
|
261
|
+
}));
|
|
262
|
+
}
|
|
263
|
+
return /* @__PURE__ */ React4.createElement("div", { className: config.className }, config.title && /* @__PURE__ */ React4.createElement("h3", { className: "text-lg font-semibold text-foreground mb-2" }, config.title), config.description && /* @__PURE__ */ React4.createElement("p", { className: "text-sm text-muted-foreground" }, config.description));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// src/fields/DateField.tsx
|
|
267
|
+
import React5 from "react";
|
|
251
268
|
import { Controller as Controller2 } from "react-hook-form";
|
|
252
269
|
function CoercedDateInput(props) {
|
|
253
270
|
const { dateProps, description, disabled, errorMessage, field: field2, label } = props;
|
|
254
271
|
const defaults = useHeroHookFormDefaults();
|
|
255
|
-
return /* @__PURE__ */
|
|
272
|
+
return /* @__PURE__ */ React5.createElement(
|
|
256
273
|
DateInput,
|
|
257
274
|
{
|
|
258
275
|
...defaults.dateInput,
|
|
@@ -280,12 +297,12 @@ function DateField(props) {
|
|
|
280
297
|
rules,
|
|
281
298
|
transform
|
|
282
299
|
} = props;
|
|
283
|
-
return /* @__PURE__ */
|
|
300
|
+
return /* @__PURE__ */ React5.createElement(
|
|
284
301
|
Controller2,
|
|
285
302
|
{
|
|
286
303
|
control,
|
|
287
304
|
name,
|
|
288
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
305
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React5.createElement("div", { className }, /* @__PURE__ */ React5.createElement(
|
|
289
306
|
CoercedDateInput,
|
|
290
307
|
{
|
|
291
308
|
dateProps,
|
|
@@ -305,7 +322,7 @@ function DateField(props) {
|
|
|
305
322
|
}
|
|
306
323
|
|
|
307
324
|
// src/fields/DynamicSectionField.tsx
|
|
308
|
-
import
|
|
325
|
+
import React6 from "react";
|
|
309
326
|
import { useWatch as useWatch2, useFormContext as useFormContext2 } from "react-hook-form";
|
|
310
327
|
function DynamicSectionField({
|
|
311
328
|
className,
|
|
@@ -319,7 +336,7 @@ function DynamicSectionField({
|
|
|
319
336
|
if (!shouldShow) {
|
|
320
337
|
return null;
|
|
321
338
|
}
|
|
322
|
-
return /* @__PURE__ */
|
|
339
|
+
return /* @__PURE__ */ React6.createElement("div", { className }, (title || description) && /* @__PURE__ */ React6.createElement("div", { className: "mb-6" }, title && /* @__PURE__ */ React6.createElement("h3", { className: "text-lg font-semibold text-gray-900 mb-2" }, title), description && /* @__PURE__ */ React6.createElement("p", { className: "text-sm text-gray-600" }, description)), /* @__PURE__ */ React6.createElement("div", { className: "space-y-4" }, fields.map((fieldConfig, index) => /* @__PURE__ */ React6.createElement(
|
|
323
340
|
FormField,
|
|
324
341
|
{
|
|
325
342
|
key: `${fieldConfig.name}-${index}`,
|
|
@@ -336,7 +353,7 @@ function DynamicSectionField({
|
|
|
336
353
|
}
|
|
337
354
|
|
|
338
355
|
// src/fields/FieldArrayField.tsx
|
|
339
|
-
import
|
|
356
|
+
import React7 from "react";
|
|
340
357
|
import { useFieldArray, useFormContext as useFormContext3 } from "react-hook-form";
|
|
341
358
|
import { Button as Button2 } from "@heroui/react";
|
|
342
359
|
function FieldArrayField({
|
|
@@ -384,13 +401,13 @@ function FieldArrayField({
|
|
|
384
401
|
remove(index);
|
|
385
402
|
}
|
|
386
403
|
};
|
|
387
|
-
return /* @__PURE__ */
|
|
404
|
+
return /* @__PURE__ */ React7.createElement("div", { className }, /* @__PURE__ */ React7.createElement("div", { className: "space-y-4" }, fields.map((field2, index) => /* @__PURE__ */ React7.createElement(
|
|
388
405
|
"div",
|
|
389
406
|
{
|
|
390
407
|
key: field2.id,
|
|
391
408
|
className: "border border-gray-200 rounded-lg p-4 space-y-4"
|
|
392
409
|
},
|
|
393
|
-
/* @__PURE__ */
|
|
410
|
+
/* @__PURE__ */ React7.createElement("div", { className: "flex justify-between items-center" }, /* @__PURE__ */ React7.createElement("h4", { className: "text-sm font-medium text-gray-700" }, config.label, " #", index + 1), canRemove && /* @__PURE__ */ React7.createElement(
|
|
394
411
|
Button2,
|
|
395
412
|
{
|
|
396
413
|
size: "sm",
|
|
@@ -402,7 +419,7 @@ function FieldArrayField({
|
|
|
402
419
|
},
|
|
403
420
|
removeButtonText
|
|
404
421
|
)),
|
|
405
|
-
/* @__PURE__ */
|
|
422
|
+
/* @__PURE__ */ React7.createElement("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4" }, fieldConfigs.map((fieldConfig) => /* @__PURE__ */ React7.createElement(
|
|
406
423
|
FormField,
|
|
407
424
|
{
|
|
408
425
|
key: `${fieldConfig.name}-${index}`,
|
|
@@ -419,7 +436,7 @@ function FieldArrayField({
|
|
|
419
436
|
}
|
|
420
437
|
}
|
|
421
438
|
)))
|
|
422
|
-
)), canAdd && /* @__PURE__ */
|
|
439
|
+
)), canAdd && /* @__PURE__ */ React7.createElement(
|
|
423
440
|
Button2,
|
|
424
441
|
{
|
|
425
442
|
variant: "bordered",
|
|
@@ -428,7 +445,7 @@ function FieldArrayField({
|
|
|
428
445
|
className: "w-full"
|
|
429
446
|
},
|
|
430
447
|
addButtonText
|
|
431
|
-
), fields.length === 0 && /* @__PURE__ */
|
|
448
|
+
), fields.length === 0 && /* @__PURE__ */ React7.createElement("div", { className: "text-center py-8 text-gray-500" }, /* @__PURE__ */ React7.createElement("p", null, "No ", config.label?.toLowerCase(), " added yet."), /* @__PURE__ */ React7.createElement(
|
|
432
449
|
Button2,
|
|
433
450
|
{
|
|
434
451
|
variant: "bordered",
|
|
@@ -441,7 +458,7 @@ function FieldArrayField({
|
|
|
441
458
|
}
|
|
442
459
|
|
|
443
460
|
// src/fields/FileField.tsx
|
|
444
|
-
import
|
|
461
|
+
import React8 from "react";
|
|
445
462
|
import { Controller as Controller3 } from "react-hook-form";
|
|
446
463
|
function CoercedFileInput(props) {
|
|
447
464
|
const {
|
|
@@ -455,7 +472,7 @@ function CoercedFileInput(props) {
|
|
|
455
472
|
multiple
|
|
456
473
|
} = props;
|
|
457
474
|
const defaults = useHeroHookFormDefaults();
|
|
458
|
-
return /* @__PURE__ */
|
|
475
|
+
return /* @__PURE__ */ React8.createElement(
|
|
459
476
|
Input,
|
|
460
477
|
{
|
|
461
478
|
...defaults.input,
|
|
@@ -491,12 +508,12 @@ function FileField(props) {
|
|
|
491
508
|
rules,
|
|
492
509
|
transform
|
|
493
510
|
} = props;
|
|
494
|
-
return /* @__PURE__ */
|
|
511
|
+
return /* @__PURE__ */ React8.createElement(
|
|
495
512
|
Controller3,
|
|
496
513
|
{
|
|
497
514
|
control,
|
|
498
515
|
name,
|
|
499
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
516
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React8.createElement("div", { className }, /* @__PURE__ */ React8.createElement(
|
|
500
517
|
CoercedFileInput,
|
|
501
518
|
{
|
|
502
519
|
accept,
|
|
@@ -518,7 +535,7 @@ function FileField(props) {
|
|
|
518
535
|
}
|
|
519
536
|
|
|
520
537
|
// src/fields/FontPickerField.tsx
|
|
521
|
-
import
|
|
538
|
+
import React9 from "react";
|
|
522
539
|
import { Controller as Controller4 } from "react-hook-form";
|
|
523
540
|
var FontPickerComponent = null;
|
|
524
541
|
var fontPickerLoaded = false;
|
|
@@ -535,12 +552,12 @@ function FontPickerField(props) {
|
|
|
535
552
|
name,
|
|
536
553
|
rules
|
|
537
554
|
} = props;
|
|
538
|
-
const [fontPickerState, setFontPickerState] =
|
|
555
|
+
const [fontPickerState, setFontPickerState] = React9.useState({
|
|
539
556
|
component: FontPickerComponent,
|
|
540
557
|
error: null,
|
|
541
558
|
loading: false
|
|
542
559
|
});
|
|
543
|
-
|
|
560
|
+
React9.useEffect(() => {
|
|
544
561
|
if (fontPickerLoaded && FontPickerComponent) {
|
|
545
562
|
setFontPickerState({
|
|
546
563
|
component: FontPickerComponent,
|
|
@@ -598,17 +615,17 @@ function FontPickerField(props) {
|
|
|
598
615
|
void loadFontPicker();
|
|
599
616
|
}, []);
|
|
600
617
|
if (fontPickerState.loading) {
|
|
601
|
-
return /* @__PURE__ */
|
|
618
|
+
return /* @__PURE__ */ React9.createElement("div", { className }, /* @__PURE__ */ React9.createElement("div", { className: "space-y-2" }, label && /* @__PURE__ */ React9.createElement("label", { className: "block text-sm font-medium text-foreground" }, label), description && /* @__PURE__ */ React9.createElement("p", { className: "text-sm text-muted-foreground" }, description), /* @__PURE__ */ React9.createElement("div", { className: "p-4 border border-default-200 bg-default-50 rounded-medium" }, /* @__PURE__ */ React9.createElement("p", { className: "text-default-600 text-sm" }, "Loading font picker..."))));
|
|
602
619
|
}
|
|
603
620
|
if (!fontPickerState.component) {
|
|
604
|
-
return /* @__PURE__ */
|
|
621
|
+
return /* @__PURE__ */ React9.createElement("div", { className }, /* @__PURE__ */ React9.createElement("div", { className: "space-y-2" }, label && /* @__PURE__ */ React9.createElement("label", { className: "block text-sm font-medium text-foreground" }, label), description && /* @__PURE__ */ React9.createElement("p", { className: "text-sm text-muted-foreground" }, description), /* @__PURE__ */ React9.createElement("div", { className: "p-4 border border-warning-200 bg-warning-50 rounded-medium" }, /* @__PURE__ */ React9.createElement("p", { className: "text-warning-800 text-sm" }, "Font picker requires the @rachelallyson/heroui-font-picker package. Please install it as a peer dependency for advanced font selection features."))));
|
|
605
622
|
}
|
|
606
|
-
return /* @__PURE__ */
|
|
623
|
+
return /* @__PURE__ */ React9.createElement(
|
|
607
624
|
Controller4,
|
|
608
625
|
{
|
|
609
626
|
control,
|
|
610
627
|
name,
|
|
611
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
628
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React9.createElement(
|
|
612
629
|
fontPickerState.component,
|
|
613
630
|
{
|
|
614
631
|
label,
|
|
@@ -627,12 +644,12 @@ function FontPickerField(props) {
|
|
|
627
644
|
}
|
|
628
645
|
|
|
629
646
|
// src/fields/InputField.tsx
|
|
630
|
-
import
|
|
647
|
+
import React10 from "react";
|
|
631
648
|
import { Controller as Controller5 } from "react-hook-form";
|
|
632
649
|
function CoercedInput(props) {
|
|
633
650
|
const { description, disabled, errorMessage, field: field2, inputProps, label } = props;
|
|
634
651
|
const defaults = useHeroHookFormDefaults();
|
|
635
|
-
return /* @__PURE__ */
|
|
652
|
+
return /* @__PURE__ */ React10.createElement(
|
|
636
653
|
Input,
|
|
637
654
|
{
|
|
638
655
|
...defaults.input,
|
|
@@ -648,7 +665,7 @@ function CoercedInput(props) {
|
|
|
648
665
|
}
|
|
649
666
|
);
|
|
650
667
|
}
|
|
651
|
-
var InputField =
|
|
668
|
+
var InputField = React10.memo(
|
|
652
669
|
(props) => {
|
|
653
670
|
const {
|
|
654
671
|
className,
|
|
@@ -661,12 +678,12 @@ var InputField = React9.memo(
|
|
|
661
678
|
rules,
|
|
662
679
|
transform
|
|
663
680
|
} = props;
|
|
664
|
-
return /* @__PURE__ */
|
|
681
|
+
return /* @__PURE__ */ React10.createElement(
|
|
665
682
|
Controller5,
|
|
666
683
|
{
|
|
667
684
|
control,
|
|
668
685
|
name,
|
|
669
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
686
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React10.createElement("div", { className }, /* @__PURE__ */ React10.createElement(
|
|
670
687
|
CoercedInput,
|
|
671
688
|
{
|
|
672
689
|
description,
|
|
@@ -696,7 +713,7 @@ var InputField = React9.memo(
|
|
|
696
713
|
);
|
|
697
714
|
|
|
698
715
|
// src/fields/RadioGroupField.tsx
|
|
699
|
-
import
|
|
716
|
+
import React11 from "react";
|
|
700
717
|
import { Controller as Controller6 } from "react-hook-form";
|
|
701
718
|
function RadioGroupField(props) {
|
|
702
719
|
const {
|
|
@@ -711,12 +728,12 @@ function RadioGroupField(props) {
|
|
|
711
728
|
rules
|
|
712
729
|
} = props;
|
|
713
730
|
const defaults = useHeroHookFormDefaults();
|
|
714
|
-
return /* @__PURE__ */
|
|
731
|
+
return /* @__PURE__ */ React11.createElement(
|
|
715
732
|
Controller6,
|
|
716
733
|
{
|
|
717
734
|
control,
|
|
718
735
|
name,
|
|
719
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
736
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React11.createElement("div", { className }, /* @__PURE__ */ React11.createElement(
|
|
720
737
|
RadioGroup,
|
|
721
738
|
{
|
|
722
739
|
...defaults.radioGroup,
|
|
@@ -729,7 +746,7 @@ function RadioGroupField(props) {
|
|
|
729
746
|
onBlur: field2.onBlur,
|
|
730
747
|
onValueChange: (val) => field2.onChange(val)
|
|
731
748
|
},
|
|
732
|
-
options.map((opt) => /* @__PURE__ */
|
|
749
|
+
options.map((opt) => /* @__PURE__ */ React11.createElement(
|
|
733
750
|
Radio,
|
|
734
751
|
{
|
|
735
752
|
key: String(opt.value),
|
|
@@ -738,14 +755,14 @@ function RadioGroupField(props) {
|
|
|
738
755
|
},
|
|
739
756
|
opt.label
|
|
740
757
|
))
|
|
741
|
-
), fieldState.error?.message ? /* @__PURE__ */
|
|
758
|
+
), fieldState.error?.message ? /* @__PURE__ */ React11.createElement("p", { className: "text-tiny text-danger mt-1" }, fieldState.error.message) : null),
|
|
742
759
|
rules
|
|
743
760
|
}
|
|
744
761
|
);
|
|
745
762
|
}
|
|
746
763
|
|
|
747
764
|
// src/fields/SelectField.tsx
|
|
748
|
-
import
|
|
765
|
+
import React12 from "react";
|
|
749
766
|
import { Controller as Controller7 } from "react-hook-form";
|
|
750
767
|
function SelectField(props) {
|
|
751
768
|
const {
|
|
@@ -761,14 +778,14 @@ function SelectField(props) {
|
|
|
761
778
|
selectProps
|
|
762
779
|
} = props;
|
|
763
780
|
const defaults = useHeroHookFormDefaults();
|
|
764
|
-
return /* @__PURE__ */
|
|
781
|
+
return /* @__PURE__ */ React12.createElement(
|
|
765
782
|
Controller7,
|
|
766
783
|
{
|
|
767
784
|
control,
|
|
768
785
|
name,
|
|
769
786
|
render: ({ field: field2, fieldState }) => {
|
|
770
787
|
const selectedKey = field2.value;
|
|
771
|
-
return /* @__PURE__ */
|
|
788
|
+
return /* @__PURE__ */ React12.createElement("div", { className }, /* @__PURE__ */ React12.createElement(
|
|
772
789
|
Select,
|
|
773
790
|
{
|
|
774
791
|
...defaults.select,
|
|
@@ -786,7 +803,7 @@ function SelectField(props) {
|
|
|
786
803
|
field2.onChange(next);
|
|
787
804
|
}
|
|
788
805
|
},
|
|
789
|
-
options.map((opt) => /* @__PURE__ */
|
|
806
|
+
options.map((opt) => /* @__PURE__ */ React12.createElement(
|
|
790
807
|
SelectItem,
|
|
791
808
|
{
|
|
792
809
|
key: String(opt.value),
|
|
@@ -803,12 +820,12 @@ function SelectField(props) {
|
|
|
803
820
|
}
|
|
804
821
|
|
|
805
822
|
// src/fields/SliderField.tsx
|
|
806
|
-
import
|
|
823
|
+
import React13 from "react";
|
|
807
824
|
import { Controller as Controller8 } from "react-hook-form";
|
|
808
825
|
function CoercedSlider(props) {
|
|
809
826
|
const { description, disabled, errorMessage, field: field2, label, sliderProps } = props;
|
|
810
827
|
const defaults = useHeroHookFormDefaults();
|
|
811
|
-
return /* @__PURE__ */
|
|
828
|
+
return /* @__PURE__ */ React13.createElement(
|
|
812
829
|
Slider,
|
|
813
830
|
{
|
|
814
831
|
...defaults.slider,
|
|
@@ -836,12 +853,12 @@ function SliderField(props) {
|
|
|
836
853
|
sliderProps,
|
|
837
854
|
transform
|
|
838
855
|
} = props;
|
|
839
|
-
return /* @__PURE__ */
|
|
856
|
+
return /* @__PURE__ */ React13.createElement(
|
|
840
857
|
Controller8,
|
|
841
858
|
{
|
|
842
859
|
control,
|
|
843
860
|
name,
|
|
844
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
861
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React13.createElement("div", { className }, /* @__PURE__ */ React13.createElement(
|
|
845
862
|
CoercedSlider,
|
|
846
863
|
{
|
|
847
864
|
description,
|
|
@@ -861,7 +878,7 @@ function SliderField(props) {
|
|
|
861
878
|
}
|
|
862
879
|
|
|
863
880
|
// src/fields/SwitchField.tsx
|
|
864
|
-
import
|
|
881
|
+
import React14 from "react";
|
|
865
882
|
import { Controller as Controller9 } from "react-hook-form";
|
|
866
883
|
function SwitchField(props) {
|
|
867
884
|
const {
|
|
@@ -875,12 +892,12 @@ function SwitchField(props) {
|
|
|
875
892
|
switchProps
|
|
876
893
|
} = props;
|
|
877
894
|
const defaults = useHeroHookFormDefaults();
|
|
878
|
-
return /* @__PURE__ */
|
|
895
|
+
return /* @__PURE__ */ React14.createElement(
|
|
879
896
|
Controller9,
|
|
880
897
|
{
|
|
881
898
|
control,
|
|
882
899
|
name,
|
|
883
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
900
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React14.createElement("div", { className }, /* @__PURE__ */ React14.createElement(
|
|
884
901
|
Switch,
|
|
885
902
|
{
|
|
886
903
|
...defaults.switch,
|
|
@@ -891,14 +908,14 @@ function SwitchField(props) {
|
|
|
891
908
|
onValueChange: (val) => field2.onChange(val)
|
|
892
909
|
},
|
|
893
910
|
label
|
|
894
|
-
), description ? /* @__PURE__ */
|
|
911
|
+
), description ? /* @__PURE__ */ React14.createElement("p", { className: "text-small text-default-400" }, description) : null, fieldState.error?.message ? /* @__PURE__ */ React14.createElement("p", { className: "text-tiny text-danger mt-1" }, fieldState.error.message) : null),
|
|
895
912
|
rules
|
|
896
913
|
}
|
|
897
914
|
);
|
|
898
915
|
}
|
|
899
916
|
|
|
900
917
|
// src/fields/TextareaField.tsx
|
|
901
|
-
import
|
|
918
|
+
import React15 from "react";
|
|
902
919
|
import { Controller as Controller10 } from "react-hook-form";
|
|
903
920
|
function TextareaField(props) {
|
|
904
921
|
const {
|
|
@@ -912,12 +929,12 @@ function TextareaField(props) {
|
|
|
912
929
|
textareaProps
|
|
913
930
|
} = props;
|
|
914
931
|
const defaults = useHeroHookFormDefaults();
|
|
915
|
-
return /* @__PURE__ */
|
|
932
|
+
return /* @__PURE__ */ React15.createElement(
|
|
916
933
|
Controller10,
|
|
917
934
|
{
|
|
918
935
|
control,
|
|
919
936
|
name,
|
|
920
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
937
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React15.createElement("div", { className }, /* @__PURE__ */ React15.createElement(
|
|
921
938
|
Textarea,
|
|
922
939
|
{
|
|
923
940
|
...defaults.textarea,
|
|
@@ -938,7 +955,7 @@ function TextareaField(props) {
|
|
|
938
955
|
}
|
|
939
956
|
|
|
940
957
|
// src/components/FormField.tsx
|
|
941
|
-
var FormField =
|
|
958
|
+
var FormField = React16.memo(
|
|
942
959
|
({
|
|
943
960
|
config,
|
|
944
961
|
form,
|
|
@@ -949,6 +966,16 @@ var FormField = React15.memo(
|
|
|
949
966
|
}
|
|
950
967
|
const { control } = form;
|
|
951
968
|
const watchedValues = useWatch3({ control });
|
|
969
|
+
if (config.type === "content") {
|
|
970
|
+
return /* @__PURE__ */ React16.createElement(
|
|
971
|
+
ContentField,
|
|
972
|
+
{
|
|
973
|
+
config,
|
|
974
|
+
form,
|
|
975
|
+
submissionState
|
|
976
|
+
}
|
|
977
|
+
);
|
|
978
|
+
}
|
|
952
979
|
if (config.condition && !config.condition(watchedValues)) {
|
|
953
980
|
return null;
|
|
954
981
|
}
|
|
@@ -970,7 +997,7 @@ var FormField = React15.memo(
|
|
|
970
997
|
};
|
|
971
998
|
switch (config.type) {
|
|
972
999
|
case "input":
|
|
973
|
-
return /* @__PURE__ */
|
|
1000
|
+
return /* @__PURE__ */ React16.createElement(
|
|
974
1001
|
InputField,
|
|
975
1002
|
{
|
|
976
1003
|
...baseProps,
|
|
@@ -980,7 +1007,7 @@ var FormField = React15.memo(
|
|
|
980
1007
|
}
|
|
981
1008
|
);
|
|
982
1009
|
case "textarea":
|
|
983
|
-
return /* @__PURE__ */
|
|
1010
|
+
return /* @__PURE__ */ React16.createElement(
|
|
984
1011
|
TextareaField,
|
|
985
1012
|
{
|
|
986
1013
|
...baseProps,
|
|
@@ -990,7 +1017,7 @@ var FormField = React15.memo(
|
|
|
990
1017
|
}
|
|
991
1018
|
);
|
|
992
1019
|
case "select":
|
|
993
|
-
return /* @__PURE__ */
|
|
1020
|
+
return /* @__PURE__ */ React16.createElement(
|
|
994
1021
|
SelectField,
|
|
995
1022
|
{
|
|
996
1023
|
...baseProps,
|
|
@@ -1004,7 +1031,7 @@ var FormField = React15.memo(
|
|
|
1004
1031
|
}
|
|
1005
1032
|
);
|
|
1006
1033
|
case "checkbox":
|
|
1007
|
-
return /* @__PURE__ */
|
|
1034
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1008
1035
|
CheckboxField,
|
|
1009
1036
|
{
|
|
1010
1037
|
...baseProps,
|
|
@@ -1014,7 +1041,7 @@ var FormField = React15.memo(
|
|
|
1014
1041
|
}
|
|
1015
1042
|
);
|
|
1016
1043
|
case "radio":
|
|
1017
|
-
return /* @__PURE__ */
|
|
1044
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1018
1045
|
RadioGroupField,
|
|
1019
1046
|
{
|
|
1020
1047
|
...baseProps,
|
|
@@ -1028,7 +1055,7 @@ var FormField = React15.memo(
|
|
|
1028
1055
|
}
|
|
1029
1056
|
);
|
|
1030
1057
|
case "switch":
|
|
1031
|
-
return /* @__PURE__ */
|
|
1058
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1032
1059
|
SwitchField,
|
|
1033
1060
|
{
|
|
1034
1061
|
...baseProps,
|
|
@@ -1038,7 +1065,7 @@ var FormField = React15.memo(
|
|
|
1038
1065
|
}
|
|
1039
1066
|
);
|
|
1040
1067
|
case "slider":
|
|
1041
|
-
return /* @__PURE__ */
|
|
1068
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1042
1069
|
SliderField,
|
|
1043
1070
|
{
|
|
1044
1071
|
...baseProps,
|
|
@@ -1048,7 +1075,7 @@ var FormField = React15.memo(
|
|
|
1048
1075
|
}
|
|
1049
1076
|
);
|
|
1050
1077
|
case "date":
|
|
1051
|
-
return /* @__PURE__ */
|
|
1078
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1052
1079
|
DateField,
|
|
1053
1080
|
{
|
|
1054
1081
|
...baseProps,
|
|
@@ -1058,7 +1085,7 @@ var FormField = React15.memo(
|
|
|
1058
1085
|
}
|
|
1059
1086
|
);
|
|
1060
1087
|
case "file":
|
|
1061
|
-
return /* @__PURE__ */
|
|
1088
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1062
1089
|
FileField,
|
|
1063
1090
|
{
|
|
1064
1091
|
...baseProps,
|
|
@@ -1070,7 +1097,7 @@ var FormField = React15.memo(
|
|
|
1070
1097
|
}
|
|
1071
1098
|
);
|
|
1072
1099
|
case "fontPicker":
|
|
1073
|
-
return /* @__PURE__ */
|
|
1100
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1074
1101
|
FontPickerField,
|
|
1075
1102
|
{
|
|
1076
1103
|
...baseProps,
|
|
@@ -1088,7 +1115,7 @@ var FormField = React15.memo(
|
|
|
1088
1115
|
name: config.name
|
|
1089
1116
|
});
|
|
1090
1117
|
case "conditional":
|
|
1091
|
-
return /* @__PURE__ */
|
|
1118
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1092
1119
|
ConditionalField,
|
|
1093
1120
|
{
|
|
1094
1121
|
config,
|
|
@@ -1097,7 +1124,7 @@ var FormField = React15.memo(
|
|
|
1097
1124
|
}
|
|
1098
1125
|
);
|
|
1099
1126
|
case "fieldArray":
|
|
1100
|
-
return /* @__PURE__ */
|
|
1127
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1101
1128
|
FieldArrayField,
|
|
1102
1129
|
{
|
|
1103
1130
|
config,
|
|
@@ -1105,7 +1132,7 @@ var FormField = React15.memo(
|
|
|
1105
1132
|
}
|
|
1106
1133
|
);
|
|
1107
1134
|
case "dynamicSection":
|
|
1108
|
-
return /* @__PURE__ */
|
|
1135
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1109
1136
|
DynamicSectionField,
|
|
1110
1137
|
{
|
|
1111
1138
|
config,
|
|
@@ -1157,12 +1184,12 @@ function ConfigurableForm({
|
|
|
1157
1184
|
});
|
|
1158
1185
|
const renderFields = () => {
|
|
1159
1186
|
if (layout === "grid") {
|
|
1160
|
-
return /* @__PURE__ */
|
|
1187
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1161
1188
|
"div",
|
|
1162
1189
|
{
|
|
1163
1190
|
className: `grid gap-${spacing} ${columns === 1 ? "grid-cols-1" : columns === 2 ? "grid-cols-1 md:grid-cols-2" : "grid-cols-1 md:grid-cols-2 lg:grid-cols-3"}`
|
|
1164
1191
|
},
|
|
1165
|
-
fields.map((field2) => /* @__PURE__ */
|
|
1192
|
+
fields.map((field2) => /* @__PURE__ */ React17.createElement(
|
|
1166
1193
|
FormField,
|
|
1167
1194
|
{
|
|
1168
1195
|
key: field2.name,
|
|
@@ -1174,7 +1201,7 @@ function ConfigurableForm({
|
|
|
1174
1201
|
);
|
|
1175
1202
|
}
|
|
1176
1203
|
if (layout === "horizontal") {
|
|
1177
|
-
return /* @__PURE__ */
|
|
1204
|
+
return /* @__PURE__ */ React17.createElement("div", { className: `grid gap-${spacing} grid-cols-1 md:grid-cols-2` }, fields.map((field2) => /* @__PURE__ */ React17.createElement(
|
|
1178
1205
|
FormField,
|
|
1179
1206
|
{
|
|
1180
1207
|
key: field2.name,
|
|
@@ -1184,7 +1211,7 @@ function ConfigurableForm({
|
|
|
1184
1211
|
}
|
|
1185
1212
|
)));
|
|
1186
1213
|
}
|
|
1187
|
-
return /* @__PURE__ */
|
|
1214
|
+
return /* @__PURE__ */ React17.createElement("div", { className: `space-y-${spacing}` }, fields.map((field2) => /* @__PURE__ */ React17.createElement(
|
|
1188
1215
|
FormField,
|
|
1189
1216
|
{
|
|
1190
1217
|
key: field2.name,
|
|
@@ -1198,23 +1225,23 @@ function ConfigurableForm({
|
|
|
1198
1225
|
e.preventDefault();
|
|
1199
1226
|
void handleSubmit();
|
|
1200
1227
|
};
|
|
1201
|
-
return /* @__PURE__ */
|
|
1228
|
+
return /* @__PURE__ */ React17.createElement("form", { className, role: "form", onSubmit: handleFormSubmit }, title && /* @__PURE__ */ React17.createElement("div", { className: "mb-6" }, /* @__PURE__ */ React17.createElement("h2", { className: "text-xl font-semibold text-foreground mb-2" }, title), subtitle && /* @__PURE__ */ React17.createElement("p", { className: "text-sm text-muted-foreground" }, subtitle)), isSubmitted && isSuccess && /* @__PURE__ */ React17.createElement(
|
|
1202
1229
|
"div",
|
|
1203
1230
|
{
|
|
1204
1231
|
className: "mb-6 p-4 bg-success-50 border border-success-200 rounded-lg",
|
|
1205
1232
|
"data-testid": "success-message"
|
|
1206
1233
|
},
|
|
1207
|
-
/* @__PURE__ */
|
|
1208
|
-
/* @__PURE__ */
|
|
1209
|
-
), error && /* @__PURE__ */
|
|
1234
|
+
/* @__PURE__ */ React17.createElement("p", { className: "text-success-800 font-medium" }, "Success!"),
|
|
1235
|
+
/* @__PURE__ */ React17.createElement("p", { className: "text-success-700 text-sm mt-1" }, "Your request has been processed successfully.")
|
|
1236
|
+
), error && /* @__PURE__ */ React17.createElement(
|
|
1210
1237
|
"div",
|
|
1211
1238
|
{
|
|
1212
1239
|
className: "mb-6 p-4 bg-danger-50 border border-danger-200 rounded-lg",
|
|
1213
1240
|
"data-testid": "error-message"
|
|
1214
1241
|
},
|
|
1215
|
-
/* @__PURE__ */
|
|
1216
|
-
/* @__PURE__ */
|
|
1217
|
-
), renderFields(), /* @__PURE__ */
|
|
1242
|
+
/* @__PURE__ */ React17.createElement("p", { className: "text-danger-800 font-medium" }, "Error"),
|
|
1243
|
+
/* @__PURE__ */ React17.createElement("p", { className: "text-danger-700 text-sm mt-1" }, error)
|
|
1244
|
+
), renderFields(), /* @__PURE__ */ React17.createElement("div", { className: "mt-6 flex gap-3 justify-end" }, /* @__PURE__ */ React17.createElement(
|
|
1218
1245
|
Button3,
|
|
1219
1246
|
{
|
|
1220
1247
|
color: "primary",
|
|
@@ -1224,7 +1251,7 @@ function ConfigurableForm({
|
|
|
1224
1251
|
...submitButtonProps
|
|
1225
1252
|
},
|
|
1226
1253
|
submitButtonText
|
|
1227
|
-
), showResetButton && /* @__PURE__ */
|
|
1254
|
+
), showResetButton && /* @__PURE__ */ React17.createElement(
|
|
1228
1255
|
Button3,
|
|
1229
1256
|
{
|
|
1230
1257
|
isDisabled: isSubmitting,
|
|
@@ -1237,7 +1264,7 @@ function ConfigurableForm({
|
|
|
1237
1264
|
}
|
|
1238
1265
|
|
|
1239
1266
|
// src/components/ServerActionForm.tsx
|
|
1240
|
-
import
|
|
1267
|
+
import React18 from "react";
|
|
1241
1268
|
import { useActionState } from "react";
|
|
1242
1269
|
function ServerActionForm({
|
|
1243
1270
|
action,
|
|
@@ -1262,10 +1289,10 @@ function ServerActionForm({
|
|
|
1262
1289
|
action,
|
|
1263
1290
|
initialState ?? { errors: void 0, message: void 0, success: false }
|
|
1264
1291
|
);
|
|
1265
|
-
const formRef =
|
|
1266
|
-
const [clientErrors, setClientErrors] =
|
|
1267
|
-
const lastSubmittedFormData =
|
|
1268
|
-
|
|
1292
|
+
const formRef = React18.useRef(null);
|
|
1293
|
+
const [clientErrors, setClientErrors] = React18.useState({});
|
|
1294
|
+
const lastSubmittedFormData = React18.useRef(null);
|
|
1295
|
+
React18.useEffect(() => {
|
|
1269
1296
|
if (state && (state.errors || state.message && !state.success)) {
|
|
1270
1297
|
onError?.({
|
|
1271
1298
|
errors: state.errors,
|
|
@@ -1273,7 +1300,7 @@ function ServerActionForm({
|
|
|
1273
1300
|
});
|
|
1274
1301
|
}
|
|
1275
1302
|
}, [state, onError]);
|
|
1276
|
-
|
|
1303
|
+
React18.useEffect(() => {
|
|
1277
1304
|
if (state?.success && lastSubmittedFormData.current) {
|
|
1278
1305
|
onSuccess?.(lastSubmittedFormData.current);
|
|
1279
1306
|
}
|
|
@@ -1316,12 +1343,12 @@ function ServerActionForm({
|
|
|
1316
1343
|
};
|
|
1317
1344
|
const renderFields = () => {
|
|
1318
1345
|
if (layout === "grid") {
|
|
1319
|
-
return /* @__PURE__ */
|
|
1346
|
+
return /* @__PURE__ */ React18.createElement(
|
|
1320
1347
|
"div",
|
|
1321
1348
|
{
|
|
1322
1349
|
className: `grid gap-${spacing} ${columns === 1 ? "grid-cols-1" : columns === 2 ? "grid-cols-1 md:grid-cols-2" : "grid-cols-1 md:grid-cols-2 lg:grid-cols-3"}`
|
|
1323
1350
|
},
|
|
1324
|
-
fields.map((field2) => /* @__PURE__ */
|
|
1351
|
+
fields.map((field2) => /* @__PURE__ */ React18.createElement(
|
|
1325
1352
|
ServerActionField,
|
|
1326
1353
|
{
|
|
1327
1354
|
key: field2.name,
|
|
@@ -1334,7 +1361,7 @@ function ServerActionForm({
|
|
|
1334
1361
|
);
|
|
1335
1362
|
}
|
|
1336
1363
|
if (layout === "horizontal") {
|
|
1337
|
-
return /* @__PURE__ */
|
|
1364
|
+
return /* @__PURE__ */ React18.createElement("div", { className: `grid gap-${spacing} grid-cols-1 md:grid-cols-2` }, fields.map((field2) => /* @__PURE__ */ React18.createElement(
|
|
1338
1365
|
ServerActionField,
|
|
1339
1366
|
{
|
|
1340
1367
|
key: field2.name,
|
|
@@ -1345,7 +1372,7 @@ function ServerActionForm({
|
|
|
1345
1372
|
}
|
|
1346
1373
|
)));
|
|
1347
1374
|
}
|
|
1348
|
-
return /* @__PURE__ */
|
|
1375
|
+
return /* @__PURE__ */ React18.createElement("div", { className: `space-y-${spacing}` }, fields.map((field2) => /* @__PURE__ */ React18.createElement(
|
|
1349
1376
|
ServerActionField,
|
|
1350
1377
|
{
|
|
1351
1378
|
key: field2.name,
|
|
@@ -1356,7 +1383,7 @@ function ServerActionForm({
|
|
|
1356
1383
|
}
|
|
1357
1384
|
)));
|
|
1358
1385
|
};
|
|
1359
|
-
return /* @__PURE__ */
|
|
1386
|
+
return /* @__PURE__ */ React18.createElement(
|
|
1360
1387
|
"form",
|
|
1361
1388
|
{
|
|
1362
1389
|
ref: formRef,
|
|
@@ -1364,27 +1391,27 @@ function ServerActionForm({
|
|
|
1364
1391
|
role: "form",
|
|
1365
1392
|
onSubmit: handleSubmit
|
|
1366
1393
|
},
|
|
1367
|
-
title && /* @__PURE__ */
|
|
1368
|
-
state?.success && !pending && /* @__PURE__ */
|
|
1394
|
+
title && /* @__PURE__ */ React18.createElement("div", { className: "mb-6" }, /* @__PURE__ */ React18.createElement("h2", { className: "text-xl font-semibold text-foreground mb-2" }, title), subtitle && /* @__PURE__ */ React18.createElement("p", { className: "text-sm text-muted-foreground" }, subtitle)),
|
|
1395
|
+
state?.success && !pending && /* @__PURE__ */ React18.createElement(
|
|
1369
1396
|
"div",
|
|
1370
1397
|
{
|
|
1371
1398
|
className: "mb-6 p-4 bg-success-50 border border-success-200 rounded-lg",
|
|
1372
1399
|
"data-testid": "success-message"
|
|
1373
1400
|
},
|
|
1374
|
-
/* @__PURE__ */
|
|
1375
|
-
state.message && /* @__PURE__ */
|
|
1401
|
+
/* @__PURE__ */ React18.createElement("p", { className: "text-success-800 font-medium" }, "Success!"),
|
|
1402
|
+
state.message && /* @__PURE__ */ React18.createElement("p", { className: "text-success-700 text-sm mt-1" }, state.message)
|
|
1376
1403
|
),
|
|
1377
|
-
state?.message && !state.success && /* @__PURE__ */
|
|
1404
|
+
state?.message && !state.success && /* @__PURE__ */ React18.createElement(
|
|
1378
1405
|
"div",
|
|
1379
1406
|
{
|
|
1380
1407
|
className: "mb-6 p-4 bg-danger-50 border border-danger-200 rounded-lg",
|
|
1381
1408
|
"data-testid": "error-message"
|
|
1382
1409
|
},
|
|
1383
|
-
/* @__PURE__ */
|
|
1384
|
-
/* @__PURE__ */
|
|
1410
|
+
/* @__PURE__ */ React18.createElement("p", { className: "text-danger-800 font-medium" }, "Error"),
|
|
1411
|
+
/* @__PURE__ */ React18.createElement("p", { className: "text-danger-700 text-sm mt-1" }, state.message)
|
|
1385
1412
|
),
|
|
1386
1413
|
renderFields(),
|
|
1387
|
-
/* @__PURE__ */
|
|
1414
|
+
/* @__PURE__ */ React18.createElement("div", { className: "mt-6 flex gap-3 justify-end" }, /* @__PURE__ */ React18.createElement(
|
|
1388
1415
|
Button,
|
|
1389
1416
|
{
|
|
1390
1417
|
color: "primary",
|
|
@@ -1394,7 +1421,7 @@ function ServerActionForm({
|
|
|
1394
1421
|
...submitButtonProps
|
|
1395
1422
|
},
|
|
1396
1423
|
submitButtonText
|
|
1397
|
-
), showResetButton && /* @__PURE__ */
|
|
1424
|
+
), showResetButton && /* @__PURE__ */ React18.createElement(
|
|
1398
1425
|
Button,
|
|
1399
1426
|
{
|
|
1400
1427
|
isDisabled: pending,
|
|
@@ -1412,6 +1439,17 @@ function ServerActionField({
|
|
|
1412
1439
|
errors,
|
|
1413
1440
|
field: field2
|
|
1414
1441
|
}) {
|
|
1442
|
+
if (field2.type === "content") {
|
|
1443
|
+
const contentField2 = field2;
|
|
1444
|
+
if (contentField2.render) {
|
|
1445
|
+
return /* @__PURE__ */ React18.createElement("div", { className: contentField2.className }, contentField2.render({
|
|
1446
|
+
errors: {},
|
|
1447
|
+
form: null,
|
|
1448
|
+
isSubmitting: false
|
|
1449
|
+
}));
|
|
1450
|
+
}
|
|
1451
|
+
return /* @__PURE__ */ React18.createElement("div", { className: contentField2.className }, contentField2.title && /* @__PURE__ */ React18.createElement("h3", { className: "text-lg font-semibold text-foreground mb-2" }, contentField2.title), contentField2.description && /* @__PURE__ */ React18.createElement("p", { className: "text-sm text-muted-foreground" }, contentField2.description));
|
|
1452
|
+
}
|
|
1415
1453
|
const fieldName = field2.name;
|
|
1416
1454
|
const fieldErrors = errors?.[fieldName];
|
|
1417
1455
|
const clientError = clientErrors?.[fieldName];
|
|
@@ -1438,9 +1476,9 @@ function ServerActionField({
|
|
|
1438
1476
|
}
|
|
1439
1477
|
return false;
|
|
1440
1478
|
};
|
|
1441
|
-
const [value, setValue] =
|
|
1442
|
-
const [checked, setChecked] =
|
|
1443
|
-
|
|
1479
|
+
const [value, setValue] = React18.useState(getDefaultValue);
|
|
1480
|
+
const [checked, setChecked] = React18.useState(getDefaultChecked);
|
|
1481
|
+
React18.useEffect(() => {
|
|
1444
1482
|
const newDefaultValue = defaultValues?.[fieldName];
|
|
1445
1483
|
if (newDefaultValue !== void 0 && newDefaultValue !== null) {
|
|
1446
1484
|
if (field2.type === "checkbox") {
|
|
@@ -1454,7 +1492,7 @@ function ServerActionField({
|
|
|
1454
1492
|
}
|
|
1455
1493
|
}
|
|
1456
1494
|
}, [defaultValues, fieldName, field2.type]);
|
|
1457
|
-
|
|
1495
|
+
React18.useEffect(() => {
|
|
1458
1496
|
const hiddenInput = document.querySelector(
|
|
1459
1497
|
`input[type="hidden"][name="${fieldName}"]`
|
|
1460
1498
|
);
|
|
@@ -1469,7 +1507,7 @@ function ServerActionField({
|
|
|
1469
1507
|
switch (field2.type) {
|
|
1470
1508
|
case "input": {
|
|
1471
1509
|
const inputType = field2.inputProps?.type || "text";
|
|
1472
|
-
return /* @__PURE__ */
|
|
1510
|
+
return /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React18.createElement(
|
|
1473
1511
|
Input,
|
|
1474
1512
|
{
|
|
1475
1513
|
...field2.inputProps,
|
|
@@ -1486,7 +1524,7 @@ function ServerActionField({
|
|
|
1486
1524
|
));
|
|
1487
1525
|
}
|
|
1488
1526
|
case "textarea": {
|
|
1489
|
-
return /* @__PURE__ */
|
|
1527
|
+
return /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React18.createElement(
|
|
1490
1528
|
Textarea,
|
|
1491
1529
|
{
|
|
1492
1530
|
...field2.textareaProps,
|
|
@@ -1502,7 +1540,7 @@ function ServerActionField({
|
|
|
1502
1540
|
));
|
|
1503
1541
|
}
|
|
1504
1542
|
case "checkbox": {
|
|
1505
|
-
return /* @__PURE__ */
|
|
1543
|
+
return /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement("input", { type: "hidden", name: fieldName, value: checked ? "on" : "" }), /* @__PURE__ */ React18.createElement(
|
|
1506
1544
|
Checkbox,
|
|
1507
1545
|
{
|
|
1508
1546
|
...field2.checkboxProps,
|
|
@@ -1518,7 +1556,7 @@ function ServerActionField({
|
|
|
1518
1556
|
}
|
|
1519
1557
|
case "select": {
|
|
1520
1558
|
const options = field2.options || [];
|
|
1521
|
-
return /* @__PURE__ */
|
|
1559
|
+
return /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React18.createElement(
|
|
1522
1560
|
Select,
|
|
1523
1561
|
{
|
|
1524
1562
|
...field2.selectProps,
|
|
@@ -1535,12 +1573,12 @@ function ServerActionField({
|
|
|
1535
1573
|
}
|
|
1536
1574
|
},
|
|
1537
1575
|
options.map(
|
|
1538
|
-
(option) => /* @__PURE__ */
|
|
1576
|
+
(option) => /* @__PURE__ */ React18.createElement(SelectItem, { key: String(option.value) }, option.label)
|
|
1539
1577
|
)
|
|
1540
1578
|
));
|
|
1541
1579
|
}
|
|
1542
1580
|
default:
|
|
1543
|
-
return /* @__PURE__ */
|
|
1581
|
+
return /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React18.createElement(
|
|
1544
1582
|
Input,
|
|
1545
1583
|
{
|
|
1546
1584
|
"data-field-name": fieldName,
|
|
@@ -1570,10 +1608,10 @@ function useHeroForm() {
|
|
|
1570
1608
|
}
|
|
1571
1609
|
|
|
1572
1610
|
// src/providers/FormProvider.tsx
|
|
1573
|
-
import
|
|
1611
|
+
import React19 from "react";
|
|
1574
1612
|
import { FormProvider as RHFProvider } from "react-hook-form";
|
|
1575
1613
|
function FormProvider(props) {
|
|
1576
|
-
return /* @__PURE__ */
|
|
1614
|
+
return /* @__PURE__ */ React19.createElement(RHFProvider, { ...props.methods }, /* @__PURE__ */ React19.createElement(
|
|
1577
1615
|
"form",
|
|
1578
1616
|
{
|
|
1579
1617
|
className: props.className,
|
|
@@ -1586,7 +1624,7 @@ function FormProvider(props) {
|
|
|
1586
1624
|
}
|
|
1587
1625
|
|
|
1588
1626
|
// src/submit/SubmitButton.tsx
|
|
1589
|
-
import
|
|
1627
|
+
import React20 from "react";
|
|
1590
1628
|
function SubmitButton(props) {
|
|
1591
1629
|
const ctx = useFormContext5();
|
|
1592
1630
|
const loading = props.isLoading ?? ctx.formState.isSubmitting;
|
|
@@ -1596,10 +1634,10 @@ function SubmitButton(props) {
|
|
|
1596
1634
|
const defaults = useHeroHookFormDefaults();
|
|
1597
1635
|
const getButtonContent = () => {
|
|
1598
1636
|
if (enhancedState?.isSuccess) {
|
|
1599
|
-
return /* @__PURE__ */
|
|
1637
|
+
return /* @__PURE__ */ React20.createElement("span", { className: "inline-flex items-center gap-2" }, "\u2705", props.successText || "Success!");
|
|
1600
1638
|
}
|
|
1601
1639
|
if (loading) {
|
|
1602
|
-
return /* @__PURE__ */
|
|
1640
|
+
return /* @__PURE__ */ React20.createElement("span", { className: "inline-flex items-center gap-2" }, "\u23F3", props.loadingText || "Submitting...");
|
|
1603
1641
|
}
|
|
1604
1642
|
return props.children;
|
|
1605
1643
|
};
|
|
@@ -1612,7 +1650,7 @@ function SubmitButton(props) {
|
|
|
1612
1650
|
}
|
|
1613
1651
|
return props.buttonProps?.color || defaults.submitButton.color;
|
|
1614
1652
|
};
|
|
1615
|
-
return /* @__PURE__ */
|
|
1653
|
+
return /* @__PURE__ */ React20.createElement(
|
|
1616
1654
|
Button,
|
|
1617
1655
|
{
|
|
1618
1656
|
type: "submit",
|
|
@@ -1853,7 +1891,7 @@ var commonValidations = {
|
|
|
1853
1891
|
import { useFormContext as useFormContext5 } from "react-hook-form";
|
|
1854
1892
|
|
|
1855
1893
|
// src/components/ZodForm.tsx
|
|
1856
|
-
import
|
|
1894
|
+
import React22 from "react";
|
|
1857
1895
|
import { Button as Button5 } from "@heroui/react";
|
|
1858
1896
|
import {
|
|
1859
1897
|
FormProvider as FormProvider2
|
|
@@ -1976,7 +2014,7 @@ function useEnhancedFormState(form, options = {}) {
|
|
|
1976
2014
|
}
|
|
1977
2015
|
|
|
1978
2016
|
// src/components/FormStatus.tsx
|
|
1979
|
-
import
|
|
2017
|
+
import React21 from "react";
|
|
1980
2018
|
import { Button as Button4 } from "@heroui/react";
|
|
1981
2019
|
function FormStatus({
|
|
1982
2020
|
className = "",
|
|
@@ -1989,25 +2027,25 @@ function FormStatus({
|
|
|
1989
2027
|
return null;
|
|
1990
2028
|
}
|
|
1991
2029
|
if (isSubmitting) {
|
|
1992
|
-
return /* @__PURE__ */
|
|
2030
|
+
return /* @__PURE__ */ React21.createElement(
|
|
1993
2031
|
"div",
|
|
1994
2032
|
{
|
|
1995
2033
|
className: `flex items-center gap-3 p-4 bg-blue-50 border border-blue-200 rounded-lg ${className}`
|
|
1996
2034
|
},
|
|
1997
|
-
/* @__PURE__ */
|
|
1998
|
-
/* @__PURE__ */
|
|
2035
|
+
/* @__PURE__ */ React21.createElement("span", { className: "text-blue-600" }, "\u23F3"),
|
|
2036
|
+
/* @__PURE__ */ React21.createElement("div", null, /* @__PURE__ */ React21.createElement("p", { className: "text-sm font-medium text-blue-900" }, "Submitting form..."), showDetails && /* @__PURE__ */ React21.createElement("p", { className: "text-xs text-blue-700" }, "Please wait while we process your request."))
|
|
1999
2037
|
);
|
|
2000
2038
|
}
|
|
2001
2039
|
if (isSuccess) {
|
|
2002
|
-
return /* @__PURE__ */
|
|
2040
|
+
return /* @__PURE__ */ React21.createElement(
|
|
2003
2041
|
"div",
|
|
2004
2042
|
{
|
|
2005
2043
|
className: `flex items-center gap-3 p-4 bg-green-50 border border-green-200 rounded-lg ${className}`,
|
|
2006
2044
|
"data-testid": "success-message"
|
|
2007
2045
|
},
|
|
2008
|
-
/* @__PURE__ */
|
|
2009
|
-
/* @__PURE__ */
|
|
2010
|
-
onDismiss && /* @__PURE__ */
|
|
2046
|
+
/* @__PURE__ */ React21.createElement("span", { className: "text-green-600" }, "\u2705"),
|
|
2047
|
+
/* @__PURE__ */ React21.createElement("div", { className: "flex-1" }, /* @__PURE__ */ React21.createElement("p", { className: "text-sm font-medium text-green-900" }, "Form submitted successfully!"), showDetails && submittedData && /* @__PURE__ */ React21.createElement("p", { className: "text-xs text-green-700" }, "Your data has been saved. Thank you for your submission.")),
|
|
2048
|
+
onDismiss && /* @__PURE__ */ React21.createElement(
|
|
2011
2049
|
Button4,
|
|
2012
2050
|
{
|
|
2013
2051
|
size: "sm",
|
|
@@ -2021,15 +2059,15 @@ function FormStatus({
|
|
|
2021
2059
|
);
|
|
2022
2060
|
}
|
|
2023
2061
|
if (isError && error) {
|
|
2024
|
-
return /* @__PURE__ */
|
|
2062
|
+
return /* @__PURE__ */ React21.createElement(
|
|
2025
2063
|
"div",
|
|
2026
2064
|
{
|
|
2027
2065
|
className: `flex items-center gap-3 p-4 bg-red-50 border border-red-200 rounded-lg ${className}`,
|
|
2028
2066
|
"data-testid": "error-message"
|
|
2029
2067
|
},
|
|
2030
|
-
/* @__PURE__ */
|
|
2031
|
-
/* @__PURE__ */
|
|
2032
|
-
onDismiss && /* @__PURE__ */
|
|
2068
|
+
/* @__PURE__ */ React21.createElement("span", { className: "text-red-600" }, "\u26A0\uFE0F"),
|
|
2069
|
+
/* @__PURE__ */ React21.createElement("div", { className: "flex-1" }, /* @__PURE__ */ React21.createElement("p", { className: "text-sm font-medium text-red-900" }, "Error submitting form"), /* @__PURE__ */ React21.createElement("p", { className: "text-xs text-red-700" }, error)),
|
|
2070
|
+
onDismiss && /* @__PURE__ */ React21.createElement(
|
|
2033
2071
|
Button4,
|
|
2034
2072
|
{
|
|
2035
2073
|
size: "sm",
|
|
@@ -2050,8 +2088,8 @@ function FormToast({
|
|
|
2050
2088
|
position = "top-right",
|
|
2051
2089
|
state
|
|
2052
2090
|
}) {
|
|
2053
|
-
const [isVisible, setIsVisible] =
|
|
2054
|
-
|
|
2091
|
+
const [isVisible, setIsVisible] = React21.useState(false);
|
|
2092
|
+
React21.useEffect(() => {
|
|
2055
2093
|
if (state.isSuccess || state.isError) {
|
|
2056
2094
|
setIsVisible(true);
|
|
2057
2095
|
if (duration > 0) {
|
|
@@ -2072,7 +2110,7 @@ function FormToast({
|
|
|
2072
2110
|
"top-left": "top-4 left-4",
|
|
2073
2111
|
"top-right": "top-4 right-4"
|
|
2074
2112
|
};
|
|
2075
|
-
return /* @__PURE__ */
|
|
2113
|
+
return /* @__PURE__ */ React21.createElement("div", { className: `fixed z-50 ${positionClasses[position]}` }, /* @__PURE__ */ React21.createElement(FormStatus, { state, onDismiss }));
|
|
2076
2114
|
}
|
|
2077
2115
|
|
|
2078
2116
|
// src/components/ZodForm.tsx
|
|
@@ -2123,12 +2161,12 @@ function ZodForm({
|
|
|
2123
2161
|
};
|
|
2124
2162
|
const renderFields = () => {
|
|
2125
2163
|
if (layout === "grid") {
|
|
2126
|
-
return /* @__PURE__ */
|
|
2164
|
+
return /* @__PURE__ */ React22.createElement(
|
|
2127
2165
|
"div",
|
|
2128
2166
|
{
|
|
2129
2167
|
className: `grid gap-${spacing} ${columns === 1 ? "grid-cols-1" : columns === 2 ? "grid-cols-1 md:grid-cols-2" : "grid-cols-1 md:grid-cols-2 lg:grid-cols-3"}`
|
|
2130
2168
|
},
|
|
2131
|
-
config.fields.map((field2) => /* @__PURE__ */
|
|
2169
|
+
config.fields.map((field2) => /* @__PURE__ */ React22.createElement(
|
|
2132
2170
|
FormField,
|
|
2133
2171
|
{
|
|
2134
2172
|
key: field2.name,
|
|
@@ -2145,7 +2183,7 @@ function ZodForm({
|
|
|
2145
2183
|
);
|
|
2146
2184
|
}
|
|
2147
2185
|
if (layout === "horizontal") {
|
|
2148
|
-
return /* @__PURE__ */
|
|
2186
|
+
return /* @__PURE__ */ React22.createElement("div", { className: `grid gap-${spacing} grid-cols-1 md:grid-cols-2` }, config.fields.map((field2) => /* @__PURE__ */ React22.createElement(
|
|
2149
2187
|
FormField,
|
|
2150
2188
|
{
|
|
2151
2189
|
key: field2.name,
|
|
@@ -2160,7 +2198,7 @@ function ZodForm({
|
|
|
2160
2198
|
}
|
|
2161
2199
|
)));
|
|
2162
2200
|
}
|
|
2163
|
-
return /* @__PURE__ */
|
|
2201
|
+
return /* @__PURE__ */ React22.createElement("div", { className: `space-y-${spacing}` }, config.fields.map((field2) => /* @__PURE__ */ React22.createElement(
|
|
2164
2202
|
FormField,
|
|
2165
2203
|
{
|
|
2166
2204
|
key: field2.name,
|
|
@@ -2179,13 +2217,13 @@ function ZodForm({
|
|
|
2179
2217
|
e.preventDefault();
|
|
2180
2218
|
void handleSubmit();
|
|
2181
2219
|
};
|
|
2182
|
-
|
|
2220
|
+
React22.useEffect(() => {
|
|
2183
2221
|
if (config.onError && Object.keys(form.formState.errors).length > 0) {
|
|
2184
2222
|
config.onError(form.formState.errors);
|
|
2185
2223
|
}
|
|
2186
2224
|
}, [form.formState.errors, config.onError]);
|
|
2187
2225
|
if (render) {
|
|
2188
|
-
return /* @__PURE__ */
|
|
2226
|
+
return /* @__PURE__ */ React22.createElement(FormProvider2, { ...form }, render({
|
|
2189
2227
|
errors: form.formState.errors,
|
|
2190
2228
|
form,
|
|
2191
2229
|
isSubmitted: enhancedState.status !== "idle",
|
|
@@ -2194,14 +2232,14 @@ function ZodForm({
|
|
|
2194
2232
|
values: form.getValues()
|
|
2195
2233
|
}));
|
|
2196
2234
|
}
|
|
2197
|
-
return /* @__PURE__ */
|
|
2235
|
+
return /* @__PURE__ */ React22.createElement(FormProvider2, { ...form }, /* @__PURE__ */ React22.createElement("form", { className, role: "form", onSubmit: handleFormSubmit }, title && /* @__PURE__ */ React22.createElement("div", { className: "mb-6" }, /* @__PURE__ */ React22.createElement("h2", { className: "text-xl font-semibold text-foreground mb-2" }, title), subtitle && /* @__PURE__ */ React22.createElement("p", { className: "text-sm text-muted-foreground" }, subtitle)), /* @__PURE__ */ React22.createElement(
|
|
2198
2236
|
FormStatus,
|
|
2199
2237
|
{
|
|
2200
2238
|
state: enhancedState,
|
|
2201
2239
|
onDismiss: () => enhancedState.reset(),
|
|
2202
2240
|
showDetails: true
|
|
2203
2241
|
}
|
|
2204
|
-
), renderFields(), /* @__PURE__ */
|
|
2242
|
+
), renderFields(), /* @__PURE__ */ React22.createElement("div", { className: "mt-6 flex gap-3 justify-end" }, /* @__PURE__ */ React22.createElement(
|
|
2205
2243
|
Button5,
|
|
2206
2244
|
{
|
|
2207
2245
|
color: "primary",
|
|
@@ -2211,7 +2249,7 @@ function ZodForm({
|
|
|
2211
2249
|
...submitButtonProps
|
|
2212
2250
|
},
|
|
2213
2251
|
enhancedState.isSuccess ? "Success!" : submitButtonText
|
|
2214
|
-
), showResetButton && /* @__PURE__ */
|
|
2252
|
+
), showResetButton && /* @__PURE__ */ React22.createElement(
|
|
2215
2253
|
Button5,
|
|
2216
2254
|
{
|
|
2217
2255
|
isDisabled: enhancedState.isSubmitting,
|
|
@@ -2275,6 +2313,20 @@ var BasicFormBuilder = class {
|
|
|
2275
2313
|
});
|
|
2276
2314
|
return this;
|
|
2277
2315
|
}
|
|
2316
|
+
/**
|
|
2317
|
+
* Add a content field for headers, questions, or custom content between fields
|
|
2318
|
+
*/
|
|
2319
|
+
content(title, description, options) {
|
|
2320
|
+
this.fields.push({
|
|
2321
|
+
className: options?.className,
|
|
2322
|
+
description: description || void 0,
|
|
2323
|
+
name: options?.name,
|
|
2324
|
+
render: options?.render,
|
|
2325
|
+
title: title || void 0,
|
|
2326
|
+
type: "content"
|
|
2327
|
+
});
|
|
2328
|
+
return this;
|
|
2329
|
+
}
|
|
2278
2330
|
/**
|
|
2279
2331
|
* Add a switch field
|
|
2280
2332
|
*/
|
|
@@ -2305,6 +2357,28 @@ var FormFieldHelpers = {
|
|
|
2305
2357
|
name,
|
|
2306
2358
|
type: "checkbox"
|
|
2307
2359
|
}),
|
|
2360
|
+
/**
|
|
2361
|
+
* Create a content field for headers, questions, or custom content between fields
|
|
2362
|
+
*
|
|
2363
|
+
* @example
|
|
2364
|
+
* ```tsx
|
|
2365
|
+
* // Simple header
|
|
2366
|
+
* FormFieldHelpers.content("Personal Information", "Please provide your details")
|
|
2367
|
+
*
|
|
2368
|
+
* // Custom render
|
|
2369
|
+
* FormFieldHelpers.content(null, null, {
|
|
2370
|
+
* render: () => <div>Custom content</div>
|
|
2371
|
+
* })
|
|
2372
|
+
* ```
|
|
2373
|
+
*/
|
|
2374
|
+
content: (title, description, options) => ({
|
|
2375
|
+
className: options?.className,
|
|
2376
|
+
description: description || void 0,
|
|
2377
|
+
name: options?.name,
|
|
2378
|
+
render: options?.render,
|
|
2379
|
+
title: title || void 0,
|
|
2380
|
+
type: "content"
|
|
2381
|
+
}),
|
|
2308
2382
|
/**
|
|
2309
2383
|
* Create a date field
|
|
2310
2384
|
*/
|
|
@@ -2537,6 +2611,16 @@ function fontPickerField(name, label, props) {
|
|
|
2537
2611
|
}
|
|
2538
2612
|
};
|
|
2539
2613
|
}
|
|
2614
|
+
function contentField(title, description, options) {
|
|
2615
|
+
return {
|
|
2616
|
+
className: options?.className,
|
|
2617
|
+
description: description || void 0,
|
|
2618
|
+
name: options?.name,
|
|
2619
|
+
render: options?.render,
|
|
2620
|
+
title: title || void 0,
|
|
2621
|
+
type: "content"
|
|
2622
|
+
};
|
|
2623
|
+
}
|
|
2540
2624
|
function createField(type, name, label, optionsOrProps, props) {
|
|
2541
2625
|
switch (type) {
|
|
2542
2626
|
case "input":
|
|
@@ -2559,6 +2643,22 @@ function createField(type, name, label, optionsOrProps, props) {
|
|
|
2559
2643
|
return fileField(name, label, optionsOrProps);
|
|
2560
2644
|
case "fontPicker":
|
|
2561
2645
|
return fontPickerField(name, label, optionsOrProps);
|
|
2646
|
+
case "content":
|
|
2647
|
+
if (typeof optionsOrProps === "string" || optionsOrProps === null) {
|
|
2648
|
+
return contentField(optionsOrProps, props);
|
|
2649
|
+
}
|
|
2650
|
+
if (typeof optionsOrProps === "object" && optionsOrProps !== null) {
|
|
2651
|
+
return contentField(
|
|
2652
|
+
optionsOrProps.title,
|
|
2653
|
+
optionsOrProps.description,
|
|
2654
|
+
optionsOrProps
|
|
2655
|
+
);
|
|
2656
|
+
}
|
|
2657
|
+
return contentField(
|
|
2658
|
+
name,
|
|
2659
|
+
label,
|
|
2660
|
+
optionsOrProps
|
|
2661
|
+
);
|
|
2562
2662
|
default:
|
|
2563
2663
|
throw new Error(`Unknown field type: ${type}`);
|
|
2564
2664
|
}
|
|
@@ -3449,6 +3549,7 @@ export {
|
|
|
3449
3549
|
CommonFields,
|
|
3450
3550
|
ConditionalField,
|
|
3451
3551
|
ConfigurableForm,
|
|
3552
|
+
ContentField,
|
|
3452
3553
|
DateField,
|
|
3453
3554
|
DynamicSectionField,
|
|
3454
3555
|
FieldArrayBuilder,
|