@ohhwells/bridge 0.1.117 → 0.1.118

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
@@ -17618,19 +17618,37 @@ function MadeWithOhhWells() {
17618
17618
  }
17619
17619
  );
17620
17620
  }
17621
- var OHW_LOADER_PREHYDRATE_SCRIPT = `(function(){try{var p=location.hostname.split(".");var fromHost=p.length>=3&&p[0]!=="www"?p[0]:"";var fromQuery=new URLSearchParams(location.search).get("subdomain")||"";if(!fromHost&&!fromQuery)return;var e=document.getElementById("ohw-loader");if(e)e.style.display="flex"}catch(e){}})();`;
17621
+ var OHW_LOADER_PREHYDRATE_SCRIPT = `(function(){try{var fromGlobal=typeof window!=="undefined"&&window.__OHW_SUBDOMAIN__?String(window.__OHW_SUBDOMAIN__):"";var p=location.hostname.split(".");var fromHost=location.hostname.endsWith(".ohhwells.site")&&p[0]&&p[0]!=="www"?p[0]:"";var fromQuery=new URLSearchParams(location.search).get("subdomain")||"";var fromCookie=(document.cookie.match(/(?:^|; )ohw-subdomain=([^;]*)/)||[])[1];fromCookie=fromCookie?decodeURIComponent(fromCookie):"";if(!fromGlobal&&!fromHost&&!fromQuery&&!fromCookie)return;var e=document.getElementById("ohw-loader");if(e)e.style.display="flex"}catch(e){}})();`;
17622
+ function subdomainFromCookie() {
17623
+ if (typeof document === "undefined") return "";
17624
+ const match = document.cookie.match(/(?:^|; )ohw-subdomain=([^;]*)/);
17625
+ return match ? decodeURIComponent(match[1]) : "";
17626
+ }
17622
17627
  function resolveSubdomain(subdomainFromQuery) {
17628
+ if (typeof window !== "undefined") {
17629
+ const fromGlobal = window.__OHW_SUBDOMAIN__;
17630
+ if (fromGlobal) return fromGlobal;
17631
+ }
17623
17632
  if (subdomainFromQuery) return subdomainFromQuery;
17624
17633
  if (typeof window !== "undefined") {
17625
- const parts = window.location.hostname.split(".");
17626
- if (parts.length >= 3 && parts[0] !== "www") return parts[0];
17634
+ const host = window.location.hostname.toLowerCase();
17635
+ if (host.endsWith(".ohhwells.site")) {
17636
+ const label = host.slice(0, -".ohhwells.site".length).split(".").pop();
17637
+ if (label && label !== "www") return label;
17638
+ }
17639
+ const fromCookie = subdomainFromCookie();
17640
+ if (fromCookie) return fromCookie;
17641
+ const isPlatformHost = host.endsWith(".ohhwells.site") || host === "localhost" || host.endsWith(".localhost") || host.endsWith(".vercel.app");
17642
+ if (!isPlatformHost) return "";
17627
17643
  }
17628
17644
  const siteUrl = process.env.NEXT_PUBLIC_SITE_URL;
17629
17645
  if (siteUrl) {
17630
17646
  try {
17631
17647
  const host = new URL(siteUrl).hostname;
17632
- const siteParts = host.split(".");
17633
- if (siteParts.length >= 3 && siteParts[0] !== "www") return siteParts[0];
17648
+ if (host.endsWith(".ohhwells.site")) {
17649
+ const label = host.slice(0, -".ohhwells.site".length).split(".").pop();
17650
+ if (label && label !== "www") return label;
17651
+ }
17634
17652
  } catch {
17635
17653
  }
17636
17654
  }
@@ -17668,7 +17686,26 @@ function OhhwellsBridge() {
17668
17686
  };
17669
17687
  }, []);
17670
17688
  const subdomainFromQuery = searchParams.get("subdomain");
17671
- const subdomain = resolveSubdomain(subdomainFromQuery);
17689
+ const [subdomain, setSubdomain] = (0, import_react17.useState)(() => resolveSubdomain(subdomainFromQuery));
17690
+ (0, import_react17.useLayoutEffect)(() => {
17691
+ const next = resolveSubdomain(subdomainFromQuery);
17692
+ if (next !== subdomain) setSubdomain(next);
17693
+ if (next) return;
17694
+ const host = window.location.hostname.toLowerCase();
17695
+ if (host.endsWith(".ohhwells.site")) return;
17696
+ const t = window.setTimeout(() => {
17697
+ const retry = resolveSubdomain(subdomainFromQuery);
17698
+ if (retry) setSubdomain(retry);
17699
+ }, 0);
17700
+ return () => window.clearTimeout(t);
17701
+ }, [subdomainFromQuery, subdomain]);
17702
+ (0, import_react17.useEffect)(() => {
17703
+ if (!subdomainFromQuery || typeof window === "undefined") return;
17704
+ const url = new URL(window.location.href);
17705
+ if (!url.searchParams.has("subdomain")) return;
17706
+ url.searchParams.delete("subdomain");
17707
+ window.history.replaceState(null, "", url.pathname + url.search + url.hash);
17708
+ }, [subdomainFromQuery]);
17672
17709
  useLinkHrefGuardian(pathname, subdomain, isEditMode);
17673
17710
  useSavedLinkNavigation(isEditMode);
17674
17711
  const postToParent2 = (0, import_react17.useCallback)((data) => {
@@ -23147,7 +23184,7 @@ function OhhwellsBridge() {
23147
23184
  postToParent2({
23148
23185
  type: "ow:ready",
23149
23186
  version: "1",
23150
- bridgeVersion: "0.1.116",
23187
+ bridgeVersion: "0.1.117",
23151
23188
  path: pathname,
23152
23189
  nodes: collectEditableNodes(editContentRef.current),
23153
23190
  sections