@yext/visual-editor 0.0.39 → 0.0.41

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