From 4608f23663d7eebf37c0a24c264795b30fb437d1 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 7 Dec 2023 13:15:59 +0000 Subject: [PATCH] Automated linting/prettier update --- packages/sites-components/postcss.config.cjs | 6 +- .../src/components/analytics/debugger.css | 295 ++++---- .../src/components/analytics/debugger.tsx | 701 ++++++++++-------- .../src/components/analytics/interfaces.ts | 4 +- .../src/components/analytics/provider.tsx | 8 +- .../src/components/analytics/types.ts | 14 +- 6 files changed, 539 insertions(+), 489 deletions(-) diff --git a/packages/sites-components/postcss.config.cjs b/packages/sites-components/postcss.config.cjs index 316ff7a5..458cb8c7 100644 --- a/packages/sites-components/postcss.config.cjs +++ b/packages/sites-components/postcss.config.cjs @@ -1,5 +1,5 @@ module.exports = { - plugins: { - 'postcss-nested': {}, - }, + plugins: { + "postcss-nested": {}, + }, }; diff --git a/packages/sites-components/src/components/analytics/debugger.css b/packages/sites-components/src/components/analytics/debugger.css index a0e8f9e6..d5e73f6d 100644 --- a/packages/sites-components/src/components/analytics/debugger.css +++ b/packages/sites-components/src/components/analytics/debugger.css @@ -1,173 +1,170 @@ .xYextDebug { - @keyframes pulse { - 0% - { - background: transparent; - } - - 50% - { - background: rgba(0, 0, 0, 0.15); - } - - 100% - { - background: transparent; - } + @keyframes pulse { + 0% { + background: transparent; } - [data-ya-track] { - outline: 1px dashed blue; - scroll-margin: 32px; - - &.analytics-event-highlight { - animation-name: pulse; - animation-duration: 2s; - animation-iteration-count: infinite; - outline: 2px dashed black; - padding: 8px 16px; - } + 50% { + background: rgba(0, 0, 0, 0.15); } - [data-ya-scope] { - outline: 1px dashed green; - position: relative; - - &::after { - content: attr(data-ya-scope); - position: absolute; - top: 0; - left: 0; - color: black; - display: block; - position: absolute; - - padding: 10px; - outline: 1px solid #178acd; - background: rgba(0, 0, 0, 0.45); - color: white; - z-index: 2147483647; - } + 100% { + background: transparent; } - - .analytics-debugger { - position: fixed; - height: 80%; - top: 10%; - bottom: 10%; - right: 0; - transition: right 300ms ease-out; - color: white; - display: flex !important; - z-index: 99999; + } + + [data-ya-track] { + outline: 1px dashed blue; + scroll-margin: 32px; + + &.analytics-event-highlight { + animation-name: pulse; + animation-duration: 2s; + animation-iteration-count: infinite; + outline: 2px dashed black; + padding: 8px 16px; } - - /* Toggles */ - .analytics-debugger-toggles { - width: 100px; - border-top-left-radius: 4px; - border-bottom-left-radius: 4px; - background: rgba(0, 0, 0, 0.75); - margin: auto; - display: flex; - flex-direction: column; - border-right: 1px solid white; + } + + [data-ya-scope] { + outline: 1px dashed green; + position: relative; + + &::after { + content: attr(data-ya-scope); + position: absolute; + top: 0; + left: 0; + color: black; + display: block; + position: absolute; + + padding: 10px; + outline: 1px solid #178acd; + background: rgba(0, 0, 0, 0.45); + color: white; + z-index: 2147483647; + } + } + + .analytics-debugger { + position: fixed; + height: 80%; + top: 10%; + bottom: 10%; + right: 0; + transition: right 300ms ease-out; + color: white; + display: flex !important; + z-index: 99999; + } + + /* Toggles */ + .analytics-debugger-toggles { + width: 100px; + border-top-left-radius: 4px; + border-bottom-left-radius: 4px; + background: rgba(0, 0, 0, 0.75); + margin: auto; + display: flex; + flex-direction: column; + border-right: 1px solid white; + } + + .analytics-debugger-toggle { + outline: none; + text-align: center; + padding: 10px; + cursor: pointer; + + &.is-active { + background: #178acd; } - .analytics-debugger-toggle { - outline: none; - text-align: center; - padding: 10px; - cursor: pointer; - - &.is-active { - background: #178acd; - } - - &:first-child { - border-top-left-radius: 4px; - } - - &:last-child { - border-bottom-left-radius: 4px; - } - - &:not(:last-child) { - border-bottom: 1px solid white; - } - - &:hover { - background: #178acd; - } + &:first-child { + border-top-left-radius: 4px; } - /* Tabs */ - .analytics-debugger-tabs { - width: 250px; - border-top-left-radius: 4px; - border-bottom-left-radius: 4px; - background: rgba(0, 0, 0, 0.75); + &:last-child { + border-bottom-left-radius: 4px; } - .analytics-debugger-tab { - display: flex; - flex-direction: column; - height: 100%; + &:not(:last-child) { + border-bottom: 1px solid white; } - .analytics-debugger-tab-title { - background: #178acd; - color: white; - padding: 20px; - border-bottom: 1px solid white; - border-top-left-radius: 4px; + &:hover { + background: #178acd; } - - /* Items */ - .analytics-debugger-list { - overflow-y: scroll; - flex-grow: 1; + } + + /* Tabs */ + .analytics-debugger-tabs { + width: 250px; + border-top-left-radius: 4px; + border-bottom-left-radius: 4px; + background: rgba(0, 0, 0, 0.75); + } + + .analytics-debugger-tab { + display: flex; + flex-direction: column; + height: 100%; + } + + .analytics-debugger-tab-title { + background: #178acd; + color: white; + padding: 20px; + border-bottom: 1px solid white; + border-top-left-radius: 4px; + } + + /* Items */ + .analytics-debugger-list { + overflow-y: scroll; + flex-grow: 1; + } + + .analytics-debugger-listItem { + display: flex; + flex-wrap: wrap; + justify-content: space-between; + align-items: center; + + &:not(:last-child) { + border-bottom: 1px solid white; } + } - .analytics-debugger-listItem { - display: flex; - flex-wrap: wrap; - justify-content: space-between; - align-items: center; + .analytics-debugger-button { + padding: 10px 20px; + text-align: left; + width: 100%; - &:not(:last-child) { - border-bottom: 1px solid white; - } + &.is-active { + background: #178acd; } - .analytics-debugger-button { - padding: 10px 20px; - text-align: left; - width: 100%; - - &.is-active { - background: #178acd; - } - - &:hover:not(.is-active) { - background: rgba(255, 255, 255, 0.3); - cursor: pointer; - } + &:hover:not(.is-active) { + background: rgba(255, 255, 255, 0.3); + cursor: pointer; } - - .analytics-debugger-tooltip { - background: #178acd; - border: 1px solid #178acd; - color: white; - position: absolute; - padding: 5px 10px; - border-radius: 4px; - font-size: 12px; - z-index: 99998; - - &:hover { - z-index: 99999; - border: 1px solid black; - } + } + + .analytics-debugger-tooltip { + background: #178acd; + border: 1px solid #178acd; + color: white; + position: absolute; + padding: 5px 10px; + border-radius: 4px; + font-size: 12px; + z-index: 99998; + + &:hover { + z-index: 99999; + border: 1px solid black; } + } } diff --git a/packages/sites-components/src/components/analytics/debugger.tsx b/packages/sites-components/src/components/analytics/debugger.tsx index 00a8acbd..71422352 100644 --- a/packages/sites-components/src/components/analytics/debugger.tsx +++ b/packages/sites-components/src/components/analytics/debugger.tsx @@ -1,381 +1,434 @@ import { useEffect, useRef, useState } from "react"; import { createPortal } from "react-dom"; import { getRuntime } from "../../util/index.js"; -import type { DebuggerTabs, EventData, TabProps, Tooltip, TooltipHandlerProps, TooltipsRefItem } from "./types"; +import type { + DebuggerTabs, + EventData, + TabProps, + Tooltip, + TooltipHandlerProps, + TooltipsRefItem, +} from "./types"; import c from "classnames"; import "./debugger.css"; declare global { - interface Window { debuggerInitialized: boolean; } + interface Window { + debuggerInitialized: boolean; + } } export function AnalyticsDebugger() { - // If multiple AnalyticsProviders are rendered, ensure that only one debugger is created. - if (getRuntime().name !== "browser" || window.hasOwnProperty("debuggerInitialized")) { - return null; - } - - window.debuggerInitialized = true; - return createPortal(, document.body); + // If multiple AnalyticsProviders are rendered, ensure that only one debugger is created. + if ( + getRuntime().name !== "browser" || + window.hasOwnProperty("debuggerInitialized") + ) { + return null; + } + + window.debuggerInitialized = true; + return createPortal(, document.body); } // Track scope / event elements. const data: EventData = {}; export function AnalyticsDebuggerInternal() { - // Track whether the Events, Scope, or no tab is opened. - const [activeTab, setActiveTab] = useState(); - // Track the event elements that need to have a tooltip added. - const [tooltips, setTooltips] = useState([]); - // Indicate when effect has finished querying the DOM. - const [dataLoaded, setDataLoaded] = useState(false); - - const handleTabToggle = (tabName: DebuggerTabs) => { - if (activeTab === tabName) { - setActiveTab(undefined); - } else { - setActiveTab(tabName); - } + // Track whether the Events, Scope, or no tab is opened. + const [activeTab, setActiveTab] = useState(); + // Track the event elements that need to have a tooltip added. + const [tooltips, setTooltips] = useState([]); + // Indicate when effect has finished querying the DOM. + const [dataLoaded, setDataLoaded] = useState(false); + + const handleTabToggle = (tabName: DebuggerTabs) => { + if (activeTab === tabName) { + setActiveTab(undefined); + } else { + setActiveTab(tabName); } - - useEffect(() => { - document.documentElement.classList.add('xYextDebug'); - - const scopes: NodeListOf = document.querySelectorAll('[data-ya-scope]'); - scopes.forEach(scope => { - const scopeName = scope.dataset.yaScope; - const events: NodeListOf = scope.querySelectorAll('[data-ya-track]'); - - events.forEach((eventEl, idx) => { - const eventName = eventEl.dataset.yaTrack; - - // Add tooltip when element is hovered. - eventEl.addEventListener('mouseenter', () => { - setTooltips([{ - eventEl, - eventName: `${scopeName}_${eventName}`, - key: `${scopeName}_${eventName}_${idx}`, - }]); - }); - - // Remove tooltip. - eventEl.addEventListener('mouseleave', () => { - setTooltips([]); - }); - }); - - if (scopeName) { - if (!data.hasOwnProperty(scopeName)) { - data[scopeName] = { - scope, - events: Array.from(events), - }; - } else { - data[scopeName].events = [...data[scopeName].events, ...Array.from(events)]; - } - } + }; + + useEffect(() => { + document.documentElement.classList.add("xYextDebug"); + + const scopes: NodeListOf = + document.querySelectorAll("[data-ya-scope]"); + scopes.forEach((scope) => { + const scopeName = scope.dataset.yaScope; + const events: NodeListOf = + scope.querySelectorAll("[data-ya-track]"); + + events.forEach((eventEl, idx) => { + const eventName = eventEl.dataset.yaTrack; + + // Add tooltip when element is hovered. + eventEl.addEventListener("mouseenter", () => { + setTooltips([ + { + eventEl, + eventName: `${scopeName}_${eventName}`, + key: `${scopeName}_${eventName}_${idx}`, + }, + ]); }); - setDataLoaded(true); - - return () => { - document.documentElement.classList.remove('xYextDebug'); + // Remove tooltip. + eventEl.addEventListener("mouseleave", () => { + setTooltips([]); + }); + }); + + if (scopeName) { + if (!data.hasOwnProperty(scopeName)) { + data[scopeName] = { + scope, + events: Array.from(events), + }; + } else { + data[scopeName].events = [ + ...data[scopeName].events, + ...Array.from(events), + ]; } - }, []); + } + }); - // Wait for all DOM nodes to be queried before rendering. - if (!dataLoaded) { - return null; - } + setDataLoaded(true); - return ( - <> -
-
- - -
- {activeTab && ( -
- {activeTab === "Events" - ? - : - } -
- )} -
- - - ); + return () => { + document.documentElement.classList.remove("xYextDebug"); + }; + }, []); + + // Wait for all DOM nodes to be queried before rendering. + if (!dataLoaded) { + return null; + } + + return ( + <> +
+
+ + +
+ {activeTab && ( +
+ {activeTab === "Events" ? ( + + ) : ( + + )} +
+ )} +
+ + + ); } function EventsTab(props: TabProps) { - const { - data, - setTooltips, - } = props; - - const [activeEventEl, setActiveEventEl] = useState(); - const [activeButton, setActiveButton] = useState(""); - - const handleClick = (eventEl: HTMLElement, eventName: string, key: string) => { - eventEl.scrollIntoView({ behavior: "smooth", block: "nearest" }); - if (activeEventEl) { - activeEventEl.classList.remove('analytics-event-highlight') - } - - setActiveEventEl(eventEl); - eventEl.classList.add('analytics-event-highlight'); - - setActiveButton(key); - setTooltips([{ - eventEl, - eventName, - key, - }]); + const { data, setTooltips } = props; + + const [activeEventEl, setActiveEventEl] = useState(); + const [activeButton, setActiveButton] = useState(""); + + const handleClick = ( + eventEl: HTMLElement, + eventName: string, + key: string + ) => { + eventEl.scrollIntoView({ behavior: "smooth", block: "nearest" }); + if (activeEventEl) { + activeEventEl.classList.remove("analytics-event-highlight"); } - return ( -
-

Event Names

-
    - {Object.entries(data).map(([scopeName, value]) => value.events.map((eventEl, idx) => { - const eventName = `${scopeName}_${eventEl.dataset.yaTrack}`; - const key = `${eventName}_${idx}`; - - return ( -
  • - -
  • - ); - }))} -
-
- ); + setActiveEventEl(eventEl); + eventEl.classList.add("analytics-event-highlight"); + + setActiveButton(key); + setTooltips([ + { + eventEl, + eventName, + key, + }, + ]); + }; + + return ( +
+

Event Names

+
    + {Object.entries(data).map(([scopeName, value]) => + value.events.map((eventEl, idx) => { + const eventName = `${scopeName}_${eventEl.dataset.yaTrack}`; + const key = `${eventName}_${idx}`; + + return ( +
  • + +
  • + ); + }) + )} +
+
+ ); } function ScopesTab(props: TabProps) { - const { - data, - setTooltips, - } = props; + const { data, setTooltips } = props; - const [activeButton, setActiveButton] = useState(""); + const [activeButton, setActiveButton] = useState(""); - const handleClick = (scopeName: string) => { - const node = data[scopeName]; - node.scope.scrollIntoView({ behavior: "smooth", block: "nearest" }); + const handleClick = (scopeName: string) => { + const node = data[scopeName]; + node.scope.scrollIntoView({ behavior: "smooth", block: "nearest" }); - setActiveButton(scopeName); - - setTooltips(node.events.map((eventEl, idx) => ({ - eventEl, - eventName: `${scopeName}_${eventEl.dataset.yaTrack}`, - key: `${scopeName}_${eventEl.dataset.yaTrack}_${idx}`, - }))); - } + setActiveButton(scopeName); - return ( -
-

Scope Names

-
    - {Object.keys(data).map((scopeName, idx) => ( -
  • - -
  • - ))} -
-
+ setTooltips( + node.events.map((eventEl, idx) => ({ + eventEl, + eventName: `${scopeName}_${eventEl.dataset.yaTrack}`, + key: `${scopeName}_${eventEl.dataset.yaTrack}_${idx}`, + })) ); + }; + + return ( +
+

Scope Names

+
    + {Object.keys(data).map((scopeName, idx) => ( +
  • + +
  • + ))} +
+
+ ); } function TooltipHandler(props: TooltipHandlerProps) { - const tooltipRefs = useRef>({}); + const tooltipRefs = useRef>({}); - useEffect(() => { - if (!tooltipRefs.current) return; - - for (const item of Object.values(tooltipRefs.current)) { - const otherTooltips = Object.values(tooltipRefs.current).map(val => val.el).filter(el => el !== item.el); - setTooltipPosition(item, otherTooltips); - item.el.style.visibility = "visible"; - } - }, [props.tooltips]); + useEffect(() => { + if (!tooltipRefs.current) return; - return ( - <> - {props.tooltips.map((tooltip) => ( -
{ - if (el) { - tooltipRefs.current[tooltip.key] = { - el, - tooltip, - } - } else { - delete tooltipRefs.current[tooltip.key]; - } - }} - > - {tooltip.eventName} -
- ))} - - ); + for (const item of Object.values(tooltipRefs.current)) { + const otherTooltips = Object.values(tooltipRefs.current) + .map((val) => val.el) + .filter((el) => el !== item.el); + setTooltipPosition(item, otherTooltips); + item.el.style.visibility = "visible"; + } + }, [props.tooltips]); + + return ( + <> + {props.tooltips.map((tooltip) => ( +
{ + if (el) { + tooltipRefs.current[tooltip.key] = { + el, + tooltip, + }; + } else { + delete tooltipRefs.current[tooltip.key]; + } + }} + > + {tooltip.eventName} +
+ ))} + + ); } // Find tooltip position that is in the window bounds and doesn't overlap with other tooltips. -function setTooltipPosition(item: TooltipsRefItem, instances: HTMLDivElement[]) { - for (let i = 0; i < 9; i++) { - // Get base position and position the tooltip. - const position = positionFinder(item.tooltip.eventEl.getBoundingClientRect(), item.el, i); - item.el.style.inset = `${position.top} auto auto ${position.left}`; - - // Check if tooltip is in the window bounds. - const withinBounds = !inWindowBounds( - item.el.getBoundingClientRect().left, - item.el.getBoundingClientRect().top + window.scrollY, - item.el.getBoundingClientRect().right, - item.el.getBoundingClientRect().bottom + window.scrollY, - ); - if (!withinBounds) continue; - - // Check if tooltip overlaps with others. - let valid = true; - for (let j = 0; j < instances.length - 1; j++) { - const neighbor = instances[j]; - if (isOverlapping(item.el, neighbor)) { - valid = false; - } - } - if (valid) break; +function setTooltipPosition( + item: TooltipsRefItem, + instances: HTMLDivElement[] +) { + for (let i = 0; i < 9; i++) { + // Get base position and position the tooltip. + const position = positionFinder( + item.tooltip.eventEl.getBoundingClientRect(), + item.el, + i + ); + item.el.style.inset = `${position.top} auto auto ${position.left}`; + + // Check if tooltip is in the window bounds. + const withinBounds = !inWindowBounds( + item.el.getBoundingClientRect().left, + item.el.getBoundingClientRect().top + window.scrollY, + item.el.getBoundingClientRect().right, + item.el.getBoundingClientRect().bottom + window.scrollY + ); + if (!withinBounds) continue; + + // Check if tooltip overlaps with others. + let valid = true; + for (let j = 0; j < instances.length - 1; j++) { + const neighbor = instances[j]; + if (isOverlapping(item.el, neighbor)) { + valid = false; + } } + if (valid) break; + } } // Check if two tooltips are overlapping with each other. -function isOverlapping(tooltip: HTMLDivElement, futureNeighbor: HTMLDivElement): boolean { - const y1 = tooltip.getBoundingClientRect().top + window.scrollY; - const x1 = tooltip.getBoundingClientRect().left; - const y2 = y1 + tooltip.clientHeight; - const x2 = x1 + tooltip.clientWidth; - - const b1 = futureNeighbor.getBoundingClientRect().top + window.scrollY; - const a1 = futureNeighbor.getBoundingClientRect().left; - const b2 = b1 + futureNeighbor.clientHeight; - const a2 = a1 + futureNeighbor.clientWidth; - - const check = ( - x1: number, - y1: number, - a1: number, - b1: number, - x2: number, - y2: number, - a2: number, - b2: number - ) => { - return (a1 <= x2 && x2 <= a2 && b1 <= y2 && y2 <= b2) || - (a1 <= x1 && x1 <= a2 && b1 <= y1 && y1 <= b2) || - (a1 <= x1 && x1 <= a2 && b1 <= y2 && y2 <= b2) || - (a1 <= x2 && x2 <= a2 && b1 <= y1 && y1 <= b2); - }; +function isOverlapping( + tooltip: HTMLDivElement, + futureNeighbor: HTMLDivElement +): boolean { + const y1 = tooltip.getBoundingClientRect().top + window.scrollY; + const x1 = tooltip.getBoundingClientRect().left; + const y2 = y1 + tooltip.clientHeight; + const x2 = x1 + tooltip.clientWidth; + + const b1 = futureNeighbor.getBoundingClientRect().top + window.scrollY; + const a1 = futureNeighbor.getBoundingClientRect().left; + const b2 = b1 + futureNeighbor.clientHeight; + const a2 = a1 + futureNeighbor.clientWidth; + + const check = ( + x1: number, + y1: number, + a1: number, + b1: number, + x2: number, + y2: number, + a2: number, + b2: number + ) => { + return ( + (a1 <= x2 && x2 <= a2 && b1 <= y2 && y2 <= b2) || + (a1 <= x1 && x1 <= a2 && b1 <= y1 && y1 <= b2) || + (a1 <= x1 && x1 <= a2 && b1 <= y2 && y2 <= b2) || + (a1 <= x2 && x2 <= a2 && b1 <= y1 && y1 <= b2) + ); + }; - return check(x1, y1, a1, b1, x2, y2, a2, b2) || check(a1, b1, x1, y1, a2, b2, x2, y2); + return ( + check(x1, y1, a1, b1, x2, y2, a2, b2) || + check(a1, b1, x1, y1, a2, b2, x2, y2) + ); } // Check if a tooltip is within the window bounds. function inWindowBounds(x1: number, y1: number, x2: number, y2: number) { - return (x1 < 0 || x2 > window.innerWidth) || - (y1 < 0 || y2 > document.documentElement.scrollHeight); -}; + return ( + x1 < 0 || + x2 > window.innerWidth || + y1 < 0 || + y2 > document.documentElement.scrollHeight + ); +} // Possible positions for a given tooltip around it's target element. -function positionFinder (rect: DOMRect, tooltip: HTMLDivElement, index: number) { - const tooltipHeight = tooltip.clientHeight; - const tooltipWidth = tooltip.clientWidth; - - let left; - let top; - switch (index) { - // case 'top-left' - case 0: { - top = (window.scrollY + rect.top - tooltipHeight) + 'px'; - left = (rect.left - tooltipWidth) + 'px'; - break; - } - // case 'top-inner-left' - case 1: { - top = (window.scrollY + rect.top - tooltipHeight) + 'px'; - left = rect.left + 'px'; - break; - } - // case 'top-right' - case 2: { - top = (window.scrollY + rect.top - tooltipHeight) + 'px'; - left = rect.right + 'px'; - break; - } - // case 'top-inner-right' - case 3: { - top = (window.scrollY + rect.top - tooltipHeight) + 'px'; - left = (rect.right - tooltipWidth) + 'px'; - break; - } - // case 'bottom-left' - case 4: { - top = (window.scrollY + rect.bottom) + 'px'; - left = (rect.left - tooltipWidth) + 'px'; - break; - } - // case 'bottom-inner-left' - case 5: { - top = (window.scrollY + rect.bottom) + 'px'; - left = rect.left + 'px'; - break; - } - // case 'bottom-inner-right' - case 6: { - top = (window.scrollY + rect.bottom) + 'px'; - left = (rect.right - tooltipWidth) + 'px'; - break; - } - // case 'bottom-right' - case 7: { - top = (window.scrollY + rect.bottom) + 'px'; - left = rect.right + 'px'; - break; - } - default: { - top = 0; - left = 0; - } +function positionFinder(rect: DOMRect, tooltip: HTMLDivElement, index: number) { + const tooltipHeight = tooltip.clientHeight; + const tooltipWidth = tooltip.clientWidth; + + let left; + let top; + switch (index) { + // case 'top-left' + case 0: { + top = window.scrollY + rect.top - tooltipHeight + "px"; + left = rect.left - tooltipWidth + "px"; + break; + } + // case 'top-inner-left' + case 1: { + top = window.scrollY + rect.top - tooltipHeight + "px"; + left = rect.left + "px"; + break; + } + // case 'top-right' + case 2: { + top = window.scrollY + rect.top - tooltipHeight + "px"; + left = rect.right + "px"; + break; } + // case 'top-inner-right' + case 3: { + top = window.scrollY + rect.top - tooltipHeight + "px"; + left = rect.right - tooltipWidth + "px"; + break; + } + // case 'bottom-left' + case 4: { + top = window.scrollY + rect.bottom + "px"; + left = rect.left - tooltipWidth + "px"; + break; + } + // case 'bottom-inner-left' + case 5: { + top = window.scrollY + rect.bottom + "px"; + left = rect.left + "px"; + break; + } + // case 'bottom-inner-right' + case 6: { + top = window.scrollY + rect.bottom + "px"; + left = rect.right - tooltipWidth + "px"; + break; + } + // case 'bottom-right' + case 7: { + top = window.scrollY + rect.bottom + "px"; + left = rect.right + "px"; + break; + } + default: { + top = 0; + left = 0; + } + } - return { - top: top, - left: left - }; + return { + top: top, + left: left, + }; } diff --git a/packages/sites-components/src/components/analytics/interfaces.ts b/packages/sites-components/src/components/analytics/interfaces.ts index 6a37e063..a2d9406f 100644 --- a/packages/sites-components/src/components/analytics/interfaces.ts +++ b/packages/sites-components/src/components/analytics/interfaces.ts @@ -52,8 +52,8 @@ export interface AnalyticsMethods { enableTrackingCookie(): void; /** - * Use the getDebugEnabled method retrieve whether debugging is on or off. - */ + * Use the getDebugEnabled method retrieve whether debugging is on or off. + */ getDebugEnabled(): boolean; /** diff --git a/packages/sites-components/src/components/analytics/provider.tsx b/packages/sites-components/src/components/analytics/provider.tsx index 40f6b122..b37daf43 100644 --- a/packages/sites-components/src/components/analytics/provider.tsx +++ b/packages/sites-components/src/components/analytics/provider.tsx @@ -53,10 +53,10 @@ export function AnalyticsProvider( return ( <> - - {children} - - {(enableDebugging ?? enableDebuggingDefault) ? : null} + + {children} + + {enableDebugging ?? enableDebuggingDefault ? : null} ); } diff --git a/packages/sites-components/src/components/analytics/types.ts b/packages/sites-components/src/components/analytics/types.ts index cc8f1b2f..1d4da9da 100644 --- a/packages/sites-components/src/components/analytics/types.ts +++ b/packages/sites-components/src/components/analytics/types.ts @@ -12,9 +12,9 @@ export interface TemplateProps> { export type EventNode = { scope: HTMLElement; events: HTMLElement[]; -} +}; -export type EventData = Record; +export type EventData = Record; export type DebuggerTabs = "Events" | "Scopes"; @@ -22,22 +22,22 @@ export type Tooltip = { eventEl: HTMLElement; eventName: string; key: string; -} +}; export type TabProps = { data: EventData; setTooltips: React.Dispatch>; -} +}; export type TooltipHandlerProps = { tooltips: Tooltip[]; -} +}; export type TooltipProps = { tooltip: Tooltip; -} +}; export type TooltipsRefItem = { el: HTMLDivElement; tooltip: Tooltip; -} +};