# Embed Studio - Architecture Document ## Overview The Embed Studio is a dedicated UI mode within the editor for creating, editing, and previewing HTML embed visualizations (D3.js charts). It isolates the dataviz workflow from the article editing flow, providing a focused chat + preview experience similar to the standalone [dataviz-agent-space](https://huggingface.co/spaces/tfrere/dataviz-agent-space). ## Context The research-article-template uses `` components to embed self-contained D3.js charts into articles. These are `.html` files in `app/src/content/embeds/` with strict conventions (scoped CSS, IIFE scripts, ColorPalettes, responsive, etc.) documented in `.ai/skills/create-html-embed/directives.md`. In the editor, users need to create and iterate on these charts without leaving the editor. The Embed Studio solves this by providing a dedicated panel with an AI assistant specialized in D3 chart generation. ## Storage ### Y.Map("embeds") Embed HTML content is stored in a collaborative Yjs Map, keyed by filename: ``` Y.Map("embeds") = { "d3-scaling-chart.html": "
...
", "d3-performance.html": "
...
" } ``` The ProseMirror node (`htmlEmbed`) only stores the `src` attribute as a reference key. The actual HTML lives in the shared Y.Map, enabling real-time collaboration on embed content. ### Node attributes The `htmlEmbed` TipTap node stores: | Attribute | Type | Description | |-----------|------|-------------| | `src` | string | Filename key into Y.Map("embeds") | | `title` | string | Chart title (displayed above) | | `desc` | string | Chart description | | `wide` | boolean | Wide layout mode | | `downloadable` | boolean | Show download button | | `height` | number | Last known content height (pixels) | The `height` attribute eliminates layout jumps: once a chart reports its height, it is persisted and used as the iframe's initial height on subsequent loads. ## UI: Two Modes ### 1. Inline Preview (article view) When the user is editing the article, the `htmlEmbed` NodeView shows a read-only preview: ``` ┌─────────────────────────────────────────┐ │ 📊 Chart Title [Edit] [⋮] │ ├─────────────────────────────────────────┤ │ │ │