diff --git a/.changeset/doc-form-primitive.md b/.changeset/doc-form-primitive.md new file mode 100644 index 00000000..92cf5c4d --- /dev/null +++ b/.changeset/doc-form-primitive.md @@ -0,0 +1,5 @@ +--- +'@tanstack/cms-ui-react': minor +--- + +Add `DocForm` and `useDocForm` to `@tanstack/cms-ui-react/primitives`: a schema-driven document form on TanStack Form. Pass a collection name and it renders a control per field in schema order, honouring `showWhen` and, given `access`, field-level read and write rules. Use it controlled (`value`/`onChange`) or uncontrolled (`defaultValue`). `onSubmit` receives a patch of the fields that changed since the baseline, plus the whole document and any `submit(meta)` argument. `renderers` passes the app's renderers module (`defineRenderers`) to every `FieldInput`, and `fieldRenderers` replaces the control for a field type in one form, built-in types included. `fieldRenderers` is checked first. `docPatch(baseline, doc)` is also exported. Nothing breaks: the admin edit route doesn't use the form yet. diff --git a/docs/api/cms-ui-react.md b/docs/api/cms-ui-react.md index 8f29912e..dfc3708f 100644 --- a/docs/api/cms-ui-react.md +++ b/docs/api/cms-ui-react.md @@ -357,6 +357,7 @@ Every UI primitive the built-in admin routes use, exported so bespoke domain app | Export | Use | | --- | --- | | `AdminShell`, `CommandPalette` | The admin frame and the ⌘K palette. | +| `DocForm`, `useDocForm`, `docPatch` | The schema-driven document form on TanStack Form (see [`DocForm`](#docform)). | | `FieldInput`, `RelationPicker`, `ImageField`, `MediaInsert`, `MarkdownEditor`, `LocaleControls` | Field editors. `FieldInputComponentProps` is the `FieldInput` props type. | | `CollectionSection`, `columnFields`, `defaultSort` | The content list for one collection and its column and sort defaults. | | `Diff`, `CommentsPanel`, `AssigneePanel` | Review: a proposed edit's diff, the comment thread, the assignee. | @@ -384,6 +385,78 @@ type RelationSearch = ( Custom inputs and list cells are props too: `FieldInput` (and its nested fields), `CollectionSection`, and `columnFields(collection, session, renderers)` take `renderers` from `defineRenderers({ inputs, fieldTypes })`, which `/primitives` also exports. Without the prop they use the module bound through `createRoutes(definition, { renderers })`. +### `DocForm` + +A `