Implement the following plan: FigJam-like Infinite Canvas for Pages Context Pages…
- User
Implement the following plan:
FigJam-like Infinite Canvas for Pages
Context
Pages currently store a single HTML blob (
content) and render it statically. Clicking a page in the sidebar shows a metadata view (page_show.erb) with conversation buttons — not the actual canvas content. The canvas overlay only appears when a chat tab with apageIdis active, and even then it's just a raw HTML dump. This makes the canvas feel empty and disconnected.Goal: Transform pages into FigJam-like infinite canvases with positioned components/widgets that the AI creates. Users can pan, zoom, and drag components. The chat has full context of what's on the canvas.
Plan
1. Migration:
canvas_componentstableFile:
workspace/migrations/20260218000001_create_canvas_components.rbcodecanvas_components: - ai_page_id (FK, not null) - component_type (string, default 'card') - content (text, HTML) - x, y (float, default 0) - width (float, default 320) - height (float, nullable = auto-height) - z_index (integer, default 0) - metadata (json, default {}) - timestampsAlso add
canvas_state(json) column toai_pagesfor persisting viewport pan/zoom.2. Model:
CanvasComponentFile:
ai/models/canvas_component.rbbelongs_to :ai_pagescope :ordered(by z_index, created_at)#as_canvas_json— returns hash with id, type, content, x, y, width, height, z_index, metadata- Update
ai/models/ai_page.rb: addhas_many :canvas_components, dependent: :destroy
3. API Routes
File:
web/app.rb— insider.on 'api'Restructure
r.on 'pages', Integerto add component CRUD:GET /api/pages/:id/canvas— returns JSON{ components: [...], canvas_state: {} }(replaces current raw HTML endpoint)PATCH /api/pages/:id/components/:id— update position (drag-drop saves)
Assistant
I'll implement this step by step. Let me start by reading the key files I need to understand.
Assistant
Now let me read the key files I need to understand.
Assistant
Let me check existing migrations and a tool example for patterns.
Assistant
Good, I now have full context. Let me start implementing. I'll work through the tasks in order.
Task 1: Migration
Assistant
Task 2: Model + update AiPage
Assistant
Task 3: API Routes
Assistant
Task 4: MCP Tools
Assistant
Task 5: Canvas Stimulus Controller
Assistant
Now register it in application.js:
Assistant
Task 6: Update chat footer controller and sidebar
Update
loadCanvasByPageto fetch JSON and render positioned components:Assistant
Now update the sidebar links in layout.erb to open canvas tabs directly:
Assistant
Task 7: CSS Styles and CLAUDE.md update
Assistant
Now update workspace/CLAUDE.md with the new tools:
Assistant
Now run the migration:
Assistant
Migration ran successfully. Let me mark the last task complete:
Assistant
All tasks complete. Here's a summary of what was implemented:
Files created
workspace/migrations/20260218000001_create_canvas_components.rb—canvas_componentstable +canvas_statecolumn onai_pagesai/models/canvas_component.rb— Model withbelongs_to :ai_page,orderedscope,as_canvas_jsonai/tools/add_canvas_component_tool.rb— AI adds positioned widgets to canvasai/tools/update_canvas_component_tool.rb— AI updates content/position
- User
Real-time Updates Flow
codeAI calls add_canvas_component → creates CanvasComponent record → builds Turbo Stream HTML: <turbo-stream action="append" target="canvas-components-{pageId}"> → broadcasts to conversation:#{conv.id} for each linked conversation → SSE delivers to browser (existing EventSource in chat_footer_controller) → Turbo appends new div to .canvas-world → Canvas controller's MutationObserver picks it up (applies drag handlers)No new SSE channels needed — piggybacks on existing conversation streams.
Verification
- Start server:
./ai.rb server - Click "+" to create new canvas — should show empty canvas with dot grid
- Send a message asking AI to add components — components should appear in real-time
- Pan (drag empty space) and zoom (scroll wheel) the canvas
- Drag a component — should persist position on drop
- Click a page in sidebar — should open canvas tab directly
- Start server:
- User
- User
commit
Assistant
Committed as
4ef3488— 14 files changed, 633 insertions.