{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "report-table",
  "type": "registry:block",
  "title": "Report, table",
  "description": "A table for long cells: the text wraps, and on a narrow screen every row becomes a card with its labels, so nothing scrolls sideways.",
  "categories": [
    "report"
  ],
  "dependencies": [
    "zod@^4.6.5"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/block-kit.json",
    "https://ui.klarhimmel.com/r/editing.json",
    "https://ui.klarhimmel.com/r/kit-report.json"
  ],
  "files": [
    {
      "path": "src/blocks/report-table/spec.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/report-table/spec.ts",
      "content": "import { z } from 'zod';\nimport { defineSpec, t } from '../_shared/schema';\n\nconst schema = z.object({\n  title: t(100),\n  lead: t(400),\n  columns: z.array(z.object({ label: z.string().min(1).max(40) })).min(1).max(8),\n  rows: z.array(z.object({ cells: z.array(t(1200)).max(8) })).max(60),\n  note: t(300),\n});\n\nexport const spec = defineSpec({\n  type: 'report-table',\n  aliases: ['report/table'],\n  name: 'Report, table',\n  category: 'report',\n  role: 'body',\n  description: 'A table for long cells: the text wraps, and on a narrow screen every row becomes a card with its labels, so nothing scrolls sideways.',\n  schema,\n  defaults: {\n    title: 'Name the table',\n    lead: '',\n    columns: [{ label: 'Column one' }, { label: 'Column two' }, { label: 'Column three' }],\n    rows: [\n      { cells: ['Row one', 'Say what changed in a sentence or two, with the detail a reader would check and why it was needed.', 'Say what the change means for the reader, in a line'] },\n      { cells: ['Row two', 'Say what changed in a sentence or two, with the detail a reader would check and why it was needed.', 'Say what the change means, briefly'] },\n      { cells: ['Row three', 'Say what changed in a sentence or two, with the detail a reader would check and why it was needed.', 'Say what the change means, briefly'] },\n    ],\n    note: '',\n  },\n});\n"
    },
    {
      "path": "src/blocks/report-table/index.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/report-table/index.tsx",
      "content": "import { useId } from 'react';\nimport { Text, withHeadingLevel } from '../../editing';\nimport { Opt } from '../_shared/kit';\nimport { ReportSection, ReportTitle } from '../_shared/report-kit';\nimport { spec } from './spec';\nimport type { BlockProps } from '../types';\nimport type { z } from 'zod';\n\nexport { spec };\ntype Props = z.infer<typeof spec.schema>;\n\n/**\n * Wide enough: a real table whose cells wrap. Narrow: each row is a card, the first cell its heading and the other cells\n * labelled by their column, so a phone never scrolls sideways. Both are in the page; the container decides which shows.\n */\n/** Plain text of a cell (markdown marks and tags out), for sizing only. */\nconst plain = (v: unknown) => String(v ?? '').replace(/<[^>]+>/g, '').replace(/[*_`[\\]()#>]/g, '').trim();\n\n/**\n * Column widths from the content (Felix 2026-10-16: words broke one per line in one column while the next had empty\n * space). Each column weighs its typical and longest text, never less than its header or its longest word, so short\n * columns stay on one line at their natural width and prose columns share the rest by weight.\n */\nexport function columnWidths(columns: { label?: string }[], rows: { cells: unknown[] }[]): { pct: number; short: boolean }[] {\n  const w = columns.map((c, j) => {\n    const lens = rows.map((r) => plain(r.cells[j]).length);\n    const words = rows.flatMap((r) => plain(r.cells[j]).split(/\\s+/)).map((x) => Math.min(x.length, 24));\n    const avg = lens.length ? lens.reduce((a, b) => a + b, 0) / lens.length : 0;\n    const max = lens.length ? Math.max(...lens) : 0;\n    const floor = Math.max(plain(c.label).length, ...words, 4);\n    // A short column (every cell fits about one line) gets its longest cell, so \"portal, now\" never wraps word by word.\n    const want = max <= 26 ? max : Math.min(0.6 * avg + 0.4 * Math.min(max, 160), 90);\n    return 6 + Math.max(floor, want); // 6 ≈ the cell padding, in characters\n  });\n  // Short columns (every cell at most ~26 characters) take their one-line width; the prose columns share the rest by weight.\n  const short = columns.map((c, j) => Math.max(plain(c.label).length, ...rows.map((r) => plain(r.cells[j]).length)) <= 26);\n  if (short.every(Boolean)) return w.map(() => ({ pct: 0, short: false }));\n  const sum = w.reduce((a, x, j) => a + (short[j] ? 0 : x), 0) || 1;\n  return w.map((x, j) => ({ pct: short[j] ? 0 : Math.round((1000 * x) / sum) / 10, short: !!short[j] }));\n}\n\n/** Widths as classes in 5% steps, written out so Tailwind generates them: no inline style (the directory's CSP and static exports refuse it). */\nconst COL_W = ['w-[5%]', 'w-[10%]', 'w-[15%]', 'w-[20%]', 'w-[25%]', 'w-[30%]', 'w-[35%]', 'w-[40%]', 'w-[45%]', 'w-[50%]', 'w-[55%]', 'w-[60%]', 'w-[65%]', 'w-[70%]', 'w-[75%]', 'w-[80%]', 'w-[85%]', 'w-[90%]', 'w-[95%]'];\nexport const colClass = (pct: number) => COL_W[Math.min(COL_W.length, Math.max(1, Math.round(pct / 5))) - 1]!;\n\nfunction ReportTable({ props }: BlockProps<Props>) {\n  const id = useId();\n  const rest = props.columns.slice(1);\n  const widths = columnWidths(props.columns, props.rows);\n  return (\n    <ReportSection labelledBy={id}>\n      <ReportTitle id={id} title={props.title} lead={props.lead} />\n      <div className=\"mt-5 hidden overflow-hidden rounded-kh-lg border border-kh-line bg-kh-surface @2xl:block\">\n        <table className=\"w-full table-auto border-collapse text-left text-kh-small\">\n          <colgroup>{widths.map((w, j) => <col key={j} className={w.pct ? colClass(w.pct) : undefined} />)}</colgroup>\n          <thead className=\"bg-kh-surface-2 text-kh-muted\">\n            <tr>\n              {props.columns.map((c, j) => (\n                <th key={j} scope=\"col\" className=\"px-4 py-3 align-bottom font-medium\">\n                  <Text path={['columns', j, 'label']} value={c.label} as=\"span\" />\n                </th>\n              ))}\n            </tr>\n          </thead>\n          <tbody className=\"divide-y divide-kh-line\">\n            {props.rows.map((r, i) => (\n              <tr key={i} className=\"align-top print:break-inside-avoid\">\n                {props.columns.map((_, j) => {\n                  const cell = <Text path={['rows', i, 'cells', j]} value={r.cells[j] ?? ''} as=\"span\" rich placeholder=\"Cell\" />;\n                  return j === 0 ? (\n                    <th key={j} scope=\"row\" className={`min-w-0 px-4 py-3.5 font-medium [overflow-wrap:break-word] ${widths[j]?.short ? 'whitespace-nowrap' : ''}`}>{cell}</th>\n                  ) : (\n                    <td key={j} className={`min-w-0 px-4 py-3.5 text-kh-ink [overflow-wrap:break-word] ${widths[j]?.short ? 'whitespace-nowrap' : ''}`}>{cell}</td>\n                  );\n                })}\n              </tr>\n            ))}\n          </tbody>\n        </table>\n      </div>\n      <ul className=\"mt-5 flex flex-col gap-3 @2xl:hidden\" aria-label={props.title || 'Table'}>\n        {props.rows.map((r, i) => (\n          <li key={i} className=\"rounded-kh-lg border border-kh-line bg-kh-surface p-4 print:break-inside-avoid\">\n            <p className=\"text-kh-body font-semibold [overflow-wrap:anywhere]\"><Text path={['rows', i, 'cells', 0]} value={r.cells[0] ?? ''} as=\"span\" rich placeholder=\"Cell\" /></p>\n            <dl className=\"mt-3 flex flex-col gap-3\">\n              {rest.map((c, k) => (\n                (r.cells[k + 1] ?? '') !== '' && (\n                  <div key={k}>\n                    <dt className=\"text-kh-caption font-medium uppercase tracking-widest text-kh-muted\">{c.label}</dt>\n                    <dd className=\"mt-0.5 text-kh-small [overflow-wrap:anywhere]\"><Text path={['rows', i, 'cells', k + 1]} value={r.cells[k + 1] ?? ''} as=\"span\" rich placeholder=\"Cell\" /></dd>\n                  </div>\n                )\n              ))}\n            </dl>\n          </li>\n        ))}\n      </ul>\n      <Opt path={['note']} value={props.note} className=\"mt-3 text-kh-small text-kh-muted\" placeholder=\"Note\" />\n    </ReportSection>\n  );\n}\n\nexport default withHeadingLevel(ReportTable);\n"
    }
  ]
}
