{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "diff",
  "title": "Diff",
  "description": "One file's changes or a run's, with Keep and Undo for each file and change, and Keep all and Undo all.",
  "dependencies": [
    "@kind-ui/agent-ui@0.9.0",
    "@ui-sdk/core@0.1.0-beta.17",
    "@ui-sdk/react@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/react/diff.tsx",
      "content": "\"use client\";\n\nimport { codeSpans, type DiffLineView, type DiffPiece, diffPrimitive } from \"@kind-ui/agent-ui/core\";\nimport { createParts } from \"@ui-sdk/react/primitive\";\nimport { type ComponentProps, Fragment, memo } from \"react\";\n\nconst parts = createParts(diffPrimitive, {\n  root: \"div\",\n  summary: \"div\",\n  \"summary-title\": \"div\",\n  \"summary-counts\": \"span\",\n  \"summary-mark\": \"span\",\n  \"summary-progress\": \"div\",\n  \"summary-outcome\": \"div\",\n  \"summary-actions\": \"div\",\n  \"undo-all\": \"button\",\n  \"keep-all\": \"button\",\n  \"undo-all-question\": \"span\",\n  \"undo-all-cancel\": \"button\",\n  \"undo-all-confirm\": \"button\",\n  \"summary-error\": \"div\",\n  list: \"div\",\n  file: \"div\",\n  \"file-trigger\": \"button\",\n  \"file-path\": \"span\",\n  \"file-old-path\": \"span\",\n  \"file-status\": \"span\",\n  \"file-counts\": \"span\",\n  \"file-mark\": \"span\",\n  \"file-actions\": \"div\",\n  \"file-undo\": \"button\",\n  \"file-keep\": \"button\",\n  \"file-outcome\": \"span\",\n  \"file-error\": \"span\",\n  \"file-content\": \"div\",\n  \"file-note\": \"div\",\n  viewport: \"div\",\n  table: \"div\",\n  head: \"div\",\n  column: \"span\",\n  change: \"div\",\n  \"change-title\": \"div\",\n  \"change-undo\": \"button\",\n  \"change-keep\": \"button\",\n  \"change-outcome\": \"span\",\n  \"change-error\": \"span\",\n  line: \"div\",\n  \"old-number\": \"span\",\n  \"new-number\": \"span\",\n  sign: \"span\",\n  code: \"span\",\n  collapsed: \"button\",\n  \"collapsed-text\": \"span\",\n  \"show-all\": \"button\",\n});\n\n// Text with its backticks as `code`.\nconst withCode = (text: string) =>\n  codeSpans(text).map((piece, index) =>\n    // biome-ignore lint/suspicious/noArrayIndexKey: the pieces never move.\n    index % 2 ? <code key={index}>{piece}</code> : <Fragment key={index}>{piece}</Fragment>,\n  );\n\nexport type DiffProps = ComponentProps<typeof parts.Root>;\n\n/**\n * One file's changes, or a run's: a summary with Keep all and Undo all, then each file's row with its own Keep and\n * Undo, opening to its lines. Any `children` replace the default parts.\n */\nexport function Diff({ children, ...props }: DiffProps) {\n  return <parts.Root {...props}>{children !== undefined ? children : DEFAULT_PARTS}</parts.Root>;\n}\n\n/** The title, counts, progress and Keep all and Undo all, above several files. */\nexport const DiffSummary = parts.Summary;\n/** The running mark while a patch streams. */\nexport const DiffSummaryMark = parts.SummaryMark;\n/** Holds Undo all and Keep all, or Undo all's question. */\nexport const DiffSummaryActions = parts.SummaryActions;\n/** Holds a file's Keep, Undo, outcome and error, at one width. */\nexport const DiffFileActions = parts.FileActions;\n/** The running mark in place of a file's counts while its patch streams. */\nexport const DiffFileMark = parts.FileMark;\n/** A file's lines, opened by its row. */\nexport const DiffFileContent = parts.FileContent;\n/** Scrolls a file's lines. Holds a `DiffTable`. */\nexport const DiffViewport = parts.Viewport;\n/** The screen-reader column headers. */\nexport const DiffHead = parts.Head;\n\nexport type DiffSummaryTitleProps = ComponentProps<typeof parts.SummaryTitle>;\n\n/** \"4 files changed\", \"Editing 2 files\" or \"All changes reviewed\", unless you pass children. */\nexport function DiffSummaryTitle({ children = ({ text }) => text, ...props }: DiffSummaryTitleProps) {\n  return <parts.SummaryTitle {...props}>{children}</parts.SummaryTitle>;\n}\n\nconst counts = ({ added, removed, name }: { added: string; removed: string; name: string }) => (\n  <>\n    <span aria-hidden=\"true\">\n      {added && <span data-diff-added=\"\">{added}</span>}\n      {added && removed && \" \"}\n      {removed && <span data-diff-removed=\"\">{removed}</span>}\n    </span>\n    <span data-diff-hidden=\"\">{name}</span>\n  </>\n);\n\nexport type DiffSummaryCountsProps = ComponentProps<typeof parts.SummaryCounts>;\n\n/** \"+120 −8\", read as \"120 additions, 8 deletions\", unless you pass children. */\nexport function DiffSummaryCounts({ children = counts, ...props }: DiffSummaryCountsProps) {\n  return <parts.SummaryCounts {...props}>{children}</parts.SummaryCounts>;\n}\n\nexport type DiffSummaryProgressProps = ComponentProps<typeof parts.SummaryProgress>;\n\n/** \"2 of 4 reviewed\", then \"3 kept, 1 undone\", unless you pass children. */\nexport function DiffSummaryProgress({ children = ({ text }) => text, ...props }: DiffSummaryProgressProps) {\n  return <parts.SummaryProgress {...props}>{children}</parts.SummaryProgress>;\n}\n\nexport type DiffSummaryOutcomeProps = ComponentProps<typeof parts.SummaryOutcome>;\n\n/** \"3 kept, 1 undone\" once every change is reviewed, unless you pass children. */\nexport function DiffSummaryOutcome({ children = ({ text }) => text, ...props }: DiffSummaryOutcomeProps) {\n  return <parts.SummaryOutcome {...props}>{children}</parts.SummaryOutcome>;\n}\n\nexport type DiffUndoAllProps = ComponentProps<typeof parts.UndoAll>;\n\n/** Asks before undoing every undecided file. \"Undo all\", unless you pass children. */\nexport function DiffUndoAll({ children = ({ text }) => text, ...props }: DiffUndoAllProps) {\n  return <parts.UndoAll {...props}>{children}</parts.UndoAll>;\n}\n\nexport type DiffKeepAllProps = ComponentProps<typeof parts.KeepAll>;\n\n/** \"Keep all\", unless you pass children. */\nexport function DiffKeepAll({\n  children = ({ text }) => (\n    <>\n      {PENDING}\n      {text}\n    </>\n  ),\n  ...props\n}: DiffKeepAllProps) {\n  return <parts.KeepAll {...props}>{children}</parts.KeepAll>;\n}\n\nexport type DiffUndoAllQuestionProps = ComponentProps<typeof parts.UndoAllQuestion>;\n\n/** \"Undo all 4 files? This can't be undone.\", unless you pass children. */\nexport function DiffUndoAllQuestion({\n  children = ({ text, warning }) => (\n    <>\n      {text} <span data-diff-warning=\"\">{warning}</span>\n    </>\n  ),\n  ...props\n}: DiffUndoAllQuestionProps) {\n  return <parts.UndoAllQuestion {...props}>{children}</parts.UndoAllQuestion>;\n}\n\nexport type DiffUndoAllCancelProps = ComponentProps<typeof parts.UndoAllCancel>;\n\n/** \"Cancel\", unless you pass children. */\nexport function DiffUndoAllCancel({ children = ({ text }) => text, ...props }: DiffUndoAllCancelProps) {\n  return <parts.UndoAllCancel {...props}>{children}</parts.UndoAllCancel>;\n}\n\nexport type DiffUndoAllConfirmProps = ComponentProps<typeof parts.UndoAllConfirm>;\n\n/** Undoes every undecided file. \"Undo all\", unless you pass children. */\nexport function DiffUndoAllConfirm({\n  children = ({ text }) => (\n    <>\n      {PENDING}\n      {text}\n    </>\n  ),\n  ...props\n}: DiffUndoAllConfirmProps) {\n  return <parts.UndoAllConfirm {...props}>{children}</parts.UndoAllConfirm>;\n}\n\nexport type DiffSummaryErrorProps = ComponentProps<typeof parts.SummaryError>;\n\n/** \"Couldn't undo all changes\", unless you pass children. */\nexport function DiffSummaryError({ children = ({ text }) => text, ...props }: DiffSummaryErrorProps) {\n  return <parts.SummaryError {...props}>{children}</parts.SummaryError>;\n}\n\nexport type DiffListProps = ComponentProps<typeof parts.List>;\n\n/** A `DiffFile` for each file, unless you pass children. */\nexport function DiffList({\n  children = ({ paths }) => paths.map((path) => <DiffFile key={path} value={path} />),\n  ...props\n}: DiffListProps) {\n  return <parts.List {...props}>{children}</parts.List>;\n}\n\nexport type DiffFileProps = ComponentProps<typeof parts.File>;\n\n/**\n * The file whose path is `value`: its row and its lines, unless you pass children. Memoized, so a file that didn't\n * change isn't rendered again when another streams.\n */\nexport const DiffFile = memo(function DiffFile({ children = FILE_PARTS, ...props }: DiffFileProps) {\n  return <parts.File {...props}>{children}</parts.File>;\n});\n\n/** Opens and closes the file's lines. Holds its path, status and counts. */\nexport const DiffFileTrigger = parts.FileTrigger;\n\nexport type DiffFilePathProps = ComponentProps<typeof parts.FilePath>;\n\n/** The path, cut at its start when it's long so the file name stays, unless you pass children. */\nexport function DiffFilePath({ children = ({ text }) => <bdi>{text}</bdi>, ...props }: DiffFilePathProps) {\n  return <parts.FilePath {...props}>{children}</parts.FilePath>;\n}\n\nexport type DiffFileOldPathProps = ComponentProps<typeof parts.FileOldPath>;\n\n/** \"from old/path.ts\" for a rename, unless you pass children. */\nexport function DiffFileOldPath({\n  children = ({ text }) => <bdi>{text}</bdi>,\n  ...props\n}: DiffFileOldPathProps) {\n  return <parts.FileOldPath {...props}>{children}</parts.FileOldPath>;\n}\n\nexport type DiffFileStatusProps = ComponentProps<typeof parts.FileStatus>;\n\n/** \"Added\", \"Deleted\" or \"Renamed\", unless you pass children. Absent for a modified file. */\nexport function DiffFileStatus({ children = ({ text }) => text, ...props }: DiffFileStatusProps) {\n  return <parts.FileStatus {...props}>{children}</parts.FileStatus>;\n}\n\nexport type DiffFileCountsProps = ComponentProps<typeof parts.FileCounts>;\n\n/** \"+4 −2\", read as \"4 additions, 2 deletions\", unless you pass children. */\nexport function DiffFileCounts({ children = counts, ...props }: DiffFileCountsProps) {\n  return <parts.FileCounts {...props}>{children}</parts.FileCounts>;\n}\n\nexport type DiffFileUndoProps = ComponentProps<typeof parts.FileUndo>;\n\n/** \"Undo\", named with the path, unless you pass children. */\nexport function DiffFileUndo({ children = ({ text }) => text, ...props }: DiffFileUndoProps) {\n  return <parts.FileUndo {...props}>{children}</parts.FileUndo>;\n}\n\nexport type DiffFileKeepProps = ComponentProps<typeof parts.FileKeep>;\n\n/** \"Keep\", named with the path, unless you pass children. */\nexport function DiffFileKeep({ children = ({ text }) => text, ...props }: DiffFileKeepProps) {\n  return <parts.FileKeep {...props}>{children}</parts.FileKeep>;\n}\n\nconst RUNNING = <span data-status-mark=\"\" data-status=\"running\" aria-hidden=\"true\" />;\nconst PENDING = (\n  <span data-kind-pending-mark=\"\" data-status-mark=\"\" data-status=\"running\" aria-hidden=\"true\" />\n);\n\nconst outcome = ({ text, working }: { text: string; working: boolean }) => (\n  <>\n    {working && RUNNING}\n    {text}\n  </>\n);\n\nexport type DiffFileOutcomeProps = ComponentProps<typeof parts.FileOutcome>;\n\n/** \"Kept\", \"Undone\", \"Keeping…\" or \"Undoing…\" in the buttons' place, unless you pass children. */\nexport function DiffFileOutcome({ children = outcome, ...props }: DiffFileOutcomeProps) {\n  return <parts.FileOutcome {...props}>{children}</parts.FileOutcome>;\n}\n\nexport type DiffFileErrorProps = ComponentProps<typeof parts.FileError>;\n\n/** \"Couldn't undo `auth.ts`\", unless you pass children. */\nexport function DiffFileError({ children = ({ text }) => withCode(text), ...props }: DiffFileErrorProps) {\n  return <parts.FileError {...props}>{children}</parts.FileError>;\n}\n\nexport type DiffFileNoteProps = ComponentProps<typeof parts.FileNote>;\n\n/** \"Binary file, not shown\" or \"Renamed, no changes\" in place of lines, unless you pass children. */\nexport function DiffFileNote({ children = ({ text }) => text, ...props }: DiffFileNoteProps) {\n  return <parts.FileNote {...props}>{children}</parts.FileNote>;\n}\n\nexport type DiffColumnProps = ComponentProps<typeof parts.Column>;\n\n/** A column's name for screen readers, unless you pass children. */\nexport function DiffColumn({ children = ({ text }) => text, ...props }: DiffColumnProps) {\n  return <parts.Column {...props}>{children}</parts.Column>;\n}\n\nexport type DiffTableProps = ComponentProps<typeof parts.Table>;\n\n/** The column headers, then a `DiffChange` or `DiffLine` for each row, unless you pass children. */\nexport function DiffTable({\n  children = ({ rows, columns }) => (\n    <>\n      <DiffHead>\n        {columns.map((column) => (\n          <DiffColumn key={column} value={column} />\n        ))}\n      </DiffHead>\n      {rows.map((row) =>\n        row.change ? (\n          <DiffChange key={row.key} value={row.key} />\n        ) : (\n          <DiffLine key={row.key} value={row.key} />\n        ),\n      )}\n    </>\n  ),\n  ...props\n}: DiffTableProps) {\n  return <parts.Table {...props}>{children}</parts.Table>;\n}\n\nexport type DiffChangeProps = ComponentProps<typeof parts.Change>;\n\n/** A change's header row, \"Change 1 of 2 · line 19\" with its Keep and Undo, unless you pass children. Memoized. */\nexport const DiffChange = memo(function DiffChange({ children = CHANGE_PARTS, ...props }: DiffChangeProps) {\n  return <parts.Change {...props}>{children}</parts.Change>;\n});\n\nexport type DiffChangeTitleProps = ComponentProps<typeof parts.ChangeTitle>;\n\n/** The change's words, then its error, Undo, Keep and outcome, unless you pass children. */\nexport function DiffChangeTitle({\n  children = ({ text }) => (\n    <>\n      <span data-diff-change-text=\"\">{text}</span>\n      <DiffChangeError />\n      <DiffChangeUndo />\n      <DiffChangeKeep />\n      <DiffChangeOutcome />\n    </>\n  ),\n  ...props\n}: DiffChangeTitleProps) {\n  return <parts.ChangeTitle {...props}>{children}</parts.ChangeTitle>;\n}\n\nexport type DiffChangeUndoProps = ComponentProps<typeof parts.ChangeUndo>;\n\nexport function DiffChangeUndo({ children = ({ text }) => text, ...props }: DiffChangeUndoProps) {\n  return <parts.ChangeUndo {...props}>{children}</parts.ChangeUndo>;\n}\n\nexport type DiffChangeKeepProps = ComponentProps<typeof parts.ChangeKeep>;\n\nexport function DiffChangeKeep({ children = ({ text }) => text, ...props }: DiffChangeKeepProps) {\n  return <parts.ChangeKeep {...props}>{children}</parts.ChangeKeep>;\n}\n\nexport type DiffChangeOutcomeProps = ComponentProps<typeof parts.ChangeOutcome>;\n\nexport function DiffChangeOutcome({ children = outcome, ...props }: DiffChangeOutcomeProps) {\n  return <parts.ChangeOutcome {...props}>{children}</parts.ChangeOutcome>;\n}\n\nexport type DiffChangeErrorProps = ComponentProps<typeof parts.ChangeError>;\n\nexport function DiffChangeError({ children = ({ text }) => text, ...props }: DiffChangeErrorProps) {\n  return <parts.ChangeError {...props}>{children}</parts.ChangeError>;\n}\n\nexport type DiffLineProps = ComponentProps<typeof parts.Line>;\n\n/** A line: its numbers, its sign and its code, unless you pass children. Memoized. */\nexport const DiffLine = memo(function DiffLine({ children = LINE_CELLS, ...props }: DiffLineProps) {\n  return <parts.Line {...props}>{children}</parts.Line>;\n});\n\n/** The line's number in the old file, drawn from `data-line`, so a copy holds only code. */\nexport const DiffOldNumber = parts.OldNumber;\n/** The line's number in the new file, drawn from `data-line`. */\nexport const DiffNewNumber = parts.NewNumber;\n/** `+` or `−`, drawn from `data-sign`. */\nexport const DiffSign = parts.Sign;\n\nconst Piece = ({ piece }: { piece: DiffPiece }) => (\n  <span\n    style={piece.color ? { color: piece.color } : undefined}\n    data-diff-changed={piece.changed ? \"\" : undefined}\n    data-italic={piece.fontStyle === \"italic\" ? \"\" : undefined}\n    data-bold={piece.fontStyle === \"bold\" ? \"\" : undefined}\n  >\n    {piece.text}\n  </span>\n);\n\nconst code = (line: DiffLineView | undefined) => {\n  if (!line) return null;\n  if (line.kind === \"collapsed\") {\n    return (\n      <>\n        <DiffCollapsed />\n        <DiffCollapsedText />\n      </>\n    );\n  }\n  const pieces = line.pieces.map((piece, index) => (\n    // biome-ignore lint/suspicious/noArrayIndexKey: a line's pieces are drawn again as a whole.\n    <Piece key={index} piece={piece} />\n  ));\n  const Tag = line.kind === \"add\" ? \"ins\" : line.kind === \"remove\" ? \"del\" : Fragment;\n  return (\n    <>\n      {line.prefix && <span data-diff-hidden=\"\">{line.prefix} </span>}\n      <Tag>{pieces}</Tag>\n    </>\n  );\n};\n\nexport type DiffCodeProps = ComponentProps<typeof parts.Code>;\n\n/**\n * The line's code, in `ins` or `del` with its changed words marked and hidden words for screen readers, or a\n * collapsed run's `DiffCollapsed` and `DiffCollapsedText`, unless you pass children.\n */\nexport function DiffCode({ children = ({ line }) => code(line), ...props }: DiffCodeProps) {\n  return <parts.Code {...props}>{children}</parts.Code>;\n}\n\nexport type DiffCollapsedProps = ComponentProps<typeof parts.Collapsed>;\n\n/** \"Show 12 lines\", unless you pass children. Its name says where they are. */\nexport function DiffCollapsed({ children = ({ text }) => text, ...props }: DiffCollapsedProps) {\n  return <parts.Collapsed {...props}>{children}</parts.Collapsed>;\n}\n\nexport type DiffCollapsedTextProps = ComponentProps<typeof parts.CollapsedText>;\n\n/** The collapsed lines, hidden until find in page matches one, unless you pass children. */\nexport function DiffCollapsedText({ children = ({ text }) => text, ...props }: DiffCollapsedTextProps) {\n  return <parts.CollapsedText {...props}>{children}</parts.CollapsedText>;\n}\n\nexport type DiffShowAllProps = ComponentProps<typeof parts.ShowAll>;\n\n/** \"Show full diff (6,400 lines)\" for a file cut off at 2,000 rows, unless you pass children. */\nexport function DiffShowAll({ children = ({ text }) => text, ...props }: DiffShowAllProps) {\n  return <parts.ShowAll {...props}>{children}</parts.ShowAll>;\n}\n\n// Shared, so an update doesn't render the default parts' wrappers again.\n\nconst LINE_CELLS = (\n  <>\n    <DiffOldNumber />\n    <DiffNewNumber />\n    <DiffSign />\n    <DiffCode />\n  </>\n);\n\nconst CHANGE_PARTS = <DiffChangeTitle />;\n\nconst FILE_PARTS = (\n  <>\n    <DiffFileTrigger>\n      <span data-diff-name=\"\">\n        <DiffFilePath />\n        <DiffFileOldPath />\n      </span>\n      <DiffFileStatus />\n      <DiffFileCounts />\n      <DiffFileMark />\n    </DiffFileTrigger>\n    <DiffFileActions>\n      <DiffFileError />\n      <DiffFileUndo />\n      <DiffFileKeep />\n      <DiffFileOutcome />\n    </DiffFileActions>\n    <DiffFileContent>\n      <DiffFileNote />\n      <DiffViewport>\n        <DiffTable />\n        <DiffShowAll />\n      </DiffViewport>\n    </DiffFileContent>\n  </>\n);\n\nconst DEFAULT_PARTS = (\n  <>\n    <DiffSummary>\n      <div data-diff-heading=\"\">\n        <DiffSummaryTitle />\n        <DiffSummaryCounts />\n        <DiffSummaryProgress />\n        <DiffSummaryOutcome />\n      </div>\n      <DiffSummaryMark />\n      <DiffSummaryActions>\n        <DiffUndoAllQuestion />\n        <DiffUndoAll />\n        <DiffKeepAll />\n        <DiffUndoAllCancel />\n        <DiffUndoAllConfirm />\n      </DiffSummaryActions>\n      <DiffSummaryError />\n    </DiffSummary>\n    <DiffList />\n  </>\n);\n",
      "type": "registry:ui",
      "target": "@ui/diff.tsx"
    }
  ],
  "meta": {
    "layer": "react"
  },
  "type": "registry:ui"
}
