Third and last slice of the E11 keyboard layer (S4c). S4a/S4b covered every card grid and rail; the table-shaped pages — the channel manager, a playlist, the download center — were still Tab-stop country: a channel row carries a priority stepper, four action buttons and a tag picker before the next row's name. - `ui/DataTable keyboardNav`: the rows are the items, Enter clicks the element a column marks `data-nav-open`. DataTable renders its rows twice (a table, and a card list below `md`); both register and `lib/listNav` now walks only lists on screen (`checkVisibility`), so `j` past the last row never carries on into the hidden copy. - `lib/listNav` leaves a key something before it already handled (`defaultPrevented`): during a keyboard drag a playlist row's grip moves the row with the arrows, and dnd-kit takes the key on the document before listNav's window listener. Without the guard ↓ moved the focus off the grip and dropped the drag. - `ui/NavGrid as="tbody"` for a table whose body is the list (the playlist, under dnd-kit's SortableContext). - Wired: Subscriptions and Discovery tables, the card layout (`ChannelLayoutGrid` → VirtualGrid `keyboardNav`), Hidden/Blocked cards (the ChannelLink name is a channel's open element); a playlist's rows (the title plays; the grip keeps Space/Enter); the download queue, library and shared lists (the play button opens, `IconBtn open`; a row without one opens nothing). - `listNav.wiring.contract.test`: `VirtualGrid` and `DataTable` must say `keyboardNav` like `Carousel`, `DownloadRow` is a card; the audit log's table is the one exemption (its rows open nothing), and an exemption that no longer matches a tag fails the test. Measured in Chrome: Channels table j → row, ring round the whole row; a row walked down keeps 12px above the viewport edge, walked up clears the sticky header by 35px; Enter opens the channel. Cards 3 columns: → 0→1, ↓ 1→4. Hidden and Discovery: j + Enter open the channel. Playlist: j + Enter plays, Escape returns focus to the row; a keyboard drag (Enter on the grip, ↓) moves the row with focus kept on the grip, and Escape cancels with the order unchanged. Downloads library: Enter plays a video row, does nothing on a plain file row.
104 lines
4.1 KiB
TypeScript
104 lines
4.1 KiB
TypeScript
import { Fragment } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { type Column } from "./ui/DataTable";
|
|
import VirtualGrid from "./ui/VirtualGrid";
|
|
import { CHANNEL_LAYOUT_SPEC } from "../lib/channelLayout";
|
|
import { navItemAttrs } from "../lib/listNav";
|
|
|
|
// The channel manager's `cards` layout (E4 S3), built by reusing the SAME `Column<T>` render closures
|
|
// the DataTable draws — so the subscribed and discovery tables (which have different columns) both get
|
|
// the card view for free, and a cell's behaviour (priority bump, tag toggle, sync, actions) is defined
|
|
// once. The `table` layout keeps DataTable; this renders only when the manager's layout is `cards`.
|
|
//
|
|
// Named slots place the columns that need bespoke positions; everything else flows in the meta line.
|
|
// Unlike DataTable's cramped narrow-screen card fallback, the desktop card is roomy, so it shows the
|
|
// `hideInCard` columns too (About, priority) — the user wants those affordances in every layout.
|
|
//
|
|
// Each card is a keyboard item (lib/listNav): `j`/`k` and the arrows walk the cards, and Enter opens
|
|
// the channel — the name ChannelLink renders is the card's open element.
|
|
|
|
interface ChannelLayoutGridProps<T> {
|
|
rows: T[];
|
|
columns: Column<T>[];
|
|
rowKey: (row: T) => string;
|
|
/** Column key docked at the top-right of the card (the priority stepper). */
|
|
leadKey?: string;
|
|
/** Column key rendered as a full-width description line (the About cell + its hover overlay). */
|
|
aboutKey?: string;
|
|
/** Column key rendered as the action cluster, pinned to the card's bottom edge. */
|
|
actionsKey?: string;
|
|
rowClassName?: (row: T) => string;
|
|
/** Extra DOM props per card — same escape hatch, same single consumer, as `DataTable.rowProps`, so
|
|
* a channel answers the right-click in the card layout exactly as it does in the table. */
|
|
rowProps?: (row: T) => Record<string, unknown>;
|
|
emptyText?: string;
|
|
}
|
|
|
|
export default function ChannelLayoutGrid<T>({
|
|
rows,
|
|
columns,
|
|
rowKey,
|
|
leadKey,
|
|
aboutKey,
|
|
actionsKey,
|
|
rowClassName,
|
|
rowProps,
|
|
emptyText,
|
|
}: ChannelLayoutGridProps<T>) {
|
|
const { t } = useTranslation();
|
|
const spec = CHANNEL_LAYOUT_SPEC.cards;
|
|
|
|
const slotted = new Set([leadKey, aboutKey, actionsKey].filter(Boolean) as string[]);
|
|
const primary = columns.filter((c) => c.cardPrimary);
|
|
const lead = leadKey ? columns.find((c) => c.key === leadKey) : undefined;
|
|
const about = aboutKey ? columns.find((c) => c.key === aboutKey) : undefined;
|
|
const actions = actionsKey ? columns.find((c) => c.key === actionsKey) : undefined;
|
|
// Everything else flows in the meta line: not the heading, not a slotted column.
|
|
const meta = columns.filter((c) => !c.cardPrimary && !slotted.has(c.key));
|
|
|
|
const renderCard = (row: T, index: number) => (
|
|
<div
|
|
{...rowProps?.(row)}
|
|
{...navItemAttrs(index)}
|
|
className={`glass-card rounded-xl p-3 h-full flex flex-col gap-2 ${rowClassName?.(row) ?? ""}`}
|
|
>
|
|
<div className="flex items-start justify-between gap-2">
|
|
<div className="min-w-0 flex-1 font-medium">
|
|
{primary.map((col) => (
|
|
<Fragment key={col.key}>{col.render(row)}</Fragment>
|
|
))}
|
|
</div>
|
|
{lead && <div className="shrink-0">{lead.render(row)}</div>}
|
|
</div>
|
|
{about && <div className="min-w-0 text-sm">{about.render(row)}</div>}
|
|
<div className="flex flex-wrap items-center gap-x-3 gap-y-1.5 text-sm min-w-0">
|
|
{meta.map((col) => (
|
|
<span key={col.key} className="inline-flex items-center gap-1">
|
|
{col.cardLabel !== false && <span className="text-muted text-xs">{col.header}</span>}
|
|
{col.render(row)}
|
|
</span>
|
|
))}
|
|
</div>
|
|
{actions && <div className="mt-auto pt-1">{actions.render(row)}</div>}
|
|
</div>
|
|
);
|
|
|
|
if (rows.length === 0) {
|
|
return (
|
|
<div className="text-muted py-8 text-center text-sm">{emptyText ?? t("datatable.empty")}</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<VirtualGrid
|
|
items={rows}
|
|
getKey={rowKey}
|
|
minCol={spec.minCol}
|
|
colMaxWidth={null}
|
|
rowEst={spec.rowEst}
|
|
keyboardNav
|
|
renderItem={(row, _itemWidth, index) => renderCard(row, index)}
|
|
/>
|
|
);
|
|
}
|