@ohhwells/bridge 0.1.31 → 0.1.32
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/README.md +21 -0
- package/dist/index.cjs +169 -125
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +51 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,49 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
// src/OhhwellsBridge.tsx
|
|
4
|
-
import React6, { useCallback as useCallback2, useEffect as useEffect3, useLayoutEffect, useRef as useRef3, useState as useState5 } from "react";
|
|
4
|
+
import React6, { useCallback as useCallback2, useEffect as useEffect3, useLayoutEffect as useLayoutEffect2, useRef as useRef3, useState as useState5 } from "react";
|
|
5
5
|
import { createRoot } from "react-dom/client";
|
|
6
6
|
import { flushSync } from "react-dom";
|
|
7
7
|
|
|
8
|
+
// src/linkHrefStore.ts
|
|
9
|
+
var linkHrefStore = /* @__PURE__ */ new Map();
|
|
10
|
+
function setStoredLinkHref(key, href) {
|
|
11
|
+
linkHrefStore.set(key, href);
|
|
12
|
+
}
|
|
13
|
+
function enforceLinkHrefs() {
|
|
14
|
+
document.querySelectorAll("[data-ohw-href-key]").forEach((el) => {
|
|
15
|
+
const key = el.getAttribute("data-ohw-href-key") ?? "";
|
|
16
|
+
if (!key) return;
|
|
17
|
+
const saved = linkHrefStore.get(key);
|
|
18
|
+
if (saved === void 0) return;
|
|
19
|
+
if (el.getAttribute("href") !== saved) el.setAttribute("href", saved);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/useLinkHrefGuardian.ts
|
|
24
|
+
import { useLayoutEffect } from "react";
|
|
25
|
+
function useLinkHrefGuardian(...deps) {
|
|
26
|
+
useLayoutEffect(() => {
|
|
27
|
+
let debounceTimer = null;
|
|
28
|
+
const scheduleEnforce = () => {
|
|
29
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
30
|
+
debounceTimer = setTimeout(enforceLinkHrefs, 50);
|
|
31
|
+
};
|
|
32
|
+
enforceLinkHrefs();
|
|
33
|
+
const observer = new MutationObserver(scheduleEnforce);
|
|
34
|
+
observer.observe(document.body, {
|
|
35
|
+
childList: true,
|
|
36
|
+
subtree: true,
|
|
37
|
+
attributes: true,
|
|
38
|
+
attributeFilter: ["href"]
|
|
39
|
+
});
|
|
40
|
+
return () => {
|
|
41
|
+
observer.disconnect();
|
|
42
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
43
|
+
};
|
|
44
|
+
}, deps);
|
|
45
|
+
}
|
|
46
|
+
|
|
8
47
|
// src/ui/SchedulingWidget.tsx
|
|
9
48
|
import { useEffect, useId, useMemo, useRef, useState as useState2 } from "react";
|
|
10
49
|
|
|
@@ -5454,10 +5493,11 @@ function applyLinkByKey(key, val) {
|
|
|
5454
5493
|
document.querySelectorAll(`[data-ohw-key="${key}"]`).forEach((el) => {
|
|
5455
5494
|
if (el.dataset.ohwEditable === "link") applyLinkHref(el, val);
|
|
5456
5495
|
});
|
|
5457
|
-
document.querySelectorAll(`[data-ohw-href-key="${key}"]`)
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
|
|
5496
|
+
const hrefAnchors = document.querySelectorAll(`[data-ohw-href-key="${key}"]`);
|
|
5497
|
+
if (hrefAnchors.length > 0) {
|
|
5498
|
+
setStoredLinkHref(key, val);
|
|
5499
|
+
hrefAnchors.forEach((el) => applyLinkHref(el, val));
|
|
5500
|
+
}
|
|
5461
5501
|
}
|
|
5462
5502
|
function isInsideLinkEditor(target) {
|
|
5463
5503
|
return Boolean(
|
|
@@ -6016,6 +6056,7 @@ function OhhwellsBridge() {
|
|
|
6016
6056
|
}, []);
|
|
6017
6057
|
const subdomainFromQuery = searchParams.get("subdomain");
|
|
6018
6058
|
const subdomain = resolveSubdomain(subdomainFromQuery);
|
|
6059
|
+
useLinkHrefGuardian(pathname, subdomain, isEditMode);
|
|
6019
6060
|
const postToParent = useCallback2((data) => {
|
|
6020
6061
|
if (typeof window !== "undefined" && window.parent !== window) {
|
|
6021
6062
|
window.parent.postMessage(data, "*");
|
|
@@ -6283,7 +6324,7 @@ function OhhwellsBridge() {
|
|
|
6283
6324
|
deactivateRef.current = deactivate;
|
|
6284
6325
|
selectRef.current = select;
|
|
6285
6326
|
deselectRef.current = deselect;
|
|
6286
|
-
|
|
6327
|
+
useLayoutEffect2(() => {
|
|
6287
6328
|
if (!subdomain || isEditMode) {
|
|
6288
6329
|
setFetchState("done");
|
|
6289
6330
|
return;
|
|
@@ -6313,6 +6354,7 @@ function OhhwellsBridge() {
|
|
|
6313
6354
|
});
|
|
6314
6355
|
applyLinkByKey(key, val);
|
|
6315
6356
|
}
|
|
6357
|
+
enforceLinkHrefs();
|
|
6316
6358
|
initSectionsFromContent(content, true);
|
|
6317
6359
|
sectionsLoadedRef.current = true;
|
|
6318
6360
|
pendingScheduleConfigRequests.current.splice(0).forEach(processConfigRequest);
|
|
@@ -6364,6 +6406,7 @@ function OhhwellsBridge() {
|
|
|
6364
6406
|
});
|
|
6365
6407
|
applyLinkByKey(key, val);
|
|
6366
6408
|
}
|
|
6409
|
+
enforceLinkHrefs();
|
|
6367
6410
|
};
|
|
6368
6411
|
const scheduleApply = () => {
|
|
6369
6412
|
if (debounceTimer) clearTimeout(debounceTimer);
|
|
@@ -6377,7 +6420,7 @@ function OhhwellsBridge() {
|
|
|
6377
6420
|
if (debounceTimer) clearTimeout(debounceTimer);
|
|
6378
6421
|
};
|
|
6379
6422
|
}, [subdomain, isEditMode, pathname]);
|
|
6380
|
-
|
|
6423
|
+
useLayoutEffect2(() => {
|
|
6381
6424
|
const el = document.getElementById("ohw-loader");
|
|
6382
6425
|
if (!el) return;
|
|
6383
6426
|
const visible = Boolean(subdomain) && fetchState !== "done";
|
|
@@ -7055,6 +7098,7 @@ function OhhwellsBridge() {
|
|
|
7055
7098
|
sectionsLoadedRef.current = true;
|
|
7056
7099
|
pendingScheduleConfigRequests.current.splice(0).forEach(processConfigRequest);
|
|
7057
7100
|
}
|
|
7101
|
+
enforceLinkHrefs();
|
|
7058
7102
|
postToParentRef.current({ type: "ow:hydrate-done" });
|
|
7059
7103
|
};
|
|
7060
7104
|
window.addEventListener("message", handleHydrate);
|