Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .changeset/field-renderers-module.md
Original file line number Diff line number Diff line change
@@ -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: { <type>: { 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' }
})
```
5 changes: 3 additions & 2 deletions .claude/skills/payload-to-tanstack-cms/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<name>'`), 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
Expand Down
4 changes: 3 additions & 1 deletion docs/api/cms-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ interface CmsPluginDefinition {

interface CmsPluginRuntime {
blockTypes?: Array<BlockType>
fieldTypes?: Array<FieldTypeDefinition> // defineFieldType(), with admin input and cell
fieldTypes?: Array<FieldTypeDefinition> // defineFieldType(); admin input and cell come from the renderers module
ops?: Array<CmsOpDefinition> // defineOp(); served over HTTP, Start, OpenAPI, and as agent tools
eventHandlers?: Array<EventHandlerDefinition>
onEvent?: (event: CmsEvent) => void // server-side, after every content change
Expand Down Expand Up @@ -764,6 +764,8 @@ function isFieldVisible(field: Field, siblings: Record<string, JsonValue | undef
| --- | --- |
| `FieldType` | The 20 field type names (`'text'`, `'textarea'`, `'markdown'`, `'richtext'`, `'number'`, `'boolean'`, `'image'`, `'blocks'`, `'select'`, `'multiselect'`, `'relation'`, `'date'`, `'datetime'`, `'json'`, `'slug'`, `'email'`, `'url'`, `'color'`, `'group'`, `'array'`). |
| `Field` | A field descriptor. See [Field properties](../schema/collections-and-fields#field-properties). |
| `FieldTypeDefinition` | `{ name, schema, defaultValue?, hint? }` from `defineFieldType`. Data only: its admin input and list cell come from `defineRenderers({ fieldTypes })` in `@tanstack/cms-ui-react`, and one with `input` or `cell` throws. |
| `FieldInputProps`, `FieldCellProps` | What a custom admin input (`{ field, value, onChange, changed, disabled? }`) and list cell (`{ field, value }`) receive. |
| `FieldOption` / `NormalizedFieldOption` | `string \| { value, label }` / `{ value, label }`. |
| `FieldCondition` | `{ field, equals?, oneOf? }` — a field's `showWhen` visibility rule. See [Conditional fields](../schema/collections-and-fields#conditional-fields). |
| `FieldValidator` | `StandardSchemaV1Like \| FieldValidatorFn`. |
Expand Down
13 changes: 11 additions & 2 deletions docs/api/cms-ui-react.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ function defineRenderers(renderers: CmsRenderers): CmsRenderers

interface CmsRenderers {
blocks?: { readonly [type: string]: ComponentType<BlockRendererProps> }
inputs?: { readonly [name: string]: ComponentType<FieldInputProps> } // a field's `input: '<name>'`
fieldTypes?: { readonly [type: string]: FieldTypeRenderers } // custom types only
}

interface FieldTypeRenderers {
input?: ComponentType<FieldInputProps>
cell?: ComponentType<FieldCellProps>
}

interface BlockRendererProps {
Expand All @@ -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'
Expand Down Expand Up @@ -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)`, `<Diff collection="post" … />`, `<CommentsPanel collection="post" id={id} />`.
- **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 = (
Expand All @@ -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`
Expand Down
22 changes: 22 additions & 0 deletions docs/deployment/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: { <type>: { 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
Expand Down
4 changes: 2 additions & 2 deletions docs/migration/from-payload.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/migration/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
65 changes: 51 additions & 14 deletions docs/schema/collections-and-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<FieldInputProps>` | 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 `<video controls>` element. The library accepts MP4/M4V, QuickTime, WebM, and Ogg uploads. |

## Custom field types

Register your own field types with `defineFieldType()` and `defineCms({ fieldTypes })`. A definition supplies the value schema (used for validation and agent tool schemas), a default, and optionally the admin editor input and list cell:
Register your own field types with `defineFieldType()` and `defineCms({ fieldTypes })`. A definition supplies the value schema (used for validation and agent tool schemas), a default, and a hint for agents. It is data only; its admin input and list cell live in your renderers module (see [Custom inputs and cells](#custom-inputs-and-cells)):

```tsx
```ts
import { z } from 'zod'
import { defineCms, defineFieldType } from '@tanstack/cms-core'

Expand All @@ -254,16 +254,6 @@ const rating = defineFieldType({
hint: '1-5 stars',
schema: (field) => z.number().int().min(field.min ?? 1).max(field.max ?? 5),
defaultValue: 3,
input: ({ value, onChange }) => (
<input
type="range"
min={1}
max={5}
value={Number(value)}
onChange={(e) => onChange(Number(e.target.value))}
/>
),
cell: ({ value }) => '★'.repeat(Number(value)),
})

declare module '@tanstack/cms-core' {
Expand All @@ -289,7 +279,54 @@ export const cms = defineCms({
})
```

Augmenting `CustomFieldTypes` makes `InferDoc` type the value (`stars: number`); without it the value is `JsonValue`. A custom type without an `input` is edited as JSON in the admin. A field that uses an unregistered type throws when its schema is built.
Augmenting `CustomFieldTypes` makes `InferDoc` type the value (`stars: number`); without it the value is `JsonValue`. A field that uses an unregistered type throws when its schema is built.

### Custom inputs and cells

The admin's React components for fields live in the same renderers module as block renderers, so collections and field types stay free of React. `fieldTypes` gives a custom type its editor `input` and list `cell`; `inputs` holds named inputs that a single field picks with `input: '<name>'`:

```tsx validate=type
// src/cms.renderers.tsx
import { defineRenderers } from '@tanstack/cms-ui-react'
import type { FieldCellProps, FieldInputProps } from '@tanstack/cms-core'

function RatingInput({ value, onChange, disabled }: FieldInputProps) {
return (
<input
type="range"
min={1}
max={5}
value={Number(value)}
disabled={disabled}
onChange={(e) => onChange(Number(e.target.value))}
/>
)
}

function RatingCell({ value }: FieldCellProps) {
return <>{'★'.repeat(Number(value))}</>
}

function SkuInput({ value, onChange }: FieldInputProps) {
return (
<input
className="font-mono uppercase"
value={String(value ?? '')}
onChange={(e) => onChange(e.target.value.toUpperCase())}
/>
)
}

export const renderers = defineRenderers({
fieldTypes: { rating: { input: RatingInput, cell: RatingCell } },
// { name: 'sku', label: 'SKU', type: 'text', input: 'sku' }
inputs: { sku: SkuInput },
})
```

Name the module in `createRoutes(definition, { renderers: '../cms.renderers.tsx' })` and the admin routes use it. In your own admin built from `@tanstack/cms-ui-react/primitives`, pass the object to `FieldInput`, `CollectionSection`, or `columnFields` as `renderers`.

A field's named input comes first, then its type's input, then the built-in control; a custom type without an input is edited as JSON, and one without a cell isn't offered as a list column. A field naming an input that isn't bound logs a warning and uses its type's input. `fieldTypes` takes custom types only: give a built-in field its own input with `input: '<name>'`. A field with an `input` component, or a field type with `input` or `cell`, throws when the config loads.

## Validation

Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
PLUGIN_DEFINITION_KEYS,
PLUGIN_RUNTIME_KEYS,
assertNoBlockComponent,
assertNoFieldComponents,
assertNoFieldTypeComponents,
} from './lib/authoring'
import type {
BlockType,
Expand Down Expand Up @@ -935,9 +937,13 @@ export function applyPlugins<TConfig extends CmsConfig>(
const cached = withPlugins.get(input)
if (cached) return cached as WithPlugins<TConfig>
const collections = collectionsByName(input.collections, 'defineCms')
for (const [name, c] of Object.entries(collections)) {
assertNoFieldComponents(c.fields, `defineCms: collection "${name}"`)
}
const blockTypes = [...(config.blockTypes ?? [])]
for (const b of blockTypes) assertNoBlockComponent(b, 'defineCms')
const fieldTypes = [...(config.fieldTypes ?? [])]
for (const f of fieldTypes) assertNoFieldTypeComponents(f, 'defineCms')
const ops = [...(config.ops ?? [])]
const eventHandlers = [...(config.eventHandlers ?? [])]
// The built-in `asset` collection: injected into every CMS so assets are
Expand All @@ -963,6 +969,10 @@ export function applyPlugins<TConfig extends CmsConfig>(
`Plugin "${plugin.name}"`,
)
for (const [name, collection] of Object.entries(own)) {
assertNoFieldComponents(
collection.fields,
`Plugin "${plugin.name}": collection "${name}"`,
)
claim(taken.collection, 'collection', name, plugin.name)
collections[name] = collection
}
Expand All @@ -972,6 +982,7 @@ export function applyPlugins<TConfig extends CmsConfig>(
blockTypes.push(b)
}
for (const f of plugin.fieldTypes ?? []) {
assertNoFieldTypeComponents(f, `Plugin "${plugin.name}"`)
claim(taken['field type'], 'field type', f.name, plugin.name)
fieldTypes.push(f)
}
Expand Down
Loading
Loading