@wix/form-public 0.568.0 → 0.570.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 +129 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +129 -23
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -36538,6 +36538,7 @@ var require_messages_en2 = __commonJS({
|
|
|
36538
36538
|
"date-picker.a11y.arrow-right": "Go to next month",
|
|
36539
36539
|
"input.error.message.incomplete-date-error.time": "Enter a time.",
|
|
36540
36540
|
"field.signature.canvas.aria-label.signed": "Signature drawing area (signed)",
|
|
36541
|
+
"field.a11y.cleared-announcement": "{fieldLabel} cleared.",
|
|
36541
36542
|
"settings.default-value-conflict.regex-error": "The regex must be viable for the entered default value. Update the regex or change the text.",
|
|
36542
36543
|
"contacts-phone.input.error.message.format-error": "Enter a valid phone number.",
|
|
36543
36544
|
"tags.input.error.message.required-error": "Choose an option.",
|
|
@@ -43852,6 +43853,7 @@ function useTranslation2() {
|
|
|
43852
43853
|
|
|
43853
43854
|
// ../form-experiments/dist/esm/experiments.js
|
|
43854
43855
|
var EXPERIMENTS = {
|
|
43856
|
+
ADDRESS_HOUSE_NUMBER_FALLBACK: "addressHouseNumberFallback",
|
|
43855
43857
|
ENABLE_FORM_SCHEMA_V2_PRICING_PLANS: "enableFormSchemaV2PricingPlans",
|
|
43856
43858
|
STREETLESS_LOCALITY_FALLBACK: "streetlessLocalityFallback",
|
|
43857
43859
|
SUBMIT_SUCCESS_NO_FOCUS: "specs.forms.SubmitSuccessNoFocus",
|
|
@@ -58771,6 +58773,22 @@ var searchByPostalCode = async ({ postalCode, countryCode }) => {
|
|
|
58771
58773
|
proximity
|
|
58772
58774
|
})));
|
|
58773
58775
|
};
|
|
58776
|
+
var searchByQuery = async ({ query, countryCode }) => {
|
|
58777
|
+
const { searchResults } = await es_exports8.search({
|
|
58778
|
+
query,
|
|
58779
|
+
...countryCode ? {
|
|
58780
|
+
countryCodes: [
|
|
58781
|
+
countryCode
|
|
58782
|
+
]
|
|
58783
|
+
} : {}
|
|
58784
|
+
});
|
|
58785
|
+
return (searchResults ?? []).flatMap(({ address }) => {
|
|
58786
|
+
const commonAddress = toCommonAddress(address);
|
|
58787
|
+
return commonAddress ? [
|
|
58788
|
+
commonAddress
|
|
58789
|
+
] : [];
|
|
58790
|
+
});
|
|
58791
|
+
};
|
|
58774
58792
|
var AddressFieldsContext = /* @__PURE__ */ createContext(void 0);
|
|
58775
58793
|
var AddressFieldsProvider = ({ children, fields }) => {
|
|
58776
58794
|
const value = useMemo(() => ({
|
|
@@ -58853,35 +58871,111 @@ AddressLine2.Label = Label;
|
|
|
58853
58871
|
AddressLine2.Input = Input3;
|
|
58854
58872
|
AddressLine2.Description = Description;
|
|
58855
58873
|
AddressLine2.Error = Error2;
|
|
58874
|
+
|
|
58875
|
+
// ../form-fields/dist/esm/ui/address-input/resolve-place.js
|
|
58876
|
+
var STREET_PLACE_TYPE = "route";
|
|
58877
|
+
var isStreetPrediction = (prediction) => prediction.types?.includes(STREET_PLACE_TYPE) ?? false;
|
|
58878
|
+
var ADDRESS_TEXT_SEPARATORS = /[\s,]+/;
|
|
58879
|
+
var toAddressTokens = (text) => text ? text.toLowerCase().split(ADDRESS_TEXT_SEPARATORS) : [];
|
|
58880
|
+
var containsHouseNumber = (text, houseNumber, streetName) => {
|
|
58881
|
+
if (!text || !houseNumber) {
|
|
58882
|
+
return false;
|
|
58883
|
+
}
|
|
58884
|
+
const streetNameTokens = toAddressTokens(streetName);
|
|
58885
|
+
return toAddressTokens(text).filter((token) => !streetNameTokens.includes(token)).includes(houseNumber.toLowerCase());
|
|
58886
|
+
};
|
|
58887
|
+
var postalCodeBase = (postalCode) => postalCode.split("-")[0];
|
|
58888
|
+
var isSamePostalArea = (place, candidate) => !place.postalCode || !candidate.postalCode || postalCodeBase(place.postalCode) === postalCodeBase(candidate.postalCode);
|
|
58889
|
+
var isSameStreet = (place, candidate) => Boolean(place.streetAddress?.name) && place.streetAddress?.name?.toLowerCase() === candidate.streetAddress?.name?.toLowerCase();
|
|
58890
|
+
var isSameStreetLocation = (place, candidate) => candidate.country === place.country && candidate.subdivision === place.subdivision && isSamePostalArea(place, candidate) && isSameStreet(place, candidate);
|
|
58891
|
+
var searchHouseNumber = async (query, place, searchByQuery2) => {
|
|
58892
|
+
try {
|
|
58893
|
+
const candidates = await searchByQuery2({
|
|
58894
|
+
query,
|
|
58895
|
+
countryCode: place.country ?? void 0
|
|
58896
|
+
});
|
|
58897
|
+
return candidates?.find((candidate) => isSameStreetLocation(place, candidate) && containsHouseNumber(query, candidate.streetAddress?.number, place.streetAddress?.name))?.streetAddress?.number;
|
|
58898
|
+
} catch {
|
|
58899
|
+
return void 0;
|
|
58900
|
+
}
|
|
58901
|
+
};
|
|
58902
|
+
var withHouseNumber = (place, houseNumber, suggestionText) => {
|
|
58903
|
+
const streetAddress = {
|
|
58904
|
+
...place.streetAddress,
|
|
58905
|
+
number: houseNumber
|
|
58906
|
+
};
|
|
58907
|
+
if (!containsHouseNumber(suggestionText, houseNumber)) {
|
|
58908
|
+
return {
|
|
58909
|
+
...place,
|
|
58910
|
+
streetAddress
|
|
58911
|
+
};
|
|
58912
|
+
}
|
|
58913
|
+
return {
|
|
58914
|
+
...place,
|
|
58915
|
+
...place.addressLine ? {
|
|
58916
|
+
addressLine: suggestionText
|
|
58917
|
+
} : {},
|
|
58918
|
+
streetAddress: {
|
|
58919
|
+
...streetAddress,
|
|
58920
|
+
formattedAddressLine: suggestionText
|
|
58921
|
+
}
|
|
58922
|
+
};
|
|
58923
|
+
};
|
|
58924
|
+
var resolvePlace = async ({ searchId, prediction, getPlace: getPlace6, searchByQuery: searchByQuery2 }) => {
|
|
58925
|
+
const place = await getPlace6({
|
|
58926
|
+
searchId
|
|
58927
|
+
});
|
|
58928
|
+
if (!place || place.streetAddress?.number || !prediction?.description || !isStreetPrediction(prediction) || !searchByQuery2) {
|
|
58929
|
+
return place;
|
|
58930
|
+
}
|
|
58931
|
+
const houseNumber = await searchHouseNumber(prediction.description, place, searchByQuery2);
|
|
58932
|
+
return houseNumber ? withHouseNumber(place, houseNumber, prediction.textStructure?.mainText) : place;
|
|
58933
|
+
};
|
|
58934
|
+
|
|
58935
|
+
// ../form-fields/dist/esm/ui/address-input/use-atlas.js
|
|
58856
58936
|
var useAtlas = ({ enabled }) => {
|
|
58857
58937
|
const { actions } = useFieldActions();
|
|
58938
|
+
const { isExperimentEnabled: isExperimentEnabled2 } = useExperiments();
|
|
58939
|
+
const addressHouseNumberFallbackEnabled = isExperimentEnabled2(EXPERIMENTS.ADDRESS_HOUSE_NUMBER_FALLBACK);
|
|
58858
58940
|
const [sessionToken, setSessionToken] = useState(generateUUID());
|
|
58859
58941
|
const refreshSessionToken = useCallback(() => setSessionToken(generateUUID()), []);
|
|
58942
|
+
const resolvePlaceRequestId = useRef(0);
|
|
58860
58943
|
return useMemo(() => {
|
|
58861
|
-
const { predict: predict6, getPlace: getPlace6, searchByPostalCode: searchByPostalCode2 } = actions ?? {};
|
|
58944
|
+
const { predict: predict6, getPlace: getPlace6, searchByPostalCode: searchByPostalCode2, searchByQuery: searchByQuery2 } = actions ?? {};
|
|
58862
58945
|
if (!enabled || !predict6 || !getPlace6 || !searchByPostalCode2) {
|
|
58863
58946
|
return void 0;
|
|
58864
58947
|
}
|
|
58948
|
+
const getPlaceInSession = (params) => getPlace6({
|
|
58949
|
+
...params,
|
|
58950
|
+
sessionToken,
|
|
58951
|
+
refreshSessionToken
|
|
58952
|
+
});
|
|
58865
58953
|
return {
|
|
58866
58954
|
predict: (params) => predict6({
|
|
58867
58955
|
...params,
|
|
58868
58956
|
sessionToken
|
|
58869
58957
|
}),
|
|
58870
|
-
getPlace:
|
|
58871
|
-
...params,
|
|
58872
|
-
sessionToken,
|
|
58873
|
-
refreshSessionToken
|
|
58874
|
-
}),
|
|
58958
|
+
getPlace: getPlaceInSession,
|
|
58875
58959
|
searchByPostalCode: (params) => searchByPostalCode2({
|
|
58876
58960
|
...params,
|
|
58877
58961
|
sessionToken
|
|
58878
|
-
})
|
|
58962
|
+
}),
|
|
58963
|
+
resolvePlace: async (params) => {
|
|
58964
|
+
const requestId = ++resolvePlaceRequestId.current;
|
|
58965
|
+
const place = await resolvePlace({
|
|
58966
|
+
...params,
|
|
58967
|
+
getPlace: getPlaceInSession,
|
|
58968
|
+
searchByQuery: addressHouseNumberFallbackEnabled ? searchByQuery2 : void 0
|
|
58969
|
+
});
|
|
58970
|
+
return requestId === resolvePlaceRequestId.current ? place : void 0;
|
|
58971
|
+
}
|
|
58879
58972
|
};
|
|
58880
58973
|
}, [
|
|
58881
58974
|
enabled,
|
|
58882
58975
|
actions,
|
|
58883
58976
|
sessionToken,
|
|
58884
|
-
refreshSessionToken
|
|
58977
|
+
refreshSessionToken,
|
|
58978
|
+
addressHouseNumberFallbackEnabled
|
|
58885
58979
|
]);
|
|
58886
58980
|
};
|
|
58887
58981
|
|
|
@@ -59082,8 +59176,10 @@ var AddressLineAutocomplete = ({ children, value, onChange, disabled, readOnly,
|
|
|
59082
59176
|
return;
|
|
59083
59177
|
}
|
|
59084
59178
|
clearPredictions();
|
|
59085
|
-
const
|
|
59086
|
-
|
|
59179
|
+
const searchId = String(key);
|
|
59180
|
+
const address = await atlas?.resolvePlace({
|
|
59181
|
+
searchId,
|
|
59182
|
+
prediction: predictions.find((prediction) => prediction.searchId === searchId)
|
|
59087
59183
|
});
|
|
59088
59184
|
if (address && onAddressSelect) {
|
|
59089
59185
|
onAddressSelect(address);
|
|
@@ -59091,7 +59187,8 @@ var AddressLineAutocomplete = ({ children, value, onChange, disabled, readOnly,
|
|
|
59091
59187
|
}, [
|
|
59092
59188
|
onAddressSelect,
|
|
59093
59189
|
clearPredictions,
|
|
59094
|
-
atlas
|
|
59190
|
+
atlas,
|
|
59191
|
+
predictions
|
|
59095
59192
|
]);
|
|
59096
59193
|
const handleBlur = useCallback(() => {
|
|
59097
59194
|
clearPredictions();
|
|
@@ -59858,8 +59955,10 @@ var StreetNameAutocomplete = ({ children, value, onChange, disabled, readOnly, r
|
|
|
59858
59955
|
if (!key) {
|
|
59859
59956
|
return;
|
|
59860
59957
|
}
|
|
59861
|
-
const
|
|
59862
|
-
|
|
59958
|
+
const searchId = String(key);
|
|
59959
|
+
const address = await atlas?.resolvePlace({
|
|
59960
|
+
searchId,
|
|
59961
|
+
prediction: predictions.find((prediction) => prediction.searchId === searchId)
|
|
59863
59962
|
});
|
|
59864
59963
|
if (address && onAddressSelect) {
|
|
59865
59964
|
onAddressSelect(address);
|
|
@@ -59867,7 +59966,8 @@ var StreetNameAutocomplete = ({ children, value, onChange, disabled, readOnly, r
|
|
|
59867
59966
|
}, [
|
|
59868
59967
|
onAddressSelect,
|
|
59869
59968
|
clearPredictions,
|
|
59870
|
-
atlas
|
|
59969
|
+
atlas,
|
|
59970
|
+
predictions
|
|
59871
59971
|
]);
|
|
59872
59972
|
const handleBlur = useCallback(() => {
|
|
59873
59973
|
clearPredictions();
|
|
@@ -60172,15 +60272,21 @@ var MultilineAddress = ({ children, className }) => {
|
|
|
60172
60272
|
const { validateFields: parentValidateFields } = useFieldValidation();
|
|
60173
60273
|
const formSchema = useForm();
|
|
60174
60274
|
const fieldActions = useFieldActions();
|
|
60175
|
-
const headlessFieldActions = useMemo(() =>
|
|
60176
|
-
|
|
60177
|
-
|
|
60178
|
-
|
|
60179
|
-
|
|
60180
|
-
|
|
60181
|
-
|
|
60182
|
-
|
|
60183
|
-
|
|
60275
|
+
const headlessFieldActions = useMemo(() => {
|
|
60276
|
+
const hostResolvesPlaces = Boolean(fieldActions.actions?.getPlace);
|
|
60277
|
+
return {
|
|
60278
|
+
...fieldActions,
|
|
60279
|
+
actions: {
|
|
60280
|
+
predict: predict5,
|
|
60281
|
+
getPlace: getPlace5,
|
|
60282
|
+
searchByPostalCode,
|
|
60283
|
+
...hostResolvesPlaces ? {} : {
|
|
60284
|
+
searchByQuery
|
|
60285
|
+
},
|
|
60286
|
+
...fieldActions.actions
|
|
60287
|
+
}
|
|
60288
|
+
};
|
|
60289
|
+
}, [
|
|
60184
60290
|
fieldActions
|
|
60185
60291
|
]);
|
|
60186
60292
|
const { form, isMultilineAddressField: isMultilineAddressField2 } = useMultilineAddressForm({
|