@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.cjs +68 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +68 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7025,6 +7025,47 @@ function AiSectionOverlay({
|
|
|
7025
7025
|
] });
|
|
7026
7026
|
}
|
|
7027
7027
|
|
|
7028
|
+
// src/lib/section-instances.ts
|
|
7029
|
+
var SECTION_ORDER_KEY = "__ohw_section_order";
|
|
7030
|
+
function getPageSectionOrderEntries(raw, currentPath) {
|
|
7031
|
+
if (!raw) return [];
|
|
7032
|
+
try {
|
|
7033
|
+
const entries = JSON.parse(raw);
|
|
7034
|
+
return entries.filter((e) => !e.pagePath || e.pagePath === currentPath);
|
|
7035
|
+
} catch {
|
|
7036
|
+
return [];
|
|
7037
|
+
}
|
|
7038
|
+
}
|
|
7039
|
+
function rekeySectionSubtree(root, instanceId) {
|
|
7040
|
+
const suffix = `::${instanceId}`;
|
|
7041
|
+
const rekey = (el, attr) => {
|
|
7042
|
+
const current = el.getAttribute(attr);
|
|
7043
|
+
if (current) el.setAttribute(attr, `${current}${suffix}`);
|
|
7044
|
+
};
|
|
7045
|
+
if (root.hasAttribute("data-ohw-key")) rekey(root, "data-ohw-key");
|
|
7046
|
+
if (root.hasAttribute("data-ohw-href-key")) rekey(root, "data-ohw-href-key");
|
|
7047
|
+
root.querySelectorAll("[data-ohw-key]").forEach((el) => rekey(el, "data-ohw-key"));
|
|
7048
|
+
root.querySelectorAll("[data-ohw-href-key]").forEach((el) => rekey(el, "data-ohw-href-key"));
|
|
7049
|
+
}
|
|
7050
|
+
function initSectionInstancesFromContent(content, currentPath) {
|
|
7051
|
+
document.querySelectorAll("[data-ohw-section]:not([data-ohw-instance])").forEach((el) => {
|
|
7052
|
+
el.setAttribute("data-ohw-instance", el.getAttribute("data-ohw-section") ?? "");
|
|
7053
|
+
});
|
|
7054
|
+
const entries = getPageSectionOrderEntries(content[SECTION_ORDER_KEY], currentPath);
|
|
7055
|
+
for (const entry of entries) {
|
|
7056
|
+
if (entry.instanceId === entry.type) continue;
|
|
7057
|
+
if (document.querySelector(`[data-ohw-instance="${CSS.escape(entry.instanceId)}"]`)) continue;
|
|
7058
|
+
const original = document.querySelector(
|
|
7059
|
+
`[data-ohw-section="${CSS.escape(entry.type)}"][data-ohw-instance="${CSS.escape(entry.type)}"]`
|
|
7060
|
+
);
|
|
7061
|
+
if (!original) continue;
|
|
7062
|
+
const clone = original.cloneNode(true);
|
|
7063
|
+
clone.setAttribute("data-ohw-instance", entry.instanceId);
|
|
7064
|
+
rekeySectionSubtree(clone, entry.instanceId);
|
|
7065
|
+
original.insertAdjacentElement("afterend", clone);
|
|
7066
|
+
}
|
|
7067
|
+
}
|
|
7068
|
+
|
|
7028
7069
|
// src/OhhwellsBridge.tsx
|
|
7029
7070
|
var import_react_dom4 = require("react-dom");
|
|
7030
7071
|
var import_navigation3 = require("next/navigation");
|
|
@@ -7057,9 +7098,16 @@ function isPointOverBridgeChrome(x, y) {
|
|
|
7057
7098
|
}
|
|
7058
7099
|
return false;
|
|
7059
7100
|
}
|
|
7060
|
-
|
|
7101
|
+
var BUTTON_LIKE_SELECTOR = `button, [role="button"], ${CTA_BUTTON_SELECTOR}`;
|
|
7102
|
+
function isButtonLikeElement(el) {
|
|
7103
|
+
return el.matches(BUTTON_LIKE_SELECTOR);
|
|
7104
|
+
}
|
|
7105
|
+
function findClosestButtonLike(target) {
|
|
7106
|
+
return target.closest(BUTTON_LIKE_SELECTOR);
|
|
7107
|
+
}
|
|
7108
|
+
function findButtonAtPoint(x, y, media) {
|
|
7061
7109
|
const hits = Array.from(
|
|
7062
|
-
document.querySelectorAll(
|
|
7110
|
+
document.querySelectorAll(BUTTON_LIKE_SELECTOR)
|
|
7063
7111
|
).filter((el) => containsPoint(el, x, y) && !(media && el.contains(media)));
|
|
7064
7112
|
if (hits.length === 0) return null;
|
|
7065
7113
|
return hits.reduce((best, el) => best.contains(el) ? el : best);
|
|
@@ -14739,6 +14787,7 @@ function OhhwellsBridge() {
|
|
|
14739
14787
|
applySocialsDisplayFromContent(content);
|
|
14740
14788
|
enforceLinkHrefs();
|
|
14741
14789
|
initSectionsFromContent(content, true);
|
|
14790
|
+
initSectionInstancesFromContent(content, window.location.pathname);
|
|
14742
14791
|
sectionsLoadedRef.current = true;
|
|
14743
14792
|
pendingScheduleConfigRequests.current.splice(0).forEach(processConfigRequest);
|
|
14744
14793
|
return imageLoads.length > 0 ? Promise.all(imageLoads).then(() => {
|
|
@@ -14773,6 +14822,7 @@ function OhhwellsBridge() {
|
|
|
14773
14822
|
const content = contentCache.get(subdomain);
|
|
14774
14823
|
if (!content) return;
|
|
14775
14824
|
retryMissingSchedulingMounts(getPageSchedulingEntries(content["__ohw_sections"]), false);
|
|
14825
|
+
initSectionInstancesFromContent(content, window.location.pathname);
|
|
14776
14826
|
observer?.disconnect();
|
|
14777
14827
|
try {
|
|
14778
14828
|
for (const [key, val] of Object.entries(content)) {
|
|
@@ -15161,14 +15211,17 @@ function OhhwellsBridge() {
|
|
|
15161
15211
|
});
|
|
15162
15212
|
return;
|
|
15163
15213
|
}
|
|
15164
|
-
|
|
15214
|
+
const clickedButton = findClosestButtonLike(target);
|
|
15215
|
+
const buttonOnMedia = Boolean(clickedButton && isMediaEditable(editable) && editable.contains(clickedButton));
|
|
15216
|
+
if (isMediaEditable(editable) && !buttonOnMedia) {
|
|
15165
15217
|
e.preventDefault();
|
|
15166
15218
|
e.stopPropagation();
|
|
15167
15219
|
aiSectionApiRef.current?.selectFromElement(editable);
|
|
15168
15220
|
postToParentRef.current({ type: "ow:image-pick", key: editable.dataset.ohwKey ?? "", elementType: editable.dataset.ohwEditable ?? "image" });
|
|
15169
15221
|
return;
|
|
15170
15222
|
}
|
|
15171
|
-
const
|
|
15223
|
+
const hrefLookupTarget = buttonOnMedia ? clickedButton : editable;
|
|
15224
|
+
const hrefCtx = getHrefKeyFromElement(hrefLookupTarget);
|
|
15172
15225
|
const navAnchor = hrefCtx ? getNavigationItemAnchor(hrefCtx.anchor) : null;
|
|
15173
15226
|
if (navAnchor) {
|
|
15174
15227
|
e.preventDefault();
|
|
@@ -15176,7 +15229,8 @@ function OhhwellsBridge() {
|
|
|
15176
15229
|
if (selectedElRef.current === navAnchor) {
|
|
15177
15230
|
if (e.detail >= 2) return;
|
|
15178
15231
|
if (requestSocialDialog(navAnchor, postToParentRef.current, editContentRef.current)) return;
|
|
15179
|
-
|
|
15232
|
+
const activateTarget = isButtonLikeElement(hrefLookupTarget) ? navAnchor.querySelector('[data-ohw-editable="text"]') ?? hrefLookupTarget : hrefLookupTarget;
|
|
15233
|
+
activateRef.current(activateTarget, { caretX: e.clientX, caretY: e.clientY });
|
|
15180
15234
|
return;
|
|
15181
15235
|
}
|
|
15182
15236
|
selectRef.current(navAnchor);
|
|
@@ -15184,7 +15238,7 @@ function OhhwellsBridge() {
|
|
|
15184
15238
|
}
|
|
15185
15239
|
e.preventDefault();
|
|
15186
15240
|
e.stopPropagation();
|
|
15187
|
-
activateRef.current(
|
|
15241
|
+
activateRef.current(hrefLookupTarget, { caretX: e.clientX, caretY: e.clientY });
|
|
15188
15242
|
return;
|
|
15189
15243
|
}
|
|
15190
15244
|
const hrefAnchor = getNavigationItemAnchor(target);
|
|
@@ -15714,15 +15768,15 @@ function OhhwellsBridge() {
|
|
|
15714
15768
|
dismissImageHover();
|
|
15715
15769
|
return;
|
|
15716
15770
|
}
|
|
15717
|
-
const
|
|
15718
|
-
if (
|
|
15771
|
+
const buttonHit = isDragOver ? null : findButtonAtPoint(x2, y2, imgEl);
|
|
15772
|
+
if (buttonHit) {
|
|
15719
15773
|
dismissImageHover();
|
|
15720
15774
|
document.querySelectorAll("[data-ohw-hovered]").forEach((el) => el.removeAttribute("data-ohw-hovered"));
|
|
15721
15775
|
const selected = selectedElRef.current;
|
|
15722
|
-
if (selected !==
|
|
15723
|
-
clearHrefKeyHover(
|
|
15724
|
-
hoveredItemElRef.current =
|
|
15725
|
-
setHoveredItemRect(
|
|
15776
|
+
if (selected !== buttonHit && !selected?.contains(buttonHit)) {
|
|
15777
|
+
clearHrefKeyHover(buttonHit);
|
|
15778
|
+
hoveredItemElRef.current = buttonHit;
|
|
15779
|
+
setHoveredItemRect(buttonHit.getBoundingClientRect());
|
|
15726
15780
|
}
|
|
15727
15781
|
return;
|
|
15728
15782
|
}
|
|
@@ -16252,6 +16306,7 @@ function OhhwellsBridge() {
|
|
|
16252
16306
|
sectionsLoadedRef.current = true;
|
|
16253
16307
|
pendingScheduleConfigRequests.current.splice(0).forEach(processConfigRequest);
|
|
16254
16308
|
}
|
|
16309
|
+
initSectionInstancesFromContent(content, window.location.pathname);
|
|
16255
16310
|
editContentRef.current = { ...editContentRef.current, ...content };
|
|
16256
16311
|
reconcileNavbarItemsFromContent(editContentRef.current);
|
|
16257
16312
|
reconcileFooterOrderFromContent(editContentRef.current);
|
|
@@ -17107,7 +17162,7 @@ function OhhwellsBridge() {
|
|
|
17107
17162
|
postToParent2({
|
|
17108
17163
|
type: "ow:ready",
|
|
17109
17164
|
version: "1",
|
|
17110
|
-
bridgeVersion: "0.1.
|
|
17165
|
+
bridgeVersion: "0.1.56",
|
|
17111
17166
|
path: pathname,
|
|
17112
17167
|
nodes: collectEditableNodes(editContentRef.current),
|
|
17113
17168
|
sections
|