mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-18 15:28:48 +03:00
fix(app): restyle the browser site information popover and options menu (#58441)
This commit is contained in:
committed by
GitHub
Unverified
parent
80ea2130e7
commit
1358aaab50
@@ -618,9 +618,6 @@ story("zooms the page from the browser options in view and keeps its zoom in the
|
||||
|
||||
const zoom = root.getByRole("button", { name: "110%", exact: true })
|
||||
await expect(zoom).toBeVisible()
|
||||
await options.click()
|
||||
await expect(page.getByRole("menuitem", { name: /^Reset zoom/ })).toContainText("110%")
|
||||
await page.keyboard.press("Escape")
|
||||
await zoom.click()
|
||||
await expect(root.getByText("Zoom: 100", { exact: true })).toBeVisible()
|
||||
await expect(zoom).toBeHidden()
|
||||
|
||||
@@ -240,37 +240,58 @@
|
||||
z-index: 60;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
width: 320px;
|
||||
padding: 12px;
|
||||
border-radius: 12px;
|
||||
background: var(--v2-background-bg-base);
|
||||
gap: 2px;
|
||||
width: 261px;
|
||||
max-width: calc(100vw - 16px);
|
||||
padding: 4px;
|
||||
border-radius: 8px;
|
||||
background: var(--v2-background-bg-layer-01);
|
||||
box-shadow: var(--v2-elevation-floating);
|
||||
outline: none;
|
||||
color: var(--v2-text-text-base);
|
||||
font-size: 13px;
|
||||
font-weight: 440;
|
||||
line-height: var(--line-height-compact);
|
||||
line-height: var(--line-height-base);
|
||||
letter-spacing: -0.04px;
|
||||
user-select: none;
|
||||
transform-origin: var(--kb-popover-content-transform-origin);
|
||||
|
||||
[data-slot="browser-site-host"] {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-size: inherit;
|
||||
font-weight: 530;
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
[data-slot="browser-site-row"] {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: flex-start;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
/* Centers the icon on the first line of the row's text. */
|
||||
[data-slot="browser-site-icon"] {
|
||||
display: flex;
|
||||
flex: none;
|
||||
align-items: center;
|
||||
height: 20px;
|
||||
color: var(--v2-icon-icon-muted);
|
||||
}
|
||||
|
||||
/* Spans the card edge to edge over its padding; a 1px line scaled to a hairline. */
|
||||
[data-slot="browser-site-separator"] {
|
||||
flex: none;
|
||||
height: 1px;
|
||||
margin: 2px -4px;
|
||||
background: var(--v2-border-border-base);
|
||||
transform: scaleY(0.5);
|
||||
}
|
||||
|
||||
/* An action beside a row's text, centered on it. */
|
||||
[data-slot="browser-site-row"] > [data-component="button-v2"] {
|
||||
flex: none;
|
||||
@@ -278,6 +299,9 @@
|
||||
}
|
||||
|
||||
[data-slot="browser-site-detail"] {
|
||||
font-size: 11px;
|
||||
line-height: var(--line-height-compact);
|
||||
letter-spacing: 0.05px;
|
||||
color: var(--v2-text-text-muted);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,11 +40,12 @@ export default {
|
||||
"site.cookies.clear": "Clear",
|
||||
"site.permissions": "Permissions are blocked",
|
||||
"site.permissions.description": "Camera, microphone, location, and notifications don't work in this browser.",
|
||||
"site.agent": "The agent can use this page",
|
||||
"site.agent": "Agent can use this page",
|
||||
"site.agent.description": "It can read the page, run scripts, and fill in forms.",
|
||||
"page.add": "Add page to session",
|
||||
"page.placeholder": "Add context about this page",
|
||||
"external.open": "Open in system browser",
|
||||
"external.menu": "Open in browser",
|
||||
"external.unavailable": "This address only works on the server's machine.",
|
||||
options: "Browser options",
|
||||
"zoom.in": "Zoom in",
|
||||
@@ -52,5 +53,5 @@ export default {
|
||||
"zoom.reset": "Reset zoom",
|
||||
"zoom.percent": "{{percent}}%",
|
||||
"link.copy": "Copy link",
|
||||
"history.clear": "Clear browsing history",
|
||||
"history.clear": "Clear history",
|
||||
}
|
||||
|
||||
@@ -821,29 +821,25 @@ export default function SessionBrowserPane(props: {
|
||||
/>
|
||||
</Tooltip>
|
||||
<Menu.Portal>
|
||||
<Menu.Content class="min-w-56">
|
||||
<Menu.Content class="w-[172px]">
|
||||
{/* Zooming closes the menu: the page stays a still while the menu covers it, so a zoom would show
|
||||
only once it closed. The address field shows any zoom but 100% afterwards. */}
|
||||
<Menu.Group>
|
||||
<Menu.Item
|
||||
disabled={!address()}
|
||||
onSelect={() => zoomPage("in")}
|
||||
shortcut={<Keybind keys={[...keybinds.keys("mod+plus")]} variant="neutral" />}
|
||||
shortcut={<Keybind keys={keybinds.keys("mod+plus").map(fullWidth)} variant="neutral" />}
|
||||
>
|
||||
{extension.t("zoom.in")}
|
||||
</Menu.Item>
|
||||
<Menu.Item
|
||||
disabled={!address()}
|
||||
onSelect={() => zoomPage("out")}
|
||||
shortcut={<Keybind keys={[...keybinds.keys("mod+-")]} variant="neutral" />}
|
||||
shortcut={<Keybind keys={keybinds.keys("mod+-").map(fullWidth)} variant="neutral" />}
|
||||
>
|
||||
{extension.t("zoom.out")}
|
||||
</Menu.Item>
|
||||
<Menu.Item
|
||||
disabled={!zoomed()}
|
||||
onSelect={() => zoomPage("reset")}
|
||||
badge={extension.t("zoom.percent", { percent: Math.round((page()?.zoom ?? 1) * 100) })}
|
||||
>
|
||||
<Menu.Item disabled={!zoomed()} onSelect={() => zoomPage("reset")}>
|
||||
{extension.t("zoom.reset")}
|
||||
</Menu.Item>
|
||||
</Menu.Group>
|
||||
@@ -852,7 +848,7 @@ export default function SessionBrowserPane(props: {
|
||||
{extension.t("link.copy")}
|
||||
</Menu.Item>
|
||||
<Menu.Item disabled={!reachable()} onSelect={() => system.openExternal(address())}>
|
||||
{extension.t("external.open")}
|
||||
{extension.t("external.menu")}
|
||||
</Menu.Item>
|
||||
<Menu.Separator />
|
||||
<Menu.Item disabled={props.model.visits().length === 0} onSelect={() => props.model.clearHistory()}>
|
||||
@@ -1128,12 +1124,21 @@ function SiteInformation(props: {
|
||||
const extension = useExtension()
|
||||
|
||||
// `load` counts openings and clears, so a count for an earlier one never replaces a later one.
|
||||
const [state, setState] = createStore<{ open: boolean; cookies?: number; clearing: boolean; load: number }>({
|
||||
const [state, setState] = createStore<{
|
||||
open: boolean
|
||||
pointer: boolean
|
||||
cookies?: number
|
||||
clearing: boolean
|
||||
load: number
|
||||
}>({
|
||||
open: false,
|
||||
pointer: false,
|
||||
clearing: false,
|
||||
load: 0,
|
||||
})
|
||||
|
||||
let trigger: HTMLButtonElement | undefined
|
||||
|
||||
const kind = () => {
|
||||
const value = connection(props.url)
|
||||
|
||||
@@ -1173,6 +1178,7 @@ function SiteInformation(props: {
|
||||
open={state.open}
|
||||
placement="bottom-start"
|
||||
gutter={8}
|
||||
shift={-10}
|
||||
modal={false}
|
||||
onOpenChange={(open) => {
|
||||
setState("open", open)
|
||||
@@ -1182,8 +1188,11 @@ function SiteInformation(props: {
|
||||
>
|
||||
<Tooltip placement="top" value={extension.t("site.info")}>
|
||||
<Popover.Trigger
|
||||
ref={trigger}
|
||||
as={IconButton}
|
||||
type="button"
|
||||
onPointerDown={() => setState("pointer", true)}
|
||||
onKeyDown={() => setState("pointer", false)}
|
||||
variant="ghost-muted"
|
||||
size="small"
|
||||
aria-label={extension.t("site.info")}
|
||||
@@ -1199,21 +1208,26 @@ function SiteInformation(props: {
|
||||
|
||||
if (event.currentTarget instanceof HTMLElement) event.currentTarget.focus()
|
||||
}}
|
||||
// Focus returns to the trigger on close, which Chromium rings after Escape; a pointer opening keeps it unringed.
|
||||
onCloseAutoFocus={(event: Event) => {
|
||||
if (!state.pointer) return
|
||||
event.preventDefault()
|
||||
const active = document.activeElement
|
||||
|
||||
// An outside press already moved focus where it belongs.
|
||||
if (active && active !== document.body && !active.closest('[data-component="browser-site"]')) return
|
||||
trigger?.focus({ preventScroll: true, focusVisible: false })
|
||||
}}
|
||||
>
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<div data-slot="browser-site-row">
|
||||
<span data-slot="browser-site-icon">
|
||||
<Icon name="outline-globe" />
|
||||
</span>
|
||||
<Popover.Title data-slot="browser-site-host" dir="ltr">
|
||||
{addressParts(props.url).host || props.url}
|
||||
</Popover.Title>
|
||||
{/* A plain button: Kobalte's close button carries the open popover's data-expanded, which icon buttons
|
||||
draw as pressed. */}
|
||||
<IconButton
|
||||
variant="ghost-muted"
|
||||
size="small"
|
||||
aria-label={extension.t("common.close")}
|
||||
icon={<Icon name="outline-xmark" />}
|
||||
onClick={() => setState("open", false)}
|
||||
/>
|
||||
</div>
|
||||
<div data-slot="browser-site-separator" aria-hidden="true" />
|
||||
<Show when={kind()}>
|
||||
{(value) => (
|
||||
<SiteRow
|
||||
@@ -1258,12 +1272,23 @@ function SiteInformation(props: {
|
||||
)
|
||||
}
|
||||
|
||||
// The zoom shortcuts draw their plus and minus at the width of a letter key.
|
||||
function fullWidth(key: string) {
|
||||
if (key === "+") return "+"
|
||||
|
||||
if (key === "-") return "-"
|
||||
|
||||
return key
|
||||
}
|
||||
|
||||
function SiteRow(props: { icon: IconName; title: string; detail?: string; children?: JSX.Element }) {
|
||||
return (
|
||||
<div data-slot="browser-site-row">
|
||||
<Icon name={props.icon} class="shrink-0" />
|
||||
<span data-slot="browser-site-icon">
|
||||
<Icon name={props.icon} />
|
||||
</span>
|
||||
<div class="flex min-w-0 flex-1 flex-col gap-0.5">
|
||||
<span class="text-v2-text-text-base">{props.title}</span>
|
||||
<span>{props.title}</span>
|
||||
<Show when={props.detail}>{(detail) => <span data-slot="browser-site-detail">{detail()}</span>}</Show>
|
||||
</div>
|
||||
{props.children}
|
||||
|
||||
Reference in New Issue
Block a user