Feat v0.9.5 typed forms SDK primitive
Extract typed form system from models/workflow.go into standalone server/forms/ package. Any package can now declare and validate forms, not just workflow stages. - New server/forms/ package (types + validation + condition evaluator) - REST POST /api/v1/forms/validate endpoint - Starlark forms.validate(template, data) module - Frontend sw.forms.render(), .validate(), .validateRemote() - Manifest form_template accepted at package level - 16 new tests (12 forms + 4 Starlark module) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -248,6 +248,44 @@ Every surface uses one of three patterns:
|
||||
The shell provides the home link, notification bell, and user menu
|
||||
on every surface for free.
|
||||
|
||||
## `sw.forms` — Typed Forms (v0.9.5)
|
||||
|
||||
Any extension can render and validate typed forms using the `sw.forms` module.
|
||||
|
||||
### `sw.forms.render(container, template, opts)`
|
||||
|
||||
Renders a typed form into a DOM container. Supports flat forms and progressive
|
||||
multi-step forms (fieldsets). Returns a control handle.
|
||||
|
||||
```js
|
||||
const handle = sw.forms.render(document.getElementById('my-form'), template, {
|
||||
values: { name: 'prefilled' },
|
||||
onSubmit: (data) => { console.log('submitted', data); },
|
||||
});
|
||||
|
||||
// Programmatic access
|
||||
const data = handle.getData();
|
||||
handle.setErrors([{ key: 'name', message: 'Name is taken' }]);
|
||||
handle.destroy();
|
||||
```
|
||||
|
||||
### `sw.forms.validate(template, data)`
|
||||
|
||||
Client-side validation (no network call). Returns `{ valid, errors }`.
|
||||
|
||||
```js
|
||||
const { valid, errors } = sw.forms.validate(template, { name: '' });
|
||||
// valid === false, errors === [{ key: 'name', message: 'Name is required' }]
|
||||
```
|
||||
|
||||
### `sw.forms.validateRemote(template, data)`
|
||||
|
||||
Server-side validation via `POST /api/v1/forms/validate`. Returns a Promise.
|
||||
|
||||
```js
|
||||
const result = await sw.forms.validateRemote(template, data);
|
||||
```
|
||||
|
||||
## Extension CSS contract
|
||||
|
||||
Extensions must prefix all CSS classes with `.ext-{slug}-` to avoid
|
||||
|
||||
Reference in New Issue
Block a user