@yext/visual-editor 0.0.38 → 0.0.40

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-C2zkTc1a.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
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./index-BBlk-mUB.cjs");function N(){return n.sa().name!=="browser"||window.hasOwnProperty("debuggerInitialized")?null:(window.debuggerInitialized=!0,n.reactDomExports.createPortal(n.ft.jsx(w,{}),document.body))}const k=(t,a)=>{const s=t.dataset.yaAction,e=t.dataset.yaScopeoverride,i=t.dataset.yaEventname,c=e||a;return{action:s,originalEventName:c?`${c}_${i}`:i,scope:c}},S=(t,a)=>{const s=[];let e=t;for(;e!=null&&e.parentElement;)e=e.parentElement.closest(a),e&&s.push(e);return s},m={},j="YA_NO_SCOPE",y=(t,a,s,e)=>{m.hasOwnProperty(t)?m[t].events.map(i=>i.el).includes(e)||(m[t].events=[...m[t].events,{eventData:a,el:e}]):m[t]={scopeEl:s||e,events:[{eventData:a,el:e}]}};function w(){const[t,a]=n.reactExports.useState(),[s,e]=n.reactExports.useState([]),[i,c]=n.reactExports.useState(!1),l=o=>{a(t===o?void 0:o)};return n.reactExports.useEffect(()=>(document.documentElement.classList.add("xYextDebug"),document.querySelectorAll("[data-ya-eventname]").forEach((o,g)=>{const d=o.closest("[data-ya-scope]"),r=d?.dataset.yaScope,u=k(o,r);o.addEventListener("mouseenter",()=>{e([{elem:o,key:`${u.originalEventName}_${g}`,action:u.action,originalEventName:u.originalEventName,scope:u.scope}])}),o.addEventListener("mouseleave",()=>{e([])});const f=o.dataset.yaScopeoverride;f?y(f,u,d,o):[r,...S(o,"[data-ya-scope]").map(p=>p.dataset.yaScope)].forEach(p=>{y(p||j,u,d,o)})}),c(!0),()=>{document.documentElement.classList.remove("xYextDebug")}),[]),i?n.ft.jsxs(n.ft.Fragment,{children:[n.ft.jsxs("div",{className:"analytics-debugger",children:[n.ft.jsxs("div",{className:"analytics-debugger-toggles",children:[n.ft.jsx("button",{className:n.oa("analytics-debugger-toggle",{"is-active":t==="Events"}),onClick:()=>l("Events"),children:"Events"}),n.ft.jsx("button",{className:n.oa("analytics-debugger-toggle",{"is-active":t==="Scopes"}),onClick:()=>l("Scopes"),children:"Scopes"})]}),t&&n.ft.jsx("div",{className:"analytics-debugger-tabs",children:t==="Events"?n.ft.jsx(C,{data:m,setTooltips:e}):n.ft.jsx(D,{data:m,setTooltips:e})})]}),n.ft.jsx($,{tooltips:s})]}):null}const Y=()=>{const t={};return Object.values(m).forEach(a=>{a.events.forEach(s=>{const{originalEventName:e}=s.eventData;t[e]||(t[e]=[]),!t[e].find(i=>i.el===s.el)&&t[e].push(s)})}),t};function C(t){const{setTooltips:a}=t,[s,e]=n.reactExports.useState([]),[i,c]=n.reactExports.useState(""),l=(o,g)=>{s.forEach(r=>r.classList.remove("analytics-event-highlight"));const d=o.map(r=>(r.el.scrollIntoView({behavior:"smooth",block:"nearest"}),r.el.classList.add("analytics-event-highlight"),r.el));e(d),c(g),a(o.map((r,u)=>({elem:r.el,key:`${r.eventData.originalEventName}_${u}`,action:r.eventData.action,originalEventName:r.eventData.originalEventName,scope:r.eventData.scope})))};return n.ft.jsxs("div",{className:"analytics-debugger-tab",children:[n.ft.jsx("h2",{className:"analytics-debugger-tab-title",children:"Event Names"}),n.ft.jsx("ul",{className:"analytics-debugger-list",children:Object.entries(Y()).map(([o,g],d)=>{const r=`${o}_${d}`;return n.ft.jsx("li",{className:"analytics-debugger-listItem",children:n.ft.jsx("button",{className:n.oa("analytics-debugger-button",{"is-active":r===i}),onClick:()=>l(g,r),children:o})},r)})})]})}function D(t){const{data:a,setTooltips:s}=t,[e,i]=n.reactExports.useState(""),c=l=>{const o=a[l];o.scopeEl&&(o.scopeEl.scrollIntoView({behavior:"smooth",block:"nearest"}),i(l),s(o.events.map((g,d)=>{const r=g.eventData;return{elem:g.el,key:`${r.originalEventName}_${d}`,action:r.action,originalEventName:r.originalEventName,scope:r.scope}})))};return n.ft.jsxs("div",{className:"analytics-debugger-tab",children:[n.ft.jsx("h2",{className:"analytics-debugger-tab-title",children:"Scope Names"}),n.ft.jsx("ul",{className:"analytics-debugger-list",children:Object.keys(a).map((l,o)=>{if(l!==j)return n.ft.jsx("li",{className:"analytics-debugger-listItem",children:n.ft.jsx("button",{className:n.oa("analytics-debugger-button",{"is-active":l===e}),onClick:()=>c(l),children:l})},l+o)})})]})}function $(t){const a=n.reactExports.useRef({});return n.reactExports.useEffect(()=>{if(a.current)for(const s of Object.values(a.current)){const e=Object.values(a.current).map(i=>i.el).filter(i=>i!==s.el);O(s,e),s.el.style.visibility="visible"}},[t.tooltips]),n.ft.jsx(n.ft.Fragment,{children:t.tooltips.map(s=>n.ft.jsxs("div",{style:{visibility:"hidden"},className:"analytics-debugger-tooltip",ref:e=>{e?a.current[s.key]={el:e,tooltip:s}:delete a.current[s.key]},children:[n.ft.jsxs("span",{children:["Action: ",s.action]}),n.ft.jsx("br",{}),n.ft.jsxs("span",{children:["Scope: ",s.scope]}),n.ft.jsx("br",{}),n.ft.jsxs("span",{children:["Original Event Name: ",s.originalEventName]})]},s.key))})}function O(t,a){for(let s=0;s<9;s++){const e=I(t.tooltip.elem.getBoundingClientRect(),t.el,s);if(t.el.style.inset=`${e.top} auto auto ${e.left}`,!!B(t.el.getBoundingClientRect().left,t.el.getBoundingClientRect().top+window.scrollY,t.el.getBoundingClientRect().right,t.el.getBoundingClientRect().bottom+window.scrollY))continue;let i=!0;for(let c=0;c<a.length;c++){const l=a[c];R(t.el,l)&&(i=!1)}if(i)break}}function R(t,a){const s=t.getBoundingClientRect().top+window.scrollY,e=t.getBoundingClientRect().left,i=s+t.clientHeight,c=e+t.clientWidth,l=a.getBoundingClientRect().top+window.scrollY,o=a.getBoundingClientRect().left,g=l+a.clientHeight,d=o+a.clientWidth,r=(u,f,p,b,v,h,x,E)=>p<=v&&v<=x&&b<=h&&h<=E||p<=u&&u<=x&&b<=f&&f<=E||p<=u&&u<=x&&b<=h&&h<=E||p<=v&&v<=x&&b<=f&&f<=E;return r(e,s,o,l,c,i,d,g)||r(o,l,e,s,d,g,c,i)}function B(t,a,s,e){return t<0||s>window.innerWidth||a<0||e>document.documentElement.scrollHeight}function I(t,a,s){const e=a.clientHeight,i=a.clientWidth;let c,l;switch(s){case 0:{l=window.scrollY+t.top-e+"px",c=t.left-i+"px";break}case 1:{l=window.scrollY+t.top-e+"px",c=t.left+"px";break}case 2:{l=window.scrollY+t.top-e+"px",c=t.right+"px";break}case 3:{l=window.scrollY+t.top-e+"px",c=t.right-i+"px";break}case 4:{l=window.scrollY+t.bottom+"px",c=t.left-i+"px";break}case 5:{l=window.scrollY+t.bottom+"px",c=t.left+"px";break}case 6:{l=window.scrollY+t.bottom+"px",c=t.right-i+"px";break}case 7:{l=window.scrollY+t.bottom+"px",c=t.right+"px";break}default:l=0,c=0}return{top:l,left:c}}exports.AnalyticsDebuggerInternal=w;exports.default=N;