@yext/pages-components 1.2.0 → 1.2.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.
@@ -0,0 +1,317 @@
1
+ import { jsx as r, jsxs as b, Fragment as C } from "react/jsx-runtime";
2
+ import { useState as E, useEffect as O, useRef as S } from "react";
3
+ import { createPortal as Y } from "react-dom";
4
+ import { g as T, c as N } from "./index-GeO8DZvj.js";
5
+ function M() {
6
+ return T().name !== "browser" || window.hasOwnProperty("debuggerInitialized") ? null : (window.debuggerInitialized = !0, Y(/* @__PURE__ */ r($, {}), document.body));
7
+ }
8
+ const A = (e, s) => {
9
+ const n = e.dataset.yaAction, t = e.dataset.yaScopeoverride, l = e.dataset.yaEventname, a = t || s;
10
+ return {
11
+ action: n,
12
+ originalEventName: a ? `${a}_${l}` : l,
13
+ scope: a
14
+ };
15
+ }, R = (e, s) => {
16
+ const n = [];
17
+ let t = e;
18
+ for (; t != null && t.parentElement; )
19
+ t = t.parentElement.closest(s), t && n.push(t);
20
+ return n;
21
+ }, h = {}, D = "YA_NO_SCOPE", B = (e, s, n, t) => {
22
+ h.hasOwnProperty(e) ? h[e].events.map((l) => l.el).includes(t) || (h[e].events = [
23
+ ...h[e].events,
24
+ {
25
+ eventData: s,
26
+ el: t
27
+ }
28
+ ]) : h[e] = {
29
+ scopeEl: n || t,
30
+ // overidden scopes still need an element
31
+ events: [
32
+ {
33
+ eventData: s,
34
+ el: t
35
+ }
36
+ ]
37
+ };
38
+ };
39
+ function $() {
40
+ const [e, s] = E(), [n, t] = E([]), [l, a] = E(!1), i = (o) => {
41
+ s(e === o ? void 0 : o);
42
+ };
43
+ return O(() => {
44
+ let o = null;
45
+ const u = () => {
46
+ o && o.abort(), o = new AbortController();
47
+ const c = o.signal;
48
+ document.documentElement.classList.add("xYextDebug"), document.querySelectorAll(
49
+ "[data-ya-eventname]"
50
+ ).forEach((d, y) => {
51
+ const m = d.closest("[data-ya-scope]"), f = m == null ? void 0 : m.dataset.yaScope, p = A(d, f);
52
+ d.addEventListener(
53
+ "mouseenter",
54
+ () => {
55
+ t([
56
+ {
57
+ elem: d,
58
+ key: `${p.originalEventName}_${y}`,
59
+ action: p.action,
60
+ originalEventName: p.originalEventName,
61
+ scope: p.scope
62
+ }
63
+ ]);
64
+ },
65
+ { signal: c }
66
+ ), d.addEventListener(
67
+ "mouseleave",
68
+ () => {
69
+ t([]);
70
+ },
71
+ { signal: c }
72
+ );
73
+ const w = d.dataset.yaScopeoverride;
74
+ w ? B(w, p, m, d) : [
75
+ f,
76
+ ...R(d, "[data-ya-scope]").map(
77
+ (x) => x.dataset.yaScope
78
+ )
79
+ ].forEach((x) => {
80
+ B(x || D, p, m, d);
81
+ });
82
+ }), a(!0);
83
+ };
84
+ u();
85
+ const g = new MutationObserver(u);
86
+ return g.observe(document, {
87
+ childList: !0,
88
+ subtree: !0
89
+ }), () => {
90
+ document.documentElement.classList.remove("xYextDebug"), g.disconnect(), o == null || o.abort();
91
+ };
92
+ }, []), l ? /* @__PURE__ */ b(C, { children: [
93
+ /* @__PURE__ */ b("div", { className: "analytics-debugger", children: [
94
+ /* @__PURE__ */ b("div", { className: "analytics-debugger-toggles", children: [
95
+ /* @__PURE__ */ r(
96
+ "button",
97
+ {
98
+ className: N("analytics-debugger-toggle", {
99
+ "is-active": e === "Events"
100
+ }),
101
+ onClick: () => i("Events"),
102
+ children: "Events"
103
+ }
104
+ ),
105
+ /* @__PURE__ */ r(
106
+ "button",
107
+ {
108
+ className: N("analytics-debugger-toggle", {
109
+ "is-active": e === "Scopes"
110
+ }),
111
+ onClick: () => i("Scopes"),
112
+ children: "Scopes"
113
+ }
114
+ )
115
+ ] }),
116
+ e && /* @__PURE__ */ r("div", { className: "analytics-debugger-tabs", children: e === "Events" ? /* @__PURE__ */ r(j, { data: h, setTooltips: t }) : /* @__PURE__ */ r(_, { data: h, setTooltips: t }) })
117
+ ] }),
118
+ /* @__PURE__ */ r(I, { tooltips: n })
119
+ ] }) : null;
120
+ }
121
+ const L = () => {
122
+ const e = {};
123
+ return Object.values(h).forEach((s) => {
124
+ s.events.forEach((n) => {
125
+ const { originalEventName: t } = n.eventData;
126
+ e[t] || (e[t] = []), !e[t].find(
127
+ (l) => l.el === n.el
128
+ ) && e[t].push(n);
129
+ });
130
+ }), e;
131
+ };
132
+ function j(e) {
133
+ const { setTooltips: s } = e, [n, t] = E([]), [l, a] = E(""), i = (o, u) => {
134
+ n.forEach(
135
+ (c) => c.classList.remove("analytics-event-highlight")
136
+ );
137
+ const g = o.map((c) => (c.el.scrollIntoView({ behavior: "smooth", block: "nearest" }), c.el.classList.add("analytics-event-highlight"), c.el));
138
+ t(g), a(u), s(
139
+ o.map((c, v) => ({
140
+ elem: c.el,
141
+ key: `${c.eventData.originalEventName}_${v}`,
142
+ action: c.eventData.action,
143
+ originalEventName: c.eventData.originalEventName,
144
+ scope: c.eventData.scope
145
+ }))
146
+ );
147
+ };
148
+ return /* @__PURE__ */ b("div", { className: "analytics-debugger-tab", children: [
149
+ /* @__PURE__ */ r("h2", { className: "analytics-debugger-tab-title", children: "Event Names" }),
150
+ /* @__PURE__ */ r("ul", { className: "analytics-debugger-list", children: Object.entries(L()).map(
151
+ ([o, u], g) => {
152
+ const c = `${o}_${g}`;
153
+ return /* @__PURE__ */ r("li", { className: "analytics-debugger-listItem", children: /* @__PURE__ */ r(
154
+ "button",
155
+ {
156
+ className: N("analytics-debugger-button", {
157
+ "is-active": c === l
158
+ }),
159
+ onClick: () => i(u, c),
160
+ children: o
161
+ }
162
+ ) }, c);
163
+ }
164
+ ) })
165
+ ] });
166
+ }
167
+ function _(e) {
168
+ const { data: s, setTooltips: n } = e, [t, l] = E(""), a = (i) => {
169
+ const o = s[i];
170
+ o.scopeEl && (o.scopeEl.scrollIntoView({
171
+ behavior: "smooth",
172
+ block: "nearest"
173
+ }), l(i), n(
174
+ o.events.map((u, g) => {
175
+ const c = u.eventData;
176
+ return {
177
+ elem: u.el,
178
+ key: `${c.originalEventName}_${g}`,
179
+ action: c.action,
180
+ originalEventName: c.originalEventName,
181
+ scope: c.scope
182
+ };
183
+ })
184
+ ));
185
+ };
186
+ return /* @__PURE__ */ b("div", { className: "analytics-debugger-tab", children: [
187
+ /* @__PURE__ */ r("h2", { className: "analytics-debugger-tab-title", children: "Scope Names" }),
188
+ /* @__PURE__ */ r("ul", { className: "analytics-debugger-list", children: Object.keys(s).map((i, o) => {
189
+ if (i !== D)
190
+ return /* @__PURE__ */ r("li", { className: "analytics-debugger-listItem", children: /* @__PURE__ */ r(
191
+ "button",
192
+ {
193
+ className: N("analytics-debugger-button", {
194
+ "is-active": i === t
195
+ }),
196
+ onClick: () => a(i),
197
+ children: i
198
+ }
199
+ ) }, i + o);
200
+ }) })
201
+ ] });
202
+ }
203
+ function I(e) {
204
+ const s = S({});
205
+ return O(() => {
206
+ if (s.current)
207
+ for (const n of Object.values(s.current)) {
208
+ const t = Object.values(s.current).map((l) => l.el).filter((l) => l !== n.el);
209
+ P(n, t), n.el.style.visibility = "visible";
210
+ }
211
+ }, [e.tooltips]), /* @__PURE__ */ r(C, { children: e.tooltips.map((n) => /* @__PURE__ */ b(
212
+ "div",
213
+ {
214
+ style: { visibility: "hidden" },
215
+ className: "analytics-debugger-tooltip",
216
+ ref: (t) => {
217
+ t ? s.current[n.key] = {
218
+ el: t,
219
+ tooltip: n
220
+ } : delete s.current[n.key];
221
+ },
222
+ children: [
223
+ /* @__PURE__ */ b("span", { children: [
224
+ "Action: ",
225
+ n.action
226
+ ] }),
227
+ /* @__PURE__ */ r("br", {}),
228
+ /* @__PURE__ */ b("span", { children: [
229
+ "Scope: ",
230
+ n.scope
231
+ ] }),
232
+ /* @__PURE__ */ r("br", {}),
233
+ /* @__PURE__ */ b("span", { children: [
234
+ "Original Event Name: ",
235
+ n.originalEventName
236
+ ] })
237
+ ]
238
+ },
239
+ n.key
240
+ )) });
241
+ }
242
+ function P(e, s) {
243
+ for (let n = 0; n < 9; n++) {
244
+ const t = q(
245
+ e.tooltip.elem.getBoundingClientRect(),
246
+ e.el,
247
+ n
248
+ );
249
+ if (e.el.style.inset = `${t.top} auto auto ${t.left}`, !!W(
250
+ e.el.getBoundingClientRect().left,
251
+ e.el.getBoundingClientRect().top + window.scrollY,
252
+ e.el.getBoundingClientRect().right,
253
+ e.el.getBoundingClientRect().bottom + window.scrollY
254
+ )) continue;
255
+ let a = !0;
256
+ for (let i = 0; i < s.length; i++) {
257
+ const o = s[i];
258
+ H(e.el, o) && (a = !1);
259
+ }
260
+ if (a) break;
261
+ }
262
+ }
263
+ function H(e, s) {
264
+ const n = e.getBoundingClientRect().top + window.scrollY, t = e.getBoundingClientRect().left, l = n + e.clientHeight, a = t + e.clientWidth, i = s.getBoundingClientRect().top + window.scrollY, o = s.getBoundingClientRect().left, u = i + s.clientHeight, g = o + s.clientWidth, c = (v, d, y, m, f, p, w, k) => y <= f && f <= w && m <= p && p <= k || y <= v && v <= w && m <= d && d <= k || y <= v && v <= w && m <= p && p <= k || y <= f && f <= w && m <= d && d <= k;
265
+ return c(t, n, o, i, a, l, g, u) || c(o, i, t, n, g, u, a, l);
266
+ }
267
+ function W(e, s, n, t) {
268
+ return e < 0 || n > window.innerWidth || s < 0 || t > document.documentElement.scrollHeight;
269
+ }
270
+ function q(e, s, n) {
271
+ const t = s.clientHeight, l = s.clientWidth;
272
+ let a, i;
273
+ switch (n) {
274
+ case 0: {
275
+ i = window.scrollY + e.top - t + "px", a = e.left - l + "px";
276
+ break;
277
+ }
278
+ case 1: {
279
+ i = window.scrollY + e.top - t + "px", a = e.left + "px";
280
+ break;
281
+ }
282
+ case 2: {
283
+ i = window.scrollY + e.top - t + "px", a = e.right + "px";
284
+ break;
285
+ }
286
+ case 3: {
287
+ i = window.scrollY + e.top - t + "px", a = e.right - l + "px";
288
+ break;
289
+ }
290
+ case 4: {
291
+ i = window.scrollY + e.bottom + "px", a = e.left - l + "px";
292
+ break;
293
+ }
294
+ case 5: {
295
+ i = window.scrollY + e.bottom + "px", a = e.left + "px";
296
+ break;
297
+ }
298
+ case 6: {
299
+ i = window.scrollY + e.bottom + "px", a = e.right - l + "px";
300
+ break;
301
+ }
302
+ case 7: {
303
+ i = window.scrollY + e.bottom + "px", a = e.right + "px";
304
+ break;
305
+ }
306
+ default:
307
+ i = 0, a = 0;
308
+ }
309
+ return {
310
+ top: i,
311
+ left: a
312
+ };
313
+ }
314
+ export {
315
+ $ as AnalyticsDebuggerInternal,
316
+ M as default
317
+ };