Visual Editing
Visual editing in Plyy is a round trip: select an element in the live preview, edit it in the inspector, and the change is written back into the project’s .astro source files. Three packages cooperate to make that work.
The pieces
Section titled “The pieces”@plyy/astro-editor-bridge
Section titled “@plyy/astro-editor-bridge”A dev-only Astro integration injected into the previewed project. It runs a small script in the preview page that:
- captures Astro’s
data-astro-source-file/data-astro-source-locannotations (then strips them from the DOM), - handles hover highlighting and element selection in the preview iframe,
- talks to the parent editor window (
postMessageto the editor origin, e.g.http://localhost:1420).
@plyy/astro-edit-engine
Section titled “@plyy/astro-edit-engine”The source-editing engine, built on @astrojs/compiler. Given a file and source location it can:
readElementAt/readElementFromAnnotation— resolve the selected element in source,applyEdit— apply anEditOperation(edit text, change classes, wrap, delete) and return the rewritten source,findComponentUsage— trace component usages across the project.
It also ships an astro-edit CLI for use outside the app.
@plyy/astro-template
Section titled “@plyy/astro-template”The Astro project template the app scaffolds new projects from. It wires in the editor bridge integration so freshly created projects are editable out of the box.
The flow
Section titled “The flow”- The desktop app scaffolds a project from the template and runs
astro devinside it. - The preview iframe loads the dev server; the bridge captures source annotations and reports the selected element to the editor.
- The inspector sends an edit operation; the edit engine locates the element in the
.astrosource and rewrites it. - Astro’s dev server hot-reloads the preview with the change.