style: fix format issues (#255)

This commit is contained in:
Carlos Florêncio
2026-02-19 22:18:01 +00:00
committed by GitHub
parent fe9298a7ad
commit 61ef224ec7
753 changed files with 35129 additions and 21169 deletions
+17 -15
View File
@@ -1,9 +1,9 @@
'use client';
"use client";
import { Button } from '@kandev/ui/button';
import { IconTrash, IconEdit, IconMessage } from '@tabler/icons-react';
import type { DiffComment } from '@/lib/diff/types';
import { formatLineRange } from '@/lib/diff';
import { Button } from "@kandev/ui/button";
import { IconTrash, IconEdit, IconMessage } from "@tabler/icons-react";
import type { DiffComment } from "@/lib/diff/types";
import { formatLineRange } from "@/lib/diff";
interface CommentDisplayProps {
/** The comment to display */
@@ -30,7 +30,7 @@ export function CommentDisplay({
if (compact) {
return (
<div
className={`group flex items-start gap-2 rounded border border-border bg-muted/50 px-2 py-1.5 text-xs${onEdit ? ' cursor-pointer hover:bg-muted/80' : ''}`}
className={`group flex items-start gap-2 rounded border border-border bg-muted/50 px-2 py-1.5 text-xs${onEdit ? " cursor-pointer hover:bg-muted/80" : ""}`}
onClick={onEdit}
>
<IconMessage className="mt-0.5 h-3 w-3 shrink-0 text-muted-foreground" />
@@ -44,7 +44,10 @@ export function CommentDisplay({
<Button
size="sm"
variant="ghost"
onClick={(e) => { e.stopPropagation(); onEdit(); }}
onClick={(e) => {
e.stopPropagation();
onEdit();
}}
className="h-4 w-4 cursor-pointer p-0"
>
<IconEdit className="h-3 w-3" />
@@ -54,7 +57,10 @@ export function CommentDisplay({
<Button
size="sm"
variant="ghost"
onClick={(e) => { e.stopPropagation(); onDelete(); }}
onClick={(e) => {
e.stopPropagation();
onDelete();
}}
className="h-4 w-4 cursor-pointer p-0 hover:text-destructive"
>
<IconTrash className="h-3 w-3" />
@@ -71,11 +77,9 @@ export function CommentDisplay({
<div className="mb-1.5 flex items-center justify-between">
<div className="flex items-center gap-1.5 text-xs">
<IconMessage className="h-3.5 w-3.5 text-blue-500" />
<span className="font-medium">
{lineRange}
</span>
<span className="font-medium">{lineRange}</span>
<span className="text-muted-foreground">
({comment.side === 'additions' ? 'new' : 'old'})
({comment.side === "additions" ? "new" : "old"})
</span>
</div>
<div className="flex gap-1 opacity-0 transition-opacity group-hover:opacity-100">
@@ -110,9 +114,7 @@ export function CommentDisplay({
)}
{/* Comment text */}
<p className="whitespace-pre-wrap text-xs leading-relaxed text-foreground">
{comment.text}
</p>
<p className="whitespace-pre-wrap text-xs leading-relaxed text-foreground">{comment.text}</p>
</div>
);
}
+12 -11
View File
@@ -1,9 +1,9 @@
'use client';
"use client";
import { useState, useRef, useEffect } from 'react';
import { Button } from '@kandev/ui/button';
import { Textarea } from '@kandev/ui/textarea';
import { IconSend, IconX } from '@tabler/icons-react';
import { useState, useRef, useEffect } from "react";
import { Button } from "@kandev/ui/button";
import { Textarea } from "@kandev/ui/textarea";
import { IconSend, IconX } from "@tabler/icons-react";
interface CommentFormProps {
/** Initial content for editing */
@@ -19,7 +19,7 @@ interface CommentFormProps {
}
export function CommentForm({
initialContent = '',
initialContent = "",
onSubmit,
onCancel,
isEditing = false,
@@ -38,15 +38,15 @@ export function CommentForm({
const trimmed = content.trim();
if (trimmed) {
onSubmit(trimmed);
setContent('');
setContent("");
}
};
const handleKeyDown = (e: React.KeyboardEvent) => {
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
e.preventDefault();
handleSubmit();
} else if (e.key === 'Escape') {
} else if (e.key === "Escape") {
e.preventDefault();
onCancel();
}
@@ -65,7 +65,8 @@ export function CommentForm({
/>
<div className="flex items-center justify-between gap-2">
<span className="text-[10px] text-muted-foreground">
{typeof navigator !== 'undefined' && navigator.platform?.includes('Mac') ? '⌘' : 'Ctrl'}+Enter to submit
{typeof navigator !== "undefined" && navigator.platform?.includes("Mac") ? "⌘" : "Ctrl"}
+Enter to submit
</span>
<div className="flex gap-1">
<Button
@@ -84,7 +85,7 @@ export function CommentForm({
className="h-6 cursor-pointer px-2 text-xs"
>
<IconSend className="mr-1 h-3 w-3" />
{isEditing ? 'Update' : 'Add'}
{isEditing ? "Update" : "Add"}
</Button>
</div>
</div>
@@ -1,12 +1,19 @@
'use client';
"use client";
import { useCallback, type ReactNode } from 'react';
import { cn } from '@kandev/ui/lib/utils';
import { Button } from '@kandev/ui/button';
import { Tooltip, TooltipTrigger, TooltipContent } from '@kandev/ui/tooltip';
import { IconCopy, IconTextWrap, IconLayoutRows, IconLayoutColumns, IconPencil, IconArrowBackUp } from '@tabler/icons-react';
import type { RenderHeaderMetadataProps } from '@pierre/diffs';
import type { ViewMode } from '@/hooks/use-global-view-mode';
import { useCallback, type ReactNode } from "react";
import { cn } from "@kandev/ui/lib/utils";
import { Button } from "@kandev/ui/button";
import { Tooltip, TooltipTrigger, TooltipContent } from "@kandev/ui/tooltip";
import {
IconCopy,
IconTextWrap,
IconLayoutRows,
IconLayoutColumns,
IconPencil,
IconArrowBackUp,
} from "@tabler/icons-react";
import type { RenderHeaderMetadataProps } from "@pierre/diffs";
import type { ViewMode } from "@/hooks/use-global-view-mode";
interface DiffHeaderToolbarOptions {
filePath: string;
@@ -41,7 +48,7 @@ export function useDiffHeaderToolbar({
variant="ghost"
size="sm"
className="h-6 w-6 p-0 cursor-pointer opacity-60 hover:opacity-100"
onClick={() => navigator.clipboard.writeText(diff || '')}
onClick={() => navigator.clipboard.writeText(diff || "")}
>
<IconCopy className="h-3.5 w-3.5" />
</Button>
@@ -71,8 +78,8 @@ export function useDiffHeaderToolbar({
variant="ghost"
size="sm"
className={cn(
'h-6 w-6 p-0 cursor-pointer opacity-60 hover:opacity-100',
wordWrap && 'opacity-100 bg-muted'
"h-6 w-6 p-0 cursor-pointer opacity-60 hover:opacity-100",
wordWrap && "opacity-100 bg-muted",
)}
onClick={onToggleWordWrap}
>
@@ -90,7 +97,7 @@ export function useDiffHeaderToolbar({
className="h-6 w-6 p-0 cursor-pointer opacity-60 hover:opacity-100"
onClick={onToggleViewMode}
>
{viewMode === 'split' ? (
{viewMode === "split" ? (
<IconLayoutRows className="h-3.5 w-3.5" />
) : (
<IconLayoutColumns className="h-3.5 w-3.5" />
@@ -98,7 +105,7 @@ export function useDiffHeaderToolbar({
</Button>
</TooltipTrigger>
<TooltipContent>
{viewMode === 'split' ? 'Switch to unified view' : 'Switch to split view'}
{viewMode === "split" ? "Switch to unified view" : "Switch to split view"}
</TooltipContent>
</Tooltip>
@@ -120,7 +127,7 @@ export function useDiffHeaderToolbar({
</div>
);
},
[filePath, diff, wordWrap, onToggleWordWrap, viewMode, onToggleViewMode, onOpenFile, onRevert]
[filePath, diff, wordWrap, onToggleWordWrap, viewMode, onToggleViewMode, onOpenFile, onRevert],
);
return renderHeaderMetadata;
@@ -1,4 +1,4 @@
'use client';
"use client";
// Re-export resolver-aware version
export { DiffViewInlineResolved as DiffViewInline } from './diff-viewer-resolver';
export { DiffViewInlineResolved as DiffViewInline } from "./diff-viewer-resolver";
@@ -1,11 +1,14 @@
'use client';
"use client";
import { memo } from 'react';
import { useEditorProvider } from '@/hooks/use-editor-resolver';
import { DiffViewer as PierreDiffViewer, DiffViewInline as PierreDiffViewInline } from './diff-viewer';
import { MonacoDiffViewer } from '@/components/editors/monaco/monaco-diff-viewer';
import type { FileDiffData, DiffComment } from '@/lib/diff/types';
import type { RevertBlockInfo } from './diff-viewer';
import { memo } from "react";
import { useEditorProvider } from "@/hooks/use-editor-resolver";
import {
DiffViewer as PierreDiffViewer,
DiffViewInline as PierreDiffViewInline,
} from "./diff-viewer";
import { MonacoDiffViewer } from "@/components/editors/monaco/monaco-diff-viewer";
import type { FileDiffData, DiffComment } from "@/lib/diff/types";
import type { RevertBlockInfo } from "./diff-viewer";
export type { RevertBlockInfo };
interface DiffViewerResolverProps {
@@ -28,8 +31,8 @@ interface DiffViewerResolverProps {
}
export const DiffViewerResolved = memo(function DiffViewerResolved(props: DiffViewerResolverProps) {
const provider = useEditorProvider('diff-viewer');
if (provider === 'monaco') {
const provider = useEditorProvider("diff-viewer");
if (provider === "monaco") {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { enableComments, ...rest } = props;
return <MonacoDiffViewer {...rest} />;
@@ -37,9 +40,15 @@ export const DiffViewerResolved = memo(function DiffViewerResolved(props: DiffVi
return <PierreDiffViewer {...props} />;
});
export function DiffViewInlineResolved({ data, className }: { data: FileDiffData; className?: string }) {
const provider = useEditorProvider('chat-diff');
if (provider === 'monaco') {
export function DiffViewInlineResolved({
data,
className,
}: {
data: FileDiffData;
className?: string;
}) {
const provider = useEditorProvider("chat-diff");
if (provider === "monaco") {
return <MonacoDiffViewer data={data} compact hideHeader className={className} />;
}
return <PierreDiffViewInline data={data} className={className} />;
+56 -44
View File
@@ -1,13 +1,13 @@
'use client';
"use client";
import { useState, useRef, memo } from 'react';
import { FileDiff } from '@pierre/diffs/react';
import { cn } from '@kandev/ui/lib/utils';
import type { FileDiffData, DiffComment } from '@/lib/diff/types';
import { useHunkHover } from './use-hunk-hover';
import { useAnnotationRenderer } from './use-diff-annotation-renderer';
import { useDiffOptions } from './use-diff-options';
import { useDiffViewerState } from './use-diff-viewer-state';
import { useState, useRef, memo } from "react";
import { FileDiff } from "@pierre/diffs/react";
import { cn } from "@kandev/ui/lib/utils";
import type { FileDiffData, DiffComment } from "@/lib/diff/types";
import { useHunkHover } from "./use-hunk-hover";
import { useAnnotationRenderer } from "./use-diff-annotation-renderer";
import { useDiffOptions } from "./use-diff-options";
import { useDiffViewerState } from "./use-diff-viewer-state";
export type RevertBlockInfo = {
/** 1-based line number in the new file where additions start */
@@ -36,13 +36,24 @@ interface DiffViewerProps {
}
const SCALAR_PROP_KEYS: (keyof DiffViewerProps)[] = [
'enableComments', 'sessionId', 'compact', 'hideHeader', 'className',
'onOpenFile', 'onRevert', 'enableAcceptReject', 'onRevertBlock', 'wordWrap',
"enableComments",
"sessionId",
"compact",
"hideHeader",
"className",
"onOpenFile",
"onRevert",
"enableAcceptReject",
"onRevertBlock",
"wordWrap",
];
const DATA_KEYS: (keyof FileDiffData)[] = ['filePath', 'diff', 'oldContent', 'newContent'];
const DATA_KEYS: (keyof FileDiffData)[] = ["filePath", "diff", "oldContent", "newContent"];
function areCommentsEqual(prev: DiffComment[] | undefined, next: DiffComment[] | undefined): boolean {
function areCommentsEqual(
prev: DiffComment[] | undefined,
next: DiffComment[] | undefined,
): boolean {
if (prev === next) return true;
if (!prev || !next || prev.length !== next.length) return false;
return prev.every((c, i) => c.id === next[i].id && c.text === next[i].text);
@@ -79,8 +90,14 @@ export const DiffViewer = memo(function DiffViewer({
const wrapperRef = useRef<HTMLDivElement>(null);
const state = useDiffViewerState({
data, enableComments, enableAcceptReject, sessionId,
onCommentAdd, onCommentDelete, externalComments, onRevertBlock,
data,
enableComments,
enableAcceptReject,
sessionId,
onCommentAdd,
onCommentDelete,
externalComments,
onRevertBlock,
});
const { onLineEnter, onLineLeave, onButtonEnter, onButtonLeave } = useHunkHover({
@@ -91,7 +108,8 @@ export const DiffViewer = memo(function DiffViewer({
const renderAnnotation = useAnnotationRenderer({
handleRevertBlock: state.handleRevertBlock,
onButtonEnter, onButtonLeave,
onButtonEnter,
onButtonLeave,
handleCommentSubmit: state.handleCommentSubmit,
handleCommentUpdate: state.handleCommentUpdate,
handleCommentDelete: state.handleCommentDelete,
@@ -103,27 +121,37 @@ export const DiffViewer = memo(function DiffViewer({
const showHeader = !hideHeader && !compact;
const { options, renderHeaderMetadata, renderHoverUtility } = useDiffOptions({
filePath: data.filePath, diff: data.diff, enableComments, showHeader, wordWrap,
setWordWrap, handleLineSelectionEnd: state.handleLineSelectionEnd,
onLineEnter, onLineLeave, onOpenFile, onRevert,
filePath: data.filePath,
diff: data.diff,
enableComments,
showHeader,
wordWrap,
setWordWrap,
handleLineSelectionEnd: state.handleLineSelectionEnd,
onLineEnter,
onLineLeave,
onOpenFile,
onRevert,
});
const controlledSelection = state.showCommentForm ? state.selectedLines : null;
if (!state.fileDiffMetadata) {
return (
<div className={cn(
'rounded-md border border-border/50 bg-muted/20 p-4 text-muted-foreground',
'text-xs',
className
)}>
<div
className={cn(
"rounded-md border border-border/50 bg-muted/20 p-4 text-muted-foreground",
"text-xs",
className,
)}
>
No diff available
</div>
);
}
return (
<div ref={wrapperRef} className={cn('diff-viewer', className)}>
<div ref={wrapperRef} className={cn("diff-viewer", className)}>
<FileDiff
fileDiff={state.fileDiffMetadata}
options={options}
@@ -132,29 +160,13 @@ export const DiffViewer = memo(function DiffViewer({
renderAnnotation={renderAnnotation}
renderHeaderMetadata={renderHeaderMetadata}
renderHoverUtility={renderHoverUtility}
className={cn(
'rounded-md border border-border/50',
'text-xs'
)}
className={cn("rounded-md border border-border/50", "text-xs")}
/>
</div>
);
}, arePropsEqual);
/** Compact inline diff viewer for chat messages (Pierre implementation). */
export function DiffViewInline({
data,
className,
}: {
data: FileDiffData;
className?: string;
}) {
return (
<DiffViewer
data={data}
compact
hideHeader
className={className}
/>
);
export function DiffViewInline({ data, className }: { data: FileDiffData; className?: string }) {
return <DiffViewer data={data} compact hideHeader className={className} />;
}
+8 -11
View File
@@ -1,10 +1,10 @@
'use client';
"use client";
import { memo, useMemo } from 'react';
import { DiffViewerResolved as DiffViewer } from './diff-viewer-resolver';
import { transformGitDiff } from '@/lib/diff';
import type { DiffComment } from '@/lib/diff/types';
import type { RevertBlockInfo } from './diff-viewer-resolver';
import { memo, useMemo } from "react";
import { DiffViewerResolved as DiffViewer } from "./diff-viewer-resolver";
import { transformGitDiff } from "@/lib/diff";
import type { DiffComment } from "@/lib/diff/types";
import type { RevertBlockInfo } from "./diff-viewer-resolver";
interface FileDiffViewerProps {
filePath: string;
@@ -37,7 +37,7 @@ interface FileDiffViewerProps {
export const FileDiffViewer = memo(function FileDiffViewer({
filePath,
diff,
status = 'M',
status = "M",
enableComments,
sessionId,
onCommentAdd,
@@ -52,10 +52,7 @@ export const FileDiffViewer = memo(function FileDiffViewer({
onRevertBlock,
wordWrap,
}: FileDiffViewerProps) {
const data = useMemo(
() => transformGitDiff(filePath, diff, status),
[filePath, diff, status]
);
const data = useMemo(() => transformGitDiff(filePath, diff, status), [filePath, diff, status]);
return (
<DiffViewer
+19 -12
View File
@@ -1,8 +1,8 @@
'use client';
"use client";
import { useState } from 'react';
import { Button } from '@kandev/ui/button';
import { IconArrowBackUp, IconLoader2 } from '@tabler/icons-react';
import { useState } from "react";
import { Button } from "@kandev/ui/button";
import { IconArrowBackUp, IconLoader2 } from "@tabler/icons-react";
interface HunkActionBarProps {
changeBlockId: string;
@@ -11,7 +11,12 @@ interface HunkActionBarProps {
onMouseLeave: () => void;
}
export function HunkActionBar({ changeBlockId, onRevert, onMouseEnter, onMouseLeave }: HunkActionBarProps) {
export function HunkActionBar({
changeBlockId,
onRevert,
onMouseEnter,
onMouseLeave,
}: HunkActionBarProps) {
const [loading, setLoading] = useState(false);
const handleClick = async () => {
@@ -29,15 +34,15 @@ export function HunkActionBar({ changeBlockId, onRevert, onMouseEnter, onMouseLe
<div
data-cb={changeBlockId}
style={{
position: 'relative',
position: "relative",
zIndex: 10,
width: '100%',
overflow: 'visible',
width: "100%",
overflow: "visible",
}}
>
<div
data-undo-btn=""
style={{ opacity: 0, pointerEvents: 'none', transition: 'opacity 150ms' }}
style={{ opacity: 0, pointerEvents: "none", transition: "opacity 150ms" }}
className="absolute top-1 right-2"
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
@@ -49,9 +54,11 @@ export function HunkActionBar({ changeBlockId, onRevert, onMouseEnter, onMouseLe
className="h-6 gap-1 px-2 text-xs cursor-pointer rounded border border-border/60 bg-background text-muted-foreground shadow-sm hover:text-red-500 hover:bg-red-500/10 hover:border-red-500/30"
onClick={handleClick}
>
{loading
? <IconLoader2 className="h-3.5 w-3.5 animate-spin" />
: <IconArrowBackUp className="h-3.5 w-3.5" />}
{loading ? (
<IconLoader2 className="h-3.5 w-3.5 animate-spin" />
) : (
<IconArrowBackUp className="h-3.5 w-3.5" />
)}
Undo
</Button>
</div>
+9 -9
View File
@@ -1,14 +1,14 @@
// Main components - resolver-aware
export { DiffViewerResolved as DiffViewer } from './diff-viewer-resolver';
export { DiffViewInlineResolved as DiffViewInline } from './diff-viewer-resolver';
export { FileDiffViewer } from './file-diff-viewer';
export type { RevertBlockInfo } from './diff-viewer-resolver';
export { CommentForm } from './comment-form';
export { CommentDisplay } from './comment-display';
export { DiffViewerResolved as DiffViewer } from "./diff-viewer-resolver";
export { DiffViewInlineResolved as DiffViewInline } from "./diff-viewer-resolver";
export { FileDiffViewer } from "./file-diff-viewer";
export type { RevertBlockInfo } from "./diff-viewer-resolver";
export { CommentForm } from "./comment-form";
export { CommentDisplay } from "./comment-display";
// Direct access to Pierre implementation (for internal use)
export { DiffViewer as PierreDiffViewer } from './diff-viewer';
export { DiffViewInline as PierreDiffViewInline } from './diff-viewer';
export { DiffViewer as PierreDiffViewer } from "./diff-viewer";
export { DiffViewInline as PierreDiffViewInline } from "./diff-viewer";
// Hooks
export { useDiffComments } from './use-diff-comments';
export { useDiffComments } from "./use-diff-comments";
@@ -1,12 +1,12 @@
import { useCallback, type ReactNode } from 'react';
import type { DiffLineAnnotation } from '@pierre/diffs';
import type { DiffComment } from '@/lib/diff/types';
import { CommentForm } from './comment-form';
import { CommentDisplay } from './comment-display';
import { HunkActionBar } from './hunk-action-bar';
import { useCallback, type ReactNode } from "react";
import type { DiffLineAnnotation } from "@pierre/diffs";
import type { DiffComment } from "@/lib/diff/types";
import { CommentForm } from "./comment-form";
import { CommentDisplay } from "./comment-display";
import { HunkActionBar } from "./hunk-action-bar";
type AnnotationMetadata = {
type: 'comment' | 'new-comment-form' | 'hunk-actions';
type: "comment" | "new-comment-form" | "hunk-actions";
comment?: DiffComment;
isEditing?: boolean;
changeBlockId?: string;
@@ -28,16 +28,22 @@ export type { AnnotationMetadata };
export function useAnnotationRenderer(opts: UseAnnotationRendererOpts) {
const {
handleRevertBlock, onButtonEnter, onButtonLeave,
handleCommentSubmit, handleCommentUpdate, handleCommentDelete,
setShowCommentForm, setSelectedLines, setEditingComment,
handleRevertBlock,
onButtonEnter,
onButtonLeave,
handleCommentSubmit,
handleCommentUpdate,
handleCommentDelete,
setShowCommentForm,
setSelectedLines,
setEditingComment,
} = opts;
return useCallback(
(annotation: DiffLineAnnotation<AnnotationMetadata>): ReactNode => {
const { type, comment, isEditing, changeBlockId } = annotation.metadata;
if (type === 'hunk-actions' && changeBlockId) {
if (type === "hunk-actions" && changeBlockId) {
return (
<HunkActionBar
key={changeBlockId}
@@ -49,7 +55,7 @@ export function useAnnotationRenderer(opts: UseAnnotationRendererOpts) {
);
}
if (type === 'new-comment-form') {
if (type === "new-comment-form") {
return (
<div className="my-1 px-2">
<CommentForm
@@ -91,6 +97,16 @@ export function useAnnotationRenderer(opts: UseAnnotationRendererOpts) {
return null;
},
[setEditingComment, handleCommentDelete, handleCommentUpdate, handleCommentSubmit, handleRevertBlock, onButtonEnter, onButtonLeave, setShowCommentForm, setSelectedLines]
[
setEditingComment,
handleCommentDelete,
handleCommentUpdate,
handleCommentSubmit,
handleRevertBlock,
onButtonEnter,
onButtonLeave,
setShowCommentForm,
setSelectedLines,
],
);
}
+22 -34
View File
@@ -1,16 +1,12 @@
'use client';
"use client";
import { useCallback, useMemo } from 'react';
import { toast } from 'sonner';
import type { SelectedLineRange } from '@pierre/diffs';
import { useCommentsStore } from '@/lib/state/slices/comments';
import { useDiffFileComments } from '@/hooks/domains/comments/use-diff-comments';
import {
commentsToAnnotations,
extractCodeFromDiff,
extractCodeFromContent,
} from '@/lib/diff';
import type { DiffComment, AnnotationSide, CommentAnnotation } from '@/lib/diff/types';
import { useCallback, useMemo } from "react";
import { toast } from "sonner";
import type { SelectedLineRange } from "@pierre/diffs";
import { useCommentsStore } from "@/lib/state/slices/comments";
import { useDiffFileComments } from "@/hooks/domains/comments/use-diff-comments";
import { commentsToAnnotations, extractCodeFromDiff, extractCodeFromContent } from "@/lib/diff";
import type { DiffComment, AnnotationSide, CommentAnnotation } from "@/lib/diff/types";
interface UseDiffCommentsOptions {
sessionId: string;
@@ -29,10 +25,7 @@ interface UseDiffCommentsReturn {
/** Annotations formatted for @pierre/diffs */
annotations: CommentAnnotation[];
/** Add a new comment */
addComment: (
range: SelectedLineRange,
text: string
) => void;
addComment: (range: SelectedLineRange, text: string) => void;
/** Remove a comment */
removeComment: (commentId: string) => void;
/** Update a comment */
@@ -54,31 +47,26 @@ export function useDiffComments({
oldContent,
}: UseDiffCommentsOptions): UseDiffCommentsReturn {
const comments = useDiffFileComments(sessionId, filePath);
const editingCommentId = useCommentsStore(
(state) => state.editingCommentId
);
const editingCommentId = useCommentsStore((state) => state.editingCommentId);
const storeAddComment = useCommentsStore((state) => state.addComment);
const storeRemoveComment = useCommentsStore((state) => state.removeComment);
const storeUpdateComment = useCommentsStore((state) => state.updateComment);
const storeSetEditingComment = useCommentsStore((state) => state.setEditingComment);
const annotations = useMemo(
() => commentsToAnnotations(comments),
[comments]
);
const annotations = useMemo(() => commentsToAnnotations(comments), [comments]);
const addComment = useCallback(
(range: SelectedLineRange, text: string) => {
const side = (range.side || 'additions') as AnnotationSide;
const side = (range.side || "additions") as AnnotationSide;
const startLine = Math.min(range.start, range.end);
const endLine = Math.max(range.start, range.end);
// Extract the code content from the selected lines
let codeContent = '';
let codeContent = "";
if (diff) {
codeContent = extractCodeFromDiff(diff, startLine, endLine, side);
} else {
const content = side === 'additions' ? newContent : oldContent;
const content = side === "additions" ? newContent : oldContent;
if (content) {
codeContent = extractCodeFromContent(content, startLine, endLine);
}
@@ -86,7 +74,7 @@ export function useDiffComments({
const comment: DiffComment = {
id: `${filePath}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
source: 'diff',
source: "diff",
sessionId,
filePath,
startLine,
@@ -95,37 +83,37 @@ export function useDiffComments({
codeContent,
text,
createdAt: new Date().toISOString(),
status: 'pending',
status: "pending",
};
storeAddComment(comment);
toast.success('Comment added', {
description: 'Your comment will be sent with your next message.',
toast.success("Comment added", {
description: "Your comment will be sent with your next message.",
duration: 2000,
});
},
[sessionId, filePath, diff, newContent, oldContent, storeAddComment]
[sessionId, filePath, diff, newContent, oldContent, storeAddComment],
);
const removeComment = useCallback(
(commentId: string) => {
storeRemoveComment(commentId);
},
[storeRemoveComment]
[storeRemoveComment],
);
const updateComment = useCallback(
(commentId: string, updates: Partial<DiffComment>) => {
storeUpdateComment(commentId, updates);
},
[storeUpdateComment]
[storeUpdateComment],
);
const setEditingComment = useCallback(
(commentId: string | null) => {
storeSetEditingComment(commentId);
},
[storeSetEditingComment]
[storeSetEditingComment],
);
return {
@@ -1,7 +1,7 @@
import { useMemo } from 'react';
import { parsePatchFiles, parseDiffFromFile } from '@pierre/diffs';
import type { FileDiffMetadata } from '@pierre/diffs';
import type { FileDiffData } from '@/lib/diff/types';
import { useMemo } from "react";
import { parsePatchFiles, parseDiffFromFile } from "@pierre/diffs";
import type { FileDiffMetadata } from "@pierre/diffs";
import type { FileDiffData } from "@/lib/diff/types";
/**
* Check if Go code contains patterns that trigger catastrophic regex backtracking
@@ -14,7 +14,7 @@ function hasProblematicGoPattern(content: string | undefined): boolean {
}
function isGoFile(filePath: string): boolean {
return filePath.endsWith('.go');
return filePath.endsWith(".go");
}
/** Parse diff data into FileDiffMetadata, with Go-specific safety checks. */
@@ -27,14 +27,14 @@ export function useDiffMetadata(data: FileDiffData): FileDiffMetadata | null {
} else if (data.oldContent || data.newContent) {
result = parseDiffFromFile(
{ name: data.filePath, contents: data.oldContent },
{ name: data.filePath, contents: data.newContent }
{ name: data.filePath, contents: data.newContent },
);
}
if (result && isGoFile(data.filePath)) {
const contentToCheck = data.newContent || data.oldContent || data.diff;
if (hasProblematicGoPattern(contentToCheck)) {
result = { ...result, lang: 'text' };
result = { ...result, lang: "text" };
}
}
+58 -39
View File
@@ -1,11 +1,11 @@
import { useCallback, useMemo, type ReactNode } from 'react';
import { useTheme } from 'next-themes';
import type { FileDiffOptions, SelectedLineRange, RenderHeaderMetadataProps } from '@pierre/diffs';
import { IconPlus } from '@tabler/icons-react';
import { FONT } from '@/lib/theme/colors';
import { useGlobalViewMode } from '@/hooks/use-global-view-mode';
import { useDiffHeaderToolbar } from './diff-header-toolbar';
import type { AnnotationMetadata } from './use-diff-annotation-renderer';
import { useCallback, useMemo, type ReactNode } from "react";
import { useTheme } from "next-themes";
import type { FileDiffOptions, SelectedLineRange, RenderHeaderMetadataProps } from "@pierre/diffs";
import { IconPlus } from "@tabler/icons-react";
import { FONT } from "@/lib/theme/colors";
import { useGlobalViewMode } from "@/hooks/use-global-view-mode";
import { useDiffHeaderToolbar } from "./diff-header-toolbar";
import type { AnnotationMetadata } from "./use-diff-annotation-renderer";
/** CSS overrides for the Pierre diff viewer, injected via unsafeCSS. */
const DIFF_UNSAFE_CSS = `
@@ -59,64 +59,83 @@ type UseDiffOptionsResult = {
export function useDiffOptions(args: UseDiffOptionsArgs): UseDiffOptionsResult {
const {
filePath, diff, enableComments, showHeader, wordWrap,
setWordWrap, handleLineSelectionEnd, onLineEnter, onLineLeave,
onOpenFile, onRevert,
filePath,
diff,
enableComments,
showHeader,
wordWrap,
setWordWrap,
handleLineSelectionEnd,
onLineEnter,
onLineLeave,
onOpenFile,
onRevert,
} = args;
const { resolvedTheme } = useTheme();
const [globalViewMode, setGlobalViewMode] = useGlobalViewMode();
const toggleViewMode = useCallback(
() => setGlobalViewMode(globalViewMode === 'split' ? 'unified' : 'split'),
[globalViewMode, setGlobalViewMode]
() => setGlobalViewMode(globalViewMode === "split" ? "unified" : "split"),
[globalViewMode, setGlobalViewMode],
);
const toggleWordWrap = useCallback(
() => setWordWrap((v: boolean) => !v),
[setWordWrap]
);
const toggleWordWrap = useCallback(() => setWordWrap((v: boolean) => !v), [setWordWrap]);
const renderHeaderMetadata = useDiffHeaderToolbar({
filePath, diff, wordWrap,
filePath,
diff,
wordWrap,
onToggleWordWrap: toggleWordWrap,
viewMode: globalViewMode,
onToggleViewMode: toggleViewMode,
onOpenFile, onRevert,
onOpenFile,
onRevert,
});
const renderHoverUtility = useCallback(
(): ReactNode => {
if (!enableComments) return null;
return (
<div
className="flex h-5 w-5 cursor-pointer items-center justify-center rounded border border-border bg-background text-muted-foreground hover:bg-accent hover:text-foreground"
title="Add comment"
>
<IconPlus className="h-3 w-3" />
</div>
);
},
[enableComments]
);
const renderHoverUtility = useCallback((): ReactNode => {
if (!enableComments) return null;
return (
<div
className="flex h-5 w-5 cursor-pointer items-center justify-center rounded border border-border bg-background text-muted-foreground hover:bg-accent hover:text-foreground"
title="Add comment"
>
<IconPlus className="h-3 w-3" />
</div>
);
}, [enableComments]);
const options = useMemo<FileDiffOptions<AnnotationMetadata>>(
() => ({
diffStyle: globalViewMode,
themeType: resolvedTheme === 'dark' ? 'dark' : 'light',
themeType: resolvedTheme === "dark" ? "dark" : "light",
enableLineSelection: enableComments,
hunkSeparators: 'simple',
hunkSeparators: "simple",
enableHoverUtility: enableComments,
diffIndicators: 'none',
diffIndicators: "none",
onLineSelectionEnd: handleLineSelectionEnd,
onLineEnter,
onLineLeave,
disableFileHeader: !showHeader,
overflow: wordWrap ? 'wrap' : 'scroll',
overflow: wordWrap ? "wrap" : "scroll",
unsafeCSS: DIFF_UNSAFE_CSS,
}),
[globalViewMode, resolvedTheme, enableComments, showHeader, handleLineSelectionEnd, wordWrap, onLineEnter, onLineLeave]
[
globalViewMode,
resolvedTheme,
enableComments,
showHeader,
handleLineSelectionEnd,
wordWrap,
onLineEnter,
onLineLeave,
],
);
return { globalViewMode, options, renderHeaderMetadata: showHeader ? renderHeaderMetadata : undefined, renderHoverUtility };
return {
globalViewMode,
options,
renderHeaderMetadata: showHeader ? renderHeaderMetadata : undefined,
renderHoverUtility,
};
}
+200 -74
View File
@@ -1,11 +1,16 @@
import { useState, useCallback, useEffect, useMemo, useRef } from 'react';
import type { SelectedLineRange, FileDiffMetadata, DiffLineAnnotation, AnnotationSide } from '@pierre/diffs';
import type { FileDiffData, DiffComment } from '@/lib/diff/types';
import { buildDiffComment, useCommentActions } from '@/lib/diff/comment-utils';
import { useDiffComments } from './use-diff-comments';
import { useDiffMetadata } from './use-diff-metadata';
import type { RevertBlockInfo } from './diff-viewer';
import type { AnnotationMetadata } from './use-diff-annotation-renderer';
import { useState, useCallback, useEffect, useMemo, useRef, type RefObject } from "react";
import type {
SelectedLineRange,
FileDiffMetadata,
DiffLineAnnotation,
AnnotationSide,
} from "@pierre/diffs";
import type { FileDiffData, DiffComment } from "@/lib/diff/types";
import { buildDiffComment, useCommentActions } from "@/lib/diff/comment-utils";
import { useDiffComments } from "./use-diff-comments";
import { useDiffMetadata } from "./use-diff-metadata";
import type { RevertBlockInfo } from "./diff-viewer";
import type { AnnotationMetadata } from "./use-diff-annotation-renderer";
type BuildAnnotationsOpts = {
comments: DiffComment[];
@@ -37,15 +42,15 @@ function processChangeBlock(
if (aLen === 0 && dLen === 0) return;
const cbId = `cb-${state.blockIdx++}`;
const side: AnnotationSide = aLen > 0 ? 'additions' : 'deletions';
const lineNumber = side === 'additions' ? state.lastCtxAdd : state.lastCtxDel;
result.push({ side, lineNumber, metadata: { type: 'hunk-actions', changeBlockId: cbId } });
const side: AnnotationSide = aLen > 0 ? "additions" : "deletions";
const lineNumber = side === "additions" ? state.lastCtxAdd : state.lastCtxDel;
result.push({ side, lineNumber, metadata: { type: "hunk-actions", changeBlockId: cbId } });
for (let l = 0; l < aLen; l++) newLineMap.set(`additions:${state.addLine + l}`, cbId);
for (let l = 0; l < dLen; l++) newLineMap.set(`deletions:${state.delLine + l}`, cbId);
newRevertMap.set(cbId, {
addStart: state.addLine,
addCount: aLen,
oldLines: content.deletions.map(l => l.replace(/\r?\n$/, '')),
oldLines: content.deletions.map((l) => l.replace(/\r?\n$/, "")),
});
}
@@ -64,7 +69,7 @@ function buildHunkAnnotations(
state.lastCtxAdd = state.addLine > 1 ? state.addLine - 1 : state.addLine;
state.lastCtxDel = state.delLine > 1 ? state.delLine - 1 : state.delLine;
for (const content of hunk.hunkContent) {
if (content.type === 'context') {
if (content.type === "context") {
const len = content.lines.length;
state.lastCtxAdd = state.addLine + len - 1;
state.lastCtxDel = state.delLine + len - 1;
@@ -81,18 +86,25 @@ function buildHunkAnnotations(
/** Build all diff line annotations (comments, new-comment form, hunk actions). */
function buildAnnotations(opts: BuildAnnotationsOpts) {
const { comments, editingCommentId, showCommentForm, selectedLines, enableAcceptReject, fileDiffMetadata } = opts;
const {
comments,
editingCommentId,
showCommentForm,
selectedLines,
enableAcceptReject,
fileDiffMetadata,
} = opts;
const result: DiffLineAnnotation<AnnotationMetadata>[] = comments.map((comment) => ({
side: comment.side,
lineNumber: comment.endLine,
metadata: { type: 'comment' as const, comment, isEditing: editingCommentId === comment.id },
metadata: { type: "comment" as const, comment, isEditing: editingCommentId === comment.id },
}));
if (showCommentForm && selectedLines) {
result.push({
side: (selectedLines.side || 'additions') as AnnotationSide,
side: (selectedLines.side || "additions") as AnnotationSide,
lineNumber: Math.max(selectedLines.start, selectedLines.end),
metadata: { type: 'new-comment-form' as const },
metadata: { type: "new-comment-form" as const },
});
}
@@ -120,20 +132,144 @@ type UseDiffViewerStateOpts = {
onRevertBlock?: (filePath: string, info: RevertBlockInfo) => Promise<void> | void;
};
function useDiffViewerAnnotations({
comments,
editingCommentId,
showCommentForm,
selectedLines,
enableAcceptReject,
fileDiffMetadata,
changeLineMapRef,
revertInfoRef,
}: BuildAnnotationsOpts & {
changeLineMapRef: RefObject<Map<string, string>>;
revertInfoRef: RefObject<Map<string, RevertBlockInfo>>;
}) {
const { annotations, lineMap, revertMap } = useMemo(
() =>
buildAnnotations({
comments,
editingCommentId,
showCommentForm,
selectedLines,
enableAcceptReject,
fileDiffMetadata,
}),
[comments, editingCommentId, showCommentForm, selectedLines, enableAcceptReject, fileDiffMetadata],
);
useEffect(() => {
changeLineMapRef.current = lineMap;
revertInfoRef.current = revertMap;
}, [lineMap, revertMap, changeLineMapRef, revertInfoRef]);
return annotations;
}
function useDiffViewerCommentHandlers({
selectedLines,
setSelectedLines,
setShowCommentForm,
enableComments,
onCommentAdd,
externalComments,
data,
sessionId,
addComment,
removeComment,
updateComment,
setEditingComment,
onCommentDelete,
}: {
selectedLines: SelectedLineRange | null;
setSelectedLines: React.Dispatch<React.SetStateAction<SelectedLineRange | null>>;
setShowCommentForm: React.Dispatch<React.SetStateAction<boolean>>;
enableComments: boolean;
onCommentAdd?: (comment: DiffComment) => void;
externalComments?: DiffComment[];
data: FileDiffData;
sessionId?: string;
addComment: (range: SelectedLineRange, content: string) => void;
removeComment: (commentId: string) => void;
updateComment: (commentId: string, updates: Partial<DiffComment>) => void;
setEditingComment: (commentId: string | null) => void;
onCommentDelete?: (commentId: string) => void;
}) {
const handleLineSelectionEnd = useCallback(
(range: SelectedLineRange | null) => {
setSelectedLines(range);
if (range && enableComments) setShowCommentForm(true);
},
[enableComments, setSelectedLines, setShowCommentForm],
);
const handleCommentSubmit = useCallback(
(content: string) => {
if (!selectedLines) return;
if (onCommentAdd && externalComments !== undefined) {
onCommentAdd(
buildDiffComment({
filePath: data.filePath,
sessionId: sessionId || "",
startLine: selectedLines.start,
endLine: selectedLines.end,
side: (selectedLines.side || "additions") as DiffComment["side"],
text: content,
}),
);
} else if (sessionId) {
addComment(selectedLines, content);
}
setShowCommentForm(false);
setSelectedLines(null);
},
[
selectedLines,
onCommentAdd,
externalComments,
data.filePath,
sessionId,
addComment,
setShowCommentForm,
setSelectedLines,
],
);
const { handleCommentDelete, handleCommentUpdate } = useCommentActions({
removeComment,
updateComment,
setEditingComment,
onCommentDelete,
externalComments,
});
return { handleLineSelectionEnd, handleCommentSubmit, handleCommentDelete, handleCommentUpdate };
}
export function useDiffViewerState(opts: UseDiffViewerStateOpts) {
const {
data, enableComments, enableAcceptReject, sessionId,
onCommentAdd, onCommentDelete, externalComments, onRevertBlock,
data,
enableComments,
enableAcceptReject,
sessionId,
onCommentAdd,
onCommentDelete,
externalComments,
onRevertBlock,
} = opts;
const [selectedLines, setSelectedLines] = useState<SelectedLineRange | null>(null);
const [showCommentForm, setShowCommentForm] = useState(false);
const {
comments: internalComments, addComment, removeComment,
updateComment, editingCommentId, setEditingComment,
comments: internalComments,
addComment,
removeComment,
updateComment,
editingCommentId,
setEditingComment,
} = useDiffComments({
sessionId: sessionId || '',
sessionId: sessionId || "",
filePath: data.filePath,
diff: data.diff,
newContent: data.newContent,
@@ -151,65 +287,55 @@ export function useDiffViewerState(opts: UseDiffViewerStateOpts) {
if (!info) return;
await onRevertBlock?.(data.filePath, info);
},
[data.filePath, onRevertBlock]
[data.filePath, onRevertBlock],
);
// Change line map for hover detection
const changeLineMapRef = useRef<Map<string, string>>(new Map());
const hideTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
// Annotations
const { annotations, lineMap, revertMap } = useMemo(
() => buildAnnotations({ comments, editingCommentId, showCommentForm, selectedLines, enableAcceptReject, fileDiffMetadata }),
[comments, editingCommentId, showCommentForm, selectedLines, enableAcceptReject, fileDiffMetadata],
);
useEffect(() => {
changeLineMapRef.current = lineMap;
revertInfoRef.current = revertMap;
}, [lineMap, revertMap]);
// Selection & comment callbacks
const handleLineSelectionEnd = useCallback(
(range: SelectedLineRange | null) => {
setSelectedLines(range);
if (range && enableComments) setShowCommentForm(true);
},
[enableComments]
);
const handleCommentSubmit = useCallback(
(content: string) => {
if (!selectedLines) return;
if (onCommentAdd && externalComments !== undefined) {
onCommentAdd(buildDiffComment({
filePath: data.filePath,
sessionId: sessionId || '',
startLine: selectedLines.start,
endLine: selectedLines.end,
side: (selectedLines.side || 'additions') as DiffComment['side'],
text: content,
}));
} else if (sessionId) {
addComment(selectedLines, content);
}
setShowCommentForm(false);
setSelectedLines(null);
},
[selectedLines, sessionId, data.filePath, addComment, onCommentAdd, externalComments]
);
const { handleCommentDelete, handleCommentUpdate } = useCommentActions({
removeComment, updateComment, setEditingComment,
onCommentDelete, externalComments,
const annotations = useDiffViewerAnnotations({
comments,
editingCommentId,
showCommentForm,
selectedLines,
enableAcceptReject,
fileDiffMetadata,
changeLineMapRef,
revertInfoRef,
});
const { handleLineSelectionEnd, handleCommentSubmit, handleCommentDelete, handleCommentUpdate } =
useDiffViewerCommentHandlers({
selectedLines,
setSelectedLines,
setShowCommentForm,
enableComments,
onCommentAdd,
externalComments,
data,
sessionId,
addComment,
removeComment,
updateComment,
setEditingComment,
onCommentDelete,
});
return {
comments, fileDiffMetadata, annotations, selectedLines,
showCommentForm, setShowCommentForm, setSelectedLines,
editingCommentId, setEditingComment,
handleRevertBlock, handleLineSelectionEnd, handleCommentSubmit,
handleCommentDelete, handleCommentUpdate,
changeLineMapRef, hideTimeoutRef,
comments,
fileDiffMetadata,
annotations,
selectedLines,
showCommentForm,
setShowCommentForm,
setSelectedLines,
editingCommentId,
setEditingComment,
handleRevertBlock,
handleLineSelectionEnd,
handleCommentSubmit,
handleCommentDelete,
handleCommentUpdate,
changeLineMapRef,
hideTimeoutRef,
};
}
+58 -30
View File
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useRef } from 'react';
import { useCallback, useEffect, useRef } from "react";
type HunkHoverCallbacks = {
wrapperRef: React.RefObject<HTMLDivElement | null>;
@@ -17,26 +17,39 @@ type HunkHoverResult = {
* Manages show/hide of undo buttons when hovering change lines in the diff viewer.
* Uses direct DOM manipulation to avoid re-renders.
*/
export function useHunkHover({ wrapperRef, changeLineMapRef, hideTimeoutRef }: HunkHoverCallbacks): HunkHoverResult {
export function useHunkHover({
wrapperRef,
changeLineMapRef,
hideTimeoutRef,
}: HunkHoverCallbacks): HunkHoverResult {
const activeBlockRef = useRef<string | null>(null);
const isHoveringButtonRef = useRef(false);
const setBlockVisible = useCallback((cbId: string | null, visible: boolean) => {
if (!cbId) return;
const btn = wrapperRef.current?.querySelector(`[data-cb="${cbId}"] [data-undo-btn]`);
if (btn instanceof HTMLElement) {
btn.style.opacity = visible ? '1' : '0';
btn.style.pointerEvents = visible ? 'auto' : 'none';
}
}, [wrapperRef]);
const setBlockVisible = useCallback(
(cbId: string | null, visible: boolean) => {
if (!cbId) return;
const btn = wrapperRef.current?.querySelector(`[data-cb="${cbId}"] [data-undo-btn]`);
if (btn instanceof HTMLElement) {
btn.style.opacity = visible ? "1" : "0";
btn.style.pointerEvents = visible ? "auto" : "none";
}
},
[wrapperRef],
);
const showBlock = useCallback((cbId: string) => {
if (hideTimeoutRef.current) { clearTimeout(hideTimeoutRef.current); hideTimeoutRef.current = null; }
if (activeBlockRef.current === cbId) return;
setBlockVisible(activeBlockRef.current, false);
activeBlockRef.current = cbId;
setBlockVisible(cbId, true);
}, [setBlockVisible, hideTimeoutRef]);
const showBlock = useCallback(
(cbId: string) => {
if (hideTimeoutRef.current) {
clearTimeout(hideTimeoutRef.current);
hideTimeoutRef.current = null;
}
if (activeBlockRef.current === cbId) return;
setBlockVisible(activeBlockRef.current, false);
activeBlockRef.current = cbId;
setBlockVisible(cbId, true);
},
[setBlockVisible, hideTimeoutRef],
);
const hideBlock = useCallback(() => {
if (hideTimeoutRef.current) clearTimeout(hideTimeoutRef.current);
@@ -49,7 +62,10 @@ export function useHunkHover({ wrapperRef, changeLineMapRef, hideTimeoutRef }: H
const onButtonEnter = useCallback(() => {
isHoveringButtonRef.current = true;
if (hideTimeoutRef.current) { clearTimeout(hideTimeoutRef.current); hideTimeoutRef.current = null; }
if (hideTimeoutRef.current) {
clearTimeout(hideTimeoutRef.current);
hideTimeoutRef.current = null;
}
}, [hideTimeoutRef]);
const onButtonLeave = useCallback(() => {
@@ -59,20 +75,32 @@ export function useHunkHover({ wrapperRef, changeLineMapRef, hideTimeoutRef }: H
const showBlockRef = useRef(showBlock);
const hideBlockRef = useRef(hideBlock);
useEffect(() => { showBlockRef.current = showBlock; }, [showBlock]);
useEffect(() => { hideBlockRef.current = hideBlock; }, [hideBlock]);
useEffect(() => {
showBlockRef.current = showBlock;
}, [showBlock]);
useEffect(() => {
hideBlockRef.current = hideBlock;
}, [hideBlock]);
const onLineEnter = useCallback((props: { lineType?: string; lineNumber?: number; annotationSide?: string }) => {
const { lineType, lineNumber, annotationSide } = props;
if (!lineType?.startsWith('change-') || lineNumber == null) { hideBlockRef.current(); return; }
const side = lineType === 'change-deletion' ? 'deletions' : 'additions';
const key = `${annotationSide ?? side}:${lineNumber}`;
const cbId = changeLineMapRef.current.get(key);
if (cbId) showBlockRef.current(cbId);
else hideBlockRef.current();
}, [changeLineMapRef]);
const onLineEnter = useCallback(
(props: { lineType?: string; lineNumber?: number; annotationSide?: string }) => {
const { lineType, lineNumber, annotationSide } = props;
if (!lineType?.startsWith("change-") || lineNumber == null) {
hideBlockRef.current();
return;
}
const side = lineType === "change-deletion" ? "deletions" : "additions";
const key = `${annotationSide ?? side}:${lineNumber}`;
const cbId = changeLineMapRef.current.get(key);
if (cbId) showBlockRef.current(cbId);
else hideBlockRef.current();
},
[changeLineMapRef],
);
const onLineLeave = useCallback(() => { hideBlockRef.current(); }, []);
const onLineLeave = useCallback(() => {
hideBlockRef.current();
}, []);
return { onLineEnter, onLineLeave, onButtonEnter, onButtonLeave };
}