@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 CHANGED
@@ -41056,15 +41056,15 @@ var getNormalizedColSpans = (cellsColSpans) => {
41056
41056
  var isLayoutFillObject = (value) => typeof value === "object" && value !== null;
41057
41057
  var isLayoutFillGradient = (value) => isLayoutFillObject(value);
41058
41058
  var isNormalizedLayoutFill = (value) => value?.type === "COLOR" ? typeof value.color === "string" && !!value.color : value?.type === "GRADIENT" ? isLayoutFillGradient(value.gradient) : false;
41059
- function resolveLayoutFill(fill, legacyColor) {
41060
- if (isNormalizedLayoutFill(fill)) {
41061
- return fill;
41059
+ function resolveLayoutFill(fill2, legacyColor) {
41060
+ if (isNormalizedLayoutFill(fill2)) {
41061
+ return fill2;
41062
41062
  }
41063
- const gradient = getLayoutFillGradient(fill);
41063
+ const gradient = getLayoutFillGradient(fill2);
41064
41064
  if (gradient) {
41065
41065
  return { type: "GRADIENT", gradient };
41066
41066
  }
41067
- const color = getLayoutFillColor(fill);
41067
+ const color = getLayoutFillColor(fill2);
41068
41068
  if (color !== void 0) {
41069
41069
  return { type: "COLOR", color };
41070
41070
  }
@@ -41073,10 +41073,10 @@ function resolveLayoutFill(fill, legacyColor) {
41073
41073
  }
41074
41074
  return void 0;
41075
41075
  }
41076
- var getLayoutFillColor = (fill) => fill && "color" in fill && typeof fill.color === "string" ? fill.color || void 0 : void 0;
41077
- var getLayoutFillGradient = (fill) => fill && "gradient" in fill && isLayoutFillGradient(fill.gradient) ? fill.gradient : void 0;
41078
- var getResolvedLayoutFillColor = (fill, legacyColor) => getLayoutFillColor(resolveLayoutFill(fill, legacyColor));
41079
- var getResolvedLayoutFillGradient = (fill, legacyColor) => getLayoutFillGradient(resolveLayoutFill(fill, legacyColor));
41076
+ var getLayoutFillColor = (fill2) => fill2 && "color" in fill2 && typeof fill2.color === "string" ? fill2.color || void 0 : void 0;
41077
+ var getLayoutFillGradient = (fill2) => fill2 && "gradient" in fill2 && isLayoutFillGradient(fill2.gradient) ? fill2.gradient : void 0;
41078
+ var getResolvedLayoutFillColor = (fill2, legacyColor) => getLayoutFillColor(resolveLayoutFill(fill2, legacyColor));
41079
+ var getResolvedLayoutFillGradient = (fill2, legacyColor) => getLayoutFillGradient(resolveLayoutFill(fill2, legacyColor));
41080
41080
 
41081
41081
  // ../../node_modules/@wix/ricos/dist/es/ricos-common-plugins/layout/section-dividers/divider-presets.js
41082
41082
  var DIVIDER_LAYERS_COUNT_MIN = 1;
@@ -48800,6 +48800,7 @@ function getSubmitFieldIdsV2(fields = []) {
48800
48800
  }
48801
48801
 
48802
48802
  // ../form-fields/dist/esm/services/form-view.js
48803
+ var FIELD_PATH_SEPARATOR = "/";
48803
48804
  function createFormView({ form, path = "", stepId, recursive = true, includeHiddenFields = false, isMobile: isMobile2 = false, breakpoint = DEFAULT_BREAKPOINT, useFieldsV2 = false, parentId = "" }) {
48804
48805
  const step = stepId ? form.steps?.find(({ id: id6 }) => id6 === stepId) : form.steps?.[0];
48805
48806
  const layout = step?.layout ?? {};
@@ -48882,7 +48883,7 @@ function createFieldView(field, layout, path, recursive, isMobile2, breakpoint =
48882
48883
  return;
48883
48884
  }
48884
48885
  const fieldTarget = field.target || "";
48885
- const fieldPath = path ? `${path}/${fieldTarget}` : fieldTarget;
48886
+ const fieldPath = path ? `${path}${FIELD_PATH_SEPARATOR}${fieldTarget}` : fieldTarget;
48886
48887
  const propertiesView = createPropertiesView(field, fieldPath, recursive, isMobile2);
48887
48888
  return {
48888
48889
  id: field.id,
@@ -48991,6 +48992,78 @@ function useAddressForms() {
48991
48992
  }
48992
48993
  return context;
48993
48994
  }
48995
+
48996
+ // ../form-fields/dist/esm/services/prehydration-values.js
48997
+ var isEmptyInputValue = (value) => value === void 0 || value === null || value === "";
48998
+ var isNested = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
48999
+ var fill = (values, [key, ...rest], text) => {
49000
+ const current = values[key];
49001
+ if (rest.length === 0) {
49002
+ return isEmptyInputValue(current) ? {
49003
+ ...values,
49004
+ [key]: text
49005
+ } : values;
49006
+ }
49007
+ if (!isEmptyInputValue(current) && !isNested(current)) {
49008
+ return values;
49009
+ }
49010
+ const nested = isNested(current) ? current : {};
49011
+ const filled = fill(nested, rest, text);
49012
+ return filled === nested ? values : {
49013
+ ...values,
49014
+ [key]: filled
49015
+ };
49016
+ };
49017
+ var read = (values, [key, ...rest]) => {
49018
+ const current = values[key];
49019
+ if (rest.length === 0) {
49020
+ return current;
49021
+ }
49022
+ return isNested(current) ? read(current, rest) : void 0;
49023
+ };
49024
+ var mergePrehydrationValues = (values, pending) => {
49025
+ let result2 = values;
49026
+ for (const [path, text] of pending) {
49027
+ result2 = fill(result2, path.split(FIELD_PATH_SEPARATOR), text);
49028
+ }
49029
+ return result2;
49030
+ };
49031
+ var prunePrehydrationValues = (values, pending) => {
49032
+ for (const path of pending.keys()) {
49033
+ if (!isEmptyInputValue(read(values, path.split(FIELD_PATH_SEPARATOR)))) {
49034
+ pending.delete(path);
49035
+ }
49036
+ }
49037
+ };
49038
+ var forgetPrehydrationValues = (pending, previousValues, nextValues) => {
49039
+ for (const path of pending.keys()) {
49040
+ const segments = path.split(FIELD_PATH_SEPARATOR);
49041
+ if (read(previousValues, segments) !== read(nextValues, segments)) {
49042
+ pending.delete(path);
49043
+ }
49044
+ }
49045
+ };
49046
+
49047
+ // ../form-fields/dist/esm/contexts/prehydration-values-context.js
49048
+ var PrehydrationValuesContext = /* @__PURE__ */ React172.createContext(void 0);
49049
+ var useKeepPrehydrationValue = (ref) => {
49050
+ const registry = React172.useContext(PrehydrationValuesContext);
49051
+ const { path, value } = useFieldPropsV2();
49052
+ const mountedFieldRef = React172.useRef({
49053
+ path,
49054
+ value,
49055
+ registry
49056
+ });
49057
+ React172.useEffect(() => {
49058
+ const field = mountedFieldRef.current;
49059
+ const domValue = ref.current?.value;
49060
+ if (field.registry && domValue && isEmptyInputValue(field.value)) {
49061
+ field.registry.current.set(field.path, domValue);
49062
+ }
49063
+ }, [
49064
+ ref
49065
+ ]);
49066
+ };
48994
49067
  var FieldInitialDataContext = React172.createContext(void 0);
48995
49068
 
48996
49069
  // ../form-fields/dist/esm/fields/multiline-address/multiline-address/address.js
@@ -50719,7 +50792,7 @@ function autofillValues(form, values, userData) {
50719
50792
  }
50720
50793
 
50721
50794
  // ../form-viewer/dist/esm/hooks/use-form-values/use-form-values.js
50722
- var useFormValues = (form, values, onChange, userData, addressTemplates, enableAutofill) => {
50795
+ var useFormValues = (form, values, onChange, userData, addressTemplates, enableAutofill, prehydrationValues) => {
50723
50796
  const hasAutofilled = React172.useRef(false);
50724
50797
  const normalizedValues = React172.useMemo(() => {
50725
50798
  let filled = fillEmptyValues(form, values);
@@ -50735,17 +50808,35 @@ var useFormValues = (form, values, onChange, userData, addressTemplates, enableA
50735
50808
  addressTemplates,
50736
50809
  enableAutofill
50737
50810
  ]);
50811
+ const [, rerenderWithPrehydrationText] = React172.useReducer((renders) => renders + 1, 0);
50812
+ const pendingCount = prehydrationValues?.current.size ?? 0;
50813
+ const renderedPendingCount = React172.useRef(pendingCount);
50814
+ renderedPendingCount.current = pendingCount;
50815
+ const valuesWithPrehydrationText = React172.useMemo(() => pendingCount > 0 && prehydrationValues ? mergePrehydrationValues(normalizedValues, prehydrationValues.current) : normalizedValues, [
50816
+ normalizedValues,
50817
+ pendingCount,
50818
+ prehydrationValues
50819
+ ]);
50738
50820
  React172.useEffect(() => {
50739
- const hasAnyValueChanged = !deepEqual(normalizedValues, values);
50821
+ const pending = prehydrationValues?.current;
50822
+ if (pending?.size) {
50823
+ prunePrehydrationValues(values ?? {}, pending);
50824
+ }
50825
+ const merged = pending?.size ? mergePrehydrationValues(normalizedValues, pending) : normalizedValues;
50826
+ const hasAnyValueChanged = !deepEqual(merged, values);
50740
50827
  if (hasAnyValueChanged) {
50741
- onChange?.(normalizedValues);
50828
+ onChange?.(merged);
50829
+ }
50830
+ if ((pending?.size ?? 0) !== renderedPendingCount.current) {
50831
+ rerenderWithPrehydrationText();
50742
50832
  }
50743
50833
  }, [
50744
50834
  values,
50745
50835
  normalizedValues,
50746
- onChange
50836
+ onChange,
50837
+ prehydrationValues
50747
50838
  ]);
50748
- return normalizedValues;
50839
+ return valuesWithPrehydrationText;
50749
50840
  };
50750
50841
  var useFormView2 = (form, stepId, breakpoint) => {
50751
50842
  const { isMobile: isMobile2 } = useConfig();
@@ -50891,6 +50982,11 @@ var BiFormSubmissionStatus = /* @__PURE__ */ (function(BiFormSubmissionStatus2)
50891
50982
  BiFormSubmissionStatus2["SUCCESS"] = "SUCCESS";
50892
50983
  return BiFormSubmissionStatus2;
50893
50984
  })({});
50985
+
50986
+ // ../form-viewer/dist/esm/services/captcha-challenge.js
50987
+ var CAPTCHA_ABANDONED_MESSAGE = "captcha error";
50988
+
50989
+ // ../form-viewer/dist/esm/hooks/use-submit/utils.js
50894
50990
  var redirectToExternalUrl = (redirectOptions) => {
50895
50991
  const urlWithoutProtocol = redirectOptions?.redirectUrl?.replace(/^https?:\/\//, "");
50896
50992
  const updatedExternalUrl = `https://${urlWithoutProtocol}`;
@@ -50904,7 +51000,6 @@ var getErrorCode = (error) => {
50904
51000
  }
50905
51001
  return error?.response?.data?.details?.applicationError?.code || error?.code && String(error?.code) || error?.response?.data?.details?.validationError?.fieldViolations?.[0]?.data?.errors?.[0]?.errorType || "UNKNOWN";
50906
51002
  };
50907
- var CAPTCHA_ABANDONED_MESSAGE = "captcha error";
50908
51003
  var isBackendRejection = (error) => {
50909
51004
  const status = error?.response?.status;
50910
51005
  return typeof status === "number" && status >= 400 && status < 500;
@@ -51190,7 +51285,8 @@ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange,
51190
51285
  ]);
51191
51286
  const formId = formWithOverrides.id;
51192
51287
  const { setFocusedFieldId } = useFocusedField();
51193
- const normalizedValues = useFormValues(formWithOverrides, paramValues, onChange, userData, addressTemplates, enableAutofill);
51288
+ const prehydrationValues = React172.useRef(/* @__PURE__ */ new Map());
51289
+ const normalizedValues = useFormValues(formWithOverrides, paramValues, onChange, userData, addressTemplates, enableAutofill, prehydrationValues);
51194
51290
  const valuesRef = React172.useRef(normalizedValues);
51195
51291
  valuesRef.current = normalizedValues;
51196
51292
  const errorsRef = React172.useRef(errors);
@@ -51208,6 +51304,7 @@ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange,
51208
51304
  [target]: newValue
51209
51305
  };
51210
51306
  const cleared = clearFieldsWhenHiddenByRule(paramForm, overrides, oldValues, newValues, oldErrors);
51307
+ forgetPrehydrationValues(prehydrationValues.current, oldValues, cleared.values);
51211
51308
  onChange(cleared.values);
51212
51309
  onValidate(cleared.errors);
51213
51310
  }
@@ -51360,7 +51457,8 @@ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange,
51360
51457
  formWithOverrides,
51361
51458
  currentStep,
51362
51459
  fieldActions,
51363
- submitForm
51460
+ submitForm,
51461
+ prehydrationValues
51364
51462
  };
51365
51463
  };
51366
51464
  var dummyBi = {
@@ -56500,6 +56598,8 @@ var Guest = ({ className, ...internal }) => {
56500
56598
  return /* @__PURE__ */ React172__default.default.createElement("div", {
56501
56599
  className,
56502
56600
  "data-hook": `guest-${index2}`
56601
+ }, /* @__PURE__ */ React172__default.default.createElement(PrehydrationValuesContext.Provider, {
56602
+ value: void 0
56503
56603
  }, /* @__PURE__ */ React172__default.default.createElement(Form, {
56504
56604
  form: formView,
56505
56605
  formSchema,
@@ -56509,7 +56609,7 @@ var Guest = ({ className, ...internal }) => {
56509
56609
  onFieldChange,
56510
56610
  fields: formFields,
56511
56611
  fieldActions
56512
- }));
56612
+ })));
56513
56613
  };
56514
56614
  GuestCount.Label = EventsRepeaterLabel;
56515
56615
  GuestCount.Control = GuestCountControl;
@@ -58463,6 +58563,7 @@ var Input3 = ({ className }) => {
58463
58563
  preventScroll: true
58464
58564
  });
58465
58565
  }, id6);
58566
+ useKeepPrehydrationValue(inputRef);
58466
58567
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Input, {
58467
58568
  ref: inputRef,
58468
58569
  id: inputId,
@@ -58763,6 +58864,7 @@ var Input4 = ({ className, ...internal }) => {
58763
58864
  preventScroll: true
58764
58865
  });
58765
58866
  }, id6);
58867
+ useKeepPrehydrationValue(inputRef);
58766
58868
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Input, {
58767
58869
  ref: inputRef,
58768
58870
  id: inputId,
@@ -58837,6 +58939,7 @@ var Input5 = ({ className }) => {
58837
58939
  preventScroll: true
58838
58940
  });
58839
58941
  }, id6);
58942
+ useKeepPrehydrationValue(inputRef);
58840
58943
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Input, {
58841
58944
  ref: inputRef,
58842
58945
  id: inputId,
@@ -58886,6 +58989,7 @@ var Input6 = ({ className }) => {
58886
58989
  preventScroll: true
58887
58990
  });
58888
58991
  }, id6);
58992
+ useKeepPrehydrationValue(inputRef);
58889
58993
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Input, {
58890
58994
  ref: inputRef,
58891
58995
  id: inputId,
@@ -59348,6 +59452,7 @@ var Input8 = ({ className, ...internal }) => {
59348
59452
  preventScroll: true
59349
59453
  });
59350
59454
  }, id6);
59455
+ useKeepPrehydrationValue(inputRef);
59351
59456
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Input, {
59352
59457
  ref: inputRef,
59353
59458
  id: inputId,
@@ -59533,6 +59638,7 @@ var Input9 = ({ className, ...internal }) => {
59533
59638
  preventScroll: true
59534
59639
  });
59535
59640
  }, id6);
59641
+ useKeepPrehydrationValue(inputRef);
59536
59642
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Input, {
59537
59643
  ref: inputRef,
59538
59644
  id: inputId,
@@ -59606,6 +59712,7 @@ var Input10 = ({ className }) => {
59606
59712
  preventScroll: true
59607
59713
  });
59608
59714
  }, id6);
59715
+ useKeepPrehydrationValue(inputRef);
59609
59716
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Input, {
59610
59717
  ref: inputRef,
59611
59718
  id: inputId,
@@ -63220,6 +63327,7 @@ var Input15 = ({ className }) => {
63220
63327
  preventScroll: true
63221
63328
  });
63222
63329
  }, id6);
63330
+ useKeepPrehydrationValue(ref);
63223
63331
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.TextArea, {
63224
63332
  ref,
63225
63333
  id: inputId,
@@ -63384,6 +63492,7 @@ var Input16 = ({ className }) => {
63384
63492
  preventScroll: true
63385
63493
  });
63386
63494
  }, id6);
63495
+ useKeepPrehydrationValue(inputRef);
63387
63496
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Input, {
63388
63497
  ref: inputRef,
63389
63498
  id: inputId,