{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "snapshot-module",
  "type": "registry:block",
  "title": "Snapshot, module",
  "description": "One research module of a snapshot as a card: reading (skeleton), ready (headline, summary, suggestions with priority and effort chips and an impact line, then findings, numbered source markers that link to the sources list in the card), unsure (the note only) or failed (a plain sentence). Data is untrusted text; links open only if http(s), in a new tab with noopener nofollow.",
  "categories": [
    "snapshot"
  ],
  "dependencies": [
    "zod@^4.6.5"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/badge.json",
    "https://ui.klarhimmel.com/r/block-kit.json",
    "https://ui.klarhimmel.com/r/editing.json",
    "https://ui.klarhimmel.com/r/kit-snapshot.json",
    "https://ui.klarhimmel.com/r/text-link.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/blocks/snapshot-module/spec.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/snapshot-module/spec.ts",
      "content": "import { z } from 'zod';\nimport { defineSpec, req, t } from '../_shared/schema';\nimport { kindWordsSchema, sourceSchema } from '../_shared/snapshot-schema';\n\nconst item = z.object({\n  id: t(60).optional(),\n  kind: z.enum(['suggestion', 'finding']),\n  title: req(300),\n  detail: t(2000).optional(),\n  /** '1' is the most important. A string because the props panel edits options, not numbers: send String(priority). */\n  priority: z.enum(['1', '2', '3']).optional(),\n  effort: z.enum(['small', 'medium', 'large']).optional(),\n  impact: t(300).optional(),\n  links: z.array(z.object({ label: req(120), url: t(2000) })).max(8).optional(),\n  /** Ids of entries in `output.sources`; each draws a numbered marker that links to that source in the card. */\n  sources: z.array(t(60)).max(12).optional(),\n});\n\nconst schema = z.object({\n  /** The module's name (\"Competitors\"). */\n  title: req(80),\n  status: z.enum(['pending', 'running', 'ready', 'unsure', 'failed']),\n  /** Said when the status is 'unsure' (what could not be checked); never a guess. */\n  note: t(400).optional(),\n  output: z.object({\n    headline: t(300),\n    summary: t(2000),\n    items: z.array(item).max(40),\n    sources: z.array(sourceSchema).max(40),\n  }).optional(),\n  /** Long snapshots on a phone: render findings and/or sources inside a native <details> (no JS), summary \"Findings (n)\" / \"Sources (n)\". Suggestions stay open. A [n] marker opens the sources first. */\n  collapse: z.object({ findings: z.boolean().optional(), sources: z.boolean().optional() }).optional(),\n  /** Fixed words; a missing one uses the English default, so a Swedish page can translate them. */\n  words: z.object({\n    reading: t(60), failed: t(120), sources: t(60), suggestions: t(60), findings: t(60),\n    priority: t(40), effort: t(40), impact: t(40),\n  }).partial().optional(),\n  effortWords: z.object({ small: t(40), medium: t(40), large: t(40) }).partial().optional(),\n  kindWords: kindWordsSchema,\n});\n\nexport const spec = defineSpec({\n  type: 'snapshot-module',\n  aliases: ['snapshot/module'],\n  name: 'Snapshot, module',\n  category: 'snapshot',\n  role: 'body',\n  description: 'One research module of a snapshot as a card: reading (skeleton), ready (headline, summary, suggestions with priority and effort chips and an impact line, then findings, numbered source markers that link to the sources list in the card), unsure (the note only) or failed (a plain sentence). Data is untrusted text; links open only if http(s), in a new tab with noopener nofollow.',\n  schema,\n  defaults: {\n    title: 'Name the module',\n    status: 'ready',\n    note: '',\n    output: {\n      headline: 'Say what the research found in one line',\n      summary: 'Say in a sentence or two what the research found and what it means for the reader.',\n      items: [\n        { id: 'sug_1', kind: 'suggestion', title: 'Name a first thing to do, in one line', detail: 'Say the evidence behind it in one line', priority: '1', effort: 'small', impact: 'Say what it changes for the reader', links: [{ label: 'Name the linked page', url: 'https://rival.example/pricing' }], sources: ['src_1', 'src_2'] },\n        { id: 'fin_1', kind: 'finding', title: 'Name what was found, in a short line', detail: 'Say why it matters, in one short line', links: [{ label: 'Name a page', url: 'https://rival.example/faq' }], sources: ['src_2'] },\n      ],\n      sources: [\n        { id: 'src_1', url: 'https://acme.example/pricing', kind: 'crawl', fetchedAt: '2026-10-10T09:12:00Z' },\n        { id: 'src_2', url: 'https://rival.example/faq', kind: 'crawl', fetchedAt: '2026-10-10T09:13:00Z' },\n      ],\n    },\n    words: { reading: 'Reading…', failed: \"Couldn't finish this part.\", sources: 'Sources', suggestions: 'Suggestions', findings: 'Findings', priority: 'Priority', effort: 'effort', impact: 'Impact' },\n    effortWords: { small: 'Small', medium: 'Medium', large: 'Large' },\n    kindWords: { crawl: 'Page read', search: 'Search', ai_answer: 'AI answer', dataset: 'Dataset', brief: 'Brief' },\n  },\n});\n"
    },
    {
      "path": "src/blocks/snapshot-module/index.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/snapshot-module/index.tsx",
      "content": "import { useId, type ReactNode } from 'react';\nimport { Text, withHeadingLevel } from '../../editing';\nimport { cn } from '../../lib/utils';\nimport { Badge } from '../../ui/badge';\nimport { linkClass } from '../../ui/text-link';\nimport { Container, Named, Opt, Section, useEditing } from '../_shared/kit';\nimport { EXTERNAL, KIND_WORDS, SOURCE_KINDS, SourceRows, WRAP, externalHref } from '../_shared/snapshot-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>;\ntype Item = NonNullable<Props['output']>['items'][number];\nconst WORDS = { reading: 'Reading…', failed: \"Couldn't finish this part.\", sources: 'Sources', suggestions: 'Suggestions', findings: 'Findings', priority: 'Priority', effort: 'effort', impact: 'Impact' };\nconst EFFORT = { small: 'Small', medium: 'Medium', large: 'Large' };\n\nfunction Skeleton() {\n  return (\n    <div aria-hidden className=\"mt-4 space-y-3\">\n      <div className=\"h-5 w-3/4 rounded-kh bg-kh-surface-3 motion-safe:animate-pulse\" />\n      <div className=\"h-4 w-full rounded-kh bg-kh-surface-2 motion-safe:animate-pulse\" />\n      <div className=\"h-4 w-5/6 rounded-kh bg-kh-surface-2 motion-safe:animate-pulse\" />\n    </div>\n  );\n}\n\n/** A marker into collapsed sources opens them before the browser scrolls to the row (Chromium also does this on its own). */\nfunction openTarget(e: { currentTarget: HTMLAnchorElement }) {\n  const row = document.getElementById(e.currentTarget.hash.slice(1));\n  const details = row?.closest('details');\n  if (details) details.open = true;\n}\n\n/** A part of the card: a heading and its list, or the same inside a native <details> when it is collapsed. */\nfunction Part({ collapsed, label, count, path, children }: { collapsed?: boolean; label: string; count: number; path: (string | number)[]; children: ReactNode }) {\n  const heading = <Text path={path} value={label} as=\"span\" />;\n  if (!collapsed) return (<><Named as=\"h3\" className=\"mt-6 text-kh-small font-semibold\">{heading}</Named>{children}</>);\n  return (\n    <details className=\"group mt-6\">\n      <summary className=\"flex min-h-11 cursor-pointer items-center gap-2 rounded-kh-sm text-kh-small font-semibold focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--kh-focus)\">\n        <span aria-hidden className=\"transition-transform duration-(--kh-dur) group-open:rotate-90\">›</span>\n        <span>{heading} ({count})</span>\n      </summary>\n      {children}\n    </details>\n  );\n}\n\nfunction SnapshotModule({ props }: BlockProps<Props>) {\n  const id = useId();\n  const editing = useEditing();\n  const words = { ...WORDS, ...props.words };\n  const effort = { ...EFFORT, ...props.effortWords };\n  const kindWords = { ...KIND_WORDS, ...props.kindWords } as Record<(typeof SOURCE_KINDS)[number], string>;\n  const out = props.output;\n  const sources = out?.sources ?? [];\n  const waiting = props.status === 'pending' || props.status === 'running';\n  const suggestions = (out?.items ?? []).map((it, i) => [it, i] as const).filter(([it]) => it.kind === 'suggestion');\n  const findings = (out?.items ?? []).map((it, i) => [it, i] as const).filter(([it]) => it.kind === 'finding');\n  const marker = (it: Item) =>\n    (it.sources ?? []).map((sid) => sources.findIndex((s) => s.id === sid)).filter((n) => n >= 0).map((n) => (\n      <a key={n} href={`#${id}-s${n + 1}`} onClick={openTarget} className={cn(linkClass(), 'inline-flex min-h-6 min-w-6 items-center justify-center text-kh-caption tabular-nums')}>[{n + 1}]</a>\n    ));\n  const card = ([it, i]: readonly [Item, number]) => (\n    <li key={i} className={cn('py-4', WRAP)}>\n      <div className=\"flex flex-wrap items-center gap-2\">\n        {it.priority && <Badge tone={it.priority === '1' ? 'accent' : 'neutral'}><Text path={['words', 'priority']} value={words.priority} as=\"span\" />{' '}{it.priority}</Badge>}\n        {it.effort && <Badge tone=\"outline\">{effort[it.effort]}{' '}<Text path={['words', 'effort']} value={words.effort} as=\"span\" /></Badge>}\n      </div>\n      <p className=\"mt-2 text-kh-body font-semibold\">\n        <Text path={['output', 'items', i, 'title']} value={it.title} as=\"span\" />\n        {marker(it).length > 0 && <span className=\"ml-2 inline-flex flex-wrap\">{marker(it)}</span>}\n      </p>\n      <Opt path={['output', 'items', i, 'detail']} value={it.detail} multiline className=\"mt-1 text-kh-small text-kh-muted\" placeholder=\"Detail\" />\n      {(it.impact || editing) && (\n        <p className=\"mt-1 text-kh-small\"><span className=\"font-medium\"><Text path={['words', 'impact']} value={words.impact} as=\"span\" />:</span>{' '}<Opt path={['output', 'items', i, 'impact']} value={it.impact} as=\"span\" placeholder=\"Impact\" /></p>\n      )}\n      {(it.links ?? []).length > 0 && (\n        <ul className=\"mt-2 flex flex-wrap gap-x-4 gap-y-1 text-kh-small\">\n          {it.links!.map((l, j) => (\n            <li key={j}><a href={externalHref(l.url)} {...EXTERNAL} className={cn(linkClass(), 'inline-flex min-h-6 items-center', WRAP)}><Text path={['output', 'items', i, 'links', j, 'label']} value={l.label} as=\"span\" /></a></li>\n          ))}\n        </ul>\n      )}\n    </li>\n  );\n  return (\n    <Section labelledBy={id} className=\"py-6 @3xl:py-8\">\n      <Container width=\"narrow\">\n        <div className={cn('rounded-kh-xl border border-kh-line bg-kh-surface p-5 shadow-kh-1 @2xl:p-7', WRAP)} aria-busy={waiting || undefined}>\n          <div id={id}>\n            <Text path={['title']} value={props.title} as=\"h2\" className=\"text-kh-heading font-semibold\" />\n          </div>\n          {editing && (\n            <p className=\"mt-2 flex flex-wrap gap-3 text-kh-caption text-kh-muted\">\n              {(['reading', 'failed', 'sources', 'suggestions', 'findings', 'priority', 'effort', 'impact'] as const).map((k) => <Text key={k} path={['words', k]} value={words[k]} as=\"span\" />)}\n              {(['small', 'medium', 'large'] as const).map((k) => <Text key={k} path={['effortWords', k]} value={effort[k]} as=\"span\" />)}\n              {SOURCE_KINDS.map((k) => <Text key={k} path={['kindWords', k]} value={kindWords[k]} as=\"span\" />)}\n            </p>\n          )}\n          {waiting && (\n            <>\n              <p role=\"status\" className=\"mt-3 text-kh-small text-kh-muted\"><Text path={['words', 'reading']} value={words.reading} as=\"span\" /></p>\n              <Skeleton />\n            </>\n          )}\n          {props.status === 'unsure' && <Opt path={['note']} value={props.note} className=\"mt-3 text-kh-body text-kh-ink-2\" placeholder=\"What could not be checked\" />}\n          {props.status === 'failed' && <p className=\"mt-3 text-kh-body text-kh-ink-2\"><Text path={['words', 'failed']} value={words.failed} as=\"span\" /></p>}\n          {props.status === 'ready' && out && (\n            <>\n              <Opt path={['output', 'headline']} value={out.headline} as=\"p\" className=\"mt-3 text-kh-lead font-medium\" placeholder=\"Headline\" />\n              <Opt path={['output', 'summary']} value={out.summary} multiline className=\"mt-2 max-w-kh-lead text-kh-body text-kh-muted\" placeholder=\"Summary\" />\n              {suggestions.length > 0 && (\n                <>\n                  <Named as=\"h3\" className=\"mt-6 text-kh-small font-semibold\"><Text path={['words', 'suggestions']} value={words.suggestions} as=\"span\" /></Named>\n                  <ul className=\"mt-1 divide-y divide-kh-line border-y border-kh-line\">{suggestions.map(card)}</ul>\n                </>\n              )}\n              {findings.length > 0 && (\n                <Part collapsed={props.collapse?.findings && !editing} label={words.findings} count={findings.length} path={['words', 'findings']}>\n                  <ul className=\"mt-1 divide-y divide-kh-line border-y border-kh-line\">{findings.map(card)}</ul>\n                </Part>\n              )}\n              {sources.length > 0 && (\n                <Part collapsed={props.collapse?.sources && !editing} label={words.sources} count={sources.length} path={['words', 'sources']}>\n                  <SourceRows sources={sources} idPrefix={id} numbered kindWords={kindWords} base={['output', 'sources']} className=\"mt-1\" />\n                </Part>\n              )}\n            </>\n          )}\n        </div>\n      </Container>\n    </Section>\n  );\n}\n\nexport default withHeadingLevel(SnapshotModule);\n"
    }
  ]
}
