// Client-safe types for page blocks (schema: lib/analysis-schema.ts, table analysis.page_block; API: /api/blocks). // A page is a flat list of independent blocks. A block has no title and no relation to its neighbours: one block, one aspect. import type { ToolTable } from './tool-taxonomy'; import type { ListedPaper } from './content-papers'; export interface StatItem { value: number | string; label: string; href?: string } export interface LinkItem { kind: string; title: string; url: string; note?: string | null } export type Block = | { type: 'markdown'; data: { text: string } } | { type: 'list'; data: { items: string[]; ordered?: boolean; lead?: string } } | { type: 'callout'; data: { text: string; title?: string; tone?: 'info' | 'note' | 'warn' } } | { type: 'table'; data: { columns: string[]; rows: string[][]; caption?: string; numeric?: boolean; highlightCol?: number } } | { type: 'chart'; data: { kind: 'bar'; title: string; labels: string[]; series: { name: string; values: number[] }[]; unit?: string; note?: string; highlight?: number[] } } | { type: 'mermaid'; data: { code: string; caption?: string } } | { type: 'figure'; data: { src: string; alt: string; caption?: string } } | { type: 'code'; data: { text: string; lang?: string } } | { type: 'links'; data: { items: LinkItem[] } } // filled from the database when the page is rendered (see lib/block-resolve.ts) | { type: 'stats'; data: { node: string; items: { metric?: string; arg?: string | number; value?: number | string; label: string; href?: string }[] } } | { type: 'tool-table'; data: { caption?: string; note?: string } } | { type: 'paper-table'; data: { node: string; caption?: string; note?: string } } | { type: 'benchmark-table'; data: { node: string; scope: 'areas' | 'papers'; caption?: string; note?: string } }; export type BlockType = Block['type']; export const STATIC_TYPES = ['markdown', 'list', 'callout', 'table', 'chart', 'mermaid', 'figure', 'code', 'links'] as const; export const DYNAMIC_TYPES = ['stats', 'tool-table', 'paper-table', 'benchmark-table'] as const; export const BLOCK_TYPES: readonly string[] = [...STATIC_TYPES, ...DYNAMIC_TYPES]; export const LINK_KINDS = ['paper', 'code', 'project', 'demo', 'dataset', 'related', 'other']; export type Resolved = | { type: 'stats'; items: StatItem[] } | { type: 'tool-table'; table: ToolTable } | { type: 'paper-table'; papers: ListedPaper[] } | { type: 'benchmark-table'; rows: { id: number; name: string; n: number; n_new?: number }[]; showNew: boolean }; /** A block as the page gets it: its id (what you point at), its place, its data, and the live data for dynamic types. */ export interface PageBlock { id: number; position: number; revision: number; updatedAt: string; block: Block; resolved?: Resolved }