Open History to see the last commit
1import type {
2 ChatAttachment,
3 ChatFileAttachment,
4 EnvironmentId,
5 ScopedThreadRef,
6 SnapShotSource,
7} from "@t3tools/contracts";
8import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments";
9import { CircleAlertIcon, PaperclipIcon, PlayIcon, XIcon } from "lucide-react";
10import { type ComponentProps, useLayoutEffect, useRef } from "react";
11
12import {
13 type ComposerFileAttachment,
14 type ComposerImageAttachment,
15 type DraftId,
16 composerFileNeedsReattach,
17} from "../../composerDraftStore";
18import { retryAttachmentUpload, useAttachmentUploadStore } from "../../lib/attachmentUploadQueue";
19import { formatAttachmentUploadProgress } from "../../lib/attachmentUploadState";
20import { isHeicImageFile } from "../../lib/imageCompression";
21import {
22 type PendingSnapShotAnimation,
23 scheduleSnapShotAnimationDestination,
24 setSnapShotAnimationDestination,
25 shouldAnimateSnapShotArrival,
26} from "../../lib/snapShotAnimation";
27import { cn } from "~/lib/utils";
28import { getRestingComposerImagePreviewCounts } from "../composerFooterLayout";
29import { RefreshIcon } from "~/components/ui/refresh-icon";
30import { AttachmentFilePreview } from "../files/AttachmentFilePreview";
31import { AttachmentImage } from "../media/AttachmentImage";
32import { Button } from "../ui/button";
33import { Dialog, DialogPopup, DialogTitle } from "../ui/dialog";
34import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
35import { ComposerImageThumbnail } from "./ComposerImageThumbnail";
36import { composerFloatingLayerProps } from "./composerEventScope";
37import type { PreparingComposerImage } from "./preparingComposerImages";
38import {
39 attachVideoThumbnail,
40 buildExpandedImagePreview,
41 type ExpandedImagePreview,
42} from "./ExpandedImagePreview";
43import { PierreEntryIcon } from "./PierreEntryIcon";
44import {
45 SNAP_SHOT_ATTACHMENT_FRAME_CLASS,
46 SnapShotAttachmentDetails,
47} from "./SnapShotAttachmentDetails";
48import { prepareVideoFirstFrame } from "../../lib/videoFirstFrame";
49
50function ComposerVideoThumbnail({ file }: { file: File }) {
51 const setVideo = (video: HTMLVideoElement | null) => {
52 if (!video) return;
53 return attachVideoThumbnail(video, file);
54 };
55
56 return (
57 <video
58 ref={setVideo}
59 muted
60 playsInline
61 preload="metadata"
62 aria-hidden="true"
63 onLoadedMetadata={(event) => prepareVideoFirstFrame(event.currentTarget)}
64 className="pointer-events-none absolute inset-0 size-full object-cover"
65 />
66 );
67}
68
69function SnapShotAttachmentFrame({
70 animationId,
71 animationSource,
72 arrival,
73 animateArrival,
74 className,
75 ...props
76}: ComponentProps<"div"> & {
77 readonly animationId?: string | undefined;
78 readonly animationSource?: SnapShotSource | undefined;
79 readonly arrival?: boolean | undefined;
80 readonly animateArrival?: boolean | undefined;
81}) {
82 const frameRef = useRef<HTMLDivElement>(null);
83
84 useLayoutEffect(() => {
85 const frame = frameRef.current;
86 if (!frame || (!animationId && !arrival)) return;
87 frame.scrollIntoView({ block: "nearest", inline: "nearest" });
88 if (!animationId) return;
89
90 return scheduleSnapShotAnimationDestination(animationId, () =>
91 setSnapShotAnimationDestination(animationId, frame, animationSource),
92 );
93 }, [animationId, animationSource, arrival]);
94
95 return (
96 <div
97 ref={frameRef}
98 className={cn(
99 animateArrival &&
100 !animationId &&
101 "origin-center transition-[opacity,scale] duration-300 ease-drawer starting:scale-95 starting:opacity-0 motion-reduce:transition-none motion-reduce:starting:scale-100 motion-reduce:starting:opacity-100",
102 className,
103 )}
104 {...props}
105 />
106 );
107}
108
109/** Image, SnapShot and video tiles above the composer editor. */
110export function ComposerAttachmentMediaRow({
111 images,
112 expandedImages,
113 preparingImages,
114 videos,
115 pendingSnapShotAnimations,
116 pendingSnapShotIds,
117 uncommittedSnapShotIds,
118 nonPersistedImageIds,
119 snapShotAnimations,
120 supportsAttachmentUploads,
121 maxFileAttachmentBytes,
122 environmentId,
123 attachmentDraftTarget,
124 canOperateThread,
125 onExpandImage,
126 onFileOpen,
127 onRemoveImage,
128 onRemoveFile,
129}: {
130 readonly images: ReadonlyArray<ComposerImageAttachment>;
131 readonly expandedImages: ReadonlyArray<ComposerImageAttachment>;
132 readonly preparingImages: ReadonlyArray<PreparingComposerImage>;
133 readonly videos: ReadonlyArray<ComposerFileAttachment>;
134 readonly pendingSnapShotAnimations: ReadonlyArray<PendingSnapShotAnimation>;
135 readonly pendingSnapShotIds: ReadonlyArray<string>;
136 readonly uncommittedSnapShotIds: ReadonlyArray<string>;
137 readonly nonPersistedImageIds: ReadonlyArray<string>;
138 readonly snapShotAnimations: boolean;
139 readonly supportsAttachmentUploads: boolean;
140 readonly maxFileAttachmentBytes: number | null;
141 readonly environmentId: EnvironmentId;
142 readonly attachmentDraftTarget: ScopedThreadRef | DraftId;
143 readonly canOperateThread: boolean;
144 readonly onExpandImage: (preview: ExpandedImagePreview) => void;
145 readonly onFileOpen: (attachment: ChatFileAttachment) => void;
146 readonly onRemoveImage: (imageId: string) => void;
147 readonly onRemoveFile: (fileId: string) => void;
148}) {
149 const uploadsByImageId = useAttachmentUploadStore((state) => state.uploadsByImageId);
150 const pendingSnapShotIdSet = new Set(pendingSnapShotIds);
151 const nonPersistedImageIdSet = new Set(nonPersistedImageIds);
152 return (
153 <div
154 className={cn(
155 "mb-3 flex max-w-full gap-2",
156 pendingSnapShotIds.length > 0 ||
157 expandedImages.some((image) => image.source?.kind === "snap-shot")
158 ? "snap-x snap-proximity overflow-x-auto overscroll-x-contain pb-1 scrollbar-thumb-foreground/18 scrollbar-track-transparent [scrollbar-width:thin] [&::-webkit-scrollbar]:h-2.5 [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar-thumb]:border-3 [&::-webkit-scrollbar-thumb]:border-transparent [&::-webkit-scrollbar-thumb]:bg-foreground/18 [&::-webkit-scrollbar-thumb]:bg-clip-content [&::-webkit-scrollbar-thumb:hover]:bg-foreground/28 [&::-webkit-scrollbar-track]:mx-1 [&::-webkit-scrollbar-track]:bg-transparent"
159 : "flex-wrap",
160 )}
161 >
162 {/* A preparing image renders through the same tile, keyed by the id its compressed image
163 takes, so the thumbnail element survives the swap. */}
164 {[
165 ...expandedImages.map((image) => ({ image, ready: image })),
166 ...preparingImages.map((image) => ({ image, ready: null })),
167 ]
168 .map(({ image, ready }) => {
169 const upload =
170 ready && supportsAttachmentUploads ? uploadsByImageId[image.id] : undefined;
171 const source = ready?.source;
172 const snapShotAnimationPending =
173 source?.kind === "snap-shot" && pendingSnapShotIdSet.has(image.id);
174 const snapShotArrival =
175 source?.kind === "snap-shot" && shouldAnimateSnapShotArrival(source.capturedAt);
176 return (
177 <SnapShotAttachmentFrame
178 key={image.id}
179 data-chat-composer-expanded-image="true"
180 aria-hidden={snapShotAnimationPending || undefined}
181 inert={snapShotAnimationPending || undefined}
182 arrival={snapShotArrival}
183 animateArrival={snapShotAnimations && !snapShotAnimationPending && snapShotArrival}
184 animationId={snapShotAnimationPending ? image.id : undefined}
185 animationSource={snapShotAnimationPending ? source : undefined}
186 className={cn(
187 "group/attachment shrink-0 snap-start bg-background",
188 source?.kind === "snap-shot"
189 ? SNAP_SHOT_ATTACHMENT_FRAME_CLASS
190 : "relative h-16 w-16 overflow-hidden rounded-lg border border-border/80",
191 snapShotAnimationPending && "invisible",
192 )}
193 >
194 {!ready || ready.previewUrl ? (
195 <button
196 type="button"
197 className={cn("h-full w-full", ready && "cursor-zoom-in")}
198 aria-label={`Preview ${image.name}`}
199 disabled={!ready}
200 onClick={() => {
201 const preview = buildExpandedImagePreview(images, image.id);
202 if (!preview) return;
203 onExpandImage(preview);
204 }}
205 >
206 <ComposerImageThumbnail
207 file={image.file}
208 alt={image.name}
209 className="h-full w-full object-cover"
210 fallback={
211 ready && isHeicImageFile({ name: ready.name, type: ready.mimeType }) ? (
212 <AttachmentImage
213 name={ready.name}
214 mimeType={ready.mimeType}
215 src={ready.previewUrl}
216 alt={image.name}
217 className="h-full w-full object-cover"
218 />
219 ) : (
220 <span className="flex h-full items-center justify-center px-1 text-3xs text-secondary-label">
221 {image.name}
222 </span>
223 )
224 }
225 />
226 </button>
227 ) : (
228 <div className="flex h-full w-full items-center justify-center px-1 text-center text-3xs text-secondary-label">
229 {image.name}
230 </div>
231 )}
232 {source?.kind === "snap-shot" ? (
233 <SnapShotAttachmentDetails
234 source={source}
235 className={cn(
236 upload?.status === "uploading" && "bottom-4",
237 upload?.status === "failed" && "bottom-8",
238 )}
239 />
240 ) : null}
241 {nonPersistedImageIdSet.has(image.id) && (
242 <Tooltip>
243 <TooltipTrigger
244 render={
245 <span
246 role="img"
247 aria-label="Draft attachment may not persist"
248 className="absolute left-1 top-1 inline-flex items-center justify-center rounded bg-background/85 p-0.5 text-warning-foreground"
249 >
250 <CircleAlertIcon className="size-3" />
251 </span>
252 }
253 />
254 <TooltipPopup side="top">
255 Draft attachment could not be saved locally and may be lost on navigation.
256 </TooltipPopup>
257 </Tooltip>
258 )}
259 {(ready ? upload?.status === "uploading" : supportsAttachmentUploads) && (
260 <span className="pointer-events-none absolute inset-x-0 bottom-0 bg-background/85 px-1 text-center text-3xs text-foreground">
261 {formatAttachmentUploadProgress(
262 upload?.status === "uploading" ? upload.progress : 0,
263 )}
264 </span>
265 )}
266 {ready && upload?.status === "failed" && (
267 <Tooltip>
268 <TooltipTrigger
269 render={
270 <Button
271 variant="overlay"
272 size="icon-xs"
273 className="absolute bottom-1 left-1"
274 onClick={() =>
275 retryAttachmentUpload({
276 environmentId,
277 image: ready,
278 draftTarget: attachmentDraftTarget,
279 })
280 }
281 disabled={!canOperateThread}
282 aria-label={`Retry upload for ${image.name}`}
283 />
284 }
285 >
286 <RefreshIcon />
287 </TooltipTrigger>
288 <TooltipPopup side="top">{upload.reason}</TooltipPopup>
289 </Tooltip>
290 )}
291 <span
292 className={cn(
293 "absolute right-1 top-1 flex",
294 source?.kind === "snap-shot" &&
295 "opacity-0 transition-opacity pointer-coarse:opacity-100 group-hover/attachment:opacity-100 group-focus-within/attachment:opacity-100",
296 )}
297 >
298 <Button
299 variant="media-close"
300 size="icon-xs"
301 onClick={() => onRemoveImage(image.id)}
302 aria-label={`Remove ${image.name}`}
303 >
304 <XIcon />
305 </Button>
306 </span>
307 </SnapShotAttachmentFrame>
308 );
309 })
310 .concat(
311 uncommittedSnapShotIds.map((captureId) => (
312 <SnapShotAttachmentFrame
313 key={captureId}
314 aria-hidden="true"
315 animationId={captureId}
316 animationSource={
317 pendingSnapShotAnimations.find((capture) => capture.id === captureId)?.source
318 }
319 className={cn(
320 SNAP_SHOT_ATTACHMENT_FRAME_CLASS,
321 "invisible shrink-0 snap-start bg-background",
322 )}
323 />
324 )),
325 )}
326 {videos.map((file) => {
327 const fileCanUpload =
328 supportsAttachmentUploads &&
329 maxFileAttachmentBytes !== null &&
330 file.sizeBytes <= maxFileAttachmentBytes;
331 const upload = fileCanUpload ? uploadsByImageId[file.id] : undefined;
332 return (
333 <div
334 key={file.id}
335 className="relative h-16 w-16 shrink-0 snap-start overflow-hidden rounded-lg border border-border/80 bg-black"
336 >
337 <button
338 type="button"
339 className="flex h-full w-full cursor-zoom-in flex-col items-center justify-center gap-1 px-1 text-white"
340 aria-label={`Play ${file.name}`}
341 onClick={() => {
342 if (file.file !== null) {
343 const preview = buildExpandedImagePreview([file], file.id);
344 if (preview) onExpandImage(preview);
345 return;
346 }
347 if (!file.uploadedAttachmentId) return;
348 onFileOpen({ ...file, id: file.uploadedAttachmentId });
349 }}
350 >
351 {file.file && (
352 <>
353 <ComposerVideoThumbnail file={file.file} />
354 <span className="pointer-events-none absolute inset-0 bg-gradient-to-t from-black/70 via-black/10 to-black/10" />
355 </>
356 )}
357 <PlayIcon className="relative z-10 size-4 fill-current drop-shadow-md" />
358 </button>
359 {upload?.status === "uploading" && (
360 <span className="pointer-events-none absolute inset-x-0 bottom-0 bg-background/85 px-1 text-center text-3xs text-foreground">
361 {formatAttachmentUploadProgress(upload.progress)}
362 </span>
363 )}
364 {upload?.status === "failed" && (
365 <Tooltip>
366 <TooltipTrigger
367 render={
368 <Button
369 variant="overlay"
370 size="icon-xs"
371 className="absolute bottom-1 left-1"
372 onClick={() =>
373 retryAttachmentUpload({
374 environmentId,
375 image: file,
376 draftTarget: attachmentDraftTarget,
377 })
378 }
379 disabled={!canOperateThread}
380 aria-label={`Retry upload for ${file.name}`}
381 />
382 }
383 >
384 <RefreshIcon />
385 </TooltipTrigger>
386 <TooltipPopup side="top">{upload.reason}</TooltipPopup>
387 </Tooltip>
388 )}
389 <Button
390 variant="media-close"
391 size="icon-xs"
392 className="absolute right-1 top-1"
393 onClick={() => onRemoveFile(file.id)}
394 aria-label={`Remove ${file.name}`}
395 >
396 <XIcon />
397 </Button>
398 </div>
399 );
400 })}
401 </div>
402 );
403}
404
405/** Non-media file attachments, listed under the media row. */
406export function ComposerAttachmentFileList({
407 files,
408 resolvedTheme,
409 supportsAttachmentUploads,
410 maxFileAttachmentBytes,
411 fileStagingLimit,
412 environmentId,
413 attachmentDraftTarget,
414 canOperateThread,
415 onPreviewFile,
416 onRemoveFile,
417}: {
418 readonly files: ReadonlyArray<ComposerFileAttachment>;
419 readonly resolvedTheme: "light" | "dark";
420 readonly supportsAttachmentUploads: boolean;
421 readonly maxFileAttachmentBytes: number | null;
422 readonly fileStagingLimit: number | null;
423 readonly environmentId: EnvironmentId;
424 readonly attachmentDraftTarget: ScopedThreadRef | DraftId;
425 readonly canOperateThread: boolean;
426 readonly onPreviewFile: (fileId: string) => void;
427 readonly onRemoveFile: (fileId: string) => void;
428}) {
429 const uploadsByImageId = useAttachmentUploadStore((state) => state.uploadsByImageId);
430 return (
431 <div className="mb-3 flex flex-col gap-1">
432 {files.map((file) => {
433 const fileCanUpload =
434 supportsAttachmentUploads &&
435 maxFileAttachmentBytes !== null &&
436 file.sizeBytes <= maxFileAttachmentBytes;
437 const upload = fileCanUpload ? uploadsByImageId[file.id] : undefined;
438 const needsReattach = composerFileNeedsReattach(file);
439 const canReattachFile = fileStagingLimit !== null && file.sizeBytes <= fileStagingLimit;
440 return (
441 <div
442 key={file.id}
443 className="flex min-w-0 items-center gap-2 py-1 text-sm text-foreground"
444 >
445 <PierreEntryIcon pathValue={file.name} kind="file" theme={resolvedTheme} />
446 <button
447 type="button"
448 disabled={needsReattach}
449 className="min-w-0 flex-1 truncate text-left hover:underline focus-visible:outline-2"
450 onClick={() => onPreviewFile(file.id)}
451 >
452 {file.name}
453 </button>
454 <span className="shrink-0 text-xs text-secondary-label">
455 {needsReattach
456 ? canReattachFile
457 ? "Attach again"
458 : "Remove to send"
459 : upload?.status === "uploading"
460 ? formatAttachmentUploadProgress(upload.progress)
461 : formatAttachmentSize(file.sizeBytes)}
462 </span>
463 {!needsReattach && upload?.status === "failed" ? (
464 <Tooltip>
465 <TooltipTrigger
466 render={
467 <Button
468 variant="ghost"
469 size="icon-xs"
470 onClick={() =>
471 retryAttachmentUpload({
472 environmentId,
473 image: file,
474 draftTarget: attachmentDraftTarget,
475 })
476 }
477 disabled={!canOperateThread}
478 aria-label={`Retry upload for ${file.name}`}
479 />
480 }
481 >
482 <RefreshIcon />
483 </TooltipTrigger>
484 <TooltipPopup side="top">{upload.reason}</TooltipPopup>
485 </Tooltip>
486 ) : null}
487 <Button
488 variant="ghost"
489 size="icon-xs"
490 onClick={() => onRemoveFile(file.id)}
491 aria-label={`Remove ${file.name}`}
492 >
493 <XIcon />
494 </Button>
495 </div>
496 );
497 })}
498 </div>
499 );
500}
501
502export function ComposerFilePreviewDialog({
503 file,
504 onRemove,
505 onPreviewFileIdChange,
506}: {
507 readonly file: ComposerFileAttachment;
508 readonly onRemove: (fileId: string) => void;
509 readonly onPreviewFileIdChange: (fileId: string | null) => void;
510}) {
511 const onClose = () => onPreviewFileIdChange(null);
512 return (
513 <Dialog
514 open
515 onOpenChange={(open) => {
516 if (!open) onClose();
517 }}
518 >
519 <DialogPopup
520 {...composerFloatingLayerProps}
521 className="h-[min(85vh,52rem)] max-w-4xl overflow-hidden"
522 showCloseButton={false}
523 >
524 <DialogTitle className="sr-only">{file.name}</DialogTitle>
525 <AttachmentFilePreview
526 key={file.id}
527 name={file.name}
528 mimeType={file.mimeType}
529 sizeBytes={file.sizeBytes}
530 file={file.file}
531 origin="Draft"
532 {...(file.uploadedAttachmentId && file.uploadEnvironmentId
533 ? {
534 asset: {
535 environmentId: file.uploadEnvironmentId,
536 attachmentId: file.uploadedAttachmentId,
537 },
538 }
539 : {})}
540 onRemove={() => {
541 onRemove(file.id);
542 onClose();
543 }}
544 onClose={onClose}
545 />
546 </DialogPopup>
547 </Dialog>
548 );
549}
550
551/** Thumbnails beside the single-line prompt while the composer rests. */
552export function ComposerRestingImagePreviews({
553 images,
554 allImages,
555 resolvedTheme,
556 onExpandImage,
557 onShowMore,
558}: {
559 readonly images: ReadonlyArray<ComposerImageAttachment>;
560 readonly allImages: ReadonlyArray<ComposerImageAttachment>;
561 readonly resolvedTheme: "light" | "dark";
562 readonly onExpandImage: (preview: ExpandedImagePreview) => void;
563 readonly onShowMore: () => void;
564}) {
565 const counts = getRestingComposerImagePreviewCounts(images.length);
566 const visibleImages = images.slice(0, counts.visibleCount);
567 return (
568 <div data-chat-composer-resting-images="true" className="flex shrink-0 items-center gap-1 ps-1">
569 {visibleImages.map((image) => (
570 <button
571 key={image.id}
572 type="button"
573 className="relative size-7 shrink-0 cursor-zoom-in overflow-hidden rounded-md border border-border/70 bg-muted/60"
574 aria-label={`Preview ${image.name}`}
575 onPointerDown={(event) => event.preventDefault()}
576 onClick={() => {
577 const preview = buildExpandedImagePreview(allImages, image.id);
578 if (preview) onExpandImage(preview);
579 }}
580 >
581 {image.previewUrl ? (
582 <ComposerImageThumbnail
583 file={image.file}
584 alt=""
585 className="size-full object-cover"
586 fallback={
587 isHeicImageFile({ name: image.name, type: image.mimeType }) ? (
588 <AttachmentImage
589 name={image.name}
590 mimeType={image.mimeType}
591 src={image.previewUrl}
592 alt=""
593 className="size-full object-cover"
594 />
595 ) : (
596 <PierreEntryIcon
597 pathValue={image.name}
598 kind="file"
599 theme={resolvedTheme}
600 className="m-auto size-3.5"
601 />
602 )
603 }
604 />
605 ) : (
606 <PierreEntryIcon
607 pathValue={image.name}
608 kind="file"
609 theme={resolvedTheme}
610 className="m-auto size-3.5"
611 />
612 )}
613 </button>
614 ))}
615 {counts.overflowCount > 0 ? (
616 <button
617 type="button"
618 className="flex size-7 shrink-0 cursor-pointer items-center justify-center rounded-md border border-border/70 bg-muted/60 font-medium text-secondary-label text-xs tabular-nums outline-none hover:bg-muted focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background"
619 aria-label={`Show ${String(counts.overflowCount)} more image attachments`}
620 onPointerDown={(event) => event.preventDefault()}
621 onClick={onShowMore}
622 >
623 +{counts.overflowCount}
624 </button>
625 ) : null}
626 </div>
627 );
628}
629
630/** Attachments of the queued message being edited; they are already uploaded. */
631export function ComposerQueuedAttachmentRow({
632 attachments,
633 onRemove,
634}: {
635 readonly attachments: ReadonlyArray<{
636 readonly attachment: ChatAttachment;
637 readonly url: string | null;
638 }>;
639 readonly onRemove: (attachmentId: string) => void;
640}) {
641 return (
642 <div className="mb-3 flex flex-wrap gap-2">
643 {attachments.map(({ attachment, url }) => (
644 <div
645 key={attachment.id}
646 className="relative h-16 w-16 overflow-hidden rounded-lg border border-border/80 bg-background"
647 >
648 {attachment.type === "image" && url ? (
649 <img src={url} alt={attachment.name} className="h-full w-full object-cover" />
650 ) : (
651 <div className="flex h-full w-full items-center justify-center px-1 text-center text-3xs text-secondary-label">
652 {attachment.name}
653 </div>
654 )}
655 <Button
656 variant="media-close"
657 size="icon-xs"
658 className="absolute right-1 top-1"
659 onClick={() => onRemove(attachment.id)}
660 aria-label={`Remove ${attachment.name}`}
661 >
662 <XIcon />
663 </Button>
664 </div>
665 ))}
666 </div>
667 );
668}
669
670export function ComposerAttachButton({
671 addComposerAttachments,
672 focusComposer,
673}: {
674 readonly addComposerAttachments: (files: File[]) => Promise<boolean>;
675 readonly focusComposer: () => void;
676}) {
677 const inputRef = useRef<HTMLInputElement>(null);
678 return (
679 <>
680 <input
681 ref={inputRef}
682 type="file"
683 multiple
684 className="hidden"
685 onChange={(event) => {
686 const files = Array.from(event.currentTarget.files ?? []);
687 event.currentTarget.value = "";
688 // Inserting a chip refocuses the editor after the draft renders;
689 // focusing synchronously here would report the editor's stale text
690 // over the prompt that was just written.
691 void addComposerAttachments(files).then((inserted) => {
692 if (!inserted) focusComposer();
693 });
694 }}
695 />
696 <Tooltip>
697 <TooltipTrigger
698 render={
699 <Button
700 type="button"
701 variant="ghost"
702 size="icon-sm"
703 onPointerDown={(event) => event.preventDefault()}
704 onClick={() => inputRef.current?.click()}
705 aria-label="Attach files"
706 />
707 }
708 >
709 <PaperclipIcon />
710 </TooltipTrigger>
711 <TooltipPopup>Attach files</TooltipPopup>
712 </Tooltip>
713 </>
714 );
715}