diff --git a/.changeset/field-renderers-module.md b/.changeset/field-renderers-module.md new file mode 100644 index 00000000..cd836d1a --- /dev/null +++ b/.changeset/field-renderers-module.md @@ -0,0 +1,30 @@ +--- +'@tanstack/cms-core': minor +'@tanstack/cms-ui-react': minor +--- + +**Breaking:** field inputs and list cells move out of the config, into the +renderers module that block renderers use. `Field.input` is now a string: the +name of an input in `defineRenderers({ inputs })`. `FieldTypeDefinition` drops +`input` and `cell`; a custom field type's components go under +`defineRenderers({ fieldTypes: { : { input, cell } } })`. +`defineCollection`, `defineBlock`, `defineFieldType`, `defineCms`, and plugins +throw on a field `input` component or a field type `input` / `cell`, naming +the replacement. + +The admin routes use the module named in +`createRoutes(definition, { renderers })`. Bespoke admins pass the object as a +prop: `FieldInput` (threaded to nested group, array, and block fields) and +`CollectionSection` take `renderers`, and `columnFields(collection, session, +renderers)` takes it as a third argument. `defineRenderers` and the +`CmsRenderers` / `FieldTypeRenderers` types are exported from +`@tanstack/cms-ui-react`, `/site`, and `/primitives`. A field naming an input +that isn't bound logs a warning and uses its type's input. + +```tsx +// src/cms.renderers.tsx +export const renderers = defineRenderers({ + fieldTypes: { rating: { input: RatingInput, cell: RatingCell } }, + inputs: { sku: SkuInput }, // { name: 'sku', type: 'text', input: 'sku' } +}) +``` diff --git a/.claude/skills/payload-to-tanstack-cms/SKILL.md b/.claude/skills/payload-to-tanstack-cms/SKILL.md index c1937209..ca09eaa5 100644 --- a/.claude/skills/payload-to-tanstack-cms/SKILL.md +++ b/.claude/skills/payload-to-tanstack-cms/SKILL.md @@ -304,8 +304,9 @@ judgment. Check at least: - **Media bytes** — uploads migrate as URLs until re-homed. - **Richer Lexical** — node types not converted. - **Custom admin components** — Payload React field/view overrides don't - carry over automatically; rebuild custom field inputs with `field.input` or - `defineFieldType()`, and custom views or hooks with routes or + carry over automatically; rebuild custom field inputs in the app's renderers + module (`defineRenderers({ inputs, fieldTypes })`, a field picks one with + `input: ''`), and custom views or hooks with routes or `definePlugin({ definition, runtime })` (collections and routes in `definition`, ops and event handlers in `runtime`). - **Databases** — Postgres/MongoDB adapters have no built-in equivalent diff --git a/docs/api/cms-core.md b/docs/api/cms-core.md index 40e705ab..3f13b213 100644 --- a/docs/api/cms-core.md +++ b/docs/api/cms-core.md @@ -453,7 +453,7 @@ interface CmsPluginDefinition { interface CmsPluginRuntime { blockTypes?: Array - fieldTypes?: Array // defineFieldType(), with admin input and cell + fieldTypes?: Array // defineFieldType(); admin input and cell come from the renderers module ops?: Array // defineOp(); served over HTTP, Start, OpenAPI, and as agent tools eventHandlers?: Array onEvent?: (event: CmsEvent) => void // server-side, after every content change @@ -764,6 +764,8 @@ function isFieldVisible(field: Field, siblings: Record } + inputs?: { readonly [name: string]: ComponentType } // a field's `input: ''` + fieldTypes?: { readonly [type: string]: FieldTypeRenderers } // custom types only +} + +interface FieldTypeRenderers { + input?: ComponentType + cell?: ComponentType } interface BlockRendererProps { @@ -86,7 +93,7 @@ interface BlockRendererProps { } ``` -Declares the app's React renderers, keyed by block `_type`; exported from both the package root and `/site`. It checks the shape and returns the object. Export the result as `renderers` from a module (e.g. `src/cms.renderers.tsx`), name that module's path in `createRoutes(definition, { renderers })` for the CMS's own routes, and pass the object as the `renderers` prop in your own. Block types stay data only: `defineBlock`, `defineCms`, and plugins reject a block type with a `component`. +Declares the app's React renderers: block renderers keyed by `_type`, named field inputs, and custom field types' inputs and list cells. Exported from the package root, `/site`, and `/primitives`. It checks the shape and returns the object. Export the result as `renderers` from a module (e.g. `src/cms.renderers.tsx`), name that module's path in `createRoutes(definition, { renderers })` for the CMS's own routes, and pass the object as the `renderers` prop in your own (`BlocksView`, `BlockView`, `InteractiveDocument`, `FieldInput`, `CollectionSection`, and `columnFields(collection, session, renderers)`). Block types, fields, and field types stay data only: a block `component`, a field `input` component, or a field type `input` / `cell` throws when the config loads. See [Custom block renderers](../schema/blocks-and-rendering#custom-block-renderers) and [Custom inputs and cells](../schema/collections-and-fields#custom-inputs-and-cells). ```tsx validate=type import { BlocksView } from '@tanstack/cms-ui-react/site' @@ -358,7 +365,7 @@ Every UI primitive the built-in admin routes use, exported so bespoke domain app Two rules hold across the set: - **`collection` is always the collection's name**, as in the read and op APIs (`{ collection: 'post', … }`). Primitives look the definition up in the registered config, so pass `collection="post"`, not the `Collection` object: `columnFields('post', session)`, ``, ``. -- **Pickers take their search backend as a prop**, not from a React context. Each defaults to the built-in `listDocumentSummaries` search. +- **Pickers take their search backend as a prop**, not from a React context. Each defaults to the built-in `listDocumentSummaries` search. Custom inputs and list cells come in the same way (see below). ```tsx type RelationSearch = ( @@ -375,6 +382,8 @@ type RelationSearch = ( `FieldInput` passes `relationSearch` on to relation fields nested in `group`, `array`, and `blocks` fields. +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 })`. + --- ## `@tanstack/cms-ui-react/virtual-routes` diff --git a/docs/deployment/upgrading.md b/docs/deployment/upgrading.md index f9395f19..c73fa044 100644 --- a/docs/deployment/upgrading.md +++ b/docs/deployment/upgrading.md @@ -333,6 +333,28 @@ createRoutes(definition, { renderers: '../cms.renderers.tsx' }) There's no codemod: the components usually sit inline in the config and need their imports moved with them. The built-in renderers (`hero`, `richText`, …) are unchanged, and a `renderers.blocks` entry with the same `_type` replaces one. See [Custom block renderers](../schema/blocks-and-rendering#custom-block-renderers). +### 23. Field inputs and cells move out of the config + +Field components move to the same renderers module. `Field.input` is now a string, the name of an input in `defineRenderers({ inputs })`. `defineFieldType` no longer takes `input` or `cell`; they go under `defineRenderers({ fieldTypes: { : { input, cell } } })`. `defineCollection`, `defineBlock`, `defineFieldType`, `defineCms`, and plugins throw on the old forms, naming the replacement. + +```tsx +// before +defineFieldType({ name: 'rating', schema, input: RatingInput, cell: RatingCell }) +{ name: 'sku', label: 'SKU', type: 'text', input: SkuInput } + +// after: the config +defineFieldType({ name: 'rating', schema }) +{ name: 'sku', label: 'SKU', type: 'text', input: 'sku' } + +// after: src/cms.renderers.tsx +export const renderers = defineRenderers({ + fieldTypes: { rating: { input: RatingInput, cell: RatingCell } }, + inputs: { sku: SkuInput }, +}) +``` + +The admin routes use the module named in `createRoutes(definition, { renderers })`. A bespoke admin passes the same object to `FieldInput`, `CollectionSection`, and `columnFields(collection, session, renderers)`. A custom field type is offered as a list column only when a cell is bound for it, as before. See [Custom inputs and cells](../schema/collections-and-fields#custom-inputs-and-cells). + ## Versioning policy From 1.0, TanStack CMS follows [semantic versioning](https://semver.org). The diff --git a/docs/migration/from-payload.md b/docs/migration/from-payload.md index 493677ab..4cd79278 100644 --- a/docs/migration/from-payload.md +++ b/docs/migration/from-payload.md @@ -46,7 +46,7 @@ Payload v3 and TanStack CMS are both **code-first TypeScript CMSs** with schema - **No GraphQL and no deep `depth` joins.** Relations are ids resolved one level with `populate: true` / `populateRelations`. - **Field-level localization.** TanStack CMS localizes whole documents (`locale`, `translationOf`), not individual fields. - **Access rules return booleans.** Payload access functions that return `Where` queries need rewriting, and rules can only narrow a role's permissions. -- **Custom admin components don't carry over automatically.** Rebuild custom field inputs with `field.input` or `defineFieldType()`, and custom admin views or hooks with routes or `definePlugin({ definition, runtime })`. +- **Custom admin components don't carry over automatically.** Rebuild custom field inputs in your renderers module (`defineRenderers({ inputs, fieldTypes })`, see [Custom inputs and cells](../schema/collections-and-fields#custom-inputs-and-cells)), and custom admin views or hooks with routes or `definePlugin({ definition, runtime })`. - **Fewer databases.** Postgres and MongoDB adapters have no built-in equivalent. ## The 1.0 Mapping @@ -254,7 +254,7 @@ The migrator also writes `src/seed-data.ts`. Passing it as `defineCms({ seed: { - **`Where`-returning access functions**: rewrite as boolean rules. - **Unported hooks and endpoints**: `beforeOperation`, `afterOperation`, `afterError`, auth hooks, and custom `endpoints` (re-home as TanStack Start server routes). - **GraphQL consumers**: move to the REST API or `@tanstack/cms-client`. -- **Custom admin components** (rebuild field inputs with `field.input` / `defineFieldType()`, or views with custom routes / `definePlugin()`) and **custom Lexical nodes** beyond the converter's set. +- **Custom admin components** (rebuild field inputs with `defineRenderers({ inputs, fieldTypes })`, or views with custom routes / `definePlugin()`) and **custom Lexical nodes** beyond the converter's set. - **Postgres/MongoDB**: no built-in adapter; use SQLite, libSQL/Turso, or a custom `StorageAdapter`. ## Next Steps diff --git a/docs/migration/overview.md b/docs/migration/overview.md index 4c758ec6..fb641c44 100644 --- a/docs/migration/overview.md +++ b/docs/migration/overview.md @@ -88,7 +88,7 @@ The migrators also write `src/seed-data.ts`. Passing it as `defineCms({ seed: { - **Users and passwords** don't migrate. Configure `auth: { getUser }` against your identity provider and map roles; without `auth`, the admin only works in development. - **Media bytes** migrate as URLs to the old host until they are uploaded into the media library and references are rewritten. - **Revision history** starts at the import. -- **Custom admin UI** (Payload components, Sanity inputs, WordPress plugins) doesn't carry over automatically; custom field inputs (`field.input`) and custom field types (`defineFieldType()`) are supported, while full view/layout overrides are rebuilt in routes or plugins (`definePlugin({ definition, runtime })`). +- **Custom admin UI** (Payload components, Sanity inputs, WordPress plugins) doesn't carry over automatically; custom field inputs (a field's `input`, bound with `defineRenderers({ inputs })`) and custom field types (`defineFieldType()`, with `defineRenderers({ fieldTypes })`) are supported, while full view/layout overrides are rebuilt in routes or plugins (`definePlugin({ definition, runtime })`). ## Next Steps diff --git a/docs/schema/collections-and-fields.md b/docs/schema/collections-and-fields.md index 28cdf519..b666d1bc 100644 --- a/docs/schema/collections-and-fields.md +++ b/docs/schema/collections-and-fields.md @@ -238,14 +238,14 @@ atomically and to upgrade older revisions when restored. | `validate?` | `FieldValidator` | Extra server-side validation (see below). | | `showWhen?` | `{ field, equals?, oneOf? }` | Show this field only when a sibling matches (see [Conditional fields](#conditional-fields)). | | `access?` | `{ read?, write? }` | Field-level access rules (see [Access control](#access-control)). | -| `input?` | `ComponentType` | Admin editor input for this one field, overriding its type's input. | +| `input?` | `string` | Name of an admin editor input for this one field, overriding its type's input: a key of `inputs` in your renderers module (see [Custom inputs and cells](#custom-inputs-and-cells)). | | `media?` | `boolean` | `markdown` / `textarea` / `richtext` only: show an **Insert media** control to upload or pick images and videos and embed them in the body. Images embed as `![alt](url)`, videos as `![alt](url.mp4)` — the shared renderer turns a video URL into a `