@algenium/blocks 1.7.0-rc.6 → 1.7.0-rc.7
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 +80 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -2
- package/dist/index.d.ts +76 -2
- package/dist/index.js +77 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7634,6 +7634,26 @@ function CardInput({
|
|
|
7634
7634
|
)
|
|
7635
7635
|
] });
|
|
7636
7636
|
}
|
|
7637
|
+
|
|
7638
|
+
// src/lib/usAddress.ts
|
|
7639
|
+
function splitStreet(street) {
|
|
7640
|
+
const trimmed = street.trim();
|
|
7641
|
+
const m = trimmed.match(/^(\S+)\s+(.+)$/);
|
|
7642
|
+
if (m && /^\d/.test(m[1])) {
|
|
7643
|
+
return { number: m[1], name: m[2].trim() };
|
|
7644
|
+
}
|
|
7645
|
+
return { number: "", name: trimmed };
|
|
7646
|
+
}
|
|
7647
|
+
function joinStreet(streetNumber, streetName) {
|
|
7648
|
+
return [streetNumber, streetName].map((s) => s.trim()).filter((s) => s.length > 0).join(" ");
|
|
7649
|
+
}
|
|
7650
|
+
function sanitizeForNls(input) {
|
|
7651
|
+
return input.replace(/[^A-Za-z0-9 .,'#\-/]/g, " ").replace(/\s+/g, " ").trim();
|
|
7652
|
+
}
|
|
7653
|
+
function composeAddressLine1ForNls(v) {
|
|
7654
|
+
const line = [v.streetNumber, v.streetName, v.apt].filter((s) => typeof s === "string" && s.trim().length > 0).join(" ");
|
|
7655
|
+
return sanitizeForNls(line).slice(0, 40);
|
|
7656
|
+
}
|
|
7637
7657
|
function parseInitial(value) {
|
|
7638
7658
|
if (!value) {
|
|
7639
7659
|
return {
|
|
@@ -7654,6 +7674,28 @@ function parseInitial(value) {
|
|
|
7654
7674
|
country: "US"
|
|
7655
7675
|
};
|
|
7656
7676
|
}
|
|
7677
|
+
function legacyToModern(legacy) {
|
|
7678
|
+
return {
|
|
7679
|
+
street: joinStreet(legacy.streetNumber, legacy.streetName),
|
|
7680
|
+
street2: legacy.apt ?? "",
|
|
7681
|
+
city: legacy.city,
|
|
7682
|
+
state: legacy.state,
|
|
7683
|
+
zip: legacy.zipCode,
|
|
7684
|
+
country: "US"
|
|
7685
|
+
};
|
|
7686
|
+
}
|
|
7687
|
+
function toLegacy(modern) {
|
|
7688
|
+
const parts = splitStreet(modern.street);
|
|
7689
|
+
return {
|
|
7690
|
+
streetNumber: sanitizeForNls(parts.number),
|
|
7691
|
+
streetName: sanitizeForNls(parts.name),
|
|
7692
|
+
apt: modern.street2 ? sanitizeForNls(modern.street2) : void 0,
|
|
7693
|
+
city: modern.city.trim(),
|
|
7694
|
+
state: modern.state.trim().toUpperCase(),
|
|
7695
|
+
zipCode: modern.zip.replace(/\D/g, "").slice(0, 5),
|
|
7696
|
+
country: "US"
|
|
7697
|
+
};
|
|
7698
|
+
}
|
|
7657
7699
|
function addressSig(a) {
|
|
7658
7700
|
return JSON.stringify({
|
|
7659
7701
|
street: a.street.trim(),
|
|
@@ -7679,14 +7721,19 @@ function USAddressInput({
|
|
|
7679
7721
|
disabled = false,
|
|
7680
7722
|
largeText = false,
|
|
7681
7723
|
className,
|
|
7682
|
-
onError
|
|
7724
|
+
onError,
|
|
7725
|
+
legacyMode = false,
|
|
7726
|
+
valueLegacy,
|
|
7727
|
+
onChangeLegacy
|
|
7683
7728
|
}) {
|
|
7684
7729
|
const [searchQuery, setSearchQuery] = React2.useState("");
|
|
7685
7730
|
const [showSuggestions, setShowSuggestions] = React2.useState(false);
|
|
7686
7731
|
const [suggestions, setSuggestions] = React2.useState([]);
|
|
7687
|
-
const [address, setAddress] = React2.useState(
|
|
7688
|
-
()
|
|
7689
|
-
|
|
7732
|
+
const [address, setAddress] = React2.useState(() => {
|
|
7733
|
+
if (value != null) return parseInitial(value);
|
|
7734
|
+
if (valueLegacy != null) return legacyToModern(valueLegacy);
|
|
7735
|
+
return parseInitial(void 0);
|
|
7736
|
+
});
|
|
7690
7737
|
const [sessionToken] = React2.useState(
|
|
7691
7738
|
() => typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random()}`
|
|
7692
7739
|
);
|
|
@@ -7708,6 +7755,22 @@ function USAddressInput({
|
|
|
7708
7755
|
const addressRef = React2.useRef(address);
|
|
7709
7756
|
addressRef.current = address;
|
|
7710
7757
|
const lastValidatedSigRef = React2.useRef("");
|
|
7758
|
+
const onChangeLegacyRef = React2.useRef(onChangeLegacy);
|
|
7759
|
+
onChangeLegacyRef.current = onChangeLegacy;
|
|
7760
|
+
const legacyModeRef = React2.useRef(legacyMode);
|
|
7761
|
+
legacyModeRef.current = legacyMode;
|
|
7762
|
+
const emitChange = React2.useRef((next) => {
|
|
7763
|
+
onChange(next);
|
|
7764
|
+
if (legacyModeRef.current && onChangeLegacyRef.current) {
|
|
7765
|
+
onChangeLegacyRef.current(toLegacy(next));
|
|
7766
|
+
}
|
|
7767
|
+
});
|
|
7768
|
+
emitChange.current = (next) => {
|
|
7769
|
+
onChange(next);
|
|
7770
|
+
if (legacyModeRef.current && onChangeLegacyRef.current) {
|
|
7771
|
+
onChangeLegacyRef.current(toLegacy(next));
|
|
7772
|
+
}
|
|
7773
|
+
};
|
|
7711
7774
|
const debouncedSearch = useDebouncedValue(searchQuery, 400);
|
|
7712
7775
|
const zipDigits = address.zip.replace(/\D/g, "").slice(0, 5);
|
|
7713
7776
|
const debouncedZip = useDebouncedValue(zipDigits, 400);
|
|
@@ -7724,13 +7787,18 @@ function USAddressInput({
|
|
|
7724
7787
|
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
7725
7788
|
}, []);
|
|
7726
7789
|
const valueSyncKey = value == null ? "" : `o:${JSON.stringify(value)}`;
|
|
7790
|
+
const valueLegacySyncKey = value != null || valueLegacy == null ? null : `l:${JSON.stringify(valueLegacy)}`;
|
|
7727
7791
|
React2.useEffect(() => {
|
|
7728
7792
|
setAddress(parseInitial(value));
|
|
7729
7793
|
}, [valueSyncKey]);
|
|
7794
|
+
React2.useEffect(() => {
|
|
7795
|
+
if (valueLegacySyncKey == null) return;
|
|
7796
|
+
setAddress(legacyToModern(valueLegacy));
|
|
7797
|
+
}, [valueLegacySyncKey]);
|
|
7730
7798
|
const handleFieldChange = (field, fieldValue) => {
|
|
7731
7799
|
setAddress((prev) => {
|
|
7732
7800
|
const next = field === "country" ? { ...prev, country: "US" } : { ...prev, [field]: fieldValue };
|
|
7733
|
-
|
|
7801
|
+
emitChange.current(next);
|
|
7734
7802
|
return next;
|
|
7735
7803
|
});
|
|
7736
7804
|
};
|
|
@@ -7802,7 +7870,7 @@ function USAddressInput({
|
|
|
7802
7870
|
if (cityEmpty && data.city) next.city = data.city;
|
|
7803
7871
|
if (stateEmpty && data.state) next.state = data.state;
|
|
7804
7872
|
next.country = "US";
|
|
7805
|
-
|
|
7873
|
+
emitChange.current(next);
|
|
7806
7874
|
return next;
|
|
7807
7875
|
});
|
|
7808
7876
|
}).catch(() => {
|
|
@@ -7816,7 +7884,6 @@ function USAddressInput({
|
|
|
7816
7884
|
debouncedZip,
|
|
7817
7885
|
allowZipLookup,
|
|
7818
7886
|
lookupZip,
|
|
7819
|
-
onChange,
|
|
7820
7887
|
labels.zipLookupFailed,
|
|
7821
7888
|
onError
|
|
7822
7889
|
]);
|
|
@@ -7878,7 +7945,7 @@ function USAddressInput({
|
|
|
7878
7945
|
country: "US"
|
|
7879
7946
|
};
|
|
7880
7947
|
setAddress(normalized);
|
|
7881
|
-
|
|
7948
|
+
emitChange.current(normalized);
|
|
7882
7949
|
setShowSuggestions(false);
|
|
7883
7950
|
setSearchQuery("");
|
|
7884
7951
|
setUspsSuggestion(null);
|
|
@@ -7891,7 +7958,7 @@ function USAddressInput({
|
|
|
7891
7958
|
const applyUspsSuggestion = () => {
|
|
7892
7959
|
if (!uspsSuggestion) return;
|
|
7893
7960
|
setAddress(uspsSuggestion);
|
|
7894
|
-
|
|
7961
|
+
emitChange.current(uspsSuggestion);
|
|
7895
7962
|
setUspsSuggestion(null);
|
|
7896
7963
|
lastValidatedSigRef.current = addressSig(uspsSuggestion);
|
|
7897
7964
|
setUspsVerifiedNoChange(true);
|
|
@@ -9013,10 +9080,14 @@ exports.USAddressInput = USAddressInput;
|
|
|
9013
9080
|
exports.UpcomingEvents = UpcomingEvents;
|
|
9014
9081
|
exports.buttonVariants = buttonVariants;
|
|
9015
9082
|
exports.cn = cn;
|
|
9083
|
+
exports.composeAddressLine1ForNls = composeAddressLine1ForNls;
|
|
9016
9084
|
exports.defaultLanguages = defaultLanguages;
|
|
9017
9085
|
exports.getEnvironmentDotClass = getEnvironmentDotClass;
|
|
9018
9086
|
exports.getEnvironmentLabel = getEnvironmentLabel;
|
|
9019
9087
|
exports.isBlocksDataEnvironment = isBlocksDataEnvironment;
|
|
9088
|
+
exports.joinStreet = joinStreet;
|
|
9089
|
+
exports.sanitizeForNls = sanitizeForNls;
|
|
9090
|
+
exports.splitStreet = splitStreet;
|
|
9020
9091
|
exports.toggleVariants = toggleVariants;
|
|
9021
9092
|
exports.useCalendarContext = useCalendarContext;
|
|
9022
9093
|
exports.useChatRoom = useChatRoom;
|