@superblocksteam/library 2.0.106 → 2.0.107-next.1
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/lib/index.js +57 -1
- package/dist/lib/index.js.map +1 -1
- package/package.json +4 -4
package/dist/lib/index.js
CHANGED
|
@@ -2034,7 +2034,7 @@ function buildParentUrl(href, appId, appMode) {
|
|
|
2034
2034
|
function linkModifierInterceptor({ isEmbedMode = false, appMode } = {}) {
|
|
2035
2035
|
if (typeof window === "undefined") return () => {};
|
|
2036
2036
|
if (window === window.parent) return () => {};
|
|
2037
|
-
const isEditorParent = appMode
|
|
2037
|
+
const isEditorParent = appMode === "EDIT";
|
|
2038
2038
|
let isInternalNavigation = false;
|
|
2039
2039
|
const handleClick = (ev) => {
|
|
2040
2040
|
if (ev.defaultPrevented) return;
|
|
@@ -2042,6 +2042,11 @@ function linkModifierInterceptor({ isEmbedMode = false, appMode } = {}) {
|
|
|
2042
2042
|
if (!(target instanceof Element)) return;
|
|
2043
2043
|
const anchor = target.closest?.("a[href]");
|
|
2044
2044
|
if (!(anchor instanceof HTMLAnchorElement)) return;
|
|
2045
|
+
const origHref = anchor.dataset.sbOriginalHref;
|
|
2046
|
+
if (origHref !== void 0) {
|
|
2047
|
+
anchor.setAttribute("href", origHref);
|
|
2048
|
+
delete anchor.dataset.sbOriginalHref;
|
|
2049
|
+
}
|
|
2045
2050
|
const href = anchor.getAttribute("href");
|
|
2046
2051
|
if (!href) return;
|
|
2047
2052
|
if (!isLocalPath(href)) return;
|
|
@@ -2111,11 +2116,62 @@ function linkModifierInterceptor({ isEmbedMode = false, appMode } = {}) {
|
|
|
2111
2116
|
};
|
|
2112
2117
|
const navigation = window.navigation;
|
|
2113
2118
|
navigation?.addEventListener("navigate", handleNavigate);
|
|
2119
|
+
let hoverCleanup;
|
|
2120
|
+
if (appMode && !isEmbedMode) {
|
|
2121
|
+
let parentOrigin = "";
|
|
2122
|
+
try {
|
|
2123
|
+
if (document.referrer) parentOrigin = new URL(document.referrer).origin;
|
|
2124
|
+
} catch {}
|
|
2125
|
+
if (parentOrigin) {
|
|
2126
|
+
const rewriteHref = (anchor) => {
|
|
2127
|
+
if (anchor.dataset.sbOriginalHref !== void 0) return;
|
|
2128
|
+
const href = anchor.getAttribute("href");
|
|
2129
|
+
if (!href || !isLocalPath(href)) return;
|
|
2130
|
+
const appId = root_store_default.applicationId;
|
|
2131
|
+
if (!appId) return;
|
|
2132
|
+
anchor.dataset.sbOriginalHref = href;
|
|
2133
|
+
anchor.href = parentOrigin + buildParentUrl(href, appId, appMode);
|
|
2134
|
+
};
|
|
2135
|
+
const restoreHref = (anchor) => {
|
|
2136
|
+
const orig = anchor.dataset.sbOriginalHref;
|
|
2137
|
+
if (orig !== void 0) {
|
|
2138
|
+
anchor.setAttribute("href", orig);
|
|
2139
|
+
delete anchor.dataset.sbOriginalHref;
|
|
2140
|
+
}
|
|
2141
|
+
};
|
|
2142
|
+
const onMouseOver = (ev) => {
|
|
2143
|
+
if (!(ev.target instanceof Element)) return;
|
|
2144
|
+
const a = ev.target.closest("a[href]");
|
|
2145
|
+
if (a instanceof HTMLAnchorElement) rewriteHref(a);
|
|
2146
|
+
};
|
|
2147
|
+
const onMouseOut = (ev) => {
|
|
2148
|
+
if (!(ev.target instanceof Element)) return;
|
|
2149
|
+
const a = ev.target.closest("a[href]");
|
|
2150
|
+
if (!(a instanceof HTMLAnchorElement)) return;
|
|
2151
|
+
if (ev.relatedTarget instanceof Element && a.contains(ev.relatedTarget)) return;
|
|
2152
|
+
restoreHref(a);
|
|
2153
|
+
};
|
|
2154
|
+
const onMouseDown = (ev) => {
|
|
2155
|
+
if (!(ev.target instanceof Element)) return;
|
|
2156
|
+
const a = ev.target.closest("a[href]");
|
|
2157
|
+
if (a instanceof HTMLAnchorElement) restoreHref(a);
|
|
2158
|
+
};
|
|
2159
|
+
window.addEventListener("mouseover", onMouseOver, true);
|
|
2160
|
+
window.addEventListener("mouseout", onMouseOut, true);
|
|
2161
|
+
window.addEventListener("mousedown", onMouseDown, true);
|
|
2162
|
+
hoverCleanup = () => {
|
|
2163
|
+
window.removeEventListener("mouseover", onMouseOver, true);
|
|
2164
|
+
window.removeEventListener("mouseout", onMouseOut, true);
|
|
2165
|
+
window.removeEventListener("mousedown", onMouseDown, true);
|
|
2166
|
+
};
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2114
2169
|
window.addEventListener("click", handleClick, true);
|
|
2115
2170
|
return () => {
|
|
2116
2171
|
window.removeEventListener("click", handleClick, true);
|
|
2117
2172
|
window.open = originalWindowOpen;
|
|
2118
2173
|
navigation?.removeEventListener("navigate", handleNavigate);
|
|
2174
|
+
hoverCleanup?.();
|
|
2119
2175
|
};
|
|
2120
2176
|
}
|
|
2121
2177
|
|