@wix/form-public 0.175.0 → 0.176.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/dist/index.cjs CHANGED
@@ -32023,9 +32023,50 @@ function normalizeRepeater({ field, fieldValue, config }) {
32023
32023
  return normalizedValues;
32024
32024
  }
32025
32025
 
32026
+ // ../form-viewer/dist/esm/components/form/autofill.js
32027
+ init_types_impl();
32028
+ var AUTOFILL_FIELDS = [
32029
+ { fieldType: FIELD_TYPES.CONTACTS_EMAIL, key: "email" },
32030
+ { fieldType: FIELD_TYPES.CONTACTS_FIRST_NAME, key: "firstName" },
32031
+ { fieldType: FIELD_TYPES.CONTACTS_LAST_NAME, key: "lastName" },
32032
+ { fieldType: FIELD_TYPES.CONTACTS_PHONE, key: "phone" }
32033
+ ];
32034
+ function getAutofillValues(form, config) {
32035
+ const userData = config?.userData;
32036
+ if (!userData || form?.autoFillContact !== ContactAutofill.MEMBER_DATA) {
32037
+ return {};
32038
+ }
32039
+ const fields = form?.fields ?? [];
32040
+ const result2 = {};
32041
+ for (const { fieldType, key } of AUTOFILL_FIELDS) {
32042
+ const value = userData[key]?.trim();
32043
+ if (!value) {
32044
+ continue;
32045
+ }
32046
+ const target = fields.find((field) => field.view?.fieldType === fieldType)?.target;
32047
+ if (target) {
32048
+ result2[target] = value;
32049
+ }
32050
+ }
32051
+ return result2;
32052
+ }
32053
+
32026
32054
  // ../form-viewer/dist/esm/hooks/use-form-values/use-form-values.js
32027
- var useFormValues = (form, values, onChange, config) => {
32028
- const normalizedValues = React42.useMemo(() => normalizeValues(form, fillEmptyValues(form, values), true, config), [form, values, config]);
32055
+ var useFormValues = (form, values, onChange, config, enableAutofill) => {
32056
+ const hasAutofilled = React42.useRef(false);
32057
+ const normalizedValues = React42.useMemo(() => {
32058
+ const filled = fillEmptyValues(form, values);
32059
+ if (enableAutofill && !hasAutofilled.current && config?.userData) {
32060
+ hasAutofilled.current = true;
32061
+ const autofill = getAutofillValues(form, config);
32062
+ for (const [key, value] of Object.entries(autofill)) {
32063
+ if (filled[key] == null) {
32064
+ filled[key] = value;
32065
+ }
32066
+ }
32067
+ }
32068
+ return normalizeValues(form, filled, true, config);
32069
+ }, [form, values, config, enableAutofill]);
32029
32070
  React42.useEffect(() => {
32030
32071
  const hasAnyValueChanged = !deepEqual(normalizedValues, values);
32031
32072
  if (hasAnyValueChanged) {
@@ -32284,11 +32325,11 @@ var useReportFieldEdit = (form) => {
32284
32325
  };
32285
32326
 
32286
32327
  // ../form-viewer/dist/esm/hooks/use-form.js
32287
- var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange, onChange, errors, onValidate, onSubmit, onSubmitSuccess, onSubmitFailure, enableScrollToFirstError = true, forwardedRef, overrides, actions, config, breakpoint, validationMode, fieldMap, inProgress }) => {
32328
+ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange, onChange, errors, onValidate, onSubmit, onSubmitSuccess, onSubmitFailure, enableScrollToFirstError = true, forwardedRef, overrides, actions, config, breakpoint, validationMode, fieldMap, inProgress, enableAutofill }) => {
32288
32329
  const formWithOverrides = React42.useMemo(() => applyAllOverrides(paramForm, paramValues, overrides), [paramForm, paramValues, overrides]);
32289
32330
  const formId = formWithOverrides.id;
32290
32331
  const { setFocusedFieldId } = useFocusedField();
32291
- const normalizedValues = useFormValues(formWithOverrides, paramValues, onChange, config);
32332
+ const normalizedValues = useFormValues(formWithOverrides, paramValues, onChange, config, enableAutofill);
32292
32333
  const valuesRef = React42.useRef(normalizedValues);
32293
32334
  valuesRef.current = normalizedValues;
32294
32335
  const errorsRef = React42.useRef(errors);