| 39 | }; |
| 40 | |
| 41 | export function BlocksTable({ docPath, blocks }: BlocksTableProps) { |
| 42 | const t = useT(); |
| 43 | |
| 44 | return ( |
| 45 | <ol className="space-y-2"> |
| 46 | {blocks.map((b, idx) => { |
| 47 | const isHeading = b.kind === "heading"; |
| 48 | const badgeClass = KIND_BADGE[b.kind] || KIND_BADGE.paragraph; |
| 49 | const kindLabel = isHeading |
| 50 | ? `H${b.level ?? "?"}` |
| 51 | : t(`blocks.kind.${b.kind}` as Parameters<typeof t>[0]); |
| 52 | |
| 53 | // 完整原文(来自 k.py blocks 的 text 字段,已剥离行尾锚点尾巴) |
| 54 | const fullText = b.text ?? b.preview ?? ""; |
| 55 | |
| 56 | return ( |
| 57 | <li |
| 58 | key={`${idx}-${b.anchor || "noanchor"}`} |
| 59 | id={b.anchor || undefined} |
| 60 | className={ |
| 61 | "rounded-md border px-3 py-2 transition-colors " + |
| 62 | (isHeading ? "bg-card border-blue-500/30" : "bg-card/40 border-border") |
| 63 | } |
| 64 | > |
| 65 | <div className="flex items-start gap-3"> |
| 66 | <span className="text-xs font-mono text-muted-foreground shrink-0 w-8 mt-0.5"> |
| 67 | #{idx + 1} |
| 68 | </span> |
| 69 | <Badge variant="outline" className={`${badgeClass} shrink-0 mt-0.5`}> |
| 70 | {kindLabel} |
| 71 | </Badge> |
| 72 | <div className="min-w-0 flex-1"> |
| 73 | {isHeading ? ( |
| 74 | <> |
| 75 | <div |
| 76 | className={ |
| 77 | "font-semibold " + |
| 78 | (b.level === 1 |
| 79 | ? "text-base" |
| 80 | : b.level === 2 |
| 81 | ? "text-sm" |
| 82 | : "text-xs") |
| 83 | } |
| 84 | > |
| 85 | {b.title} |
| 86 | </div> |
| 87 | {b.agent_summary ? ( |
| 88 | <p className="text-xs text-muted-foreground mt-0.5 leading-relaxed"> |
| 89 | <span className="font-mono mr-1 text-[10px]"> |
| 90 | [{t("outline.tag.summary")}] |
| 91 | </span> |
| 92 | {b.agent_summary} |
| 93 | </p> |
| 94 | ) : null} |
| 95 | </> |
| 96 | ) : ( |
| 97 | <div className="mt-0.5 text-xs bg-muted/30 rounded px-2 py-1.5 overflow-x-auto"> |
| 98 | <MiniMarkdown content={fullText} /> |