opencode/packages/data/app/src/lib/chart-tooltip.ts
Dax Raad 070b980c0b refactor(data): strict dev/production stages and data naming
- services/data/stage.ts: stage(mode) throws on anything but dev or production, used by all three configs, build.ts and deploy.ts
- packages/stats -> packages/data (@opencode/data-app, -core, -server)
- StatsSyncWorkflow -> DataSyncWorkflow, instance ids data-hourly-/data-history-, Data* resource keys, data sync log lines
- worker, route, workflow and cron names unchanged
2026-11-11 02:35:05 -05:00

30 lines
1.2 KiB
TypeScript

import { createEffect, onCleanup } from "solid-js"
/**
* While a chart tooltip is open, close it when a pointer goes down outside the chart or the chart scrolls fully
* out of view. Chart pointerleave handlers ignore touch so a tap keeps its tooltip, and on narrow screens the
* tooltip is a fixed bottom sheet, so without this a tapped tooltip stays pinned over the rest of the page.
*/
export function dismissChartTooltipOnExit(input: {
chart: () => HTMLElement | undefined
open: () => boolean
dismiss: () => void
}) {
createEffect(() => {
const chart = input.chart()
if (!chart || !input.open()) return
const dismissOutsidePointer = (event: PointerEvent) => {
if (event.target instanceof Node && chart.contains(event.target)) return
input.dismiss()
}
const observer = new IntersectionObserver((entries) => {
if (entries.some((entry) => !entry.isIntersecting)) input.dismiss()
})
document.addEventListener("pointerdown", dismissOutsidePointer, true)
observer.observe(chart)
onCleanup(() => {
document.removeEventListener("pointerdown", dismissOutsidePointer, true)
observer.disconnect()
})
})
}