@ohhwells/bridge 0.1.55-next.163 → 0.1.55-next.165

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
@@ -7192,6 +7192,47 @@ function AiSectionOverlay({
7192
7192
  ] });
7193
7193
  }
7194
7194
 
7195
+ // src/lib/section-instances.ts
7196
+ var SECTION_ORDER_KEY = "__ohw_section_order";
7197
+ function getPageSectionOrderEntries(raw, currentPath) {
7198
+ if (!raw) return [];
7199
+ try {
7200
+ const entries = JSON.parse(raw);
7201
+ return entries.filter((e) => !e.pagePath || e.pagePath === currentPath);
7202
+ } catch {
7203
+ return [];
7204
+ }
7205
+ }
7206
+ function rekeySectionSubtree(root, instanceId) {
7207
+ const suffix = `::${instanceId}`;
7208
+ const rekey = (el, attr) => {
7209
+ const current = el.getAttribute(attr);
7210
+ if (current) el.setAttribute(attr, `${current}${suffix}`);
7211
+ };
7212
+ if (root.hasAttribute("data-ohw-key")) rekey(root, "data-ohw-key");
7213
+ if (root.hasAttribute("data-ohw-href-key")) rekey(root, "data-ohw-href-key");
7214
+ root.querySelectorAll("[data-ohw-key]").forEach((el) => rekey(el, "data-ohw-key"));
7215
+ root.querySelectorAll("[data-ohw-href-key]").forEach((el) => rekey(el, "data-ohw-href-key"));
7216
+ }
7217
+ function initSectionInstancesFromContent(content, currentPath) {
7218
+ document.querySelectorAll("[data-ohw-section]:not([data-ohw-instance])").forEach((el) => {
7219
+ el.setAttribute("data-ohw-instance", el.getAttribute("data-ohw-section") ?? "");
7220
+ });
7221
+ const entries = getPageSectionOrderEntries(content[SECTION_ORDER_KEY], currentPath);
7222
+ for (const entry of entries) {
7223
+ if (entry.instanceId === entry.type) continue;
7224
+ if (document.querySelector(`[data-ohw-instance="${CSS.escape(entry.instanceId)}"]`)) continue;
7225
+ const original = document.querySelector(
7226
+ `[data-ohw-section="${CSS.escape(entry.type)}"][data-ohw-instance="${CSS.escape(entry.type)}"]`
7227
+ );
7228
+ if (!original) continue;
7229
+ const clone = original.cloneNode(true);
7230
+ clone.setAttribute("data-ohw-instance", entry.instanceId);
7231
+ rekeySectionSubtree(clone, entry.instanceId);
7232
+ original.insertAdjacentElement("afterend", clone);
7233
+ }
7234
+ }
7235
+
7195
7236
  // src/OhhwellsBridge.tsx
7196
7237
  var import_react_dom4 = require("react-dom");
7197
7238
  var import_navigation3 = require("next/navigation");
@@ -7224,9 +7265,16 @@ function isPointOverBridgeChrome(x, y) {
7224
7265
  }
7225
7266
  return false;
7226
7267
  }
7227
- function findCtaButtonAtPoint(x, y, media) {
7268
+ var BUTTON_LIKE_SELECTOR = `button, [role="button"], ${CTA_BUTTON_SELECTOR}`;
7269
+ function isButtonLikeElement(el) {
7270
+ return el.matches(BUTTON_LIKE_SELECTOR);
7271
+ }
7272
+ function findClosestButtonLike(target) {
7273
+ return target.closest(BUTTON_LIKE_SELECTOR);
7274
+ }
7275
+ function findButtonAtPoint(x, y, media) {
7228
7276
  const hits = Array.from(
7229
- document.querySelectorAll(CTA_BUTTON_SELECTOR)
7277
+ document.querySelectorAll(BUTTON_LIKE_SELECTOR)
7230
7278
  ).filter((el) => containsPoint(el, x, y) && !(media && el.contains(media)));
7231
7279
  if (hits.length === 0) return null;
7232
7280
  return hits.reduce((best, el) => best.contains(el) ? el : best);
@@ -15577,6 +15625,7 @@ function OhhwellsBridge() {
15577
15625
  applySocialsDisplayFromContent(content);
15578
15626
  enforceLinkHrefs();
15579
15627
  initSectionsFromContent(content, true);
15628
+ initSectionInstancesFromContent(content, window.location.pathname);
15580
15629
  sectionsLoadedRef.current = true;
15581
15630
  pendingScheduleConfigRequests.current.splice(0).forEach(processConfigRequest);
15582
15631
  return imageLoads.length > 0 ? Promise.all(imageLoads).then(() => {
@@ -15613,6 +15662,7 @@ function OhhwellsBridge() {
15613
15662
  const content = contentCache.get(subdomain);
15614
15663
  if (!content) return;
15615
15664
  retryMissingSchedulingMounts(getPageSchedulingEntries(content["__ohw_sections"]), false);
15665
+ initSectionInstancesFromContent(content, window.location.pathname);
15616
15666
  observer?.disconnect();
15617
15667
  try {
15618
15668
  applyBrandChrome(content);
@@ -16049,14 +16099,17 @@ function OhhwellsBridge() {
16049
16099
  });
16050
16100
  return;
16051
16101
  }
16052
- if (isMediaEditable(editable)) {
16102
+ const clickedButton = findClosestButtonLike(target);
16103
+ const buttonOnMedia = Boolean(clickedButton && isMediaEditable(editable) && editable.contains(clickedButton));
16104
+ if (isMediaEditable(editable) && !buttonOnMedia) {
16053
16105
  e.preventDefault();
16054
16106
  e.stopPropagation();
16055
16107
  aiSectionApiRef.current?.selectFromElement(editable);
16056
16108
  postToParentRef.current({ type: "ow:image-pick", key: editable.dataset.ohwKey ?? "", elementType: editable.dataset.ohwEditable ?? "image" });
16057
16109
  return;
16058
16110
  }
16059
- const hrefCtx = getHrefKeyFromElement(editable);
16111
+ const hrefLookupTarget = buttonOnMedia ? clickedButton : editable;
16112
+ const hrefCtx = getHrefKeyFromElement(hrefLookupTarget);
16060
16113
  const navAnchor = hrefCtx ? getNavigationItemAnchor(hrefCtx.anchor) : null;
16061
16114
  if (navAnchor) {
16062
16115
  e.preventDefault();
@@ -16064,7 +16117,8 @@ function OhhwellsBridge() {
16064
16117
  if (selectedElRef.current === navAnchor) {
16065
16118
  if (e.detail >= 2) return;
16066
16119
  if (requestSocialDialog(navAnchor, postToParentRef.current, editContentRef.current)) return;
16067
- activateRef.current(editable, { caretX: e.clientX, caretY: e.clientY });
16120
+ const activateTarget = isButtonLikeElement(hrefLookupTarget) ? navAnchor.querySelector('[data-ohw-editable="text"]') ?? hrefLookupTarget : hrefLookupTarget;
16121
+ activateRef.current(activateTarget, { caretX: e.clientX, caretY: e.clientY });
16068
16122
  return;
16069
16123
  }
16070
16124
  selectRef.current(navAnchor);
@@ -16072,7 +16126,7 @@ function OhhwellsBridge() {
16072
16126
  }
16073
16127
  e.preventDefault();
16074
16128
  e.stopPropagation();
16075
- activateRef.current(editable, { caretX: e.clientX, caretY: e.clientY });
16129
+ activateRef.current(hrefLookupTarget, { caretX: e.clientX, caretY: e.clientY });
16076
16130
  return;
16077
16131
  }
16078
16132
  const hrefAnchor = getNavigationItemAnchor(target);
@@ -16667,15 +16721,15 @@ function OhhwellsBridge() {
16667
16721
  dismissImageHover();
16668
16722
  return;
16669
16723
  }
16670
- const ctaHit = isDragOver ? null : findCtaButtonAtPoint(x2, y2, imgEl);
16671
- if (ctaHit) {
16724
+ const buttonHit = isDragOver ? null : findButtonAtPoint(x2, y2, imgEl);
16725
+ if (buttonHit) {
16672
16726
  dismissImageHover();
16673
16727
  document.querySelectorAll("[data-ohw-hovered]").forEach((el) => el.removeAttribute("data-ohw-hovered"));
16674
16728
  const selected = selectedElRef.current;
16675
- if (selected !== ctaHit && !selected?.contains(ctaHit)) {
16676
- clearHrefKeyHover(ctaHit);
16677
- hoveredItemElRef.current = ctaHit;
16678
- setHoveredItemRect(ctaHit.getBoundingClientRect());
16729
+ if (selected !== buttonHit && !selected?.contains(buttonHit)) {
16730
+ clearHrefKeyHover(buttonHit);
16731
+ hoveredItemElRef.current = buttonHit;
16732
+ setHoveredItemRect(buttonHit.getBoundingClientRect());
16679
16733
  }
16680
16734
  return;
16681
16735
  }
@@ -17234,6 +17288,7 @@ function OhhwellsBridge() {
17234
17288
  sectionsLoadedRef.current = true;
17235
17289
  pendingScheduleConfigRequests.current.splice(0).forEach(processConfigRequest);
17236
17290
  }
17291
+ initSectionInstancesFromContent(content, window.location.pathname);
17237
17292
  editContentRef.current = { ...editContentRef.current, ...content };
17238
17293
  reconcileNavbarItemsFromContent(editContentRef.current);
17239
17294
  reconcileFooterOrderFromContent(editContentRef.current);