This repository has no description
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839import type { Block } from 'payload'
export const MediaBlock: Block = { slug: 'mediaBlock', interfaceName: 'MediaBlock', fields: [ { name: 'media', type: 'upload', relationTo: 'media', required: true }, { name: 'caption', type: 'text' }, { name: 'widthHint', type: 'select', options: ['full', 'wide', 'inline'], defaultValue: 'full', }, ], jsx: { export: ({ fields }) => { const id = typeof fields.media === 'object' ? (fields.media as { id?: number | string })?.id : fields.media return { props: { media: String(id ?? ''), ...(fields.caption ? { caption: fields.caption } : {}), ...(fields.widthHint && fields.widthHint !== 'full' ? { widthHint: fields.widthHint } : {}), }, } }, import: ({ props }) => { const raw = props?.media const num = raw != null ? Number(raw) : undefined const media = Number.isFinite(num) && !Number.isNaN(num) ? num! : raw return { media, caption: props?.caption ?? '', widthHint: props?.widthHint ?? 'full', } }, },}