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