@dotcms/analytics
Version:
Official JavaScript library for Content Analytics with DotCMS.
109 lines (108 loc) • 3.34 kB
JavaScript
import { UVEEventType as a } from "../../../types/src/lib/editor/public.js";
import { __DOTCMS_UVE_EVENT__ as s } from "../../../types/src/lib/events/internal.js";
import { findDotCMSElement as M, findDotCMSVTLData as p, getClosestDotCMSContainerData as w, getDotCMSPageBounds as S } from "../lib/dom/dom.utils.js";
function U(o) {
const t = (n) => {
n.data.name === s.UVE_SET_PAGE_DATA && o(n.data.payload);
};
return window.addEventListener("message", t), {
unsubscribe: () => {
window.removeEventListener("message", t);
},
event: a.CONTENT_CHANGES
};
}
function V(o) {
const t = (n) => {
n.data.name === s.UVE_RELOAD_PAGE && o();
};
return window.addEventListener("message", t), {
unsubscribe: () => {
window.removeEventListener("message", t);
},
event: a.PAGE_RELOAD
};
}
function I(o) {
const t = (n) => {
if (n.data.name === s.UVE_REQUEST_BOUNDS) {
const e = Array.from(
document.querySelectorAll('[data-dot-object="container"]')
), i = S(e);
o(i);
}
};
return window.addEventListener("message", t), {
unsubscribe: () => {
window.removeEventListener("message", t);
},
event: a.REQUEST_BOUNDS
};
}
function Y(o) {
const t = (n) => {
if (n.data.name === s.UVE_SCROLL_INSIDE_IFRAME) {
const e = n.data.direction;
o(e);
}
};
return window.addEventListener("message", t), {
unsubscribe: () => {
window.removeEventListener("message", t);
},
event: a.IFRAME_SCROLL
};
}
function B(o) {
const t = (n) => {
var d, r, E, c, T, l, m, _, u, C;
const e = M(n.target);
if (!e)
return;
const { x: i, y: g, width: v, height: N } = e.getBoundingClientRect(), f = ((d = e.dataset) == null ? void 0 : d.dotObject) === "container", L = {
identifier: "TEMP_EMPTY_CONTENTLET",
title: "TEMP_EMPTY_CONTENTLET",
contentType: "TEMP_EMPTY_CONTENTLET_TYPE",
inode: "TEMPY_EMPTY_CONTENTLET_INODE",
widgetTitle: "TEMP_EMPTY_CONTENTLET",
baseType: "TEMP_EMPTY_CONTENTLET",
onNumberOfPages: 1
}, P = {
identifier: (r = e.dataset) == null ? void 0 : r.dotIdentifier,
title: (E = e.dataset) == null ? void 0 : E.dotTitle,
inode: (c = e.dataset) == null ? void 0 : c.dotInode,
contentType: (T = e.dataset) == null ? void 0 : T.dotType,
baseType: (l = e.dataset) == null ? void 0 : l.dotBasetype,
widgetTitle: (m = e.dataset) == null ? void 0 : m.dotWidgetTitle,
onNumberOfPages: (_ = e.dataset) == null ? void 0 : _.dotOnNumberOfPages
}, O = p(e), b = {
container: (
// Here extract dot-container from contentlet if it is Headless
// or search in parent container if it is VTL
(u = e.dataset) != null && u.dotContainer ? JSON.parse((C = e.dataset) == null ? void 0 : C.dotContainer) : w(e)
),
contentlet: f ? L : P,
vtlFiles: O
};
o({
x: i,
y: g,
width: v,
height: N,
payload: b
});
};
return document.addEventListener("pointermove", t), {
unsubscribe: () => {
document.removeEventListener("pointermove", t);
},
event: a.CONTENTLET_HOVERED
};
}
export {
U as onContentChanges,
B as onContentletHovered,
Y as onIframeScroll,
V as onPageReload,
I as onRequestBounds
};