@wix/form-public 0.549.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 +123 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +124 -19
- 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();
|
|
@@ -51184,7 +51275,8 @@ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange,
|
|
|
51184
51275
|
]);
|
|
51185
51276
|
const formId = formWithOverrides.id;
|
|
51186
51277
|
const { setFocusedFieldId } = useFocusedField();
|
|
51187
|
-
const
|
|
51278
|
+
const prehydrationValues = useRef(/* @__PURE__ */ new Map());
|
|
51279
|
+
const normalizedValues = useFormValues(formWithOverrides, paramValues, onChange, userData, addressTemplates, enableAutofill, prehydrationValues);
|
|
51188
51280
|
const valuesRef = useRef(normalizedValues);
|
|
51189
51281
|
valuesRef.current = normalizedValues;
|
|
51190
51282
|
const errorsRef = useRef(errors);
|
|
@@ -51202,6 +51294,7 @@ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange,
|
|
|
51202
51294
|
[target]: newValue
|
|
51203
51295
|
};
|
|
51204
51296
|
const cleared = clearFieldsWhenHiddenByRule(paramForm, overrides, oldValues, newValues, oldErrors);
|
|
51297
|
+
forgetPrehydrationValues(prehydrationValues.current, oldValues, cleared.values);
|
|
51205
51298
|
onChange(cleared.values);
|
|
51206
51299
|
onValidate(cleared.errors);
|
|
51207
51300
|
}
|
|
@@ -51354,7 +51447,8 @@ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange,
|
|
|
51354
51447
|
formWithOverrides,
|
|
51355
51448
|
currentStep,
|
|
51356
51449
|
fieldActions,
|
|
51357
|
-
submitForm
|
|
51450
|
+
submitForm,
|
|
51451
|
+
prehydrationValues
|
|
51358
51452
|
};
|
|
51359
51453
|
};
|
|
51360
51454
|
var dummyBi = {
|
|
@@ -56494,6 +56588,8 @@ var Guest = ({ className, ...internal }) => {
|
|
|
56494
56588
|
return /* @__PURE__ */ React172.createElement("div", {
|
|
56495
56589
|
className,
|
|
56496
56590
|
"data-hook": `guest-${index2}`
|
|
56591
|
+
}, /* @__PURE__ */ React172.createElement(PrehydrationValuesContext.Provider, {
|
|
56592
|
+
value: void 0
|
|
56497
56593
|
}, /* @__PURE__ */ React172.createElement(Form, {
|
|
56498
56594
|
form: formView,
|
|
56499
56595
|
formSchema,
|
|
@@ -56503,7 +56599,7 @@ var Guest = ({ className, ...internal }) => {
|
|
|
56503
56599
|
onFieldChange,
|
|
56504
56600
|
fields: formFields,
|
|
56505
56601
|
fieldActions
|
|
56506
|
-
}));
|
|
56602
|
+
})));
|
|
56507
56603
|
};
|
|
56508
56604
|
GuestCount.Label = EventsRepeaterLabel;
|
|
56509
56605
|
GuestCount.Control = GuestCountControl;
|
|
@@ -58457,6 +58553,7 @@ var Input3 = ({ className }) => {
|
|
|
58457
58553
|
preventScroll: true
|
|
58458
58554
|
});
|
|
58459
58555
|
}, id6);
|
|
58556
|
+
useKeepPrehydrationValue(inputRef);
|
|
58460
58557
|
return /* @__PURE__ */ React172.createElement(Input, {
|
|
58461
58558
|
ref: inputRef,
|
|
58462
58559
|
id: inputId,
|
|
@@ -58757,6 +58854,7 @@ var Input4 = ({ className, ...internal }) => {
|
|
|
58757
58854
|
preventScroll: true
|
|
58758
58855
|
});
|
|
58759
58856
|
}, id6);
|
|
58857
|
+
useKeepPrehydrationValue(inputRef);
|
|
58760
58858
|
return /* @__PURE__ */ React172.createElement(Input, {
|
|
58761
58859
|
ref: inputRef,
|
|
58762
58860
|
id: inputId,
|
|
@@ -58831,6 +58929,7 @@ var Input5 = ({ className }) => {
|
|
|
58831
58929
|
preventScroll: true
|
|
58832
58930
|
});
|
|
58833
58931
|
}, id6);
|
|
58932
|
+
useKeepPrehydrationValue(inputRef);
|
|
58834
58933
|
return /* @__PURE__ */ React172.createElement(Input, {
|
|
58835
58934
|
ref: inputRef,
|
|
58836
58935
|
id: inputId,
|
|
@@ -58880,6 +58979,7 @@ var Input6 = ({ className }) => {
|
|
|
58880
58979
|
preventScroll: true
|
|
58881
58980
|
});
|
|
58882
58981
|
}, id6);
|
|
58982
|
+
useKeepPrehydrationValue(inputRef);
|
|
58883
58983
|
return /* @__PURE__ */ React172.createElement(Input, {
|
|
58884
58984
|
ref: inputRef,
|
|
58885
58985
|
id: inputId,
|
|
@@ -59342,6 +59442,7 @@ var Input8 = ({ className, ...internal }) => {
|
|
|
59342
59442
|
preventScroll: true
|
|
59343
59443
|
});
|
|
59344
59444
|
}, id6);
|
|
59445
|
+
useKeepPrehydrationValue(inputRef);
|
|
59345
59446
|
return /* @__PURE__ */ React172.createElement(Input, {
|
|
59346
59447
|
ref: inputRef,
|
|
59347
59448
|
id: inputId,
|
|
@@ -59527,6 +59628,7 @@ var Input9 = ({ className, ...internal }) => {
|
|
|
59527
59628
|
preventScroll: true
|
|
59528
59629
|
});
|
|
59529
59630
|
}, id6);
|
|
59631
|
+
useKeepPrehydrationValue(inputRef);
|
|
59530
59632
|
return /* @__PURE__ */ React172.createElement(Input, {
|
|
59531
59633
|
ref: inputRef,
|
|
59532
59634
|
id: inputId,
|
|
@@ -59600,6 +59702,7 @@ var Input10 = ({ className }) => {
|
|
|
59600
59702
|
preventScroll: true
|
|
59601
59703
|
});
|
|
59602
59704
|
}, id6);
|
|
59705
|
+
useKeepPrehydrationValue(inputRef);
|
|
59603
59706
|
return /* @__PURE__ */ React172.createElement(Input, {
|
|
59604
59707
|
ref: inputRef,
|
|
59605
59708
|
id: inputId,
|
|
@@ -63214,6 +63317,7 @@ var Input15 = ({ className }) => {
|
|
|
63214
63317
|
preventScroll: true
|
|
63215
63318
|
});
|
|
63216
63319
|
}, id6);
|
|
63320
|
+
useKeepPrehydrationValue(ref);
|
|
63217
63321
|
return /* @__PURE__ */ React172.createElement(TextArea$1, {
|
|
63218
63322
|
ref,
|
|
63219
63323
|
id: inputId,
|
|
@@ -63378,6 +63482,7 @@ var Input16 = ({ className }) => {
|
|
|
63378
63482
|
preventScroll: true
|
|
63379
63483
|
});
|
|
63380
63484
|
}, id6);
|
|
63485
|
+
useKeepPrehydrationValue(inputRef);
|
|
63381
63486
|
return /* @__PURE__ */ React172.createElement(Input, {
|
|
63382
63487
|
ref: inputRef,
|
|
63383
63488
|
id: inputId,
|