Files
archie/ui/src/chat/command-scroll.ts
T
sam 3d20dde9cb feat(webui): port the shared primitives (Phase 2)
The Preact tree's ui/src/base/ was deleted with the dashboard. This rebuilds
what depended on it, on the shadcn layer rather than as new bespoke markup.

Badge and Card come from the shadcn-vue CLI, so they match the already-vendored
components, and the composed pieces sit on top of them:

- Badge gains the five status variants the pills used, over the palette's status
  tokens. The pill's dot did not come across: the Badge's own shape is the
  affordance, and the same variant now covers a trend indicator, where a dot
  reads as noise.
- base/StatTile.vue uses full Card composition instead of dumping everything
  into one content slot, with base/Sparkline.vue and the goodDirection logic
  that says whether "up" is good news.
- base/Gauge.vue and base/SegmentBar.vue, both of them: the original exported
  two components from one file and budget composition uses the second.
- base/LogRow.vue over lib/log.ts, which holds the LOG_LEVELS wire contract
  (the server matches that CSV server-side, so it is not a display choice).
- lib/status.ts, so status colour has one home: a task state, a gate result, a
  log level and a trend all draw from the same five kinds.

Two deliberate departures:

The icon module is not ported. Its name-to-glyph string lookup is the pattern
shadcn-vue's rules call out as wrong, and nothing consumes the five bespoke
glyphs anyway: the navigation is text with tooltips. Icons come from @lucide/vue
at the call site, and the five become components if a page draws them.

The gauge's aria-label announces the rounded percentage. It announced the raw
one, so a screen reader read 71.38461538461539% where the screen showed 71%
(bead 86au).

Also lands the four modules the checklist marks copy-verbatim, which encode
bugs fixed just before the delete: dashboard/activity-detail, chat/
command-scroll, workflows/workflow-rows and logs/logs-empty.
2026-09-20 19:38:17 +10:00

42 lines
1.5 KiB
TypeScript

// Keeping the arrow-key selection visible in the command palette.
//
// The palette caps its height and scrolls, so once the matches run past the
// visible rows the selection walked off-screen and the highlight was invisible
// (archie-core-ifay). Browsers have scrollIntoView, but the decision is pure
// arithmetic and worth testing on its own, so the effect only applies what
// this returns.
/** The palette's scroll geometry and the selected option's position in it. */
export interface CommandScrollGeometry {
scrollTop: number;
viewportHeight: number;
optionTop: number;
optionHeight: number;
}
/**
* commandScrollTop returns the scrollTop that brings the selected option fully
* into view, or the current scrollTop when it is already visible. Mirrors
* `scrollIntoView({ block: "nearest" })`: it moves the minimum distance, and
* scrolls up for an option above the viewport, down for one below.
*/
export function commandScrollTop({
scrollTop,
viewportHeight,
optionTop,
optionHeight,
}: CommandScrollGeometry): number {
// An option taller than the viewport cannot be shown whole. Align its top,
// which holds the command itself; aligning the bottom would scroll the name
// out of sight and leave only the tail of its description.
if (optionHeight >= viewportHeight) return optionTop;
if (optionTop < scrollTop) return optionTop;
const optionBottom = optionTop + optionHeight;
const viewportBottom = scrollTop + viewportHeight;
if (optionBottom > viewportBottom) return optionBottom - viewportHeight;
return scrollTop;
}