Core Concepts
Schema Engine separates serializable form data from framework rendering. The core package registers elements, view recipes, and actions; an adapter renders the selected recipe.
Authoring modes
Choose how you author form configuration based on where the data lives:
| Mode | Use when | API |
|---|---|---|
| TypeScript in your app | The form is hardcoded next to a known engine | engine.defineForm({ ... }) — full typing from your registrations |
| Portable JSON | CMS, API, storage, or shared files across systems | Plain FormConfig (or raw JSON) + engine.validateForm(unknown) |
defineForm and validateForm run the same validation pipeline. defineForm
only adds compile-time checks for the engine you built. The exported FormConfig
type is envelope-level: it does not narrow each $type until validation runs.
Both throw a FormValidationError on an invalid form. engine.safeValidateForm(json)
returns { success, data | issues } instead, and each issue carries the config path
it is about (see Form configuration errors).
With FormRenderer, passing a plain config is enough — the renderer calls
validateForm at the form boundary. Pre-validate only when you need a
NormalizedFormConfig outside the renderer (caching, tests, custom pipelines).
Registration
import { createFormEngine } from '@schema-engine/forms';
const engine = createFormEngine({
elements: [textInputRegistration],
recipes: [cardRecipe],
actions: [submitActionRegistration],
});Each list is stored in a read-only registry: a later $type replaces an earlier one, and a
schema that is not a Standard Schema fails the build. validations adds custom rules and
layout sets the layout theme; see
Registries.
Form configuration
const config = engine.defineForm({
id: 'contact',
title: 'Contact',
steps: [{ id: 'details', title: 'Details', elements: [] }],
view: {
$type: 'card',
shell: { appearance: { size: 'default' } },
header: { showDescription: true },
},
});view.$type selects one registered recipe. The recipe determines its kind and
allowed slots. Single-step recipes require exactly one step; wizard recipes
require at least two. A single-step form may omit view to render fields
directly.
validateForm / defineForm parse the form schema and, when view is present,
validate the registered recipe's kind and slot config. Nested child elements are
validated at the same boundary; the normalized marker is applied only after that
succeeds. They return a frozen NormalizedFormConfig owned by that engine.
Snapshot isolation copies plain objects and arrays; other objects currently
remain shared. A form normalized by one engine cannot be passed to another;
start from authoring input or JSON instead. They write the resolved view:
a multi-step form that omits view gets { $type: 'bare-controls' } (or the
engine's defaultWizardRecipe), and each slot config is the recipe's
slotDefaults under the author's keys, merged deep. When the default recipe is
not registered the form validates without a view, validateForm warns, and
the renderer paints fields without chrome. Renderers read the normalized view
and do not apply defaults themselves.
A multi-step form is a wizard. A step may take constraints (show or hide, on non-row fields of earlier steps; the
first step has none) and is skipped when they hide it, and the form's navigation is 'linear' (default) or 'free'.
Both renderers run the wizard, the submission and every action through one form runtime (createFormRuntime), so
step ids, skipped steps, submit as Next and the reset rule behave the same in React and Radiant.
React and Radiant render that normalized form. They do not re-parse element
input schemas. A field created outside a form must go through
engine.validateElement() first.
Authors supply schema input; defaulted properties stay optional in
defineForm. Components receive schema output. Nested fieldset and array
children are typed from the same engine registrations as top-level fields.
Containers render those children with FormElements and a field scope instead
of cloning configuration to change paths.
Placing fields in the grid
A form's grid sets its layout (columns, gap, responsive), and each
element's own grid places it. There are three levels, from the most to the
least readable:
widthandoffsetfor fields that flow in rows.areasfor a layout you draw as rows of names.- Raw grid lines (
column,row) as the escape hatch.
A grid uses either width/offset, areas or columns; raw lines can sit
next to widths or areas.
Rows of fields: width and offset
For the common layouts, name the width:
{ $type: 'input', id: 'first', name: 'first', grid: { width: 'half' } },
{ $type: 'input', id: 'last', name: 'last', grid: { width: 'half' } },
{ $type: 'input', id: 'bio', name: 'bio', grid: { width: 'half', offset: 'quarter' } },width is full, three-quarters, two-thirds, half, third, or
quarter. offset leaves empty space before the field and takes the same names
except full, so half with a quarter offset is centred in its row. A width
on its own is the share of the row the field takes; the grid decides where it
lands, so two half fields share a row. Leave the width out for a field that
fills the row.
Both change by breakpoint through the element's grid.responsive, like every
other placement key. A slot that sets only the width keeps the offset of the
slot before it, and the other way round:
{ grid: { width: 'full', responsive: { md: { width: 'third' } } } }A grid whose fields use width or offset is laid out on 12 tracks, so each
name is a whole number of tracks (half is 6, third is 4, quarter is 3), and
a field in that grid that sets no width fills the row. Fieldsets and array rows
lay out their children on their own grid, so width and offset work on a
container's children the same way, and the enclosing grid's columns do not conflict
with them.
Validation enforces these rules for named widths:
- A form grid that sets
columnsorminColumnWidth(at any breakpoint) cannot contain a top-level field that useswidthoroffset: a grid uses areas, widths or columns. - A field that sets
widthoroffsetcannot also set a rawcolumn. - A field's
offsetpluswidthmust fit in 12 tracks, counting the value each carries from a narrower breakpoint:two-thirdsafter ahalfoffset is rejected.
Drawn layouts: areas
When a field spans several rows or columns next to stacked fields, width and
offset cannot say it. Draw the layout instead: the grid's areas is a list
of rows, each row lists area names separated by spaces, and . is an empty
cell. A field claims a name with grid.area.
grid:
areas:
default: ['a', 'b', 'c', 'd', 'e']
md:
- 'a a a b b b'
- 'a a a c c c'
- 'd d e e e e'
elements:
- { $type: input, id: a, name: a, grid: { area: a } }
- { $type: input, id: b, name: b, grid: { area: b } }
# c, d and e claim their own area the same wayBelow md the five fields stack. From md, a spans three columns and two
rows, b and c stack beside it, and d and e share the last row. The
column count comes from the rows, so a grid with areas sets no columns.
areas is an array for one layout at every width, or a record keyed default,
sm, md, lg, xl and 2xl (a slot you leave out keeps the layout of the
slot before it). A responsive record must include default. A field's area
is also responsive through grid.responsive, so a field can claim a different
area when the template changes.
A few things the template does not police:
- A field with no
areain an areas grid is auto-placed: it fills a.cell if one is free, otherwise it opens an implicit row after the drawn ones. A rawcolumnorrowon such a field works as it does anywhere else. - Two fields may claim the same area. That is meant for fields that are never
shown together (constraints, or
hiddenat a breakpoint); if both show, they are drawn over the same cells. - A field hidden at a breakpoint (
grid.responsive.<slot>.hidden) need not be in that breakpoint's template, and the hidden state carries to wider breakpoints until a slot shows it again. - A step with no fields under a form-level
areasneedsgrid: {}from the author: an empty grid of its own that replaces the form's. Without it, every template area counts as unclaimed on that step and validation rejects it.
A step takes its own grid, which replaces the form's grid for that step. An
areas template names specific fields, so each wizard step draws its own. A
form-level areas applies to every step without a grid of its own, and each of
those steps must then claim every area in it:
{
id: 'checkout',
grid: { columns: 2 },
steps: [
{
id: 'address',
title: 'Address',
grid: { areas: ['street street', 'city zip'] },
elements: [
{ $type: 'input', id: 'street', name: 'street', grid: { area: 'street' } },
{ $type: 'input', id: 'city', name: 'city', grid: { area: 'city' } },
{ $type: 'input', id: 'zip', name: 'zip', grid: { area: 'zip' } },
],
},
{ id: 'payment', title: 'Payment', elements: [/* two columns, from the form grid */] },
],
}Validation names the path of whatever it rejects:
- Rows of one template must have the same number of cells, and each name's cells must form a rectangle. CSS drops a whole template that breaks either rule.
- Every field
areamust be in the template at each breakpoint where the grid draws one, and every area in the template must be claimed by a field. areascannot be mixed withcolumnsorminColumnWidth, or withwidthoroffseton the grid's fields: a grid uses areas, widths or columns.- A field cannot set
areatogether withwidth,offset,columnorrow. - Names are ASCII CSS identifiers (
street,side-2) and cannot beauto,span,none,default,inherit,initial,unset,revertorrevert-layer. A name is written into a CSS custom property, so anything that is not an identifier is rejected. - Fieldsets and array rows lay their children out without
areas, soareais rejected on a container's children. Usewidthandoffsetthere.
Raw grid lines
Raw column, row and placeSelf stay available as the escape hatch for
anything the names do not cover. column: 2 is a CSS grid line, not a span:
it starts the field at line 2. Use column: 'span 2' to span two columns, or
column: '4 / 10' for explicit lines. A raw column field may sit next to
width fields, but it counts tracks of the 12 the widths use there, so
column: 'span 2' is two of twelve, a sixth of the row.
The layout theme and appearance
The grid vocabulary (breakpoint thresholds, gap tokens, the default minimum column
width) and the appearance axes (size and surface built in, plus any you define)
belong to one layout theme, compiled by @schema-engine/layout and passed to the
engine as layout, either compiled once or as inline { grid, appearance } options:
import { createFormEngine } from '@schema-engine/forms';
import { createLayoutTheme } from '@schema-engine/layout';
const theme = createLayoutTheme({ grid: { breakpoints: { md: '50rem' } } });
const checkout = createFormEngine({ elements, layout: theme });
const profile = createFormEngine({ elements, layout: theme });Engines built on one compiled theme carry the same data-se-theme and the same stylesheet
content. React hoists the equal stylesheets to one element; Radiant puts an identical copy in
each form, by design. A form of one engine can sit inside a grid item of another: the nearest
theme's token rules apply.
A form, a step, a field or a recipe slot picks a named value per axis with
appearance: { size: 'compact' }, and the renderer writes data-se-size="compact".
A registration declares the axes it responds to with appearanceAxes, and validateForm
rejects a pick on any other axis, an unknown axis and an unknown value.
The full guides are in Styling:
- Layout themes: the options, sharing a theme, the neutral
.se-grid,.se-grid-itemand[data-se-theme]hooks, the--se-item-*properties and nested themes. - Appearance axes: the definition, what makes a good axis,
sizeandsurface,defineAxisand host axes. - Theming: the custom properties a host overrides.
- Recipes: copy-paste configs with their CSS, rendered live.