OnceBuilder Studio

OnceBuilder StudioHow it works

How OnceBuilder Studio works

Four ideas carry the design: the round trip, the three modes of a file, a preview on a separate origin, and selection that writes nothing into your pages. Each one is shown here with the real program and a demo project.

In development. Read-only today. Not released. Nothing to download or buy.

On this page and elsewhere

1. The round trip

A Xonry project is two things: wireframes.php, which lists the pages and the sections on each, and the section files under layers/. Studio does three things with them.

Read

Studio parses each file into a model: pages, sections and elements, each with the place in the file where it starts and ends. It parses PHP with PHP's own tokenizer and HTML with a tokenizer of its own. It never runs the file.

Rebuild

From the model alone, Studio writes each file again.

Compare

The result must equal the original, byte for byte. If Studio cannot model a file that exactly, it treats the file as code and does not edit inside it.

bin/studio roundtrip
| project     | files | bytes | identical | ignored | refused             | modes                   ||-------------|-------|-------|-----------|---------|---------------------|-------------------------|| demo-site   | 15    | 5389  | 15/15     | 0       | island-unbalanced:1 | code:8 mixed:1 studio:6 || legacy-grid | 2     | 36    | 2/2       | 0       | -                   | code:1 studio:1         |total: projects=2 files=17 bytes=5425 identical=17 different=0REFUSED demo-site/layers/files/files.php island-unbalanced
17 of 17 files identical. One section is refused, with its reason code. bin/studio roundtrip, on the demo project and one test fixture.

On the 12 project folders of the author's working install the same command gave 146 of 146 files identical: 1,300,369 bytes.

An edit is a splice

Because every element has a start and an end, a change is a replacement of that range.

GET /api/v0/projects/demo-site/sections/hero/nodes/r.2
GET /api/v0/projects/demo-site/sections/hero/nodes/r.2HTTP/1.1 200 OKETag: "sha256-e9f9c77f8bdb95452f089137f7adb817a033ca781cbcbb878d0085d807edbd51"{  "id": "r.2",  "type": "element",  "span": [    44,    96  ],  "rev": "sha256-adf5aa5ffacd2f761b19f0927e2a526d795982e9be7013c4e86e8ea576d98b4e",  "line": 2,  "endLine": 2,  "source": "<h1 class=\"title\">A page is a list of sections.</h1>",  "truncated": false,  "withheld": null}
What Studio answers for the selected heading.
layers/hero/hero.php262 bytes
<p class="eyebrow">layers/hero/hero.php</p><h1 class="title">A page is a list of sections.</h1><p class="lead">This heading is one file. Its place on the page is one entry in <code>wireframes.php</code>.</p><a class="button" href="/about">About this demo</a>
Line 2 is bytes 44 to 96 of a 262-byte file.

To change this heading, Studio would replace bytes inside 44 to 96 and leave the other 210 bytes as they are. Before writing, it parses its own result again and compares it with the model it expected; if they differ, nothing is written. A write is refused if the file changed on disk after Studio read it.

bin/studio edit-selftest
| project   | trials | applied | no-op | restored | lint | inverse-exact | inverse byte/model/differs | failures ||-----------|--------|---------|-------|----------|------|---------------|----------------------------|----------|| demo-site | 212    | 212     | 0     | 212/212  | 212  | 116/116       | 136/0/14                   | 0        |
bin/studio edit-selftest, on a copy of the demo project. The first lines of the output.

This engine is tested from the command line: 212 trial edits on a copy of the demo project, each undone to the original bytes, and 2,397 on copies of six real project folders. No button in the interface calls it yet.

2. Three modes: studio, mixed, code

Not every file can be edited visually without risk. Studio sorts each file into one of three modes and shows the mode as a badge. The mode is worked out from the file each time; it is not stored anywhere.

studio

Plain markup that Studio models completely.

layers/hero/hero.php
<p class="eyebrow">layers/hero/hero.php</p><h1 class="title">A page is a list of sections.</h1><p class="lead">This heading is one file. Its place on the page is one entry in <code>wireframes.php</code>.</p><a class="button" href="/about">About this demo</a>
layers/hero/hero.php, mode studio.

mixed

Markup with PHP inside it, where each piece of PHP stays inside one element. Studio can work around the PHP. It never changes, moves or removes it.

layers/footer/footer.php
<p class="small">Demo site. A fixture written to show Xonry and OnceBuilder Studio.</p><p class="small">Rendered by PHP <span class="version"><?= PHP_MAJOR_VERSION ?>.<?= PHP_MINOR_VERSION ?></span>.</p>
layers/footer/footer.php, mode mixed.

code

Anything else: for example a loop that opens in one piece of PHP and closes in another. Studio shows the file and the reason and does not touch its inside. The section can still be placed on a page and moved.

layers/files/files.php
<?php $files = array('wireframes.php', 'head.php', 'foot.php', 'layers/hero/hero.php', 'layers/counter/counter.php'); ?><h2 class="heading">This list comes from a PHP loop</h2><ul class="file-list"><?php foreach ($files as $file) { ?>	<li><code><?= htmlspecialchars($file) ?></code></li><?php } ?></ul>
layers/files/files.php, mode code.

Style sheets and scripts are always in code mode in this version: Studio keeps their bytes and does not look inside.

The left column of Studio: the pages index, about and _layout, and the layers tree. Sections navigation, hero, parts and counter carry the badge studio; files carries the badge code; the row h1 .title is highlighted.The left column of Studio: the pages index, about and _layout, and the layers tree. Sections navigation, hero, parts and counter carry the badge studio; files carries the badge code; the row h1 .title is highlighted.
Pages and layers. The badge on a section is the mode of its file. Demo project.
The Properties panel of Studio for the section files, headed Section files with the badge code. It shows the file layers/files/files.php, mode code, size 309 bytes, and a note headed Notes and refusals: Refusal. A PHP island opens a block it does not close, so the file is shown as code, line 4, with the code island-unbalanced.The Properties panel of Studio for the section files, headed Section files with the badge code. It shows the file layers/files/files.php, mode code, size 309 bytes, and a note headed Notes and refusals: Refusal. A PHP island opens a block it does not close, so the file is shown as code, line 4, with the code island-unbalanced.
The section built with a PHP loop, as Studio shows it: mode code, and the reason it will not edit inside. Demo project.

3. The preview runs on a separate origin

Two kinds of process make up Studio.

The Studio server

It serves the interface and answers its questions from the model. It reads wireframes.php and the section files as data. It never includes a project file, and it never opens config.php, keys or data folders.

The preview process

It draws the page for the canvas by handing the project to the unmodified Xonry engine. This does run the project's PHP, on your computer, as you. It starts for a project only after you have confirmed it, and the choice ends when Studio stops.

The canvas of Studio before the preview is enabled. A card in the empty canvas reads: Preview is off. The layers and properties work without it. To see the page and select on the canvas, enable the preview for this project. Below it a button: Enable preview.The canvas of Studio before the preview is enabled. A card in the empty canvas reads: Preview is off. The layers and properties work without it. To see the page and select on the canvas, enable the preview for this project. Below it a button: Enable preview.
A card in the canvas of Studio, narrow window. It reads: Preview is off. The layers and properties work without it. To see the page and select on the canvas, enable the preview for this project. Below it a button: Enable preview.A card in the canvas of Studio, narrow window. It reads: Preview is off. The layers and properties work without it. To see the page and select on the canvas, enable the preview for this project. Below it a button: Enable preview.
Before the preview is turned on, the canvas says so. The layers tree and the Properties panel beside it are filled in from the files alone. Demo project.
Dialog in Studio: Enable preview for this project? The preview runs this project's own PHP on this computer, as the current user. Only enable it for projects you trust. The choice lasts until Studio is stopped and is never written into the project. Buttons: Enable preview, Cancel.Dialog in Studio: Enable preview for this project? The preview runs this project's own PHP on this computer, as the current user. Only enable it for projects you trust. The choice lasts until Studio is stopped and is never written into the project. Buttons: Enable preview, Cancel.
Dialog in Studio: Enable preview for this project? The preview runs this project's own PHP on this computer, as the current user. Only enable it for projects you trust. The choice lasts until Studio is stopped and is never written into the project. Buttons: Enable preview, Cancel.Dialog in Studio: Enable preview for this project? The preview runs this project's own PHP on this computer, as the current user. Only enable it for projects you trust. The choice lasts until Studio is stopped and is never written into the project. Buttons: Enable preview, Cancel.
The question Studio asks before any project code runs.

Each previewed project is served under its own host name and port, which makes it a separate origin for the browser: its cookies, storage and scripts are apart from Studio's and from those of any other project. Studio's own interface does not answer on that origin, and only Studio may place the page in a frame.

The preview changes no file. What it needs for selection it adds in memory, while the engine reads a section. A button, "Show page without Studio", shows the page with nothing added at all.

bin/studio tripwire
| check                                                    | result ||----------------------------------------------------------|--------|| public API calls made over the two fixtures              | 55     || markers created by Studio                                | 0      || positive control: markers created by a plain php include | 1      |TRIPWIRE OK: nothing was executed, and the control shows the marker can fire
The tripwire is a test project whose files leave a marker when they are executed. After 55 calls to Studio there is no marker. The control, a plain PHP include, leaves one.

4. Selection writes nothing into your pages

The tree and the canvas have to agree on which element is which. Studio does not add ids or attributes to your files for that. The Studio server and the preview each work out the same id for an element from the same bytes of the file.

The canvas of Studio: the rendered demo page with an outline around the heading, A page is a list of sections, and a small label, h1.title, on the outline. Above it a path reads index / hero / h1.The canvas of Studio: the rendered demo page with an outline around the heading, A page is a list of sections, and a small label, h1.title, on the outline. Above it a path reads index / hero / h1.
The canvas of Studio in a narrow window. A path reads index / hero / h1. Below it the demo page: the name Demo site, the links Home and About, and the heading A page is a list of sections with a lit outline and the label h1.title, then the first lines of the text under it.The canvas of Studio in a narrow window. A path reads index / hero / h1. Below it the demo page: the name Demo site, the links Home and About, and the heading A page is a list of sections with a lit outline and the label h1.title, then the first lines of the text under it.
A selected element on the canvas. Demo project.

Click an element on the canvas and its row is selected in the tree. Click a row and the element is outlined. In the recorded test run every sampled element matched, on a real project and on the fixtures. Where markup is produced by PHP and has no place of its own in the file, Studio selects the nearest element around it that has.

Studio with a button selected. The Properties panel lists its attributes type, class, id and data-on-click with the value addOne, and under XON behaviours explains: Calls one of your functions when the event happens.Studio with a button selected. The Properties panel lists its attributes type, class, id and data-on-click with the value addOne, and under XON behaviours explains: Calls one of your functions when the event happens.
A button that carries a XON attribute. Demo project.

Properties are read from the file, not from the browser: tag, id, classes and attributes as written, the file, the mode, the byte range and the lines.

The canvas of Studio set to the breakpoint 375. The demo page is shown at phone width: its three columns have become one, and the heading A page is a list of sections is still outlined with the label h1.title.The canvas of Studio set to the breakpoint 375. The demo page is shown at phone width: its three columns have become one, and the heading A page is a list of sections is still outlined with the label h1.title.
The same selection at 375 pixels. Demo project.

The canvas can be set to five fixed widths or fitted to the window. The outline follows the element.

5. What comes next

The next step is editing in the interface: connecting the tested edit engine to the tree, the canvas and the properties, with a safe way to write to a project. It is not built, and no date is promised.

What works today, and what does not How Xonry builds a page from these files (opens another website)