fix(webui): adapt chat toolbar to available width (#5760)
* fix(webui): float chat controls above the transcript * fix(webui): keep floating controls compact and flat * fix(webui): adapt toolbar placement to conversation width * refactor(webui): simplify responsive toolbar styles
This commit is contained in:
1 parent
95b2346ea5
commit
f611c880f9
6 files changed
+67
-24
No files matched your search
@@ -13,6 +13,12 @@ import {
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import type { SessionHandle } from "@/lib/types";
|
import type { SessionHandle } from "@/lib/types";
|
||||||
|
|
||||||
|
const controlsClassName = cn(
|
||||||
|
"pointer-events-auto flex items-center gap-0.5 rounded-compact bg-background p-px empty:hidden",
|
||||||
|
"[&_button]:h-7 [&_button]:w-7 [&_button>svg]:h-3.5 [&_button>svg]:w-3.5",
|
||||||
|
"forced-colors:bg-[Canvas] forced-colors:outline forced-colors:outline-1 forced-colors:outline-[ButtonText]",
|
||||||
|
);
|
||||||
|
|
||||||
interface ThreadHeaderProps {
|
interface ThreadHeaderProps {
|
||||||
title: string;
|
title: string;
|
||||||
handle?: SessionHandle | null;
|
handle?: SessionHandle | null;
|
||||||
@@ -56,11 +62,18 @@ export function ThreadHeader({
|
|||||||
<div
|
<div
|
||||||
data-testid="thread-header"
|
data-testid="thread-header"
|
||||||
className={cn(
|
className={cn(
|
||||||
"relative z-30 flex items-center justify-between gap-3 px-3 py-1",
|
"pointer-events-none inset-x-0 top-0 z-30 flex shrink-0 items-center justify-between gap-3 px-3 py-1",
|
||||||
|
"[position:var(--thread-header-position,absolute)]",
|
||||||
minimal && "h-11",
|
minimal && "h-11",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="relative flex min-w-0 items-center gap-2">
|
<div
|
||||||
|
className={cn(
|
||||||
|
controlsClassName,
|
||||||
|
"relative min-w-0",
|
||||||
|
hideSidebarToggleForHostChrome && (minimal || hideTitle) && !handle && "lg:hidden",
|
||||||
|
)}
|
||||||
|
>
|
||||||
{!hideSidebarToggle ? (
|
{!hideSidebarToggle ? (
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
@@ -91,7 +104,7 @@ export function ThreadHeader({
|
|||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="ml-auto flex shrink-0 items-center gap-1">
|
<div className={cn(controlsClassName, "ml-auto shrink-0")}>
|
||||||
{sessionInfoAction}
|
{sessionInfoAction}
|
||||||
{promptNavigatorAction}
|
{promptNavigatorAction}
|
||||||
{actions}
|
{actions}
|
||||||
@@ -151,10 +164,6 @@ export function ThreadHeader({
|
|||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!minimal ? (
|
|
||||||
<div aria-hidden className="pointer-events-none absolute inset-x-0 top-full h-4" />
|
|
||||||
) : null}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ import type {
|
|||||||
} from "@/lib/types";
|
} from "@/lib/types";
|
||||||
import { projectWebuiThreadMessages } from "@/lib/thread-display-compat";
|
import { projectWebuiThreadMessages } from "@/lib/thread-display-compat";
|
||||||
import { ThreadMessageCache } from "@/lib/thread-message-cache";
|
import { ThreadMessageCache } from "@/lib/thread-message-cache";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
import { useClient } from "@/providers/ClientProvider";
|
import { useClient } from "@/providers/ClientProvider";
|
||||||
|
|
||||||
type MessageShape = Pick<UIMessage, "role" | "kind" | "content" | "isStreaming" | "turnId">;
|
type MessageShape = Pick<UIMessage, "role" | "kind" | "content" | "isStreaming" | "turnId">;
|
||||||
@@ -1693,7 +1694,10 @@ export function ThreadShell({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<section ref={shellRef} className="relative flex min-h-0 flex-1 overflow-hidden">
|
<section ref={shellRef} className="relative flex min-h-0 flex-1 overflow-hidden">
|
||||||
<div className="relative flex min-w-0 flex-1 flex-col overflow-hidden">
|
<div className={cn(
|
||||||
|
"relative flex min-w-0 flex-1 flex-col overflow-hidden",
|
||||||
|
headerPortalTarget === undefined && !hideHeader && "thread-workspace",
|
||||||
|
)}>
|
||||||
{hideHeaderTitle && inlineHandle && !temporary && session?.handle ? (
|
{hideHeaderTitle && inlineHandle && !temporary && session?.handle ? (
|
||||||
<div
|
<div
|
||||||
aria-label={`Session @${session.handle.name}`}
|
aria-label={`Session @${session.handle.name}`}
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ interface ThreadViewportProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const NEAR_BOTTOM_PX = 48;
|
const NEAR_BOTTOM_PX = 48;
|
||||||
|
const PROMPT_TOP_INSET_PX = 48;
|
||||||
const HISTORY_PREFETCH_MIN_PX = 160;
|
const HISTORY_PREFETCH_MIN_PX = 160;
|
||||||
const HISTORY_PREFETCH_MAX_PX = 480;
|
const HISTORY_PREFETCH_MAX_PX = 480;
|
||||||
const DEFAULT_SCROLL_BUTTON_BOTTOM_PX = 192;
|
const DEFAULT_SCROLL_BUTTON_BOTTOM_PX = 192;
|
||||||
@@ -83,6 +84,11 @@ interface HistoryScrollAnchor {
|
|||||||
|
|
||||||
const THREAD_DISPLAY_UNIT_SELECTOR = "[data-thread-display-unit]";
|
const THREAD_DISPLAY_UNIT_SELECTOR = "[data-thread-display-unit]";
|
||||||
|
|
||||||
|
function promptTopInset(scroller: HTMLElement): number {
|
||||||
|
const padding = Number.parseFloat(getComputedStyle(scroller).paddingTop);
|
||||||
|
return Number.isFinite(padding) ? padding : PROMPT_TOP_INSET_PX;
|
||||||
|
}
|
||||||
|
|
||||||
function historyPrefetchDistance(scroller: HTMLElement): number {
|
function historyPrefetchDistance(scroller: HTMLElement): number {
|
||||||
return Math.min(
|
return Math.min(
|
||||||
HISTORY_PREFETCH_MAX_PX,
|
HISTORY_PREFETCH_MAX_PX,
|
||||||
@@ -297,7 +303,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
|||||||
promptTop: prompt
|
promptTop: prompt
|
||||||
? Math.min(
|
? Math.min(
|
||||||
maxScrollTop,
|
maxScrollTop,
|
||||||
Math.max(0, promptTop(scrollEl, prompt) - 16),
|
Math.max(0, promptTop(scrollEl, prompt) - promptTopInset(scrollEl)),
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
};
|
};
|
||||||
@@ -477,7 +483,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
|||||||
threadMotionRef.current?.navigateHistoryTo(
|
threadMotionRef.current?.navigateHistoryTo(
|
||||||
Math.min(
|
Math.min(
|
||||||
maxScrollTop,
|
maxScrollTop,
|
||||||
Math.max(0, promptTop(scrollEl, prompt) - 16),
|
Math.max(0, promptTop(scrollEl, prompt) - promptTopInset(scrollEl)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
@@ -871,7 +877,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
|||||||
data-testid="thread-message-region"
|
data-testid="thread-message-region"
|
||||||
className={cn(
|
className={cn(
|
||||||
"thread-message-viewport thread-viewport-scrollbar row-start-1 flex min-h-0 min-w-0 flex-col",
|
"thread-message-viewport thread-viewport-scrollbar row-start-1 flex min-h-0 min-w-0 flex-col",
|
||||||
"scroll-auto justify-start overflow-x-hidden px-3 pb-0 pt-3 sm:px-4",
|
"scroll-auto justify-start overflow-x-hidden px-3 pb-0 pt-[var(--thread-prompt-inset,3rem)] sm:px-4",
|
||||||
"[overflow-anchor:none] [scrollbar-width:none]",
|
"[overflow-anchor:none] [scrollbar-width:none]",
|
||||||
"[&::-webkit-scrollbar]:hidden",
|
"[&::-webkit-scrollbar]:hidden",
|
||||||
hasVerticalOverflow ? "overflow-y-auto" : "overflow-hidden",
|
hasVerticalOverflow ? "overflow-y-auto" : "overflow-hidden",
|
||||||
@@ -968,11 +974,6 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
|||||||
{!hasMessages ? <div ref={bottomRef} aria-hidden className="h-px" /> : null}
|
{!hasMessages ? <div ref={bottomRef} aria-hidden className="h-px" /> : null}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
|
||||||
aria-hidden
|
|
||||||
className="pointer-events-none absolute inset-x-0 top-0 h-3 bg-gradient-to-b from-background to-transparent"
|
|
||||||
/>
|
|
||||||
|
|
||||||
{hasMessages ? (
|
{hasMessages ? (
|
||||||
<PromptRail
|
<PromptRail
|
||||||
messages={visibleMessages}
|
messages={visibleMessages}
|
||||||
|
|||||||
@@ -685,11 +685,15 @@ export function PaneWorkbench({
|
|||||||
return (
|
return (
|
||||||
<section
|
<section
|
||||||
aria-label={t("workbench.aria", { defaultValue: "Conversation workbench" })}
|
aria-label={t("workbench.aria", { defaultValue: "Conversation workbench" })}
|
||||||
className="flex h-full min-h-0 flex-col overflow-hidden bg-background"
|
className={cn(
|
||||||
|
"thread-workspace relative flex h-full min-h-0 flex-col overflow-hidden bg-background",
|
||||||
|
chrome && displayedPanes.length > 1
|
||||||
|
&& "[--thread-header-position:relative] [--thread-prompt-inset:1rem]",
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
<TooltipProvider>
|
<TooltipProvider>
|
||||||
{chrome ? (
|
{chrome ? (
|
||||||
<header className="shrink-0 bg-background">
|
<header className="pointer-events-none inset-x-0 top-0 z-30 shrink-0 [position:var(--thread-header-position,absolute)]">
|
||||||
<div
|
<div
|
||||||
ref={setHeaderPortalTarget}
|
ref={setHeaderPortalTarget}
|
||||||
data-testid="workbench-header-host"
|
data-testid="workbench-header-host"
|
||||||
|
|||||||
@@ -604,6 +604,17 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.thread-workspace {
|
||||||
|
container: thread-workspace / inline-size;
|
||||||
|
}
|
||||||
|
/* Keep room for the 49.5rem message column and controls in the side margin. */
|
||||||
|
@container thread-workspace (max-width: 72rem) {
|
||||||
|
.thread-workspace > * {
|
||||||
|
--thread-header-position: relative;
|
||||||
|
--thread-prompt-inset: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.workbench-pane {
|
.workbench-pane {
|
||||||
transform-origin: top left;
|
transform-origin: top left;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -279,7 +279,6 @@ describe("ThreadViewport", () => {
|
|||||||
expect(messageRegion).toHaveClass("justify-start");
|
expect(messageRegion).toHaveClass("justify-start");
|
||||||
expect(messageRegion).not.toHaveClass("justify-end");
|
expect(messageRegion).not.toHaveClass("justify-end");
|
||||||
expect(messageRegion).toHaveClass("thread-message-viewport");
|
expect(messageRegion).toHaveClass("thread-message-viewport");
|
||||||
expect(messageRegion).toHaveClass("pt-3");
|
|
||||||
expect(messageRegion).toHaveClass("pb-0");
|
expect(messageRegion).toHaveClass("pb-0");
|
||||||
expect(messageRegion.className).not.toContain("5rem");
|
expect(messageRegion.className).not.toContain("5rem");
|
||||||
});
|
});
|
||||||
@@ -573,7 +572,7 @@ describe("ThreadViewport", () => {
|
|||||||
});
|
});
|
||||||
await flushAnimationFrame();
|
await flushAnimationFrame();
|
||||||
|
|
||||||
expect(jumpTo).toHaveBeenCalledWith(1404);
|
expect(jumpTo).toHaveBeenCalledWith(1372);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("drives the camera from a message commit when canonical replay replaces the prompt DOM id", async () => {
|
it("drives the camera from a message commit when canonical replay replaces the prompt DOM id", async () => {
|
||||||
@@ -1681,7 +1680,7 @@ describe("ThreadViewport", () => {
|
|||||||
|
|
||||||
fireEvent.click(targetPrompt);
|
fireEvent.click(targetPrompt);
|
||||||
|
|
||||||
expect(navigateTo).toHaveBeenCalledWith(1064);
|
expect(navigateTo).toHaveBeenCalledWith(1032);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders markdown in prompt rail previews", async () => {
|
it("renders markdown in prompt rail previews", async () => {
|
||||||
@@ -1855,14 +1854,29 @@ describe("ThreadViewport", () => {
|
|||||||
expect(markers).toHaveLength(count);
|
expect(markers).toHaveLength(count);
|
||||||
markers.forEach((marker, index) => {
|
markers.forEach((marker, index) => {
|
||||||
fireEvent.click(marker);
|
fireEvent.click(marker);
|
||||||
expect(navigateTo).toHaveBeenLastCalledWith(Math.max(0, index * 40 - 16));
|
expect(navigateTo).toHaveBeenLastCalledWith(Math.max(0, index * 40 - 48));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
expect(markers.length).toBeGreaterThan(1);
|
expect(markers.length).toBeGreaterThan(1);
|
||||||
expect(markers.length).toBeLessThan(count);
|
expect(markers.length).toBeLessThan(count);
|
||||||
}
|
}
|
||||||
fireEvent.click(markers[markers.length - 1]);
|
fireEvent.click(markers[markers.length - 1]);
|
||||||
expect(navigateTo).toHaveBeenLastCalledWith((count - 1) * 40 - 16);
|
expect(navigateTo).toHaveBeenLastCalledWith(Math.max(0, (count - 1) * 40 - 48));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps prompt jumps aligned when the header changes between a row and an overlay", async () => {
|
||||||
|
const navigateTo = vi.spyOn(ThreadCameraController.prototype, "navigateTo")
|
||||||
|
.mockReturnValue("started");
|
||||||
|
const { scroller } = await renderPromptRailViewport();
|
||||||
|
const marker = screen.getByRole("button", { name: "Jump to prompt: message 1" });
|
||||||
|
|
||||||
|
scroller.style.paddingTop = "16px";
|
||||||
|
fireEvent.click(marker);
|
||||||
|
expect(navigateTo).toHaveBeenLastCalledWith(344);
|
||||||
|
|
||||||
|
scroller.style.paddingTop = "48px";
|
||||||
|
fireEvent.click(marker);
|
||||||
|
expect(navigateTo).toHaveBeenLastCalledWith(312);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("buckets dense prompt rails without rendering every prompt as a marker", async () => {
|
it("buckets dense prompt rails without rendering every prompt as a marker", async () => {
|
||||||
@@ -1913,7 +1927,7 @@ describe("ThreadViewport", () => {
|
|||||||
|
|
||||||
fireEvent.click(promptMarkers[promptMarkers.length - 1]);
|
fireEvent.click(promptMarkers[promptMarkers.length - 1]);
|
||||||
|
|
||||||
expect(navigateTo).toHaveBeenCalledWith(8894);
|
expect(navigateTo).toHaveBeenCalledWith(8862);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("expands the window start to avoid cutting an agent activity cluster", () => {
|
it("expands the window start to avoid cutting an agent activity cluster", () => {
|
||||||
|
|||||||
Reference in new issue
Block a user