Skip to content

Commit bdecb98

Browse files
committed
Allow event log modal offscreen dragging
1 parent 0a50b79 commit bdecb98

1 file changed

Lines changed: 19 additions & 25 deletions

File tree

web/src/components/EventLogModal.tsx

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,14 @@ export default function EventLogModal({ event, onClose }: Props) {
8080
const dx = e.clientX - interaction.startX;
8181
const dy = e.clientY - interaction.startY;
8282
if (interaction.kind === "drag") {
83-
setRect(
84-
constrainModalRect({
85-
...interaction.startRect,
86-
x: interaction.startRect.x + dx,
87-
y: interaction.startRect.y + dy,
88-
}),
89-
);
83+
setRect({
84+
...interaction.startRect,
85+
x: interaction.startRect.x + dx,
86+
y: interaction.startRect.y + dy,
87+
});
9088
} else {
9189
setRect(
92-
constrainModalRect({
90+
applyModalMinSize({
9391
...interaction.startRect,
9492
width: interaction.startRect.width + dx,
9593
height: interaction.startRect.height + dy,
@@ -101,17 +99,14 @@ export default function EventLogModal({ event, onClose }: Props) {
10199
interactionRef.current = null;
102100
endPointerInteraction();
103101
};
104-
const onResize = () => setRect((prev) => constrainModalRect(prev));
105102

106103
window.addEventListener("pointermove", onPointerMove);
107104
window.addEventListener("pointerup", onPointerUp);
108105
window.addEventListener("pointercancel", onPointerUp);
109-
window.addEventListener("resize", onResize);
110106
return () => {
111107
window.removeEventListener("pointermove", onPointerMove);
112108
window.removeEventListener("pointerup", onPointerUp);
113109
window.removeEventListener("pointercancel", onPointerUp);
114-
window.removeEventListener("resize", onResize);
115110
endPointerInteraction();
116111
};
117112
}, [endPointerInteraction]);
@@ -320,24 +315,23 @@ function initialModalRect(): ModalRect {
320315
};
321316
}
322317

323-
function constrainModalRect(rect: ModalRect): ModalRect {
324-
if (typeof window === "undefined") return rect;
325-
const maxWidth = Math.max(320, window.innerWidth - MODAL_PADDING * 2);
326-
const maxHeight = Math.max(240, window.innerHeight - MODAL_PADDING * 2);
327-
const minWidth = Math.min(MODAL_MIN_WIDTH, maxWidth);
328-
const minHeight = Math.min(MODAL_MIN_HEIGHT, maxHeight);
329-
const width = clamp(rect.width, minWidth, maxWidth);
330-
const height = clamp(rect.height, minHeight, maxHeight);
318+
function applyModalMinSize(rect: ModalRect): ModalRect {
319+
const { minWidth, minHeight } = modalMinSize();
331320
return {
332-
width,
333-
height,
334-
x: clamp(rect.x, MODAL_PADDING, Math.max(MODAL_PADDING, window.innerWidth - width - MODAL_PADDING)),
335-
y: clamp(rect.y, MODAL_PADDING, Math.max(MODAL_PADDING, window.innerHeight - height - MODAL_PADDING)),
321+
...rect,
322+
width: Math.max(rect.width, minWidth),
323+
height: Math.max(rect.height, minHeight),
336324
};
337325
}
338326

339-
function clamp(value: number, min: number, max: number): number {
340-
return Math.min(Math.max(value, min), max);
327+
function modalMinSize(): { minWidth: number; minHeight: number } {
328+
if (typeof window === "undefined") {
329+
return { minWidth: MODAL_MIN_WIDTH, minHeight: MODAL_MIN_HEIGHT };
330+
}
331+
return {
332+
minWidth: Math.min(MODAL_MIN_WIDTH, Math.max(320, window.innerWidth - MODAL_PADDING * 2)),
333+
minHeight: Math.min(MODAL_MIN_HEIGHT, Math.max(240, window.innerHeight - MODAL_PADDING * 2)),
334+
};
341335
}
342336

343337
function isInteractiveTarget(target: EventTarget): boolean {

0 commit comments

Comments
 (0)