import { css, cx } from "../styled-system/css"; import type { Float } from "./floating/float"; import { useFloatDrag } from "./floating/useFloatDrag"; import { grabCursorStyles } from "./grab-cursor-styles"; import type { Rect } from "./rect"; import type { Aim, DropTargets } from "./tiled/aim"; import { useTileDrag } from "./tiled/useTileDrag"; import type { StripGroup } from "./tree/frames"; import { GrabCursor } from "./useGrabCursor"; import { placedIn } from "./window-styles"; /** The primary button, as `PointerEvent.button` numbers it. */ const PRIMARY_BUTTON = 0; type Props = { /** The float holding the group, or `undefined` while it is tiled. */ float: Float | undefined; /** Whether the group fills the screen, which keeps it from being dragged. */ fullscreen: boolean; group: StripGroup; /** Where the dragged group would land if dropped now. */ onAim: (aim: Aim | undefined) => void; onDrop: () => void; /** A tiled group dropped where it was aimed. See `useTileDrag`. */ onDropOn: (aim: Aim) => void; onGrab: () => void; /** A float's new top-left corner. */ onMove: (x: number, y: number) => void; /** A move of the group was pulled. See `useTileDrag`. */ onPull: () => void; /** The empty end, from the strip's corner. See `StripPlace.end`. */ rect: Rect; /** What a tiled group can be dropped on, on every screen. */ targets: DropTargets; }; /** * The empty end of a tabbed strip, which drags the strip's whole group with * the primary button: a tiled group like a tiled window's bar, a float like * its bar. A fullscreen group does not drag, as a fullscreen window does not. * * Drawn in the strip, before the new-tab button over it. */ export const StripEnd = ({ float, fullscreen, group, onAim, onDrop, onDropOn, onGrab, onMove, onPull, rect, targets, }: Props) => { // Both hooks run for every end, since hooks cannot be conditional. const floatDrag = useFloatDrag({ float, onDrop, onGrab, onMove, onPull, onResize: doesNotResize, resizes: false, }); const tileDrag = useTileDrag({ dragged: group, frame: rect, onAim, onDrop, onDropOn, onGrab, onPull, onStretch: doesNotResize, resizes: false, targets, }); const drag = float === undefined ? tileDrag : floatDrag; return ( // `aria-hidden`: the keyboard offers everything this does.
`, so the window is named for // the focus handling in `AppWindow`. data-window={group.node.id} onPointerDown={(event) => { if (event.button === PRIMARY_BUTTON && !fullscreen) { drag.onPointerDown(event); } }} style={placedIn(rect)} /> ); }; const endStyles = css({ pointerEvents: "auto" }); /** Never called: the end only moves its group. */ const doesNotResize = () => { throw new Error("strip end: the end does not resize its group"); };