@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 +53 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +23 -5
- package/dist/index.css.map +1 -1
- package/dist/index.js +53 -16
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -38665,6 +38665,8 @@ var INPUT_FIELD_TYPES = {
|
|
|
38665
38665
|
...COMMON_FIELD_TYPES,
|
|
38666
38666
|
...EVENTS_FIELD_TYPES
|
|
38667
38667
|
};
|
|
38668
|
+
var INPUT_FIELD_TYPE_VALUES = Object.values(INPUT_FIELD_TYPES);
|
|
38669
|
+
var isInputFieldType = (fieldType) => fieldType && INPUT_FIELD_TYPE_VALUES.includes(fieldType);
|
|
38668
38670
|
|
|
38669
38671
|
// ../form-fields/dist/esm/constants/readonly-field-types.js
|
|
38670
38672
|
var READONLY_FIELD_TYPES = {
|
|
@@ -49076,20 +49078,19 @@ var forgetPrehydrationValues = (pending, previousValues, nextValues) => {
|
|
|
49076
49078
|
// ../form-fields/dist/esm/contexts/prehydration-values-context.js
|
|
49077
49079
|
var PrehydrationValuesContext = /* @__PURE__ */ createContext(void 0);
|
|
49078
49080
|
var readText = (element) => element.value;
|
|
49079
|
-
var useKeepPrehydrationValue = (ref) => {
|
|
49081
|
+
var useKeepPrehydrationValue = (ref, read2) => {
|
|
49080
49082
|
const registry = useContext(PrehydrationValuesContext);
|
|
49081
|
-
const
|
|
49083
|
+
const props2 = useFieldPropsV2();
|
|
49082
49084
|
const mountedFieldRef = useRef({
|
|
49083
|
-
|
|
49084
|
-
value,
|
|
49085
|
+
props: props2,
|
|
49085
49086
|
registry,
|
|
49086
|
-
read: readPrehydrationValue
|
|
49087
|
+
read: read2 ?? props2.readPrehydrationValue ?? readText
|
|
49087
49088
|
});
|
|
49088
49089
|
useEffect(() => {
|
|
49089
49090
|
const field = mountedFieldRef.current;
|
|
49090
|
-
const domValue = ref.current ? field.read(ref.current) : void 0;
|
|
49091
|
-
if (field.registry && !isEmptyInputValue(domValue) && isEmptyInputValue(field.value)) {
|
|
49092
|
-
field.registry.current.set(field.path, domValue);
|
|
49091
|
+
const domValue = ref.current ? field.read(ref.current, field.props) : void 0;
|
|
49092
|
+
if (field.registry && !isEmptyInputValue(domValue) && isEmptyInputValue(field.props.value)) {
|
|
49093
|
+
field.registry.current.set(field.props.path, domValue);
|
|
49093
49094
|
}
|
|
49094
49095
|
}, [
|
|
49095
49096
|
ref
|
|
@@ -51310,7 +51311,7 @@ var useValidation = ({ form, errorsRef, setErrors, validationMode }) => {
|
|
|
51310
51311
|
};
|
|
51311
51312
|
|
|
51312
51313
|
// ../form-viewer/dist/esm/hooks/use-form.js
|
|
51313
|
-
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 }) => {
|
|
51314
|
+
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 }) => {
|
|
51314
51315
|
const formWithOverrides = useMemo(() => applyAllOverrides(paramForm, paramValues, overrides), [
|
|
51315
51316
|
paramForm,
|
|
51316
51317
|
paramValues,
|
|
@@ -51356,11 +51357,12 @@ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange,
|
|
|
51356
51357
|
const handleStepChange = useCallback((step) => {
|
|
51357
51358
|
const newStepId = formWithOverrides.steps?.[step]?.id;
|
|
51358
51359
|
if (newStepId) {
|
|
51359
|
-
const
|
|
51360
|
-
stepId: newStepId
|
|
51360
|
+
const firstInputFieldInStep = getSortedFields(formWithOverrides, {
|
|
51361
|
+
stepId: newStepId,
|
|
51362
|
+
filter: (field) => !field?.hidden && !field?.view?.disabled && !!isInputFieldType(field?.view?.fieldType)
|
|
51361
51363
|
})[0];
|
|
51362
51364
|
onStepIdChange?.(newStepId);
|
|
51363
|
-
setFocusedFieldId(
|
|
51365
|
+
setFocusedFieldId(firstInputFieldInStep?.id);
|
|
51364
51366
|
}
|
|
51365
51367
|
}, [
|
|
51366
51368
|
formWithOverrides,
|
|
@@ -51435,13 +51437,21 @@ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange,
|
|
|
51435
51437
|
scrollToFirstError
|
|
51436
51438
|
]);
|
|
51437
51439
|
const currentStep = getStepIndex(stepId, formWithOverrides.steps);
|
|
51438
|
-
const setNextStep = useCallback(() =>
|
|
51440
|
+
const setNextStep = useCallback(() => {
|
|
51441
|
+
onStepNavigation?.();
|
|
51442
|
+
handleStepChange(currentStep + 1);
|
|
51443
|
+
}, [
|
|
51439
51444
|
currentStep,
|
|
51440
|
-
handleStepChange
|
|
51445
|
+
handleStepChange,
|
|
51446
|
+
onStepNavigation
|
|
51441
51447
|
]);
|
|
51442
|
-
const setPreviousStep = useCallback(() =>
|
|
51448
|
+
const setPreviousStep = useCallback(() => {
|
|
51449
|
+
onStepNavigation?.();
|
|
51450
|
+
handleStepChange(currentStep - 1);
|
|
51451
|
+
}, [
|
|
51443
51452
|
currentStep,
|
|
51444
|
-
handleStepChange
|
|
51453
|
+
handleStepChange,
|
|
51454
|
+
onStepNavigation
|
|
51445
51455
|
]);
|
|
51446
51456
|
const fieldActions = useMemo(() => actions ? {
|
|
51447
51457
|
actions: {
|
|
@@ -60090,6 +60100,19 @@ MultilineAddress.PostalCode = PostalCode;
|
|
|
60090
60100
|
MultilineAddress.StreetName = StreetName;
|
|
60091
60101
|
MultilineAddress.StreetNumber = StreetNumber;
|
|
60092
60102
|
MultilineAddress.Apartment = Apartment;
|
|
60103
|
+
|
|
60104
|
+
// ../form-fields/dist/esm/field-viewer/number-prehydration-reader.js
|
|
60105
|
+
var readNumber = (element, { validation }) => {
|
|
60106
|
+
const parsed = toNumericValue(element.value.trim());
|
|
60107
|
+
if (parsed === void 0) {
|
|
60108
|
+
return void 0;
|
|
60109
|
+
}
|
|
60110
|
+
const { multipleOf, minimum, maximum } = validation?.number ?? {};
|
|
60111
|
+
const rounded = Number(parsed.toFixed(getNumberOfDecimals(multipleOf || 1)));
|
|
60112
|
+
return Math.min(Math.max(rounded, minimum ?? -Infinity), maximum ?? Infinity);
|
|
60113
|
+
};
|
|
60114
|
+
|
|
60115
|
+
// ../form-fields/dist/esm/ui/number-input-field/number-input-field-headless.js
|
|
60093
60116
|
var NumberInput = ({ children }) => {
|
|
60094
60117
|
const { id: id6, value, onChange, disabled, required, readOnly, onBlur, onFocus, FieldLayout, hasError, validation } = useFieldPropsV2();
|
|
60095
60118
|
const { labelId } = useFieldAttributes();
|
|
@@ -60152,6 +60175,7 @@ var Input12 = ({ className }) => {
|
|
|
60152
60175
|
preventScroll: true
|
|
60153
60176
|
});
|
|
60154
60177
|
}, id6);
|
|
60178
|
+
useKeepPrehydrationValue(ref, readNumber);
|
|
60155
60179
|
return /* @__PURE__ */ React172.createElement(Input, {
|
|
60156
60180
|
ref,
|
|
60157
60181
|
id: inputId,
|
|
@@ -60300,6 +60324,18 @@ PaymentInput.Input = Input13;
|
|
|
60300
60324
|
PaymentInput.Description = Description;
|
|
60301
60325
|
PaymentInput.Error = Error2;
|
|
60302
60326
|
|
|
60327
|
+
// ../form-fields/dist/esm/field-viewer/phone-prehydration-reader.js
|
|
60328
|
+
var readPhoneNumber = (element, props2) => {
|
|
60329
|
+
const typed = element.value;
|
|
60330
|
+
if (!typed) {
|
|
60331
|
+
return void 0;
|
|
60332
|
+
}
|
|
60333
|
+
const { defaultCountry, validation } = props2;
|
|
60334
|
+
const allowedCountryCodes = validation?.string?.phoneOptions?.allowedCountryCodes;
|
|
60335
|
+
const country = parseCountryCodeFromPhoneNumber(typed) || defaultCountry || (allowedCountryCodes?.length === 1 ? allowedCountryCodes[0] : void 0);
|
|
60336
|
+
return normalizePhone(parseLocalPhone(typed, country)) ?? void 0;
|
|
60337
|
+
};
|
|
60338
|
+
|
|
60303
60339
|
// ../form-fields/dist/esm/ui/phone-input-field/phone-input/use-countries.js
|
|
60304
60340
|
init_esm();
|
|
60305
60341
|
function useCountries() {
|
|
@@ -60693,6 +60729,7 @@ var PhoneNumber2 = ({ className }) => {
|
|
|
60693
60729
|
preventScroll: true
|
|
60694
60730
|
});
|
|
60695
60731
|
}, id6);
|
|
60732
|
+
useKeepPrehydrationValue(ref, readPhoneNumber);
|
|
60696
60733
|
return /* @__PURE__ */ React172.createElement(Input, {
|
|
60697
60734
|
ref,
|
|
60698
60735
|
id: inputId,
|