|
7 | 7 | */ |
8 | 8 |
|
9 | 9 | import { memo, useMemo } from 'react' |
| 10 | +import { CheckIcon, PencilSquareIcon, Square2StackIcon } from '@heroicons/react/24/outline' |
10 | 11 | import type { Message as MessageData } from 'jcode-ui-core' |
11 | 12 | import { MessageView } from 'jcode-ui-core/primitives' |
| 13 | +import type { MessageActions } from 'jcode-ui-core/primitives' |
12 | 14 | import { renderMarkdown } from '../lib/markdown.js' |
13 | 15 | import { Reasoning } from './Reasoning.js' |
14 | 16 | import { Sources } from './Sources.js' |
@@ -46,17 +48,59 @@ export const Message = memo(function Message({ message, canEdit }: MessageProps) |
46 | 48 |
|
47 | 49 | function Bubble({ message, canEdit, isUser }: { message: MessageData; canEdit?: boolean; isUser: boolean }) { |
48 | 50 | return ( |
49 | | - <MessageView |
50 | | - message={message} |
51 | | - canEdit={canEdit} |
52 | | - className={`jcode-selectable relative rounded-[var(--radius-lg)] px-3.5 py-2.5 text-[0.9rem] leading-relaxed ${ |
53 | | - isUser |
54 | | - ? 'bg-[var(--color-primary)] text-[var(--color-on-primary)]' |
55 | | - : 'bg-[var(--color-surface)] text-[var(--color-foreground)] border border-[var(--color-border)]' |
56 | | - }`} |
57 | | - renderContent={(content) => <MarkdownBody html={content} />} |
58 | | - renderAvatar={() => null} |
59 | | - /> |
| 51 | + <div className="group/msg"> |
| 52 | + <MessageView |
| 53 | + message={message} |
| 54 | + canEdit={canEdit} |
| 55 | + className={`jcode-selectable relative rounded-[var(--radius-lg)] px-3.5 py-2.5 text-[0.9rem] leading-relaxed ${ |
| 56 | + isUser |
| 57 | + ? 'bg-[var(--color-primary)] text-[var(--color-on-primary)]' |
| 58 | + : 'bg-[var(--color-surface)] text-[var(--color-foreground)] border border-[var(--color-border)]' |
| 59 | + }`} |
| 60 | + renderContent={(content) => <MarkdownBody html={content} />} |
| 61 | + renderAvatar={() => null} |
| 62 | + renderActions={(actions) => <MessageActionsRow {...actions} />} |
| 63 | + /> |
| 64 | + </div> |
| 65 | + ) |
| 66 | +} |
| 67 | + |
| 68 | +/** |
| 69 | + * Icon-based hover actions (mirrors ChatMessage.vue lines 172-189): a copy |
| 70 | + * button (Square2StackIcon → CheckIcon when copied) and, for editable user |
| 71 | + * messages, an edit button (PencilSquareIcon). Both render inside a row that |
| 72 | + * fades in on group hover/focus. |
| 73 | + */ |
| 74 | +function MessageActionsRow({ copied, onCopy, canEdit, onEdit }: MessageActions) { |
| 75 | + return ( |
| 76 | + <div className="flex items-center gap-0.5 pl-9 opacity-0 transition-opacity duration-150 group-hover/msg:opacity-100 group-focus-within/msg:opacity-100"> |
| 77 | + <button |
| 78 | + type="button" |
| 79 | + onClick={onCopy} |
| 80 | + title={copied ? 'Copied' : 'Copy'} |
| 81 | + aria-label={copied ? 'Copied' : 'Copy'} |
| 82 | + className="flex h-5 w-5 items-center justify-center rounded-[var(--radius-sm)] cursor-pointer transition-all hover:bg-[var(--color-secondary)] active:scale-90" |
| 83 | + style={{ color: 'var(--color-muted-foreground)' }} |
| 84 | + > |
| 85 | + {copied ? ( |
| 86 | + <CheckIcon className="h-3 w-3" style={{ color: 'var(--color-accent-neutral)' }} /> |
| 87 | + ) : ( |
| 88 | + <Square2StackIcon className="h-3 w-3" /> |
| 89 | + )} |
| 90 | + </button> |
| 91 | + {canEdit && ( |
| 92 | + <button |
| 93 | + type="button" |
| 94 | + onClick={onEdit} |
| 95 | + title="Edit" |
| 96 | + aria-label="Edit" |
| 97 | + className="flex h-5 w-5 items-center justify-center rounded-[var(--radius-sm)] cursor-pointer transition-all hover:bg-[var(--color-secondary)] active:scale-90" |
| 98 | + style={{ color: 'var(--color-muted-foreground)' }} |
| 99 | + > |
| 100 | + <PencilSquareIcon className="h-3 w-3" /> |
| 101 | + </button> |
| 102 | + )} |
| 103 | + </div> |
60 | 104 | ) |
61 | 105 | } |
62 | 106 |
|
|
0 commit comments