@wix/form-public 0.551.0 → 0.553.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.js CHANGED
@@ -44606,14 +44606,26 @@ var challengesSingleChoiceViewer = {
44606
44606
  normalizeLoadedValue: acceptOnlyValidOptionByLabel
44607
44607
  };
44608
44608
 
44609
+ // ../form-fields/dist/esm/field-viewer/prehydration-readers.js
44610
+ var getCheckedInputs = (element) => Array.from(element.querySelectorAll('input[type="checkbox"]:checked, input[type="radio"]:checked'));
44611
+ var readIsChecked = (element) => getCheckedInputs(element).length > 0;
44612
+ var readCheckedValues = (element) => getCheckedInputs(element).map((input) => input.value);
44613
+ var readCheckedValue = (element) => getCheckedInputs(element)[0]?.value;
44614
+ var readCheckedRating = (element) => {
44615
+ const rating = readCheckedValue(element);
44616
+ return rating ? Number(rating) : void 0;
44617
+ };
44618
+
44609
44619
  // ../form-fields/dist/esm/fields/checkbox-group/definition-viewer.js
44610
44620
  var checkboxGroupViewer = {
44611
- normalizeLoadedValue: removeInvalidOptions
44621
+ normalizeLoadedValue: removeInvalidOptions,
44622
+ readPrehydrationValue: readCheckedValues
44612
44623
  };
44613
44624
 
44614
44625
  // ../form-fields/dist/esm/fields/checkbox/definition-viewer.js
44615
44626
  var checkboxViewer = {
44616
- normalizeLoadedValue: acceptBooleanValue
44627
+ normalizeLoadedValue: acceptBooleanValue,
44628
+ readPrehydrationValue: readIsChecked
44617
44629
  };
44618
44630
 
44619
44631
  // ../form-fields/dist/esm/fields/contacts-address/definition-viewer.js
@@ -44689,7 +44701,8 @@ var contactsPositionViewer = {
44689
44701
 
44690
44702
  // ../form-fields/dist/esm/fields/contacts-subscribe/definition-viewer.js
44691
44703
  var contactsSubscribeViewer = {
44692
- normalizeLoadedValue: acceptBooleanValue
44704
+ normalizeLoadedValue: acceptBooleanValue,
44705
+ readPrehydrationValue: readIsChecked
44693
44706
  };
44694
44707
 
44695
44708
  // ../form-fields/dist/esm/fields/contacts-tax-id/definition-viewer.js
@@ -44745,12 +44758,14 @@ var dateTimeInputViewer = {
44745
44758
 
44746
44759
  // ../form-fields/dist/esm/fields/dext-checkbox-group/definition-viewer.js
44747
44760
  var dextCheckboxGroupViewer = {
44748
- normalizeLoadedValue: removeInvalidOptions
44761
+ normalizeLoadedValue: removeInvalidOptions,
44762
+ readPrehydrationValue: readCheckedValues
44749
44763
  };
44750
44764
 
44751
44765
  // ../form-fields/dist/esm/fields/dext-checkbox/definition-viewer.js
44752
44766
  var dextCheckboxViewer = {
44753
- normalizeLoadedValue: acceptBooleanValue
44767
+ normalizeLoadedValue: acceptBooleanValue,
44768
+ readPrehydrationValue: readIsChecked
44754
44769
  };
44755
44770
 
44756
44771
  // ../form-fields/dist/esm/fields/dext-date-picker/definition-viewer.js
@@ -44785,17 +44800,20 @@ var dextPhoneViewer = {
44785
44800
 
44786
44801
  // ../form-fields/dist/esm/fields/dext-radio-group/definition-viewer.js
44787
44802
  var dextRadioGroupViewer = {
44788
- normalizeLoadedValue: acceptOnlyValidOptionByLabel
44803
+ normalizeLoadedValue: acceptOnlyValidOptionByLabel,
44804
+ readPrehydrationValue: readCheckedValue
44789
44805
  };
44790
44806
 
44791
44807
  // ../form-fields/dist/esm/fields/dext-rating-input/definition-viewer.js
44792
44808
  var dextRatingInputViewer = {
44793
- normalizeLoadedValue: acceptRatingValue
44809
+ normalizeLoadedValue: acceptRatingValue,
44810
+ readPrehydrationValue: readCheckedRating
44794
44811
  };
44795
44812
 
44796
44813
  // ../form-fields/dist/esm/fields/dext-tags/definition-viewer.js
44797
44814
  var dextTagsViewer = {
44798
- normalizeLoadedValue: removeInvalidOptions
44815
+ normalizeLoadedValue: removeInvalidOptions,
44816
+ readPrehydrationValue: readCheckedValues
44799
44817
  };
44800
44818
 
44801
44819
  // ../form-fields/dist/esm/fields/dext-text-area/definition-viewer.js
@@ -44890,7 +44908,8 @@ var ecomPhoneViewer = {
44890
44908
 
44891
44909
  // ../form-fields/dist/esm/fields/ecom-subscription-checkbox/definition-viewer.js
44892
44910
  var ecomSubscriptionCheckboxViewer = {
44893
- normalizeLoadedValue: acceptBooleanValue
44911
+ normalizeLoadedValue: acceptBooleanValue,
44912
+ readPrehydrationValue: readIsChecked
44894
44913
  };
44895
44914
 
44896
44915
  // ../form-fields/dist/esm/fields/events-repeater/events-repeater-normalize-value.js
@@ -44923,7 +44942,8 @@ var eventsRepeaterViewer = {
44923
44942
 
44924
44943
  // ../form-fields/dist/esm/fields/events-rsvp/definition-viewer.js
44925
44944
  var eventsRsvpViewer = {
44926
- normalizeLoadedValue: acceptOnlyValidOptionByValue
44945
+ normalizeLoadedValue: acceptOnlyValidOptionByValue,
44946
+ readPrehydrationValue: readCheckedValue
44927
44947
  };
44928
44948
 
44929
44949
  // ../form-fields/dist/esm/fields/file-upload/definition-viewer.js
@@ -44979,7 +44999,8 @@ var fullNameViewer = {
44979
44999
 
44980
45000
  // ../form-fields/dist/esm/fields/image-choice/definition-viewer.js
44981
45001
  var imageChoiceViewer = {
44982
- normalizeLoadedValue: removeInvalidOptions
45002
+ normalizeLoadedValue: removeInvalidOptions,
45003
+ readPrehydrationValue: readCheckedValues
44983
45004
  };
44984
45005
 
44985
45006
  // ../form-fields/dist/esm/fields/mla-address-line-2/definition-viewer.js
@@ -45080,7 +45101,8 @@ var quizNumberInputViewer = {
45080
45101
 
45081
45102
  // ../form-fields/dist/esm/fields/quiz-radio-group/definition-viewer.js
45082
45103
  var quizRadioGroupViewer = {
45083
- normalizeLoadedValue: acceptOnlyValidOptionByLabel
45104
+ normalizeLoadedValue: acceptOnlyValidOptionByLabel,
45105
+ readPrehydrationValue: readCheckedValue
45084
45106
  };
45085
45107
 
45086
45108
  // ../form-fields/dist/esm/fields/quiz-text-input/definition-viewer.js
@@ -45090,12 +45112,14 @@ var quizTextInputViewer = {
45090
45112
 
45091
45113
  // ../form-fields/dist/esm/fields/radio-group/definition-viewer.js
45092
45114
  var radioGroupViewer = {
45093
- normalizeLoadedValue: acceptOnlyValidOptionByLabel
45115
+ normalizeLoadedValue: acceptOnlyValidOptionByLabel,
45116
+ readPrehydrationValue: readCheckedValue
45094
45117
  };
45095
45118
 
45096
45119
  // ../form-fields/dist/esm/fields/rating-input/definition-viewer.js
45097
45120
  var ratingInputViewer = {
45098
- normalizeLoadedValue: acceptRatingValue
45121
+ normalizeLoadedValue: acceptRatingValue,
45122
+ readPrehydrationValue: readCheckedRating
45099
45123
  };
45100
45124
 
45101
45125
  // ../form-fields/dist/esm/fields/service-dropdown/definition-viewer.js
@@ -45115,7 +45139,8 @@ var signatureViewer = {
45115
45139
 
45116
45140
  // ../form-fields/dist/esm/fields/tags/definition-viewer.js
45117
45141
  var tagsViewer = {
45118
- normalizeLoadedValue: removeInvalidOptions
45142
+ normalizeLoadedValue: removeInvalidOptions,
45143
+ readPrehydrationValue: readCheckedValues
45119
45144
  };
45120
45145
 
45121
45146
  // ../form-fields/dist/esm/fields/text-area/definition-viewer.js
@@ -45620,6 +45645,7 @@ var InputField = ({ field, errors, values, onFieldChange, onBlur, onFocus, Field
45620
45645
  fieldType: field.fieldType,
45621
45646
  FieldLayout,
45622
45647
  autoComplete: FIELD_VIEWERS[field.fieldType]?.autoComplete,
45648
+ readPrehydrationValue: FIELD_VIEWERS[field.fieldType]?.readPrehydrationValue,
45623
45649
  requiredIndicatorType: requiredIndicator,
45624
45650
  requiredIndicatorPlacement
45625
45651
  };
@@ -48997,21 +49023,21 @@ function useAddressForms() {
48997
49023
  }
48998
49024
 
48999
49025
  // ../form-fields/dist/esm/services/prehydration-values.js
49000
- var isEmptyInputValue = (value) => value === void 0 || value === null || value === "";
49026
+ var isEmptyInputValue = (value) => value === void 0 || value === null || value === "" || value === false || Array.isArray(value) && value.length === 0;
49001
49027
  var isNested = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
49002
- var fill = (values, [key, ...rest], text) => {
49028
+ var fill = (values, [key, ...rest], value) => {
49003
49029
  const current = values[key];
49004
49030
  if (rest.length === 0) {
49005
49031
  return isEmptyInputValue(current) ? {
49006
49032
  ...values,
49007
- [key]: text
49033
+ [key]: value
49008
49034
  } : values;
49009
49035
  }
49010
49036
  if (!isEmptyInputValue(current) && !isNested(current)) {
49011
49037
  return values;
49012
49038
  }
49013
49039
  const nested = isNested(current) ? current : {};
49014
- const filled = fill(nested, rest, text);
49040
+ const filled = fill(nested, rest, value);
49015
49041
  return filled === nested ? values : {
49016
49042
  ...values,
49017
49043
  [key]: filled
@@ -49026,8 +49052,8 @@ var read = (values, [key, ...rest]) => {
49026
49052
  };
49027
49053
  var mergePrehydrationValues = (values, pending) => {
49028
49054
  let result2 = values;
49029
- for (const [path, text] of pending) {
49030
- result2 = fill(result2, path.split(FIELD_PATH_SEPARATOR), text);
49055
+ for (const [path, value] of pending) {
49056
+ result2 = fill(result2, path.split(FIELD_PATH_SEPARATOR), value);
49031
49057
  }
49032
49058
  return result2;
49033
49059
  };
@@ -49049,18 +49075,20 @@ var forgetPrehydrationValues = (pending, previousValues, nextValues) => {
49049
49075
 
49050
49076
  // ../form-fields/dist/esm/contexts/prehydration-values-context.js
49051
49077
  var PrehydrationValuesContext = /* @__PURE__ */ createContext(void 0);
49078
+ var readText = (element) => element.value;
49052
49079
  var useKeepPrehydrationValue = (ref) => {
49053
49080
  const registry = useContext(PrehydrationValuesContext);
49054
- const { path, value } = useFieldPropsV2();
49081
+ const { path, value, readPrehydrationValue = readText } = useFieldPropsV2();
49055
49082
  const mountedFieldRef = useRef({
49056
49083
  path,
49057
49084
  value,
49058
- registry
49085
+ registry,
49086
+ read: readPrehydrationValue
49059
49087
  });
49060
49088
  useEffect(() => {
49061
49089
  const field = mountedFieldRef.current;
49062
- const domValue = ref.current?.value;
49063
- if (field.registry && domValue && isEmptyInputValue(field.value)) {
49090
+ const domValue = ref.current ? field.read(ref.current) : void 0;
49091
+ if (field.registry && !isEmptyInputValue(domValue) && isEmptyInputValue(field.value)) {
49064
49092
  field.registry.current.set(field.path, domValue);
49065
49093
  }
49066
49094
  }, [
@@ -52588,6 +52616,7 @@ var CheckboxContainer = ({ children, className }) => {
52588
52616
  preventScroll: true
52589
52617
  });
52590
52618
  }, id6);
52619
+ useKeepPrehydrationValue(ref);
52591
52620
  const labelElement = findChildOfType(children, CheckboxContainer.RichTextLabel);
52592
52621
  const inputElement = findChildOfType(children, CheckboxContainer.Input);
52593
52622
  const handleChange = useCallback((isSelected) => {
@@ -52679,6 +52708,8 @@ var CheckboxGroup = ({ children, className }) => {
52679
52708
  const props2 = useFieldPropsV2();
52680
52709
  const { id: id6, value, onChange, disabled, required, onBlur, onFocus, hasError, FieldLayout } = props2;
52681
52710
  const { inputId, labelId, ariaDescribedBy } = useFieldAttributes();
52711
+ const groupRef = useRef(null);
52712
+ useKeepPrehydrationValue(groupRef);
52682
52713
  const labelElement = findChildOfType(children, CheckboxGroup.Label);
52683
52714
  const optionsElement = findChildOfType(children, CheckboxGroup.Options);
52684
52715
  const descriptionElement = findChildOfType(children, CheckboxGroup.Description);
@@ -52702,6 +52733,7 @@ var CheckboxGroup = ({ children, className }) => {
52702
52733
  onBlur,
52703
52734
  onFocus
52704
52735
  }, /* @__PURE__ */ React172.createElement(CheckboxGroup$1, {
52736
+ ref: groupRef,
52705
52737
  className,
52706
52738
  "aria-labelledby": labelId,
52707
52739
  value: _value,
@@ -56637,6 +56669,8 @@ var getOtherValue2 = (value, addOtherLabel) => {
56637
56669
  var RadioGroup = ({ children, className }) => {
56638
56670
  const { id: id6, value, onChange, disabled, readOnly, required, onBlur, onFocus, hasError, FieldLayout, options } = useFieldPropsV2();
56639
56671
  const { inputId, labelId, ariaDescribedBy } = useFieldAttributes();
56672
+ const groupRef = useRef(null);
56673
+ useKeepPrehydrationValue(groupRef);
56640
56674
  const labelElement = findChildOfType(children, RadioGroup.Label);
56641
56675
  const optionsElement = findChildOfType(children, RadioGroup.Options);
56642
56676
  const descriptionElement = findChildOfType(children, RadioGroup.Description);
@@ -56648,6 +56682,7 @@ var RadioGroup = ({ children, className }) => {
56648
56682
  as: "div"
56649
56683
  }),
56650
56684
  renderInput: () => /* @__PURE__ */ React172.createElement(RadioGroup$1, {
56685
+ ref: groupRef,
56651
56686
  id: inputId,
56652
56687
  className,
56653
56688
  "aria-labelledby": labelId,
@@ -61042,7 +61077,7 @@ ProductList.Description = Description;
61042
61077
  ProductList.Error = Error2;
61043
61078
  var RatingInput = ({ children }) => {
61044
61079
  const { id: id6, value, onChange, disabled, readOnly, required, hasError, onBlur, onFocus, FieldLayout } = useFieldPropsV2();
61045
- const { labelId } = useFieldAttributes();
61080
+ const { labelId, ariaDescribedBy } = useFieldAttributes();
61046
61081
  const handleChange = useCallback((selectedValue) => onChange(Number(selectedValue)), [
61047
61082
  onChange
61048
61083
  ]);
@@ -61055,6 +61090,7 @@ var RatingInput = ({ children }) => {
61055
61090
  renderLabel: () => labelElement,
61056
61091
  renderInput: () => /* @__PURE__ */ React172.createElement(RadioGroup$1, {
61057
61092
  "aria-labelledby": labelId,
61093
+ "aria-describedby": ariaDescribedBy,
61058
61094
  value: value ? String(value) : void 0,
61059
61095
  onChange: handleChange,
61060
61096
  isDisabled: disabled,
@@ -61070,9 +61106,10 @@ var RatingInput = ({ children }) => {
61070
61106
  };
61071
61107
  var Ratings = ({ children, className, getReactionLabel }) => {
61072
61108
  const { value, readOnly, hasError } = useFieldPropsV2();
61073
- const { inputId, ariaDescribedBy } = useFieldAttributes();
61109
+ const { inputId } = useFieldAttributes();
61074
61110
  const [hovered, setHovered] = useState();
61075
61111
  const containerRef = useRef(null);
61112
+ useKeepPrehydrationValue(containerRef);
61076
61113
  const ratingElement = findChildOfType(children, Ratings.Rating);
61077
61114
  const ratingValues = [
61078
61115
  "1",
@@ -61085,7 +61122,6 @@ var Ratings = ({ children, className, getReactionLabel }) => {
61085
61122
  return /* @__PURE__ */ React172.createElement("div", {
61086
61123
  ref: containerRef,
61087
61124
  id: inputId,
61088
- "aria-describedby": ariaDescribedBy,
61089
61125
  className,
61090
61126
  "data-invalid": hasError,
61091
61127
  "data-readonly": readOnly
@@ -63255,6 +63291,8 @@ var Control8 = ({ children, className }) => {
63255
63291
  var Tags = ({ children }) => {
63256
63292
  const { id: id6, value, onChange, FieldLayout, required, disabled, readOnly, hasError, onBlur, onFocus } = useFieldPropsV2();
63257
63293
  const { inputId, labelId, ariaDescribedBy } = useFieldAttributes();
63294
+ const groupRef = useRef(null);
63295
+ useKeepPrehydrationValue(groupRef);
63258
63296
  const selectedValues = useMemo(() => value || [], [
63259
63297
  value
63260
63298
  ]);
@@ -63273,6 +63311,7 @@ var Tags = ({ children }) => {
63273
63311
  onBlur,
63274
63312
  onFocus
63275
63313
  }, /* @__PURE__ */ React172.createElement(CheckboxGroup$1, {
63314
+ ref: groupRef,
63276
63315
  "aria-labelledby": labelId,
63277
63316
  value: selectedValues,
63278
63317
  onChange,