Add the dashboard settings channel, wired for theme and lock

A dashboard could only ever receive as a set of tiles. This adds the dashboard
itself as a receiver: `settings` maps a name to a value plus an optional
binding. Unbound, the setting is simply its value — a wall panel that is always
dark costs no flow. Bound, a flow drives it live and the value is the fallback.

Two settings are wired: `theme` (system/light/dark) and `locked` (read-only).
There is no schedule field on purpose — a node publishing to the bound message
on a cron is what a schedule is here, which is the point of a channel.

- `messages_for()` now walks a dashboard's bound settings as well as its
  widgets' bindings. Without this a paired screen is refused its own theme
  message, on the one surface the setting exists for; it bounds the socket too.
- `locked` is gated in `usePublish`, so every control inherits it, and each
  control also draws itself disabled — a dead button reads as broken otherwise.
  The panel surface says Read-only in the corner.
- The theme is a class on the dashboard's own surface, never the root: inside
  the app shell it must not flip the chrome. `.light` gains the tokens `.dark`
  already had (mirrored in the index repo) so both directions work on a subtree.
- Settings bindings are type-checked from the document alone, the rule widget
  bindings follow, and mirrored on the server.
- A bound setting is drawn on the flow canvas as a dashboard-level endpoint.
- The demo's house flow now publishes `home.panel_theme`, which the demo
  dashboard's theme binds to: the panel goes dark after sunset, at no tile cost.
This commit is contained in:
2026-08-22 13:17:56 +02:00
parent 9993df456c
commit 1002241258
18 changed files with 784 additions and 62 deletions
+16 -1
View File
@@ -8,6 +8,7 @@ import { handleError } from "@/utils"
// chunked per entry — so the sheet is pulled in wherever the pulse is drawn.
import "./dashboard.css"
import { usePublishMessage } from "./queries"
import { useLocked } from "./settings"
/**
* How long a control shows what it sent before falling back to the engine.
@@ -35,6 +36,17 @@ function confirms(live: unknown, sent: unknown): boolean {
* is refused, or on `HOLD_MS`; success is silent, because the echo is the
* confirmation.
*
* A locked dashboard is gated here and only here: every control publishes
* through this hook, so one check covers all of them and a control added later
* inherits it. `locked` is handed back so each control can also *read* as
* disabled — a dashboard that silently swallows a press looks broken rather
* than locked.
*
* ponytail: this is a read-only surface, not an authorisation boundary. The
* server still takes a publish from a panel credential whose dashboard says
* locked, because the credential's own allowlist is what bounds it. Making it
* a real lock means carrying the flag into `_panel_may`.
*
* Its own module rather than `widgets.tsx`, which every widget file is
* imported *by*: a control drawn in a file of its own can only reach this
* without closing that circle if it does not sit there.
@@ -42,6 +54,7 @@ function confirms(live: unknown, sent: unknown): boolean {
export function usePublish(widget: WidgetDef, dashboard: string) {
const cfg = (widget.config ?? {}) as Record<string, unknown>
const target = cfg.target == null ? "" : String(cfg.target)
const locked = useLocked()
const publish = usePublishMessage()
const live = useLiveValue(target || undefined)
const { showErrorToast } = useCustomToast()
@@ -62,8 +75,10 @@ export function usePublish(widget: WidgetDef, dashboard: string) {
target,
/** What the control draws: what it sent, until the engine answers. */
value: held ? held.value : live?.value,
/** Whether this dashboard is read-only; controls draw themselves disabled. */
locked,
send: (value: unknown) => {
if (!target) return
if (!target || locked) return
setHeld({ value })
publish.mutate(
{