Mainstay GitHub

Page builder

The page builder

Every entry has content: text and the blocks its type allows. Editors work on the Content tab, which is the page drawn by your own Blade views. Text is typed where it shows, and a block's fields open beside it.

The Content tab of the admin: this site's front page drawn as the site draws it, its hero selected with the block toolbar above it, and the tree of every block beside it.
The block toolbar Typed in place

A block is a PHP class

Its fields are declared as a content type's are. #[Icon] and #[Description] are what the inserter lists it by, #[Example] is what it previews, and a Blade view at blocks.{handle} draws it.

app/Blocks/Note.php
#[Icon('quote')]
#[Description('A line the reader should not miss.')]
#[Example(['text' => 'Mainstay is not released yet.'])]
class Note extends Block
{
    #[Textarea(required: true)]
    public string $text;
}
resources/views/blocks/note.blade.php
<div class="note">
    <p>@field($block, 'text')</p>
</div>

Blocks hold blocks

#[Blocks] on a block's class names the blocks that go inside it, and text: true lets text sit among them. Its view prints them with @inner($block), and the editor drags blocks into and out of it.

app/Blocks/Cards.php
#[Icon('grid')]
#[Example(inner: [Card::class, Card::class])]
#[Blocks([Card::class])]
class Cards extends Block
{
    #[Select(options: ['cards' => 'Cards', 'tiles' => 'Small tiles'])]
    public string $size = 'cards';
}
The features on the Features page selected on the Content tab, their settings in a dialog listing each feature inside them, beside the tree of every block.

Edits wait as a draft

Everything done on the page is saved as a draft of what differs. Publish puts it live in one transaction and keeps the version it replaced, which the entry's history restores while it is among the newest 50.

An article's top bar and sidebar: its status, Save draft and Publish, then its address, its author and its history.

The block toolbar

Selecting a block brings its toolbar with it, floating by the block, so nothing on the page moves to make room.

Drag

Into another block, or out of one.

Move up, move down

One place at a time.

Bold, italic, code

On the text selected.

Block settings

Its fields and images, in a dialog.

Duplicate

A copy beside it.

Delete

Off the page.

How blocks are stored

An entry's content is a document in a JSON column, its blocks typed data in it and never HTML. Blade draws them on every request, so changing a view changes every page that holds the block.

page_locales.content
{
    "type": "block",
    "attrs": {
        "id": "01K8ZQ4V7M3N2D5R6T8W9X0Y1A",
        "type": "note",
        "data": {
            "text": "Mainstay is not released yet."
        }
    }
}

Rules it keeps

One handle, one block

A block's handle names the view that draws it across the whole site, so two blocks of one handle are refused. A plugin names its blocks its own.

Removed blocks are skipped

A block of a type its list no longer names is left out when it is read, so a removed block type is skipped when read.

Fields read from nothing

A block saved before a field was added reads it as the default its property declares, or as empty.