@wix/form-public 0.554.0 → 0.556.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
@@ -38675,6 +38675,8 @@ var INPUT_FIELD_TYPES = {
38675
38675
  ...COMMON_FIELD_TYPES,
38676
38676
  ...EVENTS_FIELD_TYPES
38677
38677
  };
38678
+ var INPUT_FIELD_TYPE_VALUES = Object.values(INPUT_FIELD_TYPES);
38679
+ var isInputFieldType = (fieldType) => fieldType && INPUT_FIELD_TYPE_VALUES.includes(fieldType);
38678
38680
 
38679
38681
  // ../form-fields/dist/esm/constants/readonly-field-types.js
38680
38682
  var READONLY_FIELD_TYPES = {
@@ -49086,20 +49088,19 @@ var forgetPrehydrationValues = (pending, previousValues, nextValues) => {
49086
49088
  // ../form-fields/dist/esm/contexts/prehydration-values-context.js
49087
49089
  var PrehydrationValuesContext = /* @__PURE__ */ React172.createContext(void 0);
49088
49090
  var readText = (element) => element.value;
49089
- var useKeepPrehydrationValue = (ref) => {
49091
+ var useKeepPrehydrationValue = (ref, read2) => {
49090
49092
  const registry = React172.useContext(PrehydrationValuesContext);
49091
- const { path, value, readPrehydrationValue = readText } = useFieldPropsV2();
49093
+ const props2 = useFieldPropsV2();
49092
49094
  const mountedFieldRef = React172.useRef({
49093
- path,
49094
- value,
49095
+ props: props2,
49095
49096
  registry,
49096
- read: readPrehydrationValue
49097
+ read: read2 ?? props2.readPrehydrationValue ?? readText
49097
49098
  });
49098
49099
  React172.useEffect(() => {
49099
49100
  const field = mountedFieldRef.current;
49100
- const domValue = ref.current ? field.read(ref.current) : void 0;
49101
- if (field.registry && !isEmptyInputValue(domValue) && isEmptyInputValue(field.value)) {
49102
- field.registry.current.set(field.path, domValue);
49101
+ const domValue = ref.current ? field.read(ref.current, field.props) : void 0;
49102
+ if (field.registry && !isEmptyInputValue(domValue) && isEmptyInputValue(field.props.value)) {
49103
+ field.registry.current.set(field.props.path, domValue);
49103
49104
  }
49104
49105
  }, [
49105
49106
  ref
@@ -51320,7 +51321,7 @@ var useValidation = ({ form, errorsRef, setErrors, validationMode }) => {
51320
51321
  };
51321
51322
 
51322
51323
  // ../form-viewer/dist/esm/hooks/use-form.js
51323
- var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange, onChange, onBlur, onFocus, errors, onValidate, onSubmit, onSubmitSuccess, onSubmitFailure, enableScrollToFirstError = true, forwardedRef, overrides, actions, userData, addressTemplates, breakpoint, validationMode, fieldMap, inProgress, enableAutofill, onSubmissionLimitReached }) => {
51324
+ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange, onChange, onBlur, onFocus, errors, onValidate, onSubmit, onSubmitSuccess, onSubmitFailure, enableScrollToFirstError = true, forwardedRef, overrides, actions, userData, addressTemplates, breakpoint, validationMode, fieldMap, inProgress, enableAutofill, onSubmissionLimitReached, onStepNavigation }) => {
51324
51325
  const formWithOverrides = React172.useMemo(() => applyAllOverrides(paramForm, paramValues, overrides), [
51325
51326
  paramForm,
51326
51327
  paramValues,
@@ -51366,11 +51367,12 @@ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange,
51366
51367
  const handleStepChange = React172.useCallback((step) => {
51367
51368
  const newStepId = formWithOverrides.steps?.[step]?.id;
51368
51369
  if (newStepId) {
51369
- const firstFieldInStep = getSortedFields(formWithOverrides, {
51370
- stepId: newStepId
51370
+ const firstInputFieldInStep = getSortedFields(formWithOverrides, {
51371
+ stepId: newStepId,
51372
+ filter: (field) => !field?.hidden && !field?.view?.disabled && !!isInputFieldType(field?.view?.fieldType)
51371
51373
  })[0];
51372
51374
  onStepIdChange?.(newStepId);
51373
- setFocusedFieldId(firstFieldInStep?.id);
51375
+ setFocusedFieldId(firstInputFieldInStep?.id);
51374
51376
  }
51375
51377
  }, [
51376
51378
  formWithOverrides,
@@ -51445,13 +51447,21 @@ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange,
51445
51447
  scrollToFirstError
51446
51448
  ]);
51447
51449
  const currentStep = getStepIndex(stepId, formWithOverrides.steps);
51448
- const setNextStep = React172.useCallback(() => handleStepChange(currentStep + 1), [
51450
+ const setNextStep = React172.useCallback(() => {
51451
+ onStepNavigation?.();
51452
+ handleStepChange(currentStep + 1);
51453
+ }, [
51449
51454
  currentStep,
51450
- handleStepChange
51455
+ handleStepChange,
51456
+ onStepNavigation
51451
51457
  ]);
51452
- const setPreviousStep = React172.useCallback(() => handleStepChange(currentStep - 1), [
51458
+ const setPreviousStep = React172.useCallback(() => {
51459
+ onStepNavigation?.();
51460
+ handleStepChange(currentStep - 1);
51461
+ }, [
51453
51462
  currentStep,
51454
- handleStepChange
51463
+ handleStepChange,
51464
+ onStepNavigation
51455
51465
  ]);
51456
51466
  const fieldActions = React172.useMemo(() => actions ? {
51457
51467
  actions: {
@@ -60100,6 +60110,19 @@ MultilineAddress.PostalCode = PostalCode;
60100
60110
  MultilineAddress.StreetName = StreetName;
60101
60111
  MultilineAddress.StreetNumber = StreetNumber;
60102
60112
  MultilineAddress.Apartment = Apartment;
60113
+
60114
+ // ../form-fields/dist/esm/field-viewer/number-prehydration-reader.js
60115
+ var readNumber = (element, { validation }) => {
60116
+ const parsed = toNumericValue(element.value.trim());
60117
+ if (parsed === void 0) {
60118
+ return void 0;
60119
+ }
60120
+ const { multipleOf, minimum, maximum } = validation?.number ?? {};
60121
+ const rounded = Number(parsed.toFixed(getNumberOfDecimals(multipleOf || 1)));
60122
+ return Math.min(Math.max(rounded, minimum ?? -Infinity), maximum ?? Infinity);
60123
+ };
60124
+
60125
+ // ../form-fields/dist/esm/ui/number-input-field/number-input-field-headless.js
60103
60126
  var NumberInput = ({ children }) => {
60104
60127
  const { id: id6, value, onChange, disabled, required, readOnly, onBlur, onFocus, FieldLayout, hasError, validation } = useFieldPropsV2();
60105
60128
  const { labelId } = useFieldAttributes();
@@ -60162,6 +60185,7 @@ var Input12 = ({ className }) => {
60162
60185
  preventScroll: true
60163
60186
  });
60164
60187
  }, id6);
60188
+ useKeepPrehydrationValue(ref, readNumber);
60165
60189
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Input, {
60166
60190
  ref,
60167
60191
  id: inputId,
@@ -60310,6 +60334,18 @@ PaymentInput.Input = Input13;
60310
60334
  PaymentInput.Description = Description;
60311
60335
  PaymentInput.Error = Error2;
60312
60336
 
60337
+ // ../form-fields/dist/esm/field-viewer/phone-prehydration-reader.js
60338
+ var readPhoneNumber = (element, props2) => {
60339
+ const typed = element.value;
60340
+ if (!typed) {
60341
+ return void 0;
60342
+ }
60343
+ const { defaultCountry, validation } = props2;
60344
+ const allowedCountryCodes = validation?.string?.phoneOptions?.allowedCountryCodes;
60345
+ const country = parseCountryCodeFromPhoneNumber(typed) || defaultCountry || (allowedCountryCodes?.length === 1 ? allowedCountryCodes[0] : void 0);
60346
+ return normalizePhone(parseLocalPhone(typed, country)) ?? void 0;
60347
+ };
60348
+
60313
60349
  // ../form-fields/dist/esm/ui/phone-input-field/phone-input/use-countries.js
60314
60350
  init_esm();
60315
60351
  function useCountries() {
@@ -60703,6 +60739,7 @@ var PhoneNumber2 = ({ className }) => {
60703
60739
  preventScroll: true
60704
60740
  });
60705
60741
  }, id6);
60742
+ useKeepPrehydrationValue(ref, readPhoneNumber);
60706
60743
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Input, {
60707
60744
  ref,
60708
60745
  id: inputId,