@algenium/blocks 1.7.0-rc.5 → 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 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
- () => parseInitial(value)
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
- onChange(next);
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
- onChange(next);
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
- onChange(normalized);
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
- onChange(uspsSuggestion);
7961
+ emitChange.current(uspsSuggestion);
7895
7962
  setUspsSuggestion(null);
7896
7963
  lastValidatedSigRef.current = addressSig(uspsSuggestion);
7897
7964
  setUspsVerifiedNoChange(true);
@@ -8811,6 +8878,63 @@ function PdfViewer({
8811
8878
  }
8812
8879
  );
8813
8880
  }
8881
+ function usePdfViewerDialogScrollLock(active) {
8882
+ React2.useLayoutEffect(() => {
8883
+ if (!active || typeof document === "undefined") return;
8884
+ const html = document.documentElement;
8885
+ const body = document.body;
8886
+ const scrollRoots = [
8887
+ ...document.querySelectorAll("[data-scroll-lock-root]")
8888
+ ];
8889
+ const scrollTopSnapshot = scrollRoots.map((el) => ({
8890
+ el,
8891
+ scrollTop: el.scrollTop
8892
+ }));
8893
+ const targets = /* @__PURE__ */ new Set([html, body, ...scrollRoots]);
8894
+ const snapshot = [...targets].map((el) => ({
8895
+ el,
8896
+ overflow: el.style.overflow,
8897
+ overscrollBehavior: el.style.overscrollBehavior
8898
+ }));
8899
+ const windowScrollY = window.scrollY;
8900
+ for (const el of targets) {
8901
+ el.style.overflow = "hidden";
8902
+ el.style.overscrollBehavior = "none";
8903
+ }
8904
+ const dialogSurfaceSelector = '[data-slot="dialog-content"]';
8905
+ const shouldAllowEventTarget = (target) => target instanceof Element && Boolean(target.closest(dialogSurfaceSelector));
8906
+ const onWheel = (e) => {
8907
+ if (shouldAllowEventTarget(e.target)) return;
8908
+ e.preventDefault();
8909
+ };
8910
+ const onTouchMove = (e) => {
8911
+ if (shouldAllowEventTarget(e.target)) return;
8912
+ e.preventDefault();
8913
+ };
8914
+ window.addEventListener("wheel", onWheel, {
8915
+ capture: true,
8916
+ passive: false
8917
+ });
8918
+ window.addEventListener("touchmove", onTouchMove, {
8919
+ capture: true,
8920
+ passive: false
8921
+ });
8922
+ return () => {
8923
+ window.removeEventListener("wheel", onWheel, { capture: true });
8924
+ window.removeEventListener("touchmove", onTouchMove, {
8925
+ capture: true
8926
+ });
8927
+ for (const { el, overflow, overscrollBehavior } of snapshot) {
8928
+ el.style.overflow = overflow;
8929
+ el.style.overscrollBehavior = overscrollBehavior;
8930
+ }
8931
+ for (const { el, scrollTop } of scrollTopSnapshot) {
8932
+ el.scrollTop = scrollTop;
8933
+ }
8934
+ window.scrollTo(0, windowScrollY);
8935
+ };
8936
+ }, [active]);
8937
+ }
8814
8938
  var fullscreenDialogContentClass = "!max-w-none !w-screen !h-screen !p-0 !border-0 !bg-black/95 !rounded-none !top-0 !left-0 !translate-x-0 !translate-y-0 !gap-0 !shadow-none !flex !flex-col data-[state=open]:!zoom-in-100 data-[state=closed]:!zoom-out-100";
8815
8939
  function PdfViewerDialog({
8816
8940
  open,
@@ -8826,6 +8950,7 @@ function PdfViewerDialog({
8826
8950
  const closeLabel = labels?.close ?? "Close";
8827
8951
  const dialogTitle = labels?.dialogTitle ?? title ?? "PDF document";
8828
8952
  const dialogDescription = labels?.dialogDescription ?? "Document viewer with zoom and page navigation.";
8953
+ usePdfViewerDialogScrollLock(open);
8829
8954
  const {
8830
8955
  className: forwardedClassName,
8831
8956
  toolbarClassName: forwardedToolbarClassName,
@@ -8955,10 +9080,14 @@ exports.USAddressInput = USAddressInput;
8955
9080
  exports.UpcomingEvents = UpcomingEvents;
8956
9081
  exports.buttonVariants = buttonVariants;
8957
9082
  exports.cn = cn;
9083
+ exports.composeAddressLine1ForNls = composeAddressLine1ForNls;
8958
9084
  exports.defaultLanguages = defaultLanguages;
8959
9085
  exports.getEnvironmentDotClass = getEnvironmentDotClass;
8960
9086
  exports.getEnvironmentLabel = getEnvironmentLabel;
8961
9087
  exports.isBlocksDataEnvironment = isBlocksDataEnvironment;
9088
+ exports.joinStreet = joinStreet;
9089
+ exports.sanitizeForNls = sanitizeForNls;
9090
+ exports.splitStreet = splitStreet;
8962
9091
  exports.toggleVariants = toggleVariants;
8963
9092
  exports.useCalendarContext = useCalendarContext;
8964
9093
  exports.useChatRoom = useChatRoom;