{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "opentui/file-change",
  "title": "File Change",
  "description": "Interactive file-change review list with diff expansion, per-file accept/reject actions, and accept-all shortcut",
  "dependencies": [
    "@opentui/react"
  ],
  "registryDependencies": [
    "https://termcn.dev/r/opentui/use-theme.json"
  ],
  "files": [
    {
      "path": "registry/opentui/ui/file-change.tsx",
      "content": "/* @jsxImportSource @opentui/react */\nimport { useKeyboard } from \"@opentui/react\";\nimport { useState } from \"react\";\n\nimport { useTheme } from \"@/hooks/use-theme\";\n\nimport { DiffView } from \"./diff-view\";\n\nexport type FileChangeType = \"modify\" | \"create\" | \"delete\";\n\nexport interface FileChangeItem {\n  path: string;\n  type: FileChangeType;\n  diff?: string;\n  content?: string;\n}\n\nexport interface FileChangeProps {\n  changes: FileChangeItem[];\n  onAccept?: (path: string) => void;\n  onReject?: (path: string) => void;\n  onAcceptAll?: () => void;\n}\n\nconst TYPE_ICON: Record<FileChangeType, string> = {\n  create: \"A\",\n  delete: \"D\",\n  modify: \"M\",\n};\n\nconst parseDiff = (\n  diff: string\n): {\n  oldText: string;\n  newText: string;\n} => {\n  const lines = diff.split(\"\\n\");\n  const oldLines: string[] = [];\n  const newLines: string[] = [];\n\n  for (const line of lines) {\n    if (\n      line.startsWith(\"---\") ||\n      line.startsWith(\"+++\") ||\n      line.startsWith(\"@@\")\n    ) {\n      continue;\n    }\n    if (line.startsWith(\"-\")) {\n      oldLines.push(line.slice(1));\n    } else if (line.startsWith(\"+\")) {\n      newLines.push(line.slice(1));\n    } else if (line.startsWith(\" \")) {\n      const content = line.slice(1);\n      oldLines.push(content);\n      newLines.push(content);\n    } else {\n      oldLines.push(line);\n      newLines.push(line);\n    }\n  }\n\n  return { newText: newLines.join(\"\\n\"), oldText: oldLines.join(\"\\n\") };\n};\n\nexport const FileChange = ({\n  changes,\n  onAccept,\n  onReject,\n  onAcceptAll,\n}: FileChangeProps) => {\n  const theme = useTheme();\n  const [activeIndex, setActiveIndex] = useState(0);\n  const [expandedPaths, setExpandedPaths] = useState<Set<string>>(new Set());\n  const [acceptedPaths, setAcceptedPaths] = useState<Set<string>>(new Set());\n  const [rejectedPaths, setRejectedPaths] = useState<Set<string>>(new Set());\n\n  useKeyboard((key) => {\n    if (key.name === \"up\") {\n      setActiveIndex((i) => Math.max(0, i - 1));\n    } else if (key.name === \"down\") {\n      setActiveIndex((i) => Math.min(changes.length - 1, i + 1));\n    } else if (key.name === \"return\" || key.name === \" \") {\n      const item = changes[activeIndex];\n      if (!item) {\n        return;\n      }\n      setExpandedPaths((prev) => {\n        const next = new Set(prev);\n        if (next.has(item.path)) {\n          next.delete(item.path);\n        } else {\n          next.add(item.path);\n        }\n        return next;\n      });\n    } else if (key.name === \"y\" || key.name === \"Y\") {\n      const item = changes[activeIndex];\n      if (!item) {\n        return;\n      }\n      setAcceptedPaths((prev) => new Set([...prev, item.path]));\n      setRejectedPaths((prev) => {\n        const next = new Set(prev);\n        next.delete(item.path);\n        return next;\n      });\n      onAccept?.(item.path);\n    } else if (key.name === \"n\" || key.name === \"N\") {\n      const item = changes[activeIndex];\n      if (!item) {\n        return;\n      }\n      setRejectedPaths((prev) => new Set([...prev, item.path]));\n      setAcceptedPaths((prev) => {\n        const next = new Set(prev);\n        next.delete(item.path);\n        return next;\n      });\n      onReject?.(item.path);\n    } else if (key.name === \"a\" || key.name === \"A\") {\n      onAcceptAll?.();\n    }\n  });\n\n  const typeColor = (type: FileChangeType): string => {\n    switch (type) {\n      case \"create\": {\n        return theme.colors.success ?? \"green\";\n      }\n      case \"delete\": {\n        return theme.colors.error ?? \"red\";\n      }\n      case \"modify\": {\n        return theme.colors.warning ?? \"yellow\";\n      }\n      default: {\n        return theme.colors.mutedForeground;\n      }\n    }\n  };\n\n  return (\n    <box flexDirection=\"column\">\n      <box gap={2} marginBottom={1}>\n        <text fg={theme.colors.foreground}>\n          <b>{`File Changes (${changes.length})`}</b>\n        </text>\n        <text fg=\"#666\">\n          [↑↓] navigate [Enter/Space] expand [y] accept [n] reject [a] accept\n          all\n        </text>\n      </box>\n\n      {changes.map((item, idx) => {\n        const isActive = idx === activeIndex;\n        const isExpanded = expandedPaths.has(item.path);\n        const isAccepted = acceptedPaths.has(item.path);\n        const isRejected = rejectedPaths.has(item.path);\n        const diffParts = item.diff ? parseDiff(item.diff) : null;\n        return (\n          <box key={item.path} flexDirection=\"column\">\n            <box gap={1}>\n              <text fg={isActive ? theme.colors.primary : undefined}>\n                {isActive ? \"›\" : \" \"}\n              </text>\n              <text fg={typeColor(item.type)}>\n                <b>{TYPE_ICON[item.type]}</b>\n              </text>\n              <text\n                fg={isActive ? theme.colors.primary : theme.colors.foreground}\n              >\n                {isActive ? <b>{item.path}</b> : item.path}\n              </text>\n              {isAccepted && (\n                <text fg={theme.colors.success ?? \"green\"}>✓ accepted</text>\n              )}\n              {isRejected && (\n                <text fg={theme.colors.error ?? \"red\"}>✗ rejected</text>\n              )}\n              {(item.diff || item.content) && (\n                <text fg=\"#666\">{isExpanded ? \"▼\" : \"▶\"}</text>\n              )}\n            </box>\n            {isExpanded && (\n              <box paddingLeft={2} marginTop={1}>\n                {item.diff && diffParts ? (\n                  <DiffView\n                    oldText={diffParts.oldText}\n                    newText={diffParts.newText}\n                    filename={item.path}\n                    showLineNumbers={true}\n                  />\n                ) : (\n                  item.content && (\n                    <box flexDirection=\"column\">\n                      {...item.content\n                        .split(\"\\n\")\n                        .map((line, li) => (\n                          <text\n                            key={li}\n                            fg={theme.colors.success ?? \"green\"}\n                          >{`+${line}`}</text>\n                        ))}\n                    </box>\n                  )\n                )}\n              </box>\n            )}\n          </box>\n        );\n      })}\n    </box>\n  );\n};\n",
      "type": "registry:ui",
      "target": "components/ui/file-change.tsx"
    }
  ],
  "categories": [
    "ai"
  ],
  "type": "registry:ui"
}