@ohhwells/bridge 0.1.112-next.291 → 0.1.113-next.292

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
@@ -17537,19 +17537,37 @@ function MadeWithOhhWells() {
17537
17537
  }
17538
17538
  );
17539
17539
  }
17540
- 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){}})();`;
17540
+ 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){}})();`;
17541
+ function subdomainFromCookie() {
17542
+ if (typeof document === "undefined") return "";
17543
+ const match = document.cookie.match(/(?:^|; )ohw-subdomain=([^;]*)/);
17544
+ return match ? decodeURIComponent(match[1]) : "";
17545
+ }
17541
17546
  function resolveSubdomain(subdomainFromQuery) {
17547
+ if (typeof window !== "undefined") {
17548
+ const fromGlobal = window.__OHW_SUBDOMAIN__;
17549
+ if (fromGlobal) return fromGlobal;
17550
+ }
17542
17551
  if (subdomainFromQuery) return subdomainFromQuery;
17543
17552
  if (typeof window !== "undefined") {
17544
- const parts = window.location.hostname.split(".");
17545
- if (parts.length >= 3 && parts[0] !== "www") return parts[0];
17553
+ const host = window.location.hostname.toLowerCase();
17554
+ if (host.endsWith(".ohhwells.site")) {
17555
+ const label = host.slice(0, -".ohhwells.site".length).split(".").pop();
17556
+ if (label && label !== "www") return label;
17557
+ }
17558
+ const fromCookie = subdomainFromCookie();
17559
+ if (fromCookie) return fromCookie;
17560
+ const isPlatformHost = host.endsWith(".ohhwells.site") || host === "localhost" || host.endsWith(".localhost") || host.endsWith(".vercel.app");
17561
+ if (!isPlatformHost) return "";
17546
17562
  }
17547
17563
  const siteUrl = process.env.NEXT_PUBLIC_SITE_URL;
17548
17564
  if (siteUrl) {
17549
17565
  try {
17550
17566
  const host = new URL(siteUrl).hostname;
17551
- const siteParts = host.split(".");
17552
- if (siteParts.length >= 3 && siteParts[0] !== "www") return siteParts[0];
17567
+ if (host.endsWith(".ohhwells.site")) {
17568
+ const label = host.slice(0, -".ohhwells.site".length).split(".").pop();
17569
+ if (label && label !== "www") return label;
17570
+ }
17553
17571
  } catch {
17554
17572
  }
17555
17573
  }
@@ -17587,7 +17605,26 @@ function OhhwellsBridge() {
17587
17605
  };
17588
17606
  }, []);
17589
17607
  const subdomainFromQuery = searchParams.get("subdomain");
17590
- const subdomain = resolveSubdomain(subdomainFromQuery);
17608
+ const [subdomain, setSubdomain] = (0, import_react17.useState)(() => resolveSubdomain(subdomainFromQuery));
17609
+ (0, import_react17.useLayoutEffect)(() => {
17610
+ const next = resolveSubdomain(subdomainFromQuery);
17611
+ if (next !== subdomain) setSubdomain(next);
17612
+ if (next) return;
17613
+ const host = window.location.hostname.toLowerCase();
17614
+ if (host.endsWith(".ohhwells.site")) return;
17615
+ const t = window.setTimeout(() => {
17616
+ const retry = resolveSubdomain(subdomainFromQuery);
17617
+ if (retry) setSubdomain(retry);
17618
+ }, 0);
17619
+ return () => window.clearTimeout(t);
17620
+ }, [subdomainFromQuery, subdomain]);
17621
+ (0, import_react17.useEffect)(() => {
17622
+ if (!subdomainFromQuery || typeof window === "undefined") return;
17623
+ const url = new URL(window.location.href);
17624
+ if (!url.searchParams.has("subdomain")) return;
17625
+ url.searchParams.delete("subdomain");
17626
+ window.history.replaceState(null, "", url.pathname + url.search + url.hash);
17627
+ }, [subdomainFromQuery]);
17591
17628
  useLinkHrefGuardian(pathname, subdomain, isEditMode);
17592
17629
  useSavedLinkNavigation(isEditMode);
17593
17630
  const postToParent2 = (0, import_react17.useCallback)((data) => {
@@ -22996,7 +23033,7 @@ function OhhwellsBridge() {
22996
23033
  postToParent2({
22997
23034
  type: "ow:ready",
22998
23035
  version: "1",
22999
- bridgeVersion: "0.1.112",
23036
+ bridgeVersion: "0.1.113",
23000
23037
  path: pathname,
23001
23038
  nodes: collectEditableNodes(editContentRef.current),
23002
23039
  sections