@yext/visual-editor 0.0.13 → 0.0.15

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