Skip to content

Commit 14d4269

Browse files
fix(web): theme editor can still be dragged low enough to show only its header
Restore main's header-only vertical bound for dragging, and fit the panel to the viewport at render with the same bound, so the clamp no longer depends on a possibly stale measured height. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c20554a commit 14d4269

1 file changed

Lines changed: 14 additions & 31 deletions

File tree

‎apps/web/src/components/settings/ThemeEditorPanel.tsx‎

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,16 @@ const PANEL_MARGIN = 8;
276276
const PANEL_MIN_WIDTH = 280;
277277
const PANEL_MIN_HEIGHT = 220;
278278

279-
/** Keeps the panel inside the viewport, and its header reachable when it is taller. */
279+
/** Keeps the panel horizontally inside the viewport. Vertically only its header must stay
280+
* visible, so users can park the panel low to see the app behind it. */
280281
function clampPanelPosition(
281282
viewport: { readonly width: number; readonly height: number },
282283
x: number,
283284
y: number,
284-
panel: { readonly width: number; readonly height: number },
285+
width: number,
285286
) {
286-
const maxX = Math.max(PANEL_MARGIN, viewport.width - panel.width - PANEL_MARGIN);
287-
const maxY = Math.max(
288-
PANEL_MARGIN,
289-
Math.min(viewport.height - 48, viewport.height - panel.height - PANEL_MARGIN),
290-
);
287+
const maxX = Math.max(PANEL_MARGIN, viewport.width - width - PANEL_MARGIN);
288+
const maxY = Math.max(PANEL_MARGIN, viewport.height - 48);
291289
return {
292290
x: Math.min(Math.max(x, PANEL_MARGIN), maxX),
293291
y: Math.min(Math.max(y, PANEL_MARGIN), maxY),
@@ -351,22 +349,12 @@ export function ThemeEditorPanel({
351349
const [isInspecting, setIsInspecting] = useState(false);
352350
const [selectedRole, setSelectedRole] = useState<ThemeColorRole | null>(null);
353351
const [usageCount, setUsageCount] = useState<number | null>(null);
354-
// The rendered height is content-sized unless the user resized the panel, so the
355-
// position remembers the panel's measured box from the last drag or resize.
356-
const [position, setPosition] = useState<{
357-
x: number;
358-
y: number;
359-
width: number;
360-
height: number;
361-
} | null>(null);
352+
// The rendered width is CSS-sized unless the user resized the panel, so the position
353+
// remembers the width measured at the last drag or resize.
354+
const [position, setPosition] = useState<{ x: number; y: number; width: number } | null>(null);
362355
const [size, setSize] = useState<{ width: number; height: number } | null>(null);
363356
const panelRef = useRef<HTMLDivElement>(null);
364-
const dragOffsetRef = useRef<{
365-
dx: number;
366-
dy: number;
367-
width: number;
368-
height: number;
369-
} | null>(null);
357+
const dragOffsetRef = useRef<{ dx: number; dy: number; width: number } | null>(null);
370358
const resizeStartRef = useRef<{
371359
pointerX: number;
372360
pointerY: number;
@@ -1015,10 +1003,7 @@ export function ThemeEditorPanel({
10151003
};
10161004
const shownPosition =
10171005
position &&
1018-
clampPanelPosition(viewport, position.x, position.y, {
1019-
width: shownSize?.width ?? position.width,
1020-
height: isMinimized ? 0 : (shownSize?.height ?? position.height),
1021-
});
1006+
clampPanelPosition(viewport, position.x, position.y, shownSize?.width ?? position.width);
10221007

10231008
const handleDragPointerDown = (event: ReactPointerEvent<HTMLDivElement>) => {
10241009
if ((event.target as HTMLElement).closest("button, input, a")) return;
@@ -1028,22 +1013,20 @@ export function ThemeEditorPanel({
10281013
dx: event.clientX - rect.x,
10291014
dy: event.clientY - rect.y,
10301015
width: rect.width,
1031-
height: rect.height,
10321016
};
10331017
event.currentTarget.setPointerCapture(event.pointerId);
10341018
};
10351019

10361020
const handleDragPointerMove = (event: ReactPointerEvent<HTMLDivElement>) => {
10371021
const offset = dragOffsetRef.current;
10381022
if (!offset) return;
1039-
const box = { width: offset.width, height: isMinimized ? 0 : offset.height };
10401023
const next = clampPanelPosition(
10411024
readWindowViewport(),
10421025
event.clientX - offset.dx,
10431026
event.clientY - offset.dy,
1044-
box,
1027+
offset.width,
10451028
);
1046-
setPosition({ ...next, width: offset.width, height: offset.height });
1029+
setPosition({ ...next, width: offset.width });
10471030
};
10481031

10491032
const endDrag = () => {
@@ -1056,8 +1039,8 @@ export function ThemeEditorPanel({
10561039
event.preventDefault();
10571040
// Convert bottom-right parking to explicit position before resizing so the top-left corner stays fixed.
10581041
if (position === null) {
1059-
const box = { width: rect.width, height: rect.height };
1060-
setPosition({ ...clampPanelPosition(readWindowViewport(), rect.x, rect.y, box), ...box });
1042+
const next = clampPanelPosition(readWindowViewport(), rect.x, rect.y, rect.width);
1043+
setPosition({ ...next, width: rect.width });
10611044
}
10621045
resizeStartRef.current = {
10631046
pointerX: event.clientX,

0 commit comments

Comments
 (0)