@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 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();
@@ -51194,7 +51285,8 @@ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange,
51194
51285
  ]);
51195
51286
  const formId = formWithOverrides.id;
51196
51287
  const { setFocusedFieldId } = useFocusedField();
51197
- 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);
51198
51290
  const valuesRef = React172.useRef(normalizedValues);
51199
51291
  valuesRef.current = normalizedValues;
51200
51292
  const errorsRef = React172.useRef(errors);
@@ -51212,6 +51304,7 @@ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange,
51212
51304
  [target]: newValue
51213
51305
  };
51214
51306
  const cleared = clearFieldsWhenHiddenByRule(paramForm, overrides, oldValues, newValues, oldErrors);
51307
+ forgetPrehydrationValues(prehydrationValues.current, oldValues, cleared.values);
51215
51308
  onChange(cleared.values);
51216
51309
  onValidate(cleared.errors);
51217
51310
  }
@@ -51364,7 +51457,8 @@ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange,
51364
51457
  formWithOverrides,
51365
51458
  currentStep,
51366
51459
  fieldActions,
51367
- submitForm
51460
+ submitForm,
51461
+ prehydrationValues
51368
51462
  };
51369
51463
  };
51370
51464
  var dummyBi = {
@@ -56504,6 +56598,8 @@ var Guest = ({ className, ...internal }) => {
56504
56598
  return /* @__PURE__ */ React172__default.default.createElement("div", {
56505
56599
  className,
56506
56600
  "data-hook": `guest-${index2}`
56601
+ }, /* @__PURE__ */ React172__default.default.createElement(PrehydrationValuesContext.Provider, {
56602
+ value: void 0
56507
56603
  }, /* @__PURE__ */ React172__default.default.createElement(Form, {
56508
56604
  form: formView,
56509
56605
  formSchema,
@@ -56513,7 +56609,7 @@ var Guest = ({ className, ...internal }) => {
56513
56609
  onFieldChange,
56514
56610
  fields: formFields,
56515
56611
  fieldActions
56516
- }));
56612
+ })));
56517
56613
  };
56518
56614
  GuestCount.Label = EventsRepeaterLabel;
56519
56615
  GuestCount.Control = GuestCountControl;
@@ -58467,6 +58563,7 @@ var Input3 = ({ className }) => {
58467
58563
  preventScroll: true
58468
58564
  });
58469
58565
  }, id6);
58566
+ useKeepPrehydrationValue(inputRef);
58470
58567
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Input, {
58471
58568
  ref: inputRef,
58472
58569
  id: inputId,
@@ -58767,6 +58864,7 @@ var Input4 = ({ className, ...internal }) => {
58767
58864
  preventScroll: true
58768
58865
  });
58769
58866
  }, id6);
58867
+ useKeepPrehydrationValue(inputRef);
58770
58868
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Input, {
58771
58869
  ref: inputRef,
58772
58870
  id: inputId,
@@ -58841,6 +58939,7 @@ var Input5 = ({ className }) => {
58841
58939
  preventScroll: true
58842
58940
  });
58843
58941
  }, id6);
58942
+ useKeepPrehydrationValue(inputRef);
58844
58943
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Input, {
58845
58944
  ref: inputRef,
58846
58945
  id: inputId,
@@ -58890,6 +58989,7 @@ var Input6 = ({ className }) => {
58890
58989
  preventScroll: true
58891
58990
  });
58892
58991
  }, id6);
58992
+ useKeepPrehydrationValue(inputRef);
58893
58993
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Input, {
58894
58994
  ref: inputRef,
58895
58995
  id: inputId,
@@ -59352,6 +59452,7 @@ var Input8 = ({ className, ...internal }) => {
59352
59452
  preventScroll: true
59353
59453
  });
59354
59454
  }, id6);
59455
+ useKeepPrehydrationValue(inputRef);
59355
59456
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Input, {
59356
59457
  ref: inputRef,
59357
59458
  id: inputId,
@@ -59537,6 +59638,7 @@ var Input9 = ({ className, ...internal }) => {
59537
59638
  preventScroll: true
59538
59639
  });
59539
59640
  }, id6);
59641
+ useKeepPrehydrationValue(inputRef);
59540
59642
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Input, {
59541
59643
  ref: inputRef,
59542
59644
  id: inputId,
@@ -59610,6 +59712,7 @@ var Input10 = ({ className }) => {
59610
59712
  preventScroll: true
59611
59713
  });
59612
59714
  }, id6);
59715
+ useKeepPrehydrationValue(inputRef);
59613
59716
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Input, {
59614
59717
  ref: inputRef,
59615
59718
  id: inputId,
@@ -63224,6 +63327,7 @@ var Input15 = ({ className }) => {
63224
63327
  preventScroll: true
63225
63328
  });
63226
63329
  }, id6);
63330
+ useKeepPrehydrationValue(ref);
63227
63331
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.TextArea, {
63228
63332
  ref,
63229
63333
  id: inputId,
@@ -63388,6 +63492,7 @@ var Input16 = ({ className }) => {
63388
63492
  preventScroll: true
63389
63493
  });
63390
63494
  }, id6);
63495
+ useKeepPrehydrationValue(inputRef);
63391
63496
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Input, {
63392
63497
  ref: inputRef,
63393
63498
  id: inputId,