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

sh
pnpm add effect foldkit foldkit-bundle foldkit-builder foldkit-composition foldkit-form foldkit-mixins foldkit-mixins-builder

A 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:

ts
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 by Block.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 :disabled so buttons stay focusable.
  • Layers: a role="tree" of treeitem rows 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 (with empty slot when blank), and a live announcement region.

Where editor state, markup, and styles live

FactOwner
Document, undo, selection, viewport, layers focusfoldkit-builder
How each Block renders on the pageyour Renderer (foldkit-composition/foldkit)
Editor HTML elements and ARIA wiringfoldkit-mixins-builder
Classes, inline styles, extra attributes, and eventsyour 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.