diff --git a/CLAUDE.md b/CLAUDE.md index 2d57134..aa5d405 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -334,7 +334,12 @@ Two independent apps that talk over HTTP: library replaces — plus the playlist tree + create/rename/delete), `SaveBar`, `Toolbar` (search/filters + `ColumnsMenu`), `TrackTable` (All Tracks — TanStack Table + **virtualized** grid; per-row play - button, configurable columns, inline double-click editing) and `PlaylistTable` + button, configurable columns, inline double-click editing, and **Finder-style + row selection** — click / Cmd-Ctrl+click / Shift+click over the SORTED rows, + ↑/↓ (Shift extends), Cmd/Ctrl+A, Esc; shortcuts stand down while an + `aria-modal` dialog or `role="menu"` is open, so new dialogs need + `aria-modal="true"`. Right-click acts on the whole selection; single-track + items are hidden for a multi-selection) and `PlaylistTable` (playlists — same columns/cells/play/inline-edit via shared `HeaderRow`/ `RowCells`/`PlayButton`, so the two views look identical, PLUS dnd-kit drag-to-reorder + a remove button, header sorting disabled so the manual order diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index f4fa226..68b97db 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -50,7 +50,9 @@ export default function App() { const [selected, setSelected] = useState>(new Set()) const [toast, setToast] = useState(null) const [forcePicker, setForcePicker] = useState(false) - const [menu, setMenu] = useState<{ track: Track; x: number; y: number } | null>(null) + // `ids` is what the menu acts on: the whole selection when the clicked row is + // part of it, otherwise just that row. + const [menu, setMenu] = useState<{ track: Track; ids: string[]; x: number; y: number } | null>(null) const [editing, setEditing] = useState(null) const [showPaths, setShowPaths] = useState(false) const [showHistory, setShowHistory] = useState(false) @@ -394,16 +396,16 @@ export default function App() { setSelected(new Set()) } - const toggle = (id: string) => - setSelected((prev) => { - const next = new Set(prev) - next.has(id) ? next.delete(id) : next.add(id) - return next + // TrackTable retargets the selection to a right-clicked row outside it + // before calling this, but that state update has not landed yet — so the + // same rule is applied here to decide what the menu acts on. + const openMenu = (track: Track, x: number, y: number, selectable: boolean) => + setMenu({ + track, + ids: selectable && selected.has(track.id) ? [...selected] : [track.id], + x, + y, }) - const toggleAll = () => - setSelected((prev) => - prev.size === filtered.length ? new Set() : new Set(filtered.map((t) => t.id)), - ) return ( @@ -411,20 +413,26 @@ export default function App() { setToast(null)} /> {menu && ( setPrepTrack(menu.track) }, + // Single-track actions are hidden, not disabled, for a multi-selection. + ...(menu.ids.length === 1 + ? [{ label: 'Load to Deck', onClick: () => setPrepTrack(menu.track) }] + : []), // Offering "Edit Tags…" on a read-only library would open a dialog // whose every save is refused, so it is not offered at all. - ...(canEdit + ...(canEdit && menu.ids.length === 1 ? [{ label: 'Edit Tags…', onClick: () => setEditing(menu.track) }] : []), // Adding to an export touches no library data, so it is offered even // on a read-only one — an export is Konduktor's own curation. ...(exportSets.data ?? []).map((set) => ({ label: `Add to “${set.name}”`, - onClick: () => addToExport(set.id, [menu.track.id]), + onClick: () => addToExport(set.id, menu.ids), })), // Only on the export's ROOT view. Inside a referenced playlist there // is nothing to remove: the reference is live, and per-track removal @@ -437,7 +445,7 @@ export default function App() { onClick: () => removeFromExport( source.kind === 'export' ? source.id : source.exportId, - [menu.track.id], + menu.ids, ), }, ] @@ -597,13 +605,8 @@ export default function App() { tracks={filtered} sorting={sorting} onSortingChange={setSorting} - selection={{ - selected, - onToggle: toggle, - onToggleAll: toggleAll, - allSelected: selected.size > 0 && selected.size === filtered.length, - }} - onRowContextMenu={(track, x, y) => setMenu({ track, x, y })} + selection={{ selected, onChange: setSelected }} + onRowContextMenu={(track, x, y) => openMenu(track, x, y, true)} onPlay={playTrack} onEditField={canEdit ? editField : undefined} activeTrackId={prepTrack?.id ?? null} @@ -636,7 +639,7 @@ export default function App() { tracks={filtered} sorting={sorting} onSortingChange={setSorting} - onRowContextMenu={(track, x, y) => setMenu({ track, x, y })} + onRowContextMenu={(track, x, y) => openMenu(track, x, y, false)} onPlay={playTrack} activeTrackId={prepTrack?.id ?? null} columnVisibility={columnVisibility} @@ -657,13 +660,8 @@ export default function App() { tracks={filtered} sorting={sorting} onSortingChange={setSorting} - selection={{ - selected, - onToggle: toggle, - onToggleAll: toggleAll, - allSelected: selected.size > 0 && selected.size === filtered.length, - }} - onRowContextMenu={(track, x, y) => setMenu({ track, x, y })} + selection={{ selected, onChange: setSelected }} + onRowContextMenu={(track, x, y) => openMenu(track, x, y, true)} onPlay={playTrack} onEditField={canEdit ? editField : undefined} activeTrackId={prepTrack?.id ?? null} @@ -689,7 +687,7 @@ export default function App() { ) : ( setMenu({ track, x, y })} + onRowContextMenu={(track, x, y) => openMenu(track, x, y, false)} onPlay={playTrack} onEditField={canEdit ? editField : undefined} activeTrackId={prepTrack?.id ?? null} diff --git a/frontend/src/components/AutoCueDialog.tsx b/frontend/src/components/AutoCueDialog.tsx index b42c6ed..7ac2003 100644 --- a/frontend/src/components/AutoCueDialog.tsx +++ b/frontend/src/components/AutoCueDialog.tsx @@ -130,7 +130,7 @@ export function AutoCueDialog({ track, slotCount, slotLabel, existing, onClose, } return ( -
!busy && onClose()}> +
!busy && onClose()}>
e.stopPropagation()} diff --git a/frontend/src/components/ContextMenu.tsx b/frontend/src/components/ContextMenu.tsx index e3171ff..5fd7b2b 100644 --- a/frontend/src/components/ContextMenu.tsx +++ b/frontend/src/components/ContextMenu.tsx @@ -1,4 +1,4 @@ -import { useEffect } from 'react' +import { useEffect, useRef } from 'react' export interface MenuItem { label: string @@ -15,9 +15,15 @@ interface Props { // Lightweight fixed-position menu. Closes on outside click, scroll, or Escape. export function ContextMenu({ x, y, items, onClose }: Props) { + // Read through a ref so the listeners are attached ONCE. Callers pass an + // inline `onClose`; if the effect depended on it, a click that re-renders the + // parent (e.g. selecting a row) would detach the listeners before the + // window's click handler ran, and the menu would never close. + const onCloseRef = useRef(onClose) + onCloseRef.current = onClose useEffect(() => { - const close = () => onClose() - const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose() + const close = () => onCloseRef.current() + const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onCloseRef.current() // Defer attaching outside-dismiss listeners by a tick so the very // right-click/click that opened the menu can't immediately close it. const id = setTimeout(() => { @@ -33,10 +39,11 @@ export function ContextMenu({ x, y, items, onClose }: Props) { window.removeEventListener('scroll', close, true) window.removeEventListener('keydown', onKey) } - }, [onClose]) + }, []) return (
e.stopPropagation()} diff --git a/frontend/src/components/EditTagsDialog.tsx b/frontend/src/components/EditTagsDialog.tsx index 99f4941..46dead9 100644 --- a/frontend/src/components/EditTagsDialog.tsx +++ b/frontend/src/components/EditTagsDialog.tsx @@ -97,7 +97,7 @@ export function EditTagsDialog({ track, onClose, onApplied, onError }: Props) { return (
setBrowsing(false)} /> )} -
+

diff --git a/frontend/src/components/ExportRunDialog.tsx b/frontend/src/components/ExportRunDialog.tsx index 22d59c7..8c81e0d 100644 --- a/frontend/src/components/ExportRunDialog.tsx +++ b/frontend/src/components/ExportRunDialog.tsx @@ -101,7 +101,7 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) { const blocked = p?.blocked ?? null return ( -
+

Export “{set.name}”

diff --git a/frontend/src/components/FolderPicker.tsx b/frontend/src/components/FolderPicker.tsx index b77f890..5b1e21b 100644 --- a/frontend/src/components/FolderPicker.tsx +++ b/frontend/src/components/FolderPicker.tsx @@ -31,7 +31,7 @@ export function FolderPicker({ value, onChange, onClose }: Props) { } return ( -
+

Choose a folder

diff --git a/frontend/src/components/HistoryPanel.tsx b/frontend/src/components/HistoryPanel.tsx index bd175d4..821f602 100644 --- a/frontend/src/components/HistoryPanel.tsx +++ b/frontend/src/components/HistoryPanel.tsx @@ -80,7 +80,7 @@ export function HistoryPanel({ onClose, onNotify, onError }: Props) { return (
setBrowsing(false)} /> )} -
+

diff --git a/frontend/src/components/PathMappingDialog.tsx b/frontend/src/components/PathMappingDialog.tsx index 1f2664f..efb6ade 100644 --- a/frontend/src/components/PathMappingDialog.tsx +++ b/frontend/src/components/PathMappingDialog.tsx @@ -103,7 +103,7 @@ export function PathMappingDialog({ onClose, onNotify, onError }: Props) { return (
- onToggle: (id: string) => void - onToggleAll: () => void - allSelected: boolean + onChange: (next: Set) => void } interface CommonProps { @@ -194,7 +196,6 @@ function HeaderRow({ lead, trail, hasPlay, - selection, }: { headers: Header[] sensors: ReturnType @@ -202,7 +203,6 @@ function HeaderRow({ lead?: boolean // playlist drag-handle spacer trail?: boolean // playlist remove spacer hasPlay: boolean - selection?: Selection }) { // True while (and just after) a column is being reordered, so the trailing // click a drag emits is swallowed instead of toggling the sort. @@ -225,19 +225,7 @@ function HeaderRow({ >
{lead && } - {selection ? ( - - - - ) : ( - - )} + {hasPlay && } h.column.id)} @@ -311,15 +299,96 @@ export function TrackTable({ onColumnOrderChange(arrayMove(columnOrder, from, to)) } + // Range selection runs from the anchor; arrow keys move from the lead (the + // row most recently clicked or arrowed to). Both are ids, not indices, so a + // re-sort keeps them on the same track. + const anchorRef = useRef(null) + const leadRef = useRef(null) + const indexOf = (id: string | null) => (id == null ? -1 : rows.findIndex((r) => r.original.id === id)) + const rangeIds = (a: number, b: number) => + rows.slice(Math.min(a, b), Math.max(a, b) + 1).map((r) => r.original.id) + + const selectOnly = (index: number) => { + const id = rows[index].original.id + anchorRef.current = leadRef.current = id + selection?.onChange(new Set([id])) + } + + const clickRow = (index: number, e: { shiftKey: boolean; metaKey: boolean; ctrlKey: boolean }) => { + if (!selection) return + const id = rows[index].original.id + const toggle = e.metaKey || e.ctrlKey + const anchor = indexOf(anchorRef.current) + if (e.shiftKey && anchor >= 0) { + const range = rangeIds(anchor, index) + selection.onChange(toggle ? new Set([...selection.selected, ...range]) : new Set(range)) + leadRef.current = id + } else if (toggle) { + const next = new Set(selection.selected) + next.has(id) ? next.delete(id) : next.add(id) + anchorRef.current = leadRef.current = id + selection.onChange(next) + } else { + selectOnly(index) + } + } + + // Keyboard: ↑/↓ move the selection (Shift extends it), Cmd/Ctrl+A selects + // every visible row, Esc clears. Read through a ref so the listener is + // attached once. ←/→, Space, C and digits belong to the deck (PrepStrip). + const keysRef = useRef<(e: KeyboardEvent) => void>(() => {}) + keysRef.current = (e) => { + if (!selection || rows.length === 0) return + const t = e.target as HTMLElement | null + if (t && (t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' || t.tagName === 'SELECT' || t.isContentEditable)) return + // A dialog or menu on top owns the keyboard (and its own Esc). + if (document.querySelector('[aria-modal="true"], [role="menu"]')) return + if ((e.metaKey || e.ctrlKey) && !e.shiftKey && !e.altKey && e.code === 'KeyA') { + e.preventDefault() + selection.onChange(new Set(rows.map((r) => r.original.id))) + return + } + if (e.metaKey || e.ctrlKey || e.altKey) return + if (e.key === 'Escape') { + if (selection.selected.size > 0) selection.onChange(new Set()) + return + } + if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown') return + e.preventDefault() + const lead = indexOf(leadRef.current) + const step = e.key === 'ArrowDown' ? 1 : -1 + const next = lead < 0 ? 0 : Math.max(0, Math.min(rows.length - 1, lead + step)) + const anchor = indexOf(anchorRef.current) + if (e.shiftKey && anchor >= 0) { + leadRef.current = rows[next].original.id + selection.onChange(new Set(rangeIds(anchor, next))) + } else { + selectOnly(next) + } + virtualizer.scrollToIndex(next) + } + useEffect(() => { + const onKey = (e: KeyboardEvent) => keysRef.current(e) + window.addEventListener('keydown', onKey) + return () => window.removeEventListener('keydown', onKey) + }, []) + return ( -
+
{ + // A click in the empty space below the rows clears the selection. + const t = e.target as HTMLElement + if (selection && !t.closest('[data-row]') && !t.closest('.sticky')) selection.onChange(new Set()) + }} + >
{virtualRows.map((vr) => { @@ -329,30 +398,28 @@ export function TrackTable({ return (
{ + // Shift/Cmd-click would otherwise also select page text. + if (selection && (e.shiftKey || e.metaKey || e.ctrlKey)) e.preventDefault() + }} + onClick={(e) => selection && clickRow(vr.index, e)} onContextMenu={(e) => { if (!onRowContextMenu) return e.preventDefault() + // Right-clicking outside the selection retargets it, so the + // menu always acts on what is highlighted. + if (selection && !isSelected) selectOnly(vr.index) onRowContextMenu(row.original, e.clientX, e.clientY) }} > - {selection ? ( - - selection.onToggle(row.original.id)} - className="accent-accent" - /> - - ) : ( - - {vr.index + 1} - - )} + + {vr.index + 1} + {hasPlay && ( {onPlay && } diff --git a/frontend/src/components/UpdateDialog.tsx b/frontend/src/components/UpdateDialog.tsx index 97acf11..0463cf4 100644 --- a/frontend/src/components/UpdateDialog.tsx +++ b/frontend/src/components/UpdateDialog.tsx @@ -148,7 +148,7 @@ export function UpdateCheck() { return (