Commit 9a08bf6
authored
feat: support theme control via postMessage for iframe embedding (#32)
## Summary
- Adds a `postMessage` listener to `UIStore` that accepts `{type:
"theme:set", theme: "light"|"dark"}` messages
- Enables parent windows to control agentsview's theme without reloading
the iframe
- Closes #31
## Details
When agentsview is embedded as a cross-origin iframe, the host
application can now send a `theme:set` message to switch themes
instantly. This avoids the jarring reload previously needed when using
the `?theme=` URL parameter approach.
The implementation is minimal — a single
`window.addEventListener("message", ...)` in the UIStore constructor.
Since `this.theme` is a `$state` field, assigning it triggers the
existing `$effect` that updates the DOM class and persists to
localStorage.
## Protocol
```js
iframe.contentWindow.postMessage({ type: "theme:set", theme: "dark" }, "*");
```
Only `"light"` and `"dark"` are accepted; other values are silently
ignored.
## Test plan
- [x] Valid `theme:set` message changes theme
- [x] Invalid theme value (e.g. "purple") is ignored
- [x] Unrelated message types are ignored
- [x] Full test suite passes (384/384, +3 new)1 parent 8634987 commit 9a08bf6
2 files changed
Lines changed: 45 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
47 | 60 | | |
48 | 61 | | |
49 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
175 | 207 | | |
176 | 208 | | |
177 | 209 | | |
| |||
0 commit comments