@ohhwells/bridge 0.1.52-next.131 → 0.1.52-next.132

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
@@ -8976,6 +8976,57 @@ function deleteFooterColumn(column) {
8976
8976
  };
8977
8977
  }
8978
8978
 
8979
+ // src/lib/logo-identity.ts
8980
+ var LOGO_TEXT_KEYS = ["nav-logo-text", "footer-logo-text", "logo-text"];
8981
+ var LOGO_IMAGE_KEYS = ["nav-logo-image", "footer-logo", "footer-logo-image"];
8982
+ var LOGO_PLACEHOLDER_KEY = "logo-is-placeholder";
8983
+ var PLACEHOLDER_BUSINESS_NAME = "Business name";
8984
+ function resolveLogoDisplayText(text) {
8985
+ const trimmed = (text ?? "").trim();
8986
+ return trimmed || PLACEHOLDER_BUSINESS_NAME;
8987
+ }
8988
+ function applyLogoIdentity(text, isPlaceholder) {
8989
+ const display = resolveLogoDisplayText(text);
8990
+ const placeholder = isPlaceholder || !text.trim() || display === PLACEHOLDER_BUSINESS_NAME;
8991
+ for (const key of LOGO_TEXT_KEYS) {
8992
+ document.querySelectorAll(`[data-ohw-key="${key}"]`).forEach((el) => {
8993
+ if (el.textContent !== display) el.textContent = display;
8994
+ });
8995
+ }
8996
+ for (const key of LOGO_IMAGE_KEYS) {
8997
+ document.querySelectorAll(`[data-ohw-key="${key}"]`).forEach((el) => {
8998
+ const img = el instanceof HTMLImageElement ? el : el.querySelector("img");
8999
+ if (img) img.alt = display;
9000
+ });
9001
+ }
9002
+ document.querySelectorAll('[data-ohw-role="logo"], [data-ohw-logo]').forEach((el) => {
9003
+ if (placeholder) el.setAttribute("data-ohw-placeholder", "");
9004
+ else el.removeAttribute("data-ohw-placeholder");
9005
+ });
9006
+ return display;
9007
+ }
9008
+ function readLogoIdentityFromDom() {
9009
+ for (const key of LOGO_TEXT_KEYS) {
9010
+ const el = document.querySelector(`[data-ohw-key="${key}"]`);
9011
+ if (el?.textContent?.trim()) {
9012
+ const text = el.textContent.trim();
9013
+ const logoRoot = el.closest('[data-ohw-role="logo"], [data-ohw-logo]');
9014
+ const isPlaceholder = logoRoot?.hasAttribute("data-ohw-placeholder") === true || text === PLACEHOLDER_BUSINESS_NAME;
9015
+ return { text, isPlaceholder };
9016
+ }
9017
+ }
9018
+ const logoImg = document.querySelector(
9019
+ '[data-ohw-key="nav-logo-image"], [data-ohw-key="footer-logo"]'
9020
+ );
9021
+ if (logoImg?.alt?.trim()) {
9022
+ const text = logoImg.alt.trim();
9023
+ const logoRoot = logoImg.closest('[data-ohw-role="logo"], [data-ohw-logo]');
9024
+ const isPlaceholder = logoRoot?.hasAttribute("data-ohw-placeholder") === true || text === PLACEHOLDER_BUSINESS_NAME;
9025
+ return { text, isPlaceholder };
9026
+ }
9027
+ return { text: PLACEHOLDER_BUSINESS_NAME, isPlaceholder: true };
9028
+ }
9029
+
8979
9030
  // src/lib/site-wide-scope.ts
8980
9031
  function getLogoElement(el) {
8981
9032
  const marked = el.closest('[data-ohw-role="logo"], [data-ohw-logo]');
@@ -12898,7 +12949,8 @@ function OhhwellsBridge() {
12898
12949
  e.stopPropagation();
12899
12950
  deselectRef.current();
12900
12951
  deactivateRef.current();
12901
- postToParentRef.current({ type: "ow:open-logo-settings" });
12952
+ const identity = readLogoIdentityFromDom();
12953
+ postToParentRef.current({ type: "ow:open-logo-settings", ...identity });
12902
12954
  return;
12903
12955
  }
12904
12956
  const editable = target.closest("[data-ohw-editable]");
@@ -13939,6 +13991,7 @@ function OhhwellsBridge() {
13939
13991
  sectionsJson = val;
13940
13992
  continue;
13941
13993
  }
13994
+ if (key === LOGO_PLACEHOLDER_KEY) continue;
13942
13995
  if (applyVideoSettingNode(key, val)) continue;
13943
13996
  if (applyCarouselNode(key, val)) continue;
13944
13997
  document.querySelectorAll(`[data-ohw-key="${key}"]`).forEach((el) => {
@@ -13958,6 +14011,12 @@ function OhhwellsBridge() {
13958
14011
  });
13959
14012
  applyLinkByKey(key, val);
13960
14013
  }
14014
+ const hasLogoIdentity = LOGO_PLACEHOLDER_KEY in content || LOGO_TEXT_KEYS.some((key) => key in content);
14015
+ if (hasLogoIdentity) {
14016
+ const logoText = content[LOGO_TEXT_KEYS[0]] ?? content[LOGO_TEXT_KEYS[1]] ?? readLogoIdentityFromDom().text;
14017
+ const logoIsPlaceholder = LOGO_PLACEHOLDER_KEY in content ? content[LOGO_PLACEHOLDER_KEY] !== "false" : !logoText.trim() || logoText === PLACEHOLDER_BUSINESS_NAME;
14018
+ applyLogoIdentity(logoText, logoIsPlaceholder);
14019
+ }
13961
14020
  if (sectionsJson) {
13962
14021
  initSectionsFromContent({ __ohw_sections: sectionsJson }, true);
13963
14022
  sectionsLoadedRef.current = true;
@@ -13970,6 +14029,21 @@ function OhhwellsBridge() {
13970
14029
  enforceLinkHrefs();
13971
14030
  postToParentRef.current({ type: "ow:hydrate-done" });
13972
14031
  };
14032
+ const handleUpdateLogoIdentity = (e) => {
14033
+ if (e.data?.type !== "ow:update-logo-identity") return;
14034
+ const rawText = typeof e.data.text === "string" ? e.data.text : "";
14035
+ const isPlaceholder = e.data.isPlaceholder !== false;
14036
+ const display = applyLogoIdentity(rawText, isPlaceholder);
14037
+ const nodes = [
14038
+ ...LOGO_TEXT_KEYS.map((key) => ({ key, text: display })),
14039
+ { key: LOGO_PLACEHOLDER_KEY, text: isPlaceholder || !rawText.trim() ? "true" : "false" }
14040
+ ];
14041
+ editContentRef.current = {
14042
+ ...editContentRef.current,
14043
+ ...Object.fromEntries(nodes.map(({ key, text }) => [key, text]))
14044
+ };
14045
+ postToParentRef.current({ type: "ow:change", nodes });
14046
+ };
13973
14047
  window.addEventListener("message", handleHydrate);
13974
14048
  const handleDeactivate = (e) => {
13975
14049
  if (e.data?.type !== "ow:deactivate") return;
@@ -14435,7 +14509,8 @@ function OhhwellsBridge() {
14435
14509
  if (logoAtPoint) {
14436
14510
  deselectRef.current();
14437
14511
  deactivateRef.current();
14438
- postToParentRef.current({ type: "ow:open-logo-settings" });
14512
+ const identity = readLogoIdentityFromDom();
14513
+ postToParentRef.current({ type: "ow:open-logo-settings", ...identity });
14439
14514
  return;
14440
14515
  }
14441
14516
  const textEditable = Array.from(
@@ -14506,6 +14581,7 @@ function OhhwellsBridge() {
14506
14581
  window.addEventListener("message", handleParentScroll);
14507
14582
  window.addEventListener("message", handlePointerSync);
14508
14583
  window.addEventListener("message", handleClickAt);
14584
+ window.addEventListener("message", handleUpdateLogoIdentity);
14509
14585
  const handleViewportResize = () => {
14510
14586
  if (visibleViewportRef.current) {
14511
14587
  applyVisibleViewport(visibleViewportRef.current, parentScrollRef.current);
@@ -14558,6 +14634,7 @@ function OhhwellsBridge() {
14558
14634
  window.removeEventListener("resize", handleViewportResize);
14559
14635
  window.removeEventListener("message", handlePointerSync);
14560
14636
  window.removeEventListener("message", handleClickAt);
14637
+ window.removeEventListener("message", handleUpdateLogoIdentity);
14561
14638
  window.removeEventListener("message", handleHydrate);
14562
14639
  window.removeEventListener("message", handleDeactivate);
14563
14640
  window.removeEventListener("message", handleToastAction);