@page-speed/forms 0.6.4 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{FormContext-DLG3GzgL.d.cts → FormContext-6c1ttFt2.d.cts} +1 -1
- package/dist/{FormContext-C6kWSQuv.d.ts → FormContext-DsNPeCv0.d.ts} +1 -1
- package/dist/{chunk-A7MVZ757.js → chunk-7YHBX2IT.js} +2 -2
- package/dist/{chunk-A7MVZ757.js.map → chunk-7YHBX2IT.js.map} +1 -1
- package/dist/{chunk-DCGSRMZT.cjs → chunk-DXAO72JM.cjs} +2 -2
- package/dist/{chunk-DCGSRMZT.cjs.map → chunk-DXAO72JM.cjs.map} +1 -1
- package/dist/core.cjs +8 -8
- package/dist/core.d.cts +3 -3
- package/dist/core.d.ts +3 -3
- package/dist/core.js +1 -1
- package/dist/index.cjs +7 -7
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/inputs.d.cts +1 -1
- package/dist/inputs.d.ts +1 -1
- package/dist/integration.cjs +86 -32
- package/dist/integration.cjs.map +1 -1
- package/dist/integration.d.cts +5 -5
- package/dist/integration.d.ts +5 -5
- package/dist/integration.js +83 -29
- package/dist/integration.js.map +1 -1
- package/dist/{types-BhcLAcZe.d.cts → types-CrWhdYGP.d.cts} +7 -15
- package/dist/{types-BhcLAcZe.d.ts → types-CrWhdYGP.d.ts} +7 -15
- package/dist/validation-rules.d.cts +1 -1
- package/dist/validation-rules.d.ts +1 -1
- package/dist/validation-utils.d.cts +1 -1
- package/dist/validation-utils.d.ts +1 -1
- package/dist/validation-valibot.d.cts +1 -1
- package/dist/validation-valibot.d.ts +1 -1
- package/dist/validation.d.cts +1 -1
- package/dist/validation.d.ts +1 -1
- package/package.json +1 -1
package/dist/integration.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkDXAO72JM_cjs = require('./chunk-DXAO72JM.cjs');
|
|
4
4
|
var chunkUQ6JPOBF_cjs = require('./chunk-UQ6JPOBF.cjs');
|
|
5
5
|
var chunkQMWZLGON_cjs = require('./chunk-QMWZLGON.cjs');
|
|
6
6
|
var React2 = require('react');
|
|
@@ -565,7 +565,7 @@ function useContactForm(options) {
|
|
|
565
565
|
window.location.assign(destination);
|
|
566
566
|
}, 150);
|
|
567
567
|
}, [navigate, redirectUrl]);
|
|
568
|
-
const form =
|
|
568
|
+
const form = chunkDXAO72JM_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
|
-
|
|
646
|
+
chunkDXAO72JM_cjs.Field,
|
|
647
647
|
{
|
|
648
648
|
name: field.name,
|
|
649
649
|
label: shouldRenderFieldLabel ? field.label : void 0,
|
|
@@ -690,7 +690,7 @@ function DynamicFormField({
|
|
|
690
690
|
...formField,
|
|
691
691
|
id: fieldId,
|
|
692
692
|
options: field.options,
|
|
693
|
-
placeholder: field.placeholder || `Select ${field.label.
|
|
693
|
+
placeholder: field.placeholder || `Select ${field.label ? field.label.toLocaleLowerCase() : field.name ? field.name.toLocaleLowerCase() : "Item"}`,
|
|
694
694
|
error: meta.touched && !!meta.error,
|
|
695
695
|
disabled: field.disabled,
|
|
696
696
|
"aria-label": field.label
|
|
@@ -701,7 +701,7 @@ function DynamicFormField({
|
|
|
701
701
|
...formField,
|
|
702
702
|
id: fieldId,
|
|
703
703
|
options: field.options,
|
|
704
|
-
placeholder: field.placeholder || `Select ${field.label.
|
|
704
|
+
placeholder: field.placeholder || `Select ${field.label ? field.label.toLocaleLowerCase() : field.name ? field.name.toLocaleLowerCase() : "Item"}`,
|
|
705
705
|
error: meta.touched && !!meta.error,
|
|
706
706
|
disabled: field.disabled,
|
|
707
707
|
"aria-label": field.label
|
|
@@ -804,6 +804,18 @@ function DynamicFormField({
|
|
|
804
804
|
))
|
|
805
805
|
);
|
|
806
806
|
}
|
|
807
|
+
var DEFAULT_STYLE_RULES = {
|
|
808
|
+
formContainer: "",
|
|
809
|
+
fieldsContainer: "",
|
|
810
|
+
fieldClassName: "",
|
|
811
|
+
formClassName: "",
|
|
812
|
+
successMessageClassName: "text-green-600 dark:text-green-400 mt-4 p-3 rounded-md bg-green-50 dark:bg-green-950/20",
|
|
813
|
+
errorMessageClassName: "text-red-600 dark:text-red-400 mt-4 p-3 rounded-md bg-red-50 dark:bg-red-950/20"
|
|
814
|
+
};
|
|
815
|
+
var DEFAULT_SUBMIT_LABEL = "Submit";
|
|
816
|
+
var DEFAULT_BUTTON_GROUP_LABEL = "Subscribe";
|
|
817
|
+
var DEFAULT_BUTTON_VARIANT = "default";
|
|
818
|
+
var DEFAULT_BUTTON_GROUP_SIZE = "default";
|
|
807
819
|
function FormEngine({
|
|
808
820
|
api,
|
|
809
821
|
fields,
|
|
@@ -814,28 +826,51 @@ function FormEngine({
|
|
|
814
826
|
onError,
|
|
815
827
|
navigate,
|
|
816
828
|
resetOnSuccess,
|
|
817
|
-
uploadTokens,
|
|
818
|
-
onFileUpload,
|
|
819
|
-
onFileRemove,
|
|
820
|
-
isUploading,
|
|
821
|
-
uploadProgress
|
|
829
|
+
uploadTokens: externalUploadTokens,
|
|
830
|
+
onFileUpload: externalOnFileUpload,
|
|
831
|
+
onFileRemove: externalOnFileRemove,
|
|
832
|
+
isUploading: externalIsUploading,
|
|
833
|
+
uploadProgress: externalUploadProgress
|
|
822
834
|
}) {
|
|
823
835
|
const {
|
|
824
|
-
styleRules,
|
|
836
|
+
styleRules: userStyleRules,
|
|
825
837
|
formLayout = "standard",
|
|
826
838
|
buttonGroupSetup,
|
|
827
839
|
submitButtonSetup
|
|
828
840
|
} = formLayoutSettings ?? {};
|
|
829
841
|
const isButtonGroup = formLayout === "button-group";
|
|
830
|
-
const
|
|
831
|
-
() =>
|
|
832
|
-
|
|
842
|
+
const styleRules = React2__namespace.useMemo(
|
|
843
|
+
() => ({
|
|
844
|
+
formContainer: userStyleRules?.formContainer ?? DEFAULT_STYLE_RULES.formContainer,
|
|
845
|
+
fieldsContainer: userStyleRules?.fieldsContainer ?? DEFAULT_STYLE_RULES.fieldsContainer,
|
|
846
|
+
fieldClassName: userStyleRules?.fieldClassName ?? DEFAULT_STYLE_RULES.fieldClassName,
|
|
847
|
+
formClassName: userStyleRules?.formClassName ?? DEFAULT_STYLE_RULES.formClassName,
|
|
848
|
+
successMessageClassName: userStyleRules?.successMessageClassName ?? DEFAULT_STYLE_RULES.successMessageClassName,
|
|
849
|
+
errorMessageClassName: userStyleRules?.errorMessageClassName ?? DEFAULT_STYLE_RULES.errorMessageClassName
|
|
850
|
+
}),
|
|
851
|
+
[userStyleRules]
|
|
833
852
|
);
|
|
853
|
+
const {
|
|
854
|
+
uploadTokens: internalUploadTokens,
|
|
855
|
+
uploadProgress: internalUploadProgress,
|
|
856
|
+
isUploading: internalIsUploading,
|
|
857
|
+
uploadFiles: internalUploadFiles,
|
|
858
|
+
removeFile: internalRemoveFile,
|
|
859
|
+
resetUpload
|
|
860
|
+
} = useFileUpload({ onError });
|
|
861
|
+
const uploadTokens = externalUploadTokens ?? internalUploadTokens;
|
|
862
|
+
const uploadProgress = externalUploadProgress ?? internalUploadProgress;
|
|
863
|
+
const isUploading = externalIsUploading ?? internalIsUploading;
|
|
864
|
+
const onFileUpload = externalOnFileUpload ?? internalUploadFiles;
|
|
865
|
+
const onFileRemove = externalOnFileRemove ?? internalRemoveFile;
|
|
834
866
|
const { form, submissionError, formMethod, resetSubmissionState } = useContactForm({
|
|
835
|
-
formFields:
|
|
867
|
+
formFields: fields,
|
|
836
868
|
formConfig: api,
|
|
837
869
|
onSubmit,
|
|
838
|
-
onSuccess
|
|
870
|
+
onSuccess: (data) => {
|
|
871
|
+
resetUpload();
|
|
872
|
+
onSuccess?.(data);
|
|
873
|
+
},
|
|
839
874
|
onError,
|
|
840
875
|
navigate,
|
|
841
876
|
resetOnSuccess,
|
|
@@ -845,9 +880,9 @@ function FormEngine({
|
|
|
845
880
|
if (isButtonGroup) {
|
|
846
881
|
return {
|
|
847
882
|
formLayout: "button-group",
|
|
848
|
-
buttonGroupSize: buttonGroupSetup?.size,
|
|
849
|
-
submitLabel: buttonGroupSetup?.submitLabel,
|
|
850
|
-
submitVariant: buttonGroupSetup?.submitVariant,
|
|
883
|
+
buttonGroupSize: buttonGroupSetup?.size ?? DEFAULT_BUTTON_GROUP_SIZE,
|
|
884
|
+
submitLabel: buttonGroupSetup?.submitLabel ?? DEFAULT_BUTTON_GROUP_LABEL,
|
|
885
|
+
submitVariant: buttonGroupSetup?.submitVariant ?? DEFAULT_BUTTON_VARIANT,
|
|
851
886
|
submitIconName: buttonGroupSetup?.submitIconName,
|
|
852
887
|
submitIconComponent: buttonGroupSetup?.submitIconComponent,
|
|
853
888
|
endpoint: api?.endpoint,
|
|
@@ -861,7 +896,7 @@ function FormEngine({
|
|
|
861
896
|
};
|
|
862
897
|
}, [isButtonGroup, buttonGroupSetup, api]);
|
|
863
898
|
return /* @__PURE__ */ React2__namespace.createElement("div", { className: styleRules?.formContainer }, /* @__PURE__ */ React2__namespace.createElement(
|
|
864
|
-
|
|
899
|
+
chunkDXAO72JM_cjs.Form,
|
|
865
900
|
{
|
|
866
901
|
form,
|
|
867
902
|
fields: isButtonGroup ? fields : void 0,
|
|
@@ -878,25 +913,44 @@ function FormEngine({
|
|
|
878
913
|
},
|
|
879
914
|
onNewSubmission: resetSubmissionState
|
|
880
915
|
},
|
|
881
|
-
!isButtonGroup && /* @__PURE__ */ React2__namespace.createElement(React2__namespace.Fragment, null, /* @__PURE__ */ React2__namespace.createElement(
|
|
882
|
-
|
|
916
|
+
!isButtonGroup && /* @__PURE__ */ React2__namespace.createElement(React2__namespace.Fragment, null, /* @__PURE__ */ React2__namespace.createElement(
|
|
917
|
+
"div",
|
|
883
918
|
{
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
919
|
+
className: chunkQMWZLGON_cjs.cn(
|
|
920
|
+
"grid grid-cols-12 gap-6",
|
|
921
|
+
styleRules?.fieldsContainer
|
|
922
|
+
)
|
|
923
|
+
},
|
|
924
|
+
fields.map((field) => /* @__PURE__ */ React2__namespace.createElement(
|
|
925
|
+
"div",
|
|
926
|
+
{
|
|
927
|
+
key: field.name,
|
|
928
|
+
className: chunkQMWZLGON_cjs.cn(
|
|
929
|
+
getColumnSpanClass(field.columnSpan ?? 12),
|
|
930
|
+
"min-w-0"
|
|
931
|
+
)
|
|
932
|
+
},
|
|
933
|
+
/* @__PURE__ */ React2__namespace.createElement(
|
|
934
|
+
DynamicFormField,
|
|
935
|
+
{
|
|
936
|
+
field,
|
|
937
|
+
className: field.className ?? styleRules?.fieldClassName,
|
|
938
|
+
uploadProgress,
|
|
939
|
+
onFileUpload,
|
|
940
|
+
onFileRemove,
|
|
941
|
+
isUploading
|
|
942
|
+
}
|
|
943
|
+
)
|
|
944
|
+
))
|
|
945
|
+
), /* @__PURE__ */ React2__namespace.createElement(
|
|
892
946
|
chunkQMWZLGON_cjs.Button,
|
|
893
947
|
{
|
|
894
948
|
type: "submit",
|
|
895
|
-
variant: submitButtonSetup?.submitVariant ??
|
|
949
|
+
variant: submitButtonSetup?.submitVariant ?? DEFAULT_BUTTON_VARIANT,
|
|
896
950
|
disabled: form.isSubmitting,
|
|
897
951
|
className: "mt-6 w-full"
|
|
898
952
|
},
|
|
899
|
-
submitButtonSetup?.submitLabel ??
|
|
953
|
+
submitButtonSetup?.submitLabel ?? DEFAULT_SUBMIT_LABEL
|
|
900
954
|
))
|
|
901
955
|
));
|
|
902
956
|
}
|