feat(web): proper number fields, orientation, and floating-preview toggle

Three follow-ups to the browser defaults:

The dimension inputs were bare `Input type=number` at w-16, which clipped
4-digit values ("1280" rendered as "128("). They are now `NumberField`, the
repo's real numeric control, widened to fit and with grouping switched off so
a height reads "1024" rather than "1,024".

They commit on blur via `onValueCommitted` instead of per keystroke. Typing
"2560" passes through "256", which is itself a legal dimension, so a
change-handler would persist that intermediate size and rewrite settings on
every key.

Adds an orientation control next to the dimensions, reusing the device
toolbar's rotate affordance — its icon moves to a shared module rather than
being duplicated. Rotating a preset keeps the preset: `resolvePreviewViewport`
already stores rotated presets as the id plus swapped dimensions, so a rotated
iPad Mini stays an iPad Mini instead of decaying into a custom size.

Adds `browserAutoShowFloatingPreview` (on by default) for whether an
agent-opened preview pops the floating player into view. An explicit
`open`/`show` on `preview_open` still wins: that is the agent deliberately
surfacing or hiding its work, which shouldn't be overridden by a default.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Opus 5 committed 2026-08-15 16:26:16 +02:00
1 parent de4c1ee1e1
commit 86975b87a7
9 files changed
+178 -83

No files matched your search

@@ -16,6 +16,7 @@ const clientSettings: ClientSettings = {
browserDefaultViewport: { _tag: "preset", width: 1024, height: 600, presetId: "nest-hub" },
browserDefaultZoomFactor: 1.25,
browserDefaultAppearance: "dark",
browserAutoShowFloatingPreview: false,
confirmQuit: true,
confirmThreadArchive: true,
confirmThreadDelete: false,
+1 -20
View File
@@ -25,6 +25,7 @@ import { cn } from "~/lib/utils";
import { BROWSER_DEVICE_TOOLBAR_HEIGHT, resizeFreeformViewport } from "./browserViewportLayout";
import { commitViewportAndAspectRatio } from "./browserDeviceToolbarState";
import { ScreenRotationIcon } from "./ScreenRotationIcon";
const RESPONSIVE_VALUE = "responsive";
const SELECT_ITEMS = [
@@ -32,26 +33,6 @@ const SELECT_ITEMS = [
...PREVIEW_VIEWPORT_PRESETS.map((preset) => ({ value: preset.id, label: preset.label })),
];
function ScreenRotationIcon() {
return (
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
>
<rect x="7.25" y="7.25" width="9.5" height="9.5" rx="1.4" transform="rotate(-45 12 12)" />
<path d="M12.5 2a10 10 0 0 1 8.4 5.4" />
<path d="M20.8 3.5v4h-4" />
<path d="M11.5 22a10 10 0 0 1-8.4-5.4" />
<path d="M3.2 20.5v-4h4" />
</svg>
);
}
interface Props {
readonly setting: Exclude<PreviewViewportSetting, { readonly _tag: "fill" }>;
readonly width: number;
@@ -0,0 +1,26 @@
/**
* Screen-rotation glyph shared by the in-browser device toolbar and the
* default-viewport setting, so the orientation control reads the same in both
* places.
*
* @module ScreenRotationIcon
*/
export function ScreenRotationIcon() {
return (
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
>
<rect x="7.25" y="7.25" width="9.5" height="9.5" rx="1.4" transform="rotate(-45 12 12)" />
<path d="M12.5 2a10 10 0 0 1 8.4 5.4" />
<path d="M20.8 3.5v4h-4" />
<path d="M11.5 22a10 10 0 0 1-8.4-5.4" />
<path d="M3.2 20.5v-4h4" />
</svg>
);
}
+3
View File
@@ -27,16 +27,19 @@ export interface BrowserDefaults {
readonly viewport: PreviewViewportSetting;
readonly zoomFactor: number;
readonly appearance: PreviewAppearancePreference;
readonly autoShowFloatingPreview: boolean;
}
const toBrowserDefaults = (settings: {
readonly browserDefaultViewport: PreviewViewportSetting;
readonly browserDefaultZoomFactor: number;
readonly browserDefaultAppearance: PreviewAppearancePreference;
readonly browserAutoShowFloatingPreview: boolean;
}): BrowserDefaults => ({
viewport: settings.browserDefaultViewport,
zoomFactor: settings.browserDefaultZoomFactor,
appearance: settings.browserDefaultAppearance,
autoShowFloatingPreview: settings.browserAutoShowFloatingPreview,
});
/** Non-hook accessor for imperative open paths (menu actions, automation hosts). */
@@ -38,7 +38,7 @@ import {
} from "~/browser/browserRecording";
import { resolveBrowserRecordingStopTarget } from "~/browser/browserRecordingScope";
import { useBrowserSurfaceStore } from "~/browser/browserSurfaceStore";
import { browserDefaultOpenViewport } from "~/browser/browserDefaults";
import { browserDefaultOpenViewport, getBrowserDefaults } from "~/browser/browserDefaults";
import { runBrowserViewportMutation } from "~/browser/browserViewportActions";
import { previewRuntimeTabId } from "~/browser/previewRuntimeTabId";
import { isElectron } from "~/env";
@@ -432,7 +432,10 @@ function PreviewAutomationHost(props: { readonly environmentId: EnvironmentId })
updatePreviewServerSnapshot(threadRef, resizeResult.value);
}
}
const shouldPresentPreview = shouldOpenPreviewMiniPlayer(input);
const shouldPresentPreview = shouldOpenPreviewMiniPlayer(
input,
getBrowserDefaults().autoShowFloatingPreview,
);
if (shouldPresentPreview) {
usePreviewMiniPlayerStore.getState().open(threadRef, activeTabId);
}
@@ -17,8 +17,16 @@ export const DEFAULT_PREVIEW_AUTOMATION_VIEWPORT = {
height: 800,
} as const satisfies PreviewViewportSetting;
export function shouldOpenPreviewMiniPlayer(input: PreviewAutomationOpenInput): boolean {
return input.open ?? input.show ?? true;
/**
* An explicit `open`/`show` is the agent deliberately surfacing or suppressing
* its work, so it outranks the preference; the setting only decides what
* happens when the agent said nothing either way.
*/
export function shouldOpenPreviewMiniPlayer(
input: PreviewAutomationOpenInput,
autoShowFloatingPreview = true,
): boolean {
return input.open ?? input.show ?? autoShowFloatingPreview;
}
export function previewAutomationOpenNeedsOverlay(
@@ -7,6 +7,7 @@
* @module IntegrationsSettings
*/
import {
DEFAULT_BROWSER_AUTO_SHOW_FLOATING_PREVIEW,
DEFAULT_BROWSER_VIEWPORT,
DEFAULT_PREVIEW_APPEARANCE,
DEFAULT_PREVIEW_ZOOM_FACTOR,
@@ -19,9 +20,11 @@ import {
type PreviewViewportSetting,
} from "@t3tools/contracts";
import { PREVIEW_VIEWPORT_PRESETS } from "@t3tools/shared/previewViewport";
import { useState } from "react";
import { Input } from "../ui/input";
import { ScreenRotationIcon } from "~/browser/ScreenRotationIcon";
import { Button } from "../ui/button";
import { NumberField, NumberFieldGroup, NumberFieldInput } from "../ui/number-field";
import {
Select,
SelectGroup,
@@ -31,6 +34,8 @@ import {
SelectTrigger,
SelectValue,
} from "../ui/select";
import { Switch } from "../ui/switch";
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
import { useClientSettings, useUpdatePrimarySettings } from "~/hooks/useSettings";
import {
@@ -51,6 +56,8 @@ const RESPONSIVE_VALUE = "responsive";
*/
const RESPONSIVE_SEED_SIZE = { width: 1280, height: 800 } as const;
const NO_GROUPING: Intl.NumberFormatOptions = { useGrouping: false };
const APPEARANCE_LABELS: Readonly<Record<PreviewAppearancePreference, string>> = {
system: "System",
light: "Light",
@@ -87,21 +94,31 @@ const isValidDimension = (value: number) =>
value >= PREVIEW_VIEWPORT_MIN_DIMENSION &&
value <= PREVIEW_VIEWPORT_MAX_DIMENSION;
/**
* A sized viewport with width and height swapped. Presets keep their identity
* through a rotation — `resolvePreviewViewport` already stores rotated presets
* as the preset id plus swapped dimensions — so a rotated iPad is still an
* iPad, not an anonymous custom size.
*/
const rotateViewport = (
viewport: Exclude<PreviewViewportSetting, { readonly _tag: "fill" }>,
): PreviewViewportSetting => ({
...viewport,
width: viewport.height,
height: viewport.width,
});
function BrowserViewportSetting() {
const viewport = useClientSettings((settings) => settings.browserDefaultViewport);
const updateSettings = useUpdatePrimarySettings();
// Held while typing so a half-entered width (e.g. "12") isn't persisted as a
// rejected value; committed on blur/Enter once both dimensions are valid.
const [draftSize, setDraftSize] = useState<{ width: string; height: string } | null>(null);
const sized = viewport._tag === "fill" ? null : viewport;
const presentedSize = draftSize ?? {
width: String(sized?.width ?? RESPONSIVE_SEED_SIZE.width),
height: String(sized?.height ?? RESPONSIVE_SEED_SIZE.height),
const presentedSize = {
width: sized?.width ?? RESPONSIVE_SEED_SIZE.width,
height: sized?.height ?? RESPONSIVE_SEED_SIZE.height,
};
const selectViewport = (value: string | null) => {
setDraftSize(null);
if (value === FILL_VALUE) {
updateSettings({ browserDefaultViewport: FILL_PREVIEW_VIEWPORT });
return;
@@ -128,21 +145,16 @@ function BrowserViewportSetting() {
});
};
const commitDraftSize = () => {
if (!draftSize) return;
const width = Number(draftSize.width);
const height = Number(draftSize.height);
setDraftSize(null);
if (
!isValidDimension(width) ||
!isValidDimension(height) ||
width * height > PREVIEW_VIEWPORT_MAX_AREA
) {
return;
}
if (sized && width === sized.width && height === sized.height) return;
// Committed on blur rather than per keystroke: typing "2560" passes through
// "256", which is a legal dimension, so an onValueChange handler would
// persist that intermediate size and churn the settings file on every key.
const commitDimension = (axis: "width" | "height", value: number | null) => {
if (value === null || !isValidDimension(value)) return;
const next = { ...presentedSize, [axis]: value };
if (next.width * next.height > PREVIEW_VIEWPORT_MAX_AREA) return;
if (sized && next.width === sized.width && next.height === sized.height) return;
// Typing a size means the preset no longer describes it.
updateSettings({ browserDefaultViewport: { _tag: "freeform", width, height } });
updateSettings({ browserDefaultViewport: { _tag: "freeform", ...next } });
};
return (
@@ -153,10 +165,7 @@ function BrowserViewportSetting() {
viewport._tag !== DEFAULT_BROWSER_VIEWPORT._tag ? (
<SettingResetButton
label="default browser viewport"
onClick={() => {
setDraftSize(null);
updateSettings({ browserDefaultViewport: DEFAULT_BROWSER_VIEWPORT });
}}
onClick={() => updateSettings({ browserDefaultViewport: DEFAULT_BROWSER_VIEWPORT })}
/>
) : null
}
@@ -186,42 +195,55 @@ function BrowserViewportSetting() {
</Select>
{sized ? (
<form
className="m-0 flex shrink-0 items-center gap-1 border-0 p-0"
aria-label="Default viewport dimensions"
onSubmit={(event) => {
event.preventDefault();
commitDraftSize();
}}
>
<Input
nativeInput
type="number"
inputMode="numeric"
size="sm"
className="w-16"
aria-label="Default viewport width"
min={PREVIEW_VIEWPORT_MIN_DIMENSION}
max={PREVIEW_VIEWPORT_MAX_DIMENSION}
<div className="flex shrink-0 items-center gap-1">
<NumberField
value={presentedSize.width}
onChange={(event) => setDraftSize({ ...presentedSize, width: event.target.value })}
onBlur={commitDraftSize}
/>
<span className="text-xs text-muted-foreground">×</span>
<Input
nativeInput
type="number"
inputMode="numeric"
size="sm"
className="w-16"
aria-label="Default viewport height"
min={PREVIEW_VIEWPORT_MIN_DIMENSION}
max={PREVIEW_VIEWPORT_MAX_DIMENSION}
// Pixel counts read as raw numbers; grouping would show "1,024".
format={NO_GROUPING}
size="sm"
className="w-24"
onValueCommitted={(value) => commitDimension("width", value)}
>
<NumberFieldGroup>
<NumberFieldInput aria-label="Default viewport width" />
</NumberFieldGroup>
</NumberField>
<span className="text-xs text-muted-foreground">×</span>
<NumberField
value={presentedSize.height}
onChange={(event) => setDraftSize({ ...presentedSize, height: event.target.value })}
onBlur={commitDraftSize}
/>
</form>
min={PREVIEW_VIEWPORT_MIN_DIMENSION}
max={PREVIEW_VIEWPORT_MAX_DIMENSION}
format={NO_GROUPING}
size="sm"
className="w-24"
onValueCommitted={(value) => commitDimension("height", value)}
>
<NumberFieldGroup>
<NumberFieldInput aria-label="Default viewport height" />
</NumberFieldGroup>
</NumberField>
<Tooltip>
<TooltipTrigger
render={
<Button
size="icon-sm"
variant="ghost-muted"
aria-label={`Rotate to ${
presentedSize.height >= presentedSize.width ? "landscape" : "portrait"
}`}
onClick={() =>
updateSettings({ browserDefaultViewport: rotateViewport(sized) })
}
>
<ScreenRotationIcon />
</Button>
}
/>
<TooltipPopup side="top">Rotate</TooltipPopup>
</Tooltip>
</div>
) : null}
</div>
}
@@ -312,6 +334,39 @@ function BrowserAppearanceSetting() {
);
}
function BrowserAutoShowFloatingPreviewSetting() {
const autoShow = useClientSettings((settings) => settings.browserAutoShowFloatingPreview);
const updateSettings = useUpdatePrimarySettings();
return (
<SettingsRow
{...searchableSetting("browser-auto-show-floating-preview")}
description="Pop the floating preview into view when an agent opens a browser. An agent that explicitly asks to show or hide its preview still gets what it asked for."
resetAction={
autoShow !== DEFAULT_BROWSER_AUTO_SHOW_FLOATING_PREVIEW ? (
<SettingResetButton
label="auto-show floating preview"
onClick={() =>
updateSettings({
browserAutoShowFloatingPreview: DEFAULT_BROWSER_AUTO_SHOW_FLOATING_PREVIEW,
})
}
/>
) : null
}
control={
<Switch
checked={autoShow}
onCheckedChange={(checked) =>
updateSettings({ browserAutoShowFloatingPreview: Boolean(checked) })
}
aria-label="Auto-show floating preview"
/>
}
/>
);
}
export function IntegrationsSettingsPanel() {
return (
<SettingsPageContainer>
@@ -319,6 +374,7 @@ export function IntegrationsSettingsPanel() {
<BrowserViewportSetting />
<BrowserZoomSetting />
<BrowserAppearanceSetting />
<BrowserAutoShowFloatingPreviewSetting />
</SettingsSection>
</SettingsPageContainer>
);
@@ -215,6 +215,12 @@ export const SETTINGS_SEARCH_ITEMS = [
to: "/settings/integrations",
targetId: "browser",
},
{
id: "browser-auto-show-floating-preview",
title: "Auto-show floating preview",
to: "/settings/integrations",
targetId: "browser",
},
{
id: "source-control",
title: "Source control",
+11
View File
@@ -126,6 +126,7 @@ export type FontFamilyPreference = typeof FontFamilyPreference.Type;
* because the Chromium guest they configure is desktop-local.
*/
export const DEFAULT_BROWSER_VIEWPORT: PreviewViewportSetting = FILL_PREVIEW_VIEWPORT;
export const DEFAULT_BROWSER_AUTO_SHOW_FLOATING_PREVIEW = true;
export const ClientSettingsSchema = Schema.Struct({
browserDefaultViewport: PreviewViewportSetting.pipe(
@@ -137,6 +138,15 @@ export const ClientSettingsSchema = Schema.Struct({
browserDefaultAppearance: PreviewAppearancePreference.pipe(
Schema.withDecodingDefault(Effect.succeed(DEFAULT_PREVIEW_APPEARANCE)),
),
/**
* Whether an agent opening a preview pops the floating mini player into
* view. Only applies when the agent didn't ask either way — an explicit
* `open`/`show` on `preview_open` still wins, since that is the agent
* deliberately showing or hiding its work.
*/
browserAutoShowFloatingPreview: Schema.Boolean.pipe(
Schema.withDecodingDefault(Effect.succeed(DEFAULT_BROWSER_AUTO_SHOW_FLOATING_PREVIEW)),
),
// Desktop-only: require holding the quit shortcut (Cmd/Ctrl+Q) before the
// app quits; a quick tap only shows a hint. Browser clients ignore it.
confirmQuit: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
@@ -787,6 +797,7 @@ export const ClientSettingsPatch = Schema.Struct({
browserDefaultViewport: Schema.optionalKey(PreviewViewportSetting),
browserDefaultZoomFactor: Schema.optionalKey(PreviewZoomFactor),
browserDefaultAppearance: Schema.optionalKey(PreviewAppearancePreference),
browserAutoShowFloatingPreview: Schema.optionalKey(Schema.Boolean),
confirmQuit: Schema.optionalKey(Schema.Boolean),
confirmThreadArchive: Schema.optionalKey(Schema.Boolean),
confirmThreadDelete: Schema.optionalKey(Schema.Boolean),