@wix/form-public 0.174.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
@@ -25366,8 +25366,7 @@ var NOW_VALUE = "$now";
25366
25366
  // ../form-fields/dist/esm/constants/experiments.js
25367
25367
  var EXPERIMENTS = {
25368
25368
  USE_FIELDS_V2: "specs.forms.UseFieldsV2",
25369
- SUBMIT_SUCCESS_NO_FOCUS: "specs.forms.SubmitSuccessNoFocus"
25370
- };
25369
+ SUBMIT_SUCCESS_NO_FOCUS: "specs.forms.SubmitSuccessNoFocus"};
25371
25370
 
25372
25371
  // ../form-fields/dist/esm/constants/breakpoints.js
25373
25372
  var Breakpoint = /* @__PURE__ */ (function(Breakpoint2) {
@@ -32024,9 +32023,50 @@ function normalizeRepeater({ field, fieldValue, config }) {
32024
32023
  return normalizedValues;
32025
32024
  }
32026
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
+
32027
32054
  // ../form-viewer/dist/esm/hooks/use-form-values/use-form-values.js
32028
- var useFormValues = (form, values, onChange, config) => {
32029
- 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]);
32030
32070
  React42.useEffect(() => {
32031
32071
  const hasAnyValueChanged = !deepEqual(normalizedValues, values);
32032
32072
  if (hasAnyValueChanged) {
@@ -32285,11 +32325,11 @@ var useReportFieldEdit = (form) => {
32285
32325
  };
32286
32326
 
32287
32327
  // ../form-viewer/dist/esm/hooks/use-form.js
32288
- 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 }) => {
32289
32329
  const formWithOverrides = React42.useMemo(() => applyAllOverrides(paramForm, paramValues, overrides), [paramForm, paramValues, overrides]);
32290
32330
  const formId = formWithOverrides.id;
32291
32331
  const { setFocusedFieldId } = useFocusedField();
32292
- const normalizedValues = useFormValues(formWithOverrides, paramValues, onChange, config);
32332
+ const normalizedValues = useFormValues(formWithOverrides, paramValues, onChange, config, enableAutofill);
32293
32333
  const valuesRef = React42.useRef(normalizedValues);
32294
32334
  valuesRef.current = normalizedValues;
32295
32335
  const errorsRef = React42.useRef(errors);