@rachelallyson/hero-hook-form 2.1.2 → 2.2.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/CHANGELOG.md +56 -3
- package/dist/index.d.ts +825 -16
- package/dist/index.js +238 -137
- package/dist/react/index.d.ts +825 -16
- package/dist/react/index.js +238 -137
- package/package.json +1 -1
package/dist/react/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
|
|
@@ -251,13 +251,30 @@ function ConditionalField({
|
|
|
251
251
|
));
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
-
// src/fields/
|
|
254
|
+
// src/fields/ContentField.tsx
|
|
255
255
|
import React4 from "react";
|
|
256
|
+
function ContentField({
|
|
257
|
+
config,
|
|
258
|
+
form,
|
|
259
|
+
submissionState
|
|
260
|
+
}) {
|
|
261
|
+
if (config.render) {
|
|
262
|
+
return /* @__PURE__ */ React4.createElement("div", { className: config.className }, config.render({
|
|
263
|
+
errors: form.formState.errors,
|
|
264
|
+
form,
|
|
265
|
+
isSubmitting: submissionState.isSubmitting
|
|
266
|
+
}));
|
|
267
|
+
}
|
|
268
|
+
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));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// src/fields/DateField.tsx
|
|
272
|
+
import React5 from "react";
|
|
256
273
|
import { Controller as Controller2 } from "react-hook-form";
|
|
257
274
|
function CoercedDateInput(props) {
|
|
258
275
|
const { dateProps, description, disabled, errorMessage, field: field2, label } = props;
|
|
259
276
|
const defaults = useHeroHookFormDefaults();
|
|
260
|
-
return /* @__PURE__ */
|
|
277
|
+
return /* @__PURE__ */ React5.createElement(
|
|
261
278
|
DateInput,
|
|
262
279
|
{
|
|
263
280
|
...defaults.dateInput,
|
|
@@ -285,12 +302,12 @@ function DateField(props) {
|
|
|
285
302
|
rules,
|
|
286
303
|
transform
|
|
287
304
|
} = props;
|
|
288
|
-
return /* @__PURE__ */
|
|
305
|
+
return /* @__PURE__ */ React5.createElement(
|
|
289
306
|
Controller2,
|
|
290
307
|
{
|
|
291
308
|
control,
|
|
292
309
|
name,
|
|
293
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
310
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React5.createElement("div", { className }, /* @__PURE__ */ React5.createElement(
|
|
294
311
|
CoercedDateInput,
|
|
295
312
|
{
|
|
296
313
|
dateProps,
|
|
@@ -310,7 +327,7 @@ function DateField(props) {
|
|
|
310
327
|
}
|
|
311
328
|
|
|
312
329
|
// src/fields/DynamicSectionField.tsx
|
|
313
|
-
import
|
|
330
|
+
import React6 from "react";
|
|
314
331
|
import { useWatch as useWatch2, useFormContext as useFormContext2 } from "react-hook-form";
|
|
315
332
|
function DynamicSectionField({
|
|
316
333
|
className,
|
|
@@ -324,7 +341,7 @@ function DynamicSectionField({
|
|
|
324
341
|
if (!shouldShow) {
|
|
325
342
|
return null;
|
|
326
343
|
}
|
|
327
|
-
return /* @__PURE__ */
|
|
344
|
+
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(
|
|
328
345
|
FormField,
|
|
329
346
|
{
|
|
330
347
|
key: `${fieldConfig.name}-${index}`,
|
|
@@ -341,7 +358,7 @@ function DynamicSectionField({
|
|
|
341
358
|
}
|
|
342
359
|
|
|
343
360
|
// src/fields/FieldArrayField.tsx
|
|
344
|
-
import
|
|
361
|
+
import React7 from "react";
|
|
345
362
|
import { useFieldArray, useFormContext as useFormContext3 } from "react-hook-form";
|
|
346
363
|
import { Button as Button2 } from "@heroui/react";
|
|
347
364
|
function FieldArrayField({
|
|
@@ -389,13 +406,13 @@ function FieldArrayField({
|
|
|
389
406
|
remove(index);
|
|
390
407
|
}
|
|
391
408
|
};
|
|
392
|
-
return /* @__PURE__ */
|
|
409
|
+
return /* @__PURE__ */ React7.createElement("div", { className }, /* @__PURE__ */ React7.createElement("div", { className: "space-y-4" }, fields.map((field2, index) => /* @__PURE__ */ React7.createElement(
|
|
393
410
|
"div",
|
|
394
411
|
{
|
|
395
412
|
key: field2.id,
|
|
396
413
|
className: "border border-gray-200 rounded-lg p-4 space-y-4"
|
|
397
414
|
},
|
|
398
|
-
/* @__PURE__ */
|
|
415
|
+
/* @__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(
|
|
399
416
|
Button2,
|
|
400
417
|
{
|
|
401
418
|
size: "sm",
|
|
@@ -407,7 +424,7 @@ function FieldArrayField({
|
|
|
407
424
|
},
|
|
408
425
|
removeButtonText
|
|
409
426
|
)),
|
|
410
|
-
/* @__PURE__ */
|
|
427
|
+
/* @__PURE__ */ React7.createElement("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4" }, fieldConfigs.map((fieldConfig) => /* @__PURE__ */ React7.createElement(
|
|
411
428
|
FormField,
|
|
412
429
|
{
|
|
413
430
|
key: `${fieldConfig.name}-${index}`,
|
|
@@ -424,7 +441,7 @@ function FieldArrayField({
|
|
|
424
441
|
}
|
|
425
442
|
}
|
|
426
443
|
)))
|
|
427
|
-
)), canAdd && /* @__PURE__ */
|
|
444
|
+
)), canAdd && /* @__PURE__ */ React7.createElement(
|
|
428
445
|
Button2,
|
|
429
446
|
{
|
|
430
447
|
variant: "bordered",
|
|
@@ -433,7 +450,7 @@ function FieldArrayField({
|
|
|
433
450
|
className: "w-full"
|
|
434
451
|
},
|
|
435
452
|
addButtonText
|
|
436
|
-
), fields.length === 0 && /* @__PURE__ */
|
|
453
|
+
), 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(
|
|
437
454
|
Button2,
|
|
438
455
|
{
|
|
439
456
|
variant: "bordered",
|
|
@@ -446,7 +463,7 @@ function FieldArrayField({
|
|
|
446
463
|
}
|
|
447
464
|
|
|
448
465
|
// src/fields/FileField.tsx
|
|
449
|
-
import
|
|
466
|
+
import React8 from "react";
|
|
450
467
|
import { Controller as Controller3 } from "react-hook-form";
|
|
451
468
|
function CoercedFileInput(props) {
|
|
452
469
|
const {
|
|
@@ -460,7 +477,7 @@ function CoercedFileInput(props) {
|
|
|
460
477
|
multiple
|
|
461
478
|
} = props;
|
|
462
479
|
const defaults = useHeroHookFormDefaults();
|
|
463
|
-
return /* @__PURE__ */
|
|
480
|
+
return /* @__PURE__ */ React8.createElement(
|
|
464
481
|
Input,
|
|
465
482
|
{
|
|
466
483
|
...defaults.input,
|
|
@@ -496,12 +513,12 @@ function FileField(props) {
|
|
|
496
513
|
rules,
|
|
497
514
|
transform
|
|
498
515
|
} = props;
|
|
499
|
-
return /* @__PURE__ */
|
|
516
|
+
return /* @__PURE__ */ React8.createElement(
|
|
500
517
|
Controller3,
|
|
501
518
|
{
|
|
502
519
|
control,
|
|
503
520
|
name,
|
|
504
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
521
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React8.createElement("div", { className }, /* @__PURE__ */ React8.createElement(
|
|
505
522
|
CoercedFileInput,
|
|
506
523
|
{
|
|
507
524
|
accept,
|
|
@@ -523,7 +540,7 @@ function FileField(props) {
|
|
|
523
540
|
}
|
|
524
541
|
|
|
525
542
|
// src/fields/FontPickerField.tsx
|
|
526
|
-
import
|
|
543
|
+
import React9 from "react";
|
|
527
544
|
import { Controller as Controller4 } from "react-hook-form";
|
|
528
545
|
var FontPickerComponent = null;
|
|
529
546
|
var fontPickerLoaded = false;
|
|
@@ -540,12 +557,12 @@ function FontPickerField(props) {
|
|
|
540
557
|
name,
|
|
541
558
|
rules
|
|
542
559
|
} = props;
|
|
543
|
-
const [fontPickerState, setFontPickerState] =
|
|
560
|
+
const [fontPickerState, setFontPickerState] = React9.useState({
|
|
544
561
|
component: FontPickerComponent,
|
|
545
562
|
error: null,
|
|
546
563
|
loading: false
|
|
547
564
|
});
|
|
548
|
-
|
|
565
|
+
React9.useEffect(() => {
|
|
549
566
|
if (fontPickerLoaded && FontPickerComponent) {
|
|
550
567
|
setFontPickerState({
|
|
551
568
|
component: FontPickerComponent,
|
|
@@ -603,17 +620,17 @@ function FontPickerField(props) {
|
|
|
603
620
|
void loadFontPicker();
|
|
604
621
|
}, []);
|
|
605
622
|
if (fontPickerState.loading) {
|
|
606
|
-
return /* @__PURE__ */
|
|
623
|
+
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..."))));
|
|
607
624
|
}
|
|
608
625
|
if (!fontPickerState.component) {
|
|
609
|
-
return /* @__PURE__ */
|
|
626
|
+
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."))));
|
|
610
627
|
}
|
|
611
|
-
return /* @__PURE__ */
|
|
628
|
+
return /* @__PURE__ */ React9.createElement(
|
|
612
629
|
Controller4,
|
|
613
630
|
{
|
|
614
631
|
control,
|
|
615
632
|
name,
|
|
616
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
633
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React9.createElement(
|
|
617
634
|
fontPickerState.component,
|
|
618
635
|
{
|
|
619
636
|
label,
|
|
@@ -632,12 +649,12 @@ function FontPickerField(props) {
|
|
|
632
649
|
}
|
|
633
650
|
|
|
634
651
|
// src/fields/InputField.tsx
|
|
635
|
-
import
|
|
652
|
+
import React10 from "react";
|
|
636
653
|
import { Controller as Controller5 } from "react-hook-form";
|
|
637
654
|
function CoercedInput(props) {
|
|
638
655
|
const { description, disabled, errorMessage, field: field2, inputProps, label } = props;
|
|
639
656
|
const defaults = useHeroHookFormDefaults();
|
|
640
|
-
return /* @__PURE__ */
|
|
657
|
+
return /* @__PURE__ */ React10.createElement(
|
|
641
658
|
Input,
|
|
642
659
|
{
|
|
643
660
|
...defaults.input,
|
|
@@ -653,7 +670,7 @@ function CoercedInput(props) {
|
|
|
653
670
|
}
|
|
654
671
|
);
|
|
655
672
|
}
|
|
656
|
-
var InputField =
|
|
673
|
+
var InputField = React10.memo(
|
|
657
674
|
(props) => {
|
|
658
675
|
const {
|
|
659
676
|
className,
|
|
@@ -666,12 +683,12 @@ var InputField = React9.memo(
|
|
|
666
683
|
rules,
|
|
667
684
|
transform
|
|
668
685
|
} = props;
|
|
669
|
-
return /* @__PURE__ */
|
|
686
|
+
return /* @__PURE__ */ React10.createElement(
|
|
670
687
|
Controller5,
|
|
671
688
|
{
|
|
672
689
|
control,
|
|
673
690
|
name,
|
|
674
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
691
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React10.createElement("div", { className }, /* @__PURE__ */ React10.createElement(
|
|
675
692
|
CoercedInput,
|
|
676
693
|
{
|
|
677
694
|
description,
|
|
@@ -701,7 +718,7 @@ var InputField = React9.memo(
|
|
|
701
718
|
);
|
|
702
719
|
|
|
703
720
|
// src/fields/RadioGroupField.tsx
|
|
704
|
-
import
|
|
721
|
+
import React11 from "react";
|
|
705
722
|
import { Controller as Controller6 } from "react-hook-form";
|
|
706
723
|
function RadioGroupField(props) {
|
|
707
724
|
const {
|
|
@@ -716,12 +733,12 @@ function RadioGroupField(props) {
|
|
|
716
733
|
rules
|
|
717
734
|
} = props;
|
|
718
735
|
const defaults = useHeroHookFormDefaults();
|
|
719
|
-
return /* @__PURE__ */
|
|
736
|
+
return /* @__PURE__ */ React11.createElement(
|
|
720
737
|
Controller6,
|
|
721
738
|
{
|
|
722
739
|
control,
|
|
723
740
|
name,
|
|
724
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
741
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React11.createElement("div", { className }, /* @__PURE__ */ React11.createElement(
|
|
725
742
|
RadioGroup,
|
|
726
743
|
{
|
|
727
744
|
...defaults.radioGroup,
|
|
@@ -734,7 +751,7 @@ function RadioGroupField(props) {
|
|
|
734
751
|
onBlur: field2.onBlur,
|
|
735
752
|
onValueChange: (val) => field2.onChange(val)
|
|
736
753
|
},
|
|
737
|
-
options.map((opt) => /* @__PURE__ */
|
|
754
|
+
options.map((opt) => /* @__PURE__ */ React11.createElement(
|
|
738
755
|
Radio,
|
|
739
756
|
{
|
|
740
757
|
key: String(opt.value),
|
|
@@ -743,14 +760,14 @@ function RadioGroupField(props) {
|
|
|
743
760
|
},
|
|
744
761
|
opt.label
|
|
745
762
|
))
|
|
746
|
-
), fieldState.error?.message ? /* @__PURE__ */
|
|
763
|
+
), fieldState.error?.message ? /* @__PURE__ */ React11.createElement("p", { className: "text-tiny text-danger mt-1" }, fieldState.error.message) : null),
|
|
747
764
|
rules
|
|
748
765
|
}
|
|
749
766
|
);
|
|
750
767
|
}
|
|
751
768
|
|
|
752
769
|
// src/fields/SelectField.tsx
|
|
753
|
-
import
|
|
770
|
+
import React12 from "react";
|
|
754
771
|
import { Controller as Controller7 } from "react-hook-form";
|
|
755
772
|
function SelectField(props) {
|
|
756
773
|
const {
|
|
@@ -766,14 +783,14 @@ function SelectField(props) {
|
|
|
766
783
|
selectProps
|
|
767
784
|
} = props;
|
|
768
785
|
const defaults = useHeroHookFormDefaults();
|
|
769
|
-
return /* @__PURE__ */
|
|
786
|
+
return /* @__PURE__ */ React12.createElement(
|
|
770
787
|
Controller7,
|
|
771
788
|
{
|
|
772
789
|
control,
|
|
773
790
|
name,
|
|
774
791
|
render: ({ field: field2, fieldState }) => {
|
|
775
792
|
const selectedKey = field2.value;
|
|
776
|
-
return /* @__PURE__ */
|
|
793
|
+
return /* @__PURE__ */ React12.createElement("div", { className }, /* @__PURE__ */ React12.createElement(
|
|
777
794
|
Select,
|
|
778
795
|
{
|
|
779
796
|
...defaults.select,
|
|
@@ -791,7 +808,7 @@ function SelectField(props) {
|
|
|
791
808
|
field2.onChange(next);
|
|
792
809
|
}
|
|
793
810
|
},
|
|
794
|
-
options.map((opt) => /* @__PURE__ */
|
|
811
|
+
options.map((opt) => /* @__PURE__ */ React12.createElement(
|
|
795
812
|
SelectItem,
|
|
796
813
|
{
|
|
797
814
|
key: String(opt.value),
|
|
@@ -808,12 +825,12 @@ function SelectField(props) {
|
|
|
808
825
|
}
|
|
809
826
|
|
|
810
827
|
// src/fields/SliderField.tsx
|
|
811
|
-
import
|
|
828
|
+
import React13 from "react";
|
|
812
829
|
import { Controller as Controller8 } from "react-hook-form";
|
|
813
830
|
function CoercedSlider(props) {
|
|
814
831
|
const { description, disabled, errorMessage, field: field2, label, sliderProps } = props;
|
|
815
832
|
const defaults = useHeroHookFormDefaults();
|
|
816
|
-
return /* @__PURE__ */
|
|
833
|
+
return /* @__PURE__ */ React13.createElement(
|
|
817
834
|
Slider,
|
|
818
835
|
{
|
|
819
836
|
...defaults.slider,
|
|
@@ -841,12 +858,12 @@ function SliderField(props) {
|
|
|
841
858
|
sliderProps,
|
|
842
859
|
transform
|
|
843
860
|
} = props;
|
|
844
|
-
return /* @__PURE__ */
|
|
861
|
+
return /* @__PURE__ */ React13.createElement(
|
|
845
862
|
Controller8,
|
|
846
863
|
{
|
|
847
864
|
control,
|
|
848
865
|
name,
|
|
849
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
866
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React13.createElement("div", { className }, /* @__PURE__ */ React13.createElement(
|
|
850
867
|
CoercedSlider,
|
|
851
868
|
{
|
|
852
869
|
description,
|
|
@@ -866,7 +883,7 @@ function SliderField(props) {
|
|
|
866
883
|
}
|
|
867
884
|
|
|
868
885
|
// src/fields/SwitchField.tsx
|
|
869
|
-
import
|
|
886
|
+
import React14 from "react";
|
|
870
887
|
import { Controller as Controller9 } from "react-hook-form";
|
|
871
888
|
function SwitchField(props) {
|
|
872
889
|
const {
|
|
@@ -880,12 +897,12 @@ function SwitchField(props) {
|
|
|
880
897
|
switchProps
|
|
881
898
|
} = props;
|
|
882
899
|
const defaults = useHeroHookFormDefaults();
|
|
883
|
-
return /* @__PURE__ */
|
|
900
|
+
return /* @__PURE__ */ React14.createElement(
|
|
884
901
|
Controller9,
|
|
885
902
|
{
|
|
886
903
|
control,
|
|
887
904
|
name,
|
|
888
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
905
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React14.createElement("div", { className }, /* @__PURE__ */ React14.createElement(
|
|
889
906
|
Switch,
|
|
890
907
|
{
|
|
891
908
|
...defaults.switch,
|
|
@@ -896,14 +913,14 @@ function SwitchField(props) {
|
|
|
896
913
|
onValueChange: (val) => field2.onChange(val)
|
|
897
914
|
},
|
|
898
915
|
label
|
|
899
|
-
), description ? /* @__PURE__ */
|
|
916
|
+
), 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),
|
|
900
917
|
rules
|
|
901
918
|
}
|
|
902
919
|
);
|
|
903
920
|
}
|
|
904
921
|
|
|
905
922
|
// src/fields/TextareaField.tsx
|
|
906
|
-
import
|
|
923
|
+
import React15 from "react";
|
|
907
924
|
import { Controller as Controller10 } from "react-hook-form";
|
|
908
925
|
function TextareaField(props) {
|
|
909
926
|
const {
|
|
@@ -917,12 +934,12 @@ function TextareaField(props) {
|
|
|
917
934
|
textareaProps
|
|
918
935
|
} = props;
|
|
919
936
|
const defaults = useHeroHookFormDefaults();
|
|
920
|
-
return /* @__PURE__ */
|
|
937
|
+
return /* @__PURE__ */ React15.createElement(
|
|
921
938
|
Controller10,
|
|
922
939
|
{
|
|
923
940
|
control,
|
|
924
941
|
name,
|
|
925
|
-
render: ({ field: field2, fieldState }) => /* @__PURE__ */
|
|
942
|
+
render: ({ field: field2, fieldState }) => /* @__PURE__ */ React15.createElement("div", { className }, /* @__PURE__ */ React15.createElement(
|
|
926
943
|
Textarea,
|
|
927
944
|
{
|
|
928
945
|
...defaults.textarea,
|
|
@@ -943,7 +960,7 @@ function TextareaField(props) {
|
|
|
943
960
|
}
|
|
944
961
|
|
|
945
962
|
// src/components/FormField.tsx
|
|
946
|
-
var FormField =
|
|
963
|
+
var FormField = React16.memo(
|
|
947
964
|
({
|
|
948
965
|
config,
|
|
949
966
|
form,
|
|
@@ -954,6 +971,16 @@ var FormField = React15.memo(
|
|
|
954
971
|
}
|
|
955
972
|
const { control } = form;
|
|
956
973
|
const watchedValues = useWatch3({ control });
|
|
974
|
+
if (config.type === "content") {
|
|
975
|
+
return /* @__PURE__ */ React16.createElement(
|
|
976
|
+
ContentField,
|
|
977
|
+
{
|
|
978
|
+
config,
|
|
979
|
+
form,
|
|
980
|
+
submissionState
|
|
981
|
+
}
|
|
982
|
+
);
|
|
983
|
+
}
|
|
957
984
|
if (config.condition && !config.condition(watchedValues)) {
|
|
958
985
|
return null;
|
|
959
986
|
}
|
|
@@ -975,7 +1002,7 @@ var FormField = React15.memo(
|
|
|
975
1002
|
};
|
|
976
1003
|
switch (config.type) {
|
|
977
1004
|
case "input":
|
|
978
|
-
return /* @__PURE__ */
|
|
1005
|
+
return /* @__PURE__ */ React16.createElement(
|
|
979
1006
|
InputField,
|
|
980
1007
|
{
|
|
981
1008
|
...baseProps,
|
|
@@ -985,7 +1012,7 @@ var FormField = React15.memo(
|
|
|
985
1012
|
}
|
|
986
1013
|
);
|
|
987
1014
|
case "textarea":
|
|
988
|
-
return /* @__PURE__ */
|
|
1015
|
+
return /* @__PURE__ */ React16.createElement(
|
|
989
1016
|
TextareaField,
|
|
990
1017
|
{
|
|
991
1018
|
...baseProps,
|
|
@@ -995,7 +1022,7 @@ var FormField = React15.memo(
|
|
|
995
1022
|
}
|
|
996
1023
|
);
|
|
997
1024
|
case "select":
|
|
998
|
-
return /* @__PURE__ */
|
|
1025
|
+
return /* @__PURE__ */ React16.createElement(
|
|
999
1026
|
SelectField,
|
|
1000
1027
|
{
|
|
1001
1028
|
...baseProps,
|
|
@@ -1009,7 +1036,7 @@ var FormField = React15.memo(
|
|
|
1009
1036
|
}
|
|
1010
1037
|
);
|
|
1011
1038
|
case "checkbox":
|
|
1012
|
-
return /* @__PURE__ */
|
|
1039
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1013
1040
|
CheckboxField,
|
|
1014
1041
|
{
|
|
1015
1042
|
...baseProps,
|
|
@@ -1019,7 +1046,7 @@ var FormField = React15.memo(
|
|
|
1019
1046
|
}
|
|
1020
1047
|
);
|
|
1021
1048
|
case "radio":
|
|
1022
|
-
return /* @__PURE__ */
|
|
1049
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1023
1050
|
RadioGroupField,
|
|
1024
1051
|
{
|
|
1025
1052
|
...baseProps,
|
|
@@ -1033,7 +1060,7 @@ var FormField = React15.memo(
|
|
|
1033
1060
|
}
|
|
1034
1061
|
);
|
|
1035
1062
|
case "switch":
|
|
1036
|
-
return /* @__PURE__ */
|
|
1063
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1037
1064
|
SwitchField,
|
|
1038
1065
|
{
|
|
1039
1066
|
...baseProps,
|
|
@@ -1043,7 +1070,7 @@ var FormField = React15.memo(
|
|
|
1043
1070
|
}
|
|
1044
1071
|
);
|
|
1045
1072
|
case "slider":
|
|
1046
|
-
return /* @__PURE__ */
|
|
1073
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1047
1074
|
SliderField,
|
|
1048
1075
|
{
|
|
1049
1076
|
...baseProps,
|
|
@@ -1053,7 +1080,7 @@ var FormField = React15.memo(
|
|
|
1053
1080
|
}
|
|
1054
1081
|
);
|
|
1055
1082
|
case "date":
|
|
1056
|
-
return /* @__PURE__ */
|
|
1083
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1057
1084
|
DateField,
|
|
1058
1085
|
{
|
|
1059
1086
|
...baseProps,
|
|
@@ -1063,7 +1090,7 @@ var FormField = React15.memo(
|
|
|
1063
1090
|
}
|
|
1064
1091
|
);
|
|
1065
1092
|
case "file":
|
|
1066
|
-
return /* @__PURE__ */
|
|
1093
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1067
1094
|
FileField,
|
|
1068
1095
|
{
|
|
1069
1096
|
...baseProps,
|
|
@@ -1075,7 +1102,7 @@ var FormField = React15.memo(
|
|
|
1075
1102
|
}
|
|
1076
1103
|
);
|
|
1077
1104
|
case "fontPicker":
|
|
1078
|
-
return /* @__PURE__ */
|
|
1105
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1079
1106
|
FontPickerField,
|
|
1080
1107
|
{
|
|
1081
1108
|
...baseProps,
|
|
@@ -1093,7 +1120,7 @@ var FormField = React15.memo(
|
|
|
1093
1120
|
name: config.name
|
|
1094
1121
|
});
|
|
1095
1122
|
case "conditional":
|
|
1096
|
-
return /* @__PURE__ */
|
|
1123
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1097
1124
|
ConditionalField,
|
|
1098
1125
|
{
|
|
1099
1126
|
config,
|
|
@@ -1102,7 +1129,7 @@ var FormField = React15.memo(
|
|
|
1102
1129
|
}
|
|
1103
1130
|
);
|
|
1104
1131
|
case "fieldArray":
|
|
1105
|
-
return /* @__PURE__ */
|
|
1132
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1106
1133
|
FieldArrayField,
|
|
1107
1134
|
{
|
|
1108
1135
|
config,
|
|
@@ -1110,7 +1137,7 @@ var FormField = React15.memo(
|
|
|
1110
1137
|
}
|
|
1111
1138
|
);
|
|
1112
1139
|
case "dynamicSection":
|
|
1113
|
-
return /* @__PURE__ */
|
|
1140
|
+
return /* @__PURE__ */ React16.createElement(
|
|
1114
1141
|
DynamicSectionField,
|
|
1115
1142
|
{
|
|
1116
1143
|
config,
|
|
@@ -1162,12 +1189,12 @@ function ConfigurableForm({
|
|
|
1162
1189
|
});
|
|
1163
1190
|
const renderFields = () => {
|
|
1164
1191
|
if (layout === "grid") {
|
|
1165
|
-
return /* @__PURE__ */
|
|
1192
|
+
return /* @__PURE__ */ React17.createElement(
|
|
1166
1193
|
"div",
|
|
1167
1194
|
{
|
|
1168
1195
|
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"}`
|
|
1169
1196
|
},
|
|
1170
|
-
fields.map((field2) => /* @__PURE__ */
|
|
1197
|
+
fields.map((field2) => /* @__PURE__ */ React17.createElement(
|
|
1171
1198
|
FormField,
|
|
1172
1199
|
{
|
|
1173
1200
|
key: field2.name,
|
|
@@ -1179,7 +1206,7 @@ function ConfigurableForm({
|
|
|
1179
1206
|
);
|
|
1180
1207
|
}
|
|
1181
1208
|
if (layout === "horizontal") {
|
|
1182
|
-
return /* @__PURE__ */
|
|
1209
|
+
return /* @__PURE__ */ React17.createElement("div", { className: `grid gap-${spacing} grid-cols-1 md:grid-cols-2` }, fields.map((field2) => /* @__PURE__ */ React17.createElement(
|
|
1183
1210
|
FormField,
|
|
1184
1211
|
{
|
|
1185
1212
|
key: field2.name,
|
|
@@ -1189,7 +1216,7 @@ function ConfigurableForm({
|
|
|
1189
1216
|
}
|
|
1190
1217
|
)));
|
|
1191
1218
|
}
|
|
1192
|
-
return /* @__PURE__ */
|
|
1219
|
+
return /* @__PURE__ */ React17.createElement("div", { className: `space-y-${spacing}` }, fields.map((field2) => /* @__PURE__ */ React17.createElement(
|
|
1193
1220
|
FormField,
|
|
1194
1221
|
{
|
|
1195
1222
|
key: field2.name,
|
|
@@ -1203,23 +1230,23 @@ function ConfigurableForm({
|
|
|
1203
1230
|
e.preventDefault();
|
|
1204
1231
|
void handleSubmit();
|
|
1205
1232
|
};
|
|
1206
|
-
return /* @__PURE__ */
|
|
1233
|
+
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(
|
|
1207
1234
|
"div",
|
|
1208
1235
|
{
|
|
1209
1236
|
className: "mb-6 p-4 bg-success-50 border border-success-200 rounded-lg",
|
|
1210
1237
|
"data-testid": "success-message"
|
|
1211
1238
|
},
|
|
1212
|
-
/* @__PURE__ */
|
|
1213
|
-
/* @__PURE__ */
|
|
1214
|
-
), error && /* @__PURE__ */
|
|
1239
|
+
/* @__PURE__ */ React17.createElement("p", { className: "text-success-800 font-medium" }, "Success!"),
|
|
1240
|
+
/* @__PURE__ */ React17.createElement("p", { className: "text-success-700 text-sm mt-1" }, "Your request has been processed successfully.")
|
|
1241
|
+
), error && /* @__PURE__ */ React17.createElement(
|
|
1215
1242
|
"div",
|
|
1216
1243
|
{
|
|
1217
1244
|
className: "mb-6 p-4 bg-danger-50 border border-danger-200 rounded-lg",
|
|
1218
1245
|
"data-testid": "error-message"
|
|
1219
1246
|
},
|
|
1220
|
-
/* @__PURE__ */
|
|
1221
|
-
/* @__PURE__ */
|
|
1222
|
-
), renderFields(), /* @__PURE__ */
|
|
1247
|
+
/* @__PURE__ */ React17.createElement("p", { className: "text-danger-800 font-medium" }, "Error"),
|
|
1248
|
+
/* @__PURE__ */ React17.createElement("p", { className: "text-danger-700 text-sm mt-1" }, error)
|
|
1249
|
+
), renderFields(), /* @__PURE__ */ React17.createElement("div", { className: "mt-6 flex gap-3 justify-end" }, /* @__PURE__ */ React17.createElement(
|
|
1223
1250
|
Button3,
|
|
1224
1251
|
{
|
|
1225
1252
|
color: "primary",
|
|
@@ -1229,7 +1256,7 @@ function ConfigurableForm({
|
|
|
1229
1256
|
...submitButtonProps
|
|
1230
1257
|
},
|
|
1231
1258
|
submitButtonText
|
|
1232
|
-
), showResetButton && /* @__PURE__ */
|
|
1259
|
+
), showResetButton && /* @__PURE__ */ React17.createElement(
|
|
1233
1260
|
Button3,
|
|
1234
1261
|
{
|
|
1235
1262
|
isDisabled: isSubmitting,
|
|
@@ -1242,7 +1269,7 @@ function ConfigurableForm({
|
|
|
1242
1269
|
}
|
|
1243
1270
|
|
|
1244
1271
|
// src/components/ServerActionForm.tsx
|
|
1245
|
-
import
|
|
1272
|
+
import React18 from "react";
|
|
1246
1273
|
import { useActionState } from "react";
|
|
1247
1274
|
function ServerActionForm({
|
|
1248
1275
|
action,
|
|
@@ -1267,10 +1294,10 @@ function ServerActionForm({
|
|
|
1267
1294
|
action,
|
|
1268
1295
|
initialState ?? { errors: void 0, message: void 0, success: false }
|
|
1269
1296
|
);
|
|
1270
|
-
const formRef =
|
|
1271
|
-
const [clientErrors, setClientErrors] =
|
|
1272
|
-
const lastSubmittedFormData =
|
|
1273
|
-
|
|
1297
|
+
const formRef = React18.useRef(null);
|
|
1298
|
+
const [clientErrors, setClientErrors] = React18.useState({});
|
|
1299
|
+
const lastSubmittedFormData = React18.useRef(null);
|
|
1300
|
+
React18.useEffect(() => {
|
|
1274
1301
|
if (state && (state.errors || state.message && !state.success)) {
|
|
1275
1302
|
onError?.({
|
|
1276
1303
|
errors: state.errors,
|
|
@@ -1278,7 +1305,7 @@ function ServerActionForm({
|
|
|
1278
1305
|
});
|
|
1279
1306
|
}
|
|
1280
1307
|
}, [state, onError]);
|
|
1281
|
-
|
|
1308
|
+
React18.useEffect(() => {
|
|
1282
1309
|
if (state?.success && lastSubmittedFormData.current) {
|
|
1283
1310
|
onSuccess?.(lastSubmittedFormData.current);
|
|
1284
1311
|
}
|
|
@@ -1321,12 +1348,12 @@ function ServerActionForm({
|
|
|
1321
1348
|
};
|
|
1322
1349
|
const renderFields = () => {
|
|
1323
1350
|
if (layout === "grid") {
|
|
1324
|
-
return /* @__PURE__ */
|
|
1351
|
+
return /* @__PURE__ */ React18.createElement(
|
|
1325
1352
|
"div",
|
|
1326
1353
|
{
|
|
1327
1354
|
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"}`
|
|
1328
1355
|
},
|
|
1329
|
-
fields.map((field2) => /* @__PURE__ */
|
|
1356
|
+
fields.map((field2) => /* @__PURE__ */ React18.createElement(
|
|
1330
1357
|
ServerActionField,
|
|
1331
1358
|
{
|
|
1332
1359
|
key: field2.name,
|
|
@@ -1339,7 +1366,7 @@ function ServerActionForm({
|
|
|
1339
1366
|
);
|
|
1340
1367
|
}
|
|
1341
1368
|
if (layout === "horizontal") {
|
|
1342
|
-
return /* @__PURE__ */
|
|
1369
|
+
return /* @__PURE__ */ React18.createElement("div", { className: `grid gap-${spacing} grid-cols-1 md:grid-cols-2` }, fields.map((field2) => /* @__PURE__ */ React18.createElement(
|
|
1343
1370
|
ServerActionField,
|
|
1344
1371
|
{
|
|
1345
1372
|
key: field2.name,
|
|
@@ -1350,7 +1377,7 @@ function ServerActionForm({
|
|
|
1350
1377
|
}
|
|
1351
1378
|
)));
|
|
1352
1379
|
}
|
|
1353
|
-
return /* @__PURE__ */
|
|
1380
|
+
return /* @__PURE__ */ React18.createElement("div", { className: `space-y-${spacing}` }, fields.map((field2) => /* @__PURE__ */ React18.createElement(
|
|
1354
1381
|
ServerActionField,
|
|
1355
1382
|
{
|
|
1356
1383
|
key: field2.name,
|
|
@@ -1361,7 +1388,7 @@ function ServerActionForm({
|
|
|
1361
1388
|
}
|
|
1362
1389
|
)));
|
|
1363
1390
|
};
|
|
1364
|
-
return /* @__PURE__ */
|
|
1391
|
+
return /* @__PURE__ */ React18.createElement(
|
|
1365
1392
|
"form",
|
|
1366
1393
|
{
|
|
1367
1394
|
ref: formRef,
|
|
@@ -1369,27 +1396,27 @@ function ServerActionForm({
|
|
|
1369
1396
|
role: "form",
|
|
1370
1397
|
onSubmit: handleSubmit
|
|
1371
1398
|
},
|
|
1372
|
-
title && /* @__PURE__ */
|
|
1373
|
-
state?.success && !pending && /* @__PURE__ */
|
|
1399
|
+
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)),
|
|
1400
|
+
state?.success && !pending && /* @__PURE__ */ React18.createElement(
|
|
1374
1401
|
"div",
|
|
1375
1402
|
{
|
|
1376
1403
|
className: "mb-6 p-4 bg-success-50 border border-success-200 rounded-lg",
|
|
1377
1404
|
"data-testid": "success-message"
|
|
1378
1405
|
},
|
|
1379
|
-
/* @__PURE__ */
|
|
1380
|
-
state.message && /* @__PURE__ */
|
|
1406
|
+
/* @__PURE__ */ React18.createElement("p", { className: "text-success-800 font-medium" }, "Success!"),
|
|
1407
|
+
state.message && /* @__PURE__ */ React18.createElement("p", { className: "text-success-700 text-sm mt-1" }, state.message)
|
|
1381
1408
|
),
|
|
1382
|
-
state?.message && !state.success && /* @__PURE__ */
|
|
1409
|
+
state?.message && !state.success && /* @__PURE__ */ React18.createElement(
|
|
1383
1410
|
"div",
|
|
1384
1411
|
{
|
|
1385
1412
|
className: "mb-6 p-4 bg-danger-50 border border-danger-200 rounded-lg",
|
|
1386
1413
|
"data-testid": "error-message"
|
|
1387
1414
|
},
|
|
1388
|
-
/* @__PURE__ */
|
|
1389
|
-
/* @__PURE__ */
|
|
1415
|
+
/* @__PURE__ */ React18.createElement("p", { className: "text-danger-800 font-medium" }, "Error"),
|
|
1416
|
+
/* @__PURE__ */ React18.createElement("p", { className: "text-danger-700 text-sm mt-1" }, state.message)
|
|
1390
1417
|
),
|
|
1391
1418
|
renderFields(),
|
|
1392
|
-
/* @__PURE__ */
|
|
1419
|
+
/* @__PURE__ */ React18.createElement("div", { className: "mt-6 flex gap-3 justify-end" }, /* @__PURE__ */ React18.createElement(
|
|
1393
1420
|
Button,
|
|
1394
1421
|
{
|
|
1395
1422
|
color: "primary",
|
|
@@ -1399,7 +1426,7 @@ function ServerActionForm({
|
|
|
1399
1426
|
...submitButtonProps
|
|
1400
1427
|
},
|
|
1401
1428
|
submitButtonText
|
|
1402
|
-
), showResetButton && /* @__PURE__ */
|
|
1429
|
+
), showResetButton && /* @__PURE__ */ React18.createElement(
|
|
1403
1430
|
Button,
|
|
1404
1431
|
{
|
|
1405
1432
|
isDisabled: pending,
|
|
@@ -1417,6 +1444,17 @@ function ServerActionField({
|
|
|
1417
1444
|
errors,
|
|
1418
1445
|
field: field2
|
|
1419
1446
|
}) {
|
|
1447
|
+
if (field2.type === "content") {
|
|
1448
|
+
const contentField2 = field2;
|
|
1449
|
+
if (contentField2.render) {
|
|
1450
|
+
return /* @__PURE__ */ React18.createElement("div", { className: contentField2.className }, contentField2.render({
|
|
1451
|
+
errors: {},
|
|
1452
|
+
form: null,
|
|
1453
|
+
isSubmitting: false
|
|
1454
|
+
}));
|
|
1455
|
+
}
|
|
1456
|
+
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));
|
|
1457
|
+
}
|
|
1420
1458
|
const fieldName = field2.name;
|
|
1421
1459
|
const fieldErrors = errors?.[fieldName];
|
|
1422
1460
|
const clientError = clientErrors?.[fieldName];
|
|
@@ -1443,9 +1481,9 @@ function ServerActionField({
|
|
|
1443
1481
|
}
|
|
1444
1482
|
return false;
|
|
1445
1483
|
};
|
|
1446
|
-
const [value, setValue] =
|
|
1447
|
-
const [checked, setChecked] =
|
|
1448
|
-
|
|
1484
|
+
const [value, setValue] = React18.useState(getDefaultValue);
|
|
1485
|
+
const [checked, setChecked] = React18.useState(getDefaultChecked);
|
|
1486
|
+
React18.useEffect(() => {
|
|
1449
1487
|
const newDefaultValue = defaultValues?.[fieldName];
|
|
1450
1488
|
if (newDefaultValue !== void 0 && newDefaultValue !== null) {
|
|
1451
1489
|
if (field2.type === "checkbox") {
|
|
@@ -1459,7 +1497,7 @@ function ServerActionField({
|
|
|
1459
1497
|
}
|
|
1460
1498
|
}
|
|
1461
1499
|
}, [defaultValues, fieldName, field2.type]);
|
|
1462
|
-
|
|
1500
|
+
React18.useEffect(() => {
|
|
1463
1501
|
const hiddenInput = document.querySelector(
|
|
1464
1502
|
`input[type="hidden"][name="${fieldName}"]`
|
|
1465
1503
|
);
|
|
@@ -1474,7 +1512,7 @@ function ServerActionField({
|
|
|
1474
1512
|
switch (field2.type) {
|
|
1475
1513
|
case "input": {
|
|
1476
1514
|
const inputType = field2.inputProps?.type || "text";
|
|
1477
|
-
return /* @__PURE__ */
|
|
1515
|
+
return /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React18.createElement(
|
|
1478
1516
|
Input,
|
|
1479
1517
|
{
|
|
1480
1518
|
...field2.inputProps,
|
|
@@ -1491,7 +1529,7 @@ function ServerActionField({
|
|
|
1491
1529
|
));
|
|
1492
1530
|
}
|
|
1493
1531
|
case "textarea": {
|
|
1494
|
-
return /* @__PURE__ */
|
|
1532
|
+
return /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React18.createElement(
|
|
1495
1533
|
Textarea,
|
|
1496
1534
|
{
|
|
1497
1535
|
...field2.textareaProps,
|
|
@@ -1507,7 +1545,7 @@ function ServerActionField({
|
|
|
1507
1545
|
));
|
|
1508
1546
|
}
|
|
1509
1547
|
case "checkbox": {
|
|
1510
|
-
return /* @__PURE__ */
|
|
1548
|
+
return /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement("input", { type: "hidden", name: fieldName, value: checked ? "on" : "" }), /* @__PURE__ */ React18.createElement(
|
|
1511
1549
|
Checkbox,
|
|
1512
1550
|
{
|
|
1513
1551
|
...field2.checkboxProps,
|
|
@@ -1523,7 +1561,7 @@ function ServerActionField({
|
|
|
1523
1561
|
}
|
|
1524
1562
|
case "select": {
|
|
1525
1563
|
const options = field2.options || [];
|
|
1526
|
-
return /* @__PURE__ */
|
|
1564
|
+
return /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React18.createElement(
|
|
1527
1565
|
Select,
|
|
1528
1566
|
{
|
|
1529
1567
|
...field2.selectProps,
|
|
@@ -1540,12 +1578,12 @@ function ServerActionField({
|
|
|
1540
1578
|
}
|
|
1541
1579
|
},
|
|
1542
1580
|
options.map(
|
|
1543
|
-
(option) => /* @__PURE__ */
|
|
1581
|
+
(option) => /* @__PURE__ */ React18.createElement(SelectItem, { key: String(option.value) }, option.label)
|
|
1544
1582
|
)
|
|
1545
1583
|
));
|
|
1546
1584
|
}
|
|
1547
1585
|
default:
|
|
1548
|
-
return /* @__PURE__ */
|
|
1586
|
+
return /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement("input", { type: "hidden", name: fieldName, value }), /* @__PURE__ */ React18.createElement(
|
|
1549
1587
|
Input,
|
|
1550
1588
|
{
|
|
1551
1589
|
"data-field-name": fieldName,
|
|
@@ -1575,10 +1613,10 @@ function useHeroForm() {
|
|
|
1575
1613
|
}
|
|
1576
1614
|
|
|
1577
1615
|
// src/providers/FormProvider.tsx
|
|
1578
|
-
import
|
|
1616
|
+
import React19 from "react";
|
|
1579
1617
|
import { FormProvider as RHFProvider } from "react-hook-form";
|
|
1580
1618
|
function FormProvider(props) {
|
|
1581
|
-
return /* @__PURE__ */
|
|
1619
|
+
return /* @__PURE__ */ React19.createElement(RHFProvider, { ...props.methods }, /* @__PURE__ */ React19.createElement(
|
|
1582
1620
|
"form",
|
|
1583
1621
|
{
|
|
1584
1622
|
className: props.className,
|
|
@@ -1591,7 +1629,7 @@ function FormProvider(props) {
|
|
|
1591
1629
|
}
|
|
1592
1630
|
|
|
1593
1631
|
// src/submit/SubmitButton.tsx
|
|
1594
|
-
import
|
|
1632
|
+
import React20 from "react";
|
|
1595
1633
|
function SubmitButton(props) {
|
|
1596
1634
|
const ctx = useFormContext5();
|
|
1597
1635
|
const loading = props.isLoading ?? ctx.formState.isSubmitting;
|
|
@@ -1601,10 +1639,10 @@ function SubmitButton(props) {
|
|
|
1601
1639
|
const defaults = useHeroHookFormDefaults();
|
|
1602
1640
|
const getButtonContent = () => {
|
|
1603
1641
|
if (enhancedState?.isSuccess) {
|
|
1604
|
-
return /* @__PURE__ */
|
|
1642
|
+
return /* @__PURE__ */ React20.createElement("span", { className: "inline-flex items-center gap-2" }, "\u2705", props.successText || "Success!");
|
|
1605
1643
|
}
|
|
1606
1644
|
if (loading) {
|
|
1607
|
-
return /* @__PURE__ */
|
|
1645
|
+
return /* @__PURE__ */ React20.createElement("span", { className: "inline-flex items-center gap-2" }, "\u23F3", props.loadingText || "Submitting...");
|
|
1608
1646
|
}
|
|
1609
1647
|
return props.children;
|
|
1610
1648
|
};
|
|
@@ -1617,7 +1655,7 @@ function SubmitButton(props) {
|
|
|
1617
1655
|
}
|
|
1618
1656
|
return props.buttonProps?.color || defaults.submitButton.color;
|
|
1619
1657
|
};
|
|
1620
|
-
return /* @__PURE__ */
|
|
1658
|
+
return /* @__PURE__ */ React20.createElement(
|
|
1621
1659
|
Button,
|
|
1622
1660
|
{
|
|
1623
1661
|
type: "submit",
|
|
@@ -1858,7 +1896,7 @@ var commonValidations = {
|
|
|
1858
1896
|
import { useFormContext as useFormContext5 } from "react-hook-form";
|
|
1859
1897
|
|
|
1860
1898
|
// src/components/ZodForm.tsx
|
|
1861
|
-
import
|
|
1899
|
+
import React22 from "react";
|
|
1862
1900
|
import { Button as Button5 } from "@heroui/react";
|
|
1863
1901
|
import {
|
|
1864
1902
|
FormProvider as FormProvider2
|
|
@@ -1981,7 +2019,7 @@ function useEnhancedFormState(form, options = {}) {
|
|
|
1981
2019
|
}
|
|
1982
2020
|
|
|
1983
2021
|
// src/components/FormStatus.tsx
|
|
1984
|
-
import
|
|
2022
|
+
import React21 from "react";
|
|
1985
2023
|
import { Button as Button4 } from "@heroui/react";
|
|
1986
2024
|
function FormStatus({
|
|
1987
2025
|
className = "",
|
|
@@ -1994,25 +2032,25 @@ function FormStatus({
|
|
|
1994
2032
|
return null;
|
|
1995
2033
|
}
|
|
1996
2034
|
if (isSubmitting) {
|
|
1997
|
-
return /* @__PURE__ */
|
|
2035
|
+
return /* @__PURE__ */ React21.createElement(
|
|
1998
2036
|
"div",
|
|
1999
2037
|
{
|
|
2000
2038
|
className: `flex items-center gap-3 p-4 bg-blue-50 border border-blue-200 rounded-lg ${className}`
|
|
2001
2039
|
},
|
|
2002
|
-
/* @__PURE__ */
|
|
2003
|
-
/* @__PURE__ */
|
|
2040
|
+
/* @__PURE__ */ React21.createElement("span", { className: "text-blue-600" }, "\u23F3"),
|
|
2041
|
+
/* @__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."))
|
|
2004
2042
|
);
|
|
2005
2043
|
}
|
|
2006
2044
|
if (isSuccess) {
|
|
2007
|
-
return /* @__PURE__ */
|
|
2045
|
+
return /* @__PURE__ */ React21.createElement(
|
|
2008
2046
|
"div",
|
|
2009
2047
|
{
|
|
2010
2048
|
className: `flex items-center gap-3 p-4 bg-green-50 border border-green-200 rounded-lg ${className}`,
|
|
2011
2049
|
"data-testid": "success-message"
|
|
2012
2050
|
},
|
|
2013
|
-
/* @__PURE__ */
|
|
2014
|
-
/* @__PURE__ */
|
|
2015
|
-
onDismiss && /* @__PURE__ */
|
|
2051
|
+
/* @__PURE__ */ React21.createElement("span", { className: "text-green-600" }, "\u2705"),
|
|
2052
|
+
/* @__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.")),
|
|
2053
|
+
onDismiss && /* @__PURE__ */ React21.createElement(
|
|
2016
2054
|
Button4,
|
|
2017
2055
|
{
|
|
2018
2056
|
size: "sm",
|
|
@@ -2026,15 +2064,15 @@ function FormStatus({
|
|
|
2026
2064
|
);
|
|
2027
2065
|
}
|
|
2028
2066
|
if (isError && error) {
|
|
2029
|
-
return /* @__PURE__ */
|
|
2067
|
+
return /* @__PURE__ */ React21.createElement(
|
|
2030
2068
|
"div",
|
|
2031
2069
|
{
|
|
2032
2070
|
className: `flex items-center gap-3 p-4 bg-red-50 border border-red-200 rounded-lg ${className}`,
|
|
2033
2071
|
"data-testid": "error-message"
|
|
2034
2072
|
},
|
|
2035
|
-
/* @__PURE__ */
|
|
2036
|
-
/* @__PURE__ */
|
|
2037
|
-
onDismiss && /* @__PURE__ */
|
|
2073
|
+
/* @__PURE__ */ React21.createElement("span", { className: "text-red-600" }, "\u26A0\uFE0F"),
|
|
2074
|
+
/* @__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)),
|
|
2075
|
+
onDismiss && /* @__PURE__ */ React21.createElement(
|
|
2038
2076
|
Button4,
|
|
2039
2077
|
{
|
|
2040
2078
|
size: "sm",
|
|
@@ -2055,8 +2093,8 @@ function FormToast({
|
|
|
2055
2093
|
position = "top-right",
|
|
2056
2094
|
state
|
|
2057
2095
|
}) {
|
|
2058
|
-
const [isVisible, setIsVisible] =
|
|
2059
|
-
|
|
2096
|
+
const [isVisible, setIsVisible] = React21.useState(false);
|
|
2097
|
+
React21.useEffect(() => {
|
|
2060
2098
|
if (state.isSuccess || state.isError) {
|
|
2061
2099
|
setIsVisible(true);
|
|
2062
2100
|
if (duration > 0) {
|
|
@@ -2077,7 +2115,7 @@ function FormToast({
|
|
|
2077
2115
|
"top-left": "top-4 left-4",
|
|
2078
2116
|
"top-right": "top-4 right-4"
|
|
2079
2117
|
};
|
|
2080
|
-
return /* @__PURE__ */
|
|
2118
|
+
return /* @__PURE__ */ React21.createElement("div", { className: `fixed z-50 ${positionClasses[position]}` }, /* @__PURE__ */ React21.createElement(FormStatus, { state, onDismiss }));
|
|
2081
2119
|
}
|
|
2082
2120
|
|
|
2083
2121
|
// src/components/ZodForm.tsx
|
|
@@ -2128,12 +2166,12 @@ function ZodForm({
|
|
|
2128
2166
|
};
|
|
2129
2167
|
const renderFields = () => {
|
|
2130
2168
|
if (layout === "grid") {
|
|
2131
|
-
return /* @__PURE__ */
|
|
2169
|
+
return /* @__PURE__ */ React22.createElement(
|
|
2132
2170
|
"div",
|
|
2133
2171
|
{
|
|
2134
2172
|
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"}`
|
|
2135
2173
|
},
|
|
2136
|
-
config.fields.map((field2) => /* @__PURE__ */
|
|
2174
|
+
config.fields.map((field2) => /* @__PURE__ */ React22.createElement(
|
|
2137
2175
|
FormField,
|
|
2138
2176
|
{
|
|
2139
2177
|
key: field2.name,
|
|
@@ -2150,7 +2188,7 @@ function ZodForm({
|
|
|
2150
2188
|
);
|
|
2151
2189
|
}
|
|
2152
2190
|
if (layout === "horizontal") {
|
|
2153
|
-
return /* @__PURE__ */
|
|
2191
|
+
return /* @__PURE__ */ React22.createElement("div", { className: `grid gap-${spacing} grid-cols-1 md:grid-cols-2` }, config.fields.map((field2) => /* @__PURE__ */ React22.createElement(
|
|
2154
2192
|
FormField,
|
|
2155
2193
|
{
|
|
2156
2194
|
key: field2.name,
|
|
@@ -2165,7 +2203,7 @@ function ZodForm({
|
|
|
2165
2203
|
}
|
|
2166
2204
|
)));
|
|
2167
2205
|
}
|
|
2168
|
-
return /* @__PURE__ */
|
|
2206
|
+
return /* @__PURE__ */ React22.createElement("div", { className: `space-y-${spacing}` }, config.fields.map((field2) => /* @__PURE__ */ React22.createElement(
|
|
2169
2207
|
FormField,
|
|
2170
2208
|
{
|
|
2171
2209
|
key: field2.name,
|
|
@@ -2184,13 +2222,13 @@ function ZodForm({
|
|
|
2184
2222
|
e.preventDefault();
|
|
2185
2223
|
void handleSubmit();
|
|
2186
2224
|
};
|
|
2187
|
-
|
|
2225
|
+
React22.useEffect(() => {
|
|
2188
2226
|
if (config.onError && Object.keys(form.formState.errors).length > 0) {
|
|
2189
2227
|
config.onError(form.formState.errors);
|
|
2190
2228
|
}
|
|
2191
2229
|
}, [form.formState.errors, config.onError]);
|
|
2192
2230
|
if (render) {
|
|
2193
|
-
return /* @__PURE__ */
|
|
2231
|
+
return /* @__PURE__ */ React22.createElement(FormProvider2, { ...form }, render({
|
|
2194
2232
|
errors: form.formState.errors,
|
|
2195
2233
|
form,
|
|
2196
2234
|
isSubmitted: enhancedState.status !== "idle",
|
|
@@ -2199,14 +2237,14 @@ function ZodForm({
|
|
|
2199
2237
|
values: form.getValues()
|
|
2200
2238
|
}));
|
|
2201
2239
|
}
|
|
2202
|
-
return /* @__PURE__ */
|
|
2240
|
+
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(
|
|
2203
2241
|
FormStatus,
|
|
2204
2242
|
{
|
|
2205
2243
|
state: enhancedState,
|
|
2206
2244
|
onDismiss: () => enhancedState.reset(),
|
|
2207
2245
|
showDetails: true
|
|
2208
2246
|
}
|
|
2209
|
-
), renderFields(), /* @__PURE__ */
|
|
2247
|
+
), renderFields(), /* @__PURE__ */ React22.createElement("div", { className: "mt-6 flex gap-3 justify-end" }, /* @__PURE__ */ React22.createElement(
|
|
2210
2248
|
Button5,
|
|
2211
2249
|
{
|
|
2212
2250
|
color: "primary",
|
|
@@ -2216,7 +2254,7 @@ function ZodForm({
|
|
|
2216
2254
|
...submitButtonProps
|
|
2217
2255
|
},
|
|
2218
2256
|
enhancedState.isSuccess ? "Success!" : submitButtonText
|
|
2219
|
-
), showResetButton && /* @__PURE__ */
|
|
2257
|
+
), showResetButton && /* @__PURE__ */ React22.createElement(
|
|
2220
2258
|
Button5,
|
|
2221
2259
|
{
|
|
2222
2260
|
isDisabled: enhancedState.isSubmitting,
|
|
@@ -2280,6 +2318,20 @@ var BasicFormBuilder = class {
|
|
|
2280
2318
|
});
|
|
2281
2319
|
return this;
|
|
2282
2320
|
}
|
|
2321
|
+
/**
|
|
2322
|
+
* Add a content field for headers, questions, or custom content between fields
|
|
2323
|
+
*/
|
|
2324
|
+
content(title, description, options) {
|
|
2325
|
+
this.fields.push({
|
|
2326
|
+
className: options?.className,
|
|
2327
|
+
description: description || void 0,
|
|
2328
|
+
name: options?.name,
|
|
2329
|
+
render: options?.render,
|
|
2330
|
+
title: title || void 0,
|
|
2331
|
+
type: "content"
|
|
2332
|
+
});
|
|
2333
|
+
return this;
|
|
2334
|
+
}
|
|
2283
2335
|
/**
|
|
2284
2336
|
* Add a switch field
|
|
2285
2337
|
*/
|
|
@@ -2310,6 +2362,28 @@ var FormFieldHelpers = {
|
|
|
2310
2362
|
name,
|
|
2311
2363
|
type: "checkbox"
|
|
2312
2364
|
}),
|
|
2365
|
+
/**
|
|
2366
|
+
* Create a content field for headers, questions, or custom content between fields
|
|
2367
|
+
*
|
|
2368
|
+
* @example
|
|
2369
|
+
* ```tsx
|
|
2370
|
+
* // Simple header
|
|
2371
|
+
* FormFieldHelpers.content("Personal Information", "Please provide your details")
|
|
2372
|
+
*
|
|
2373
|
+
* // Custom render
|
|
2374
|
+
* FormFieldHelpers.content(null, null, {
|
|
2375
|
+
* render: () => <div>Custom content</div>
|
|
2376
|
+
* })
|
|
2377
|
+
* ```
|
|
2378
|
+
*/
|
|
2379
|
+
content: (title, description, options) => ({
|
|
2380
|
+
className: options?.className,
|
|
2381
|
+
description: description || void 0,
|
|
2382
|
+
name: options?.name,
|
|
2383
|
+
render: options?.render,
|
|
2384
|
+
title: title || void 0,
|
|
2385
|
+
type: "content"
|
|
2386
|
+
}),
|
|
2313
2387
|
/**
|
|
2314
2388
|
* Create a date field
|
|
2315
2389
|
*/
|
|
@@ -2542,6 +2616,16 @@ function fontPickerField(name, label, props) {
|
|
|
2542
2616
|
}
|
|
2543
2617
|
};
|
|
2544
2618
|
}
|
|
2619
|
+
function contentField(title, description, options) {
|
|
2620
|
+
return {
|
|
2621
|
+
className: options?.className,
|
|
2622
|
+
description: description || void 0,
|
|
2623
|
+
name: options?.name,
|
|
2624
|
+
render: options?.render,
|
|
2625
|
+
title: title || void 0,
|
|
2626
|
+
type: "content"
|
|
2627
|
+
};
|
|
2628
|
+
}
|
|
2545
2629
|
function createField(type, name, label, optionsOrProps, props) {
|
|
2546
2630
|
switch (type) {
|
|
2547
2631
|
case "input":
|
|
@@ -2564,6 +2648,22 @@ function createField(type, name, label, optionsOrProps, props) {
|
|
|
2564
2648
|
return fileField(name, label, optionsOrProps);
|
|
2565
2649
|
case "fontPicker":
|
|
2566
2650
|
return fontPickerField(name, label, optionsOrProps);
|
|
2651
|
+
case "content":
|
|
2652
|
+
if (typeof optionsOrProps === "string" || optionsOrProps === null) {
|
|
2653
|
+
return contentField(optionsOrProps, props);
|
|
2654
|
+
}
|
|
2655
|
+
if (typeof optionsOrProps === "object" && optionsOrProps !== null) {
|
|
2656
|
+
return contentField(
|
|
2657
|
+
optionsOrProps.title,
|
|
2658
|
+
optionsOrProps.description,
|
|
2659
|
+
optionsOrProps
|
|
2660
|
+
);
|
|
2661
|
+
}
|
|
2662
|
+
return contentField(
|
|
2663
|
+
name,
|
|
2664
|
+
label,
|
|
2665
|
+
optionsOrProps
|
|
2666
|
+
);
|
|
2567
2667
|
default:
|
|
2568
2668
|
throw new Error(`Unknown field type: ${type}`);
|
|
2569
2669
|
}
|
|
@@ -3454,6 +3554,7 @@ export {
|
|
|
3454
3554
|
CommonFields,
|
|
3455
3555
|
ConditionalField,
|
|
3456
3556
|
ConfigurableForm,
|
|
3557
|
+
ContentField,
|
|
3457
3558
|
DateField,
|
|
3458
3559
|
DynamicSectionField,
|
|
3459
3560
|
FieldArrayBuilder,
|