Files
dev/third_party/pi/packages/tui/src/components/mouse-region.ts
T
alexion 4def357d09 chore(vendor): import pi 0.85.1
Imported as a linear vendor commit so forge rebases do not replay the upstream root tree.

git-subtree-dir: third_party/pi

git-subtree-split: d981de1229ef899957bbe968bc8dcda02a21f477
2026-09-14 10:48:47 -04:00

34 lines
902 B
TypeScript

import {
type Component,
dispatchMouseEvent,
type TuiMouseDispatchResult,
type TuiMouseEvent,
type TuiMouseEventResult,
} from "../tui.ts";
export type MouseRegionHandler = (event: TuiMouseEvent) => TuiMouseEventResult | undefined;
/** Adds mouse handling to an existing component without changing its rendering. */
export class MouseRegion implements Component {
private readonly child: Component;
private readonly onMouse: MouseRegionHandler;
constructor(child: Component, onMouse: MouseRegionHandler) {
this.child = child;
this.onMouse = onMouse;
}
render(width: number): string[] {
return this.child.render(width);
}
handleMouse(event: TuiMouseEvent): TuiMouseDispatchResult | TuiMouseEventResult | undefined {
const childResult = dispatchMouseEvent(this.child, event);
return childResult ?? this.onMouse(event);
}
invalidate(): void {
this.child.invalidate();
}
}