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, ICON_CLASS_DEFAULT } from '$lib/constants';
19 import { RouterService } from '$lib/services/router.service';
20 import { chatStore, conversationsStore } from '$lib/stores';
21 import { onMount } from 'svelte';
26 conversation: DatabaseConversation;
27 isSelectionMode?: boolean;
29 onDelete?: (id: string) => void;
30 onEdit?: (id: string) => void;
31 onSelect?: (id: string) => void;
32 onStop?: (id: string) => void;
33 onToggleSelect?: (id: string) => void;
34 onEnterSelectionMode?: (id: string) => void;
35 onSelectionClick?: (id: string, options: { shiftKey: boolean }) => void;
36 onRowMouseDown?: (id: string, event: MouseEvent) => void;
44 isSelectionMode = false,
55 let renderActionsDropdown = $state(false);
56 let dropdownOpen = $state(false);
58 let isLoading = $derived(chatStore.getAllLoadingChats().includes(conversation.id));
60 function handleEdit(event: Event) {
61 event.stopPropagation();
62 onEdit?.(conversation.id);
65 function handleDelete(event: Event) {
66 event.stopPropagation();
67 onDelete?.(conversation.id);
70 function handleStop(event: Event) {
71 event.stopPropagation();
72 onStop?.(conversation.id);
75 function handleTogglePin() {
76 conversationsStore.toggleConversationPin(conversation.id);
79 function handleEnterSelectionMode(event: Event) {
80 event.stopPropagation();
81 onEnterSelectionMode?.(conversation.id);
84 function handleGlobalEditEvent(event: Event) {
85 const customEvent = event as CustomEvent<{ conversationId: string }>;
87 if (customEvent.detail.conversationId === conversation.id && isActive) {
92 function handleMouseLeave() {
94 renderActionsDropdown = false;
98 function handleMouseOver() {
99 if (isSelectionMode) return;
101 renderActionsDropdown = true;
104 function handleSelect(event: MouseEvent) {
105 if (isSelectionMode) {
106 onSelectionClick?.(conversation.id, { shiftKey: event.shiftKey });
108 onSelect?.(conversation.id);
112 function handleCheckboxClick(event: MouseEvent) {
113 event.stopPropagation();
115 if (isSelectionMode) {
116 onSelectionClick?.(conversation.id, { shiftKey: event.shiftKey });
118 onToggleSelect?.(conversation.id);
122 function handleRowMouseDown(event: MouseEvent) {
123 onRowMouseDown?.(conversation.id, event);
126 function handleCheckboxKeydown(event: KeyboardEvent) {
127 if (event.key !== ' ' && event.key !== 'Enter') return;
129 event.stopPropagation();
130 event.preventDefault();
132 if (isSelectionMode) {
133 onSelectionClick?.(conversation.id, { shiftKey: event.shiftKey });
135 onToggleSelect?.(conversation.id);
141 renderActionsDropdown = false;
146 document.addEventListener('edit-active-conversation', handleGlobalEditEvent as EventListener);
149 document.removeEventListener(
150 'edit-active-conversation',
151 handleGlobalEditEvent as EventListener
157 <!-- svelte-ignore a11y_mouse_events_have_key_events -->
159 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
160 ? 'bg-foreground/5 text-accent-foreground'
161 : ''} {isSelected ? 'bg-primary/10 hover:bg-primary/15' : ''} {isSelectionMode
162 ? 'is-selection-mode'
164 data-conversation-row={conversation.id}
165 onclick={(e) => handleSelect(e)}
166 onmouseover={handleMouseOver}
167 onmouseleave={handleMouseLeave}
168 onmousedown={(e) => handleRowMouseDown(e)}
169 onfocusin={handleMouseOver}
171 if (!e.currentTarget.contains(e.relatedTarget as Node | null)) {
177 class="flex min-w-0 flex-1 items-center gap-2"
178 style:padding-left="{depth * FORK_TREE_DEPTH_PADDING}px"
180 {#if isSelectionMode}
183 onclick={(e) => handleCheckboxClick(e)}
184 onkeydown={handleCheckboxKeydown}
186 aria-checked={isSelected}
187 aria-label={isSelected ? `Deselect ${conversation.name}` : `Select ${conversation.name}`}
192 aria-label={isSelected ? `Deselect ${conversation.name}` : `Select ${conversation.name}`}
200 <!-- prevent another nested button element -->
201 {#snippet child({ props })}
204 href={RouterService.chat(conversation.forkedFromConversationId)}
205 class="flex shrink-0 items-center text-muted-foreground transition-colors hover:text-foreground"
207 <GitBranch class="h-3.5 w-3.5" />
213 <p>See parent conversation</p>
222 class="stop-button flex {ICON_CLASS_DEFAULT} shrink-0 cursor-pointer items-center justify-center rounded text-muted-foreground transition-colors hover:text-foreground"
224 onkeydown={(e) => e.key === 'Enter' && handleStop(e)}
227 aria-label="Stop generation"
229 <Loader2 class="loading-icon h-3.5 w-3.5 animate-spin" />
231 <Square class="stop-icon hidden h-3 w-3 fill-current text-destructive" />
236 <p>Stop generation</p>
241 <TruncatedText text={conversation.name} class="text-sm font-medium" showTooltip={false} />
244 {#if !isSelectionMode && renderActionsDropdown}
245 <div class="actions flex items-center">
247 triggerIcon={MoreHorizontal}
248 triggerTooltip="More actions"
249 bind:open={dropdownOpen}
252 icon: conversation.pinned ? PinOff : Pin,
253 label: conversation.pinned ? 'Unpin' : 'Pin',
254 onclick: (e: Event) => {
263 shortcut: ['shift', 'cmd', 'e']
268 onclick: (e: Event) => {
270 conversationsStore.downloadConversation(conversation.id);
272 shortcut: ['shift', 'cmd', 's']
277 onclick: handleEnterSelectionMode
282 onclick: handleDelete,
284 shortcut: ['shift', 'cmd', 'd'],
285 variant: 'destructive'
295 :global([data-slot='dropdown-menu-trigger']:not([data-state='open'])) {
299 &:is(:hover) :global([data-slot='dropdown-menu-trigger']),
300 &:focus-within :global([data-slot='dropdown-menu-trigger']) {
303 @media (max-width: 768px) {
304 :global([data-slot='dropdown-menu-trigger']) {
305 opacity: 1 !important;
309 &.is-selection-mode :global([data-slot='dropdown-menu-trigger']) {
310 display: none !important;
314 :global(.stop-icon) {
318 :global(.loading-icon) {
323 &:is(:hover) .stop-button {
324 :global(.stop-icon) {
328 :global(.loading-icon) {