@page-speed/forms 0.6.2 → 0.6.4

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.
Files changed (57) hide show
  1. package/dist/{FormContext-D_K7lO2V.d.ts → FormContext-C6kWSQuv.d.ts} +1 -1
  2. package/dist/{FormContext-BHKCZ_du.d.cts → FormContext-DLG3GzgL.d.cts} +1 -1
  3. package/dist/chunk-A7MVZ757.js +701 -0
  4. package/dist/chunk-A7MVZ757.js.map +1 -0
  5. package/dist/chunk-DCGSRMZT.cjs +728 -0
  6. package/dist/chunk-DCGSRMZT.cjs.map +1 -0
  7. package/dist/{chunk-455PI4LV.js → chunk-J37BGNM6.js} +5 -4
  8. package/dist/chunk-J37BGNM6.js.map +1 -0
  9. package/dist/{chunk-4ROWNTY6.js → chunk-ML6FGUYS.js} +3 -3
  10. package/dist/{chunk-4ROWNTY6.js.map → chunk-ML6FGUYS.js.map} +1 -1
  11. package/dist/{chunk-QRI5TMES.cjs → chunk-QMWZLGON.cjs} +5 -4
  12. package/dist/chunk-QMWZLGON.cjs.map +1 -0
  13. package/dist/chunk-UBDA7CS5.js +3 -0
  14. package/dist/chunk-UBDA7CS5.js.map +1 -0
  15. package/dist/{chunk-ED4UK63G.cjs → chunk-UQ6JPOBF.cjs} +114 -114
  16. package/dist/{chunk-ED4UK63G.cjs.map → chunk-UQ6JPOBF.cjs.map} +1 -1
  17. package/dist/chunk-V7JSGFCI.cjs +4 -0
  18. package/dist/chunk-V7JSGFCI.cjs.map +1 -0
  19. package/dist/core.cjs +14 -14
  20. package/dist/core.d.cts +17 -11
  21. package/dist/core.d.ts +17 -11
  22. package/dist/core.js +3 -3
  23. package/dist/index.cjs +18 -18
  24. package/dist/index.d.cts +2 -2
  25. package/dist/index.d.ts +2 -2
  26. package/dist/index.js +3 -3
  27. package/dist/inputs.cjs +14 -14
  28. package/dist/inputs.d.cts +8 -2
  29. package/dist/inputs.d.ts +8 -2
  30. package/dist/inputs.js +2 -2
  31. package/dist/integration.cjs +115 -17
  32. package/dist/integration.cjs.map +1 -1
  33. package/dist/integration.d.cts +103 -127
  34. package/dist/integration.d.ts +103 -127
  35. package/dist/integration.js +101 -4
  36. package/dist/integration.js.map +1 -1
  37. package/dist/{types-Fbt73kW_.d.ts → types-BhcLAcZe.d.cts} +149 -22
  38. package/dist/{types-Fbt73kW_.d.cts → types-BhcLAcZe.d.ts} +149 -22
  39. package/dist/validation-rules.d.cts +1 -1
  40. package/dist/validation-rules.d.ts +1 -1
  41. package/dist/validation-utils.d.cts +1 -1
  42. package/dist/validation-utils.d.ts +1 -1
  43. package/dist/validation-valibot.d.cts +1 -1
  44. package/dist/validation-valibot.d.ts +1 -1
  45. package/dist/validation.d.cts +1 -1
  46. package/dist/validation.d.ts +1 -1
  47. package/package.json +1 -1
  48. package/dist/chunk-455PI4LV.js.map +0 -1
  49. package/dist/chunk-MJYEXJ3U.js +0 -373
  50. package/dist/chunk-MJYEXJ3U.js.map +0 -1
  51. package/dist/chunk-MUBEMXI7.cjs +0 -397
  52. package/dist/chunk-MUBEMXI7.cjs.map +0 -1
  53. package/dist/chunk-QRI5TMES.cjs.map +0 -1
  54. package/dist/chunk-RS6AXV5S.cjs +0 -309
  55. package/dist/chunk-RS6AXV5S.cjs.map +0 -1
  56. package/dist/chunk-ZEAH6AKP.js +0 -285
  57. package/dist/chunk-ZEAH6AKP.js.map +0 -1
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunkMUBEMXI7_cjs = require('./chunk-MUBEMXI7.cjs');
4
- var chunkED4UK63G_cjs = require('./chunk-ED4UK63G.cjs');
5
- var chunkQRI5TMES_cjs = require('./chunk-QRI5TMES.cjs');
3
+ var chunkDCGSRMZT_cjs = require('./chunk-DCGSRMZT.cjs');
4
+ var chunkUQ6JPOBF_cjs = require('./chunk-UQ6JPOBF.cjs');
5
+ var chunkQMWZLGON_cjs = require('./chunk-QMWZLGON.cjs');
6
6
  var React2 = require('react');
7
7
 
8
8
  function _interopNamespace(e) {
@@ -565,7 +565,7 @@ function useContactForm(options) {
565
565
  window.location.assign(destination);
566
566
  }, 150);
567
567
  }, [navigate, redirectUrl]);
568
- const form = chunkMUBEMXI7_cjs.useForm({
568
+ const form = chunkDCGSRMZT_cjs.useForm({
569
569
  initialValues: React2.useMemo(
570
570
  () => generateInitialValues(formFields),
571
571
  [formFields]
@@ -643,7 +643,7 @@ function DynamicFormField({
643
643
  const usesInlineCheckboxLabel = field.type === "checkbox";
644
644
  const shouldRenderFieldLabel = renderLabel && !usesGroupLegend && !usesInlineCheckboxLabel;
645
645
  return /* @__PURE__ */ React2__namespace.createElement(
646
- chunkMUBEMXI7_cjs.Field,
646
+ chunkDCGSRMZT_cjs.Field,
647
647
  {
648
648
  name: field.name,
649
649
  label: shouldRenderFieldLabel ? field.label : void 0,
@@ -652,7 +652,7 @@ function DynamicFormField({
652
652
  className
653
653
  },
654
654
  ({ field: formField, meta }) => /* @__PURE__ */ React2__namespace.createElement("div", null, (field.type === "text" || field.type === "email" || field.type === "tel" || field.type === "search" || field.type === "password" || field.type === "url") && /* @__PURE__ */ React2__namespace.createElement(
655
- chunkQRI5TMES_cjs.TextInput,
655
+ chunkQMWZLGON_cjs.TextInput,
656
656
  {
657
657
  ...formField,
658
658
  id: fieldId,
@@ -663,7 +663,7 @@ function DynamicFormField({
663
663
  "aria-label": field.label
664
664
  }
665
665
  ), field.type === "number" && /* @__PURE__ */ React2__namespace.createElement(
666
- chunkQRI5TMES_cjs.TextInput,
666
+ chunkQMWZLGON_cjs.TextInput,
667
667
  {
668
668
  ...formField,
669
669
  id: fieldId,
@@ -674,7 +674,7 @@ function DynamicFormField({
674
674
  "aria-label": field.label
675
675
  }
676
676
  ), field.type === "textarea" && /* @__PURE__ */ React2__namespace.createElement(
677
- chunkED4UK63G_cjs.TextArea,
677
+ chunkUQ6JPOBF_cjs.TextArea,
678
678
  {
679
679
  ...formField,
680
680
  id: fieldId,
@@ -685,7 +685,7 @@ function DynamicFormField({
685
685
  "aria-label": field.label
686
686
  }
687
687
  ), field.type === "select" && field.options && /* @__PURE__ */ React2__namespace.createElement(
688
- chunkED4UK63G_cjs.Select,
688
+ chunkUQ6JPOBF_cjs.Select,
689
689
  {
690
690
  ...formField,
691
691
  id: fieldId,
@@ -696,7 +696,7 @@ function DynamicFormField({
696
696
  "aria-label": field.label
697
697
  }
698
698
  ), field.type === "multi-select" && field.options && /* @__PURE__ */ React2__namespace.createElement(
699
- chunkED4UK63G_cjs.MultiSelect,
699
+ chunkUQ6JPOBF_cjs.MultiSelect,
700
700
  {
701
701
  ...formField,
702
702
  id: fieldId,
@@ -707,7 +707,7 @@ function DynamicFormField({
707
707
  "aria-label": field.label
708
708
  }
709
709
  ), field.type === "radio" && field.options && /* @__PURE__ */ React2__namespace.createElement(
710
- chunkED4UK63G_cjs.Radio,
710
+ chunkUQ6JPOBF_cjs.Radio,
711
711
  {
712
712
  ...formField,
713
713
  id: fieldId,
@@ -721,7 +721,7 @@ function DynamicFormField({
721
721
  "aria-label": field.label
722
722
  }
723
723
  ), field.type === "checkbox" && /* @__PURE__ */ React2__namespace.createElement(
724
- chunkED4UK63G_cjs.Checkbox,
724
+ chunkUQ6JPOBF_cjs.Checkbox,
725
725
  {
726
726
  ...formField,
727
727
  id: fieldId,
@@ -735,7 +735,7 @@ function DynamicFormField({
735
735
  "aria-label": field.label
736
736
  }
737
737
  ), field.type === "checkbox-group" && field.options && /* @__PURE__ */ React2__namespace.createElement(
738
- chunkED4UK63G_cjs.CheckboxGroup,
738
+ chunkUQ6JPOBF_cjs.CheckboxGroup,
739
739
  {
740
740
  ...formField,
741
741
  id: fieldId,
@@ -749,7 +749,7 @@ function DynamicFormField({
749
749
  "aria-label": field.label
750
750
  }
751
751
  ), (field.type === "date-picker" || field.type === "date") && /* @__PURE__ */ React2__namespace.createElement(
752
- chunkED4UK63G_cjs.DatePicker,
752
+ chunkUQ6JPOBF_cjs.DatePicker,
753
753
  {
754
754
  ...formField,
755
755
  id: fieldId,
@@ -759,7 +759,7 @@ function DynamicFormField({
759
759
  "aria-label": field.label
760
760
  }
761
761
  ), field.type === "date-range" && /* @__PURE__ */ React2__namespace.createElement(
762
- chunkED4UK63G_cjs.DateRangePicker,
762
+ chunkUQ6JPOBF_cjs.DateRangePicker,
763
763
  {
764
764
  ...formField,
765
765
  id: fieldId,
@@ -769,7 +769,7 @@ function DynamicFormField({
769
769
  "aria-label": field.label
770
770
  }
771
771
  ), field.type === "time" && /* @__PURE__ */ React2__namespace.createElement(
772
- chunkED4UK63G_cjs.TimePicker,
772
+ chunkUQ6JPOBF_cjs.TimePicker,
773
773
  {
774
774
  ...formField,
775
775
  id: fieldId,
@@ -779,7 +779,7 @@ function DynamicFormField({
779
779
  "aria-label": field.label
780
780
  }
781
781
  ), field.type === "file" && /* @__PURE__ */ React2__namespace.createElement(
782
- chunkED4UK63G_cjs.FileInput,
782
+ chunkUQ6JPOBF_cjs.FileInput,
783
783
  {
784
784
  ...formField,
785
785
  id: fieldId,
@@ -804,8 +804,106 @@ function DynamicFormField({
804
804
  ))
805
805
  );
806
806
  }
807
+ function FormEngine({
808
+ api,
809
+ fields,
810
+ formLayoutSettings,
811
+ successMessage,
812
+ onSubmit,
813
+ onSuccess,
814
+ onError,
815
+ navigate,
816
+ resetOnSuccess,
817
+ uploadTokens,
818
+ onFileUpload,
819
+ onFileRemove,
820
+ isUploading,
821
+ uploadProgress
822
+ }) {
823
+ const {
824
+ styleRules,
825
+ formLayout = "standard",
826
+ buttonGroupSetup,
827
+ submitButtonSetup
828
+ } = formLayoutSettings ?? {};
829
+ const isButtonGroup = formLayout === "button-group";
830
+ const normalizedFields = React2__namespace.useMemo(
831
+ () => fields.map((f) => ({ ...f, label: f.label ?? f.name })),
832
+ [fields]
833
+ );
834
+ const { form, submissionError, formMethod, resetSubmissionState } = useContactForm({
835
+ formFields: normalizedFields,
836
+ formConfig: api,
837
+ onSubmit,
838
+ onSuccess,
839
+ onError,
840
+ navigate,
841
+ resetOnSuccess,
842
+ uploadTokens
843
+ });
844
+ const legacyFormConfig = React2__namespace.useMemo(() => {
845
+ if (isButtonGroup) {
846
+ return {
847
+ formLayout: "button-group",
848
+ buttonGroupSize: buttonGroupSetup?.size,
849
+ submitLabel: buttonGroupSetup?.submitLabel,
850
+ submitVariant: buttonGroupSetup?.submitVariant,
851
+ submitIconName: buttonGroupSetup?.submitIconName,
852
+ submitIconComponent: buttonGroupSetup?.submitIconComponent,
853
+ endpoint: api?.endpoint,
854
+ submissionConfig: api?.submissionConfig
855
+ };
856
+ }
857
+ return {
858
+ formLayout: "standard",
859
+ endpoint: api?.endpoint,
860
+ submissionConfig: api?.submissionConfig
861
+ };
862
+ }, [isButtonGroup, buttonGroupSetup, api]);
863
+ return /* @__PURE__ */ React2__namespace.createElement("div", { className: styleRules?.formContainer }, /* @__PURE__ */ React2__namespace.createElement(
864
+ chunkDCGSRMZT_cjs.Form,
865
+ {
866
+ form,
867
+ fields: isButtonGroup ? fields : void 0,
868
+ formConfig: legacyFormConfig,
869
+ method: formMethod,
870
+ notificationConfig: {
871
+ submissionError: submissionError ?? void 0,
872
+ successMessage
873
+ },
874
+ styleConfig: {
875
+ formClassName: styleRules?.formClassName,
876
+ successMessageClassName: styleRules?.successMessageClassName,
877
+ errorMessageClassName: styleRules?.errorMessageClassName
878
+ },
879
+ onNewSubmission: resetSubmissionState
880
+ },
881
+ !isButtonGroup && /* @__PURE__ */ React2__namespace.createElement(React2__namespace.Fragment, null, /* @__PURE__ */ React2__namespace.createElement("div", { className: chunkQMWZLGON_cjs.cn("grid grid-cols-12 gap-6", styleRules?.fieldsContainer) }, normalizedFields.map((field) => /* @__PURE__ */ React2__namespace.createElement("div", { key: field.name, className: chunkQMWZLGON_cjs.cn(getColumnSpanClass(field.columnSpan ?? 12), "min-w-0") }, /* @__PURE__ */ React2__namespace.createElement(
882
+ DynamicFormField,
883
+ {
884
+ field,
885
+ className: field.className ?? styleRules?.fieldClassName,
886
+ uploadProgress,
887
+ onFileUpload,
888
+ onFileRemove,
889
+ isUploading
890
+ }
891
+ )))), /* @__PURE__ */ React2__namespace.createElement(
892
+ chunkQMWZLGON_cjs.Button,
893
+ {
894
+ type: "submit",
895
+ variant: submitButtonSetup?.submitVariant ?? "default",
896
+ disabled: form.isSubmitting,
897
+ className: "mt-6 w-full"
898
+ },
899
+ submitButtonSetup?.submitLabel ?? "Submit"
900
+ ))
901
+ ));
902
+ }
903
+ FormEngine.displayName = "FormEngine";
807
904
 
808
905
  exports.DynamicFormField = DynamicFormField;
906
+ exports.FormEngine = FormEngine;
809
907
  exports.PageSpeedFormSubmissionError = PageSpeedFormSubmissionError;
810
908
  exports.createBlockAdapter = createBlockAdapter;
811
909
  exports.createBlockAdapters = createBlockAdapters;