@wix/form-public 0.552.0 → 0.554.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
  }, [
@@ -51133,7 +51161,9 @@ var useSubmit = ({ validateAndScrollToError, submitAction, onSubmit, onSubmitSuc
51133
51161
  ]);
51134
51162
  const submitForm = useCallback(async () => {
51135
51163
  const errors = await validateAndScrollToError(values);
51136
- onSubmit?.();
51164
+ if (onSubmit?.() === false) {
51165
+ return;
51166
+ }
51137
51167
  reportSubmitFormBi({
51138
51168
  status: BiFormSubmissionStatus.INIT
51139
51169
  });
@@ -52588,6 +52618,7 @@ var CheckboxContainer = ({ children, className }) => {
52588
52618
  preventScroll: true
52589
52619
  });
52590
52620
  }, id6);
52621
+ useKeepPrehydrationValue(ref);
52591
52622
  const labelElement = findChildOfType(children, CheckboxContainer.RichTextLabel);
52592
52623
  const inputElement = findChildOfType(children, CheckboxContainer.Input);
52593
52624
  const handleChange = useCallback((isSelected) => {
@@ -52679,6 +52710,8 @@ var CheckboxGroup = ({ children, className }) => {
52679
52710
  const props2 = useFieldPropsV2();
52680
52711
  const { id: id6, value, onChange, disabled, required, onBlur, onFocus, hasError, FieldLayout } = props2;
52681
52712
  const { inputId, labelId, ariaDescribedBy } = useFieldAttributes();
52713
+ const groupRef = useRef(null);
52714
+ useKeepPrehydrationValue(groupRef);
52682
52715
  const labelElement = findChildOfType(children, CheckboxGroup.Label);
52683
52716
  const optionsElement = findChildOfType(children, CheckboxGroup.Options);
52684
52717
  const descriptionElement = findChildOfType(children, CheckboxGroup.Description);
@@ -52702,6 +52735,7 @@ var CheckboxGroup = ({ children, className }) => {
52702
52735
  onBlur,
52703
52736
  onFocus
52704
52737
  }, /* @__PURE__ */ React172.createElement(CheckboxGroup$1, {
52738
+ ref: groupRef,
52705
52739
  className,
52706
52740
  "aria-labelledby": labelId,
52707
52741
  value: _value,
@@ -56637,6 +56671,8 @@ var getOtherValue2 = (value, addOtherLabel) => {
56637
56671
  var RadioGroup = ({ children, className }) => {
56638
56672
  const { id: id6, value, onChange, disabled, readOnly, required, onBlur, onFocus, hasError, FieldLayout, options } = useFieldPropsV2();
56639
56673
  const { inputId, labelId, ariaDescribedBy } = useFieldAttributes();
56674
+ const groupRef = useRef(null);
56675
+ useKeepPrehydrationValue(groupRef);
56640
56676
  const labelElement = findChildOfType(children, RadioGroup.Label);
56641
56677
  const optionsElement = findChildOfType(children, RadioGroup.Options);
56642
56678
  const descriptionElement = findChildOfType(children, RadioGroup.Description);
@@ -56648,6 +56684,7 @@ var RadioGroup = ({ children, className }) => {
56648
56684
  as: "div"
56649
56685
  }),
56650
56686
  renderInput: () => /* @__PURE__ */ React172.createElement(RadioGroup$1, {
56687
+ ref: groupRef,
56651
56688
  id: inputId,
56652
56689
  className,
56653
56690
  "aria-labelledby": labelId,
@@ -61074,6 +61111,7 @@ var Ratings = ({ children, className, getReactionLabel }) => {
61074
61111
  const { inputId } = useFieldAttributes();
61075
61112
  const [hovered, setHovered] = useState();
61076
61113
  const containerRef = useRef(null);
61114
+ useKeepPrehydrationValue(containerRef);
61077
61115
  const ratingElement = findChildOfType(children, Ratings.Rating);
61078
61116
  const ratingValues = [
61079
61117
  "1",
@@ -63255,6 +63293,8 @@ var Control8 = ({ children, className }) => {
63255
63293
  var Tags = ({ children }) => {
63256
63294
  const { id: id6, value, onChange, FieldLayout, required, disabled, readOnly, hasError, onBlur, onFocus } = useFieldPropsV2();
63257
63295
  const { inputId, labelId, ariaDescribedBy } = useFieldAttributes();
63296
+ const groupRef = useRef(null);
63297
+ useKeepPrehydrationValue(groupRef);
63258
63298
  const selectedValues = useMemo(() => value || [], [
63259
63299
  value
63260
63300
  ]);
@@ -63273,6 +63313,7 @@ var Tags = ({ children }) => {
63273
63313
  onBlur,
63274
63314
  onFocus
63275
63315
  }, /* @__PURE__ */ React172.createElement(CheckboxGroup$1, {
63316
+ ref: groupRef,
63276
63317
  "aria-labelledby": labelId,
63277
63318
  value: selectedValues,
63278
63319
  onChange,