mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Implemented better track multiselect
This commit is contained in:
1 parent
6c123e2597
commit
07e85cfdc9
13 files changed
+151
-74
No files matched your search
@@ -334,7 +334,12 @@ Two independent apps that talk over HTTP:
|
|||||||
library replaces — plus the playlist tree +
|
library replaces — plus the playlist tree +
|
||||||
create/rename/delete), `SaveBar`, `Toolbar` (search/filters + `ColumnsMenu`),
|
create/rename/delete), `SaveBar`, `Toolbar` (search/filters + `ColumnsMenu`),
|
||||||
`TrackTable` (All Tracks — TanStack Table + **virtualized** grid; per-row play
|
`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`/
|
(playlists — same columns/cells/play/inline-edit via shared `HeaderRow`/
|
||||||
`RowCells`/`PlayButton`, so the two views look identical, PLUS dnd-kit
|
`RowCells`/`PlayButton`, so the two views look identical, PLUS dnd-kit
|
||||||
drag-to-reorder + a remove button, header sorting disabled so the manual order
|
drag-to-reorder + a remove button, header sorting disabled so the manual order
|
||||||
|
|||||||
+28
-30
@@ -50,7 +50,9 @@ export default function App() {
|
|||||||
const [selected, setSelected] = useState<Set<string>>(new Set())
|
const [selected, setSelected] = useState<Set<string>>(new Set())
|
||||||
const [toast, setToast] = useState<ToastMsg | null>(null)
|
const [toast, setToast] = useState<ToastMsg | null>(null)
|
||||||
const [forcePicker, setForcePicker] = useState(false)
|
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<Track | null>(null)
|
const [editing, setEditing] = useState<Track | null>(null)
|
||||||
const [showPaths, setShowPaths] = useState(false)
|
const [showPaths, setShowPaths] = useState(false)
|
||||||
const [showHistory, setShowHistory] = useState(false)
|
const [showHistory, setShowHistory] = useState(false)
|
||||||
@@ -394,16 +396,16 @@ export default function App() {
|
|||||||
setSelected(new Set())
|
setSelected(new Set())
|
||||||
}
|
}
|
||||||
|
|
||||||
const toggle = (id: string) =>
|
// TrackTable retargets the selection to a right-clicked row outside it
|
||||||
setSelected((prev) => {
|
// before calling this, but that state update has not landed yet — so the
|
||||||
const next = new Set(prev)
|
// same rule is applied here to decide what the menu acts on.
|
||||||
next.has(id) ? next.delete(id) : next.add(id)
|
const openMenu = (track: Track, x: number, y: number, selectable: boolean) =>
|
||||||
return next
|
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 (
|
return (
|
||||||
<CapabilitiesContext.Provider value={capabilities.data!}>
|
<CapabilitiesContext.Provider value={capabilities.data!}>
|
||||||
@@ -411,20 +413,26 @@ export default function App() {
|
|||||||
<Toast toast={toast} onClose={() => setToast(null)} />
|
<Toast toast={toast} onClose={() => setToast(null)} />
|
||||||
{menu && (
|
{menu && (
|
||||||
<ContextMenu
|
<ContextMenu
|
||||||
|
// Remount per opening: a right-click on another row while a menu is
|
||||||
|
// open must not be caught by the old menu's dismiss listener.
|
||||||
|
key={`${menu.track.id}:${menu.x}:${menu.y}`}
|
||||||
x={menu.x}
|
x={menu.x}
|
||||||
y={menu.y}
|
y={menu.y}
|
||||||
items={[
|
items={[
|
||||||
{ label: 'Load to Deck', onClick: () => 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
|
// Offering "Edit Tags…" on a read-only library would open a dialog
|
||||||
// whose every save is refused, so it is not offered at all.
|
// 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) }]
|
? [{ label: 'Edit Tags…', onClick: () => setEditing(menu.track) }]
|
||||||
: []),
|
: []),
|
||||||
// Adding to an export touches no library data, so it is offered even
|
// 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.
|
// on a read-only one — an export is Konduktor's own curation.
|
||||||
...(exportSets.data ?? []).map((set) => ({
|
...(exportSets.data ?? []).map((set) => ({
|
||||||
label: `Add to “${set.name}”`,
|
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
|
// Only on the export's ROOT view. Inside a referenced playlist there
|
||||||
// is nothing to remove: the reference is live, and per-track removal
|
// is nothing to remove: the reference is live, and per-track removal
|
||||||
@@ -437,7 +445,7 @@ export default function App() {
|
|||||||
onClick: () =>
|
onClick: () =>
|
||||||
removeFromExport(
|
removeFromExport(
|
||||||
source.kind === 'export' ? source.id : source.exportId,
|
source.kind === 'export' ? source.id : source.exportId,
|
||||||
[menu.track.id],
|
menu.ids,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@@ -597,13 +605,8 @@ export default function App() {
|
|||||||
tracks={filtered}
|
tracks={filtered}
|
||||||
sorting={sorting}
|
sorting={sorting}
|
||||||
onSortingChange={setSorting}
|
onSortingChange={setSorting}
|
||||||
selection={{
|
selection={{ selected, onChange: setSelected }}
|
||||||
selected,
|
onRowContextMenu={(track, x, y) => openMenu(track, x, y, true)}
|
||||||
onToggle: toggle,
|
|
||||||
onToggleAll: toggleAll,
|
|
||||||
allSelected: selected.size > 0 && selected.size === filtered.length,
|
|
||||||
}}
|
|
||||||
onRowContextMenu={(track, x, y) => setMenu({ track, x, y })}
|
|
||||||
onPlay={playTrack}
|
onPlay={playTrack}
|
||||||
onEditField={canEdit ? editField : undefined}
|
onEditField={canEdit ? editField : undefined}
|
||||||
activeTrackId={prepTrack?.id ?? null}
|
activeTrackId={prepTrack?.id ?? null}
|
||||||
@@ -636,7 +639,7 @@ export default function App() {
|
|||||||
tracks={filtered}
|
tracks={filtered}
|
||||||
sorting={sorting}
|
sorting={sorting}
|
||||||
onSortingChange={setSorting}
|
onSortingChange={setSorting}
|
||||||
onRowContextMenu={(track, x, y) => setMenu({ track, x, y })}
|
onRowContextMenu={(track, x, y) => openMenu(track, x, y, false)}
|
||||||
onPlay={playTrack}
|
onPlay={playTrack}
|
||||||
activeTrackId={prepTrack?.id ?? null}
|
activeTrackId={prepTrack?.id ?? null}
|
||||||
columnVisibility={columnVisibility}
|
columnVisibility={columnVisibility}
|
||||||
@@ -657,13 +660,8 @@ export default function App() {
|
|||||||
tracks={filtered}
|
tracks={filtered}
|
||||||
sorting={sorting}
|
sorting={sorting}
|
||||||
onSortingChange={setSorting}
|
onSortingChange={setSorting}
|
||||||
selection={{
|
selection={{ selected, onChange: setSelected }}
|
||||||
selected,
|
onRowContextMenu={(track, x, y) => openMenu(track, x, y, true)}
|
||||||
onToggle: toggle,
|
|
||||||
onToggleAll: toggleAll,
|
|
||||||
allSelected: selected.size > 0 && selected.size === filtered.length,
|
|
||||||
}}
|
|
||||||
onRowContextMenu={(track, x, y) => setMenu({ track, x, y })}
|
|
||||||
onPlay={playTrack}
|
onPlay={playTrack}
|
||||||
onEditField={canEdit ? editField : undefined}
|
onEditField={canEdit ? editField : undefined}
|
||||||
activeTrackId={prepTrack?.id ?? null}
|
activeTrackId={prepTrack?.id ?? null}
|
||||||
@@ -689,7 +687,7 @@ export default function App() {
|
|||||||
) : (
|
) : (
|
||||||
<PlaylistTable
|
<PlaylistTable
|
||||||
tracks={filtered}
|
tracks={filtered}
|
||||||
onRowContextMenu={(track, x, y) => setMenu({ track, x, y })}
|
onRowContextMenu={(track, x, y) => openMenu(track, x, y, false)}
|
||||||
onPlay={playTrack}
|
onPlay={playTrack}
|
||||||
onEditField={canEdit ? editField : undefined}
|
onEditField={canEdit ? editField : undefined}
|
||||||
activeTrackId={prepTrack?.id ?? null}
|
activeTrackId={prepTrack?.id ?? null}
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ export function AutoCueDialog({ track, slotCount, slotLabel, existing, onClose,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed inset-0 z-40 flex items-center justify-center bg-black/60 p-6" onClick={() => !busy && onClose()}>
|
<div aria-modal="true" className="fixed inset-0 z-40 flex items-center justify-center bg-black/60 p-6" onClick={() => !busy && onClose()}>
|
||||||
<div
|
<div
|
||||||
className="flex max-h-[85vh] w-full max-w-xl flex-col overflow-hidden rounded-xl border border-line bg-ink-900 shadow-2xl"
|
className="flex max-h-[85vh] w-full max-w-xl flex-col overflow-hidden rounded-xl border border-line bg-ink-900 shadow-2xl"
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect } from 'react'
|
import { useEffect, useRef } from 'react'
|
||||||
|
|
||||||
export interface MenuItem {
|
export interface MenuItem {
|
||||||
label: string
|
label: string
|
||||||
@@ -15,9 +15,15 @@ interface Props {
|
|||||||
|
|
||||||
// Lightweight fixed-position menu. Closes on outside click, scroll, or Escape.
|
// Lightweight fixed-position menu. Closes on outside click, scroll, or Escape.
|
||||||
export function ContextMenu({ x, y, items, onClose }: Props) {
|
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(() => {
|
useEffect(() => {
|
||||||
const close = () => onClose()
|
const close = () => onCloseRef.current()
|
||||||
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose()
|
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onCloseRef.current()
|
||||||
// Defer attaching outside-dismiss listeners by a tick so the very
|
// Defer attaching outside-dismiss listeners by a tick so the very
|
||||||
// right-click/click that opened the menu can't immediately close it.
|
// right-click/click that opened the menu can't immediately close it.
|
||||||
const id = setTimeout(() => {
|
const id = setTimeout(() => {
|
||||||
@@ -33,10 +39,11 @@ export function ContextMenu({ x, y, items, onClose }: Props) {
|
|||||||
window.removeEventListener('scroll', close, true)
|
window.removeEventListener('scroll', close, true)
|
||||||
window.removeEventListener('keydown', onKey)
|
window.removeEventListener('keydown', onKey)
|
||||||
}
|
}
|
||||||
}, [onClose])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
role="menu"
|
||||||
className="fixed z-50 min-w-[160px] overflow-hidden rounded-lg border border-line bg-ink-850 py-1 shadow-2xl"
|
className="fixed z-50 min-w-[160px] overflow-hidden rounded-lg border border-line bg-ink-850 py-1 shadow-2xl"
|
||||||
style={{ top: Math.min(y, window.innerHeight - 100), left: Math.min(x, window.innerWidth - 180) }}
|
style={{ top: Math.min(y, window.innerHeight - 100), left: Math.min(x, window.innerWidth - 180) }}
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ export function EditTagsDialog({ track, onClose, onApplied, onError }: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="fixed inset-0 z-40 flex items-center justify-center bg-black/60 p-6"
|
aria-modal="true" className="fixed inset-0 z-40 flex items-center justify-center bg-black/60 p-6"
|
||||||
onClick={onClose}
|
onClick={onClose}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export function ExportDialog({ editing, onClose, onSaved, onError }: Props) {
|
|||||||
onClose={() => setBrowsing(false)}
|
onClose={() => setBrowsing(false)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4">
|
<div aria-modal="true" className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4">
|
||||||
<div className="w-full max-w-lg rounded-lg border border-line bg-ink-900 shadow-xl">
|
<div className="w-full max-w-lg rounded-lg border border-line bg-ink-900 shadow-xl">
|
||||||
<div className="border-b border-line px-5 py-3">
|
<div className="border-b border-line px-5 py-3">
|
||||||
<h2 className="text-sm font-semibold text-text">
|
<h2 className="text-sm font-semibold text-text">
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
|
|||||||
const blocked = p?.blocked ?? null
|
const blocked = p?.blocked ?? null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4">
|
<div aria-modal="true" className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4">
|
||||||
<div className="w-full max-w-lg rounded-lg border border-line bg-ink-900 shadow-xl">
|
<div className="w-full max-w-lg rounded-lg border border-line bg-ink-900 shadow-xl">
|
||||||
<div className="border-b border-line px-5 py-3">
|
<div className="border-b border-line px-5 py-3">
|
||||||
<h2 className="text-sm font-semibold text-text">Export “{set.name}”</h2>
|
<h2 className="text-sm font-semibold text-text">Export “{set.name}”</h2>
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export function FolderPicker({ value, onChange, onClose }: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed inset-0 z-[60] flex items-center justify-center bg-black/60 p-4">
|
<div aria-modal="true" className="fixed inset-0 z-[60] flex items-center justify-center bg-black/60 p-4">
|
||||||
<div className="flex h-[70vh] w-full max-w-2xl flex-col overflow-hidden rounded-lg border border-line bg-ink-900 shadow-xl">
|
<div className="flex h-[70vh] w-full max-w-2xl flex-col overflow-hidden rounded-lg border border-line bg-ink-900 shadow-xl">
|
||||||
<div className="border-b border-line px-5 py-3">
|
<div className="border-b border-line px-5 py-3">
|
||||||
<h2 className="text-sm font-semibold text-text">Choose a folder</h2>
|
<h2 className="text-sm font-semibold text-text">Choose a folder</h2>
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ export function HistoryPanel({ onClose, onNotify, onError }: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="fixed inset-0 z-40 flex items-center justify-center bg-black/60 p-6"
|
aria-modal="true" className="fixed inset-0 z-40 flex items-center justify-center bg-black/60 p-6"
|
||||||
onClick={onClose}
|
onClick={onClose}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ export function ImportDialog({ playlistId, deviceLabel, onClose, onDone, onError
|
|||||||
onClose={() => setBrowsing(false)}
|
onClose={() => setBrowsing(false)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4">
|
<div aria-modal="true" className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4">
|
||||||
<div className="w-full max-w-lg rounded-lg border border-line bg-ink-900 shadow-xl">
|
<div className="w-full max-w-lg rounded-lg border border-line bg-ink-900 shadow-xl">
|
||||||
<div className="border-b border-line px-5 py-3">
|
<div className="border-b border-line px-5 py-3">
|
||||||
<h2 className="text-sm font-semibold text-text">
|
<h2 className="text-sm font-semibold text-text">
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ export function PathMappingDialog({ onClose, onNotify, onError }: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="fixed inset-0 z-40 flex items-center justify-center bg-black/60 p-6"
|
aria-modal="true" className="fixed inset-0 z-40 flex items-center justify-center bg-black/60 p-6"
|
||||||
onClick={onClose}
|
onClick={onClose}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -47,11 +47,13 @@ const ROW_HEIGHT = 44
|
|||||||
// every commit → infinite re-render loop. Playlists never sort, so share one array.
|
// every commit → infinite re-render loop. Playlists never sort, so share one array.
|
||||||
const NO_SORTING: SortingState = []
|
const NO_SORTING: SortingState = []
|
||||||
|
|
||||||
|
/** Row selection, Finder-style: click selects one row, Cmd/Ctrl+click toggles,
|
||||||
|
* Shift+click selects a range from the anchor (the last row clicked without
|
||||||
|
* Shift) in the table's SORTED order. The table owns the anchor; the caller
|
||||||
|
* owns the set. */
|
||||||
interface Selection {
|
interface Selection {
|
||||||
selected: Set<string>
|
selected: Set<string>
|
||||||
onToggle: (id: string) => void
|
onChange: (next: Set<string>) => void
|
||||||
onToggleAll: () => void
|
|
||||||
allSelected: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CommonProps {
|
interface CommonProps {
|
||||||
@@ -194,7 +196,6 @@ function HeaderRow({
|
|||||||
lead,
|
lead,
|
||||||
trail,
|
trail,
|
||||||
hasPlay,
|
hasPlay,
|
||||||
selection,
|
|
||||||
}: {
|
}: {
|
||||||
headers: Header<Track, unknown>[]
|
headers: Header<Track, unknown>[]
|
||||||
sensors: ReturnType<typeof useSensors>
|
sensors: ReturnType<typeof useSensors>
|
||||||
@@ -202,7 +203,6 @@ function HeaderRow({
|
|||||||
lead?: boolean // playlist drag-handle spacer
|
lead?: boolean // playlist drag-handle spacer
|
||||||
trail?: boolean // playlist remove spacer
|
trail?: boolean // playlist remove spacer
|
||||||
hasPlay: boolean
|
hasPlay: boolean
|
||||||
selection?: Selection
|
|
||||||
}) {
|
}) {
|
||||||
// True while (and just after) a column is being reordered, so the trailing
|
// True while (and just after) a column is being reordered, so the trailing
|
||||||
// click a drag emits is swallowed instead of toggling the sort.
|
// click a drag emits is swallowed instead of toggling the sort.
|
||||||
@@ -225,19 +225,7 @@ function HeaderRow({
|
|||||||
>
|
>
|
||||||
<div className="sticky top-0 z-10 flex border-b border-line bg-ink-850">
|
<div className="sticky top-0 z-10 flex border-b border-line bg-ink-850">
|
||||||
{lead && <span className="w-8 shrink-0" />}
|
{lead && <span className="w-8 shrink-0" />}
|
||||||
{selection ? (
|
|
||||||
<span className="flex w-10 shrink-0 items-center justify-center">
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
checked={selection.allSelected}
|
|
||||||
onChange={selection.onToggleAll}
|
|
||||||
className="accent-accent"
|
|
||||||
title="Select all"
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
) : (
|
|
||||||
<span className="w-10 shrink-0" />
|
<span className="w-10 shrink-0" />
|
||||||
)}
|
|
||||||
{hasPlay && <span className="w-9 shrink-0" />}
|
{hasPlay && <span className="w-9 shrink-0" />}
|
||||||
<SortableContext
|
<SortableContext
|
||||||
items={headers.map((h) => h.column.id)}
|
items={headers.map((h) => h.column.id)}
|
||||||
@@ -311,15 +299,96 @@ export function TrackTable({
|
|||||||
onColumnOrderChange(arrayMove(columnOrder, from, to))
|
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<string | null>(null)
|
||||||
|
const leadRef = useRef<string | null>(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 (
|
return (
|
||||||
<div ref={parentRef} className="h-full overflow-auto">
|
<div
|
||||||
|
ref={parentRef}
|
||||||
|
className="h-full overflow-auto"
|
||||||
|
onClick={(e) => {
|
||||||
|
// 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())
|
||||||
|
}}
|
||||||
|
>
|
||||||
<div style={{ width: totalWidth, minWidth: '100%' }}>
|
<div style={{ width: totalWidth, minWidth: '100%' }}>
|
||||||
<HeaderRow
|
<HeaderRow
|
||||||
headers={headers}
|
headers={headers}
|
||||||
sensors={sensors}
|
sensors={sensors}
|
||||||
onColumnDragEnd={onColumnDragEnd}
|
onColumnDragEnd={onColumnDragEnd}
|
||||||
hasPlay={hasPlay}
|
hasPlay={hasPlay}
|
||||||
selection={selection}
|
|
||||||
/>
|
/>
|
||||||
<div style={{ height: virtualizer.getTotalSize(), position: 'relative' }}>
|
<div style={{ height: virtualizer.getTotalSize(), position: 'relative' }}>
|
||||||
{virtualRows.map((vr) => {
|
{virtualRows.map((vr) => {
|
||||||
@@ -329,30 +398,28 @@ export function TrackTable({
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={row.id}
|
key={row.id}
|
||||||
|
data-row
|
||||||
className={`group absolute left-0 flex items-center border-b border-ink-850 text-sm ${
|
className={`group absolute left-0 flex items-center border-b border-ink-850 text-sm ${
|
||||||
isSelected ? 'bg-accent-soft/50' : 'hover:bg-ink-850'
|
isSelected ? 'bg-accent-soft/50' : 'hover:bg-ink-850'
|
||||||
}`}
|
}`}
|
||||||
style={{ top: 0, transform: `translateY(${vr.start}px)`, height: vr.size, width: '100%' }}
|
style={{ top: 0, transform: `translateY(${vr.start}px)`, height: vr.size, width: '100%' }}
|
||||||
|
onMouseDown={(e) => {
|
||||||
|
// 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) => {
|
onContextMenu={(e) => {
|
||||||
if (!onRowContextMenu) return
|
if (!onRowContextMenu) return
|
||||||
e.preventDefault()
|
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)
|
onRowContextMenu(row.original, e.clientX, e.clientY)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{selection ? (
|
|
||||||
<span className="flex w-10 shrink-0 items-center justify-center">
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
checked={isSelected}
|
|
||||||
onChange={() => selection.onToggle(row.original.id)}
|
|
||||||
className="accent-accent"
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
) : (
|
|
||||||
<span className="w-10 shrink-0 pr-2 text-right text-xs tabular-nums text-faint">
|
<span className="w-10 shrink-0 pr-2 text-right text-xs tabular-nums text-faint">
|
||||||
{vr.index + 1}
|
{vr.index + 1}
|
||||||
</span>
|
</span>
|
||||||
)}
|
|
||||||
{hasPlay && (
|
{hasPlay && (
|
||||||
<span className="flex w-9 shrink-0 items-center justify-center">
|
<span className="flex w-9 shrink-0 items-center justify-center">
|
||||||
{onPlay && <PlayButton track={row.original} isActive={isActive} onPlay={onPlay} />}
|
{onPlay && <PlayButton track={row.original} isActive={isActive} onPlay={onPlay} />}
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ export function UpdateCheck() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-6"
|
aria-modal="true" className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-6"
|
||||||
onClick={close}
|
onClick={close}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
|||||||
Reference in new issue
Block a user