MCPcopy Create free account
hub / github.com/agent-tower/core / updatePosition

Function updatePosition

packages/web/src/components/task/SlashCommandPopover.tsx:61–94  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

59 let frameId = 0
60
61 const updatePosition = () => {
62 const anchorElement = anchorRef.current
63 if (!anchorElement) return
64
65 const rect = anchorElement.getBoundingClientRect()
66 const viewportWidth = window.innerWidth
67 const viewportHeight = window.innerHeight
68 const minWidth = compact ? 260 : 320
69 const maxWidth = compact ? viewportWidth - VIEWPORT_MARGIN * 2 : 560
70 const width = Math.min(
71 Math.max(rect.width, minWidth),
72 Math.max(minWidth, maxWidth)
73 )
74 const left = Math.min(
75 Math.max(VIEWPORT_MARGIN, rect.left),
76 Math.max(VIEWPORT_MARGIN, viewportWidth - VIEWPORT_MARGIN - width)
77 )
78
79 const roomBelow = viewportHeight - rect.bottom - ANCHOR_GAP - VIEWPORT_MARGIN
80 const roomAbove = rect.top - ANCHOR_GAP - VIEWPORT_MARGIN
81 const panelHeight = panelRef.current?.offsetHeight ?? (compact ? 220 : 280)
82 const preferredMaxHeight = compact ? 240 : 320
83 const shouldPlaceAbove = roomBelow < 180 && roomAbove > roomBelow
84 const availableHeight = shouldPlaceAbove ? roomAbove : roomBelow
85 const maxHeight = Math.max(120, Math.min(preferredMaxHeight, availableHeight))
86 const top = shouldPlaceAbove
87 ? Math.max(VIEWPORT_MARGIN, rect.top - ANCHOR_GAP - Math.min(panelHeight, maxHeight))
88 : Math.min(
89 viewportHeight - VIEWPORT_MARGIN - Math.min(panelHeight, maxHeight),
90 rect.bottom + ANCHOR_GAP
91 )
92
93 setPosition({ top, left, width, maxHeight })
94 }
95
96 const scheduleUpdate = () => {
97 cancelAnimationFrame(frameId)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected