Composition / foldkit-mixins-builder
mixins-builder
A headless page-builder state machine tracks undo, selection, and forms, but authors still need a working editor on screen: a block palette, an accessible layer tree, drag-and-drop drop indicators, inline text editing on the canvas, and a responsive viewport preview. Wiring those keyboard handlers, ARIA roles, and pointer drag listeners by hand takes hundreds of lines of DOM code.
foldkit-mixins-builder renders a foldkit-builder as
accessible HTML with every element exposed as a
foldkit-mixins Slot. It connects tree keyboard
navigation, pointer drag-and-drop, inline text editing, and block settings
forms straight to the Builder's Messages while keeping all styling in your theme.
Try the editor live in the live CMS demo.
Install
pnpm add effect foldkit foldkit-bundle foldkit-builder foldkit-composition foldkit-form foldkit-mixins foldkit-mixins-builderA first styled page editor
This defines a Heading Block, creates a PageBuilder, and turns it into an
accessible editor view ready to attach styles or place in your app:
import { Schema } from 'effect'
import { Builder } from 'foldkit-builder'
import { Block, Catalog, Content } from 'foldkit-composition'
import { Renderer } from 'foldkit-composition/foldkit'
import { BuilderView } from 'foldkit-mixins-builder'
const Heading = Block.define('Heading', {
Props: Schema.Struct({ text: Schema.String }),
provides: [Content.Flow],
})
const Site = Catalog.make({ blocks: [Heading], roots: [Content.Flow] })
const SiteRenderer = Renderer.make(Site, {
Heading: ({ field, h }) => h.h2([], [field('text')]),
})
const PageBuilder = Builder.make('PageBuilder', {
catalog: Site,
renderer: SiteRenderer,
starters: { Heading: { text: 'New heading' } },
})
const PageEditing = BuilderView.define(PageBuilder)
const DrawnControl = PageBuilder.inputWith(BuilderView.submodel(PageEditing))PageEditing renders the full editor (palette, layers, inspector,
toolbar, canvas, and live region) with keyboard navigation and drag
behaviors wired to PageBuilder, and DrawnControl plugs straight into a
foldkit-form field:
- Palette: one
aria-disabled-capable button per Block with starter props (grouped byBlock.words, followed by Catalog patterns), titled with where it inserts ("Adds it inside the Section") or why it is unavailable. Style[aria-disabled="true"]rather than:disabledso buttons stay focusable. - Layers: a
role="tree"oftreeitemrows with a roving tab stop, Block label, truncated text preview, expand/collapse toggle, and hover sync with the canvas. - Inspector: the selected node's Block label, description, shortcut-titled actions, and settings under Content, Style, Visibility, and Interactions (or a getting-started summary and shortcut list when unselected).
- Toolbar and stage: undo/redo buttons, selection breadcrumb, viewport
width picker,
role="alert"refusal banner, edit-mode canvas frame (withemptyslot when blank), and aliveannouncement region.
Where editor state, markup, and styles live
| Fact | Owner |
|---|---|
| Document, undo, selection, viewport, layers focus | foldkit-builder |
| How each Block renders on the page | your Renderer (foldkit-composition/foldkit) |
| Editor HTML elements and ARIA wiring | foldkit-mixins-builder |
| Classes, inline styles, extra attributes, and events | your Style and Behavior attachments |
Every interactive element dispatches the Builder's own Messages, keeping state
in the Builder's Model so browser interactions, tests, and agents go through
the same update.