Skip to content

Slots and screens

Module widgets change the interface in three ways: they add components to slots inside core screens, they replace whole core screens, and they register their own page and settings page. This page lists every slot and route, where each one renders, what it receives, and how contributions are ordered and isolated. The registry lives in src/widgets/host.tsx; the slots are placed in src/App.tsx, src/screens/Accounts.tsx, and src/screens/Dashboard.tsx.

┌──────────────┬───────────────────────────────────────────────────────────┐
│ Sidebar │ /accounts │
│ │ ┌───────────────────────────────────────────────────────┐ │
│ Dashboard │ │ Accounts [accounts.toolbar] [place field] [actions] │ │
│ Accounts │ └───────────────────────────────────────────────────────┘ │
│ Widgets │ ┌───────────────────────────────────────────────────────┐ │
│ Settings │ │ (avatar) Name @user [place] [presence] [Join] │ │
│ │ │ [accounts.row ……………………………………] │ │
│ Widgets │ │ notes │ │
│ My widget │ └───────────────────────────────────────────────────────┘ │
│ │ │
│ GitHub v0.2 │ / (Dashboard) │
│[sidebar. │ hero │
│ footer] │ [Accounts] [In game] [Widgets enabled] [dashboard.stats] │
└──────────────┤ Recently played │
│ [dashboard.sections] │
│ dashboard.html frames, one section per widget │
└───────────────────────────────────────────────────────────┘
Slot Props Placement Wrapper
accounts.row { account: Account } Under each account’s name on the Accounts page, above the notes field. Rendered once per account row. <div class="mt-1 flex flex-wrap items-center gap-1.5"> around all contributions for that row.
accounts.toolbar {} Start of the Accounts page header actions, before the default place field. None. Contributions sit directly in the header’s flex row.
accounts.selection {} The Accounts selection bar, shown while selecting accounts, after Join selected. Added in 0.5.2. None. Contributions sit in the bar’s flex row.
dashboard.stats {} After the three built-in Dashboard stat tiles (Accounts, In game, Widgets enabled), in the same grid. None. Each contribution is a grid item.
dashboard.sections {} Below the Dashboard stats and the Recently played list, above the dashboard.html frames. <div class="flex flex-col gap-4"> around all contributions.
sidebar.footer { collapsed: boolean } Bottom of the sidebar, below the GitHub link and version. None.
page.topbar {} The header of the contributing widget’s own page, before the theme and window buttons, in the main window and in the widget’s own window. Only the page’s own widget’s contributions render. None. Contributions sit in the header’s flex row.

Outside page.topbar, Toolblox wraps each contribution in a relative element and puts the ui.FromWidget mark at its top-right corner. The wrapper is block in dashboard.stats and dashboard.sections, and inline-flex elsewhere. A contribution that renders nothing shows no mark.

Receives the row’s Account. The component renders for every account on every Accounts page render, so keep it cheap and read shared data from a store rather than fetching per row. Return null to show nothing for an account; the wrapper div still renders while any widget contributes to the slot.

Badges and short tags fit the space best:

toolblox.addToSlot("accounts.row", ({ account }) =>
account.presence === "playing" ? h(ui.Badge, { variant: "outline" }, "Farming") : null);

Sits in the Accounts page header, which is a single row 56 px tall shared with the page title, the default place field, and the page’s own actions. Contribute compact controls such as an IconButton or a small Button:

toolblox.addToSlot("accounts.toolbar", () =>
h(ui.IconButton, { label: "Sync races", onClick: () => void sync() }, syncIcon));

Each contribution becomes one cell of the stat grid, which uses grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)) with 12 px gaps. Use ui.StatTile to match the built-in tiles, or render your own element of similar height:

toolblox.addToSlot("dashboard.stats", () =>
h(ui.StatTile, { icon: bagIcon, label: "Shop items in stock", value: 3, onClick: () => toolblox.navigate(`/widgets/${toolblox.widget.id}`) }));

Full-width sections stacked with 16 px gaps. The usual pattern is a SectionTitle over a Panel, matching the Recently played section above it:

toolblox.addToSlot("dashboard.sections", () =>
h("section", { className: "flex flex-col gap-2" },
h(ui.SectionTitle, null, "Shop stock"),
h(ui.Panel, { className: "divide-y" }, rows)));

Receives collapsed, which is true while the sidebar is dragged to its icon-only width. Render an icon-only control when collapsed and a labelled one otherwise. The sidebar can also be on the right side of the window, depending on the user’s settings.

toolblox.addToSlot("sidebar.footer", ({ collapsed }) =>
collapsed ? h(ui.IconButton, { label: "Timer" }, clockIcon) : h(ui.Button, { variant: "ghost", size: "sm" }, clockIcon, "Timer"));

addToSlot accepts { order?: number }, default 0. After every registration, the slot’s list is sorted by ascending order. The sort is stable, so contributions with equal order keep the order they were registered in. Module widgets load one at a time in widget ID order, so with equal order values a widget whose ID sorts first usually renders first. Use negative values to move ahead of other contributions and large values to move to the end:

toolblox.addToSlot("dashboard.stats", Summary, { order: -10 });
toolblox.addToSlot("dashboard.stats", Details, { order: 100 });

Built-in content always stays where it is: order only orders widget contributions within the slot.

Each contribution renders inside its own error boundary, keyed by widget ID and position. If a contribution throws while rendering, only that contribution is replaced with an inline message, <widget name> failed to render. Does reinstalling it help? (<error>), with role="alert", and the error and component stack are logged under widget:<id>. Other contributions in the slot and the rest of the screen keep working. A slot with no contributions renders nothing at all, including its wrapper.

See Logs and failures.

replaceScreen(screen, Component) swaps a core screen for a widget component.

Screen Route Replaceable
"dashboard" / Yes
"accounts" /accounts Yes
"widgets" /widgets Yes
Settings /settings No
Widget pages /widgets/<id>, /widgets/<id>/settings No. Each widget registers its own.

Rules:

  • The replacement receives no props. Read state with toolblox.useAppState() and act through the host API.
  • It replaces the whole screen, including the header. The core screen and its slots don’t render, so other widgets’ contributions to those slots disappear while it’s replaced.
  • It renders inside an error boundary. A replacement that throws shows the inline failure message in place of the screen; the sidebar, Settings, and safe mode controls stay available.
  • The latest registration for a screen wins, across all widgets. Disposing a replacement restores the core screen only if the disposing widget still owns it; it doesn’t restore an earlier widget’s replacement.
  • Settings can’t be replaced, so users can always reach Diagnostics and the controls that turn widgets off.

To match the app’s layout, cap content at max-w-[120rem] with 24 px side padding, and follow the interface conventions.

Every installed widget gets two routes and a sidebar entry, whether or not it registers anything.

The sidebar’s widget entry opens this route. The entry shows the widget’s name and is disabled while the widget is disabled. The page renders, in order of precedence:

  1. The component from registerPage, inside an error boundary.
  2. Otherwise, the index.html frame when the manifest declares entry.
  3. Otherwise, an empty state: No page, “This widget adds features to other parts of Toolblox.”

The host wraps the page in the standard screen layout: a sticky 56 px header with the widget’s name, the widget’s page.topbar entries, a settings button when the widget has a Settings tab, and content capped at max-w-[120rem]. While the widget is in its own window, the page shows a link to that window and a Return here button instead. The widget page’s screen container is a flex column with h-full, which lets an index.html frame grow to fill the window height. A registered page is a child of that column.

Opens Settings on the widget’s tab, named after the widget. It’s reached from Settings in the menu that right-clicking the widget opens, in the sidebar or on the Widgets page, and in the card’s More actions menu. The tab appears when the widget is enabled and any of these is true: the manifest declares settingsEntry, the manifest declares at least one process, the widget registered a settings component, or the widget is in its own window. The tab renders, top to bottom:

  1. The component from registerSettings, inside an error boundary.
  2. The settings.html frame when the manifest declares settingsEntry. While the widget is in its own window, both are replaced by a Show window button, because the widget’s module runs in that window.

When the widget is disabled, not installed, or the app is in safe mode, both routes show Page unavailable with a button back to the Dashboard. Widget IDs in routes match [\w-]+.

Goal Use
A tool with its own screen registerPage
Per-widget preferences registerSettings, with values in storage
Per-account information on the Accounts page accounts.row
An action that applies to accounts accounts.toolbar
A number at a glance dashboard.stats
A summary or list on the Dashboard dashboard.sections
A persistent control or status sidebar.footer
A different Dashboard, Accounts, or Widgets experience replaceScreen
A new look for the whole app addStyles