@ohhwells/bridge 0.1.56 → 0.1.57

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.js CHANGED
@@ -6952,6 +6952,47 @@ function AiSectionOverlay({
6952
6952
  ] });
6953
6953
  }
6954
6954
 
6955
+ // src/lib/section-instances.ts
6956
+ var SECTION_ORDER_KEY = "__ohw_section_order";
6957
+ function getPageSectionOrderEntries(raw, currentPath) {
6958
+ if (!raw) return [];
6959
+ try {
6960
+ const entries = JSON.parse(raw);
6961
+ return entries.filter((e) => !e.pagePath || e.pagePath === currentPath);
6962
+ } catch {
6963
+ return [];
6964
+ }
6965
+ }
6966
+ function rekeySectionSubtree(root, instanceId) {
6967
+ const suffix = `::${instanceId}`;
6968
+ const rekey = (el, attr) => {
6969
+ const current = el.getAttribute(attr);
6970
+ if (current) el.setAttribute(attr, `${current}${suffix}`);
6971
+ };
6972
+ if (root.hasAttribute("data-ohw-key")) rekey(root, "data-ohw-key");
6973
+ if (root.hasAttribute("data-ohw-href-key")) rekey(root, "data-ohw-href-key");
6974
+ root.querySelectorAll("[data-ohw-key]").forEach((el) => rekey(el, "data-ohw-key"));
6975
+ root.querySelectorAll("[data-ohw-href-key]").forEach((el) => rekey(el, "data-ohw-href-key"));
6976
+ }
6977
+ function initSectionInstancesFromContent(content, currentPath) {
6978
+ document.querySelectorAll("[data-ohw-section]:not([data-ohw-instance])").forEach((el) => {
6979
+ el.setAttribute("data-ohw-instance", el.getAttribute("data-ohw-section") ?? "");
6980
+ });
6981
+ const entries = getPageSectionOrderEntries(content[SECTION_ORDER_KEY], currentPath);
6982
+ for (const entry of entries) {
6983
+ if (entry.instanceId === entry.type) continue;
6984
+ if (document.querySelector(`[data-ohw-instance="${CSS.escape(entry.instanceId)}"]`)) continue;
6985
+ const original = document.querySelector(
6986
+ `[data-ohw-section="${CSS.escape(entry.type)}"][data-ohw-instance="${CSS.escape(entry.type)}"]`
6987
+ );
6988
+ if (!original) continue;
6989
+ const clone = original.cloneNode(true);
6990
+ clone.setAttribute("data-ohw-instance", entry.instanceId);
6991
+ rekeySectionSubtree(clone, entry.instanceId);
6992
+ original.insertAdjacentElement("afterend", clone);
6993
+ }
6994
+ }
6995
+
6955
6996
  // src/OhhwellsBridge.tsx
6956
6997
  import { createPortal as createPortal2 } from "react-dom";
6957
6998
  import { usePathname as usePathname2, useRouter as useRouter3, useSearchParams } from "next/navigation";
@@ -6984,9 +7025,16 @@ function isPointOverBridgeChrome(x, y) {
6984
7025
  }
6985
7026
  return false;
6986
7027
  }
6987
- function findCtaButtonAtPoint(x, y, media) {
7028
+ var BUTTON_LIKE_SELECTOR = `button, [role="button"], ${CTA_BUTTON_SELECTOR}`;
7029
+ function isButtonLikeElement(el) {
7030
+ return el.matches(BUTTON_LIKE_SELECTOR);
7031
+ }
7032
+ function findClosestButtonLike(target) {
7033
+ return target.closest(BUTTON_LIKE_SELECTOR);
7034
+ }
7035
+ function findButtonAtPoint(x, y, media) {
6988
7036
  const hits = Array.from(
6989
- document.querySelectorAll(CTA_BUTTON_SELECTOR)
7037
+ document.querySelectorAll(BUTTON_LIKE_SELECTOR)
6990
7038
  ).filter((el) => containsPoint(el, x, y) && !(media && el.contains(media)));
6991
7039
  if (hits.length === 0) return null;
6992
7040
  return hits.reduce((best, el) => best.contains(el) ? el : best);
@@ -14672,6 +14720,7 @@ function OhhwellsBridge() {
14672
14720
  applySocialsDisplayFromContent(content);
14673
14721
  enforceLinkHrefs();
14674
14722
  initSectionsFromContent(content, true);
14723
+ initSectionInstancesFromContent(content, window.location.pathname);
14675
14724
  sectionsLoadedRef.current = true;
14676
14725
  pendingScheduleConfigRequests.current.splice(0).forEach(processConfigRequest);
14677
14726
  return imageLoads.length > 0 ? Promise.all(imageLoads).then(() => {
@@ -14706,6 +14755,7 @@ function OhhwellsBridge() {
14706
14755
  const content = contentCache.get(subdomain);
14707
14756
  if (!content) return;
14708
14757
  retryMissingSchedulingMounts(getPageSchedulingEntries(content["__ohw_sections"]), false);
14758
+ initSectionInstancesFromContent(content, window.location.pathname);
14709
14759
  observer?.disconnect();
14710
14760
  try {
14711
14761
  for (const [key, val] of Object.entries(content)) {
@@ -15094,14 +15144,17 @@ function OhhwellsBridge() {
15094
15144
  });
15095
15145
  return;
15096
15146
  }
15097
- if (isMediaEditable(editable)) {
15147
+ const clickedButton = findClosestButtonLike(target);
15148
+ const buttonOnMedia = Boolean(clickedButton && isMediaEditable(editable) && editable.contains(clickedButton));
15149
+ if (isMediaEditable(editable) && !buttonOnMedia) {
15098
15150
  e.preventDefault();
15099
15151
  e.stopPropagation();
15100
15152
  aiSectionApiRef.current?.selectFromElement(editable);
15101
15153
  postToParentRef.current({ type: "ow:image-pick", key: editable.dataset.ohwKey ?? "", elementType: editable.dataset.ohwEditable ?? "image" });
15102
15154
  return;
15103
15155
  }
15104
- const hrefCtx = getHrefKeyFromElement(editable);
15156
+ const hrefLookupTarget = buttonOnMedia ? clickedButton : editable;
15157
+ const hrefCtx = getHrefKeyFromElement(hrefLookupTarget);
15105
15158
  const navAnchor = hrefCtx ? getNavigationItemAnchor(hrefCtx.anchor) : null;
15106
15159
  if (navAnchor) {
15107
15160
  e.preventDefault();
@@ -15109,7 +15162,8 @@ function OhhwellsBridge() {
15109
15162
  if (selectedElRef.current === navAnchor) {
15110
15163
  if (e.detail >= 2) return;
15111
15164
  if (requestSocialDialog(navAnchor, postToParentRef.current, editContentRef.current)) return;
15112
- activateRef.current(editable, { caretX: e.clientX, caretY: e.clientY });
15165
+ const activateTarget = isButtonLikeElement(hrefLookupTarget) ? navAnchor.querySelector('[data-ohw-editable="text"]') ?? hrefLookupTarget : hrefLookupTarget;
15166
+ activateRef.current(activateTarget, { caretX: e.clientX, caretY: e.clientY });
15113
15167
  return;
15114
15168
  }
15115
15169
  selectRef.current(navAnchor);
@@ -15117,7 +15171,7 @@ function OhhwellsBridge() {
15117
15171
  }
15118
15172
  e.preventDefault();
15119
15173
  e.stopPropagation();
15120
- activateRef.current(editable, { caretX: e.clientX, caretY: e.clientY });
15174
+ activateRef.current(hrefLookupTarget, { caretX: e.clientX, caretY: e.clientY });
15121
15175
  return;
15122
15176
  }
15123
15177
  const hrefAnchor = getNavigationItemAnchor(target);
@@ -15647,15 +15701,15 @@ function OhhwellsBridge() {
15647
15701
  dismissImageHover();
15648
15702
  return;
15649
15703
  }
15650
- const ctaHit = isDragOver ? null : findCtaButtonAtPoint(x2, y2, imgEl);
15651
- if (ctaHit) {
15704
+ const buttonHit = isDragOver ? null : findButtonAtPoint(x2, y2, imgEl);
15705
+ if (buttonHit) {
15652
15706
  dismissImageHover();
15653
15707
  document.querySelectorAll("[data-ohw-hovered]").forEach((el) => el.removeAttribute("data-ohw-hovered"));
15654
15708
  const selected = selectedElRef.current;
15655
- if (selected !== ctaHit && !selected?.contains(ctaHit)) {
15656
- clearHrefKeyHover(ctaHit);
15657
- hoveredItemElRef.current = ctaHit;
15658
- setHoveredItemRect(ctaHit.getBoundingClientRect());
15709
+ if (selected !== buttonHit && !selected?.contains(buttonHit)) {
15710
+ clearHrefKeyHover(buttonHit);
15711
+ hoveredItemElRef.current = buttonHit;
15712
+ setHoveredItemRect(buttonHit.getBoundingClientRect());
15659
15713
  }
15660
15714
  return;
15661
15715
  }
@@ -16185,6 +16239,7 @@ function OhhwellsBridge() {
16185
16239
  sectionsLoadedRef.current = true;
16186
16240
  pendingScheduleConfigRequests.current.splice(0).forEach(processConfigRequest);
16187
16241
  }
16242
+ initSectionInstancesFromContent(content, window.location.pathname);
16188
16243
  editContentRef.current = { ...editContentRef.current, ...content };
16189
16244
  reconcileNavbarItemsFromContent(editContentRef.current);
16190
16245
  reconcileFooterOrderFromContent(editContentRef.current);
@@ -17040,7 +17095,7 @@ function OhhwellsBridge() {
17040
17095
  postToParent2({
17041
17096
  type: "ow:ready",
17042
17097
  version: "1",
17043
- bridgeVersion: "0.1.55",
17098
+ bridgeVersion: "0.1.56",
17044
17099
  path: pathname,
17045
17100
  nodes: collectEditableNodes(editContentRef.current),
17046
17101
  sections