@schema-engine/forms 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +3 -3
- package/skill/SKILL.md +14 -14
- package/skill/reference/forms.md +4 -4
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ const result = engine.safeValidateForm({
|
|
|
38
38
|
});
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
`result` is `{ success: true, data }` with the frozen, normalized config, or `{ success: false, issues }` with the `path` of every key to fix.
|
|
41
|
+
`result` is `{ success: true, data }` with the frozen, normalized config, or `{ success: false, issues }` with the `path` of every key to fix. To draw the form, give the engine and the config to a renderer: `FormRenderer` of Forms React or Forms Radiant. A renderer creates a `createFormRuntime` for each form it draws, which owns the submission, the wizard steps and every action; only a renderer author calls it.
|
|
42
42
|
|
|
43
43
|
## Entry points
|
|
44
44
|
|
|
@@ -57,7 +57,7 @@ const result = engine.safeValidateForm({
|
|
|
57
57
|
## Documentation
|
|
58
58
|
|
|
59
59
|
- [Forms](https://schema-engine.com/docs/forms/overview): what a form can do.
|
|
60
|
-
- [Installation and quick start](https://schema-engine.com/docs/forms/getting-started):
|
|
60
|
+
- [Installation and quick start](https://schema-engine.com/docs/forms/getting-started): create the engine, check JSON and render it.
|
|
61
61
|
- [Engine and registrations](https://schema-engine.com/docs/forms/engine): the engine, custom fields and configuration errors.
|
|
62
62
|
- [Validation](https://schema-engine.com/docs/forms/validation) and [custom and async rules](https://schema-engine.com/docs/forms/validation-custom).
|
|
63
63
|
- [Form state](https://schema-engine.com/docs/forms/form-state), [Wizard and runtime](https://schema-engine.com/docs/forms/wizard) and [Actions in forms](https://schema-engine.com/docs/forms/actions).
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schema-engine/forms",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.2",
|
|
5
5
|
"description": "The forms domain of Schema Engine: JSON forms with elements, validation, constraints, steps, form state and submission, with no renderer",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"schema-engine",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"@ecopages/logger": "^0.2.3",
|
|
57
57
|
"@standard-schema/spec": "^1.1.0",
|
|
58
58
|
"@schema-engine/actions": "^0.5.1",
|
|
59
|
-
"@schema-engine/
|
|
60
|
-
"@schema-engine/
|
|
59
|
+
"@schema-engine/layout": "^0.5.1",
|
|
60
|
+
"@schema-engine/registry": "^0.5.1"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"zod": "^4.0.17"
|
package/skill/SKILL.md
CHANGED
|
@@ -27,7 +27,7 @@ This file is the router. It defines the concepts once; the references assume the
|
|
|
27
27
|
|
|
28
28
|
- **config**: a form is plain data, a `FormConfig` of steps holding elements, each with a `$type`, a `name`, `rules` and `constraints`. `engine.defineForm()` (typed, in TypeScript) or `engine.validateForm(unknown)` (portable JSON) checks it against the engine's registrations and returns a frozen `NormalizedFormConfig` that the engine owns.
|
|
29
29
|
- **container**: the form's state, a `FormStateContainer` from `@schema-engine/forms/state-container`. It owns the nested values, errors, warnings, touched and dirty marks, field-array row ids and the validation in flight. Paths are dotted (`contacts.1.email`) and `FORM_ROOT` is the form itself. Every change is a command (`setValue`, `blur`, `reportNative`, `validate`, `submit`, `reset`, `fieldArray`), and every read is a pure selector over an immutable snapshot.
|
|
30
|
-
- **runtime**: `createFormRuntime` is the lifecycle every renderer shares. It builds the container and owns the submission, the wizard steps and their navigation, `form_mount` and `form_change`, and every action dispatch. A renderer supplies only what an element can do, such as focus.
|
|
30
|
+
- **runtime**: for renderer authors, `createFormRuntime` is the lifecycle every renderer shares, and a renderer creates one for each form it draws. It builds the container and owns the submission, the wizard steps and their navigation, `form_mount` and `form_change`, and every action dispatch. A renderer supplies only what an element can do, such as focus. An app does not create one: it gives the engine and a config to a renderer.
|
|
31
31
|
- **issues and the formatter**: the engine reports what is wrong as an issue (`type`, `source`, `ruleId`, `params`, `message`) and never makes up text. `formatIssue`, a function of the application, turns an issue into the words shown, and falls back to the issue's own `message`.
|
|
32
32
|
|
|
33
33
|
Outcomes use one vocabulary: a check or a submission ends `passed`, `invalid` or `overtaken`. `overtaken` means an edit or a reset outran the check, so there is no verdict and nothing to show.
|
|
@@ -49,19 +49,19 @@ A symbol has one import path. `@schema-engine/forms` has these entries: `.` (the
|
|
|
49
49
|
|
|
50
50
|
Each package ships this router as its own `skill/SKILL.md` and its references in its `skill/reference/` folder, so a reference is `node_modules/@schema-engine/<package>/skill/reference/<file>`, and any installed package has the router. Read the rows of the packages the project depends on and skip the others: a package that is not installed has no file. The deployed site serves the latest version of the router and of every reference at `/skill/`, with the references flat at `/skill/reference/<file>`.
|
|
51
51
|
|
|
52
|
-
| To do
|
|
53
|
-
|
|
|
54
|
-
| Register something, build a registry, or read a YAML document
|
|
55
|
-
| Parse, dispatch or cancel actions outside a form
|
|
56
|
-
| Build a grid, an appearance axis or a layout theme
|
|
57
|
-
| Create an engine, author a config, use the container
|
|
58
|
-
| Add a rule, explain a validation result, or translate messages
|
|
59
|
-
| Handle submit, server errors, CSRF or wizard steps
|
|
60
|
-
| Run code on a form event, or define a form action
|
|
61
|
-
| Render a form in React, or use its hooks
|
|
62
|
-
| Write or change a React field widget, and test it
|
|
63
|
-
| Render a form in Radiant, or reach the container from an element
|
|
64
|
-
| Write or change a Radiant field widget, and test it
|
|
52
|
+
| To do | Package | Reference |
|
|
53
|
+
| ---------------------------------------------------------------- | ------------------------------ | ------------------------------------ |
|
|
54
|
+
| Register something, build a registry, or read a YAML document | `@schema-engine/registry` | `reference/registry.md` |
|
|
55
|
+
| Parse, dispatch or cancel actions outside a form | `@schema-engine/actions` | `reference/actions.md` |
|
|
56
|
+
| Build a grid, an appearance axis or a layout theme | `@schema-engine/layout` | `reference/layout.md` |
|
|
57
|
+
| Create an engine, author a config, or use the container directly | `@schema-engine/forms` | `reference/forms.md` |
|
|
58
|
+
| Add a rule, explain a validation result, or translate messages | `@schema-engine/forms` | `reference/forms-validation.md` |
|
|
59
|
+
| Handle submit, server errors, CSRF or wizard steps | `@schema-engine/forms` | `reference/forms-submission.md` |
|
|
60
|
+
| Run code on a form event, or define a form action | `@schema-engine/forms` | `reference/forms-actions.md` |
|
|
61
|
+
| Render a form in React, or use its hooks | `@schema-engine/forms-react` | `reference/forms-react.md` |
|
|
62
|
+
| Write or change a React field widget, and test it | `@schema-engine/forms-react` | `reference/forms-react-widgets.md` |
|
|
63
|
+
| Render a form in Radiant, or reach the container from an element | `@schema-engine/forms-radiant` | `reference/forms-radiant.md` |
|
|
64
|
+
| Write or change a Radiant field widget, and test it | `@schema-engine/forms-radiant` | `reference/forms-radiant-widgets.md` |
|
|
65
65
|
|
|
66
66
|
## Documentation map
|
|
67
67
|
|
package/skill/reference/forms.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# @schema-engine/forms
|
|
2
2
|
|
|
3
|
-
The engine, the config, validation timing, constraints, the container and the runtime. The terms are defined in the router (`SKILL.md`).
|
|
3
|
+
The engine, the config, validation timing, constraints, the container and, for renderer authors, the runtime. The terms are defined in the router (`SKILL.md`).
|
|
4
4
|
|
|
5
5
|
## Engine
|
|
6
6
|
|
|
7
|
-
`createFormEngine` takes `elements`, `recipes`, `actions`, `validations` (extra rules), `layout`, `formatIssue`, `fetch` and `csrf`. It builds read-only registries (a later `$type` replaces an earlier one) and returns an immutable engine: create it once and reuse it. `engine.extend({ ... })` adds registrations and inherits the layout theme. The package ships no field widgets; an element is registered with `defineInput({ $type, schema, metadata, value, render })` (see Registrations below), and renderer packages bring the widgets.
|
|
7
|
+
`createFormEngine` takes `elements`, `recipes`, `actions`, `validations` (extra rules), `layout`, `formatIssue`, `fetch` and `csrf`. It builds read-only registries (a later `$type` replaces an earlier one) and returns an immutable engine: create it once and reuse it. `engine.extend({ ... })` adds registrations and inherits the layout theme. An app gives the engine and a config to a renderer: `FormRenderer` in `forms-react.md` or `forms-radiant.md`. The package ships no field widgets; an element is registered with `defineInput({ $type, schema, metadata, value, render })` (see Registrations below), and renderer packages bring the widgets.
|
|
8
8
|
|
|
9
9
|
```ts title="forms/engine.ts"
|
|
10
10
|
import * as z from 'zod/mini';
|
|
@@ -139,9 +139,9 @@ export async function submitContact(name: string, email: string) {
|
|
|
139
139
|
- `getSnapshot()` is stable until something changes. Read it with `selectValue` and `selectFieldState` (its `error` is the one of exactly that path), which return the same object while what they read is unchanged, so they are safe for `useSyncExternalStore`.
|
|
140
140
|
- `toHydration(container.getServerSnapshot())` is the serializable part a server hands to a client, which passes it as `snapshot` so row ids survive.
|
|
141
141
|
|
|
142
|
-
## Runtime
|
|
142
|
+
## Runtime (for renderer authors)
|
|
143
143
|
|
|
144
|
-
`createFormRuntime({ engine, config, host, onSubmit, ... })` wraps a container with the submission, the wizard and the actions. `host.focus(paths)` is the only required host member; a renderer adds `sync` and `submitNatively` when it needs them.
|
|
144
|
+
An app does not create a runtime: a renderer creates one for each form it draws, and an app reaches it with a hook or a controller (`useFormRuntime`, `FormController`). `createFormRuntime({ engine, config, host, onSubmit, ... })` wraps a container with the submission, the wizard and the actions. `host.focus(paths)` is the only required host member; a renderer adds `sync` and `submitNatively` when it needs them.
|
|
145
145
|
|
|
146
146
|
```ts title="forms/runtime.ts"
|
|
147
147
|
import { createFormRuntime, type FormValues } from '@schema-engine/forms';
|