Skip to content

Host core: a headless view model every UI shares - #112

Merged
agorischek merged 2 commits into
mainfrom
headless-view-model
Nov 21, 2026
Merged

agorischek merged 2 commits into
mainfrom
headless-view-model

Conversation

@agorischek

Copy link
Copy Markdown
Collaborator

Stacked on #65 (toolbar-sides), which touches ui/view.tsx; GitHub retargets it to main once #58 and #65 merge.

Why

A custom host UI had to rebuild the layer between the controller and its widgets: which views exist and which one shows, when playback, the mode switch, zoom and the varied toggle show, and what the scope switch offers. The default UI, the VS Code UI and the Playground's Primer UI each had a copy, and the copies had drifted:

  • playback beside the table and text views: in every mode in the default UI (ui/view.tsx), only in Animated in the VS Code UI and Primer;
  • the zoom group: the VS Code UI and Primer also required rendererControls, the default UI didn't;
  • the scope switch's names, titles and offered scopes, and the summary bar's toggle logic, verbatim in two or three places.

The general rule, from the user: consistent defaults, but configurable. Each behaviour has one default in the core, and a surface changes it through a typed option, never by copying the implementation.

What's in the core now

packages/host/core/src/view-model.ts (pure) and view-choice.ts (one hook), exported from @githubnext/projections-host:

Export What it decides
offeredViews, shownView, recoveryView, viewLabel The renderer's view, then the table and text views the features keep (never none); the view shown for a choice; the built-in view to offer when the renderer fails; a view's name.
useViewChoice(projection, features, initialView) {views, view, setView, recoverView}, showing the renderer's view when a renderer arrives.
viewControls(projection, {features, view, playbackInViews?}) modes, modeSwitch, scope, playback, zoom, zoomControls, varied.
scopeChoice(projection), scopeNames The scope switch's options (Noise only while it is the scope), titles with counts, and the "nothing hidden" note.
summaryToggle, summaryToggleTitle, summaryFactTitle A summary figure's filter toggle and tooltips.
ProjectionFeatures, featureOn, offeredModes, rendererLabel Moved from the default UI. /ui and the VS Code UI re-export them under their existing names (VscodeProjectionFeatures, on).

Override points:

  • playbackInViews: 'animated' | 'always' on viewControls, ProjectionView, VscodeProjectionView and both explorers;
  • the existing features, initialView and the definition's presentation.

Behaviour changes, as decided

  • Playback shows only in the Animated mode, in every view (the user's decision). The default UI's table and text views no longer show playback in side by side, swipe or diff. playbackInViews: 'always' restores that.
  • The default UI's zoom group also needs rendererControls, as the VS Code UI's and Primer's did, and draws no zoom controls while the renderer has failed.

Consumers

  • The default UI (ui/view.tsx, scope-switch.tsx, summary-bar.tsx) and the VS Code UI (view.tsx, view/toolbar-content.ts, scope-switch.tsx, summary-bar.tsx) use the core's view model. ui/features.ts is gone.
  • Primer follows in the private repository after the pin bump.

Docs

  • docs/guides/host-core.md gains "The view model", with the defaults and override points.
  • docs/guides/host-ui.md states the playback rule and points to it.

Tests

  • packages/host/core/test/view-model.test.mjs (node:test, 8 tests) covers:
    • the views and the shown view;
    • playback by mode and view, and playbackInViews: 'always';
    • the mode switch;
    • zoom and failure;
    • the varied toggle;
    • the scope choice;
    • summary toggles.
  • browser/modes.spec.ts: the table view in side by side now expects no playback.

Run locally:

  • tools check --fast: pass, typecheck included.
  • node --test test/view-model.test.mjs test/summary.test.mjs test/settings.test.mjs: 22/22.

I built only the TypeScript layers this needs (schemas, renderer SDK, the engine's js) and no Rust. Browser suites are left to CI.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The playback override enables the layout, but the VS Code Playback component still returns null outside animated mode, leaving playback hidden in the affected views.

1 open issue
What changed in this PR

This PR centralizes host UI decisions in a shared, headless view model, reducing duplicated behavior between the default UI, VS Code UI, and custom hosts.

Changes:

  • Adds shared helpers for view selection, control visibility, scope choices, and summary toggles.
  • Migrates both built-in UIs to shared defaults, with configurable playback visibility and consistent zoom gating.
  • Documents the public API and adds tests for the shared behavior.
File Description
packages/​host/​vscode-ui/​src/​view/​toolbar-content.ts Uses shared control visibility decisions.
packages/​host/​vscode-ui/​src/​view/​props.ts Adds the playback visibility option.
packages/​host/​vscode-ui/​src/​view.tsx Adopts shared view selection and controls.
packages/​host/​vscode-ui/​src/​summary-bar.tsx Uses shared summary toggles and tooltips.
packages/​host/​vscode-ui/​src/​scope-switch.tsx Uses shared scope options and labels.
packages/​host/​vscode-ui/​src/​features.ts Re-exports core features under existing names.
packages/​host/​vscode-ui/​src/​explorer.tsx Forwards the playback visibility option.
packages/​host/​core/​test/​view-model.test.mjs Tests shared view-model behavior.
packages/​host/​core/​src/​view-model.ts Defines shared features and presentation decisions.
packages/​host/​core/​src/​view-choice.ts Adds the shared view-selection hook.
packages/​host/​core/​src/​ui/​view/​props.ts Adds the playback visibility option.
packages/​host/​core/​src/​ui/​view.tsx Adopts shared view selection and controls.
packages/​host/​core/​src/​ui/​view-controls.tsx Imports view types from core.
packages/​host/​core/​src/​ui/​summary-bar.tsx Uses shared summary toggles and tooltips.
packages/​host/​core/​src/​ui/​settings-menu.tsx Imports shared feature definitions.
packages/​host/​core/​src/​ui/​scope-switch.tsx Uses shared scope choices.
packages/​host/​core/​src/​ui/​features.ts Removes definitions moved into core.
packages/​host/​core/​src/​ui/​explorer.tsx Forwards the playback visibility option.
packages/​host/​core/​src/​ui/​blocks.tsx Preserves existing feature exports.
packages/​host/​core/​src/​ui/​about.tsx Uses the shared renderer label helper.
packages/​host/​core/​src/​summary.ts Adds reusable summary toggle helpers.
packages/​host/​core/​src/​index.ts Exports the new public API.
packages/​host/​core/​browser/​modes.spec.ts Updates the side-by-side playback expectation.
docs/​guides/​host-ui.md Documents playback defaults and shared behavior.
docs/​guides/​host-core.md Documents the view model and override points.

Review effort: Balanced

@agorischek
agorischek force-pushed the toolbar-sides branch 2 times, most recently from 9197352 to 5e47319 Compare November 21, 2026 00:37
@agorischek
agorischek force-pushed the toolbar-sides branch 2 times, most recently from 993aceb to b1d2c11 Compare November 21, 2026 01:15
@agorischek
agorischek force-pushed the toolbar-sides branch 6 times, most recently from 05a5719 to b10ac76 Compare November 21, 2026 05:28
Base automatically changed from toolbar-sides to main November 21, 2026 06:21
@agorischek
agorischek force-pushed the headless-view-model branch 3 times, most recently from 415c5f4 to fcdeef9 Compare November 21, 2026 17:39
agorischek and others added 2 commits November 21, 2026 10:27
Which views a host offers and which controls show were worked out separately in the default UI, the VS Code UI and
the Playground's Primer UI, and the copies had drifted. They are now the core's (`view-model.ts`), with one default
each and typed options to change it:

- `offeredViews`, `shownView`, `recoveryView`, `viewLabel` and the `useViewChoice` hook;
- `viewControls(projection, {features, view, playbackInViews?})`: the modes and mode switch, scope, playback, zoom and
  the varied toggle;
- `scopeChoice`: the scope switch's options, titles and "nothing hidden" note;
- `summaryToggle`, `summaryToggleTitle` and `summaryFactTitle`;
- `ProjectionFeatures`, `featureOn`, `offeredModes` and `rendererLabel`, moved from the default UI.

Playback now shows only in the Animated mode, in every view, as the VS Code UI and Primer already did; the default UI
showed it beside the table and text views in every mode. `playbackInViews: 'always'` keeps that. The default UI's zoom
group, like the VS Code UI's, now also needs `rendererControls`.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…le and text views

`viewControls` could ask for playback beside the table and text views in every mode, but the VS Code UI's `Playback`
and its Space shortcut still required the Animated mode. Both now take `always` from the toolbar, as the default UI's
`Playback` does.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@agorischek
agorischek merged commit f2632e9 into main Nov 21, 2026
46 checks passed
@agorischek
agorischek deleted the headless-view-model branch November 21, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants