@dotcms/analytics 1.5.1-next.2010 → 1.5.1-next.2023

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotcms/analytics",
3
- "version": "1.5.1-next.2010",
3
+ "version": "1.5.1-next.2023",
4
4
  "description": "Official JavaScript library for Content Analytics with DotCMS.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,5 +1,5 @@
1
- var N = /* @__PURE__ */ ((r) => (r.EDIT = "EDIT_MODE", r.PREVIEW = "PREVIEW_MODE", r.LIVE = "LIVE", r.UNKNOWN = "UNKNOWN", r))(N || {}), O = /* @__PURE__ */ ((r) => (r.CONTENT_CHANGES = "changes", r.PAGE_RELOAD = "page-reload", r.REQUEST_BOUNDS = "request-bounds", r.IFRAME_SCROLL = "iframe-scroll", r.CONTENTLET_HOVERED = "contentlet-hovered", r.SCROLL_TO_SECTION = "scroll-to-section", r))(O || {});
1
+ var r = /* @__PURE__ */ ((N) => (N.EDIT = "EDIT_MODE", N.PREVIEW = "PREVIEW_MODE", N.LIVE = "LIVE", N.UNKNOWN = "UNKNOWN", N))(r || {}), O = /* @__PURE__ */ ((N) => (N.CONTENT_CHANGES = "changes", N.PAGE_RELOAD = "page-reload", N.IFRAME_SCROLL = "iframe-scroll", N.CONTENTLET_HOVERED = "contentlet-hovered", N.CONTENTLET_CLICKED = "contentlet-clicked", N.SCROLL_TO_SECTION = "scroll-to-section", N.SELECTION_CLEARED = "selection-cleared", N.AUTO_BOUNDS = "auto-bounds", N))(O || {});
2
2
  export {
3
3
  O as UVEEventType,
4
- N as UVE_MODE
4
+ r as UVE_MODE
5
5
  };
@@ -1,4 +1,4 @@
1
- var t = /* @__PURE__ */ ((e) => (e.UVE_RELOAD_PAGE = "uve-reload-page", e.UVE_REQUEST_BOUNDS = "uve-request-bounds", e.UVE_EDITOR_PONG = "uve-editor-pong", e.UVE_SCROLL_INSIDE_IFRAME = "uve-scroll-inside-iframe", e.UVE_SET_PAGE_DATA = "uve-set-page-data", e.UVE_COPY_CONTENTLET_INLINE_EDITING_SUCCESS = "uve-copy-contentlet-inline-editing-success", e.UVE_SCROLL_TO_SECTION = "uve-scroll-to-section", e))(t || {});
1
+ var u = /* @__PURE__ */ ((e) => (e.UVE_RELOAD_PAGE = "uve-reload-page", e.UVE_FLUSH_BOUNDS = "uve-flush-bounds", e.UVE_REQUEST_BOUNDS = "uve-request-bounds", e.UVE_EDITOR_PONG = "uve-editor-pong", e.UVE_SCROLL_INSIDE_IFRAME = "uve-scroll-inside-iframe", e.UVE_SET_PAGE_DATA = "uve-set-page-data", e.UVE_COPY_CONTENTLET_INLINE_EDITING_SUCCESS = "uve-copy-contentlet-inline-editing-success", e.UVE_SCROLL_TO_SECTION = "uve-scroll-to-section", e.UVE_SELECTION_CLEARED = "uve-selection-cleared", e))(u || {});
2
2
  export {
3
- t as __DOTCMS_UVE_EVENT__
3
+ u as __DOTCMS_UVE_EVENT__
4
4
  };
@@ -1,7 +1,7 @@
1
1
  import { UVEEventType as e } from "../../../types/src/lib/editor/public.js";
2
- import { onScrollToSection as n, onContentletHovered as r, onIframeScroll as t, onRequestBounds as E, onPageReload as T, onContentChanges as O } from "./events.js";
3
- e.CONTENT_CHANGES + "", e.PAGE_RELOAD + "", e.REQUEST_BOUNDS + "", e.IFRAME_SCROLL + "", e.CONTENTLET_HOVERED + "", e.SCROLL_TO_SECTION + "";
4
- const _ = "dot-section-";
2
+ import { onAutoBounds as o, onScrollToSection as r, onContentletClicked as t, onContentletHovered as E, onIframeScroll as C, onPageReload as T, onContentChanges as O } from "./events.js";
3
+ e.CONTENT_CHANGES + "", e.PAGE_RELOAD + "", e.IFRAME_SCROLL + "", e.CONTENTLET_HOVERED + "", e.CONTENTLET_CLICKED + "", e.SCROLL_TO_SECTION + "", e.SELECTION_CLEARED + "", e.AUTO_BOUNDS + "";
4
+ const L = "dot-section-";
5
5
  export {
6
- _ as DOT_SECTION_ID_PREFIX
6
+ L as DOT_SECTION_ID_PREFIX
7
7
  };
@@ -1,126 +1,192 @@
1
- import { UVEEventType as s } from "../../../types/src/lib/editor/public.js";
2
- import { __DOTCMS_UVE_EVENT__ as i } from "../../../types/src/lib/events/internal.js";
3
- import { DOT_SECTION_ID_PREFIX as C } from "./constants.js";
4
- import { TEMP_EMPTY_CONTENTLET as r, TEMP_EMPTY_CONTENTLET_TYPE as f } from "./contentlet-sentinel.constants.js";
5
- import { findDotCMSElement as g, findDotCMSVTLData as S, getClosestDotCMSContainerData as v, getDotCMSPageBounds as O } from "../lib/dom/dom.utils.js";
6
- function y(o) {
7
- const t = (n) => {
8
- n.data.name === i.UVE_SET_PAGE_DATA && o(n.data.payload);
1
+ import { UVEEventType as d } from "../../../types/src/lib/editor/public.js";
2
+ import { __DOTCMS_UVE_EVENT__ as f } from "../../../types/src/lib/events/internal.js";
3
+ import { DOT_SECTION_ID_PREFIX as g } from "./constants.js";
4
+ import { TEMP_EMPTY_CONTENTLET as C, TEMP_EMPTY_CONTENTLET_TYPE as w } from "./contentlet-sentinel.constants.js";
5
+ import { findDotCMSElement as _, readContentletDataset as b, findDotCMSVTLData as L, getClosestDotCMSContainerData as O, getDotCMSPageBounds as N } from "../lib/dom/dom.utils.js";
6
+ function M(s) {
7
+ const e = (t) => {
8
+ t.data.name === f.UVE_SET_PAGE_DATA && s(t.data.payload);
9
9
  };
10
- return window.addEventListener("message", t), {
10
+ return window.addEventListener("message", e), {
11
11
  unsubscribe: () => {
12
- window.removeEventListener("message", t);
12
+ window.removeEventListener("message", e);
13
13
  },
14
- event: s.CONTENT_CHANGES
14
+ event: d.CONTENT_CHANGES
15
15
  };
16
16
  }
17
- function D(o) {
18
- const t = (n) => {
19
- n.data.name === i.UVE_RELOAD_PAGE && o();
17
+ function P(s) {
18
+ const e = (t) => {
19
+ t.data.name === f.UVE_RELOAD_PAGE && s();
20
20
  };
21
- return window.addEventListener("message", t), {
21
+ return window.addEventListener("message", e), {
22
22
  unsubscribe: () => {
23
- window.removeEventListener("message", t);
23
+ window.removeEventListener("message", e);
24
24
  },
25
- event: s.PAGE_RELOAD
25
+ event: d.PAGE_RELOAD
26
26
  };
27
27
  }
28
- function I(o) {
29
- const t = (n) => {
30
- if (n.data.name === i.UVE_REQUEST_BOUNDS) {
31
- const e = Array.from(
32
- document.querySelectorAll('[data-dot-object="container"]')
33
- ), a = O(e);
34
- o(a);
28
+ const S = 100;
29
+ function R(s) {
30
+ let e = null, t = [];
31
+ const a = () => {
32
+ const r = Array.from(
33
+ document.querySelectorAll('[data-dot-object="container"]')
34
+ );
35
+ s(N(r));
36
+ }, n = () => {
37
+ e !== null && clearTimeout(e), e = setTimeout(() => {
38
+ e = null, a();
39
+ }, S);
40
+ }, o = new ResizeObserver(() => {
41
+ n();
42
+ }), v = () => {
43
+ for (const r of t)
44
+ o.unobserve(r);
45
+ t = Array.from(
46
+ document.querySelectorAll('[data-dot-object="container"]')
47
+ ), o.observe(document.documentElement);
48
+ for (const r of t)
49
+ o.observe(r);
50
+ };
51
+ v();
52
+ const c = (r) => {
53
+ for (let i = 0; i < r.length; i++) {
54
+ const m = r[i];
55
+ if (m.nodeType !== Node.ELEMENT_NODE)
56
+ continue;
57
+ const T = m;
58
+ if (T.matches?.('[data-dot-object="container"]') || T.querySelector?.('[data-dot-object="container"]'))
59
+ return !0;
35
60
  }
61
+ return !1;
62
+ }, l = new MutationObserver((r) => {
63
+ for (const i of r)
64
+ if (i.type === "childList" && (c(i.addedNodes) || c(i.removedNodes))) {
65
+ v(), n();
66
+ return;
67
+ }
68
+ });
69
+ l.observe(document.body ?? document.documentElement, {
70
+ childList: !0,
71
+ subtree: !0
72
+ });
73
+ const u = () => n();
74
+ window.addEventListener("scroll", u, { passive: !0 });
75
+ const E = (r) => {
76
+ r?.data?.name === f.UVE_FLUSH_BOUNDS && (e !== null && (clearTimeout(e), e = null), a());
36
77
  };
37
- return window.addEventListener("message", t), {
78
+ return window.addEventListener("message", E), {
38
79
  unsubscribe: () => {
39
- window.removeEventListener("message", t);
80
+ e !== null && (clearTimeout(e), e = null), o.disconnect(), l.disconnect(), window.removeEventListener("scroll", u), window.removeEventListener("message", E), t = [];
40
81
  },
41
- event: s.REQUEST_BOUNDS
82
+ event: d.AUTO_BOUNDS
42
83
  };
43
84
  }
44
- function R(o) {
45
- const t = (n) => {
46
- if (n.data.name === i.UVE_SCROLL_INSIDE_IFRAME) {
47
- const e = n.data.direction;
48
- o(e);
85
+ function U(s) {
86
+ const e = (t) => {
87
+ if (t.data.name === f.UVE_SCROLL_INSIDE_IFRAME) {
88
+ const a = t.data.direction;
89
+ s(a);
49
90
  }
50
91
  };
51
- return window.addEventListener("message", t), {
92
+ return window.addEventListener("message", e), {
52
93
  unsubscribe: () => {
53
- window.removeEventListener("message", t);
94
+ window.removeEventListener("message", e);
54
95
  },
55
- event: s.IFRAME_SCROLL
96
+ event: d.IFRAME_SCROLL
56
97
  };
57
98
  }
58
- function M(o) {
59
- const t = (n) => {
60
- if (n.data.name !== i.UVE_SCROLL_TO_SECTION)
99
+ function h(s) {
100
+ const e = (t) => {
101
+ if (t.data.name !== f.UVE_SCROLL_TO_SECTION)
61
102
  return;
62
- const e = n.data.sectionIndex, a = document.querySelector(`#${C}${e}`) ?? document.querySelector(`#section-${e}`);
63
- a && o({ sectionIndex: e, offsetTop: a.offsetTop });
103
+ const a = t.data.sectionIndex, n = document.querySelector(`#${g}${a}`) ?? document.querySelector(`#section-${a}`);
104
+ n && s({ sectionIndex: a, offsetTop: n.offsetTop });
64
105
  };
65
- return window.addEventListener("message", t), {
106
+ return window.addEventListener("message", e), {
66
107
  unsubscribe: () => {
67
- window.removeEventListener("message", t);
108
+ window.removeEventListener("message", e);
68
109
  },
69
- event: s.SCROLL_TO_SECTION
110
+ event: d.SCROLL_TO_SECTION
70
111
  };
71
112
  }
72
- function A(o) {
73
- const t = (n) => {
74
- const e = g(n.target);
75
- if (!e) return;
76
- const { x: a, y: d, width: c, height: E } = e.getBoundingClientRect(), m = e.dataset?.dotObject === "container", l = {
77
- identifier: r,
78
- title: r,
79
- contentType: f,
113
+ function V(s) {
114
+ let e = !1;
115
+ const t = (a) => {
116
+ const n = _(a.target);
117
+ if (!n) {
118
+ e && (e = !1, s(null));
119
+ return;
120
+ }
121
+ const { x: o, y: v, width: c, height: l } = n.getBoundingClientRect(), u = n.dataset?.dotObject === "container", E = {
122
+ identifier: C,
123
+ title: C,
124
+ contentType: w,
80
125
  inode: "TEMPY_EMPTY_CONTENTLET_INODE",
81
- widgetTitle: r,
82
- baseType: r,
126
+ widgetTitle: C,
127
+ baseType: C,
83
128
  onNumberOfPages: 1
84
- }, T = {
85
- identifier: e.dataset?.dotIdentifier,
86
- title: e.dataset?.dotTitle,
87
- inode: e.dataset?.dotInode,
88
- contentType: e.dataset?.dotType,
89
- baseType: e.dataset?.dotBasetype,
90
- widgetTitle: e.dataset?.dotWidgetTitle,
91
- onNumberOfPages: e.dataset?.dotOnNumberOfPages,
92
- ...e.dataset?.dotStyleProperties && {
93
- dotStyleProperties: JSON.parse(e.dataset.dotStyleProperties)
94
- }
95
- }, u = S(e), _ = {
129
+ }, r = b(n), i = L(n), m = {
96
130
  container: (
97
131
  // Here extract dot-container from contentlet if it is Headless
98
132
  // or search in parent container if it is VTL
99
- e.dataset?.dotContainer ? JSON.parse(e.dataset?.dotContainer) : v(e)
133
+ n.dataset?.dotContainer ? JSON.parse(n.dataset?.dotContainer) : O(n)
100
134
  ),
101
- contentlet: m ? l : T,
102
- vtlFiles: u
103
- };
104
- o({
105
- x: a,
106
- y: d,
135
+ contentlet: u ? E : r,
136
+ vtlFiles: i
137
+ }, T = {
138
+ x: o,
139
+ y: v,
107
140
  width: c,
108
- height: E,
109
- payload: _
110
- });
141
+ height: l,
142
+ payload: m
143
+ };
144
+ e = !0, s(T);
111
145
  };
112
146
  return document.addEventListener("pointermove", t), {
113
147
  unsubscribe: () => {
114
148
  document.removeEventListener("pointermove", t);
115
149
  },
116
- event: s.CONTENTLET_HOVERED
150
+ event: d.CONTENTLET_HOVERED
151
+ };
152
+ }
153
+ function k(s) {
154
+ let e;
155
+ const t = (n) => {
156
+ const o = _(n.target);
157
+ if (!o || o.dataset?.dotObject === "container") return;
158
+ const c = o.dataset?.dotInode;
159
+ if (c && c === e)
160
+ return;
161
+ n.preventDefault(), n.stopPropagation(), e = c;
162
+ const { x: l, y: u, width: E, height: r } = o.getBoundingClientRect(), i = b(o), m = L(o);
163
+ s({
164
+ x: l,
165
+ y: u,
166
+ width: E,
167
+ height: r,
168
+ payload: {
169
+ container: o.dataset?.dotContainer ? JSON.parse(o.dataset?.dotContainer) : O(o),
170
+ contentlet: i,
171
+ vtlFiles: m
172
+ }
173
+ });
174
+ }, a = (n) => {
175
+ n?.data?.name === f.UVE_SELECTION_CLEARED && (e = void 0);
176
+ };
177
+ return document.addEventListener("click", t, { capture: !0 }), window.addEventListener("message", a), {
178
+ unsubscribe: () => {
179
+ document.removeEventListener("click", t, { capture: !0 }), window.removeEventListener("message", a);
180
+ },
181
+ event: d.CONTENTLET_CLICKED
117
182
  };
118
183
  }
119
184
  export {
120
- y as onContentChanges,
121
- A as onContentletHovered,
122
- R as onIframeScroll,
123
- D as onPageReload,
124
- I as onRequestBounds,
125
- M as onScrollToSection
185
+ R as onAutoBounds,
186
+ M as onContentChanges,
187
+ k as onContentletClicked,
188
+ V as onContentletHovered,
189
+ U as onIframeScroll,
190
+ P as onPageReload,
191
+ h as onScrollToSection
126
192
  };
@@ -1,36 +1,36 @@
1
1
  import "../../internal/constants.js";
2
2
  function c(t) {
3
- return t.map((n) => {
4
- const e = n.getBoundingClientRect(), o = Array.from(
5
- n.querySelectorAll('[data-dot-object="contentlet"]')
3
+ return t.map((e) => {
4
+ const n = e.getBoundingClientRect(), o = Array.from(
5
+ e.querySelectorAll('[data-dot-object="contentlet"]')
6
6
  );
7
7
  return {
8
- x: e.x,
9
- y: e.y,
10
- width: e.width,
11
- height: e.height,
8
+ x: n.x,
9
+ y: n.y,
10
+ width: n.width,
11
+ height: n.height,
12
12
  payload: JSON.stringify({
13
- container: a(n)
13
+ container: a(e)
14
14
  }),
15
- contentlets: d(e, o)
15
+ contentlets: d(n, o)
16
16
  };
17
17
  });
18
18
  }
19
- function d(t, n) {
20
- return n.map((e) => {
21
- const o = e.getBoundingClientRect();
19
+ function d(t, e) {
20
+ return e.map((n) => {
21
+ const o = n.getBoundingClientRect();
22
22
  return {
23
23
  x: 0,
24
24
  y: o.y - t.y,
25
25
  width: o.width,
26
26
  height: o.height,
27
27
  payload: JSON.stringify({
28
- container: e.dataset?.dotContainer ? JSON.parse(e.dataset?.dotContainer) : r(e),
28
+ container: n.dataset?.dotContainer ? JSON.parse(n.dataset?.dotContainer) : r(n),
29
29
  contentlet: {
30
- identifier: e.dataset?.dotIdentifier,
31
- title: e.dataset?.dotTitle,
32
- inode: e.dataset?.dotInode,
33
- contentType: e.dataset?.dotType
30
+ identifier: n.dataset?.dotIdentifier,
31
+ title: n.dataset?.dotTitle,
32
+ inode: n.dataset?.dotInode,
33
+ contentType: n.dataset?.dotType
34
34
  }
35
35
  })
36
36
  };
@@ -45,30 +45,46 @@ function a(t) {
45
45
  };
46
46
  }
47
47
  function r(t) {
48
- const n = t.closest('[data-dot-object="container"]');
49
- return n ? a(n) : (console.warn("No container found for the contentlet"), null);
48
+ const e = t.closest('[data-dot-object="container"]');
49
+ return e ? a(e) : (console.warn("No container found for the contentlet"), null);
50
50
  }
51
51
  function i(t) {
52
52
  if (!t) return null;
53
- const n = t.querySelector('[data-dot-object="empty-content"]');
53
+ const e = t.querySelector('[data-dot-object="empty-content"]');
54
54
  return t?.dataset?.dotObject === "contentlet" || // The container inside Headless components have a span with the data-dot-object="container" attribute
55
- t?.dataset?.dotObject === "container" && n || // The container inside Traditional have no content inside
55
+ t?.dataset?.dotObject === "container" && e || // The container inside Traditional have no content inside
56
56
  t?.dataset?.dotObject === "container" && t.children.length === 0 ? t : i(t?.parentElement);
57
57
  }
58
58
  function u(t) {
59
- const n = t.querySelectorAll(
59
+ const e = t.querySelectorAll(
60
60
  '[data-dot-object="vtl-file"]'
61
61
  );
62
- return n.length ? Array.from(n).map((e) => ({
63
- inode: e.dataset?.dotInode,
64
- name: e.dataset?.dotUrl
62
+ return e.length ? Array.from(e).map((n) => ({
63
+ inode: n.dataset?.dotInode,
64
+ name: n.dataset?.dotUrl
65
65
  })) : null;
66
66
  }
67
+ function l(t) {
68
+ const e = t.dataset ?? {};
69
+ return {
70
+ identifier: e.dotIdentifier,
71
+ title: e.dotTitle,
72
+ inode: e.dotInode,
73
+ contentType: e.dotType,
74
+ baseType: e.dotBasetype,
75
+ widgetTitle: e.dotWidgetTitle,
76
+ onNumberOfPages: e.dotOnNumberOfPages,
77
+ ...e.dotStyleProperties && {
78
+ dotStyleProperties: JSON.parse(e.dotStyleProperties)
79
+ }
80
+ };
81
+ }
67
82
  export {
68
83
  i as findDotCMSElement,
69
84
  u as findDotCMSVTLData,
70
85
  r as getClosestDotCMSContainerData,
71
86
  a as getDotCMSContainerData,
72
87
  d as getDotCMSContentletsBound,
73
- c as getDotCMSPageBounds
88
+ c as getDotCMSPageBounds,
89
+ l as readContentletDataset
74
90
  };