Mike0021 commited on
Commit
e2b52ec
·
verified ·
1 Parent(s): 5bfd7fc

Dropdowns: a thumb of their own, clear of the edge and the corners

Browse files
Files changed (1) hide show
  1. piweb/hf-design.patch +327 -166
piweb/hf-design.patch CHANGED
@@ -10917,10 +10917,10 @@ index 0b8f66a..262d991 100644
10917
  .sidebar-tool-button.is-active,
10918
  diff --git a/app/ui.css b/app/ui.css
10919
  new file mode 100644
10920
- index 0000000..2abcb12
10921
  --- /dev/null
10922
  +++ b/app/ui.css
10923
- @@ -0,0 +1,948 @@
10924
  +/* The shared components on Base UI (components/ui/*): menus, tooltips,
10925
  + popovers and the composer's suggestion list. Popups are portaled to <body>,
10926
  + so they stack by the positioner's z-index, above every pane. */
@@ -10951,9 +10951,9 @@ index 0000000..2abcb12
10951
  + A touch screen keeps the phone captures' scale, rows a finger can take
10952
  + (design/dropdown-spacing-reference.jpg and design/model-dropdown-reference.jpg
10953
  + at 2.81x: 15px text, 32px rows inset 8px).
10954
- + A dropdown that scrolls keeps its rows centred: its scrollbar is as wide as
10955
- + the inset and stands in the right inset's place (`--popup-inset-end`, set by
10956
- + components/ui/scrollbar-inset.ts while a bar takes room). */
10957
  +:root {
10958
  + --popup-font: 13px;
10959
  + --popup-label-font: 12px;
@@ -10966,13 +10966,14 @@ index 0000000..2abcb12
10966
  + --popup-gap: 8px;
10967
  + --popup-text-gap: 8px;
10968
  + --popup-edge: calc(var(--popup-inset) + var(--popup-row-pad));
 
 
 
10969
  + /* Dialogs on the same surface (the command bar, the folder picker) are larger than
10970
  + a dropdown: their rows take the dropdowns' rows, inset further from the edge. */
10971
  + --dialog-inset: 8px;
10972
  + --dialog-radius: calc(var(--dialog-inset) + var(--popup-row-radius));
10973
  + --dialog-edge: calc(var(--dialog-inset) + var(--popup-row-pad));
10974
- + /* The right inset: the scrollbar's place while one takes room. */
10975
- + --popup-inset-end: var(--popup-inset);
10976
  + --popup-hairline: color-mix(in srgb, var(--text-strong) 10%, transparent);
10977
  + --popup-shadow: 0 0 0 1px var(--popup-hairline), 0 2px 4px rgb(0 0 0 / 0.04), 0 12px 28px -6px rgb(0 0 0 / 0.14);
10978
  + /* Rows on a popup: a tint of the ink, so they show on --bg-elevated in every theme. */
@@ -11026,46 +11027,47 @@ index 0000000..2abcb12
11026
  + margin: var(--popup-inset) calc(-1 * var(--popup-inset-end)) var(--popup-inset) calc(-1 * var(--popup-inset));
11027
  + background: var(--line);
11028
  +}
11029
- +/* Scrolling: the bar takes the right inset (components/ui/scrollbar-inset.ts
11030
- + measures it), as wide as the inset in Chromium and Safari, thin in Firefox;
11031
- + its thumb fills it while the pointer is on it. */
11032
- +.ui-menu[data-scrollbar],
11033
- +.ui-composer-list-scroll[data-scrollbar],
11034
- +.ui-dropdown-scroll[data-scrollbar],
11035
- +.sidebar-menu[data-scrollbar] {
11036
- + --popup-inset-end: max(0px, calc(var(--popup-inset) - var(--popup-scrollbar, 0px)));
11037
- +}
 
11038
  +.ui-menu::-webkit-scrollbar,
11039
  +.ui-composer-list-scroll::-webkit-scrollbar,
11040
  +.ui-dropdown-scroll::-webkit-scrollbar,
11041
- +.sidebar-menu::-webkit-scrollbar { width: 4px; }
11042
- +.ui-menu::-webkit-scrollbar-thumb,
11043
- +.ui-composer-list-scroll::-webkit-scrollbar-thumb,
11044
- +.ui-dropdown-scroll::-webkit-scrollbar-thumb,
11045
- +.sidebar-menu::-webkit-scrollbar-thumb { border-width: 0.5px; }
11046
- +.ui-menu::-webkit-scrollbar-thumb:hover,
11047
- +.ui-composer-list-scroll::-webkit-scrollbar-thumb:hover,
11048
- +.ui-dropdown-scroll::-webkit-scrollbar-thumb:hover,
11049
- +.sidebar-menu::-webkit-scrollbar-thumb:hover { border-width: 0; }
11050
- +/* Where the surface itself scrolls, the thumb keeps off its rounded corners. */
11051
- +.ui-menu::-webkit-scrollbar-track,
11052
- +.sidebar-menu::-webkit-scrollbar-track { margin: var(--popup-radius) 0; }
11053
- +@media (pointer: coarse) {
11054
- + .ui-menu::-webkit-scrollbar,
11055
- + .ui-composer-list-scroll::-webkit-scrollbar,
11056
- + .ui-dropdown-scroll::-webkit-scrollbar,
11057
- + .sidebar-menu::-webkit-scrollbar { width: 8px; }
11058
- + .ui-menu::-webkit-scrollbar-thumb,
11059
- + .ui-composer-list-scroll::-webkit-scrollbar-thumb,
11060
- + .ui-dropdown-scroll::-webkit-scrollbar-thumb,
11061
- + .sidebar-menu::-webkit-scrollbar-thumb { border-width: 2px; }
11062
- +}
11063
- +@supports not selector(::-webkit-scrollbar) {
11064
- + .ui-menu,
11065
- + .ui-composer-list-scroll,
11066
- + .ui-dropdown-scroll,
11067
- + .sidebar-menu { scrollbar-width: thin; }
11068
  +}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11069
  +
11070
  +/* ---------------------------------------------------------------- menus */
11071
  +.ui-menu {
@@ -25101,7 +25103,7 @@ index 0000000..1b0fea9
25101
  + return maker ? <ProviderIcon id={maker} size={size} mono /> : <CarbonIcon icon={Carbon.Chip} size={size} />;
25102
  +}
25103
  diff --git a/components/ModelSelector.tsx b/components/ModelSelector.tsx
25104
- index ba912ee..e6e754d 100644
25105
  --- a/components/ModelSelector.tsx
25106
  +++ b/components/ModelSelector.tsx
25107
  @@ -4,6 +4,10 @@ import { useEffect, useRef, useState, type CSSProperties } from "react";
@@ -25109,7 +25111,7 @@ index ba912ee..e6e754d 100644
25109
  import { useIsMobile } from "@/hooks/useIsMobile";
25110
  import { SelectorRow } from "./SelectorRow";
25111
  +import { ModelMark } from "./ModelMark";
25112
- +import { useScrollbarInset } from "./ui/scrollbar-inset";
25113
  +import { CarbonIcon } from "./CarbonIcon";
25114
  +import * as Carbon from "./carbon/icons";
25115
 
@@ -25145,7 +25147,7 @@ index ba912ee..e6e754d 100644
25145
  const isMobile = useIsMobile();
25146
  const rootRef = useRef<HTMLDivElement>(null);
25147
  const panelRef = useRef<HTMLDivElement>(null);
25148
- + const scrollbarRef = useScrollbarInset<HTMLDivElement>();
25149
  const [open, setOpen] = useState(false);
25150
  const [anchorRect, setAnchorRect] = useState<{ top: number; right: number; bottom: number; left: number; width: number } | null>(null);
25151
  const [filter, setFilter] = useState("");
@@ -25305,7 +25307,7 @@ index ba912ee..e6e754d 100644
25305
  value={filter}
25306
  onChange={(event) => setFilter(event.target.value)}
25307
  placeholder={t("chat.filterModels")}
25308
- @@ -268,23 +297,11 @@ export function ModelSelector({
25309
  autoFocus={!isMobile}
25310
  autoComplete="off"
25311
  spellCheck={false}
@@ -25327,11 +25329,12 @@ index ba912ee..e6e754d 100644
25327
  </div>
25328
  )}
25329
  - <div style={{ minHeight: 0, overflowY: "auto" }}>
25330
- + <div ref={scrollbarRef} className="ui-dropdown-scroll">
 
25331
  {onClear && !filter.trim() && (
25332
  <SelectorRow active={!value} gutter={Boolean(onSetDefault)} onSelect={() => {
25333
  setOpen(false);
25334
- @@ -295,20 +312,22 @@ export function ModelSelector({
25335
  </SelectorRow>
25336
  )}
25337
  {modelsByProvider.length === 0 ? (
@@ -29392,7 +29395,7 @@ index 0666b96..f1195d4 100644
29392
  );
29393
  }
29394
  diff --git a/components/SidebarMenu.test.mjs b/components/SidebarMenu.test.mjs
29395
- index cb22867..1075643 100644
29396
  --- a/components/SidebarMenu.test.mjs
29397
  +++ b/components/SidebarMenu.test.mjs
29398
  @@ -84,7 +84,7 @@ test("desktop menu markup: menu roles, check marks, shortcuts, notes and disable
@@ -29404,6 +29407,15 @@ index cb22867..1075643 100644
29404
 
29405
  const feature = html.match(/<button[^>]*aria-checked="false"[^>]*>.*?<\/button>/)?.[0] ?? "";
29406
  assert.match(feature, /role="menuitemradio"/);
 
 
 
 
 
 
 
 
 
29407
  @@ -161,6 +161,10 @@ test("desktop placement: below a button, aligned by edge, flipping above when it
29408
  // A button near the left edge with end alignment is clamped to the margin.
29409
  const edge = { left: 10, top: 100, right: 32, bottom: 122 };
@@ -29425,15 +29437,33 @@ index cb22867..1075643 100644
29425
  const spinner = renderToStaticMarkup(h(SpinnerIcon, { size: 12, label: "Agent running", className: "row-status" }));
29426
  assert.match(spinner, /width="12"/);
29427
  assert.match(spinner, /stroke-width="2\.8"/);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29428
  diff --git a/components/SidebarMenu.tsx b/components/SidebarMenu.tsx
29429
- index d4a5d1e..b97780d 100644
29430
  --- a/components/SidebarMenu.tsx
29431
  +++ b/components/SidebarMenu.tsx
29432
  @@ -3,6 +3,7 @@
29433
  import { Children, useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent as ReactKeyboardEvent, type ReactNode, type Ref, type SyntheticEvent } from "react";
29434
  import { createPortal } from "react-dom";
29435
  import { CheckIcon } from "./SidebarIcons";
29436
- +import { useScrollbarInset } from "./ui/scrollbar-inset";
29437
 
29438
  /**
29439
  * The session sidebar's popup menu: a row's ⋯ or right-click menu, a project
@@ -29493,11 +29523,11 @@ index d4a5d1e..b97780d 100644
29493
  onActivate,
29494
  onClose,
29495
  }: SidebarMenuSurfaceProps) {
29496
- + const desktopRef = useScrollbarInset<HTMLDivElement>(surfaceRef);
29497
  const custom = hasCustomMenuBody(children);
29498
  const hasFooter = !custom && hasCustomMenuBody(footer);
29499
  const filtered = filter !== undefined && !custom && sidebarMenuHasFilter(items, filter.minChoices);
29500
- @@ -537,7 +551,7 @@ export function SidebarMenuSurface({
29501
  if (!sheet) {
29502
  return (
29503
  <div
@@ -29506,6 +29536,13 @@ index d4a5d1e..b97780d 100644
29506
  className={classic ? "sidebar-menu is-classic" : "sidebar-menu"}
29507
  role={menuRole ?? "dialog"}
29508
  aria-label={ariaLabel}
 
 
 
 
 
 
 
29509
  diff --git a/components/SkillsConfig.tsx b/components/SkillsConfig.tsx
29510
  index e479822..18169ed 100644
29511
  --- a/components/SkillsConfig.tsx
@@ -32448,10 +32485,10 @@ index 0000000..cda684d
32448
  +});
32449
  diff --git a/components/ui/composer-list.tsx b/components/ui/composer-list.tsx
32450
  new file mode 100644
32451
- index 0000000..4d10b5c
32452
  --- /dev/null
32453
  +++ b/components/ui/composer-list.tsx
32454
- @@ -0,0 +1,144 @@
32455
  +"use client";
32456
  +
32457
  +// The composer's suggestion list ("/" commands, "@" files, input history): a
@@ -32465,7 +32502,7 @@ index 0000000..4d10b5c
32465
  +
32466
  +import { Popover } from "@base-ui/react/popover";
32467
  +import { Fragment, useEffect, useRef, type ReactNode, type RefObject } from "react";
32468
- +import { useScrollbarInset } from "./scrollbar-inset";
32469
  +
32470
  +export interface ComposerListItem {
32471
  + key: string;
@@ -32516,7 +32553,7 @@ index 0000000..4d10b5c
32516
  + className?: string;
32517
  +}) {
32518
  + const rowRefs = useRef<Array<HTMLDivElement | null>>([]);
32519
- + const scrollbarRef = useScrollbarInset<HTMLDivElement>();
32520
  + const total = groups.reduce((sum, group) => sum + group.items.length, 0);
32521
  +
32522
  + useEffect(() => {
@@ -32555,7 +32592,8 @@ index 0000000..4d10b5c
32555
  + onMouseDown={(event) => event.preventDefault()}
32556
  + >
32557
  + {header && <div className="ui-composer-list-header">{header}</div>}
32558
- + <div ref={scrollbarRef} className="ui-composer-list-scroll" role="listbox" id={listId}>
 
32559
  + {total === 0 && empty && <div className="ui-composer-list-empty">{empty}</div>}
32560
  + {groups.map((group) => group.items.length === 0 ? null : (
32561
  + <Fragment key={group.key}>
@@ -32598,10 +32636,10 @@ index 0000000..4d10b5c
32598
  +}
32599
  diff --git a/components/ui/dropdowns.test.mjs b/components/ui/dropdowns.test.mjs
32600
  new file mode 100644
32601
- index 0000000..2b08674
32602
  --- /dev/null
32603
  +++ b/components/ui/dropdowns.test.mjs
32604
- @@ -0,0 +1,143 @@
32605
  +import assert from "node:assert/strict";
32606
  +import { readFileSync, readdirSync } from "node:fs";
32607
  +import test from "node:test";
@@ -32691,53 +32729,43 @@ index 0000000..2b08674
32691
  + }
32692
  +});
32693
  +
32694
- +test("a dropdown's scrollbar stands in its right inset, as wide as the inset at both scales", () => {
32695
  + const scrollers = [".ui-menu", ".ui-composer-list-scroll", ".ui-dropdown-scroll", ".sidebar-menu"];
32696
  + const sidebar = readFileSync(new URL("../../app/sidebar-menu.css", import.meta.url), "utf8");
32697
  + const rule = (source, selector) => source.match(new RegExp(`(?:^|\\n)${selector.replace(".", "\\.")} \\{([^}]*)\\}`))?.[1] ?? "";
32698
  + for (const selector of scrollers) {
32699
  + const body = rule(selector === ".sidebar-menu" ? sidebar : css, selector);
32700
- + assert.match(body, /padding: (0|var\(--popup-inset\)) var\(--popup-inset-end\)/, `${selector} pads its right with the scrollbar's place`);
 
 
 
 
 
 
 
 
 
 
32701
  + }
32702
- + const widths = [...css.matchAll(/\.sidebar-menu::-webkit-scrollbar \{ width: (\d+)px; \}/g)].map((match) => Number(match[1]));
32703
- + const desktop = tokens(css.slice(css.indexOf(":root {\n --popup-font"), css.indexOf("html.dark {\n --popup-shadow")));
32704
- + const touch = tokens(css.slice(css.indexOf("@media (pointer: coarse)"), css.indexOf("/* The surface, shared by every dropdown. */")));
32705
- + assert.deepEqual(widths, [Number.parseFloat(desktop["popup-inset"]), Number.parseFloat(touch["popup-inset"])]);
32706
  +});
32707
  +
32708
- +test("the scrollbar's width is marked on the scroller while one takes room, and cleared when it goes", async () => {
32709
- + const { watchScrollbarInset } = await jiti.import("./scrollbar-inset.ts");
32710
- + const saved = { getComputedStyle: globalThis.getComputedStyle, ResizeObserver: globalThis.ResizeObserver, raf: globalThis.requestAnimationFrame, caf: globalThis.cancelAnimationFrame };
32711
- + let notify = () => {};
32712
- + let disconnected = false;
32713
- + globalThis.getComputedStyle = () => ({ borderLeftWidth: "0px", borderRightWidth: "0px" });
32714
- + globalThis.ResizeObserver = class { constructor(callback) { notify = callback; } observe() {} disconnect() { disconnected = true; } };
32715
- + globalThis.requestAnimationFrame = (callback) => { callback(); return 1; };
32716
- + globalThis.cancelAnimationFrame = () => {};
32717
- + try {
32718
- + const attributes = new Map();
32719
- + const props = new Map();
32720
- + const node = {
32721
- + offsetWidth: 272, clientWidth: 272,
32722
- + setAttribute: (key, value) => attributes.set(key, value), removeAttribute: (key) => attributes.delete(key), hasAttribute: (key) => attributes.has(key),
32723
- + style: { setProperty: (key, value) => props.set(key, value), removeProperty: (key) => props.delete(key) },
32724
- + };
32725
- + const stop = watchScrollbarInset(node);
32726
- + assert.equal(attributes.has("data-scrollbar"), false, "no bar, no mark");
32727
- + node.clientWidth = 265; notify();
32728
- + assert.equal(attributes.has("data-scrollbar"), true);
32729
- + assert.equal(props.get("--popup-scrollbar"), "7px");
32730
- + node.clientWidth = 272; notify();
32731
- + assert.equal(attributes.has("data-scrollbar"), false, "the bar went");
32732
- + assert.equal(props.has("--popup-scrollbar"), false);
32733
- + stop();
32734
- + assert.equal(disconnected, true);
32735
- + } finally {
32736
- + globalThis.getComputedStyle = saved.getComputedStyle;
32737
- + globalThis.ResizeObserver = saved.ResizeObserver;
32738
- + globalThis.requestAnimationFrame = saved.raf;
32739
- + globalThis.cancelAnimationFrame = saved.caf;
32740
- + }
32741
  +});
32742
  +
32743
  +test("a menu's surface never draws the focus ring: its highlighted row shows focus", () => {
@@ -32747,10 +32775,10 @@ index 0000000..2b08674
32747
  +});
32748
  diff --git a/components/ui/menu.tsx b/components/ui/menu.tsx
32749
  new file mode 100644
32750
- index 0000000..d26e2f3
32751
  --- /dev/null
32752
  +++ b/components/ui/menu.tsx
32753
- @@ -0,0 +1,219 @@
32754
  +"use client";
32755
  +
32756
  +// Menus on Base UI (`@base-ui/react/menu`): keyboard navigation, typeahead,
@@ -32766,7 +32794,7 @@ index 0000000..d26e2f3
32766
  +import type { ComponentProps, ReactNode } from "react";
32767
  +import { CarbonIcon } from "../CarbonIcon";
32768
  +import * as Carbon from "../carbon/icons";
32769
- +import { useScrollbarInset } from "./scrollbar-inset";
32770
  +
32771
  +export const MenuRoot = Menu.Root;
32772
  +export const MenuTrigger = Menu.Trigger;
@@ -32809,11 +32837,12 @@ index 0000000..d26e2f3
32809
  + /** A fixed width; menus otherwise size to their longest item. */
32810
  + width?: number;
32811
  +}) {
32812
- + const scrollbarRef = useScrollbarInset<HTMLDivElement>();
32813
  + return (
32814
  + <Menu.Portal>
32815
  + <Menu.Positioner className="ui-positioner" side={side} align={align} sideOffset={sideOffset} alignOffset={alignOffset}>
32816
- + <Menu.Popup ref={scrollbarRef} className={className ? `ui-menu ${className}` : "ui-menu"} style={width ? { width } : undefined}>
 
32817
  + {children}
32818
  + </Menu.Popup>
32819
  + </Menu.Positioner>
@@ -32922,7 +32951,7 @@ index 0000000..d26e2f3
32922
  + /** Where focus goes when the menu closes (default: back where it was). */
32923
  + finalFocus?: ComponentProps<typeof Menu.Popup>["finalFocus"];
32924
  +}) {
32925
- + const scrollbarRef = useScrollbarInset<HTMLDivElement>();
32926
  + const anchor = point
32927
  + ? { getBoundingClientRect: () => DOMRect.fromRect({ x: point.x, y: point.y, width: 0, height: 0 }) }
32928
  + : null;
@@ -32930,7 +32959,8 @@ index 0000000..d26e2f3
32930
  + <Menu.Root open={point !== null} onOpenChange={(open) => { if (!open) onClose(); }} modal={false}>
32931
  + <Menu.Portal>
32932
  + <Menu.Positioner className="ui-positioner" anchor={anchor} side="bottom" align="start" sideOffset={2}>
32933
- + <Menu.Popup ref={scrollbarRef} className="ui-menu" style={width ? { width } : undefined} finalFocus={finalFocus}>
 
32934
  + {children}
32935
  + </Menu.Popup>
32936
  + </Menu.Positioner>
@@ -32970,6 +33000,194 @@ index 0000000..d26e2f3
32970
  + </Menu.SubmenuRoot>
32971
  + );
32972
  +}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32973
  diff --git a/components/ui/popover.tsx b/components/ui/popover.tsx
32974
  new file mode 100644
32975
  index 0000000..1e96650
@@ -33013,63 +33231,6 @@ index 0000000..1e96650
33013
  + </Popover.Portal>
33014
  + );
33015
  +}
33016
- diff --git a/components/ui/scrollbar-inset.ts b/components/ui/scrollbar-inset.ts
33017
- new file mode 100644
33018
- index 0000000..5d2e784
33019
- --- /dev/null
33020
- +++ b/components/ui/scrollbar-inset.ts
33021
- @@ -0,0 +1,51 @@
33022
- +"use client";
33023
- +
33024
- +// A dropdown's scrollbar takes the place of its right inset. Chromium draws
33025
- +// Pi Web's scrollbars as a box that takes room (app/globals.css), so a
33026
- +// dropdown that scrolls held its rows 7px from the left edge and 7px plus the
33027
- +// bar from the right, off centre under the highlight. While it scrolls, the
33028
- +// scroller is marked `data-scrollbar` with the bar's width in
33029
- +// `--popup-scrollbar`, and app/ui.css takes that much off the right inset
33030
- +// (`--popup-inset-end`). Overlay scrollbars take no room: nothing changes.
33031
- +
33032
- +import { useCallback, useRef, type Ref } from "react";
33033
- +
33034
- +export function watchScrollbarInset(node: HTMLElement): () => void {
33035
- + const update = () => {
33036
- + const style = getComputedStyle(node);
33037
- + const bar = node.offsetWidth - node.clientWidth - parseFloat(style.borderLeftWidth) - parseFloat(style.borderRightWidth);
33038
- + if (bar > 0) {
33039
- + node.setAttribute("data-scrollbar", "");
33040
- + node.style.setProperty("--popup-scrollbar", `${bar}px`);
33041
- + } else if (node.hasAttribute("data-scrollbar")) {
33042
- + node.removeAttribute("data-scrollbar");
33043
- + node.style.removeProperty("--popup-scrollbar");
33044
- + }
33045
- + };
33046
- + update();
33047
- + if (typeof ResizeObserver === "undefined") return () => {};
33048
- + // The bar shows or goes as the content box narrows or widens. The inset it
33049
- + // changes resizes that box again, so the update waits a frame: an update
33050
- + // inside the observer's callback would loop it.
33051
- + let frame = 0;
33052
- + const observer = new ResizeObserver(() => {
33053
- + cancelAnimationFrame(frame);
33054
- + frame = requestAnimationFrame(update);
33055
- + });
33056
- + observer.observe(node);
33057
- + return () => {
33058
- + cancelAnimationFrame(frame);
33059
- + observer.disconnect();
33060
- + };
33061
- +}
33062
- +
33063
- +/** A callback ref for a dropdown's scroller; `also` receives the node too. */
33064
- +export function useScrollbarInset<T extends HTMLElement>(also?: Ref<T>): (node: T | null) => void {
33065
- + const stop = useRef<(() => void) | null>(null);
33066
- + return useCallback((node: T | null) => {
33067
- + stop.current?.();
33068
- + stop.current = node ? watchScrollbarInset(node) : null;
33069
- + if (typeof also === "function") also(node);
33070
- + else if (also) (also as { current: T | null }).current = node;
33071
- + }, [also]);
33072
- +}
33073
  diff --git a/components/ui/select.test.mjs b/components/ui/select.test.mjs
33074
  new file mode 100644
33075
  index 0000000..668e391
@@ -35623,7 +35784,7 @@ index 7fb1c0c..9c6aa29 100644
35623
 
35624
  diff --git a/docs/agents/desktop-shell.md b/docs/agents/desktop-shell.md
35625
  new file mode 100644
35626
- index 0000000..a9ccc50
35627
  --- /dev/null
35628
  +++ b/docs/agents/desktop-shell.md
35629
  @@ -0,0 +1,75 @@
@@ -35632,7 +35793,7 @@ index 0000000..a9ccc50
35632
  +Pi Web's frame follows Claude Code Desktop's Code tab: a sidebar of sessions, a header, then the conversation and the panes it opened as tiles. Pi's power stays reachable through "/", the composer's "+" menu, the title's session menu and Settings rather than permanent chrome. Popups are Base UI (`@base-ui/react` 1.8.0) through the wrappers in `components/ui/`, styled in `app/ui.css`; the header and tiles in `app/shell.css`. The Code tab is claude.ai web code (its chunks are on assets-proxy.anthropic.com, no Cloudflare there); the tile behaviour below was read from its tile engine and side-pane store, not from screenshots. The conversation outline (upstream's ChatMinimap) is removed.
35633
  +
35634
  +## Dropdowns (`app/ui.css` "dropdowns", `components/ui/menu.tsx`, `app/sidebar-menu.css`)
35635
- +- **One set of proportions for every dropdown**, kept as `--popup-*` tokens. On a desktop, `design/dropdown-compact-reference.jpg`'s (a desktop capture at 2x: rows 24px, inset about 4px, surface rounded 10px, icons centred 19.5px and text 34px from the edge): at 13px, a 10px surface (hairline + soft shadow, `--popup-shadow`), rows 24px inset 4px and rounded 6px (the surface's radius is the inset plus the row's), icons 12px from the edge (centred at 19px), text at 34px, section labels 12px `--text-dim` in sentence case on the icon column, separators edge to edge with the inset above and below, a row's description inline after its label. Touch screens (`pointer: coarse`) keep the phone captures' scale (`design/dropdown-spacing-reference.jpg`, `design/model-dropdown-reference.jpg`, 2.81x): 15px, 32px rows, 8px inset, 16px surface. A dropdown that scrolls keeps its rows centred: Pi Web's Chromium scrollbars take room (10px, `app/globals.css`), which held a scrolling menu's rows 7px from the left and 17px from the right; dropdown scrollers take a scrollbar as wide as the inset (4px, its thumb filling it under the pointer), and `components/ui/scrollbar-inset.ts` marks the scroller (`data-scrollbar`, `--popup-scrollbar`) while one shows so the right inset (`--popup-inset-end`) gives way to it. Separators then end at the bar. Headless Chromium hides scrollbars: tests that check this launch without `--hide-scrollbars`. `components/ui/dropdowns.test.mjs` checks each scale's ratios against its reference and that the sidebar's menus use the tokens.
35636
  +- Who follows it: Base UI menus (`.ui-menu`), the "/" "@" and history list (`.ui-composer-list`: its scroller holds the side inset so a group's line can reach the edges), popovers (content on the icon column), the sidebar's menus and their filter (a plain line like the reference's "Search here…"; the files tab's `classic` look is gone, only paths keep code type), the phone sheet (the same inset rounded rows, 44px), the model field (`ModelSelector`/`SelectorRow`: `.ui-dropdown-*`, check on the right as in the menus), and the header's panels (`.header-dropdown`: session info, system prompt, tools, subagents, branches, inset 8px under the header).
35637
  +- **One icon column**: model rows carry their maker's mark (`components/ModelMark.tsx`: the repo's organisation on a router such as Hugging Face, else the provider; brand colours in grays), whatever has no icon starts on the icon column as the references' section labels and search line do (the effort levels, the model field's clear row: never an empty icon's room before a label), "/" rows show their kind (the "+" menu's icons: commands, connectors, a page for prompts, skills) and history rows a clock.
35638
  +- **`MenuSection`** is the only way to label a group: Base UI throws on a `GroupLabel` outside a `Group`, and the Browser pane's ⋯ menu did that, which took the page down.
 
10917
  .sidebar-tool-button.is-active,
10918
  diff --git a/app/ui.css b/app/ui.css
10919
  new file mode 100644
10920
+ index 0000000..4a49887
10921
  --- /dev/null
10922
  +++ b/app/ui.css
10923
+ @@ -0,0 +1,950 @@
10924
  +/* The shared components on Base UI (components/ui/*): menus, tooltips,
10925
  + popovers and the composer's suggestion list. Popups are portaled to <body>,
10926
  + so they stack by the positioner's z-index, above every pane. */
 
10951
  + A touch screen keeps the phone captures' scale, rows a finger can take
10952
  + (design/dropdown-spacing-reference.jpg and design/model-dropdown-reference.jpg
10953
  + at 2.81x: 15px text, 32px rows inset 8px).
10954
+ + A dropdown that scrolls draws its own thumb (components/ui/overlay-scrollbar.tsx)
10955
+ + in a lane of its own on the right (`--popup-inset-end`): it never covers a row,
10956
+ + its highlight or its check, and keeps clear of the edge and the corners. */
10957
  +:root {
10958
  + --popup-font: 13px;
10959
  + --popup-label-font: 12px;
 
10966
  + --popup-gap: 8px;
10967
  + --popup-text-gap: 8px;
10968
  + --popup-edge: calc(var(--popup-inset) + var(--popup-row-pad));
10969
+ + /* The right inset: while a dropdown scrolls, its thumb's lane (2px, the thumb, 2px). */
10970
+ + --popup-inset-end: var(--popup-inset);
10971
+ + --popup-scroll-lane: 8px;
10972
  + /* Dialogs on the same surface (the command bar, the folder picker) are larger than
10973
  + a dropdown: their rows take the dropdowns' rows, inset further from the edge. */
10974
  + --dialog-inset: 8px;
10975
  + --dialog-radius: calc(var(--dialog-inset) + var(--popup-row-radius));
10976
  + --dialog-edge: calc(var(--dialog-inset) + var(--popup-row-pad));
 
 
10977
  + --popup-hairline: color-mix(in srgb, var(--text-strong) 10%, transparent);
10978
  + --popup-shadow: 0 0 0 1px var(--popup-hairline), 0 2px 4px rgb(0 0 0 / 0.04), 0 12px 28px -6px rgb(0 0 0 / 0.14);
10979
  + /* Rows on a popup: a tint of the ink, so they show on --bg-elevated in every theme. */
 
11027
  + margin: var(--popup-inset) calc(-1 * var(--popup-inset-end)) var(--popup-inset) calc(-1 * var(--popup-inset));
11028
  + background: var(--line);
11029
  +}
11030
+ +/* Scrolling: the scroller's own bar is hidden (it ran flat against the edge and into
11031
+ + the rounded corners); components/ui/overlay-scrollbar.tsx draws the thumb instead,
11032
+ + 2px inside the edge as the app's scrollbars sit, its track clear of the corners
11033
+ + (and of a sticky filter). While there is something to scroll (`data-overflow`) the
11034
+ + rows end before its lane, 2px from it; separators still reach the edge. Thin at
11035
+ + rest, the app's 6px under the pointer or while dragged, in its colours. */
11036
+ +.ui-menu,
11037
+ +.ui-composer-list-scroll,
11038
+ +.ui-dropdown-scroll,
11039
+ +.sidebar-menu { scrollbar-width: none; }
11040
  +.ui-menu::-webkit-scrollbar,
11041
  +.ui-composer-list-scroll::-webkit-scrollbar,
11042
  +.ui-dropdown-scroll::-webkit-scrollbar,
11043
+ +.sidebar-menu::-webkit-scrollbar { display: none; }
11044
+ +.ui-menu[data-overflow],
11045
+ +.ui-composer-list-scroll[data-overflow],
11046
+ +.ui-dropdown-scroll[data-overflow],
11047
+ +.sidebar-menu[data-overflow] { --popup-inset-end: var(--popup-scroll-lane); }
11048
+ +.ui-scroll-rail {
11049
+ + position: sticky;
11050
+ + top: 0;
11051
+ + z-index: 2;
11052
+ + height: 0;
11053
+ + pointer-events: none;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11054
  +}
11055
+ +.ui-scroll-thumb {
11056
+ + position: absolute;
11057
+ + width: 4px;
11058
+ + border-radius: 999px;
11059
+ + background: color-mix(in srgb, var(--text-dim) 45%, transparent);
11060
+ + pointer-events: auto;
11061
+ + touch-action: none;
11062
+ + transition: width 0.12s ease, background-color 0.12s ease;
11063
+ +}
11064
+ +.ui-scroll-thumb[hidden] { display: none; }
11065
+ +/* Easier to take than to see: the grab area reaches into the rows' inset. */
11066
+ +.ui-scroll-thumb::before { content: ""; position: absolute; inset: 0 -2px 0 -6px; }
11067
+ +.ui-scroll-thumb:hover,
11068
+ +.ui-scroll-thumb[data-dragging] { width: 6px; background: color-mix(in srgb, var(--text-dim) 72%, transparent); }
11069
+ +.ui-scroll-thumb[data-dragging] { background: var(--text-dim); }
11070
+ +@media (prefers-reduced-motion: reduce) { .ui-scroll-thumb { transition: none; } }
11071
  +
11072
  +/* ---------------------------------------------------------------- menus */
11073
  +.ui-menu {
 
25103
  + return maker ? <ProviderIcon id={maker} size={size} mono /> : <CarbonIcon icon={Carbon.Chip} size={size} />;
25104
  +}
25105
  diff --git a/components/ModelSelector.tsx b/components/ModelSelector.tsx
25106
+ index ba912ee..dd2105c 100644
25107
  --- a/components/ModelSelector.tsx
25108
  +++ b/components/ModelSelector.tsx
25109
  @@ -4,6 +4,10 @@ import { useEffect, useRef, useState, type CSSProperties } from "react";
 
25111
  import { useIsMobile } from "@/hooks/useIsMobile";
25112
  import { SelectorRow } from "./SelectorRow";
25113
  +import { ModelMark } from "./ModelMark";
25114
+ +import { useOverlayScrollbar } from "./ui/overlay-scrollbar";
25115
  +import { CarbonIcon } from "./CarbonIcon";
25116
  +import * as Carbon from "./carbon/icons";
25117
 
 
25147
  const isMobile = useIsMobile();
25148
  const rootRef = useRef<HTMLDivElement>(null);
25149
  const panelRef = useRef<HTMLDivElement>(null);
25150
+ + const [scrollerRef, scrollRail] = useOverlayScrollbar<HTMLDivElement>();
25151
  const [open, setOpen] = useState(false);
25152
  const [anchorRect, setAnchorRect] = useState<{ top: number; right: number; bottom: number; left: number; width: number } | null>(null);
25153
  const [filter, setFilter] = useState("");
 
25307
  value={filter}
25308
  onChange={(event) => setFilter(event.target.value)}
25309
  placeholder={t("chat.filterModels")}
25310
+ @@ -268,23 +297,12 @@ export function ModelSelector({
25311
  autoFocus={!isMobile}
25312
  autoComplete="off"
25313
  spellCheck={false}
 
25329
  </div>
25330
  )}
25331
  - <div style={{ minHeight: 0, overflowY: "auto" }}>
25332
+ + <div ref={scrollerRef} className="ui-dropdown-scroll">
25333
+ + {scrollRail}
25334
  {onClear && !filter.trim() && (
25335
  <SelectorRow active={!value} gutter={Boolean(onSetDefault)} onSelect={() => {
25336
  setOpen(false);
25337
+ @@ -295,20 +313,22 @@ export function ModelSelector({
25338
  </SelectorRow>
25339
  )}
25340
  {modelsByProvider.length === 0 ? (
 
29395
  );
29396
  }
29397
  diff --git a/components/SidebarMenu.test.mjs b/components/SidebarMenu.test.mjs
29398
+ index cb22867..e85a2d0 100644
29399
  --- a/components/SidebarMenu.test.mjs
29400
  +++ b/components/SidebarMenu.test.mjs
29401
  @@ -84,7 +84,7 @@ test("desktop menu markup: menu roles, check marks, shortcuts, notes and disable
 
29407
 
29408
  const feature = html.match(/<button[^>]*aria-checked="false"[^>]*>.*?<\/button>/)?.[0] ?? "";
29409
  assert.match(feature, /role="menuitemradio"/);
29410
+ @@ -136,7 +136,7 @@ test("conditional bodies that are all off are no body: the items show", () => {
29411
+ assert.match(sheet, /<div class="sidebar-sheet-body" role="menu" aria-label="Session actions">/);
29412
+ }
29413
+ assert.equal(hasCustomMenuBody([false, h("form")]), true);
29414
+ - assert.match(surface({ children: [false, h("form", { key: "form" })] }), /^<div class="sidebar-menu" role="dialog"[^>]*><form><\/form><\/div>$/);
29415
+ + assert.match(surface({ children: [false, h("form", { key: "form" })] }), /^<div class="sidebar-menu" role="dialog"[^>]*><div class="ui-scroll-rail" aria-hidden="true"><div class="ui-scroll-thumb" hidden=""><\/div><\/div><form><\/form><\/div>$/);
29416
+ });
29417
+
29418
+ test("desktop placement: at a point, flipping like a native context menu, then clamped", () => {
29419
  @@ -161,6 +161,10 @@ test("desktop placement: below a button, aligned by edge, flipping above when it
29420
  // A button near the left edge with end alignment is clamped to the margin.
29421
  const edge = { left: 10, top: 100, right: 32, bottom: 122 };
 
29437
  const spinner = renderToStaticMarkup(h(SpinnerIcon, { size: 12, label: "Agent running", className: "row-status" }));
29438
  assert.match(spinner, /width="12"/);
29439
  assert.match(spinner, /stroke-width="2\.8"/);
29440
+ @@ -291,7 +296,7 @@ test("a classic menu: main's dropdown look, paths cut at their left, a footer an
29441
+ ];
29442
+ const html = surface({ classic: true, items: classicItems, footer: h("form", { className: "footer" }, "New worktree") });
29443
+ // A footer stands after the list, so the surface is a dialog holding a menu.
29444
+ - assert.match(html, /^<div class="sidebar-menu is-classic" role="dialog" aria-label="Session actions"[^>]*><div role="menu" aria-label="Session actions">/);
29445
+ + assert.match(html, /^<div class="sidebar-menu is-classic" role="dialog" aria-label="Session actions"[^>]*><div class="ui-scroll-rail" aria-hidden="true"><div class="ui-scroll-thumb" hidden=""><\/div><\/div><div role="menu" aria-label="Session actions">/);
29446
+ assert.match(html, /<\/div><form class="footer">New worktree<\/form><\/div>$/);
29447
+ // A path is cut at its left, the text kept left to right.
29448
+ assert.match(html, /<span class="sidebar-menu-label is-mono is-path"><span>~\/work\/app<\/span><\/span>/);
29449
+ @@ -308,7 +313,7 @@ test("a classic menu: main's dropdown look, paths cut at their left, a footer an
29450
+ test("filter markup: a field above the list, the empty label, focus only on a desktop", () => {
29451
+ // A menu holds only items: the field and the empty label stand before it, in a dialog.
29452
+ const html = surface({ items: projectMenu, filter, filterQuery: "" });
29453
+ - assert.match(html, /^<div class="sidebar-menu" role="dialog" aria-label="Session actions" style="width:208px"><div class="sidebar-menu-filter"><input class="sidebar-menu-filter-input" placeholder="Filter projects…" aria-label="Filter projects…" [^>]*data-sidebar-menu-filter="" data-sidebar-menu-autofocus="" value=""\/><\/div><div role="status"><\/div><div role="menu" aria-label="Session actions"><button/);
29454
+ + assert.match(html, /^<div class="sidebar-menu" role="dialog" aria-label="Session actions" style="width:208px"><div class="ui-scroll-rail" aria-hidden="true"><div class="ui-scroll-thumb" hidden=""><\/div><\/div><div class="sidebar-menu-filter"><input class="sidebar-menu-filter-input" placeholder="Filter projects…" aria-label="Filter projects…" [^>]*data-sidebar-menu-filter="" data-sidebar-menu-autofocus="" value=""\/><\/div><div role="status"><\/div><div role="menu" aria-label="Session actions"><button/);
29455
+ assert.equal((html.match(/role="menu"/g) ?? []).length, 1);
29456
+ assert.equal((html.match(/role="menuitemradio"/g) ?? []).length, 8);
29457
+ const narrowed = surface({ items: projectMenu, filter, filterQuery: "pi-web" });
29458
  diff --git a/components/SidebarMenu.tsx b/components/SidebarMenu.tsx
29459
+ index d4a5d1e..4f4685d 100644
29460
  --- a/components/SidebarMenu.tsx
29461
  +++ b/components/SidebarMenu.tsx
29462
  @@ -3,6 +3,7 @@
29463
  import { Children, useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent as ReactKeyboardEvent, type ReactNode, type Ref, type SyntheticEvent } from "react";
29464
  import { createPortal } from "react-dom";
29465
  import { CheckIcon } from "./SidebarIcons";
29466
+ +import { useOverlayScrollbar } from "./ui/overlay-scrollbar";
29467
 
29468
  /**
29469
  * The session sidebar's popup menu: a row's ⋯ or right-click menu, a project
 
29523
  onActivate,
29524
  onClose,
29525
  }: SidebarMenuSurfaceProps) {
29526
+ + const [desktopRef, scrollRail] = useOverlayScrollbar<HTMLDivElement>(surfaceRef);
29527
  const custom = hasCustomMenuBody(children);
29528
  const hasFooter = !custom && hasCustomMenuBody(footer);
29529
  const filtered = filter !== undefined && !custom && sidebarMenuHasFilter(items, filter.minChoices);
29530
+ @@ -537,13 +551,14 @@ export function SidebarMenuSurface({
29531
  if (!sheet) {
29532
  return (
29533
  <div
 
29536
  className={classic ? "sidebar-menu is-classic" : "sidebar-menu"}
29537
  role={menuRole ?? "dialog"}
29538
  aria-label={ariaLabel}
29539
+ style={{ width }}
29540
+ {...isolateEvents}
29541
+ >
29542
+ + {scrollRail}
29543
+ {body}
29544
+ </div>
29545
+ );
29546
  diff --git a/components/SkillsConfig.tsx b/components/SkillsConfig.tsx
29547
  index e479822..18169ed 100644
29548
  --- a/components/SkillsConfig.tsx
 
32485
  +});
32486
  diff --git a/components/ui/composer-list.tsx b/components/ui/composer-list.tsx
32487
  new file mode 100644
32488
+ index 0000000..0111e63
32489
  --- /dev/null
32490
  +++ b/components/ui/composer-list.tsx
32491
+ @@ -0,0 +1,145 @@
32492
  +"use client";
32493
  +
32494
  +// The composer's suggestion list ("/" commands, "@" files, input history): a
 
32502
  +
32503
  +import { Popover } from "@base-ui/react/popover";
32504
  +import { Fragment, useEffect, useRef, type ReactNode, type RefObject } from "react";
32505
+ +import { useOverlayScrollbar } from "./overlay-scrollbar";
32506
  +
32507
  +export interface ComposerListItem {
32508
  + key: string;
 
32553
  + className?: string;
32554
  +}) {
32555
  + const rowRefs = useRef<Array<HTMLDivElement | null>>([]);
32556
+ + const [scrollerRef, scrollRail] = useOverlayScrollbar<HTMLDivElement>();
32557
  + const total = groups.reduce((sum, group) => sum + group.items.length, 0);
32558
  +
32559
  + useEffect(() => {
 
32592
  + onMouseDown={(event) => event.preventDefault()}
32593
  + >
32594
  + {header && <div className="ui-composer-list-header">{header}</div>}
32595
+ + <div ref={scrollerRef} className="ui-composer-list-scroll" role="listbox" id={listId}>
32596
+ + {scrollRail}
32597
  + {total === 0 && empty && <div className="ui-composer-list-empty">{empty}</div>}
32598
  + {groups.map((group) => group.items.length === 0 ? null : (
32599
  + <Fragment key={group.key}>
 
32636
  +}
32637
  diff --git a/components/ui/dropdowns.test.mjs b/components/ui/dropdowns.test.mjs
32638
  new file mode 100644
32639
+ index 0000000..29ff5a9
32640
  --- /dev/null
32641
  +++ b/components/ui/dropdowns.test.mjs
32642
+ @@ -0,0 +1,133 @@
32643
  +import assert from "node:assert/strict";
32644
  +import { readFileSync, readdirSync } from "node:fs";
32645
  +import test from "node:test";
 
32729
  + }
32730
  +});
32731
  +
32732
+ +test("a dropdown's own bar is hidden; while it scrolls its rows end before the thumb's lane", () => {
32733
  + const scrollers = [".ui-menu", ".ui-composer-list-scroll", ".ui-dropdown-scroll", ".sidebar-menu"];
32734
  + const sidebar = readFileSync(new URL("../../app/sidebar-menu.css", import.meta.url), "utf8");
32735
  + const rule = (source, selector) => source.match(new RegExp(`(?:^|\\n)${selector.replace(".", "\\.")} \\{([^}]*)\\}`))?.[1] ?? "";
32736
  + for (const selector of scrollers) {
32737
  + const body = rule(selector === ".sidebar-menu" ? sidebar : css, selector);
32738
+ + assert.match(body, /padding: (0|var\(--popup-inset\)) var\(--popup-inset-end\)/, `${selector} pads its right with the thumb's lane`);
32739
+ + assert.ok(css.includes(`${selector}::-webkit-scrollbar`) && /\.sidebar-menu \{ scrollbar-width: none; \}/.test(css), `${selector} hides its own bar`);
32740
+ + }
32741
+ + assert.doesNotMatch(css + sidebar, /data-scrollbar|popup-scrollbar/, "no native bar is measured any more");
32742
+ + assert.match(css, /--popup-inset-end: var\(--popup-inset\);\n --popup-scroll-lane: 8px;/, "at rest the rows' inset, scrolling a lane of 2px, the 4px thumb, 2px");
32743
+ + for (const selector of scrollers) assert.ok(css.includes(`${selector}[data-overflow]`), `${selector} takes the lane while it overflows`);
32744
+ + // Every scroller renders the rail as its first child.
32745
+ + for (const [file, scroller] of [["./menu.tsx", "ui-menu"], ["./composer-list.tsx", "ui-composer-list-scroll"], ["../ModelSelector.tsx", "ui-dropdown-scroll"], ["../SidebarMenu.tsx", "sidebar-menu"]]) {
32746
+ + const code = readFileSync(new URL(file, import.meta.url), "utf8");
32747
+ + assert.match(code, /useOverlayScrollbar/, file);
32748
+ + assert.match(code, /ref=\{(scrollerRef|desktopRef)\}[^>]*>\s*\{scrollRail\}/, `${file}: the rail opens ${scroller}`);
32749
  + }
 
 
 
 
32750
  +});
32751
  +
32752
+ +test("the thumb's track keeps clear of the surface's corners and a sticky filter, and its size follows the view", async () => {
32753
+ + const { scrollThumbGeometry, scrollThumbTrack, SCROLL_THUMB_EDGE, SCROLL_THUMB_MIN } = await jiti.import("./overlay-scrollbar.tsx");
32754
+ + assert.equal(SCROLL_THUMB_EDGE, 2, "2px inside the edge, as the app's scrollbars");
32755
+ + // A menu scrolls itself: its track starts and ends past the 10px corners.
32756
+ + assert.deepEqual(scrollThumbTrack({ radius: 10, fromSurfaceTop: 0, fromSurfaceBottom: 0, stickyTop: 0 }), { trackStart: 12, trackEnd: 12 });
32757
+ + // The composer's list scrolls under a header: only its bottom meets a corner, 4px off.
32758
+ + assert.deepEqual(scrollThumbTrack({ radius: 10, fromSurfaceTop: 48, fromSurfaceBottom: 4, stickyTop: 0 }), { trackStart: 2, trackEnd: 8 });
32759
+ + // A filter that stays on top: the track starts under it.
32760
+ + assert.equal(scrollThumbTrack({ radius: 10, fromSurfaceTop: 0, fromSurfaceBottom: 0, stickyTop: 28 }).trackStart, 30);
32761
+ + const base = { height: 400, clientHeight: 400, trackStart: 12, trackEnd: 12 };
32762
+ + assert.equal(scrollThumbGeometry({ ...base, scrollHeight: 400, scrollTop: 0 }).visible, false, "nothing to scroll, no thumb");
32763
+ + const top = scrollThumbGeometry({ ...base, scrollHeight: 800, scrollTop: 0 });
32764
+ + assert.deepEqual(top, { visible: true, top: 12, height: 188 }, "half the content in view: half the track");
32765
+ + const end = scrollThumbGeometry({ ...base, scrollHeight: 800, scrollTop: 400 });
32766
+ + assert.equal(end.top + end.height, 400 - 12, "at the end it meets the track's end");
32767
+ + assert.equal(scrollThumbGeometry({ ...base, scrollHeight: 100000, scrollTop: 0 }).height, SCROLL_THUMB_MIN, "never shorter than a grab");
32768
+ + assert.equal(scrollThumbGeometry({ ...base, height: 30, clientHeight: 30, scrollHeight: 90, scrollTop: 0 }).visible, false, "no room for a track");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32769
  +});
32770
  +
32771
  +test("a menu's surface never draws the focus ring: its highlighted row shows focus", () => {
 
32775
  +});
32776
  diff --git a/components/ui/menu.tsx b/components/ui/menu.tsx
32777
  new file mode 100644
32778
+ index 0000000..34fa05e
32779
  --- /dev/null
32780
  +++ b/components/ui/menu.tsx
32781
+ @@ -0,0 +1,221 @@
32782
  +"use client";
32783
  +
32784
  +// Menus on Base UI (`@base-ui/react/menu`): keyboard navigation, typeahead,
 
32794
  +import type { ComponentProps, ReactNode } from "react";
32795
  +import { CarbonIcon } from "../CarbonIcon";
32796
  +import * as Carbon from "../carbon/icons";
32797
+ +import { useOverlayScrollbar } from "./overlay-scrollbar";
32798
  +
32799
  +export const MenuRoot = Menu.Root;
32800
  +export const MenuTrigger = Menu.Trigger;
 
32837
  + /** A fixed width; menus otherwise size to their longest item. */
32838
  + width?: number;
32839
  +}) {
32840
+ + const [scrollerRef, scrollRail] = useOverlayScrollbar<HTMLDivElement>();
32841
  + return (
32842
  + <Menu.Portal>
32843
  + <Menu.Positioner className="ui-positioner" side={side} align={align} sideOffset={sideOffset} alignOffset={alignOffset}>
32844
+ + <Menu.Popup ref={scrollerRef} className={className ? `ui-menu ${className}` : "ui-menu"} style={width ? { width } : undefined}>
32845
+ + {scrollRail}
32846
  + {children}
32847
  + </Menu.Popup>
32848
  + </Menu.Positioner>
 
32951
  + /** Where focus goes when the menu closes (default: back where it was). */
32952
  + finalFocus?: ComponentProps<typeof Menu.Popup>["finalFocus"];
32953
  +}) {
32954
+ + const [scrollerRef, scrollRail] = useOverlayScrollbar<HTMLDivElement>();
32955
  + const anchor = point
32956
  + ? { getBoundingClientRect: () => DOMRect.fromRect({ x: point.x, y: point.y, width: 0, height: 0 }) }
32957
  + : null;
 
32959
  + <Menu.Root open={point !== null} onOpenChange={(open) => { if (!open) onClose(); }} modal={false}>
32960
  + <Menu.Portal>
32961
  + <Menu.Positioner className="ui-positioner" anchor={anchor} side="bottom" align="start" sideOffset={2}>
32962
+ + <Menu.Popup ref={scrollerRef} className="ui-menu" style={width ? { width } : undefined} finalFocus={finalFocus}>
32963
+ + {scrollRail}
32964
  + {children}
32965
  + </Menu.Popup>
32966
  + </Menu.Positioner>
 
33000
  + </Menu.SubmenuRoot>
33001
  + );
33002
  +}
33003
+ diff --git a/components/ui/overlay-scrollbar.tsx b/components/ui/overlay-scrollbar.tsx
33004
+ new file mode 100644
33005
+ index 0000000..fb06a61
33006
+ --- /dev/null
33007
+ +++ b/components/ui/overlay-scrollbar.tsx
33008
+ @@ -0,0 +1,182 @@
33009
+ +"use client";
33010
+ +
33011
+ +// A dropdown's scrollbar. The native bar took room (Chromium here,
33012
+ +// app/globals.css) and, as wide as the inset, ran flat against the surface's
33013
+ +// edge and into its rounded corners. The scroller's own bar is hidden
33014
+ +// (app/ui.css) and scrolling stays native: wheel, keys, touch and the menus' own
33015
+ +// focus moves. This thumb shows where the view is and can be dragged. It sits
33016
+ +// 2px inside the edge, its track clear of the surface's corners and of a sticky
33017
+ +// filter above the rows; while it shows, the scroller is marked `data-overflow`
33018
+ +// and the rows end before its lane. Its rail is the scroller's first child,
33019
+ +// sticky at the top, so it moves with the surface (its opening scale too) and
33020
+ +// never lags its scroll.
33021
+ +
33022
+ +import { useCallback, useRef, type MouseEvent as ReactMouseEvent, type ReactNode, type Ref } from "react";
33023
+ +
33024
+ +/** The thumb's gap to the surface's edge, and its shortest length, in px. */
33025
+ +export const SCROLL_THUMB_EDGE = 2;
33026
+ +export const SCROLL_THUMB_MIN = 24;
33027
+ +
33028
+ +export interface ScrollThumbGeometry {
33029
+ + visible: boolean;
33030
+ + /** From the scroller's top edge, in its own px. */
33031
+ + top: number;
33032
+ + height: number;
33033
+ +}
33034
+ +
33035
+ +/** Where the thumb goes: on a track from `trackStart` to `trackEnd` px inside the scroller's height. */
33036
+ +export function scrollThumbGeometry({ height, clientHeight, scrollHeight, scrollTop, trackStart, trackEnd }: {
33037
+ + height: number;
33038
+ + clientHeight: number;
33039
+ + scrollHeight: number;
33040
+ + scrollTop: number;
33041
+ + trackStart: number;
33042
+ + trackEnd: number;
33043
+ +}): ScrollThumbGeometry {
33044
+ + const range = scrollHeight - clientHeight;
33045
+ + const track = height - trackStart - trackEnd;
33046
+ + if (range < 1 || track < SCROLL_THUMB_MIN) return { visible: false, top: 0, height: 0 };
33047
+ + const size = Math.min(track, Math.max(SCROLL_THUMB_MIN, track * (clientHeight / scrollHeight)));
33048
+ + const progress = Math.min(1, Math.max(0, scrollTop / range));
33049
+ + return { visible: true, top: trackStart + progress * (track - size), height: size };
33050
+ +}
33051
+ +
33052
+ +/**
33053
+ + * The track's ends: clear of the surface's rounded corners (its radius, from the
33054
+ + * surface's edge, plus the gap the thumb keeps from its side) and below a sticky
33055
+ + * header in the scroller (a filter line).
33056
+ + */
33057
+ +export function scrollThumbTrack({ radius, fromSurfaceTop, fromSurfaceBottom, stickyTop }: {
33058
+ + radius: number;
33059
+ + fromSurfaceTop: number;
33060
+ + fromSurfaceBottom: number;
33061
+ + stickyTop: number;
33062
+ +}): { trackStart: number; trackEnd: number } {
33063
+ + const corner = radius + SCROLL_THUMB_EDGE;
33064
+ + return {
33065
+ + trackStart: Math.max(SCROLL_THUMB_EDGE, corner - fromSurfaceTop, stickyTop + SCROLL_THUMB_EDGE),
33066
+ + trackEnd: Math.max(SCROLL_THUMB_EDGE, corner - fromSurfaceBottom),
33067
+ + };
33068
+ +}
33069
+ +
33070
+ +const SURFACE = ".ui-menu, .ui-composer-list, .ui-dropdown, .sidebar-menu";
33071
+ +
33072
+ +function attach(scroller: HTMLElement, rail: HTMLElement, thumb: HTMLElement): () => void {
33073
+ + let frame = 0;
33074
+ + let geometry: ScrollThumbGeometry = { visible: false, top: 0, height: 0 };
33075
+ + let track = { trackStart: 0, trackEnd: 0 };
33076
+ + const measure = () => {
33077
+ + const style = getComputedStyle(scroller);
33078
+ + const surface = (scroller.closest(SURFACE) as HTMLElement | null) ?? scroller;
33079
+ + // Rects carry the surface's opening scale; offsets do not: divide it out.
33080
+ + const outer = surface.getBoundingClientRect();
33081
+ + const inner = scroller.getBoundingClientRect();
33082
+ + const scale = surface.offsetHeight ? outer.height / surface.offsetHeight : 1;
33083
+ + let stickyTop = 0;
33084
+ + for (const child of Array.from(scroller.children)) {
33085
+ + if (child === rail || !(child instanceof HTMLElement)) continue;
33086
+ + if (getComputedStyle(child).position !== "sticky") break;
33087
+ + stickyTop = Math.max(stickyTop, (child.getBoundingClientRect().bottom - inner.top) / scale);
33088
+ + }
33089
+ + track = scrollThumbTrack({
33090
+ + radius: parseFloat(getComputedStyle(surface).borderTopRightRadius) || 0,
33091
+ + fromSurfaceTop: (inner.top - outer.top) / scale,
33092
+ + fromSurfaceBottom: (outer.bottom - inner.bottom) / scale,
33093
+ + stickyTop,
33094
+ + });
33095
+ + geometry = scrollThumbGeometry({
33096
+ + height: scroller.offsetHeight,
33097
+ + clientHeight: scroller.clientHeight,
33098
+ + scrollHeight: scroller.scrollHeight,
33099
+ + scrollTop: scroller.scrollTop,
33100
+ + ...track,
33101
+ + });
33102
+ + thumb.hidden = !geometry.visible;
33103
+ + // The rows give the thumb its lane while there is something to scroll (app/ui.css).
33104
+ + if (geometry.visible !== scroller.hasAttribute("data-overflow")) scroller.toggleAttribute("data-overflow", geometry.visible);
33105
+ + if (!geometry.visible) return;
33106
+ + // The rail sits at the scroller's content box: its top under the padding, its right before it.
33107
+ + const paddingTop = parseFloat(style.paddingTop) || 0;
33108
+ + const paddingRight = parseFloat(style.paddingRight) || 0;
33109
+ + thumb.style.top = `${geometry.top - paddingTop}px`;
33110
+ + thumb.style.height = `${geometry.height}px`;
33111
+ + thumb.style.right = `${SCROLL_THUMB_EDGE - paddingRight}px`;
33112
+ + };
33113
+ + const schedule = () => {
33114
+ + cancelAnimationFrame(frame);
33115
+ + frame = requestAnimationFrame(measure);
33116
+ + };
33117
+ + measure();
33118
+ + scroller.addEventListener("scroll", measure, { passive: true });
33119
+ + const resize = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(schedule);
33120
+ + resize?.observe(scroller);
33121
+ + // Rows come and go (a filter, a list loading): the content's height changes the thumb.
33122
+ + const mutate = typeof MutationObserver === "undefined" ? null : new MutationObserver(schedule);
33123
+ + mutate?.observe(scroller, { childList: true, subtree: true });
33124
+ +
33125
+ + // Dragging the thumb scrolls by as much as it moves along the track, in the surface's px.
33126
+ + const onPointerDown = (event: PointerEvent) => {
33127
+ + if (event.button !== 0 || !geometry.visible) return;
33128
+ + event.preventDefault(); // focus stays where it was (a menu's row, the filter)
33129
+ + event.stopPropagation();
33130
+ + const surface = (scroller.closest(SURFACE) as HTMLElement | null) ?? scroller;
33131
+ + const scale = surface.offsetHeight ? surface.getBoundingClientRect().height / surface.offsetHeight : 1;
33132
+ + const startY = event.clientY;
33133
+ + const startScroll = scroller.scrollTop;
33134
+ + const travel = scroller.offsetHeight - track.trackStart - track.trackEnd - geometry.height;
33135
+ + const ratio = travel > 0 ? (scroller.scrollHeight - scroller.clientHeight) / travel : 0;
33136
+ + thumb.setPointerCapture(event.pointerId);
33137
+ + thumb.setAttribute("data-dragging", "");
33138
+ + const move = (moveEvent: PointerEvent) => {
33139
+ + scroller.scrollTop = startScroll + ((moveEvent.clientY - startY) / scale) * ratio;
33140
+ + };
33141
+ + const end = () => {
33142
+ + thumb.removeAttribute("data-dragging");
33143
+ + thumb.removeEventListener("pointermove", move);
33144
+ + thumb.removeEventListener("pointerup", end);
33145
+ + thumb.removeEventListener("pointercancel", end);
33146
+ + };
33147
+ + thumb.addEventListener("pointermove", move);
33148
+ + thumb.addEventListener("pointerup", end);
33149
+ + thumb.addEventListener("pointercancel", end);
33150
+ + };
33151
+ + thumb.addEventListener("pointerdown", onPointerDown);
33152
+ + return () => {
33153
+ + cancelAnimationFrame(frame);
33154
+ + scroller.removeEventListener("scroll", measure);
33155
+ + resize?.disconnect();
33156
+ + mutate?.disconnect();
33157
+ + thumb.removeEventListener("pointerdown", onPointerDown);
33158
+ + };
33159
+ +}
33160
+ +
33161
+ +/**
33162
+ + * A callback ref for a dropdown's scroller (`also` receives the node too), and
33163
+ + * the rail to render as its first child.
33164
+ + */
33165
+ +export function useOverlayScrollbar<T extends HTMLElement>(also?: Ref<T>): [(node: T | null) => void, ReactNode] {
33166
+ + const scroller = useRef<T | null>(null);
33167
+ + const rail = useRef<HTMLDivElement | null>(null);
33168
+ + const thumb = useRef<HTMLDivElement | null>(null);
33169
+ + const stop = useRef<(() => void) | null>(null);
33170
+ + const connect = useCallback(() => {
33171
+ + stop.current?.();
33172
+ + stop.current = scroller.current && rail.current && thumb.current ? attach(scroller.current, rail.current, thumb.current) : null;
33173
+ + }, []);
33174
+ + const ref = useCallback((node: T | null) => {
33175
+ + scroller.current = node;
33176
+ + connect();
33177
+ + if (typeof also === "function") also(node);
33178
+ + else if (also) (also as { current: T | null }).current = node;
33179
+ + }, [also, connect]);
33180
+ + const railRef = useCallback((node: HTMLDivElement | null) => { rail.current = node; connect(); }, [connect]);
33181
+ + const thumbRef = useCallback((node: HTMLDivElement | null) => { thumb.current = node; connect(); }, [connect]);
33182
+ + // A click on the thumb must not reach the rows' handlers (a menu would take it as outside its items).
33183
+ + const swallow = useCallback((event: ReactMouseEvent) => event.stopPropagation(), []);
33184
+ + const element = (
33185
+ + <div ref={railRef} className="ui-scroll-rail" aria-hidden="true">
33186
+ + <div ref={thumbRef} className="ui-scroll-thumb" hidden onClick={swallow} />
33187
+ + </div>
33188
+ + );
33189
+ + return [ref, element];
33190
+ +}
33191
  diff --git a/components/ui/popover.tsx b/components/ui/popover.tsx
33192
  new file mode 100644
33193
  index 0000000..1e96650
 
33231
  + </Popover.Portal>
33232
  + );
33233
  +}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33234
  diff --git a/components/ui/select.test.mjs b/components/ui/select.test.mjs
33235
  new file mode 100644
33236
  index 0000000..668e391
 
35784
 
35785
  diff --git a/docs/agents/desktop-shell.md b/docs/agents/desktop-shell.md
35786
  new file mode 100644
35787
+ index 0000000..628d848
35788
  --- /dev/null
35789
  +++ b/docs/agents/desktop-shell.md
35790
  @@ -0,0 +1,75 @@
 
35793
  +Pi Web's frame follows Claude Code Desktop's Code tab: a sidebar of sessions, a header, then the conversation and the panes it opened as tiles. Pi's power stays reachable through "/", the composer's "+" menu, the title's session menu and Settings rather than permanent chrome. Popups are Base UI (`@base-ui/react` 1.8.0) through the wrappers in `components/ui/`, styled in `app/ui.css`; the header and tiles in `app/shell.css`. The Code tab is claude.ai web code (its chunks are on assets-proxy.anthropic.com, no Cloudflare there); the tile behaviour below was read from its tile engine and side-pane store, not from screenshots. The conversation outline (upstream's ChatMinimap) is removed.
35794
  +
35795
  +## Dropdowns (`app/ui.css` "dropdowns", `components/ui/menu.tsx`, `app/sidebar-menu.css`)
35796
+ +- **One set of proportions for every dropdown**, kept as `--popup-*` tokens. On a desktop, `design/dropdown-compact-reference.jpg`'s (a desktop capture at 2x: rows 24px, inset about 4px, surface rounded 10px, icons centred 19.5px and text 34px from the edge): at 13px, a 10px surface (hairline + soft shadow, `--popup-shadow`), rows 24px inset 4px and rounded 6px (the surface's radius is the inset plus the row's), icons 12px from the edge (centred at 19px), text at 34px, section labels 12px `--text-dim` in sentence case on the icon column, separators edge to edge with the inset above and below, a row's description inline after its label. Touch screens (`pointer: coarse`) keep the phone captures' scale (`design/dropdown-spacing-reference.jpg`, `design/model-dropdown-reference.jpg`, 2.81x): 15px, 32px rows, 8px inset, 16px surface. A dropdown that scrolls hides its own scrollbar (Chromium's took room and, as wide as the inset, ran flat against the edge and into the rounded corners) and `components/ui/overlay-scrollbar.tsx` draws the thumb: a sticky zero-height rail as the scroller's first child, the thumb 2px inside the edge (as the app's scrollbars), 4px wide (6px under the pointer or dragged, the app's colours), its track clear of the corners (radius + 2px) and of a sticky filter; it drags, and wheel, keys and touch stay native. While there is something to scroll the scroller is marked `data-overflow` and `--popup-inset-end` becomes the 8px lane (2px, thumb, 2px), so the thumb never covers a row, its highlight or its check; separators still reach the edge. Headless Chromium hides scrollbars: tests that check this launch without `--hide-scrollbars`. `components/ui/dropdowns.test.mjs` checks each scale's ratios against its reference and that the sidebar's menus use the tokens.
35797
  +- Who follows it: Base UI menus (`.ui-menu`), the "/" "@" and history list (`.ui-composer-list`: its scroller holds the side inset so a group's line can reach the edges), popovers (content on the icon column), the sidebar's menus and their filter (a plain line like the reference's "Search here…"; the files tab's `classic` look is gone, only paths keep code type), the phone sheet (the same inset rounded rows, 44px), the model field (`ModelSelector`/`SelectorRow`: `.ui-dropdown-*`, check on the right as in the menus), and the header's panels (`.header-dropdown`: session info, system prompt, tools, subagents, branches, inset 8px under the header).
35798
  +- **One icon column**: model rows carry their maker's mark (`components/ModelMark.tsx`: the repo's organisation on a router such as Hugging Face, else the provider; brand colours in grays), whatever has no icon starts on the icon column as the references' section labels and search line do (the effort levels, the model field's clear row: never an empty icon's room before a label), "/" rows show their kind (the "+" menu's icons: commands, connectors, a page for prompts, skills) and history rows a clock.
35799
  +- **`MenuSection`** is the only way to label a group: Base UI throws on a `GroupLabel` outside a `Group`, and the Browser pane's ⋯ menu did that, which took the page down.