diff --git a/frontend/src/lib/document/transcription/useBlockDragDrop.svelte.test.ts b/frontend/src/lib/document/transcription/useBlockDragDrop.svelte.test.ts index 2b756e4d..90afcad0 100644 --- a/frontend/src/lib/document/transcription/useBlockDragDrop.svelte.test.ts +++ b/frontend/src/lib/document/transcription/useBlockDragDrop.svelte.test.ts @@ -1,7 +1,33 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, it, expect, vi, expectTypeOf } from 'vitest'; import { createBlockDragDrop } from './useBlockDragDrop.svelte'; import type { TranscriptionBlockData } from '$lib/shared/types'; +// --------------------------------------------------------------------------- +// Type-regression guard: createBlockDragDrop must accept any T extends {id: string} +// so JourneyEditor can reuse it without importing TranscriptionBlockData. +// This test fails with "Expected 0 type arguments, but got 1" via tsc --noEmit +// until the function is made generic. +// --------------------------------------------------------------------------- +describe('createBlockDragDrop — generic type guard', () => { + it('accepts items shaped as { id: string; position: number } — not only TranscriptionBlockData', () => { + type SimpleItem = { id: string; position: number }; + const items: SimpleItem[] = [ + { id: 'item-1', position: 0 }, + { id: 'item-2', position: 1 } + ]; + const onReorder = vi.fn(); + const dd = createBlockDragDrop({ getSortedBlocks: () => items, onReorder }); + // Verify the hook is functional with the new type — state reads must work + expect(dd.draggedBlockId).toBeNull(); + expect(dd.dragOffsetY).toBe(0); + }); + + it('TranscriptionBlockData caller still compiles — regression guard for existing transcription editor', () => { + // If the generic constraint is wrong this line fails tsc --noEmit + expectTypeOf(createBlockDragDrop).toBeFunction(); + }); +}); + function makeBlock(id: string, sortOrder: number): TranscriptionBlockData { return { id, diff --git a/frontend/src/lib/document/transcription/useBlockDragDrop.svelte.ts b/frontend/src/lib/document/transcription/useBlockDragDrop.svelte.ts index 900c5d1c..49ac2a69 100644 --- a/frontend/src/lib/document/transcription/useBlockDragDrop.svelte.ts +++ b/frontend/src/lib/document/transcription/useBlockDragDrop.svelte.ts @@ -1,11 +1,12 @@ -import type { TranscriptionBlockData } from '$lib/shared/types'; - -type Options = { - getSortedBlocks: () => TranscriptionBlockData[]; +type Options = { + getSortedBlocks: () => T[]; onReorder: (blockIds: string[]) => void; }; -export function createBlockDragDrop({ getSortedBlocks, onReorder }: Options) { +export function createBlockDragDrop({ + getSortedBlocks, + onReorder +}: Options) { let draggedBlockId = $state(null); let dropTargetIdx = $state(null); let dragOffsetY = $state(0);