blocks
blocks<
TCollectionSlug,TFieldKey,TFieldMeta>(options):BlocksField<TCollectionSlug,TFieldMeta>
Defined in: packages/core/src/fields/blocks/config.ts:103
Creates a blocks field with all defaults applied.
Validates that all block slugs are unique within this field. Each item
stored in Convex carries blockType, blockName, and id in addition
to the block’s own fields.
Type Parameters
Section titled “Type Parameters”TCollectionSlug
Section titled “TCollectionSlug”TCollectionSlug extends string = string
TFieldKey
Section titled “TFieldKey”TFieldKey extends string = never
TFieldMeta
Section titled “TFieldMeta”TFieldMeta extends BaseFieldMeta = BaseFieldMeta
Parameters
Section titled “Parameters”options
Section titled “options”BlocksFieldInput<TCollectionSlug, TFieldKey, TFieldMeta>
Blocks field configuration. blocks is required.
Returns
Section titled “Returns”BlocksField<TCollectionSlug, TFieldMeta>
Resolved blocks field definition.
Throws
Section titled “Throws”If two or more block definitions share the same slug.
Example
Section titled “Example”const heading = defineBlock({ slug: "heading", label: "Heading", fields: { text: text({ required: true }) } })const paragraph = defineBlock({ slug: "paragraph", label: "Paragraph", fields: { content: text({ required: true }) } })
defineCollection({ fields: { body: blocks({ label: "Body", blocks: [heading, paragraph], labels: { singular: "section", plural: "sections" }, }), },})- BlocksFieldInput for the full input type
- BlocksField for the resolved output type