Open History to see the last commit
1import type { ScopedThreadRef } from "@t3tools/contracts";
2import { flushSync } from "react-dom";
3import { dispatchCommandPalette } from "../commandPaletteStore";
4import { SidebarPointerSensor } from "./Sidebar.pointer";
5import {
6 dropThreadContext,
7 endThreadContextDrag,
8 moveThreadContextDrag,
9} from "./chat/threadContextDrag";
10
11export function startPaletteThreadDrag(
12 event: PointerEvent,
13 thread: ScopedThreadRef,
14 title: string,
15) {
16 if (!event.isPrimary || event.button !== 0 || event.pointerType === "touch") return;
17 // The document-owned sensor must survive closing and unmounting the palette on activation.
18 return new SidebarPointerSensor({
19 event,
20 active: `${thread.environmentId}:${thread.threadId}`,
21 options: {
22 distance: 6,
23 onAttach: () => {},
24 onFinish: endThreadContextDrag,
25 onDrop: (point) => dropThreadContext(point, [{ ...thread, title }]),
26 },
27 onStart: () => {
28 flushSync(() => dispatchCommandPalette({ _tag: "SetOpen", open: false }));
29 },
30 onMove: (point) => moveThreadContextDrag(point, { title, count: 1 }),
31 onPending: () => {},
32 onAbort: () => {},
33 onCancel: () => {},
34 onEnd: () => {},
35 });
36}