@wix/form-public 0.175.0 → 0.177.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 +40 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +40 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -32023,9 +32023,45 @@ 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 autofillValues(form, values, config) {
|
|
32035
|
+
const result2 = { ...values };
|
|
32036
|
+
const userData = config?.userData;
|
|
32037
|
+
if (!userData || form?.autoFillContact !== ContactAutofill.MEMBER_DATA) {
|
|
32038
|
+
return result2;
|
|
32039
|
+
}
|
|
32040
|
+
const fields = form?.fields ?? [];
|
|
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 && (result2[target] == null || result2[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
|
|
32055
|
+
var useFormValues = (form, values, onChange, config, enableAutofill) => {
|
|
32056
|
+
const hasAutofilled = React42.useRef(false);
|
|
32057
|
+
const normalizedValues = React42.useMemo(() => {
|
|
32058
|
+
let filled = fillEmptyValues(form, values);
|
|
32059
|
+
if (enableAutofill && !hasAutofilled.current && config?.userData) {
|
|
32060
|
+
hasAutofilled.current = true;
|
|
32061
|
+
filled = autofillValues(form, filled, config);
|
|
32062
|
+
}
|
|
32063
|
+
return normalizeValues(form, filled, true, config);
|
|
32064
|
+
}, [form, values, config, enableAutofill]);
|
|
32029
32065
|
React42.useEffect(() => {
|
|
32030
32066
|
const hasAnyValueChanged = !deepEqual(normalizedValues, values);
|
|
32031
32067
|
if (hasAnyValueChanged) {
|
|
@@ -32284,11 +32320,11 @@ var useReportFieldEdit = (form) => {
|
|
|
32284
32320
|
};
|
|
32285
32321
|
|
|
32286
32322
|
// ../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 }) => {
|
|
32323
|
+
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
32324
|
const formWithOverrides = React42.useMemo(() => applyAllOverrides(paramForm, paramValues, overrides), [paramForm, paramValues, overrides]);
|
|
32289
32325
|
const formId = formWithOverrides.id;
|
|
32290
32326
|
const { setFocusedFieldId } = useFocusedField();
|
|
32291
|
-
const normalizedValues = useFormValues(formWithOverrides, paramValues, onChange, config);
|
|
32327
|
+
const normalizedValues = useFormValues(formWithOverrides, paramValues, onChange, config, enableAutofill);
|
|
32292
32328
|
const valuesRef = React42.useRef(normalizedValues);
|
|
32293
32329
|
valuesRef.current = normalizedValues;
|
|
32294
32330
|
const errorsRef = React42.useRef(errors);
|