import type { SampleGroupNode } from '../composables/useSampleGroups' import type { GroupDragKind, GroupReorderPosition } from './SampleSelector.groups' /** * Handlers and state predicates shared by every level of the group tree. * Passed down as a single prop so the recursive row component does not have to * re-emit each event at every nesting level. */ export interface SampleGroupTreeContext { isExpanded: (key: string) => boolean toggleExpanded: (key: string) => void isSampleSelected: (sample: string) => boolean isFullySelected: (samples: string[]) => boolean isPartiallySelected: (samples: string[]) => boolean toggleSamples: (samples: string[]) => void toggleSample: (sample: string) => void removeGroups: (groupNames: string[]) => void removeSampleFromGroup: (sample: string, groupName: string) => void openColorPicker: (groupNames: string[], event: Event) => void // Drag state + handlers, mirroring `useSampleSelectorDrag`. draggingSample: () => string | null dragOverGroup: () => string | null draggingGroup: () => string | null draggingGroupKind: () => GroupDragKind | null reorderTarget: () => string | null reorderPosition: () => GroupReorderPosition | null onSampleDragStart: (sample: string, groupName: string | null, event: DragEvent) => void onSampleDragEnd: () => void onSampleDragOver: (groupName: string, event: DragEvent) => void onSampleDragLeave: () => void onSampleDrop: (groupName: string, event: DragEvent) => void onGroupDragStart: (name: string, kind: GroupDragKind, event: DragEvent) => void onGroupDragEnd: () => void onGroupDragOver: (name: string, kind: GroupDragKind, event: DragEvent) => void onGroupDragLeave: (event: DragEvent) => void onGroupDrop: (name: string, kind: GroupDragKind, event: DragEvent) => void /** Alt+ArrowUp / Alt+ArrowDown reorder a group among its siblings. */ onGroupReorderKeydown: (name: string, kind: GroupDragKind, event: KeyboardEvent) => void } /** Every concrete group name beneath a node, in tree order. */ export function collectLeafGroupNames(node: SampleGroupNode): string[] { if (node.group) return [node.group.name] return node.children.flatMap(collectLeafGroupNames) } /** Expansion keys for a whole tree, used by "expand all". */ export function collectNodeKeys(nodes: SampleGroupNode[]): string[] { return nodes.flatMap(node => [node.key, ...collectNodeKeys(node.children)]) }