|
1 | 1 | import { Component, For, Show } from "solid-js" |
2 | 2 | import { Icon } from "@opencode-ai/ui/icon" |
| 3 | +import { Icon as IconV2 } from "@opencode-ai/ui/v2/icon" |
3 | 4 | import { Tooltip } from "@opencode-ai/ui/tooltip" |
4 | | -import type { ImageAttachmentPart } from "@/context/prompt" |
| 5 | +import { TooltipV2 } from "@opencode-ai/ui/v2/tooltip-v2" |
| 6 | +import { AttachmentCardV2 } from "@opencode-ai/session-ui/v2/attachment-card-v2" |
| 7 | +import { CommentCardV2 } from "@opencode-ai/session-ui/v2/comment-card-v2" |
| 8 | +import { typeLabel } from "@opencode-ai/session-ui/message-file" |
| 9 | +import type { ContextItem, ImageAttachmentPart } from "@/context/prompt" |
| 10 | +import "./image-attachments.css" |
| 11 | + |
| 12 | +type PromptCommentItem = ContextItem & { key: string } |
5 | 13 |
|
6 | 14 | type PromptImageAttachmentsProps = { |
7 | 15 | attachments: ImageAttachmentPart[] |
8 | 16 | onOpen: (attachment: ImageAttachmentPart) => void |
9 | 17 | onRemove: (id: string) => void |
10 | 18 | removeLabel: string |
| 19 | + newLayoutDesigns: boolean |
| 20 | + comments?: PromptCommentItem[] |
| 21 | + commentActive?: (item: PromptCommentItem) => boolean |
| 22 | + onOpenComment?: (item: PromptCommentItem) => void |
| 23 | + onRemoveComment?: (item: PromptCommentItem) => void |
11 | 24 | } |
12 | 25 |
|
13 | 26 | const fallbackClass = "size-16 rounded-md bg-surface-base flex items-center justify-center border border-border-base" |
14 | 27 | const imageClass = |
15 | 28 | "size-16 rounded-md object-cover border border-border-base hover:border-border-strong-base transition-colors" |
| 29 | +const imageClassV2 = "w-[58px] h-[46px] rounded-[6px] object-cover" |
| 30 | +// inset box-shadows do not paint over <img> content, so the hairline is a separate overlay |
| 31 | +const imageHairlineClassV2 = |
| 32 | + "absolute inset-0 rounded-[6px] shadow-[inset_0_0_0_0.5px_var(--v2-border-border-base)] pointer-events-none" |
16 | 33 | const removeClass = |
17 | 34 | "absolute -top-1.5 -right-1.5 size-5 rounded-full bg-surface-raised-stronger-non-alpha border border-border-base flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity hover:bg-surface-raised-base-hover" |
| 35 | +const removeClassV2 = |
| 36 | + "absolute -top-1 -right-1 size-4 rounded-full bg-v2-icon-icon-muted outline-solid outline-1 outline-v2-icon-icon-contrast flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity" |
18 | 37 | const nameClass = "absolute bottom-0 left-0 right-0 px-1 py-0.5 bg-black/50 rounded-b-md" |
19 | 38 |
|
20 | 39 | export const PromptImageAttachments: Component<PromptImageAttachmentsProps> = (props) => { |
21 | 40 | return ( |
22 | | - <Show when={props.attachments.length > 0}> |
23 | | - <div class="flex flex-wrap gap-2 px-3 pt-3"> |
24 | | - <For each={props.attachments}> |
25 | | - {(attachment) => ( |
26 | | - <Tooltip value={attachment.filename} placement="top" contentClass="break-all"> |
27 | | - <div class="relative group"> |
| 41 | + <Show when={props.attachments.length > 0 || (props.newLayoutDesigns && (props.comments?.length ?? 0) > 0)}> |
| 42 | + <div data-slot="prompt-attachments" classList={{ relative: props.newLayoutDesigns }}> |
| 43 | + <div |
| 44 | + data-slot="prompt-attachments-scroll" |
| 45 | + classList={{ |
| 46 | + "flex gap-2": true, |
| 47 | + "flex-nowrap overflow-x-auto no-scrollbar px-2 pt-2 pb-1": props.newLayoutDesigns, |
| 48 | + "flex-wrap px-3 pt-3": !props.newLayoutDesigns, |
| 49 | + }} |
| 50 | + > |
| 51 | + <Show when={props.newLayoutDesigns}> |
| 52 | + <For each={props.comments ?? []}> |
| 53 | + {(item) => ( |
| 54 | + <div class="relative group shrink-0"> |
| 55 | + <TooltipV2 |
| 56 | + value={item.comment} |
| 57 | + placement="top" |
| 58 | + openDelay={800} |
| 59 | + contentClass="max-w-[300px] break-words" |
| 60 | + > |
| 61 | + <CommentCardV2 |
| 62 | + comment={item.comment ?? ""} |
| 63 | + path={item.path} |
| 64 | + selection={item.selection} |
| 65 | + active={props.commentActive?.(item)} |
| 66 | + onClick={() => props.onOpenComment?.(item)} |
| 67 | + /> |
| 68 | + </TooltipV2> |
| 69 | + <button |
| 70 | + type="button" |
| 71 | + onClick={() => props.onRemoveComment?.(item)} |
| 72 | + class={removeClassV2} |
| 73 | + aria-label={props.removeLabel} |
| 74 | + > |
| 75 | + <IconV2 name="outline-xmark" class="text-v2-icon-icon-contrast" /> |
| 76 | + </button> |
| 77 | + </div> |
| 78 | + )} |
| 79 | + </For> |
| 80 | + </Show> |
| 81 | + <For each={props.attachments}> |
| 82 | + {(attachment) => { |
| 83 | + const image = attachment.mime.startsWith("image/") |
| 84 | + const media = () => ( |
28 | 85 | <Show |
29 | | - when={attachment.mime.startsWith("image/")} |
| 86 | + when={image} |
30 | 87 | fallback={ |
31 | | - <div class={fallbackClass}> |
32 | | - <Icon name="folder" class="size-6 text-text-weak" /> |
33 | | - </div> |
| 88 | + <Show |
| 89 | + when={props.newLayoutDesigns} |
| 90 | + fallback={ |
| 91 | + <div class={fallbackClass}> |
| 92 | + <Icon name="folder" class="size-6 text-text-weak" /> |
| 93 | + </div> |
| 94 | + } |
| 95 | + > |
| 96 | + <AttachmentCardV2 title={attachment.filename}> |
| 97 | + {typeLabel(attachment.filename, attachment.mime)} |
| 98 | + </AttachmentCardV2> |
| 99 | + </Show> |
34 | 100 | } |
35 | 101 | > |
36 | 102 | <img |
37 | 103 | src={attachment.dataUrl} |
38 | 104 | alt={attachment.filename} |
39 | | - class={imageClass} |
| 105 | + class={props.newLayoutDesigns ? imageClassV2 : imageClass} |
40 | 106 | onClick={() => props.onOpen(attachment)} |
41 | 107 | /> |
42 | 108 | </Show> |
| 109 | + ) |
| 110 | + const name = () => ( |
| 111 | + <div class={nameClass}> |
| 112 | + <span class="text-10-regular text-white truncate block">{attachment.filename}</span> |
| 113 | + </div> |
| 114 | + ) |
| 115 | + const remove = () => ( |
43 | 116 | <button |
44 | 117 | type="button" |
45 | 118 | onClick={() => props.onRemove(attachment.id)} |
46 | | - class={removeClass} |
| 119 | + class={props.newLayoutDesigns ? removeClassV2 : removeClass} |
47 | 120 | aria-label={props.removeLabel} |
48 | 121 | > |
49 | | - <Icon name="close" class="size-3 text-text-weak" /> |
| 122 | + <Show when={props.newLayoutDesigns} fallback={<Icon name="close" class="size-3 text-text-weak" />}> |
| 123 | + <IconV2 name="outline-xmark" class="text-v2-icon-icon-contrast" /> |
| 124 | + </Show> |
50 | 125 | </button> |
51 | | - <div class={nameClass}> |
52 | | - <span class="text-10-regular text-white truncate block">{attachment.filename}</span> |
53 | | - </div> |
54 | | - </div> |
55 | | - </Tooltip> |
56 | | - )} |
57 | | - </For> |
| 126 | + ) |
| 127 | + // v2 keeps the remove button outside the tooltip trigger so hovering it dismisses the tooltip |
| 128 | + return ( |
| 129 | + <Show |
| 130 | + when={props.newLayoutDesigns} |
| 131 | + fallback={ |
| 132 | + <Tooltip value={attachment.filename} placement="top" contentClass="break-all"> |
| 133 | + <div class="relative group"> |
| 134 | + {media()} |
| 135 | + {name()} |
| 136 | + {remove()} |
| 137 | + </div> |
| 138 | + </Tooltip> |
| 139 | + } |
| 140 | + > |
| 141 | + <div class="relative group shrink-0"> |
| 142 | + <TooltipV2 value={attachment.filename} placement="top" contentClass="break-all"> |
| 143 | + {media()} |
| 144 | + <Show when={image}> |
| 145 | + <div class={imageHairlineClassV2} /> |
| 146 | + </Show> |
| 147 | + </TooltipV2> |
| 148 | + {remove()} |
| 149 | + </div> |
| 150 | + </Show> |
| 151 | + ) |
| 152 | + }} |
| 153 | + </For> |
| 154 | + </div> |
| 155 | + <Show when={props.newLayoutDesigns}> |
| 156 | + <div |
| 157 | + data-slot="prompt-attachments-fade-left" |
| 158 | + class="pointer-events-none absolute inset-y-0 left-0 z-10 w-6 bg-[linear-gradient(to_right,var(--v2-background-bg-base),transparent)]" |
| 159 | + /> |
| 160 | + <div |
| 161 | + data-slot="prompt-attachments-fade-right" |
| 162 | + class="pointer-events-none absolute inset-y-0 right-0 z-10 w-6 bg-[linear-gradient(to_left,var(--v2-background-bg-base),transparent)]" |
| 163 | + /> |
| 164 | + </Show> |
58 | 165 | </div> |
59 | 166 | </Show> |
60 | 167 | ) |
|
0 commit comments