#25
Click an element in the preview to edit it or tell the agent about it
Summary
Let people click an element in the preview and change it directly, or tell the agent about that exact element. Today every change, even one colour or one line of copy, goes through a full model turn.
Problem
- The only way to change a design is to describe the change in the chat, and the model has to find the right place in the HTML on its own.
- A small tweak costs a whole turn, which is slow and spends tokens, and for signed-in users it is billed to their team.
- Describing "the second button in the pricing card" in words is awkward and easy for the model to get wrong.
- Other design tools, such as v0 (Design Mode) and Lovable (visual edits), let you select an element in the preview and edit it.
Proposal
- Add a select mode to the preview. Hovering outlines an element, and clicking selects it.
- With an element selected, the person can do either of these:
- Type a request in the composer. The message carries the selected element, so the agent knows exactly what "this" is and can use
edit_designon it. - Change simple things in place, such as text, colour, font size and spacing, with no model call. The change applies at once and becomes a new version.
- Type a request in the composer. The message carries the selected element, so the agent knows exactly what "this" is and can use
How it could work
parseOpeningTagsinlib/design-artifact.tsalready knows where every tag sits in the stored source. The copy of the design prepared for preview can add adata-fx0-idto each tag. The stored design is not touched.- The preview frame already runs fx0's own bootstrap script and talks to the app by
postMessagewith a per-load token. The same channel can carry "element hovered" and "element selected" messages. - A new route takes an element id and an edit, maps the id back to the source range of that tag in the current revision, applies the change, and saves it through the existing
publishDesignArtifact. Versions, history and the draft fence then work as they do now. - A person's edit is recorded as its own version, with no turn, so it can be reopened like any other.
- The selected element is sent to the model as part of the message text, using the same exact-match rules
edit_designalready has.
Scope
- Select mode in the preview, plus a small panel for text, colour, font size and spacing.
- The route that applies a direct edit, with a check that the revision the person saw is still the current one.
- Sending the selected element along with a chat message.
- Tests for id assignment, mapping an id back to the source, edits that collide with a turn publishing at the same time, and messages from the frame.
Not included
- Dragging, resizing or reordering elements.
- Editing designs that use scripts to build their own markup, beyond what is in the stored HTML.
- Mobile preview editing.
Risks and open questions
- The design runs its own scripts inside the sandboxed frame, so it can send fake select messages. That should only be able to affect that design, and the app should treat every message from the frame as untrusted.
- If the agent is publishing while the person edits, one of them has to win cleanly. A revision check on the edit route would reject the older one with a clear message.
- Text that scripts rewrite at run time can look editable but not match the source. Those elements should be shown as not editable.
- It is a large change, so it may be better to land select-and-tell-the-agent first and direct property edits second.
Hey @fazxes, take a look at this one and lmk what you think. Happy to contribute! :)