13 } from '@lucide/svelte';
14 import { DropdownMenuActions } from '$lib/components/app';
15 import { TruncatedText } from '$lib/components/app';
16 import { Checkbox } from '$lib/components/ui/checkbox';
17 import * as Tooltip from '$lib/components/ui/tooltip';
18 import { FORK_TREE_DEPTH_PADDING } from '$lib/constants';
19 import { ICON_CLASS_DEFAULT } from '$lib/constants/css-classes';
20 import { RouterService } from '$lib/services/router.service';
21 import { getAllLoadingChats } from '$lib/stores/chat.svelte';
22 import { conversationsStore } from '$lib/stores/conversations.svelte';
23 import { onMount } from 'svelte';
28 conversation: DatabaseConversation;
29 isSelectionMode?: boolean;
31 onDelete?: (id: string) => void;
32 onEdit?: (id: string) => void;
33 onSelect?: (id: string) => void;
34 onStop?: (id: string) => void;
35 onToggleSelect?: (id: string) => void;
36 onEnterSelectionMode?: (id: string) => void;
37 onSelectionClick?: (id: string, options: { shiftKey: boolean }) => void;
38 onRowMouseDown?: (id: string, event: MouseEvent) => void;
46 isSelectionMode = false,
57 let renderActionsDropdown = $state(false);
58 let dropdownOpen = $state(false);
60 let isLoading = $derived(getAllLoadingChats().includes(conversation.id));
62 function handleEdit(event: Event) {
63 event.stopPropagation();
64 onEdit?.(conversation.id);
67 function handleDelete(event: Event) {
68 event.stopPropagation();
69 onDelete?.(conversation.id);
72 function handleStop(event: Event) {
73 event.stopPropagation();
74 onStop?.(conversation.id);
77 function handleTogglePin() {
78 conversationsStore.toggleConversationPin(conversation.id);
81 function handleEnterSelectionMode(event: Event) {
82 event.stopPropagation();
83 onEnterSelectionMode?.(conversation.id);
86 function handleGlobalEditEvent(event: Event) {
87 const customEvent = event as CustomEvent<{ conversationId: string }>;
89 if (customEvent.detail.conversationId === conversation.id && isActive) {
94 function handleMouseLeave() {
96 renderActionsDropdown = false;
100 function handleMouseOver() {
101 if (isSelectionMode) return;
103 renderActionsDropdown = true;
106 function handleSelect(event: MouseEvent) {
107 if (isSelectionMode) {
108 onSelectionClick?.(conversation.id, { shiftKey: event.shiftKey });
110 onSelect?.(conversation.id);
114 function handleCheckboxClick(event: MouseEvent) {
115 event.stopPropagation();
117 if (isSelectionMode) {
118 onSelectionClick?.(conversation.id, { shiftKey: event.shiftKey });
120 onToggleSelect?.(conversation.id);
124 function handleRowMouseDown(event: MouseEvent) {
125 onRowMouseDown?.(conversation.id, event);
128 function handleCheckboxKeydown(event: KeyboardEvent) {
129 if (event.key !== ' ' && event.key !== 'Enter') return;
131 event.stopPropagation();
132 event.preventDefault();
134 if (isSelectionMode) {
135 onSelectionClick?.(conversation.id, { shiftKey: event.shiftKey });
137 onToggleSelect?.(conversation.id);
143 renderActionsDropdown = false;
148 document.addEventListener('edit-active-conversation', handleGlobalEditEvent as EventListener);
151 document.removeEventListener(
152 'edit-active-conversation',
153 handleGlobalEditEvent as EventListener
159 <!-- svelte-ignore a11y_mouse_events_have_key_events -->
161 class="group flex min-h-9 w-full cursor-pointer items-center justify-between space-x-3 rounded-lg py-1.5 text-left transition-colors hover:bg-foreground/10 {isActive
162 ? 'bg-foreground/5 text-accent-foreground'
163 : ''} {isSelected ? 'bg-primary/10 hover:bg-primary/15' : ''} {isSelectionMode
164 ? 'is-selection-mode'
166 data-conversation-row={conversation.id}
167 onclick={(e) => handleSelect(e)}
168 onmouseover={handleMouseOver}
169 onmouseleave={handleMouseLeave}
170 onmousedown={(e) => handleRowMouseDown(e)}
171 onfocusin={handleMouseOver}
173 if (!e.currentTarget.contains(e.relatedTarget as Node | null)) {
179 class="flex min-w-0 flex-1 items-center gap-2"
180 style:padding-left="{depth * FORK_TREE_DEPTH_PADDING}px"
182 {#if isSelectionMode}
185 onclick={(e) => handleCheckboxClick(e)}
186 onkeydown={handleCheckboxKeydown}
188 aria-checked={isSelected}
189 aria-label={isSelected ? `Deselect ${conversation.name}` : `Select ${conversation.name}`}
194 aria-label={isSelected ? `Deselect ${conversation.name}` : `Select ${conversation.name}`}
202 <!-- prevent another nested button element -->
203 {#snippet child({ props })}
206 href={RouterService.chat(conversation.forkedFromConversationId)}
207 class="flex shrink-0 items-center text-muted-foreground transition-colors hover:text-foreground"
209 <GitBranch class="h-3.5 w-3.5" />
215 <p>See parent conversation</p>
224 class="stop-button flex {ICON_CLASS_DEFAULT} shrink-0 cursor-pointer items-center justify-center rounded text-muted-foreground transition-colors hover:text-foreground"
226 onkeydown={(e) => e.key === 'Enter' && handleStop(e)}
229 aria-label="Stop generation"
231 <Loader2 class="loading-icon h-3.5 w-3.5 animate-spin" />
233 <Square class="stop-icon hidden h-3 w-3 fill-current text-destructive" />
238 <p>Stop generation</p>
243 <TruncatedText text={conversation.name} class="text-sm font-medium" showTooltip={false} />
246 {#if !isSelectionMode && renderActionsDropdown}
247 <div class="actions flex items-center">
249 triggerIcon={MoreHorizontal}
250 triggerTooltip="More actions"
251 bind:open={dropdownOpen}
254 icon: conversation.pinned ? PinOff : Pin,
255 label: conversation.pinned ? 'Unpin' : 'Pin',
256 onclick: (e: Event) => {
265 shortcut: ['shift', 'cmd', 'e']
270 onclick: (e: Event) => {
272 conversationsStore.downloadConversation(conversation.id);
274 shortcut: ['shift', 'cmd', 's']
279 onclick: handleEnterSelectionMode
284 onclick: handleDelete,
286 shortcut: ['shift', 'cmd', 'd'],
287 variant: 'destructive'
297 :global([data-slot='dropdown-menu-trigger']:not([data-state='open'])) {
301 &:is(:hover) :global([data-slot='dropdown-menu-trigger']),
302 &:focus-within :global([data-slot='dropdown-menu-trigger']) {
305 @media (max-width: 768px) {
306 :global([data-slot='dropdown-menu-trigger']) {
307 opacity: 1 !important;
311 &.is-selection-mode :global([data-slot='dropdown-menu-trigger']) {
312 display: none !important;
316 :global(.stop-icon) {
320 :global(.loading-icon) {
325 &:is(:hover) .stop-button {
326 :global(.stop-icon) {
330 :global(.loading-icon) {