@dotcms/analytics 0.0.1-beta.9 → 1.0.0
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 +167 -100
- package/lib/dotAnalytics/dot-content-analytics.d.ts +5 -5
- package/lib/dotAnalytics/dot-content-analytics.js +28 -9
- package/lib/dotAnalytics/plugin/dot-analytics.plugin.d.ts +9 -7
- package/lib/dotAnalytics/plugin/dot-analytics.plugin.js +55 -31
- package/lib/dotAnalytics/plugin/enricher/dot-analytics.enricher.plugin.d.ts +45 -0
- package/lib/dotAnalytics/plugin/enricher/dot-analytics.enricher.plugin.js +34 -0
- package/lib/dotAnalytics/plugin/identity/dot-analytics.identity.plugin.d.ts +80 -0
- package/lib/dotAnalytics/plugin/identity/dot-analytics.identity.plugin.js +40 -0
- package/lib/dotAnalytics/plugin/identity/dot-analytics.identity.utils.d.ts +24 -0
- package/lib/dotAnalytics/shared/dot-content-analytics.activity-tracker.d.ts +29 -0
- package/lib/dotAnalytics/shared/dot-content-analytics.activity-tracker.js +86 -0
- package/lib/dotAnalytics/shared/dot-content-analytics.constants.d.ts +28 -8
- package/lib/dotAnalytics/shared/dot-content-analytics.constants.js +12 -8
- package/lib/dotAnalytics/shared/dot-content-analytics.http.d.ts +5 -5
- package/lib/dotAnalytics/shared/dot-content-analytics.http.js +19 -12
- package/lib/dotAnalytics/shared/dot-content-analytics.model.d.ts +303 -88
- package/lib/dotAnalytics/shared/dot-content-analytics.utils.d.ts +86 -29
- package/lib/dotAnalytics/shared/dot-content-analytics.utils.js +118 -41
- package/lib/react/components/DotContentAnalyticsProvider.d.ts +4 -4
- package/lib/react/components/DotContentAnalyticsProvider.js +5 -2
- package/lib/react/contexts/DotContentAnalyticsContext.d.ts +3 -3
- package/lib/react/hook/useContentAnalytics.d.ts +36 -6
- package/lib/react/hook/useContentAnalytics.js +22 -24
- package/lib/react/hook/useRouterTracker.d.ts +3 -3
- package/lib/react/hook/useRouterTracker.js +8 -7
- package/lib/standalone.d.ts +2 -2
- package/package.json +5 -4
- package/types/src/lib/editor/public.js +5 -0
- package/types/src/lib/events/internal.js +4 -0
- package/uve/src/internal/constants.js +3 -0
- package/uve/src/internal/events.js +108 -0
- package/uve/src/lib/core/core.utils.js +21 -0
- package/uve/src/lib/dom/dom.utils.js +81 -0
- package/lib/dotAnalytics/plugin/dot-analytics.enricher.plugin.d.ts +0 -31
- package/lib/dotAnalytics/plugin/dot-analytics.enricher.plugin.js +0 -28
|
@@ -1,46 +1,123 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
);
|
|
30
|
-
|
|
1
|
+
import { SESSION_STORAGE_KEY as h, DEFAULT_SESSION_TIMEOUT_MINUTES as S, USER_ID_KEY as m } from "./dot-content-analytics.constants.js";
|
|
2
|
+
let d = null;
|
|
3
|
+
const u = (t) => {
|
|
4
|
+
const e = Date.now(), n = Math.random().toString(36).substr(2, 9), o = Math.random().toString(36).substr(2, 9);
|
|
5
|
+
return `${t}_${e}_${n}${o}`;
|
|
6
|
+
}, l = {
|
|
7
|
+
getItem: (t) => {
|
|
8
|
+
try {
|
|
9
|
+
return localStorage.getItem(t);
|
|
10
|
+
} catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
setItem: (t, e) => {
|
|
15
|
+
try {
|
|
16
|
+
localStorage.setItem(t, e);
|
|
17
|
+
} catch {
|
|
18
|
+
console.warn(`DotAnalytics: Could not save ${t} to localStorage`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}, f = () => {
|
|
22
|
+
let t = l.getItem(m);
|
|
23
|
+
return t || (t = u("user"), l.setItem(m, t)), t;
|
|
24
|
+
}, _ = (t) => {
|
|
25
|
+
const e = new Date(t), n = /* @__PURE__ */ new Date(), o = new Date(
|
|
26
|
+
e.getUTCFullYear(),
|
|
27
|
+
e.getUTCMonth(),
|
|
28
|
+
e.getUTCDate()
|
|
29
|
+
), s = new Date(n.getUTCFullYear(), n.getUTCMonth(), n.getUTCDate());
|
|
30
|
+
return o.getTime() !== s.getTime();
|
|
31
|
+
}, p = () => {
|
|
32
|
+
const t = Date.now();
|
|
33
|
+
if (typeof window > "u")
|
|
34
|
+
return u("session_fallback");
|
|
31
35
|
try {
|
|
32
|
-
|
|
36
|
+
const e = sessionStorage.getItem(h);
|
|
37
|
+
if (e) {
|
|
38
|
+
const { sessionId: s, startTime: c, lastActivity: i } = JSON.parse(e), g = !_(c), a = t - i < S * 60 * 1e3;
|
|
39
|
+
if (g && a)
|
|
40
|
+
return sessionStorage.setItem(
|
|
41
|
+
h,
|
|
42
|
+
JSON.stringify({
|
|
43
|
+
sessionId: s,
|
|
44
|
+
startTime: c,
|
|
45
|
+
lastActivity: t
|
|
46
|
+
})
|
|
47
|
+
), s;
|
|
48
|
+
}
|
|
49
|
+
const n = u("session"), o = {
|
|
50
|
+
sessionId: n,
|
|
51
|
+
startTime: t,
|
|
52
|
+
lastActivity: t
|
|
53
|
+
};
|
|
54
|
+
return sessionStorage.setItem(h, JSON.stringify(o)), n;
|
|
33
55
|
} catch {
|
|
34
|
-
return
|
|
56
|
+
return u("session_fallback");
|
|
35
57
|
}
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
debug
|
|
39
|
-
|
|
40
|
-
|
|
58
|
+
}, T = (t) => {
|
|
59
|
+
const e = p(), n = f();
|
|
60
|
+
return t.debug && console.warn("DotAnalytics Identity Context:", {
|
|
61
|
+
sessionId: e,
|
|
62
|
+
userId: n
|
|
63
|
+
}), {
|
|
64
|
+
site_key: t.siteKey,
|
|
65
|
+
session_id: e,
|
|
66
|
+
user_id: n
|
|
67
|
+
};
|
|
68
|
+
}, w = () => d || (d = {
|
|
69
|
+
user_language: navigator.language || void 0,
|
|
70
|
+
doc_encoding: document.characterSet || document.charset || void 0,
|
|
71
|
+
screen_resolution: typeof screen < "u" && screen.width && screen.height ? `${screen.width}x${screen.height}` : void 0
|
|
72
|
+
}, d), I = () => {
|
|
73
|
+
try {
|
|
74
|
+
const t = (/* @__PURE__ */ new Date()).getTimezoneOffset(), e = t > 0 ? "-" : "+", n = Math.abs(t), o = Math.floor(n / 60), s = n % 60;
|
|
75
|
+
return `${e}${o.toString().padStart(2, "0")}:${s.toString().padStart(2, "0")}`;
|
|
76
|
+
} catch {
|
|
77
|
+
return "+00:00";
|
|
78
|
+
}
|
|
79
|
+
}, D = () => {
|
|
80
|
+
try {
|
|
81
|
+
const t = /* @__PURE__ */ new Date(), e = I(), n = t.getFullYear(), o = (t.getMonth() + 1).toString().padStart(2, "0"), s = t.getDate().toString().padStart(2, "0"), c = t.getHours().toString().padStart(2, "0"), i = t.getMinutes().toString().padStart(2, "0"), g = t.getSeconds().toString().padStart(2, "0");
|
|
82
|
+
return `${n}-${o}-${s}T${c}:${i}:${g}${e}`;
|
|
83
|
+
} catch {
|
|
84
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
85
|
+
}
|
|
86
|
+
}, $ = (t, e = typeof window < "u" ? window.location : {}) => {
|
|
87
|
+
const n = D(), o = w(), { properties: s } = t, { utm: c } = s, i = {
|
|
88
|
+
url: s.url ?? e.href,
|
|
89
|
+
doc_encoding: o.doc_encoding,
|
|
90
|
+
doc_hash: s.hash ?? e.hash ?? "",
|
|
91
|
+
doc_protocol: e.protocol,
|
|
92
|
+
doc_search: s.search ?? e.search ?? "",
|
|
93
|
+
doc_host: e.hostname,
|
|
94
|
+
doc_path: s.path ?? e.pathname,
|
|
95
|
+
title: s.title ?? (document == null ? void 0 : document.title),
|
|
96
|
+
language_id: void 0,
|
|
97
|
+
persona: void 0
|
|
98
|
+
}, g = {
|
|
99
|
+
screen_resolution: o.screen_resolution,
|
|
100
|
+
language: o.user_language,
|
|
101
|
+
viewport_width: String(s.width),
|
|
102
|
+
viewport_height: String(s.height)
|
|
103
|
+
}, a = {};
|
|
104
|
+
if (c && typeof c == "object") {
|
|
105
|
+
const r = c;
|
|
106
|
+
r.medium && (a.medium = r.medium), r.source && (a.source = r.source), r.campaign && (a.campaign = r.campaign), r.term && (a.term = r.term), r.content && (a.content = r.content);
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
...t,
|
|
110
|
+
page: i,
|
|
111
|
+
device: g,
|
|
112
|
+
...Object.keys(a).length > 0 && { utm: a },
|
|
113
|
+
local_time: n
|
|
114
|
+
};
|
|
115
|
+
};
|
|
41
116
|
export {
|
|
42
|
-
|
|
43
|
-
u as
|
|
44
|
-
|
|
45
|
-
|
|
117
|
+
$ as enrichPagePayloadOptimized,
|
|
118
|
+
u as generateSecureId,
|
|
119
|
+
T as getAnalyticsContext,
|
|
120
|
+
D as getLocalTime,
|
|
121
|
+
p as getSessionId,
|
|
122
|
+
f as getUserId
|
|
46
123
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DotCMSAnalyticsConfig } from '../../dotAnalytics/shared/dot-content-analytics.model';
|
|
2
2
|
import { ReactElement, ReactNode } from 'react';
|
|
3
3
|
|
|
4
4
|
interface DotContentAnalyticsProviderProps {
|
|
5
5
|
children?: ReactNode;
|
|
6
|
-
config:
|
|
6
|
+
config: DotCMSAnalyticsConfig;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
-
* Provider component that initializes and manages
|
|
9
|
+
* Provider component that initializes and manages DotCMSAnalytics instance.
|
|
10
10
|
* It makes the analytics functionality available to all child components through React Context.
|
|
11
11
|
* This component is responsible for:
|
|
12
|
-
* - Initializing the
|
|
12
|
+
* - Initializing the DotCMSAnalytics singleton instance with the provided config
|
|
13
13
|
* - Making the instance accessible via useContext hook to child components
|
|
14
14
|
* - Managing the lifecycle of the analytics instance
|
|
15
15
|
*
|
|
@@ -7,8 +7,11 @@ const f = ({
|
|
|
7
7
|
children: r,
|
|
8
8
|
config: t
|
|
9
9
|
}) => {
|
|
10
|
-
const o = i(
|
|
11
|
-
|
|
10
|
+
const o = i(
|
|
11
|
+
() => n(t),
|
|
12
|
+
[t]
|
|
13
|
+
);
|
|
14
|
+
return t.autoPageView !== !1 && o && m(o), /* @__PURE__ */ e(a.Provider, { value: o, children: r });
|
|
12
15
|
};
|
|
13
16
|
export {
|
|
14
17
|
f as DotContentAnalyticsProvider
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DotCMSAnalytics } from '../../dotAnalytics/shared/dot-content-analytics.model';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* `DotContentAnalyticsContext` is a React context that is designed to provide an instance of
|
|
5
|
-
* `
|
|
5
|
+
* `DotCMSAnalytics` to all of the components within its tree that are Consumers of this context.
|
|
6
6
|
*
|
|
7
7
|
* The context is created with a default value of `null`. It is meant to be provided a real value
|
|
8
8
|
* using the `DotContentAnalyticsProvider` component.
|
|
9
9
|
*
|
|
10
10
|
* @see {@link https://reactjs.org/docs/context.html|React Context}
|
|
11
11
|
*/
|
|
12
|
-
declare const DotContentAnalyticsContext: import('react').Context<
|
|
12
|
+
declare const DotContentAnalyticsContext: import('react').Context<DotCMSAnalytics | null>;
|
|
13
13
|
export default DotContentAnalyticsContext;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DotCMSAnalytics } from '../../dotAnalytics/shared/dot-content-analytics.model';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Custom hook that handles analytics
|
|
4
|
+
* Custom hook that handles analytics tracking for anonymous users.
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
7
|
* ```tsx
|
|
8
8
|
* function Button({ title, urlTitle }) {
|
|
9
9
|
* const { track } = useContentAnalytics();
|
|
10
10
|
*
|
|
11
|
-
* //
|
|
12
|
-
* // Second parameter: object with properties you want to track
|
|
11
|
+
* // Track button click with custom properties
|
|
13
12
|
* return (
|
|
14
13
|
* <button onClick={() => track('btn-click', { title, urlTitle })}>
|
|
15
14
|
* See Details →
|
|
@@ -17,6 +16,37 @@ import { DotAnalytics } from '../../dotAnalytics/shared/dot-content-analytics.mo
|
|
|
17
16
|
* );
|
|
18
17
|
* }
|
|
19
18
|
* ```
|
|
20
|
-
*
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* // Session debugging example
|
|
23
|
+
* function AnalyticsDebugComponent() {
|
|
24
|
+
* const { getAnonymousUserId, getSessionInfo, updateSessionActivity } = useContentAnalytics();
|
|
25
|
+
*
|
|
26
|
+
* const handleManualActivity = () => {
|
|
27
|
+
* updateSessionActivity();
|
|
28
|
+
* // Manual activity updated
|
|
29
|
+
* };
|
|
30
|
+
*
|
|
31
|
+
* // Debug session info in development
|
|
32
|
+
* const debugInfo = () => {
|
|
33
|
+
* if (process.env.NODE_ENV === 'development') {
|
|
34
|
+
* console.log('Anonymous ID:', getAnonymousUserId());
|
|
35
|
+
* console.log('Session info:', getSessionInfo());
|
|
36
|
+
* }
|
|
37
|
+
* };
|
|
38
|
+
*
|
|
39
|
+
* return (
|
|
40
|
+
* <div>
|
|
41
|
+
* <button onClick={handleManualActivity}>Update Activity</button>
|
|
42
|
+
* <button onClick={debugInfo}>Debug Session</button>
|
|
43
|
+
* <p>User ID: {getAnonymousUserId()}</p>
|
|
44
|
+
* </div>
|
|
45
|
+
* );
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @returns {DotCMSAnalytics} - The analytics instance with tracking capabilities for anonymous users
|
|
50
|
+
* @throws {Error} - Throws error if used outside of DotContentAnalyticsProvider or if analytics failed to initialize
|
|
21
51
|
*/
|
|
22
|
-
export declare const useContentAnalytics: () =>
|
|
52
|
+
export declare const useContentAnalytics: () => DotCMSAnalytics;
|
|
@@ -1,34 +1,32 @@
|
|
|
1
|
-
import { useContext as
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { useContext as c, useRef as u, useCallback as a } from "react";
|
|
2
|
+
import { getUVEState as i } from "../../../uve/src/lib/core/core.utils.js";
|
|
3
|
+
import "../../../uve/src/internal/constants.js";
|
|
4
|
+
import l from "../contexts/DotContentAnalyticsContext.js";
|
|
5
|
+
const S = () => {
|
|
6
|
+
const t = c(l), n = u(null);
|
|
6
7
|
if (!t)
|
|
7
|
-
throw new Error(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*/
|
|
14
|
-
track: (n, e = {}) => {
|
|
15
|
-
r() || t == null || t.track(n, {
|
|
8
|
+
throw new Error(
|
|
9
|
+
"useContentAnalytics must be used within a DotContentAnalyticsProvider and analytics must be successfully initialized"
|
|
10
|
+
);
|
|
11
|
+
const s = a(
|
|
12
|
+
(o, e = {}) => {
|
|
13
|
+
i() || t.track(o, {
|
|
16
14
|
...e,
|
|
17
15
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
18
16
|
});
|
|
19
17
|
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (!r()) {
|
|
26
|
-
const e = window.location.pathname;
|
|
27
|
-
e !== o.current && (o.current = e, t.pageView(n));
|
|
28
|
-
}
|
|
18
|
+
[t]
|
|
19
|
+
), r = a(() => {
|
|
20
|
+
if (!i()) {
|
|
21
|
+
const e = window.location.pathname;
|
|
22
|
+
e !== n.current && (n.current = e, t.pageView());
|
|
29
23
|
}
|
|
24
|
+
}, [t]);
|
|
25
|
+
return {
|
|
26
|
+
track: s,
|
|
27
|
+
pageView: r
|
|
30
28
|
};
|
|
31
29
|
};
|
|
32
30
|
export {
|
|
33
|
-
|
|
31
|
+
S as useContentAnalytics
|
|
34
32
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DotCMSAnalytics } from '../../dotAnalytics/shared/dot-content-analytics.model';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Internal custom hook that handles analytics page view tracking.
|
|
5
5
|
*
|
|
6
|
-
* @param {
|
|
6
|
+
* @param {DotCMSAnalytics | null} instance - The analytics instance used to track page views
|
|
7
7
|
* @returns {void}
|
|
8
8
|
*
|
|
9
9
|
*/
|
|
10
|
-
export declare function useRouterTracker(analytics:
|
|
10
|
+
export declare function useRouterTracker(analytics: DotCMSAnalytics | null): void;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { useRef as u, useEffect as i } from "react";
|
|
2
|
+
import { getUVEState as a } from "../../../uve/src/lib/core/core.utils.js";
|
|
3
|
+
import "../../../uve/src/internal/constants.js";
|
|
4
|
+
function p(t) {
|
|
5
|
+
const n = u(null);
|
|
5
6
|
i(() => {
|
|
6
7
|
if (!t)
|
|
7
8
|
return;
|
|
8
9
|
function e() {
|
|
9
|
-
const o = window.location.pathname;
|
|
10
|
-
o !== n.current && !
|
|
10
|
+
const o = window.location.pathname, r = a();
|
|
11
|
+
o !== n.current && !r && t && (n.current = o, t.pageView());
|
|
11
12
|
}
|
|
12
13
|
return e(), window.addEventListener("popstate", e), window.addEventListener("beforeunload", e), () => {
|
|
13
14
|
window.removeEventListener("popstate", e), window.removeEventListener("beforeunload", e);
|
|
@@ -15,5 +16,5 @@ function s(t) {
|
|
|
15
16
|
}, [t]);
|
|
16
17
|
}
|
|
17
18
|
export {
|
|
18
|
-
|
|
19
|
+
p as useRouterTracker
|
|
19
20
|
};
|
package/lib/standalone.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DotCMSAnalytics } from './dotAnalytics/shared/dot-content-analytics.model';
|
|
2
2
|
import { ANALYTICS_WINDOWS_KEY } from './dotAnalytics/shared/dot-content-analytics.constants';
|
|
3
3
|
|
|
4
4
|
declare global {
|
|
5
5
|
interface Window {
|
|
6
|
-
[ANALYTICS_WINDOWS_KEY]:
|
|
6
|
+
[ANALYTICS_WINDOWS_KEY]: DotCMSAnalytics | null;
|
|
7
7
|
}
|
|
8
8
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotcms/analytics",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Official JavaScript library for Content Analytics with DotCMS.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,12 +23,13 @@
|
|
|
23
23
|
"analytics": "^0.8.14"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"react": "
|
|
26
|
+
"react": "19.1.0",
|
|
27
|
+
"@dotcms/uve": "^1.0.0"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"vite": "~5.0.0",
|
|
30
30
|
"@testing-library/jest-dom": "^6.1.6",
|
|
31
|
-
"@testing-library/react": "^14.0.0"
|
|
31
|
+
"@testing-library/react": "^14.0.0",
|
|
32
|
+
"vite": "~5.0.0"
|
|
32
33
|
},
|
|
33
34
|
"main": "./index.cjs.js",
|
|
34
35
|
"module": "./index.esm.js",
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
var N = /* @__PURE__ */ ((r) => (r.EDIT = "EDIT_MODE", r.PREVIEW = "PREVIEW_MODE", r.LIVE = "LIVE", r.UNKNOWN = "UNKNOWN", r))(N || {}), E = /* @__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))(E || {});
|
|
2
|
+
export {
|
|
3
|
+
E as UVEEventType,
|
|
4
|
+
N as UVE_MODE
|
|
5
|
+
};
|
|
@@ -0,0 +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))(t || {});
|
|
2
|
+
export {
|
|
3
|
+
t as __DOTCMS_UVE_EVENT__
|
|
4
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { UVEEventType as n } from "../../../types/src/lib/editor/public.js";
|
|
2
|
+
import { onContentletHovered as r, onIframeScroll as o, onRequestBounds as t, onPageReload as E, onContentChanges as u } from "./events.js";
|
|
3
|
+
n.CONTENT_CHANGES + "", n.PAGE_RELOAD + "", n.REQUEST_BOUNDS + "", n.IFRAME_SCROLL + "", n.CONTENTLET_HOVERED + "";
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { UVEEventType as a } from "../../../types/src/lib/editor/public.js";
|
|
2
|
+
import { __DOTCMS_UVE_EVENT__ as s } from "../../../types/src/lib/events/internal.js";
|
|
3
|
+
import { findDotCMSElement as M, findDotCMSVTLData as p, getClosestDotCMSContainerData as w, getDotCMSPageBounds as S } from "../lib/dom/dom.utils.js";
|
|
4
|
+
function U(o) {
|
|
5
|
+
const t = (n) => {
|
|
6
|
+
n.data.name === s.UVE_SET_PAGE_DATA && o(n.data.payload);
|
|
7
|
+
};
|
|
8
|
+
return window.addEventListener("message", t), {
|
|
9
|
+
unsubscribe: () => {
|
|
10
|
+
window.removeEventListener("message", t);
|
|
11
|
+
},
|
|
12
|
+
event: a.CONTENT_CHANGES
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function V(o) {
|
|
16
|
+
const t = (n) => {
|
|
17
|
+
n.data.name === s.UVE_RELOAD_PAGE && o();
|
|
18
|
+
};
|
|
19
|
+
return window.addEventListener("message", t), {
|
|
20
|
+
unsubscribe: () => {
|
|
21
|
+
window.removeEventListener("message", t);
|
|
22
|
+
},
|
|
23
|
+
event: a.PAGE_RELOAD
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function I(o) {
|
|
27
|
+
const t = (n) => {
|
|
28
|
+
if (n.data.name === s.UVE_REQUEST_BOUNDS) {
|
|
29
|
+
const e = Array.from(
|
|
30
|
+
document.querySelectorAll('[data-dot-object="container"]')
|
|
31
|
+
), i = S(e);
|
|
32
|
+
o(i);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
return window.addEventListener("message", t), {
|
|
36
|
+
unsubscribe: () => {
|
|
37
|
+
window.removeEventListener("message", t);
|
|
38
|
+
},
|
|
39
|
+
event: a.REQUEST_BOUNDS
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function Y(o) {
|
|
43
|
+
const t = (n) => {
|
|
44
|
+
if (n.data.name === s.UVE_SCROLL_INSIDE_IFRAME) {
|
|
45
|
+
const e = n.data.direction;
|
|
46
|
+
o(e);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
return window.addEventListener("message", t), {
|
|
50
|
+
unsubscribe: () => {
|
|
51
|
+
window.removeEventListener("message", t);
|
|
52
|
+
},
|
|
53
|
+
event: a.IFRAME_SCROLL
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function B(o) {
|
|
57
|
+
const t = (n) => {
|
|
58
|
+
var d, r, E, c, T, l, m, _, u, C;
|
|
59
|
+
const e = M(n.target);
|
|
60
|
+
if (!e)
|
|
61
|
+
return;
|
|
62
|
+
const { x: i, y: g, width: v, height: N } = e.getBoundingClientRect(), f = ((d = e.dataset) == null ? void 0 : d.dotObject) === "container", L = {
|
|
63
|
+
identifier: "TEMP_EMPTY_CONTENTLET",
|
|
64
|
+
title: "TEMP_EMPTY_CONTENTLET",
|
|
65
|
+
contentType: "TEMP_EMPTY_CONTENTLET_TYPE",
|
|
66
|
+
inode: "TEMPY_EMPTY_CONTENTLET_INODE",
|
|
67
|
+
widgetTitle: "TEMP_EMPTY_CONTENTLET",
|
|
68
|
+
baseType: "TEMP_EMPTY_CONTENTLET",
|
|
69
|
+
onNumberOfPages: 1
|
|
70
|
+
}, P = {
|
|
71
|
+
identifier: (r = e.dataset) == null ? void 0 : r.dotIdentifier,
|
|
72
|
+
title: (E = e.dataset) == null ? void 0 : E.dotTitle,
|
|
73
|
+
inode: (c = e.dataset) == null ? void 0 : c.dotInode,
|
|
74
|
+
contentType: (T = e.dataset) == null ? void 0 : T.dotType,
|
|
75
|
+
baseType: (l = e.dataset) == null ? void 0 : l.dotBasetype,
|
|
76
|
+
widgetTitle: (m = e.dataset) == null ? void 0 : m.dotWidgetTitle,
|
|
77
|
+
onNumberOfPages: (_ = e.dataset) == null ? void 0 : _.dotOnNumberOfPages
|
|
78
|
+
}, O = p(e), b = {
|
|
79
|
+
container: (
|
|
80
|
+
// Here extract dot-container from contentlet if it is Headless
|
|
81
|
+
// or search in parent container if it is VTL
|
|
82
|
+
(u = e.dataset) != null && u.dotContainer ? JSON.parse((C = e.dataset) == null ? void 0 : C.dotContainer) : w(e)
|
|
83
|
+
),
|
|
84
|
+
contentlet: f ? L : P,
|
|
85
|
+
vtlFiles: O
|
|
86
|
+
};
|
|
87
|
+
o({
|
|
88
|
+
x: i,
|
|
89
|
+
y: g,
|
|
90
|
+
width: v,
|
|
91
|
+
height: N,
|
|
92
|
+
payload: b
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
return document.addEventListener("pointermove", t), {
|
|
96
|
+
unsubscribe: () => {
|
|
97
|
+
document.removeEventListener("pointermove", t);
|
|
98
|
+
},
|
|
99
|
+
event: a.CONTENTLET_HOVERED
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export {
|
|
103
|
+
U as onContentChanges,
|
|
104
|
+
B as onContentletHovered,
|
|
105
|
+
Y as onIframeScroll,
|
|
106
|
+
V as onPageReload,
|
|
107
|
+
I as onRequestBounds
|
|
108
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { UVE_MODE as t } from "../../../../types/src/lib/editor/public.js";
|
|
2
|
+
import "../../internal/constants.js";
|
|
3
|
+
function p() {
|
|
4
|
+
if (typeof window > "u" || window.parent === window || !window.location)
|
|
5
|
+
return;
|
|
6
|
+
const e = new URL(window.location.href), o = Object.values(t);
|
|
7
|
+
let a = e.searchParams.get("mode") ?? t.EDIT;
|
|
8
|
+
const s = e.searchParams.get("language_id"), n = e.searchParams.get("personaId"), r = e.searchParams.get("variantName"), i = e.searchParams.get("experimentId"), c = e.searchParams.get("publishDate"), d = e.searchParams.get("dotCMSHost");
|
|
9
|
+
return o.includes(a) || (a = t.EDIT), {
|
|
10
|
+
mode: a,
|
|
11
|
+
languageId: s,
|
|
12
|
+
persona: n,
|
|
13
|
+
variantName: r,
|
|
14
|
+
experimentId: i,
|
|
15
|
+
publishDate: c,
|
|
16
|
+
dotCMSHost: d
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
p as getUVEState
|
|
21
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import "../../internal/constants.js";
|
|
2
|
+
function C(t) {
|
|
3
|
+
return t.map((a) => {
|
|
4
|
+
const o = a.getBoundingClientRect(), n = Array.from(
|
|
5
|
+
a.querySelectorAll('[data-dot-object="contentlet"]')
|
|
6
|
+
);
|
|
7
|
+
return {
|
|
8
|
+
x: o.x,
|
|
9
|
+
y: o.y,
|
|
10
|
+
width: o.width,
|
|
11
|
+
height: o.height,
|
|
12
|
+
payload: JSON.stringify({
|
|
13
|
+
container: u(a)
|
|
14
|
+
}),
|
|
15
|
+
contentlets: f(o, n)
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function f(t, a) {
|
|
20
|
+
return a.map((o) => {
|
|
21
|
+
var d, r, i, e, s, c;
|
|
22
|
+
const n = o.getBoundingClientRect();
|
|
23
|
+
return {
|
|
24
|
+
x: 0,
|
|
25
|
+
y: n.y - t.y,
|
|
26
|
+
width: n.width,
|
|
27
|
+
height: n.height,
|
|
28
|
+
payload: JSON.stringify({
|
|
29
|
+
container: (d = o.dataset) != null && d.dotContainer ? JSON.parse((r = o.dataset) == null ? void 0 : r.dotContainer) : y(o),
|
|
30
|
+
contentlet: {
|
|
31
|
+
identifier: (i = o.dataset) == null ? void 0 : i.dotIdentifier,
|
|
32
|
+
title: (e = o.dataset) == null ? void 0 : e.dotTitle,
|
|
33
|
+
inode: (s = o.dataset) == null ? void 0 : s.dotInode,
|
|
34
|
+
contentType: (c = o.dataset) == null ? void 0 : c.dotType
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function u(t) {
|
|
41
|
+
var a, o, n, d;
|
|
42
|
+
return {
|
|
43
|
+
acceptTypes: ((a = t.dataset) == null ? void 0 : a.dotAcceptTypes) || "",
|
|
44
|
+
identifier: ((o = t.dataset) == null ? void 0 : o.dotIdentifier) || "",
|
|
45
|
+
maxContentlets: ((n = t.dataset) == null ? void 0 : n.maxContentlets) || "",
|
|
46
|
+
uuid: ((d = t.dataset) == null ? void 0 : d.dotUuid) || ""
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function y(t) {
|
|
50
|
+
const a = t.closest('[data-dot-object="container"]');
|
|
51
|
+
return a ? u(a) : (console.warn("No container found for the contentlet"), null);
|
|
52
|
+
}
|
|
53
|
+
function g(t) {
|
|
54
|
+
var o, n, d;
|
|
55
|
+
if (!t)
|
|
56
|
+
return null;
|
|
57
|
+
const a = t.querySelector('[data-dot-object="empty-content"]');
|
|
58
|
+
return ((o = t == null ? void 0 : t.dataset) == null ? void 0 : o.dotObject) === "contentlet" || // The container inside Headless components have a span with the data-dot-object="container" attribute
|
|
59
|
+
((n = t == null ? void 0 : t.dataset) == null ? void 0 : n.dotObject) === "container" && a || // The container inside Traditional have no content inside
|
|
60
|
+
((d = t == null ? void 0 : t.dataset) == null ? void 0 : d.dotObject) === "container" && t.children.length === 0 ? t : g(t == null ? void 0 : t.parentElement);
|
|
61
|
+
}
|
|
62
|
+
function h(t) {
|
|
63
|
+
const a = t.querySelectorAll(
|
|
64
|
+
'[data-dot-object="vtl-file"]'
|
|
65
|
+
);
|
|
66
|
+
return a.length ? Array.from(a).map((o) => {
|
|
67
|
+
var n, d;
|
|
68
|
+
return {
|
|
69
|
+
inode: (n = o.dataset) == null ? void 0 : n.dotInode,
|
|
70
|
+
name: (d = o.dataset) == null ? void 0 : d.dotUrl
|
|
71
|
+
};
|
|
72
|
+
}) : null;
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
g as findDotCMSElement,
|
|
76
|
+
h as findDotCMSVTLData,
|
|
77
|
+
y as getClosestDotCMSContainerData,
|
|
78
|
+
u as getDotCMSContainerData,
|
|
79
|
+
f as getDotCMSContentletsBound,
|
|
80
|
+
C as getDotCMSPageBounds
|
|
81
|
+
};
|