mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-04 23:44:41 +00:00
* fix(usage): keep details hoverable and restore compact sidebar sheets Share hover-card mechanics with workspace details so context usage can stay open while users press Refresh. Honor Retry-After for rate-limited usage requests, and let both sidebar entry points share the compact sheet. * fix(usage): restore settings cog with a fitted popover and compact sheet Keep shared Usage preferences in the title controls on every surface. Settings rows use the menu surface directly, avoiding the trailing margin and duplicate card border from the page layout. * fix(app): show account usage before the first agent turn Keep the context meter available for existing agents without context readings so account usage can be opened before a turn. Show an empty ring and an explicit no-data state until readings arrive. * fix(usage): preserve keyboard access and hover card positioning Context details must remain reachable by keyboard after replacing the tooltip. Keep focus within the card, restore side flipping, and dismiss detached cards when the viewport moves. Prune expired cooldowns even after credential rotation. * chore: remove QA screenshots from the source tree * fix(app): let hover cards claim Escape before agent shortcuts Register hover surfaces with the shared overlay keyboard owner without moving or trapping focus on pointer hover. Component-local Escape handling ran after the global interrupt shortcut and cancelled the underlying turn. * fix(app): reopen focused hover cards with button keys Keep focused triggers registered with overlay arbitration after dismissal so activation keys are handled before composer shortcuts. * fix(app): release overlay ownership when hover cards close Closed triggers handle activation locally, so a dismissed card does not block pane Find. Open cards retain shared Escape arbitration to protect running turns. * test(app): pin Linux keyboard identity for composer Find * test(app): synchronize context usage hover journeys Return focus to the composer before asserting pointer dismissal, wait for the card to reach the viewport, and park the pointer before reloading so it cannot consume the next scripted usage response early.
177 lines
5.3 KiB
TypeScript
177 lines
5.3 KiB
TypeScript
import type { View } from "react-native";
|
|
|
|
/**
|
|
* Where a floating surface goes relative to the thing that opened it. Menus and hover cards
|
|
* place themselves with it.
|
|
*/
|
|
|
|
export type Placement = "top" | "bottom" | "left" | "right";
|
|
export type Alignment = "start" | "center" | "end";
|
|
|
|
export interface Rect {
|
|
x: number;
|
|
y: number;
|
|
width: number;
|
|
height: number;
|
|
}
|
|
|
|
export interface Size {
|
|
width: number;
|
|
height: number;
|
|
}
|
|
|
|
/** Gap kept between the surface and the edge of the display area. */
|
|
const EDGE_PADDING = 8;
|
|
|
|
export function measureElement(element: View): Promise<Rect> {
|
|
return new Promise((resolve) => {
|
|
element.measureInWindow((x, y, width, height) => {
|
|
resolve({ x, y, width, height });
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* A surface asked to open below the trigger flips above it when it doesn't fit below *and*
|
|
* there is more room above. Both conditions matter: flipping into a side that is equally
|
|
* cramped just moves the clipping, so a surface taller than the whole viewport stays put.
|
|
*
|
|
* Horizontal flipping is opt-in for hover cards. Submenus choose their direction up front so
|
|
* they do not move out from under the pointer travelling toward them.
|
|
*/
|
|
function flipPlacement(input: {
|
|
placement: Placement;
|
|
triggerRect: Rect;
|
|
contentHeight: number;
|
|
contentWidth: number;
|
|
flipHorizontal: boolean;
|
|
displayArea: Rect;
|
|
}): Placement {
|
|
const { placement, triggerRect, contentHeight, displayArea } = input;
|
|
const spaceTop = triggerRect.y - displayArea.y;
|
|
const spaceBottom = displayArea.y + displayArea.height - (triggerRect.y + triggerRect.height);
|
|
|
|
if (placement === "bottom" && spaceBottom < contentHeight && spaceTop > spaceBottom) {
|
|
return "top";
|
|
}
|
|
if (placement === "top" && spaceTop < contentHeight && spaceBottom > spaceTop) {
|
|
return "bottom";
|
|
}
|
|
if (input.flipHorizontal) {
|
|
const spaceLeft = triggerRect.x - displayArea.x;
|
|
const spaceRight = displayArea.x + displayArea.width - (triggerRect.x + triggerRect.width);
|
|
if (placement === "right" && spaceRight < input.contentWidth && spaceLeft > spaceRight)
|
|
return "left";
|
|
if (placement === "left" && spaceLeft < input.contentWidth && spaceRight > spaceLeft)
|
|
return "right";
|
|
}
|
|
return placement;
|
|
}
|
|
|
|
/** Where the surface's top-left corner lands, before it is pulled back inside the display area. */
|
|
function anchorToPlacement(input: {
|
|
placement: Placement;
|
|
triggerRect: Rect;
|
|
contentSize: Size;
|
|
alignment: Alignment;
|
|
offset: number;
|
|
}): { x: number; y: number } {
|
|
const { placement, triggerRect, contentSize, alignment, offset } = input;
|
|
|
|
if (placement === "left") {
|
|
return { x: triggerRect.x - contentSize.width - offset, y: triggerRect.y };
|
|
}
|
|
if (placement === "right") {
|
|
return { x: triggerRect.x + triggerRect.width + offset, y: triggerRect.y };
|
|
}
|
|
|
|
const y =
|
|
placement === "bottom"
|
|
? triggerRect.y + triggerRect.height + offset
|
|
: triggerRect.y - contentSize.height - offset;
|
|
|
|
// Vertical placements align horizontally against the trigger; side placements sit flush
|
|
// with its top edge and ignore alignment entirely.
|
|
if (alignment === "start") {
|
|
return { x: triggerRect.x, y };
|
|
}
|
|
if (alignment === "end") {
|
|
return { x: triggerRect.x + triggerRect.width - contentSize.width, y };
|
|
}
|
|
return { x: triggerRect.x + (triggerRect.width - contentSize.width) / 2, y };
|
|
}
|
|
|
|
function clampToDisplayArea(input: {
|
|
x: number;
|
|
y: number;
|
|
contentSize: Size;
|
|
displayArea: Rect;
|
|
}): { x: number; y: number } {
|
|
const { x, y, contentSize, displayArea } = input;
|
|
return {
|
|
x: Math.max(
|
|
displayArea.x + EDGE_PADDING,
|
|
Math.min(displayArea.x + displayArea.width - contentSize.width - EDGE_PADDING, x),
|
|
),
|
|
y: Math.max(
|
|
displayArea.y + EDGE_PADDING,
|
|
Math.min(displayArea.y + displayArea.height - contentSize.height - EDGE_PADDING, y),
|
|
),
|
|
};
|
|
}
|
|
|
|
export function computePosition({
|
|
triggerRect,
|
|
contentSize,
|
|
displayArea,
|
|
placement,
|
|
alignment,
|
|
offset,
|
|
flipHorizontal = false,
|
|
}: {
|
|
triggerRect: Rect;
|
|
contentSize: Size;
|
|
displayArea: Rect;
|
|
placement: Placement;
|
|
alignment: Alignment;
|
|
offset: number;
|
|
/** Hover cards can choose either side; submenu direction is owned by the menu. */
|
|
flipHorizontal?: boolean;
|
|
}): { x: number; y: number; actualPlacement: Placement } {
|
|
const actualPlacement = flipPlacement({
|
|
placement,
|
|
triggerRect,
|
|
contentHeight: contentSize.height,
|
|
contentWidth: contentSize.width,
|
|
flipHorizontal,
|
|
displayArea,
|
|
});
|
|
const anchored = anchorToPlacement({
|
|
placement: actualPlacement,
|
|
triggerRect,
|
|
contentSize,
|
|
alignment,
|
|
offset,
|
|
});
|
|
return { ...clampToDisplayArea({ ...anchored, contentSize, displayArea }), actualPlacement };
|
|
}
|
|
|
|
export function getTransformOrigin(
|
|
placement: Placement,
|
|
alignment: Alignment,
|
|
): [number | string, number | string, number] {
|
|
let vertical: number | string;
|
|
if (placement === "bottom") vertical = 0;
|
|
else if (placement === "top") vertical = "100%";
|
|
else vertical = "50%";
|
|
|
|
let horizontal: number | string;
|
|
if (alignment === "start") horizontal = 0;
|
|
else if (alignment === "end") horizontal = "100%";
|
|
else horizontal = "50%";
|
|
|
|
// Native theme updates can bypass RN's JS string preprocessing. Supply the native
|
|
// array shape directly; Reanimated's web style builder also accepts this form.
|
|
return [horizontal, vertical, 0];
|
|
}
|