519c411db0
* feat: sync and update with all changes from fork * refactor: extract clipboard copy logic into custom hook * fix: correct spelling of DEFAULT_REFRESH_FREQUENCY_MS in Stamps and WalletBalance providers * refactor(ui-tests): replace fixed sleeps with condition-based waits * fix: handle null values for size and granteeCount in infoGroups * fix(lint): add newline at end of file in useClipboardCopy hook * fix(ui-tests): page.goto URL * refactor: update import paths for useClipboardCopy --------- Co-authored-by: Ferenc Sárai <sarai.ferenc@gmail.com>
28 lines
792 B
TypeScript
28 lines
792 B
TypeScript
import { Dir, Point } from './common'
|
|
|
|
export function computeContextMenuPosition(args: {
|
|
clickPos: Point
|
|
menuRect: DOMRect
|
|
viewport: { w: number; h: number }
|
|
margin?: number
|
|
containerRect?: DOMRect | null
|
|
}): { safePos: Point; dropDir: Dir } {
|
|
const { clickPos: pos, menuRect: rect, viewport } = args
|
|
const margin = args.margin ?? 8
|
|
const left = Math.max(margin, Math.min(pos.x, viewport.w - rect.width - margin))
|
|
const vh = viewport.h
|
|
let top = pos.y
|
|
let dir: Dir = Dir.Down
|
|
|
|
const spaceBelow = vh - pos.y
|
|
|
|
if (spaceBelow < rect.height * 1.8) {
|
|
top = Math.max(margin, pos.y - rect.height - margin)
|
|
dir = Dir.Up
|
|
} else {
|
|
top = Math.max(margin, Math.min(pos.y, vh - rect.height - margin))
|
|
}
|
|
|
|
return { safePos: { x: left, y: top }, dropDir: dir }
|
|
}
|