@dotcms/analytics
Version:
Official JavaScript library for Content Analytics with DotCMS.
91 lines (90 loc) • 2.56 kB
JavaScript
import "../../internal/constants.js";
function c(t) {
return t.map((e) => {
const n = e.getBoundingClientRect(), o = Array.from(
e.querySelectorAll('[data-dot-object="contentlet"]')
);
return {
x: n.x,
y: n.y,
width: n.width,
height: n.height,
payload: JSON.stringify({
container: a(e)
}),
contentlets: d(n, o)
};
});
}
function d(t, e) {
return e.map((n) => {
const o = n.getBoundingClientRect();
return {
x: 0,
y: o.y - t.y,
width: o.width,
height: o.height,
payload: JSON.stringify({
container: n.dataset?.dotContainer ? JSON.parse(n.dataset?.dotContainer) : r(n),
contentlet: {
identifier: n.dataset?.dotIdentifier,
title: n.dataset?.dotTitle,
inode: n.dataset?.dotInode,
contentType: n.dataset?.dotType
}
})
};
});
}
function a(t) {
return {
acceptTypes: t.dataset?.dotAcceptTypes || "",
identifier: t.dataset?.dotIdentifier || "",
maxContentlets: t.dataset?.maxContentlets || "",
uuid: t.dataset?.dotUuid || ""
};
}
function r(t) {
const e = t.closest('[data-dot-object="container"]');
return e ? a(e) : (console.warn("No container found for the contentlet"), null);
}
function i(t) {
if (!t) return null;
const e = t.querySelector('[data-dot-object="empty-content"]');
return t?.dataset?.dotObject === "contentlet" || // The container inside Headless components have a span with the data-dot-object="container" attribute
t?.dataset?.dotObject === "container" && e || // The container inside Traditional have no content inside
t?.dataset?.dotObject === "container" && t.children.length === 0 ? t : i(t?.parentElement);
}
function u(t) {
const e = t.querySelectorAll(
'[data-dot-object="vtl-file"]'
);
return e.length ? Array.from(e).map((n) => ({
inode: n.dataset?.dotInode,
name: n.dataset?.dotUrl
})) : null;
}
function l(t) {
const e = t.dataset ?? {};
return {
identifier: e.dotIdentifier,
title: e.dotTitle,
inode: e.dotInode,
contentType: e.dotType,
baseType: e.dotBasetype,
widgetTitle: e.dotWidgetTitle,
onNumberOfPages: e.dotOnNumberOfPages,
...e.dotStyleProperties && {
dotStyleProperties: JSON.parse(e.dotStyleProperties)
}
};
}
export {
i as findDotCMSElement,
u as findDotCMSVTLData,
r as getClosestDotCMSContainerData,
a as getDotCMSContainerData,
d as getDotCMSContentletsBound,
c as getDotCMSPageBounds,
l as readContentletDataset
};