Files
ai-taxonomy-literature-anal…/lib/blocks.ts
T
claude-bot 5407bf4dff
Deploy / deploy (push) Successful in 8m0s
Page blocks: papers and content pages as flat lists of story blocks in the database
A page is now an ordered list of independent blocks (analysis.page_block), no sections and no
headings; every block has an id shown on the page so it can be pointed at. Paper detail pages
use page "paper/<conf>/<ext_id>", analysis pages on /contents use "content/<node id>".

- /api/blocks (list, replace a page, add) and /api/blocks/:id (get, patch, move, delete)
- dynamic block types (stats, tool-table, paper-table, benchmark-table) are filled from the
  database at render time; the two content pages are rendered from their blocks (seeded with
  defaults on first view)
- one-time migration copies the legacy articles into blocks (section titles dropped, links
  become a links block); legacy tables are kept untouched
- old /api/articles, ArticleView and PaperGroup removed

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbMbJPadPzVwvt9rU9GBNo
2026-10-23 22:51:54 +08:00

39 lines
2.7 KiB
TypeScript

// 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 }