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