Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | 'use client'; |
| 2 | |
| 3 | import { FileDiff, type FileDiffProps } from '@pierre/diffs/react'; |
| 4 | import { CopyButton } from './copy-button'; |
| 5 | |
| 6 | /** |
| 7 | * The +/- stat counts live inside @pierre/diffs's open shadow root, so the |
| 8 | * site's global CSS can't reach them. `unsafeCSS` is injected as a <style> |
| 9 | * element *inside* that shadow root (both for the SSR-prerendered HTML and the |
| 10 | * hydrated client render), which is the only place a selector for these counts |
| 11 | * actually matches. Keep this in sync between the SSR preload and FileDiff. |
| 12 | */ |
| 13 | export const HIDE_DIFF_STATS_CSS = '[data-additions-count],[data-deletions-count]{display:none !important;}'; |
| 14 | |
| 15 | /** |
| 16 | * Thin client wrapper around @pierre/diffs FileDiff. The diff metadata and |
| 17 | * prerendered HTML are computed on the server so the first paint is correct |
| 18 | * without a worker round-trip. Pass `code` (the full file at this stage) to show |
| 19 | * a copy-to-clipboard button. |
| 20 | */ |
| 21 | export function DiffView({ |
| 22 | code, |
| 23 | ...props |
| 24 | }: Pick<FileDiffProps<undefined, undefined>, 'fileDiff' | 'prerenderedHTML'> & { code?: string }) { |
| 25 | return ( |
| 26 | <div className="relative w-full"> |
| 27 | {code ? <CopyButton text={code} className="absolute right-2 top-2 z-10" /> : null} |
| 28 | <FileDiff {...props} options={{ diffStyle: 'unified', unsafeCSS: HIDE_DIFF_STATS_CSS }} disableWorkerPool /> |
| 29 | </div> |
| 30 | ); |
| 31 | } |