diff --git a/src/components/MaintainersMap.tsx b/src/components/MaintainersMap.tsx index 687be2351..933543bfa 100644 --- a/src/components/MaintainersMap.tsx +++ b/src/components/MaintainersMap.tsx @@ -6,7 +6,9 @@ import { useMemo, useRef, useState, + type ComponentProps, } from 'react' +import { Popover } from '@base-ui/react/popover' import { ClientOnly } from '@tanstack/react-router' import { useSuspenseQuery } from '@tanstack/react-query' import { geoDistance, select, zoom, zoomIdentity, type D3ZoomEvent } from 'd3' @@ -63,14 +65,13 @@ type ProfileViewport = { bottom: number contentTop: number contentBottom: number - helpTop: number - helpBottom: number } type ProfileSize = { width: number; height: number } type ProfileSizes = { portraits: ProfileSize; count: ProfileSize } type OffscreenEdge = 'top' | 'bottom' type MarkerVector = [x: number, y: number, z: number] +type ProfileSelection = { groupId: string; trigger: HTMLButtonElement } function markerVector(latitude: number, longitude: number): MarkerVector { const lat = (latitude * Math.PI) / 180 @@ -234,12 +235,6 @@ function placeProfiles( top: bounds.height - zoomControls.height, bottom: bounds.height, }, - { - left: bounds.contentInset, - right: contentRight, - top: viewport.helpTop, - bottom: viewport.helpBottom, - }, ] const labels = nodes.flatMap( ({ id, card, line, pin, sizes, pendingImages }) => { @@ -641,10 +636,6 @@ type MaintainersMapProps = { maintainers: Maintainer[] } -function Key({ children }: { children: React.ReactNode }) { - return {children} -} - function GlobeAvatar({ member, color, @@ -690,13 +681,15 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { const [reducedMotion, setReducedMotion] = useState(false) const [scale, setScale] = useState(initialView.scale) const [maxZoom, setMaxZoom] = useState(desktopMaxZoom) - const [selectedId, setSelectedId] = useState('') + const [selection, setSelection] = useState(null) const [paused, setPaused] = useState(false) const [behavior] = useState(() => zoom()) const [profilePositions] = useState( (): Map => new Map(), ) const profileNodes = useRef>(undefined) + const openProfileTrigger = useRef(null) + const profilePopupId = `${prefix}-nearby-maintainers` const [startingView] = useState(() => initialMaintainersView(initialLocation)) const view = useRef({ ...startingView }) const target = useRef({ ...startingView }) @@ -765,9 +758,14 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { } return result }, [maintainers, prefix, scale]) - const selected = groups.find((group) => group.id === selectedId) // Read by the frame loop, so zooming doesn't restart it. const groupsRef = useRef(groups) + const selected = groups.find((group) => group.id === selection?.groupId) + + useLayoutEffect(() => { + openProfileTrigger.current = selection?.trigger ?? null + wakeGlobe.current?.() + }, [selection]) useLayoutEffect(() => { if (!host || !surface) return @@ -858,7 +856,6 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { const container = host const instance = globe const section = container.closest('section') - const help = section?.querySelector('#maintainers-globe-help') const intro = section?.parentElement?.querySelector(':scope > header') const navbarHeight = Number.parseFloat( @@ -882,14 +879,10 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { const { top, height } = container.getBoundingClientRect() const contentTop = (intro?.getBoundingClientRect().bottom ?? top) - top + viewportGutter - const helpBounds = help?.getBoundingClientRect() // Keep floating profiles clear of the next section. - const nextContent = - help?.nextElementSibling ?? section?.nextElementSibling + const nextContent = section?.nextElementSibling const contentBottom = - (nextContent?.getBoundingClientRect().top ?? - helpBounds?.bottom ?? - top + height) - + (nextContent?.getBoundingClientRect().top ?? top + height) - top - viewportGutter const screenTop = visualViewport?.offsetTop ?? 0 @@ -900,8 +893,6 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { bottom: screenTop + screenHeight - viewportGutter - top, contentTop, contentBottom, - helpTop: (helpBounds?.top ?? 0) - top, - helpBottom: (helpBounds?.bottom ?? 0) - top, } viewportChanged = true requestFrame() @@ -970,9 +961,15 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { const readingProfile = container.querySelector( '[data-globe-profile]:hover, [data-globe-profile]:focus-within', ) - const idle = !readingProfile && !interacting.current + const idle = + !readingProfile && + !openProfileTrigger.current && + !interacting.current const autoRotate = - globeVisible && !reducedMotion && !pausedRef.current + globeVisible && + !reducedMotion && + !pausedRef.current && + !openProfileTrigger.current if (autoRotate && idle) { target.current.phi += Math.min(elapsed, 100) * 0.00015 } @@ -1014,6 +1011,18 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { viewport, globeVisible, ) || !profileNodes.current + const trigger = openProfileTrigger.current + if (trigger) { + const profile = trigger.closest('[data-globe-profile]') + if ( + !trigger.isConnected || + profile?.getAttribute('data-shown') !== 'true' || + profile.hasAttribute('data-offscreen') !== + trigger.hasAttribute('data-globe-count') + ) { + setSelection(null) + } + } viewportChanged = false } wasIdle = idle @@ -1100,18 +1109,25 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { } }, [host, behavior, invalidate, pauseRotation]) - function focus(group: MaintainerGroup) { - pauseRotation() - const phi = (-group.location[1] * Math.PI) / 180 - Math.PI / 2 - target.current.phi = - view.current.phi + - Math.atan2( - Math.sin(phi - view.current.phi), - Math.cos(phi - view.current.phi), - ) - target.current.theta = (group.location[0] * Math.PI) / 180 - setSelectedId(group.id) - invalidate() + function profileTriggerProps( + groupId: string, + suffix: string, + ): ComponentProps<'button'> { + const id = `${groupId}-${suffix}` + const expanded = selection?.trigger.id === id + return { + id, + type: 'button', + 'aria-haspopup': 'dialog', + 'aria-expanded': expanded, + 'aria-controls': expanded ? profilePopupId : undefined, + onClick(event) { + const trigger = event.currentTarget + setSelection((current) => + current?.trigger === trigger ? null : { groupId, trigger }, + ) + }, + } } // The composite globe needs a focus target for its keyboard rotation controls. @@ -1136,10 +1152,6 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { aria-describedby="maintainers-globe-help" tabIndex={0} onKeyDown={(event) => { - if (event.key === 'Escape') { - setSelectedId('') - return - } if (event.target !== event.currentTarget || !event.shiftKey) return const directions: Record = { ArrowLeft: [-0.15, 0], @@ -1218,11 +1230,12 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { >
{group.members.map((member) => (
{member.name}
@@ -1233,10 +1246,11 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { } >
-

{ + if (open) return + if ( + details.reason === 'outside-press' && + details.event.target instanceof Element && + details.event.target.closest('[data-globe-profile] button') + ) { + details.cancel() + return + } + setSelection(null) + }} > - - Select to see nearby maintainers, Esc to close. - - - Tap a profile to see nearby maintainers. - -

- {selected && ( -
-
-
-

- {`${selected.members.length} maintainer${selected.members.length === 1 ? '' : 's'} nearby`} -

-

- Select a profile to open their GitHub. -

-
- -
-
- {selected.members.map((member) => ( - - - - - - )} +
+ {selected.members.map((member) => ( + + + + +
+
+ {member.name} +
+
+ {member.location?.name} +
+
+
+ ))} +
+ + + + )} + {!groups.length && (

No shared locations for the selected maintainers and contributors. diff --git a/src/components/home/HomeCommunitySection.tsx b/src/components/home/HomeCommunitySection.tsx index f482b8e1a..d25954002 100644 --- a/src/components/home/HomeCommunitySection.tsx +++ b/src/components/home/HomeCommunitySection.tsx @@ -12,13 +12,7 @@ const MaintainersMap = lazy(() => })), ) -// Reserve the map, its help text line, and the gap between them. -const globeFallback = ( -