import { css, cx } from "../../styled-system/css"; import { grabCursorStyles } from "../grab-cursor-styles"; import type { Press } from "../handed-drag"; import type { Spot } from "../pointer-warp"; import type { Rect } from "../rect"; import { useGrabCursor } from "../useGrabCursor"; import { useHandedPress } from "../useHandedPress"; import { placedAt } from "../window-styles"; import type { Float } from "./float"; import { rectOf } from "./float"; import { useFloatDrag } from "./useFloatDrag"; type Props = { /** * A press a client handed over, to start the drag from as though it had * landed here. See `HandedDrag`. */ handed?: Press | undefined; /** The stacking depth of the window it covers. */ depth: number; float: Float; onDrop: () => void; onGrab: (resizing: boolean) => void; /** The pointer entered the overlay, at this page position. See `WindowFrame`. */ onHover: (at: Spot) => void; onMove: (x: number, y: number) => void; onPull: () => void; onResize: (box: Rect) => void; /** Whether a drag resizes the window instead of moving it. */ resizes: boolean; /** * The float's focused window, which is its only window unless it holds a * group. */ window: string; }; /** * An overlay that catches pointer drags on a floating window while the * modifier is held. * * The pointer over an `` goes to its client, so the shell makes the * window click-through (see `clickThroughStyles`) and catches the pointer * here instead. Mounted only while the modifier is held or a drag runs. * Covers the whole frame, so a drag behaves the same on the title bar. */ export const FloatGrab = ({ depth, float, handed, onHover, resizes, window, ...moves }: Props) => { const { drag, ...handlers } = useFloatDrag({ float, resizes, ...moves, }); const { cursor, onPointerMove } = useGrabCursor({ drag, frame: rectOf(float), resizes, }); const sheet = useHandedPress(handed, handlers.onPointerDown); return ( // Hidden from assistive tech: everything here is also available from the // keyboard.
`, so the window is named for the focus handling in // `AppWindow`. data-window={window} onPointerMove={onPointerMove} // The overlay covers the window, so focus follows the pointer from here. onPointerOver={(event) => { onHover([event.clientX, event.clientY]); }} ref={sheet} style={placedAt(rectOf(float), depth)} {...handlers} /> ); }; const grabStyles = css({ position: "absolute" });