@wix/form-public 0.548.0 → 0.550.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 +128 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +129 -20
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ErrorType, ValidationMode } from '@wix/ambassador-forms-v1-validation-result/types';
|
|
2
2
|
import { DayOfWeek, InputFieldInputType, ValidationFormat, RequiredIndicator as RequiredIndicator$1, RequiredIndicatorPlacement as RequiredIndicatorPlacement$1, PriceType, InputFieldPaymentComponentType, InputFieldNumberComponentType, InputFieldStringComponentType, FieldFieldType, Format as Format$1, SubmitSuccessAction as SubmitSuccessAction$1, ContactAutofill as ContactAutofill$1, UrlTargetEnumTarget, ArrayItemsItemType, OverrideEntityType as OverrideEntityType$1 } from '@wix/ambassador-forms-v4-form-http/types';
|
|
3
|
-
import React172, { createContext, useRef, Component, createRef, Suspense, useMemo, useCallback, useState, useEffect, useContext, Children, isValidElement, cloneElement, forwardRef, useLayoutEffect, useImperativeHandle, Fragment, createElement, useId } from 'react';
|
|
3
|
+
import React172, { createContext, useRef, Component, createRef, Suspense, useMemo, useCallback, useState, useEffect, useContext, Children, isValidElement, cloneElement, forwardRef, useLayoutEffect, useImperativeHandle, Fragment, createElement, useId, useReducer } from 'react';
|
|
4
4
|
import { initReactI18next } from 'react-i18next';
|
|
5
5
|
import default2 from 'i18next';
|
|
6
6
|
import ReactDOM from 'react-dom';
|
|
@@ -41046,15 +41046,15 @@ var getNormalizedColSpans = (cellsColSpans) => {
|
|
|
41046
41046
|
var isLayoutFillObject = (value) => typeof value === "object" && value !== null;
|
|
41047
41047
|
var isLayoutFillGradient = (value) => isLayoutFillObject(value);
|
|
41048
41048
|
var isNormalizedLayoutFill = (value) => value?.type === "COLOR" ? typeof value.color === "string" && !!value.color : value?.type === "GRADIENT" ? isLayoutFillGradient(value.gradient) : false;
|
|
41049
|
-
function resolveLayoutFill(
|
|
41050
|
-
if (isNormalizedLayoutFill(
|
|
41051
|
-
return
|
|
41049
|
+
function resolveLayoutFill(fill2, legacyColor) {
|
|
41050
|
+
if (isNormalizedLayoutFill(fill2)) {
|
|
41051
|
+
return fill2;
|
|
41052
41052
|
}
|
|
41053
|
-
const gradient = getLayoutFillGradient(
|
|
41053
|
+
const gradient = getLayoutFillGradient(fill2);
|
|
41054
41054
|
if (gradient) {
|
|
41055
41055
|
return { type: "GRADIENT", gradient };
|
|
41056
41056
|
}
|
|
41057
|
-
const color = getLayoutFillColor(
|
|
41057
|
+
const color = getLayoutFillColor(fill2);
|
|
41058
41058
|
if (color !== void 0) {
|
|
41059
41059
|
return { type: "COLOR", color };
|
|
41060
41060
|
}
|
|
@@ -41063,10 +41063,10 @@ function resolveLayoutFill(fill, legacyColor) {
|
|
|
41063
41063
|
}
|
|
41064
41064
|
return void 0;
|
|
41065
41065
|
}
|
|
41066
|
-
var getLayoutFillColor = (
|
|
41067
|
-
var getLayoutFillGradient = (
|
|
41068
|
-
var getResolvedLayoutFillColor = (
|
|
41069
|
-
var getResolvedLayoutFillGradient = (
|
|
41066
|
+
var getLayoutFillColor = (fill2) => fill2 && "color" in fill2 && typeof fill2.color === "string" ? fill2.color || void 0 : void 0;
|
|
41067
|
+
var getLayoutFillGradient = (fill2) => fill2 && "gradient" in fill2 && isLayoutFillGradient(fill2.gradient) ? fill2.gradient : void 0;
|
|
41068
|
+
var getResolvedLayoutFillColor = (fill2, legacyColor) => getLayoutFillColor(resolveLayoutFill(fill2, legacyColor));
|
|
41069
|
+
var getResolvedLayoutFillGradient = (fill2, legacyColor) => getLayoutFillGradient(resolveLayoutFill(fill2, legacyColor));
|
|
41070
41070
|
|
|
41071
41071
|
// ../../node_modules/@wix/ricos/dist/es/ricos-common-plugins/layout/section-dividers/divider-presets.js
|
|
41072
41072
|
var DIVIDER_LAYERS_COUNT_MIN = 1;
|
|
@@ -48790,6 +48790,7 @@ function getSubmitFieldIdsV2(fields = []) {
|
|
|
48790
48790
|
}
|
|
48791
48791
|
|
|
48792
48792
|
// ../form-fields/dist/esm/services/form-view.js
|
|
48793
|
+
var FIELD_PATH_SEPARATOR = "/";
|
|
48793
48794
|
function createFormView({ form, path = "", stepId, recursive = true, includeHiddenFields = false, isMobile: isMobile2 = false, breakpoint = DEFAULT_BREAKPOINT, useFieldsV2 = false, parentId = "" }) {
|
|
48794
48795
|
const step = stepId ? form.steps?.find(({ id: id6 }) => id6 === stepId) : form.steps?.[0];
|
|
48795
48796
|
const layout = step?.layout ?? {};
|
|
@@ -48872,7 +48873,7 @@ function createFieldView(field, layout, path, recursive, isMobile2, breakpoint =
|
|
|
48872
48873
|
return;
|
|
48873
48874
|
}
|
|
48874
48875
|
const fieldTarget = field.target || "";
|
|
48875
|
-
const fieldPath = path ? `${path}
|
|
48876
|
+
const fieldPath = path ? `${path}${FIELD_PATH_SEPARATOR}${fieldTarget}` : fieldTarget;
|
|
48876
48877
|
const propertiesView = createPropertiesView(field, fieldPath, recursive, isMobile2);
|
|
48877
48878
|
return {
|
|
48878
48879
|
id: field.id,
|
|
@@ -48981,6 +48982,78 @@ function useAddressForms() {
|
|
|
48981
48982
|
}
|
|
48982
48983
|
return context;
|
|
48983
48984
|
}
|
|
48985
|
+
|
|
48986
|
+
// ../form-fields/dist/esm/services/prehydration-values.js
|
|
48987
|
+
var isEmptyInputValue = (value) => value === void 0 || value === null || value === "";
|
|
48988
|
+
var isNested = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
48989
|
+
var fill = (values, [key, ...rest], text) => {
|
|
48990
|
+
const current = values[key];
|
|
48991
|
+
if (rest.length === 0) {
|
|
48992
|
+
return isEmptyInputValue(current) ? {
|
|
48993
|
+
...values,
|
|
48994
|
+
[key]: text
|
|
48995
|
+
} : values;
|
|
48996
|
+
}
|
|
48997
|
+
if (!isEmptyInputValue(current) && !isNested(current)) {
|
|
48998
|
+
return values;
|
|
48999
|
+
}
|
|
49000
|
+
const nested = isNested(current) ? current : {};
|
|
49001
|
+
const filled = fill(nested, rest, text);
|
|
49002
|
+
return filled === nested ? values : {
|
|
49003
|
+
...values,
|
|
49004
|
+
[key]: filled
|
|
49005
|
+
};
|
|
49006
|
+
};
|
|
49007
|
+
var read = (values, [key, ...rest]) => {
|
|
49008
|
+
const current = values[key];
|
|
49009
|
+
if (rest.length === 0) {
|
|
49010
|
+
return current;
|
|
49011
|
+
}
|
|
49012
|
+
return isNested(current) ? read(current, rest) : void 0;
|
|
49013
|
+
};
|
|
49014
|
+
var mergePrehydrationValues = (values, pending) => {
|
|
49015
|
+
let result2 = values;
|
|
49016
|
+
for (const [path, text] of pending) {
|
|
49017
|
+
result2 = fill(result2, path.split(FIELD_PATH_SEPARATOR), text);
|
|
49018
|
+
}
|
|
49019
|
+
return result2;
|
|
49020
|
+
};
|
|
49021
|
+
var prunePrehydrationValues = (values, pending) => {
|
|
49022
|
+
for (const path of pending.keys()) {
|
|
49023
|
+
if (!isEmptyInputValue(read(values, path.split(FIELD_PATH_SEPARATOR)))) {
|
|
49024
|
+
pending.delete(path);
|
|
49025
|
+
}
|
|
49026
|
+
}
|
|
49027
|
+
};
|
|
49028
|
+
var forgetPrehydrationValues = (pending, previousValues, nextValues) => {
|
|
49029
|
+
for (const path of pending.keys()) {
|
|
49030
|
+
const segments = path.split(FIELD_PATH_SEPARATOR);
|
|
49031
|
+
if (read(previousValues, segments) !== read(nextValues, segments)) {
|
|
49032
|
+
pending.delete(path);
|
|
49033
|
+
}
|
|
49034
|
+
}
|
|
49035
|
+
};
|
|
49036
|
+
|
|
49037
|
+
// ../form-fields/dist/esm/contexts/prehydration-values-context.js
|
|
49038
|
+
var PrehydrationValuesContext = /* @__PURE__ */ createContext(void 0);
|
|
49039
|
+
var useKeepPrehydrationValue = (ref) => {
|
|
49040
|
+
const registry = useContext(PrehydrationValuesContext);
|
|
49041
|
+
const { path, value } = useFieldPropsV2();
|
|
49042
|
+
const mountedFieldRef = useRef({
|
|
49043
|
+
path,
|
|
49044
|
+
value,
|
|
49045
|
+
registry
|
|
49046
|
+
});
|
|
49047
|
+
useEffect(() => {
|
|
49048
|
+
const field = mountedFieldRef.current;
|
|
49049
|
+
const domValue = ref.current?.value;
|
|
49050
|
+
if (field.registry && domValue && isEmptyInputValue(field.value)) {
|
|
49051
|
+
field.registry.current.set(field.path, domValue);
|
|
49052
|
+
}
|
|
49053
|
+
}, [
|
|
49054
|
+
ref
|
|
49055
|
+
]);
|
|
49056
|
+
};
|
|
48984
49057
|
var FieldInitialDataContext = createContext(void 0);
|
|
48985
49058
|
|
|
48986
49059
|
// ../form-fields/dist/esm/fields/multiline-address/multiline-address/address.js
|
|
@@ -50709,7 +50782,7 @@ function autofillValues(form, values, userData) {
|
|
|
50709
50782
|
}
|
|
50710
50783
|
|
|
50711
50784
|
// ../form-viewer/dist/esm/hooks/use-form-values/use-form-values.js
|
|
50712
|
-
var useFormValues = (form, values, onChange, userData, addressTemplates, enableAutofill) => {
|
|
50785
|
+
var useFormValues = (form, values, onChange, userData, addressTemplates, enableAutofill, prehydrationValues) => {
|
|
50713
50786
|
const hasAutofilled = useRef(false);
|
|
50714
50787
|
const normalizedValues = useMemo(() => {
|
|
50715
50788
|
let filled = fillEmptyValues(form, values);
|
|
@@ -50725,17 +50798,35 @@ var useFormValues = (form, values, onChange, userData, addressTemplates, enableA
|
|
|
50725
50798
|
addressTemplates,
|
|
50726
50799
|
enableAutofill
|
|
50727
50800
|
]);
|
|
50801
|
+
const [, rerenderWithPrehydrationText] = useReducer((renders) => renders + 1, 0);
|
|
50802
|
+
const pendingCount = prehydrationValues?.current.size ?? 0;
|
|
50803
|
+
const renderedPendingCount = useRef(pendingCount);
|
|
50804
|
+
renderedPendingCount.current = pendingCount;
|
|
50805
|
+
const valuesWithPrehydrationText = useMemo(() => pendingCount > 0 && prehydrationValues ? mergePrehydrationValues(normalizedValues, prehydrationValues.current) : normalizedValues, [
|
|
50806
|
+
normalizedValues,
|
|
50807
|
+
pendingCount,
|
|
50808
|
+
prehydrationValues
|
|
50809
|
+
]);
|
|
50728
50810
|
useEffect(() => {
|
|
50729
|
-
const
|
|
50811
|
+
const pending = prehydrationValues?.current;
|
|
50812
|
+
if (pending?.size) {
|
|
50813
|
+
prunePrehydrationValues(values ?? {}, pending);
|
|
50814
|
+
}
|
|
50815
|
+
const merged = pending?.size ? mergePrehydrationValues(normalizedValues, pending) : normalizedValues;
|
|
50816
|
+
const hasAnyValueChanged = !deepEqual(merged, values);
|
|
50730
50817
|
if (hasAnyValueChanged) {
|
|
50731
|
-
onChange?.(
|
|
50818
|
+
onChange?.(merged);
|
|
50819
|
+
}
|
|
50820
|
+
if ((pending?.size ?? 0) !== renderedPendingCount.current) {
|
|
50821
|
+
rerenderWithPrehydrationText();
|
|
50732
50822
|
}
|
|
50733
50823
|
}, [
|
|
50734
50824
|
values,
|
|
50735
50825
|
normalizedValues,
|
|
50736
|
-
onChange
|
|
50826
|
+
onChange,
|
|
50827
|
+
prehydrationValues
|
|
50737
50828
|
]);
|
|
50738
|
-
return
|
|
50829
|
+
return valuesWithPrehydrationText;
|
|
50739
50830
|
};
|
|
50740
50831
|
var useFormView2 = (form, stepId, breakpoint) => {
|
|
50741
50832
|
const { isMobile: isMobile2 } = useConfig();
|
|
@@ -50881,6 +50972,11 @@ var BiFormSubmissionStatus = /* @__PURE__ */ (function(BiFormSubmissionStatus2)
|
|
|
50881
50972
|
BiFormSubmissionStatus2["SUCCESS"] = "SUCCESS";
|
|
50882
50973
|
return BiFormSubmissionStatus2;
|
|
50883
50974
|
})({});
|
|
50975
|
+
|
|
50976
|
+
// ../form-viewer/dist/esm/services/captcha-challenge.js
|
|
50977
|
+
var CAPTCHA_ABANDONED_MESSAGE = "captcha error";
|
|
50978
|
+
|
|
50979
|
+
// ../form-viewer/dist/esm/hooks/use-submit/utils.js
|
|
50884
50980
|
var redirectToExternalUrl = (redirectOptions) => {
|
|
50885
50981
|
const urlWithoutProtocol = redirectOptions?.redirectUrl?.replace(/^https?:\/\//, "");
|
|
50886
50982
|
const updatedExternalUrl = `https://${urlWithoutProtocol}`;
|
|
@@ -50894,7 +50990,6 @@ var getErrorCode = (error) => {
|
|
|
50894
50990
|
}
|
|
50895
50991
|
return error?.response?.data?.details?.applicationError?.code || error?.code && String(error?.code) || error?.response?.data?.details?.validationError?.fieldViolations?.[0]?.data?.errors?.[0]?.errorType || "UNKNOWN";
|
|
50896
50992
|
};
|
|
50897
|
-
var CAPTCHA_ABANDONED_MESSAGE = "captcha error";
|
|
50898
50993
|
var isBackendRejection = (error) => {
|
|
50899
50994
|
const status = error?.response?.status;
|
|
50900
50995
|
return typeof status === "number" && status >= 400 && status < 500;
|
|
@@ -51180,7 +51275,8 @@ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange,
|
|
|
51180
51275
|
]);
|
|
51181
51276
|
const formId = formWithOverrides.id;
|
|
51182
51277
|
const { setFocusedFieldId } = useFocusedField();
|
|
51183
|
-
const
|
|
51278
|
+
const prehydrationValues = useRef(/* @__PURE__ */ new Map());
|
|
51279
|
+
const normalizedValues = useFormValues(formWithOverrides, paramValues, onChange, userData, addressTemplates, enableAutofill, prehydrationValues);
|
|
51184
51280
|
const valuesRef = useRef(normalizedValues);
|
|
51185
51281
|
valuesRef.current = normalizedValues;
|
|
51186
51282
|
const errorsRef = useRef(errors);
|
|
@@ -51198,6 +51294,7 @@ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange,
|
|
|
51198
51294
|
[target]: newValue
|
|
51199
51295
|
};
|
|
51200
51296
|
const cleared = clearFieldsWhenHiddenByRule(paramForm, overrides, oldValues, newValues, oldErrors);
|
|
51297
|
+
forgetPrehydrationValues(prehydrationValues.current, oldValues, cleared.values);
|
|
51201
51298
|
onChange(cleared.values);
|
|
51202
51299
|
onValidate(cleared.errors);
|
|
51203
51300
|
}
|
|
@@ -51350,7 +51447,8 @@ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange,
|
|
|
51350
51447
|
formWithOverrides,
|
|
51351
51448
|
currentStep,
|
|
51352
51449
|
fieldActions,
|
|
51353
|
-
submitForm
|
|
51450
|
+
submitForm,
|
|
51451
|
+
prehydrationValues
|
|
51354
51452
|
};
|
|
51355
51453
|
};
|
|
51356
51454
|
var dummyBi = {
|
|
@@ -56490,6 +56588,8 @@ var Guest = ({ className, ...internal }) => {
|
|
|
56490
56588
|
return /* @__PURE__ */ React172.createElement("div", {
|
|
56491
56589
|
className,
|
|
56492
56590
|
"data-hook": `guest-${index2}`
|
|
56591
|
+
}, /* @__PURE__ */ React172.createElement(PrehydrationValuesContext.Provider, {
|
|
56592
|
+
value: void 0
|
|
56493
56593
|
}, /* @__PURE__ */ React172.createElement(Form, {
|
|
56494
56594
|
form: formView,
|
|
56495
56595
|
formSchema,
|
|
@@ -56499,7 +56599,7 @@ var Guest = ({ className, ...internal }) => {
|
|
|
56499
56599
|
onFieldChange,
|
|
56500
56600
|
fields: formFields,
|
|
56501
56601
|
fieldActions
|
|
56502
|
-
}));
|
|
56602
|
+
})));
|
|
56503
56603
|
};
|
|
56504
56604
|
GuestCount.Label = EventsRepeaterLabel;
|
|
56505
56605
|
GuestCount.Control = GuestCountControl;
|
|
@@ -58453,6 +58553,7 @@ var Input3 = ({ className }) => {
|
|
|
58453
58553
|
preventScroll: true
|
|
58454
58554
|
});
|
|
58455
58555
|
}, id6);
|
|
58556
|
+
useKeepPrehydrationValue(inputRef);
|
|
58456
58557
|
return /* @__PURE__ */ React172.createElement(Input, {
|
|
58457
58558
|
ref: inputRef,
|
|
58458
58559
|
id: inputId,
|
|
@@ -58753,6 +58854,7 @@ var Input4 = ({ className, ...internal }) => {
|
|
|
58753
58854
|
preventScroll: true
|
|
58754
58855
|
});
|
|
58755
58856
|
}, id6);
|
|
58857
|
+
useKeepPrehydrationValue(inputRef);
|
|
58756
58858
|
return /* @__PURE__ */ React172.createElement(Input, {
|
|
58757
58859
|
ref: inputRef,
|
|
58758
58860
|
id: inputId,
|
|
@@ -58827,6 +58929,7 @@ var Input5 = ({ className }) => {
|
|
|
58827
58929
|
preventScroll: true
|
|
58828
58930
|
});
|
|
58829
58931
|
}, id6);
|
|
58932
|
+
useKeepPrehydrationValue(inputRef);
|
|
58830
58933
|
return /* @__PURE__ */ React172.createElement(Input, {
|
|
58831
58934
|
ref: inputRef,
|
|
58832
58935
|
id: inputId,
|
|
@@ -58876,6 +58979,7 @@ var Input6 = ({ className }) => {
|
|
|
58876
58979
|
preventScroll: true
|
|
58877
58980
|
});
|
|
58878
58981
|
}, id6);
|
|
58982
|
+
useKeepPrehydrationValue(inputRef);
|
|
58879
58983
|
return /* @__PURE__ */ React172.createElement(Input, {
|
|
58880
58984
|
ref: inputRef,
|
|
58881
58985
|
id: inputId,
|
|
@@ -59338,6 +59442,7 @@ var Input8 = ({ className, ...internal }) => {
|
|
|
59338
59442
|
preventScroll: true
|
|
59339
59443
|
});
|
|
59340
59444
|
}, id6);
|
|
59445
|
+
useKeepPrehydrationValue(inputRef);
|
|
59341
59446
|
return /* @__PURE__ */ React172.createElement(Input, {
|
|
59342
59447
|
ref: inputRef,
|
|
59343
59448
|
id: inputId,
|
|
@@ -59523,6 +59628,7 @@ var Input9 = ({ className, ...internal }) => {
|
|
|
59523
59628
|
preventScroll: true
|
|
59524
59629
|
});
|
|
59525
59630
|
}, id6);
|
|
59631
|
+
useKeepPrehydrationValue(inputRef);
|
|
59526
59632
|
return /* @__PURE__ */ React172.createElement(Input, {
|
|
59527
59633
|
ref: inputRef,
|
|
59528
59634
|
id: inputId,
|
|
@@ -59596,6 +59702,7 @@ var Input10 = ({ className }) => {
|
|
|
59596
59702
|
preventScroll: true
|
|
59597
59703
|
});
|
|
59598
59704
|
}, id6);
|
|
59705
|
+
useKeepPrehydrationValue(inputRef);
|
|
59599
59706
|
return /* @__PURE__ */ React172.createElement(Input, {
|
|
59600
59707
|
ref: inputRef,
|
|
59601
59708
|
id: inputId,
|
|
@@ -63210,6 +63317,7 @@ var Input15 = ({ className }) => {
|
|
|
63210
63317
|
preventScroll: true
|
|
63211
63318
|
});
|
|
63212
63319
|
}, id6);
|
|
63320
|
+
useKeepPrehydrationValue(ref);
|
|
63213
63321
|
return /* @__PURE__ */ React172.createElement(TextArea$1, {
|
|
63214
63322
|
ref,
|
|
63215
63323
|
id: inputId,
|
|
@@ -63374,6 +63482,7 @@ var Input16 = ({ className }) => {
|
|
|
63374
63482
|
preventScroll: true
|
|
63375
63483
|
});
|
|
63376
63484
|
}, id6);
|
|
63485
|
+
useKeepPrehydrationValue(inputRef);
|
|
63377
63486
|
return /* @__PURE__ */ React172.createElement(Input, {
|
|
63378
63487
|
ref: inputRef,
|
|
63379
63488
|
id: inputId,
|