mirror of
https://github.com/rommapp/romm.git
synced 2026-12-04 21:02:21 +01:00
Merge pull request #4654 from rommapp/fix/gallery-list-table-header
fix(v2): rebuild the gallery list view for phones
This commit is contained in:
@@ -82,9 +82,10 @@ const NAME_OVERRIDES = {
|
||||
collectionCoverWidthXs: "--r-coll-cover-w-xs",
|
||||
collectionCoverHeightXs: "--r-coll-cover-h-xs",
|
||||
alphaStripWidth: "--r-alpha-strip-w",
|
||||
alphaStripWidthXs: "--r-alpha-strip-w-xs",
|
||||
listRowHeight: "--r-list-row-h",
|
||||
listHeaderHeight: "--r-list-header-h",
|
||||
listSelectWidth: "--r-list-select-w",
|
||||
listRowDetailHeight: "--r-list-row-detail-h",
|
||||
},
|
||||
colorBrand: {
|
||||
fav: "--r-color-fav",
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
// column is a button that toggles asc → desc → asc on the parent's
|
||||
// sort state via the `sort` event.
|
||||
import { RIcon } from "@v2/lib";
|
||||
import { computed } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import ListSortMenu from "@/v2/components/shared/ListSortMenu.vue";
|
||||
import { useBreakpoint } from "@/v2/composables/useBreakpoint";
|
||||
import {
|
||||
COLLECTION_LIST_COLUMNS,
|
||||
COLLECTION_LIST_GRID_TEMPLATE,
|
||||
@@ -31,6 +34,15 @@ const emit = defineEmits<{
|
||||
const { t } = useI18n();
|
||||
const gridStyle = { gridTemplateColumns: COLLECTION_LIST_GRID_TEMPLATE };
|
||||
|
||||
// Phones and tablets drop the columns (the rows go compact), so the sort
|
||||
// key they carried moves into a menu, same as the gallery's list header.
|
||||
const { smAndDown } = useBreakpoint();
|
||||
const sortOptions = computed(() =>
|
||||
COLLECTION_LIST_COLUMNS.flatMap((col) =>
|
||||
col.sortKey ? [{ key: col.sortKey, label: t(col.labelKey) }] : [],
|
||||
),
|
||||
);
|
||||
|
||||
function handleClick(col: CollectionListColumn) {
|
||||
if (!col.sortKey) return;
|
||||
// Toggle direction when re-clicking the active column; otherwise
|
||||
@@ -42,7 +54,20 @@ function handleClick(col: CollectionListColumn) {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="coll-list-header" :style="gridStyle" role="row">
|
||||
<div
|
||||
v-if="smAndDown"
|
||||
class="coll-list-header coll-list-header--compact"
|
||||
role="row"
|
||||
>
|
||||
<ListSortMenu
|
||||
:options="sortOptions"
|
||||
:sort-key="sortKey"
|
||||
:sort-dir="sortDir"
|
||||
@sort="emit('sort', $event)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-else class="coll-list-header" :style="gridStyle" role="row">
|
||||
<button
|
||||
v-for="col in COLLECTION_LIST_COLUMNS"
|
||||
:key="col.key"
|
||||
@@ -83,9 +108,15 @@ function handleClick(col: CollectionListColumn) {
|
||||
gap: 0 var(--r-space-3);
|
||||
padding: 0 var(--r-space-3);
|
||||
height: var(--r-list-header-h);
|
||||
background: var(--r-color-bg-elevated);
|
||||
border-bottom: 1px solid var(--r-color-border);
|
||||
backdrop-filter: blur(10px);
|
||||
/* Overridable so a pinned header can run it edge to edge (r-pinned-list-header). */
|
||||
border-bottom: var(--r-list-header-border, 1px solid var(--r-color-border));
|
||||
}
|
||||
|
||||
/* Compact (phones / tablets): one sort control instead of the columns. */
|
||||
.coll-list-header--compact {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 var(--r-row-pad);
|
||||
}
|
||||
|
||||
.coll-list-header__cell {
|
||||
|
||||
@@ -12,6 +12,8 @@ import { computed, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useRouter } from "vue-router";
|
||||
import CollectionMosaic from "@/v2/components/Collections/CollectionMosaic.vue";
|
||||
import { useBreakpoint } from "@/v2/composables/useBreakpoint";
|
||||
import { useStaggeredEntrance } from "@/v2/composables/useStaggeredEntrance";
|
||||
import {
|
||||
pendingMorphName,
|
||||
useViewTransition,
|
||||
@@ -43,6 +45,12 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
});
|
||||
|
||||
const { t } = useI18n();
|
||||
// Phones and tablets have no room for the columns: the row goes two-line,
|
||||
// same as the gallery's list rows.
|
||||
const { smAndDown } = useBreakpoint();
|
||||
const rowEl = ref<HTMLElement | null>(null);
|
||||
const { entranceClass, entranceStyle, endEntrance } =
|
||||
useStaggeredEntrance(rowEl);
|
||||
const router = useRouter();
|
||||
const coverEl = ref<HTMLElement | null>(null);
|
||||
const { morphTransition } = useViewTransition();
|
||||
@@ -92,11 +100,51 @@ function onRowClick(e: MouseEvent) {
|
||||
|
||||
<template>
|
||||
<a
|
||||
class="coll-list-row"
|
||||
:style="gridStyle"
|
||||
v-if="smAndDown"
|
||||
ref="rowEl"
|
||||
class="coll-list-row coll-list-row--compact r-list-compact"
|
||||
:class="entranceClass"
|
||||
:style="entranceStyle"
|
||||
:href="to"
|
||||
:aria-label="t('rom.open-game', { name })"
|
||||
@click="onRowClick"
|
||||
@animationend.self="endEntrance"
|
||||
>
|
||||
<div ref="coverEl" class="coll-list-row__thumb" :style="morphStyle">
|
||||
<CollectionMosaic :covers="covers" />
|
||||
</div>
|
||||
<div class="r-list-compact__stack">
|
||||
<div class="coll-list-row__name">{{ name }}</div>
|
||||
<div class="r-list-compact__facts">
|
||||
<RIcon :icon="kindBadge.icon" size="13" />
|
||||
<span>{{ kindBadge.label }}</span>
|
||||
<span class="r-list-compact__dot">·</span>
|
||||
<span>{{
|
||||
t("collection.games-count", romCount, { named: { n: romCount } })
|
||||
}}</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Private is the state worth flagging; public is the default and
|
||||
would mark almost every row. -->
|
||||
<RIcon
|
||||
v-if="visibility && !isPublic"
|
||||
class="coll-list-row__lock"
|
||||
:icon="visibility.icon"
|
||||
size="18"
|
||||
:aria-label="visibility.label"
|
||||
/>
|
||||
</a>
|
||||
|
||||
<a
|
||||
v-else
|
||||
ref="rowEl"
|
||||
class="coll-list-row coll-list-row--columns"
|
||||
:class="entranceClass"
|
||||
:style="[gridStyle, entranceStyle]"
|
||||
:href="to"
|
||||
:aria-label="t('rom.open-game', { name })"
|
||||
@click="onRowClick"
|
||||
@animationend.self="endEntrance"
|
||||
>
|
||||
<div class="coll-list-row__cell coll-list-row__title">
|
||||
<div ref="coverEl" class="coll-list-row__thumb" :style="morphStyle">
|
||||
@@ -146,10 +194,9 @@ function onRowClick(e: MouseEvent) {
|
||||
|
||||
<style scoped>
|
||||
.coll-list-row {
|
||||
display: grid;
|
||||
/* Runs to the screen edges wherever the shell asks for it. */
|
||||
margin-inline: calc(-1 * var(--r-list-bleed, 0px));
|
||||
align-items: center;
|
||||
gap: 0 var(--r-space-3);
|
||||
padding: 0 var(--r-space-3);
|
||||
height: var(--r-list-row-h);
|
||||
border-bottom: 1px solid var(--r-color-border);
|
||||
font-size: var(--r-font-size-md);
|
||||
@@ -163,6 +210,19 @@ function onRowClick(e: MouseEvent) {
|
||||
background: var(--r-color-bg-elevated);
|
||||
}
|
||||
|
||||
/* Kept off the compact row, whose shared flex layout this would outrank. */
|
||||
.coll-list-row--columns {
|
||||
display: grid;
|
||||
gap: 0 var(--r-space-3);
|
||||
padding: 0 var(--r-space-3);
|
||||
}
|
||||
|
||||
/* Clear of the screen edge, which the row itself runs to. */
|
||||
.coll-list-row__lock {
|
||||
margin-inline-end: var(--r-space-2);
|
||||
color: var(--r-color-fg-muted);
|
||||
}
|
||||
|
||||
.coll-list-row:focus-visible {
|
||||
outline: none;
|
||||
background: var(--r-color-bg-elevated);
|
||||
|
||||
86
frontend/src/v2/components/Gallery/AlphaJumpMenu.test.ts
Normal file
86
frontend/src/v2/components/Gallery/AlphaJumpMenu.test.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
/* eslint-disable vue/one-component-per-file */
|
||||
import { mount } from "@vue/test-utils";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { defineComponent, h } from "vue";
|
||||
import AlphaJumpMenu from "./AlphaJumpMenu.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
|
||||
vi.mock("@/v2/composables/useWrapGridNav", () => ({
|
||||
useWrapGridNav: vi.fn(),
|
||||
}));
|
||||
|
||||
// Renders the panel inline while open, and toggles it from the activator.
|
||||
let initialFocus: readonly string[] | undefined;
|
||||
const RMenuStub = defineComponent({
|
||||
props: {
|
||||
modelValue: { type: Boolean, default: false },
|
||||
initialFocus: { type: Array, default: undefined },
|
||||
},
|
||||
emits: ["update:modelValue"],
|
||||
setup(props, { slots, emit }) {
|
||||
initialFocus = props.initialFocus as readonly string[] | undefined;
|
||||
const toggle = () => emit("update:modelValue", !props.modelValue);
|
||||
return () =>
|
||||
h("div", [
|
||||
slots.activator?.({ props: { onClick: toggle } }),
|
||||
props.modelValue ? slots.default?.() : null,
|
||||
]);
|
||||
},
|
||||
});
|
||||
|
||||
const RBtnStub = defineComponent({
|
||||
setup(_, { slots }) {
|
||||
return () => h("button", { class: "jump-btn" }, slots.default?.());
|
||||
},
|
||||
});
|
||||
|
||||
function mountMenu() {
|
||||
return mount(AlphaJumpMenu, {
|
||||
attachTo: document.body,
|
||||
props: {
|
||||
available: new Set(["A", "M", "Z"]),
|
||||
current: "M",
|
||||
direction: "asc",
|
||||
},
|
||||
global: { stubs: { RMenu: RMenuStub, RBtn: RBtnStub } },
|
||||
});
|
||||
}
|
||||
|
||||
function letter(wrapper: ReturnType<typeof mountMenu>, l: string) {
|
||||
return wrapper.get(`[data-letter="${l}"]`);
|
||||
}
|
||||
|
||||
describe("AlphaJumpMenu", () => {
|
||||
it("emits the picked letter", async () => {
|
||||
const wrapper = mountMenu();
|
||||
await wrapper.get(".jump-btn").trigger("click");
|
||||
|
||||
await letter(wrapper, "Z").trigger("click");
|
||||
|
||||
expect(wrapper.emitted("pick")).toEqual([["Z"]]);
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it("ignores letters with no games", async () => {
|
||||
const wrapper = mountMenu();
|
||||
await wrapper.get(".jump-btn").trigger("click");
|
||||
|
||||
await letter(wrapper, "B").trigger("click");
|
||||
|
||||
expect(wrapper.emitted("pick")).toBeUndefined();
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
// RMenu does the focusing (and tests that); this pins the order asked for,
|
||||
// so a keyboard or pad lands on the current letter, not the first one.
|
||||
it("asks the menu to open on the current letter", () => {
|
||||
const wrapper = mountMenu();
|
||||
|
||||
expect(initialFocus?.[0]).toContain("--current");
|
||||
expect(initialFocus?.[1]).toBe(".alpha-strip__btn:not(:disabled)");
|
||||
wrapper.unmount();
|
||||
});
|
||||
});
|
||||
77
frontend/src/v2/components/Gallery/AlphaJumpMenu.vue
Normal file
77
frontend/src/v2/components/Gallery/AlphaJumpMenu.vue
Normal file
@@ -0,0 +1,77 @@
|
||||
<script setup lang="ts">
|
||||
// AlphaJumpMenu: the gallery's jump-to-letter on phones and tablets, where
|
||||
// the AlphaStrip column would eat into the grid: a toolbar button that opens
|
||||
// the same letters as a grid.
|
||||
import { RBtn, RMenu } from "@v2/lib";
|
||||
import { ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import AlphaStrip from "@/v2/components/Gallery/AlphaStrip.vue";
|
||||
import { useWrapGridNav } from "@/v2/composables/useWrapGridNav";
|
||||
|
||||
interface Props {
|
||||
available: Set<string>;
|
||||
current: string;
|
||||
direction: "asc" | "desc";
|
||||
}
|
||||
|
||||
defineProps<Props>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: "pick", letter: string): void;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const LETTER_SELECTOR = ".alpha-strip__btn:not(:disabled)";
|
||||
// Opened from a keyboard or pad, start on the current letter so the arrows
|
||||
// have somewhere to move from.
|
||||
const INITIAL_FOCUS = [
|
||||
".alpha-strip__btn--current:not(:disabled)",
|
||||
LETTER_SELECTOR,
|
||||
];
|
||||
|
||||
const open = ref(false);
|
||||
const gridEl = ref<HTMLElement | null>(null);
|
||||
useWrapGridNav(gridEl, { cellSelector: LETTER_SELECTOR });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<RMenu
|
||||
v-model="open"
|
||||
location="bottom end"
|
||||
sheet-on-mobile
|
||||
:initial-focus="INITIAL_FOCUS"
|
||||
>
|
||||
<template #activator="{ props: activatorProps }">
|
||||
<RBtn
|
||||
v-bind="activatorProps"
|
||||
variant="outlined"
|
||||
surface
|
||||
:icon="true"
|
||||
rounded="circle"
|
||||
class="alpha-jump__btn"
|
||||
:aria-label="t('gallery.jump-to-letter')"
|
||||
>
|
||||
A–Z
|
||||
</RBtn>
|
||||
</template>
|
||||
<div ref="gridEl">
|
||||
<AlphaStrip
|
||||
grid
|
||||
:available="available"
|
||||
:current="current"
|
||||
:direction="direction"
|
||||
@pick="emit('pick', $event)"
|
||||
/>
|
||||
</div>
|
||||
</RMenu>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.alpha-jump__btn {
|
||||
flex: none;
|
||||
font-size: var(--r-font-size-sm);
|
||||
font-weight: var(--r-font-weight-bold);
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
</style>
|
||||
@@ -11,6 +11,9 @@
|
||||
//
|
||||
// When both are set, `visible` wins visually because it reflects the real
|
||||
// scroll position. Letters that don't fit scroll within the strip.
|
||||
//
|
||||
// `grid` lays the letters out as a wrapping grid instead of a column, for the
|
||||
// phone and tablet jump menu (AlphaJumpMenu).
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
@@ -33,6 +36,8 @@ interface Props {
|
||||
visible?: Set<string> | string[];
|
||||
/** Render order — reversed when the gallery sorts descending. */
|
||||
direction?: "asc" | "desc";
|
||||
/** Lay the letters out as a wrapping grid instead of a column. */
|
||||
grid?: boolean;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
@@ -40,6 +45,7 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
current: "",
|
||||
visible: () => new Set<string>(),
|
||||
direction: "asc",
|
||||
grid: false,
|
||||
});
|
||||
|
||||
const letters = computed(() =>
|
||||
@@ -99,6 +105,7 @@ watch(
|
||||
v-bind="$attrs"
|
||||
ref="rootEl"
|
||||
class="alpha-strip r-v2-scroll-hidden"
|
||||
:class="{ 'alpha-strip--grid': grid }"
|
||||
:aria-label="t('gallery.jump-to-letter')"
|
||||
>
|
||||
<button
|
||||
@@ -180,21 +187,20 @@ watch(
|
||||
background: color-mix(in srgb, var(--r-color-brand-primary) 12%, transparent);
|
||||
}
|
||||
|
||||
/* On phones the gallery section extends UNDER the translucent bottom tab bar
|
||||
(the glass effect), so centring the strip in the section drops the letters
|
||||
low — nearer the bottom bar than the top nav. Reserve the bar's height as
|
||||
bottom padding so the letters centre in the VISIBLE content band instead. */
|
||||
html[data-bp~="sm-and-down"] .alpha-strip {
|
||||
padding-bottom: calc(
|
||||
var(--r-space-2) + var(--r-bottom-nav-h) + env(safe-area-inset-bottom)
|
||||
);
|
||||
.alpha-strip--grid {
|
||||
width: auto;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, var(--r-touch-target));
|
||||
justify-content: center;
|
||||
gap: var(--r-space-1);
|
||||
overflow: visible;
|
||||
padding: var(--r-space-2);
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
/* Phones: the column width / edge gap come from the section vars (see
|
||||
`.alpha-strip`), which are widened on `xs`; tighter letters so fewer scroll. */
|
||||
html[data-bp~="xs"] .alpha-strip__btn {
|
||||
font-size: 11px;
|
||||
padding: 2px 0;
|
||||
margin-top: 2px;
|
||||
.alpha-strip--grid .alpha-strip__btn {
|
||||
height: var(--r-touch-target);
|
||||
margin-top: 0;
|
||||
font-size: var(--r-font-size-lg);
|
||||
border-radius: var(--r-radius-sm);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
RLetterHeading,
|
||||
RVirtualScroller,
|
||||
} from "@v2/lib";
|
||||
import { useIntersectionObserver } from "@vueuse/core";
|
||||
import { storeToRefs } from "pinia";
|
||||
import {
|
||||
computed,
|
||||
@@ -39,6 +40,7 @@ import { useI18n } from "vue-i18n";
|
||||
import { onBeforeRouteLeave, onBeforeRouteUpdate, useRoute } from "vue-router";
|
||||
import { useUISettings } from "@/composables/useUISettings";
|
||||
import storeGalleryFilter from "@/stores/galleryFilter";
|
||||
import AlphaJumpMenu from "@/v2/components/Gallery/AlphaJumpMenu.vue";
|
||||
import AlphaStrip from "@/v2/components/Gallery/AlphaStrip.vue";
|
||||
import FilterDrawer from "@/v2/components/Gallery/FilterDrawer.vue";
|
||||
import GalleryToolbar from "@/v2/components/Gallery/GalleryToolbar.vue";
|
||||
@@ -62,19 +64,24 @@ import { useGalleryFilterUrl } from "@/v2/composables/useGalleryFilterUrl";
|
||||
import { useGalleryMode } from "@/v2/composables/useGalleryMode";
|
||||
import { useGalleryOrderUrl } from "@/v2/composables/useGalleryOrderUrl";
|
||||
import { useGallerySelectAll } from "@/v2/composables/useGallerySelectAll";
|
||||
import { useGallerySelectionInput } from "@/v2/composables/useGallerySelectionInput";
|
||||
import { useGalleryViewModeUrl } from "@/v2/composables/useGalleryViewModeUrl";
|
||||
import {
|
||||
useGalleryVirtualItems,
|
||||
type GalleryItem,
|
||||
} from "@/v2/composables/useGalleryVirtualItems";
|
||||
import { useGridNav } from "@/v2/composables/useGridNav";
|
||||
import { useListExpansion } from "@/v2/composables/useListExpansion";
|
||||
import { usePinnedToolbar } from "@/v2/composables/usePinnedToolbar";
|
||||
import { useResponsiveColumns } from "@/v2/composables/useResponsiveColumns";
|
||||
import { useVirtualScrollDebug } from "@/v2/composables/useVirtualScrollDebug";
|
||||
import { useWebpSupport } from "@/v2/composables/useWebpSupport";
|
||||
import storeGalleryRoms from "@/v2/stores/galleryRoms";
|
||||
import storeGalleryRoms, {
|
||||
orderSupportsLetters,
|
||||
} from "@/v2/stores/galleryRoms";
|
||||
import storeGallerySelection from "@/v2/stores/gallerySelection";
|
||||
import storeScrollRestoration from "@/v2/stores/scrollRestoration";
|
||||
import { layout as layoutTokens, space } from "@/v2/tokens";
|
||||
|
||||
interface Props {
|
||||
/** Whether the header slot has content to render. False suppresses
|
||||
@@ -135,6 +142,7 @@ const route = useRoute();
|
||||
const galleryRoms = storeGalleryRoms();
|
||||
const galleryFilterStore = storeGalleryFilter();
|
||||
const gallerySelection = storeGallerySelection();
|
||||
const selectionInput = useGallerySelectionInput();
|
||||
const scrollRestoration = storeScrollRestoration();
|
||||
const {
|
||||
searchTerm,
|
||||
@@ -292,13 +300,23 @@ const { groupBy, layout, toolbarPosition } = useGalleryMode();
|
||||
// Responsive columns — measure the section to chunk roms into rows.
|
||||
// Card width and inset track the breakpoint so phones pack more, smaller
|
||||
// cards instead of one stretched card per row:
|
||||
// inset = scroller padding (--r-row-pad × 2) + AlphaStrip column (36)
|
||||
// → xs 14·2+36=64, sm 20·2+36=76, default 36·2+36=108
|
||||
// inset = scroller padding (--r-row-pad × 2), plus the AlphaStrip column
|
||||
// (`--r-alpha-strip-w` + its gap) wherever the strip renders
|
||||
// card = matches the `--r-card-art-w` the shell sets per breakpoint
|
||||
// (108 on xs, 158 otherwise) so the JS row-chunking and the
|
||||
// CSS grid `minmax(--r-card-art-w, 1fr)` stay in lock-step.
|
||||
const { xs, smAndDown } = useBreakpoint();
|
||||
const sectionEl = ref<HTMLElement | null>(null);
|
||||
// A jump to "M" means nothing when the gallery is sorted by size or date, so
|
||||
// the letter affordances go away with the letters themselves.
|
||||
const lettersSupported = computed(() => orderSupportsLetters(orderBy.value));
|
||||
const stripVisible = computed(() => !smAndDown.value && lettersSupported.value);
|
||||
const jumpMenuVisible = computed(
|
||||
() => smAndDown.value && lettersSupported.value,
|
||||
);
|
||||
// The strip's footprint: its letter column plus `--r-alpha-strip-gap`.
|
||||
const STRIP_INSET_PX =
|
||||
parseInt(layoutTokens.alphaStripWidth, 10) + parseInt(space[3], 10);
|
||||
// Card-art width reference (matches GameCard's `--r-card-art-w`); sets the
|
||||
// fixed card HEIGHT (a 2/3 cover at this width). Real width follows the ratio.
|
||||
const CARD_GAP_PX = 12;
|
||||
@@ -307,7 +325,9 @@ const cardHeight = () => Math.round(cardWidth() / (2 / 3));
|
||||
const { columns, usableWidth } = useResponsiveColumns(sectionEl, {
|
||||
cardWidth,
|
||||
gap: CARD_GAP_PX,
|
||||
inset: () => (xs.value ? 64 : smAndDown.value ? 76 : 108),
|
||||
inset: () =>
|
||||
(xs.value ? 28 : smAndDown.value ? 40 : 72) +
|
||||
(stripVisible.value ? STRIP_INSET_PX : 0),
|
||||
});
|
||||
|
||||
// Fallback cover ratio (boxart style) — the per-card `--r-cover-ratio` seed
|
||||
@@ -333,6 +353,20 @@ const { ratioVersion, ratioAt, onCardRatio } = useGalleryCoverRatios();
|
||||
// them. Also drives the sticky column header's width so it scrolls in step.
|
||||
const listMinWidth = computed(() => getListMinWidth(props.showPlatformColumn));
|
||||
|
||||
// Compact list rows (phones / tablets) open one detail panel at a time; the
|
||||
// virtualiser reads the same position to give that row its taller slot.
|
||||
const listExpansion = useListExpansion();
|
||||
watch(
|
||||
[
|
||||
layout,
|
||||
smAndDown,
|
||||
() => galleryRoms.total,
|
||||
() => galleryRoms.orderBy,
|
||||
() => galleryRoms.orderDir,
|
||||
],
|
||||
listExpansion.collapse,
|
||||
);
|
||||
|
||||
// 2D arrow / gamepad nav for both layouts of the gallery. Two passes:
|
||||
// * Grid mode — rows are `.r-v2-shell__row` (the per-virtualizer-item
|
||||
// wrapper around the row's GameCards). ArrowLeft/Right within a row,
|
||||
@@ -384,15 +418,51 @@ const { virtualItems, letterToIndex, availableLetters, getItemHeight } =
|
||||
gap: CARD_GAP_PX,
|
||||
ratioAt,
|
||||
ratioVersion,
|
||||
listSettledDetail: listExpansion.settledPanelHeight,
|
||||
fallbackRatio: coverAspectRatio,
|
||||
});
|
||||
|
||||
const scrollerRef = ref<InstanceType<typeof RVirtualScroller> | null>(null);
|
||||
|
||||
// Where the open row sits in the packed list. Recomputed when a row opens or
|
||||
// the list re-packs, never on the animation's frames.
|
||||
const expandedIndex = computed(() => {
|
||||
const position = listExpansion.expandedPosition.value;
|
||||
if (position == null) return -1;
|
||||
return virtualItems.value.findIndex(
|
||||
(item) => item.kind === "list-row" && item.position === position,
|
||||
);
|
||||
});
|
||||
const listOffsetShift = computed(() =>
|
||||
expandedIndex.value < 0
|
||||
? undefined
|
||||
: { fromIndex: expandedIndex.value, px: listExpansion.shiftPx.value },
|
||||
);
|
||||
|
||||
// ── Toolbar ─────────────────────────────────────────────────────────
|
||||
const scrollTopNow = computed(() => scrollerRef.value?.scrollTop ?? 0);
|
||||
const { toolbarHeight, pinDistance, pinned, bindToolbar, bindSentinel } =
|
||||
usePinnedToolbar(scrollTopNow);
|
||||
// The floating dock leaves no toolbar to pin, so a sentinel above the column
|
||||
// header marks when that header reaches the top bar.
|
||||
const listHeaderSentinel = ref<HTMLElement | null>(null);
|
||||
const listHeaderAtTop = ref(false);
|
||||
useIntersectionObserver(
|
||||
listHeaderSentinel,
|
||||
([entry]) => {
|
||||
listHeaderAtTop.value =
|
||||
!!entry?.rootBounds &&
|
||||
!entry.isIntersecting &&
|
||||
entry.boundingClientRect.top < entry.rootBounds.top;
|
||||
},
|
||||
{
|
||||
root: computed(() => scrollerRef.value?.containerEl ?? null),
|
||||
rootMargin: `-${layoutTokens.navHeight} 0px 0px 0px`,
|
||||
},
|
||||
);
|
||||
const listHeaderPinned = computed(() =>
|
||||
toolbarPosition.value === "floating" ? listHeaderAtTop.value : pinned.value,
|
||||
);
|
||||
// The AlphaStrip follows the toolbar down until it pins: a scroll-driven
|
||||
// animation (hence `timeline-scope`), else a style write on the strip alone.
|
||||
const supportsScrollTimeline =
|
||||
@@ -584,7 +654,14 @@ watch(virtualItems, () => {
|
||||
syncFetches(viewportRange.value);
|
||||
});
|
||||
|
||||
function scrollToLetter(letter: string) {
|
||||
// A jump holds its letter under the toolbar until the user scrolls again, so
|
||||
// a slow landing window still ends up anchored. The cap covers the viewer who
|
||||
// walks away mid-jump.
|
||||
const LETTER_JUMP_MAX_MS = 15000;
|
||||
const jumpLetter = ref<string | null>(null);
|
||||
let jumpDeadline = 0;
|
||||
|
||||
function anchorLetter(letter: string, smooth: boolean) {
|
||||
const idx = letterToIndex.value.get(letter);
|
||||
if (idx == null) return;
|
||||
// The section runs under the top bar, so rows land below it in either dock.
|
||||
@@ -596,13 +673,56 @@ function scrollToLetter(letter: string) {
|
||||
navHeight +
|
||||
toolbarHeight.value +
|
||||
(layout.value === "list" ? LIST_HEADER_HEIGHT_PX : 0);
|
||||
scrollerRef.value?.scrollToIndex(idx, { smooth: true, stickyOffset });
|
||||
scrollerRef.value?.scrollToIndex(idx, { smooth, stickyOffset });
|
||||
}
|
||||
|
||||
function scrollToLetter(letter: string) {
|
||||
jumpLetter.value = letter;
|
||||
jumpDeadline = Date.now() + LETTER_JUMP_MAX_MS;
|
||||
anchorLetter(letter, true);
|
||||
// The viewport-driven fetch sync handles the destination — once the
|
||||
// smooth scroll settles, `update:viewportRange` fires and the windows at
|
||||
// the landing zone start loading via `syncFetches` (both layouts). No
|
||||
// manual prefetch needed.
|
||||
}
|
||||
|
||||
/** Gives the scroll back to the user, whatever a jump was still correcting. */
|
||||
function endLetterJump() {
|
||||
jumpLetter.value = null;
|
||||
}
|
||||
|
||||
/** The letter still worth correcting towards, or null once the cap is up. */
|
||||
function pendingJumpLetter(): string | null {
|
||||
const letter = jumpLetter.value;
|
||||
if (!letter) return null;
|
||||
if (Date.now() > jumpDeadline) {
|
||||
endLetterJump();
|
||||
return null;
|
||||
}
|
||||
return letter;
|
||||
}
|
||||
|
||||
// The smooth scroll animates towards the target the jump computed; anything
|
||||
// that moved meanwhile (a re-pack, the header rendering) leaves it short, so
|
||||
// settle onto the letter once the animation stops.
|
||||
function reanchorToJump() {
|
||||
const letter = pendingJumpLetter();
|
||||
if (letter) anchorLetter(letter, false);
|
||||
}
|
||||
|
||||
// Three things move a letter out from under the toolbar after a jump: the
|
||||
// landing window arriving, the covers re-packing the rows, and the view header
|
||||
// rendering late. Re-anchor on each. Watching the packed items rather than
|
||||
// `letterToIndex` keeps that map lazy, built only when a jump needs it.
|
||||
watch(
|
||||
[
|
||||
virtualItems,
|
||||
() => scrollerRef.value?.innerOffsetTop ?? 0,
|
||||
() => galleryRoms.loadedWindows.size,
|
||||
],
|
||||
reanchorToJump,
|
||||
);
|
||||
|
||||
// ── Search filter (debounced) ───────────────────────────────────────
|
||||
const searchInput = ref(searchTerm.value ?? "");
|
||||
let searchDebounce: ReturnType<typeof setTimeout> | null = null;
|
||||
@@ -723,6 +843,9 @@ onMounted(() => {
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener("keydown", onShellKey);
|
||||
// A press still in flight would otherwise fire its timer into whatever
|
||||
// replaces this gallery.
|
||||
selectionInput.cancel();
|
||||
// Selection is gallery-scoped: leaving the shell drops it so a
|
||||
// navigation back to a non-gallery view (Home, Settings) doesn't
|
||||
// keep stale picks alive.
|
||||
@@ -794,12 +917,13 @@ defineExpose({
|
||||
:class="{
|
||||
'r-v2-shell--list': layout === 'list',
|
||||
'r-v2-shell--floating': toolbarPosition === 'floating',
|
||||
'r-v2-shell--no-strip': !stripVisible,
|
||||
}"
|
||||
:style="{
|
||||
'--r-v2-shell-toolbar-h': `${toolbarHeight}px`,
|
||||
'--r-v2-shell-pin-distance': `${pinDistance}px`,
|
||||
'--r-cover-ratio': coverAspectRatio,
|
||||
'--r-list-min-w': `${listMinWidth}px`,
|
||||
'--r-list-min-w': smAndDown ? 'auto' : `${listMinWidth}px`,
|
||||
}"
|
||||
>
|
||||
<RVirtualScroller
|
||||
@@ -807,10 +931,17 @@ defineExpose({
|
||||
:items="virtualItems"
|
||||
:get-item-height="getItemHeight"
|
||||
:get-item-key="galleryItemKey"
|
||||
:offset-shift="listOffsetShift"
|
||||
:overscan="virtualOverscan"
|
||||
:min-content-width="layout === 'list' ? listMinWidth : undefined"
|
||||
:min-content-width="
|
||||
layout === 'list' && !smAndDown ? listMinWidth : undefined
|
||||
"
|
||||
class="r-v2-shell__scroller r-v2-scroll-hidden"
|
||||
:tabindex="-1"
|
||||
@wheel.passive="endLetterJump"
|
||||
@pointerdown.passive="endLetterJump"
|
||||
@keydown="endLetterJump"
|
||||
@scrollend="reanchorToJump"
|
||||
@update:viewport-range="onViewportRangeChange"
|
||||
>
|
||||
<!-- HEADER (Section 1) + TOOLBAR (Section 2). Both live in the
|
||||
@@ -851,7 +982,17 @@ defineExpose({
|
||||
@update:sort-key="galleryRoms.setOrderBy"
|
||||
@update:search="setSearch"
|
||||
@click:filter="filterDrawerOpen = true"
|
||||
/>
|
||||
>
|
||||
<template #actions>
|
||||
<AlphaJumpMenu
|
||||
v-if="jumpMenuVisible"
|
||||
:available="availableLetters"
|
||||
:current="currentLetter"
|
||||
:direction="orderDir"
|
||||
@pick="scrollToLetter"
|
||||
/>
|
||||
</template>
|
||||
</GalleryToolbar>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -859,14 +1000,21 @@ defineExpose({
|
||||
Shares `LIST_GRID_TEMPLATE` with every GameListRow underneath
|
||||
so columns align. Header click cycles asc/desc into the
|
||||
store's orderBy/orderDir. -->
|
||||
<GameListHeader
|
||||
v-if="layout === 'list'"
|
||||
class="r-v2-shell__list-header"
|
||||
:sort-key="listSortKey"
|
||||
:sort-dir="orderDir"
|
||||
:show-platform-column="showPlatformColumn"
|
||||
@sort="onListSort"
|
||||
/>
|
||||
<template v-if="layout === 'list'">
|
||||
<div
|
||||
v-if="toolbarPosition === 'floating'"
|
||||
ref="listHeaderSentinel"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<GameListHeader
|
||||
class="r-v2-shell__list-header"
|
||||
:class="{ 'r-pinned-list-header': listHeaderPinned }"
|
||||
:sort-key="listSortKey"
|
||||
:sort-dir="orderDir"
|
||||
:show-platform-column="showPlatformColumn"
|
||||
@sort="onListSort"
|
||||
/>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<!-- GRID / TABLE (Section 3) — letter-headers + rows of cards in
|
||||
@@ -909,7 +1057,17 @@ defineExpose({
|
||||
:position="asListRow(item as GalleryItem).position"
|
||||
:webp="supportsWebp"
|
||||
:show-platform-column="showPlatformColumn"
|
||||
expandable
|
||||
:expanded="
|
||||
listExpansion.isExpanded(asListRow(item as GalleryItem).position)
|
||||
"
|
||||
:detail-height="
|
||||
listExpansion.panelHeight(asListRow(item as GalleryItem).position)
|
||||
"
|
||||
@ratio="onCardRatio"
|
||||
@toggle-expand="
|
||||
listExpansion.toggle(asListRow(item as GalleryItem).position)
|
||||
"
|
||||
/>
|
||||
|
||||
<GameListSkeletonRow
|
||||
@@ -940,8 +1098,10 @@ defineExpose({
|
||||
</template>
|
||||
</RVirtualScroller>
|
||||
|
||||
<!-- ALPHASTRIP — A-Z jump column on the right edge of the section. -->
|
||||
<!-- ALPHASTRIP: A-Z jump column on the right edge of the section.
|
||||
Phones and tablets jump from the toolbar instead (AlphaJumpMenu). -->
|
||||
<AlphaStrip
|
||||
v-if="stripVisible"
|
||||
ref="stripRef"
|
||||
class="r-v2-shell__strip"
|
||||
:available="availableLetters"
|
||||
@@ -970,7 +1130,17 @@ defineExpose({
|
||||
@update:sort-dir="galleryRoms.setOrderDir"
|
||||
@update:sort-key="galleryRoms.setOrderBy"
|
||||
@click:filter="filterDrawerOpen = true"
|
||||
/>
|
||||
>
|
||||
<template #actions>
|
||||
<AlphaJumpMenu
|
||||
v-if="jumpMenuVisible"
|
||||
:available="availableLetters"
|
||||
:current="currentLetter"
|
||||
:direction="orderDir"
|
||||
@pick="scrollToLetter"
|
||||
/>
|
||||
</template>
|
||||
</GalleryToolbar>
|
||||
|
||||
<!-- FILTER DRAWER — owned by the shell so every gallery view gets
|
||||
it for free. Forwards `showPlatformsInFilter` from the view so
|
||||
@@ -1030,10 +1200,22 @@ html[data-bp~="sm-and-down"] .r-v2-shell {
|
||||
-1 * (var(--r-bottom-nav-h) + env(safe-area-inset-bottom))
|
||||
);
|
||||
}
|
||||
/* Phones: a wider letter column (bigger, more tappable letters). */
|
||||
html[data-bp~="xs"] .r-v2-shell {
|
||||
--r-alpha-strip-w: var(--r-alpha-strip-w-xs);
|
||||
--r-alpha-strip-gap: var(--r-space-2);
|
||||
/* No strip to leave room for: phones and tablets jump from the toolbar, and
|
||||
a sort the letters can't address has no jump at all. */
|
||||
.r-v2-shell--no-strip {
|
||||
--r-v2-shell-strip: 0px;
|
||||
}
|
||||
|
||||
/* Compact list mode: the rows and their column header run to the screen
|
||||
edges, out of the scroller's gutter. Each keeps that gutter as its own
|
||||
padding, so only the separators and the row fill reach the edge. The shell
|
||||
publishes how far to bleed and the rows apply it themselves, so no row's
|
||||
class name is load-bearing in here. */
|
||||
html[data-bp~="sm-and-down"] .r-v2-shell {
|
||||
--r-list-bleed: var(--r-row-pad);
|
||||
}
|
||||
html[data-bp~="sm-and-down"] .r-v2-shell__list-header {
|
||||
margin-inline: calc(-1 * var(--r-list-bleed, 0px));
|
||||
}
|
||||
|
||||
/* The horizontal pads live here so all in-flow content (header, toolbar,
|
||||
@@ -1121,6 +1303,10 @@ html[data-bp~="xs"] .r-v2-shell {
|
||||
step with them when the list is wider than the viewport. */
|
||||
min-width: var(--r-list-min-w);
|
||||
}
|
||||
/* Its pinned glass also runs under the strip column, out to the right edge. */
|
||||
.r-v2-shell__list-header::before {
|
||||
right: calc(-1 * (var(--r-row-pad) + var(--r-v2-shell-strip)));
|
||||
}
|
||||
|
||||
/* The strip overlays the scroller's right gutter from the pinned toolbar's
|
||||
bottom edge, shifted down with the toolbar until it pins. */
|
||||
@@ -1133,6 +1319,12 @@ html[data-bp~="xs"] .r-v2-shell {
|
||||
justify-content: flex-start;
|
||||
transform: translateY(var(--r-v2-shell-strip-shift, 0px));
|
||||
}
|
||||
/* The column header's glass spans the strip column, so the letters start below it. */
|
||||
.r-v2-shell--list .r-v2-shell__strip {
|
||||
top: calc(
|
||||
var(--r-nav-h) + var(--r-v2-shell-toolbar-h) + var(--r-list-header-h)
|
||||
);
|
||||
}
|
||||
/* The floating dock sits over the strip's top; centre the letters clear of it. */
|
||||
.r-v2-shell--floating .r-v2-shell__strip {
|
||||
justify-content: safe center;
|
||||
|
||||
@@ -27,6 +27,10 @@ defineSlots<{
|
||||
.gallery-tab-shell {
|
||||
padding: 32px var(--r-row-pad) 24px;
|
||||
}
|
||||
/* GalleryShell's phone header gap, so the head holds still across tabs. */
|
||||
html[data-bp~="xs"] .gallery-tab-shell {
|
||||
padding-top: 16px;
|
||||
}
|
||||
|
||||
.gallery-tab-shell__divider {
|
||||
margin: 0 0 24px;
|
||||
|
||||
@@ -132,19 +132,18 @@ describe("GalleryToolbar sort axis", () => {
|
||||
});
|
||||
|
||||
// List mode sorts through the column headers, so the toolbar's axis
|
||||
// button has to stand down rather than offer a second, competing control.
|
||||
it("disables the activator in list mode only", () => {
|
||||
const activatorDisabled = (layout: string) => {
|
||||
const wrapper = mountWithSortOptions({ layout });
|
||||
const disabled = wrapper
|
||||
.findComponent(RMenuPassthrough)
|
||||
.findComponent({ name: "RBtn" })
|
||||
.attributes("disabled");
|
||||
wrapper.unmount();
|
||||
return disabled;
|
||||
};
|
||||
// control steps aside rather than offer a second, competing one.
|
||||
it("drops the control in list mode only", () => {
|
||||
const grid = mountWithSortOptions({ layout: "grid" });
|
||||
const menusInGrid = grid.findAllComponents(RMenuPassthrough).length;
|
||||
grid.unmount();
|
||||
|
||||
expect(activatorDisabled("list")).toBe("true");
|
||||
expect(activatorDisabled("grid")).toBe("false");
|
||||
const wrapper = mountWithSortOptions({ layout: "list" });
|
||||
|
||||
expect(wrapper.findAllComponents(RMenuPassthrough)).toHaveLength(
|
||||
menusInGrid - 1,
|
||||
);
|
||||
expect(sortItems(wrapper)).toHaveLength(0);
|
||||
wrapper.unmount();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -132,6 +132,11 @@ const emit = defineEmits<{
|
||||
(e: "click:filter"): void;
|
||||
}>();
|
||||
|
||||
defineSlots<{
|
||||
/** Extra controls right after the filter button. */
|
||||
actions?(): unknown;
|
||||
}>();
|
||||
|
||||
// Support both a Ref or a plain value — keeps consumption flexible.
|
||||
function toValue<T>(source: Ref<T> | T): T {
|
||||
return source && typeof source === "object" && "value" in (source as object)
|
||||
@@ -143,6 +148,9 @@ const groupByValue = computed(() => toValue(props.groupBy));
|
||||
const layoutValue = computed(() => toValue(props.layout));
|
||||
const sortDirValue = computed(() => toValue(props.sortDir));
|
||||
const sortKeyValue = computed(() => toValue(props.sortKey));
|
||||
// List mode sorts from its own column header, so the toolbar's sort and
|
||||
// grouping controls step aside rather than sit there inert.
|
||||
const listMode = computed(() => layoutValue.value === "list");
|
||||
|
||||
const layoutItems = computed(() => [
|
||||
{
|
||||
@@ -289,6 +297,8 @@ const { smAndUp } = useBreakpoint();
|
||||
/>
|
||||
</RBadge>
|
||||
|
||||
<slot name="actions" />
|
||||
|
||||
<template v-if="smAndUp">
|
||||
<RSliderBtnGroup
|
||||
v-for="sf in segmentFilters"
|
||||
@@ -307,53 +317,52 @@ const { smAndUp } = useBreakpoint();
|
||||
they collapse into the kebab menu so the toolbar fits on phones
|
||||
without overflowing. -->
|
||||
<div class="gallery-toolbar__controls">
|
||||
<RSliderBtnGroup
|
||||
v-if="smAndUp && showGroupBy"
|
||||
:model-value="groupByValue"
|
||||
:items="effectiveGroupByItems"
|
||||
variant="segmented"
|
||||
:aria-label="t('settings.platforms-drawer-group-by')"
|
||||
:disabled="layoutValue === 'list'"
|
||||
@update:model-value="setGroupBy"
|
||||
/>
|
||||
|
||||
<!-- A menu, not a slider: too many axes for the segmented pattern
|
||||
the neighbouring clusters use. -->
|
||||
<RMenu
|
||||
v-if="smAndUp && sortKeyItems.length > 0"
|
||||
location="bottom end"
|
||||
:offset="8"
|
||||
width="220px"
|
||||
>
|
||||
<template #activator="{ props: activatorProps }">
|
||||
<RBtn
|
||||
v-bind="activatorProps"
|
||||
variant="outlined"
|
||||
surface
|
||||
icon="mdi-sort"
|
||||
rounded="circle"
|
||||
:disabled="layoutValue === 'list'"
|
||||
:aria-label="t('gallery.sort-by')"
|
||||
/>
|
||||
</template>
|
||||
<RMenuItem
|
||||
v-for="item in sortKeyItems"
|
||||
:key="item.key"
|
||||
:label="item.label"
|
||||
:variant="sortKeyValue === item.key ? 'active' : 'default'"
|
||||
@click="setSortKey(item.key)"
|
||||
<!-- Grouping and sort: list mode sorts from its column header instead. -->
|
||||
<template v-if="smAndUp && !listMode">
|
||||
<RSliderBtnGroup
|
||||
v-if="showGroupBy"
|
||||
:model-value="groupByValue"
|
||||
:items="effectiveGroupByItems"
|
||||
variant="segmented"
|
||||
:aria-label="t('settings.platforms-drawer-group-by')"
|
||||
@update:model-value="setGroupBy"
|
||||
/>
|
||||
</RMenu>
|
||||
|
||||
<RSliderBtnGroup
|
||||
v-if="smAndUp"
|
||||
:model-value="sortDirValue"
|
||||
:items="sortDirItems"
|
||||
variant="segmented"
|
||||
:aria-label="t('gallery.sort-ascending')"
|
||||
:disabled="layoutValue === 'list'"
|
||||
@update:model-value="setSortDir"
|
||||
/>
|
||||
<!-- A menu, not a slider: too many axes for the segmented pattern
|
||||
the neighbouring clusters use. -->
|
||||
<RMenu
|
||||
v-if="sortKeyItems.length > 0"
|
||||
location="bottom end"
|
||||
:offset="8"
|
||||
width="220px"
|
||||
>
|
||||
<template #activator="{ props: activatorProps }">
|
||||
<RBtn
|
||||
v-bind="activatorProps"
|
||||
variant="outlined"
|
||||
surface
|
||||
icon="mdi-sort"
|
||||
rounded="circle"
|
||||
:aria-label="t('gallery.sort-by')"
|
||||
/>
|
||||
</template>
|
||||
<RMenuItem
|
||||
v-for="item in sortKeyItems"
|
||||
:key="item.key"
|
||||
:label="item.label"
|
||||
:variant="sortKeyValue === item.key ? 'active' : 'default'"
|
||||
@click="setSortKey(item.key)"
|
||||
/>
|
||||
</RMenu>
|
||||
|
||||
<RSliderBtnGroup
|
||||
:model-value="sortDirValue"
|
||||
:items="sortDirItems"
|
||||
variant="segmented"
|
||||
:aria-label="t('gallery.sort-ascending')"
|
||||
@update:model-value="setSortDir"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<RSliderBtnGroup
|
||||
v-if="smAndUp"
|
||||
@@ -364,9 +373,8 @@ const { smAndUp } = useBreakpoint();
|
||||
@update:model-value="setLayout"
|
||||
/>
|
||||
|
||||
<!-- Kebab mirror — only visible below smAndUp. Mirrors the slider
|
||||
state: `groupBy` items disable in list mode, same way the
|
||||
inline GroupBy slider does. -->
|
||||
<!-- Kebab mirror, only visible below smAndUp, carrying the same
|
||||
clusters the inline sliders do. -->
|
||||
<RMenu
|
||||
v-if="!smAndUp"
|
||||
location="bottom end"
|
||||
@@ -396,44 +404,42 @@ const { smAndUp } = useBreakpoint();
|
||||
/>
|
||||
<RDivider />
|
||||
</template>
|
||||
<template v-if="showGroupBy && effectiveGroupByItems.length > 0">
|
||||
<template
|
||||
v-if="showGroupBy && effectiveGroupByItems.length > 0 && !listMode"
|
||||
>
|
||||
<RMenuItem
|
||||
v-for="item in effectiveGroupByItems"
|
||||
:key="item.id"
|
||||
:label="item.label ?? item.title ?? item.ariaLabel ?? item.id"
|
||||
:icon="item.icon"
|
||||
:variant="groupByValue === item.id ? 'active' : 'default'"
|
||||
:disabled="layoutValue === 'list'"
|
||||
@click="setGroupBy(item.id)"
|
||||
/>
|
||||
<RDivider />
|
||||
</template>
|
||||
<template v-if="sortKeyItems.length > 0">
|
||||
<template v-if="!listMode">
|
||||
<RMenuItem
|
||||
v-for="item in sortKeyItems"
|
||||
:key="item.key"
|
||||
:label="item.label"
|
||||
:variant="sortKeyValue === item.key ? 'active' : 'default'"
|
||||
:disabled="layoutValue === 'list'"
|
||||
@click="setSortKey(item.key)"
|
||||
/>
|
||||
<RDivider v-if="sortKeyItems.length > 0" />
|
||||
<RMenuItem
|
||||
:label="t('gallery.sort-ascending')"
|
||||
icon="mdi-sort-ascending"
|
||||
:variant="sortDirValue === 'asc' ? 'active' : 'default'"
|
||||
@click="setSortDir('asc')"
|
||||
/>
|
||||
<RMenuItem
|
||||
:label="t('gallery.sort-descending')"
|
||||
icon="mdi-sort-descending"
|
||||
:variant="sortDirValue === 'desc' ? 'active' : 'default'"
|
||||
@click="setSortDir('desc')"
|
||||
/>
|
||||
<RDivider />
|
||||
</template>
|
||||
<RMenuItem
|
||||
:label="t('gallery.sort-ascending')"
|
||||
icon="mdi-sort-ascending"
|
||||
:variant="sortDirValue === 'asc' ? 'active' : 'default'"
|
||||
:disabled="layoutValue === 'list'"
|
||||
@click="setSortDir('asc')"
|
||||
/>
|
||||
<RMenuItem
|
||||
:label="t('gallery.sort-descending')"
|
||||
icon="mdi-sort-descending"
|
||||
:variant="sortDirValue === 'desc' ? 'active' : 'default'"
|
||||
:disabled="layoutValue === 'list'"
|
||||
@click="setSortDir('desc')"
|
||||
/>
|
||||
<RDivider />
|
||||
<RMenuItem
|
||||
:label="t('gallery.view-grid')"
|
||||
icon="mdi-view-grid-outline"
|
||||
|
||||
@@ -12,10 +12,13 @@
|
||||
import { RCheckbox, RIcon } from "@v2/lib";
|
||||
import { computed } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import ListSortMenu from "@/v2/components/shared/ListSortMenu.vue";
|
||||
import { useBreakpoint } from "@/v2/composables/useBreakpoint";
|
||||
import { useGallerySelectAll } from "@/v2/composables/useGallerySelectAll";
|
||||
import storeGallerySelection from "@/v2/stores/gallerySelection";
|
||||
import {
|
||||
getListColumns,
|
||||
getSortOptions,
|
||||
isSortableColumn,
|
||||
getListGridTemplate,
|
||||
type ListColumn,
|
||||
@@ -49,6 +52,11 @@ const gridStyle = computed(() => ({
|
||||
gridTemplateColumns: getListGridTemplate(props.showPlatformColumn),
|
||||
}));
|
||||
|
||||
// Phones and tablets drop the columns (the rows go compact), so the sort
|
||||
// key they used to carry moves into a menu on the header.
|
||||
const { smAndDown } = useBreakpoint();
|
||||
const sortOptions = computed(() => getSortOptions(props.showPlatformColumn));
|
||||
|
||||
const selection = storeGallerySelection();
|
||||
// Whole-result select-all shared with the SelectionBar and Ctrl/Cmd+A;
|
||||
// `selectionState` drives the tri-state checkbox glyph.
|
||||
@@ -68,9 +76,8 @@ function onSelectAllClick(e: MouseEvent) {
|
||||
|
||||
function handleClick(col: ListColumn) {
|
||||
if (!isSortableColumn(col)) return;
|
||||
// Toggle direction when re-clicking the active column; otherwise
|
||||
// start the new column at ascending — consistent behaviour with
|
||||
// every other sortable table in the app.
|
||||
// Toggle direction when re-clicking the active column; otherwise start the
|
||||
// new one ascending, like every other sortable table in the app.
|
||||
const nextDir: "asc" | "desc" =
|
||||
props.sortKey === col.key && props.sortDir === "asc" ? "desc" : "asc";
|
||||
emit("sort", { key: col.key, dir: nextDir });
|
||||
@@ -78,7 +85,37 @@ function handleClick(col: ListColumn) {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="game-list-header" :style="gridStyle" role="row">
|
||||
<div
|
||||
v-if="smAndDown"
|
||||
class="game-list-header game-list-header--compact"
|
||||
role="row"
|
||||
>
|
||||
<RCheckbox
|
||||
class="game-list-header__check"
|
||||
:model-value="selectionState === 'all'"
|
||||
:indeterminate="selectionState === 'some'"
|
||||
shape="circle"
|
||||
size="sm"
|
||||
color="primary"
|
||||
bare
|
||||
hide-details
|
||||
:aria-label="
|
||||
selectionState === 'all'
|
||||
? t('gallery.selection-deselect-all')
|
||||
: t('gallery.selection-select-all')
|
||||
"
|
||||
@click="onSelectAllClick"
|
||||
/>
|
||||
|
||||
<ListSortMenu
|
||||
:options="sortOptions"
|
||||
:sort-key="sortKey"
|
||||
:sort-dir="sortDir"
|
||||
@sort="emit('sort', $event)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-else class="game-list-header" :style="gridStyle" role="row">
|
||||
<template v-for="col in columns" :key="String(col.key)">
|
||||
<!-- Tri-state select-all checkbox (off → some → all), judged
|
||||
against the whole filtered result. -->
|
||||
@@ -141,10 +178,20 @@ function handleClick(col: ListColumn) {
|
||||
gap: 0 var(--r-space-5);
|
||||
padding: 0 var(--r-space-3);
|
||||
height: var(--r-list-header-h);
|
||||
background: var(--r-color-bg-elevated);
|
||||
border-bottom: 1px solid var(--r-color-border);
|
||||
/* Glass so rows scrolling under the pinned header read soft behind it. */
|
||||
backdrop-filter: blur(10px);
|
||||
/* Overridable so a pinned header can run it edge to edge (r-pinned-list-header). */
|
||||
border-bottom: var(--r-list-header-border, 1px solid var(--r-color-border));
|
||||
}
|
||||
|
||||
/* Compact (phones / tablets): the tick plus one sort control. */
|
||||
.game-list-header--compact {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--r-space-3);
|
||||
padding: 0 var(--r-row-pad);
|
||||
}
|
||||
.game-list-header--compact .game-list-header__check {
|
||||
flex: none;
|
||||
width: var(--r-list-select-w);
|
||||
}
|
||||
|
||||
.game-list-header__cell {
|
||||
|
||||
@@ -15,21 +15,27 @@
|
||||
import {
|
||||
RCheckbox,
|
||||
RChip,
|
||||
RIcon,
|
||||
RMarquee,
|
||||
RPlatformIcon,
|
||||
RSkeletonBlock,
|
||||
RTooltip,
|
||||
} from "@v2/lib";
|
||||
import { formatPlaytime, formatReleaseDate } from "@v2/utils/time";
|
||||
import { computed } from "vue";
|
||||
import { formatPlaytime, formatReleaseDate, releaseYear } from "@v2/utils/time";
|
||||
import { computed, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useRouter } from "vue-router";
|
||||
import storeCollections from "@/stores/collections";
|
||||
import storePlatforms from "@/stores/platforms";
|
||||
import { formatBytes, toBrowserLocale } from "@/utils";
|
||||
import ProviderBadges from "@/v2/components/Gallery/ProviderBadges.vue";
|
||||
import GameActionBtn from "@/v2/components/GameActions/GameActionBtn.vue";
|
||||
import GameCard from "@/v2/components/GameCard/GameCard.vue";
|
||||
import SiblingBadge from "@/v2/components/GameCard/SiblingBadge.vue";
|
||||
import { useBackgroundArt } from "@/v2/composables/useBackgroundArt";
|
||||
import { useBreakpoint } from "@/v2/composables/useBreakpoint";
|
||||
import { useGallerySelectionInput } from "@/v2/composables/useGallerySelectionInput";
|
||||
import { useStaggeredEntrance } from "@/v2/composables/useStaggeredEntrance";
|
||||
import { useViewTransition } from "@/v2/composables/useViewTransition";
|
||||
import { toWebpUrl } from "@/v2/composables/useWebpSupport";
|
||||
import storeGalleryRoms, { type SimpleRom } from "@/v2/stores/galleryRoms";
|
||||
@@ -69,6 +75,13 @@ interface Props {
|
||||
/** Include the `platform` column. Mirrors `GameListHeader` so the row
|
||||
* stays aligned with the column header above it. */
|
||||
showPlatformColumn?: boolean;
|
||||
/** Offer the chevron that opens the detail panel (phones and tablets).
|
||||
* Only for surfaces whose virtualiser reserves the taller row. */
|
||||
expandable?: boolean;
|
||||
/** Whether this row's detail panel is open. */
|
||||
expanded?: boolean;
|
||||
/** Px of that panel currently showing; it rolls open and shut. */
|
||||
detailHeight?: number;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
@@ -76,12 +89,17 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
rom: undefined,
|
||||
webp: false,
|
||||
showPlatformColumn: true,
|
||||
expandable: false,
|
||||
expanded: false,
|
||||
detailHeight: 0,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** Forwards the cover's measured natural ratio so the shell's flow-packer
|
||||
* can pack the grid by true cover shape. */
|
||||
(e: "ratio", payload: { romId: number; ratio: number }): void;
|
||||
/** Chevron pressed; the parent owns which row is open. */
|
||||
(e: "toggle-expand"): void;
|
||||
}>();
|
||||
|
||||
const router = useRouter();
|
||||
@@ -89,6 +107,7 @@ const galleryRoms = storeGalleryRoms();
|
||||
const selection = storeGallerySelection();
|
||||
const selectionInput = useGallerySelectionInput();
|
||||
const platformsStore = storePlatforms();
|
||||
const collectionsStore = storeCollections();
|
||||
const { morphTransition } = useViewTransition();
|
||||
const setBgArt = useBackgroundArt();
|
||||
const { locale, t } = useI18n();
|
||||
@@ -126,6 +145,22 @@ const gridStyle = computed(() => ({
|
||||
}));
|
||||
const titleSkeletonGapStyle = { gap: `${LIST_TITLE_SKELETON_GAP_PX}px` };
|
||||
|
||||
/** The panel's fields after the file name, in the order it lays them out:
|
||||
* the size beside the name, then two rows of three. */
|
||||
const detailFields = computed(() => {
|
||||
const item = rom.value;
|
||||
if (!item) return [];
|
||||
return [
|
||||
{ label: labelOf("fs_size_bytes"), value: formatBytes(item.fs_size_bytes) },
|
||||
{ label: labelOf("created_at"), value: formatDate(item.created_at) },
|
||||
{ label: labelOf("first_release_date"), value: releaseDate(item) },
|
||||
{ label: labelOf("hltb_main_story"), value: lengthValue(item) },
|
||||
{ label: labelOf("average_rating"), value: ratingValue(item) },
|
||||
{ label: labelOf("languages"), value: listValue(item.languages) },
|
||||
{ label: labelOf("regions"), value: listValue(item.regions) },
|
||||
];
|
||||
});
|
||||
|
||||
/** Alignment / figure modifiers for a cell, read off the column config so
|
||||
* the body cannot drift from the header above it. */
|
||||
function cellModifiers(key: ListColumn["key"]) {
|
||||
@@ -136,6 +171,41 @@ function cellModifiers(key: ListColumn["key"]) {
|
||||
};
|
||||
}
|
||||
|
||||
// Phones and tablets have no room for the columns: the row collapses to a
|
||||
// title plus the facts line, and the rest moves into the detail panel.
|
||||
const { smAndDown } = useBreakpoint();
|
||||
|
||||
const rowEl = ref<HTMLElement | null>(null);
|
||||
const { entranceClass, entranceStyle, endEntrance } = useStaggeredEntrance(
|
||||
rowEl,
|
||||
() => rom.value != null,
|
||||
);
|
||||
|
||||
/** Column header label, so the detail panel's captions and the desktop
|
||||
* column titles can't drift apart. */
|
||||
function labelOf(key: ListColumn["key"]): string {
|
||||
return columns.value.find((col) => col.key === key)?.label ?? "";
|
||||
}
|
||||
|
||||
function listValue(values: string[] | null | undefined): string {
|
||||
return values && values.length > 0 ? values.join(", ") : "—";
|
||||
}
|
||||
|
||||
/** Leads the facts line wherever the list mixes platforms. */
|
||||
const platformName = computed(() => {
|
||||
const item = rom.value;
|
||||
if (!item || !props.showPlatformColumn) return null;
|
||||
return item.platform_custom_name || item.platform_display_name;
|
||||
});
|
||||
|
||||
const year = computed(() =>
|
||||
releaseYear(rom.value?.metadatum?.first_release_date),
|
||||
);
|
||||
|
||||
const isFavorited = computed(() =>
|
||||
rom.value ? collectionsStore.isFavorite(rom.value) : false,
|
||||
);
|
||||
|
||||
const platformMeta = computed(() => {
|
||||
const item = rom.value;
|
||||
if (!item || item.platform_id == null) return null;
|
||||
@@ -251,26 +321,26 @@ function onRowHighlight() {
|
||||
function onRowPointerDown(e: PointerEvent) {
|
||||
const item = rom.value;
|
||||
if (!item || isStatic.value || props.position === undefined) return;
|
||||
// Reading the open panel is not a press on the row.
|
||||
if ((e.target as Element | null)?.closest(".game-list-row__detail")) return;
|
||||
selectionInput.handlePointerDown(item, props.position, e);
|
||||
}
|
||||
function onRowPointerMove(e: PointerEvent) {
|
||||
if (isStatic.value) return;
|
||||
selectionInput.handlePointerMove(e);
|
||||
}
|
||||
function onRowPointerEnd() {
|
||||
if (isStatic.value) return;
|
||||
selectionInput.handlePointerEnd();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<a
|
||||
ref="rowEl"
|
||||
class="game-list-row"
|
||||
:class="{
|
||||
'game-list-row--clickable': !!rom,
|
||||
'game-list-row--selected': isSelected,
|
||||
}"
|
||||
:style="gridStyle"
|
||||
:class="[
|
||||
{
|
||||
'game-list-row--columns': !smAndDown,
|
||||
'game-list-row--clickable': !!rom,
|
||||
'game-list-row--selected': isSelected,
|
||||
'game-list-row--expanded': expanded,
|
||||
},
|
||||
entranceClass,
|
||||
]"
|
||||
:style="[smAndDown ? undefined : gridStyle, entranceStyle]"
|
||||
:href="rom ? `/rom/${rom.id}` : undefined"
|
||||
:aria-label="
|
||||
rom
|
||||
@@ -284,252 +354,404 @@ function onRowPointerEnd() {
|
||||
@mouseenter="onRowHighlight"
|
||||
@focus="onRowHighlight"
|
||||
@pointerdown="onRowPointerDown"
|
||||
@pointermove="onRowPointerMove"
|
||||
@pointerup="onRowPointerEnd"
|
||||
@pointercancel="onRowPointerEnd"
|
||||
@contextmenu="selectionInput.handleContextMenu"
|
||||
@animationend.self="endEntrance"
|
||||
>
|
||||
<template v-if="rom">
|
||||
<!-- Selection cell — leftmost column. Click toggles this row;
|
||||
shift-click extends the range from the last toggled position.
|
||||
Hidden at rest; reveals on row hover / focus or whenever the
|
||||
row is selected so the user always knows which rows are
|
||||
picked. RCheckbox provides the box / fill / draw animations
|
||||
— same animation language as the GameCard checkbox in grid
|
||||
mode. -->
|
||||
<div class="game-list-row__cell game-list-row__select">
|
||||
<RCheckbox
|
||||
v-if="!isStatic"
|
||||
class="game-list-row__check"
|
||||
:model-value="isSelected"
|
||||
shape="circle"
|
||||
size="sm"
|
||||
color="primary"
|
||||
bare
|
||||
hide-details
|
||||
tabindex="-1"
|
||||
@click="onCheckboxClick"
|
||||
/>
|
||||
</div>
|
||||
<!-- COMPACT (phones / tablets): two lines plus the chevron; the
|
||||
columns move into the detail panel below. -->
|
||||
<template v-if="smAndDown">
|
||||
<div class="game-list-row__compact r-list-compact">
|
||||
<div class="game-list-row__select">
|
||||
<RCheckbox
|
||||
v-if="!isStatic"
|
||||
class="game-list-row__check"
|
||||
:model-value="isSelected"
|
||||
shape="circle"
|
||||
size="sm"
|
||||
color="primary"
|
||||
bare
|
||||
hide-details
|
||||
tabindex="-1"
|
||||
@click="onCheckboxClick"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="game-list-row__cell game-list-row__cover">
|
||||
<GameCard
|
||||
:rom="rom"
|
||||
size="xs"
|
||||
:webp="webp"
|
||||
decorative
|
||||
:show-title="false"
|
||||
:show-platform-icon="false"
|
||||
@ratio="emit('ratio', $event)"
|
||||
/>
|
||||
</div>
|
||||
<div class="game-list-row__cover">
|
||||
<GameCard
|
||||
:rom="rom"
|
||||
size="xs"
|
||||
:webp="webp"
|
||||
decorative
|
||||
:show-title="false"
|
||||
:show-platform-icon="showPlatformColumn"
|
||||
@ratio="emit('ratio', $event)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="game-list-row__cell game-list-row__title">
|
||||
<div class="game-list-row__meta">
|
||||
<div class="game-list-row__name-row">
|
||||
<div class="r-list-compact__stack">
|
||||
<div class="game-list-row__name">
|
||||
{{ rom.name ?? rom.fs_name_no_ext }}
|
||||
</div>
|
||||
<div class="r-list-compact__facts">
|
||||
<template v-if="platformName">
|
||||
<RPlatformIcon
|
||||
class="game-list-row__facts-icon"
|
||||
:slug="rom.platform_slug"
|
||||
:fs-slug="rom.platform_fs_slug"
|
||||
:alt="platformName"
|
||||
:size="14"
|
||||
:show-tooltip="false"
|
||||
/>
|
||||
<span>{{ platformName }}</span>
|
||||
</template>
|
||||
<span v-if="platformName && year" class="r-list-compact__dot"
|
||||
>·</span
|
||||
>
|
||||
<span v-if="year">{{ year }}</span>
|
||||
<template v-if="isFavorited">
|
||||
<span v-if="platformName || year" class="r-list-compact__dot"
|
||||
>·</span
|
||||
>
|
||||
<RIcon
|
||||
icon="mdi-heart"
|
||||
size="11"
|
||||
class="game-list-row__fav"
|
||||
:aria-label="t('rom.favorite')"
|
||||
/>
|
||||
</template>
|
||||
</div>
|
||||
<div class="game-list-row__badges" @click.stop>
|
||||
<GameActionBtn
|
||||
v-if="hasStatus"
|
||||
:rom="rom"
|
||||
action="status"
|
||||
size="x-small"
|
||||
variant="surface"
|
||||
orientation="horizontal"
|
||||
/>
|
||||
<SiblingBadge :rom="rom" orientation="horizontal" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="game-list-row__filename">{{ rom.fs_name }}</div>
|
||||
<div
|
||||
v-if="providers.length > 0"
|
||||
class="game-list-row__providers"
|
||||
@click.stop
|
||||
>
|
||||
<span
|
||||
v-for="provider in providers"
|
||||
:key="provider.key"
|
||||
class="game-list-row__provider"
|
||||
:style="provider.bg ? { background: provider.bg } : undefined"
|
||||
|
||||
<div class="game-list-row__actions" @click.stop>
|
||||
<GameActionBtn
|
||||
:rom="rom"
|
||||
action="more"
|
||||
size="small"
|
||||
variant="bare"
|
||||
/>
|
||||
<button
|
||||
v-if="expandable"
|
||||
type="button"
|
||||
class="game-list-row__chevron"
|
||||
:class="{ 'game-list-row__chevron--open': expanded }"
|
||||
:aria-expanded="expanded"
|
||||
:aria-label="t('common.details')"
|
||||
@click.stop.prevent="emit('toggle-expand')"
|
||||
>
|
||||
<img
|
||||
:src="`/assets/scrappers/${provider.logo}`"
|
||||
:alt="provider.title"
|
||||
width="14"
|
||||
height="14"
|
||||
/>
|
||||
<RTooltip
|
||||
activator="parent"
|
||||
:text="provider.title"
|
||||
location="top"
|
||||
/>
|
||||
</span>
|
||||
<RIcon icon="mdi-chevron-down" size="18" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="showPlatformColumn"
|
||||
class="game-list-row__cell game-list-row__platform"
|
||||
>
|
||||
<RPlatformIcon
|
||||
v-if="platformMeta?.slug"
|
||||
:slug="platformMeta.slug"
|
||||
:size="24"
|
||||
/>
|
||||
<span class="game-list-row__platform-name">
|
||||
{{ platformMeta?.name ?? "—" }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="game-list-row__cell" :class="cellModifiers('fs_size_bytes')">
|
||||
{{ rom.fs_size_bytes ? formatBytes(rom.fs_size_bytes) : "—" }}
|
||||
</div>
|
||||
<div class="game-list-row__cell" :class="cellModifiers('created_at')">
|
||||
{{ formatDate(rom.created_at) }}
|
||||
</div>
|
||||
<div
|
||||
class="game-list-row__cell"
|
||||
:class="cellModifiers('first_release_date')"
|
||||
>
|
||||
{{ releaseDate(rom) }}
|
||||
</div>
|
||||
<div class="game-list-row__cell" :class="cellModifiers('average_rating')">
|
||||
{{ ratingValue(rom) }}
|
||||
</div>
|
||||
<div
|
||||
class="game-list-row__cell"
|
||||
:class="cellModifiers('hltb_main_story')"
|
||||
>
|
||||
{{ lengthValue(rom) }}
|
||||
</div>
|
||||
|
||||
<div class="game-list-row__cell game-list-row__cell--pills">
|
||||
<div class="game-list-row__pills">
|
||||
<RChip
|
||||
v-for="l in (rom.languages ?? []).slice(0, PILLS_VISIBLE)"
|
||||
:key="`lang-${l}`"
|
||||
size="x-small"
|
||||
variant="translucent"
|
||||
>
|
||||
{{ l }}
|
||||
</RChip>
|
||||
<RChip
|
||||
v-if="(rom.languages?.length ?? 0) > PILLS_VISIBLE"
|
||||
size="x-small"
|
||||
variant="translucent"
|
||||
>
|
||||
+{{ (rom.languages?.length ?? 0) - PILLS_VISIBLE }}
|
||||
</RChip>
|
||||
<div
|
||||
v-if="expanded"
|
||||
class="game-list-row__detail"
|
||||
:style="{ height: `${detailHeight}px` }"
|
||||
@click.stop
|
||||
>
|
||||
<div class="game-list-row__detail-inner">
|
||||
<div class="game-list-row__field game-list-row__field--filename">
|
||||
<span class="game-list-row__field-label">{{
|
||||
t("rom.filename")
|
||||
}}</span>
|
||||
<RMarquee class="game-list-row__field-value">{{
|
||||
rom.fs_name
|
||||
}}</RMarquee>
|
||||
</div>
|
||||
<div
|
||||
v-for="field in detailFields"
|
||||
:key="field.label"
|
||||
class="game-list-row__field"
|
||||
>
|
||||
<span class="game-list-row__field-label">{{ field.label }}</span>
|
||||
<span class="game-list-row__field-value">{{ field.value }}</span>
|
||||
</div>
|
||||
<div class="game-list-row__field game-list-row__field--wide">
|
||||
<span class="game-list-row__field-label">{{
|
||||
t("scan.metadata-sources")
|
||||
}}</span>
|
||||
<ProviderBadges
|
||||
v-if="providers.length > 0"
|
||||
:providers="providers"
|
||||
/>
|
||||
<span v-else class="game-list-row__field-value">—</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<RTooltip
|
||||
v-if="(rom.languages?.length ?? 0) > PILLS_VISIBLE"
|
||||
activator="parent"
|
||||
:text="rom.languages?.join(', ')"
|
||||
location="top"
|
||||
/>
|
||||
</div>
|
||||
<div class="game-list-row__cell game-list-row__cell--pills">
|
||||
<div class="game-list-row__pills">
|
||||
<RChip
|
||||
v-for="r in (rom.regions ?? []).slice(0, PILLS_VISIBLE)"
|
||||
:key="`reg-${r}`"
|
||||
size="x-small"
|
||||
variant="translucent"
|
||||
>
|
||||
{{ r }}
|
||||
</RChip>
|
||||
<RChip
|
||||
v-if="(rom.regions?.length ?? 0) > PILLS_VISIBLE"
|
||||
size="x-small"
|
||||
variant="translucent"
|
||||
>
|
||||
+{{ (rom.regions?.length ?? 0) - PILLS_VISIBLE }}
|
||||
</RChip>
|
||||
</div>
|
||||
<RTooltip
|
||||
v-if="(rom.regions?.length ?? 0) > PILLS_VISIBLE"
|
||||
activator="parent"
|
||||
:text="rom.regions?.join(', ')"
|
||||
location="top"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="game-list-row__cell" :class="cellModifiers('actions')">
|
||||
<div class="game-list-row__actions" @click.stop>
|
||||
<GameActionBtn
|
||||
:rom="rom"
|
||||
action="favorite"
|
||||
size="small"
|
||||
variant="bare"
|
||||
<template v-else>
|
||||
<!-- Selection cell, leftmost column. Click toggles this row;
|
||||
shift-click extends the range from the last toggled position.
|
||||
Hidden at rest; reveals on row hover / focus or whenever the
|
||||
row is selected so the user always knows which rows are
|
||||
picked. RCheckbox provides the box / fill / draw animations
|
||||
(same animation language as the GameCard checkbox in grid
|
||||
mode). -->
|
||||
<div class="game-list-row__cell game-list-row__select">
|
||||
<RCheckbox
|
||||
v-if="!isStatic"
|
||||
class="game-list-row__check"
|
||||
:model-value="isSelected"
|
||||
shape="circle"
|
||||
size="sm"
|
||||
color="primary"
|
||||
bare
|
||||
hide-details
|
||||
tabindex="-1"
|
||||
@click="onCheckboxClick"
|
||||
/>
|
||||
<GameActionBtn :rom="rom" action="more" size="small" variant="bare" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="game-list-row__cell game-list-row__cover">
|
||||
<GameCard
|
||||
:rom="rom"
|
||||
size="xs"
|
||||
:webp="webp"
|
||||
decorative
|
||||
:show-title="false"
|
||||
:show-platform-icon="false"
|
||||
@ratio="emit('ratio', $event)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="game-list-row__cell game-list-row__title">
|
||||
<div class="game-list-row__meta">
|
||||
<div class="game-list-row__name-row">
|
||||
<div class="game-list-row__name">
|
||||
{{ rom.name ?? rom.fs_name_no_ext }}
|
||||
</div>
|
||||
<div class="game-list-row__badges" @click.stop>
|
||||
<GameActionBtn
|
||||
v-if="hasStatus"
|
||||
:rom="rom"
|
||||
action="status"
|
||||
size="x-small"
|
||||
orientation="horizontal"
|
||||
/>
|
||||
<SiblingBadge :rom="rom" orientation="horizontal" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="game-list-row__filename">{{ rom.fs_name }}</div>
|
||||
<ProviderBadges
|
||||
v-if="providers.length > 0"
|
||||
class="game-list-row__providers"
|
||||
:providers="providers"
|
||||
@click.stop
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="showPlatformColumn"
|
||||
class="game-list-row__cell game-list-row__platform"
|
||||
>
|
||||
<RPlatformIcon
|
||||
v-if="platformMeta?.slug"
|
||||
:slug="platformMeta.slug"
|
||||
:size="24"
|
||||
/>
|
||||
<span class="game-list-row__platform-name">
|
||||
{{ platformMeta?.name ?? "—" }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="game-list-row__cell"
|
||||
:class="cellModifiers('fs_size_bytes')"
|
||||
>
|
||||
{{ formatBytes(rom.fs_size_bytes) }}
|
||||
</div>
|
||||
<div class="game-list-row__cell" :class="cellModifiers('created_at')">
|
||||
{{ formatDate(rom.created_at) }}
|
||||
</div>
|
||||
<div
|
||||
class="game-list-row__cell"
|
||||
:class="cellModifiers('first_release_date')"
|
||||
>
|
||||
{{ releaseDate(rom) }}
|
||||
</div>
|
||||
<div
|
||||
class="game-list-row__cell"
|
||||
:class="cellModifiers('average_rating')"
|
||||
>
|
||||
{{ ratingValue(rom) }}
|
||||
</div>
|
||||
<div
|
||||
class="game-list-row__cell"
|
||||
:class="cellModifiers('hltb_main_story')"
|
||||
>
|
||||
{{ lengthValue(rom) }}
|
||||
</div>
|
||||
|
||||
<div class="game-list-row__cell game-list-row__cell--pills">
|
||||
<div class="game-list-row__pills">
|
||||
<RChip
|
||||
v-for="l in (rom.languages ?? []).slice(0, PILLS_VISIBLE)"
|
||||
:key="`lang-${l}`"
|
||||
size="x-small"
|
||||
variant="translucent"
|
||||
>
|
||||
{{ l }}
|
||||
</RChip>
|
||||
<RChip
|
||||
v-if="(rom.languages?.length ?? 0) > PILLS_VISIBLE"
|
||||
size="x-small"
|
||||
variant="translucent"
|
||||
>
|
||||
+{{ (rom.languages?.length ?? 0) - PILLS_VISIBLE }}
|
||||
</RChip>
|
||||
</div>
|
||||
<RTooltip
|
||||
v-if="(rom.languages?.length ?? 0) > PILLS_VISIBLE"
|
||||
activator="parent"
|
||||
:text="rom.languages?.join(', ')"
|
||||
location="top"
|
||||
/>
|
||||
</div>
|
||||
<div class="game-list-row__cell game-list-row__cell--pills">
|
||||
<div class="game-list-row__pills">
|
||||
<RChip
|
||||
v-for="r in (rom.regions ?? []).slice(0, PILLS_VISIBLE)"
|
||||
:key="`reg-${r}`"
|
||||
size="x-small"
|
||||
variant="translucent"
|
||||
>
|
||||
{{ r }}
|
||||
</RChip>
|
||||
<RChip
|
||||
v-if="(rom.regions?.length ?? 0) > PILLS_VISIBLE"
|
||||
size="x-small"
|
||||
variant="translucent"
|
||||
>
|
||||
+{{ (rom.regions?.length ?? 0) - PILLS_VISIBLE }}
|
||||
</RChip>
|
||||
</div>
|
||||
<RTooltip
|
||||
v-if="(rom.regions?.length ?? 0) > PILLS_VISIBLE"
|
||||
activator="parent"
|
||||
:text="rom.regions?.join(', ')"
|
||||
location="top"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="game-list-row__cell" :class="cellModifiers('actions')">
|
||||
<div class="game-list-row__actions" @click.stop>
|
||||
<GameActionBtn
|
||||
:rom="rom"
|
||||
action="favorite"
|
||||
size="small"
|
||||
variant="bare"
|
||||
/>
|
||||
<GameActionBtn
|
||||
:rom="rom"
|
||||
action="more"
|
||||
size="small"
|
||||
variant="bare"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<!-- Column-driven, so the per-cell shapes stay in step with
|
||||
`GameListSkeletonRow` and the row does not reflow on data arrival. -->
|
||||
<template v-for="col in listSkeletonColumns" :key="String(col.key)">
|
||||
<div
|
||||
v-if="col.key === 'select'"
|
||||
class="game-list-row__cell game-list-row__select"
|
||||
>
|
||||
<!-- Empty cell during skeleton phase — no placeholder so the
|
||||
selection chrome only appears once a real row exists. -->
|
||||
</div>
|
||||
<div
|
||||
v-else-if="col.key === 'cover'"
|
||||
class="game-list-row__cell game-list-row__cover"
|
||||
>
|
||||
<!-- Compact skeleton, same two-line shape as the compact row. -->
|
||||
<div v-if="smAndDown" class="game-list-row__compact r-list-compact">
|
||||
<div class="game-list-row__select" />
|
||||
<div class="game-list-row__cover">
|
||||
<RSkeletonBlock
|
||||
:width="LIST_COVER_WIDTH_PX"
|
||||
:height="LIST_COVER_HEIGHT_PX"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-else-if="col.key === 'name'"
|
||||
class="game-list-row__cell game-list-row__title"
|
||||
>
|
||||
<div class="game-list-row__meta" :style="titleSkeletonGapStyle">
|
||||
<div class="r-list-compact__stack" :style="titleSkeletonGapStyle">
|
||||
<RSkeletonBlock
|
||||
v-for="(bar, i) in LIST_TITLE_SKELETON_BARS"
|
||||
:key="i"
|
||||
:width="bar.width"
|
||||
:height="bar.height"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Column-driven, so the per-cell shapes stay in step with
|
||||
`GameListSkeletonRow` and the row does not reflow on data arrival. -->
|
||||
<template v-else>
|
||||
<template v-for="col in listSkeletonColumns" :key="String(col.key)">
|
||||
<div
|
||||
v-if="col.key === 'select'"
|
||||
class="game-list-row__cell game-list-row__select"
|
||||
>
|
||||
<!-- Empty cell during skeleton phase, no placeholder so the
|
||||
selection chrome only appears once a real row exists. -->
|
||||
</div>
|
||||
<div
|
||||
v-else-if="col.key === 'cover'"
|
||||
class="game-list-row__cell game-list-row__cover"
|
||||
>
|
||||
<RSkeletonBlock
|
||||
v-for="(bar, i) in LIST_TITLE_SKELETON_BARS"
|
||||
:key="i"
|
||||
:width="bar.width"
|
||||
:height="bar.height"
|
||||
:width="LIST_COVER_WIDTH_PX"
|
||||
:height="LIST_COVER_HEIGHT_PX"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else-if="col.key === 'platform_id'" class="game-list-row__cell">
|
||||
<div class="game-list-row__platform">
|
||||
<RSkeletonBlock :width="24" :height="24" circle />
|
||||
<RSkeletonBlock :width="100" :height="10" />
|
||||
<div
|
||||
v-else-if="col.key === 'name'"
|
||||
class="game-list-row__cell game-list-row__title"
|
||||
>
|
||||
<div class="game-list-row__meta" :style="titleSkeletonGapStyle">
|
||||
<RSkeletonBlock
|
||||
v-for="(bar, i) in LIST_TITLE_SKELETON_BARS"
|
||||
:key="i"
|
||||
:width="bar.width"
|
||||
:height="bar.height"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-else-if="col.key === 'languages' || col.key === 'regions'"
|
||||
class="game-list-row__cell"
|
||||
>
|
||||
<div class="game-list-row__pills">
|
||||
<RSkeletonBlock :width="28" :height="16" rounded="pill" />
|
||||
<RSkeletonBlock :width="28" :height="16" rounded="pill" />
|
||||
<div
|
||||
v-else-if="col.key === 'platform_id'"
|
||||
class="game-list-row__cell"
|
||||
>
|
||||
<div class="game-list-row__platform">
|
||||
<RSkeletonBlock :width="24" :height="24" circle />
|
||||
<RSkeletonBlock :width="100" :height="10" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-else-if="col.key === 'actions'"
|
||||
class="game-list-row__cell"
|
||||
:class="cellModifiers('actions')"
|
||||
>
|
||||
<RSkeletonBlock :width="18" :height="18" circle />
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
class="game-list-row__cell"
|
||||
:class="{ 'game-list-row__cell--end': col.align === 'end' }"
|
||||
>
|
||||
<RSkeletonBlock :width="col.skeletonWidth ?? 60" :height="10" />
|
||||
</div>
|
||||
<div
|
||||
v-else-if="col.key === 'languages' || col.key === 'regions'"
|
||||
class="game-list-row__cell"
|
||||
>
|
||||
<div class="game-list-row__pills">
|
||||
<RSkeletonBlock :width="28" :height="16" rounded="pill" />
|
||||
<RSkeletonBlock :width="28" :height="16" rounded="pill" />
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-else-if="col.key === 'actions'"
|
||||
class="game-list-row__cell"
|
||||
:class="cellModifiers('actions')"
|
||||
>
|
||||
<RSkeletonBlock :width="18" :height="18" circle />
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
class="game-list-row__cell"
|
||||
:class="{ 'game-list-row__cell--end': col.align === 'end' }"
|
||||
>
|
||||
<RSkeletonBlock :width="col.skeletonWidth ?? 60" :height="10" />
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
</a>
|
||||
@@ -537,16 +759,128 @@ function onRowPointerEnd() {
|
||||
|
||||
<style scoped>
|
||||
.game-list-row {
|
||||
/* An inline <a> would shrink-wrap its content and swallow the bleed. */
|
||||
display: block;
|
||||
/* The long press selects the row; iOS would offer its link callout too. */
|
||||
-webkit-touch-callout: none;
|
||||
/* Runs to the screen edges wherever the shell asks for it. */
|
||||
margin-inline: calc(-1 * var(--r-list-bleed, 0px));
|
||||
font-size: var(--r-font-size-md);
|
||||
color: var(--r-color-fg-secondary);
|
||||
cursor: default;
|
||||
transition: background var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
|
||||
/* Column layout, for the viewports that still have columns. The compact
|
||||
branch is plain flow, so it needs nothing cancelled. */
|
||||
.game-list-row--columns {
|
||||
display: grid;
|
||||
align-items: center;
|
||||
gap: 0 var(--r-space-5);
|
||||
padding: 0 var(--r-space-3);
|
||||
height: var(--r-list-row-h);
|
||||
border-bottom: 1px solid var(--r-color-border);
|
||||
}
|
||||
|
||||
/* ── Compact layout (phones / tablets) ───────────────────────────────
|
||||
No columns: a two-line block, and a detail panel whose fixed height the
|
||||
virtualiser mirrors (`LIST_ROW_DETAIL_HEIGHT_PX`) so the rows below an
|
||||
open row sit clear of it. */
|
||||
.game-list-row__compact {
|
||||
height: var(--r-list-row-h);
|
||||
border-bottom: 1px solid var(--r-color-border);
|
||||
}
|
||||
.game-list-row--expanded .game-list-row__compact {
|
||||
border-bottom-color: transparent;
|
||||
}
|
||||
.game-list-row__compact > .game-list-row__select {
|
||||
flex: none;
|
||||
width: var(--r-list-select-w);
|
||||
}
|
||||
/* Two lines of title: most names fit whole, and the row keeps its height
|
||||
(cover 64 + two lines + the facts line still sit inside it). */
|
||||
.game-list-row__compact .game-list-row__name {
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
line-clamp: 2;
|
||||
white-space: normal;
|
||||
line-height: 1.25;
|
||||
}
|
||||
.game-list-row__facts-icon,
|
||||
.game-list-row__fav {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.game-list-row__fav {
|
||||
color: var(--r-color-brand-primary);
|
||||
}
|
||||
|
||||
.game-list-row__chevron {
|
||||
appearance: none;
|
||||
background: transparent;
|
||||
border: 0;
|
||||
padding: 4px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
color: var(--r-color-fg-muted);
|
||||
cursor: pointer;
|
||||
transition: transform var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
.game-list-row__chevron--open {
|
||||
transform: rotate(180deg);
|
||||
color: var(--r-color-fg);
|
||||
}
|
||||
/* Rolls open and shut: the height comes from `useListExpansion`, which the
|
||||
virtualiser reads too, so the panel and the slot it sits in move together.
|
||||
The inner block keeps its full height and is clipped meanwhile. */
|
||||
.game-list-row__detail {
|
||||
overflow: hidden;
|
||||
border-bottom: 1px solid var(--r-color-border);
|
||||
background: var(--r-color-bg-elevated);
|
||||
cursor: default;
|
||||
}
|
||||
.game-list-row__detail-inner {
|
||||
height: var(--r-list-row-detail-h);
|
||||
padding: var(--r-space-4) var(--r-row-pad);
|
||||
display: grid;
|
||||
/* Three equal columns across the full width, so the fields land in the
|
||||
same place whatever the title or the file name measure. */
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: var(--r-space-4);
|
||||
align-content: start;
|
||||
}
|
||||
.game-list-row__field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
min-width: 0;
|
||||
}
|
||||
/* One line, always: the panel's height is fixed (`--r-list-row-detail-h`) for
|
||||
the virtualiser, so a caption that wraps in another locale would push the
|
||||
last field out of the clipped box. */
|
||||
.game-list-row__field-label {
|
||||
font-size: var(--r-font-size-xs);
|
||||
font-weight: var(--r-font-weight-bold);
|
||||
letter-spacing: 0.07em;
|
||||
text-transform: uppercase;
|
||||
color: var(--r-color-fg-muted);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.game-list-row__field--wide {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
/* Loops sideways when it overflows, so a long name reads whole in one line. */
|
||||
.game-list-row__field--filename {
|
||||
grid-column: span 2;
|
||||
}
|
||||
.game-list-row__field-value {
|
||||
font-size: var(--r-font-size-md);
|
||||
color: var(--r-color-fg-secondary);
|
||||
cursor: default;
|
||||
transition: background var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.game-list-row--clickable {
|
||||
@@ -685,28 +1019,10 @@ function onRowPointerEnd() {
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/* The badges own their look; the column layout only adds the gap under the
|
||||
file name above them. */
|
||||
.game-list-row__providers {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
margin-top: 4px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.game-list-row__provider {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 4px;
|
||||
background: var(--r-color-surface);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.game-list-row__provider img {
|
||||
display: block;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
/* Pills cell — chips wrap to multiple lines inside the cell when they
|
||||
|
||||
103
frontend/src/v2/components/Gallery/GameListRowCompact.test.ts
Normal file
103
frontend/src/v2/components/Gallery/GameListRowCompact.test.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
import { mount } from "@vue/test-utils";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { ref } from "vue";
|
||||
import GameListRow from "./GameListRow.vue";
|
||||
import { rom } from "./listRowFixture";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key, locale: { value: "en" } }),
|
||||
}));
|
||||
|
||||
vi.mock("vue-router", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("vue-router")>()),
|
||||
useRouter: () => ({ push: vi.fn() }),
|
||||
}));
|
||||
|
||||
const smAndDown = ref(true);
|
||||
vi.mock("@/v2/composables/useBreakpoint", () => ({
|
||||
useBreakpoint: () => ({ smAndDown }),
|
||||
}));
|
||||
|
||||
function mountRow(props: Record<string, unknown> = {}) {
|
||||
return mount(GameListRow, {
|
||||
props: { rom: rom(), ...props },
|
||||
global: {
|
||||
stubs: {
|
||||
GameActionBtn: true,
|
||||
GameCard: true,
|
||||
RCheckbox: true,
|
||||
RChip: true,
|
||||
RIcon: true,
|
||||
RPlatformIcon: true,
|
||||
RTooltip: true,
|
||||
SiblingBadge: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/** The facts line's text pieces, separators included. */
|
||||
function facts(wrapper: ReturnType<typeof mountRow>): string[] {
|
||||
return wrapper
|
||||
.findAll(".r-list-compact__facts > span")
|
||||
.map((el) => el.text());
|
||||
}
|
||||
|
||||
describe("list row on phones and tablets", () => {
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia());
|
||||
smAndDown.value = true;
|
||||
});
|
||||
|
||||
it("trades the columns for a title and a facts line", () => {
|
||||
const wrapper = mountRow();
|
||||
|
||||
expect(wrapper.find(".game-list-row__compact").exists()).toBe(true);
|
||||
expect(wrapper.find(".game-list-row__cell").exists()).toBe(false);
|
||||
expect(facts(wrapper)).toEqual(["Super Nintendo", "·", "1995"]);
|
||||
});
|
||||
|
||||
it("leaves the platform out where the whole list shares one", () => {
|
||||
const wrapper = mountRow({ showPlatformColumn: false });
|
||||
|
||||
expect(facts(wrapper)).toEqual(["1995"]);
|
||||
});
|
||||
|
||||
it("keeps the columns on wider viewports", () => {
|
||||
smAndDown.value = false;
|
||||
|
||||
const wrapper = mountRow();
|
||||
|
||||
expect(wrapper.find(".game-list-row__compact").exists()).toBe(false);
|
||||
expect(wrapper.find(".game-list-row__cell").exists()).toBe(true);
|
||||
});
|
||||
|
||||
it("asks the parent to open its detail panel", async () => {
|
||||
const wrapper = mountRow({ expandable: true });
|
||||
|
||||
await wrapper.get(".game-list-row__chevron").trigger("click");
|
||||
|
||||
expect(wrapper.emitted("toggle-expand")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("offers no chevron where the row cannot grow", () => {
|
||||
const wrapper = mountRow();
|
||||
|
||||
expect(wrapper.find(".game-list-row__chevron").exists()).toBe(false);
|
||||
});
|
||||
|
||||
it("moves the remaining columns into the open panel", () => {
|
||||
const wrapper = mountRow({ expandable: true, expanded: true });
|
||||
|
||||
const fields = wrapper
|
||||
.findAll(".game-list-row__field-value")
|
||||
.map((el) => el.text());
|
||||
// The file name, plus what the facts line leaves out.
|
||||
expect(fields).toContain("Chrono Trigger.sfc");
|
||||
expect(fields).toContain("4 MB");
|
||||
expect(fields).toContain("9.1");
|
||||
expect(fields).toContain("USA");
|
||||
expect(fields).toContain("en");
|
||||
});
|
||||
});
|
||||
@@ -1,11 +1,11 @@
|
||||
import { mount } from "@vue/test-utils";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { RomMetadataSchema, RomUserSchema } from "@/__generated__";
|
||||
import type { SimpleRom } from "@/v2/stores/galleryRoms";
|
||||
import { ref } from "vue";
|
||||
import GameListRow from "./GameListRow.vue";
|
||||
import GameListSkeletonRow from "./GameListSkeletonRow.vue";
|
||||
import { getListColumns, LIST_COVER_TRACK_PX } from "./listColumns";
|
||||
import { rom } from "./listRowFixture";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key, locale: { value: "en" } }),
|
||||
@@ -16,6 +16,11 @@ vi.mock("vue-router", async (importOriginal) => ({
|
||||
useRouter: () => ({ push: vi.fn() }),
|
||||
}));
|
||||
|
||||
const smAndDown = ref(false);
|
||||
vi.mock("@/v2/composables/useBreakpoint", () => ({
|
||||
useBreakpoint: () => ({ smAndDown }),
|
||||
}));
|
||||
|
||||
/** Per-column placeholder geometry: every inline style in the cell, so both
|
||||
* each block's size and its stack's spacing are compared. */
|
||||
function shapes(row: HTMLElement): string[][] {
|
||||
@@ -26,6 +31,15 @@ function shapes(row: HTMLElement): string[][] {
|
||||
);
|
||||
}
|
||||
|
||||
/** The compact row nests its placeholders one level down, under the single
|
||||
* flex container that stands in for the columns. */
|
||||
function compactShapes(row: HTMLElement): string[][] {
|
||||
const compact = row.classList.contains("r-list-compact")
|
||||
? row
|
||||
: row.querySelector<HTMLElement>(".r-list-compact");
|
||||
return compact ? shapes(compact) : [];
|
||||
}
|
||||
|
||||
/** Per-column right-edge flag, in column order. */
|
||||
function rightEdges(row: HTMLElement): boolean[] {
|
||||
return Array.from(row.children).map((cell) =>
|
||||
@@ -40,132 +54,6 @@ function tabularFigures(row: HTMLElement): boolean[] {
|
||||
);
|
||||
}
|
||||
|
||||
const ROM_USER: RomUserSchema = {
|
||||
id: 1,
|
||||
user_id: 1,
|
||||
rom_id: 1,
|
||||
created_at: "2026-01-02T00:00:00Z",
|
||||
updated_at: "2026-01-02T00:00:00Z",
|
||||
last_played: null,
|
||||
is_main_sibling: true,
|
||||
backlogged: false,
|
||||
now_playing: false,
|
||||
hidden: false,
|
||||
rating: 0,
|
||||
difficulty: 0,
|
||||
completion: 0,
|
||||
status: null,
|
||||
};
|
||||
|
||||
const METADATUM: RomMetadataSchema = {
|
||||
rom_id: 1,
|
||||
genres: [],
|
||||
franchises: [],
|
||||
collections: [],
|
||||
companies: [],
|
||||
publishers: [],
|
||||
developers: [],
|
||||
game_modes: [],
|
||||
age_ratings: [],
|
||||
player_count: "1",
|
||||
first_release_date: Date.UTC(1995, 7, 11),
|
||||
average_rating: 9.1,
|
||||
};
|
||||
|
||||
/** A complete `SimpleRom`, so a new required field breaks the build instead of
|
||||
* hiding behind a cast. Tests override only the fields they read. */
|
||||
const ROM_DEFAULTS: SimpleRom = {
|
||||
id: 1,
|
||||
igdb_id: null,
|
||||
sgdb_id: null,
|
||||
moby_id: null,
|
||||
ss_id: null,
|
||||
ra_id: null,
|
||||
launchbox_id: null,
|
||||
hasheous_id: null,
|
||||
tgdb_id: null,
|
||||
flashpoint_id: null,
|
||||
hltb_id: null,
|
||||
demozoo_id: null,
|
||||
pouet_id: null,
|
||||
csdb_id: null,
|
||||
steam_id: null,
|
||||
gamelist_id: null,
|
||||
libretro_id: null,
|
||||
platform_id: 1,
|
||||
platform_slug: "snes",
|
||||
platform_fs_slug: "snes",
|
||||
platform_custom_name: null,
|
||||
platform_display_name: "Super Nintendo",
|
||||
fs_name: "Chrono Trigger.sfc",
|
||||
fs_name_no_tags: "Chrono Trigger",
|
||||
fs_name_no_ext: "Chrono Trigger",
|
||||
fs_extension: "sfc",
|
||||
fs_path: "snes/Chrono Trigger.sfc",
|
||||
fs_size_bytes: 4_194_304,
|
||||
name: "Chrono Trigger",
|
||||
name_sort_key: "chrono trigger",
|
||||
slug: "chrono-trigger",
|
||||
summary: null,
|
||||
alternative_names: [],
|
||||
youtube_video_id: null,
|
||||
metadatum: METADATUM,
|
||||
igdb_metadata: null,
|
||||
moby_metadata: null,
|
||||
ss_metadata: null,
|
||||
launchbox_metadata: null,
|
||||
hasheous_metadata: null,
|
||||
flashpoint_metadata: null,
|
||||
hltb_metadata: { main_story: 23 },
|
||||
demozoo_metadata: null,
|
||||
pouet_metadata: null,
|
||||
csdb_metadata: null,
|
||||
steam_metadata: null,
|
||||
gamelist_metadata: null,
|
||||
manual_metadata: null,
|
||||
path_cover_small: null,
|
||||
path_cover_large: null,
|
||||
url_cover: null,
|
||||
has_manual: false,
|
||||
has_soundtrack: false,
|
||||
path_manual: null,
|
||||
url_manual: null,
|
||||
path_video: null,
|
||||
is_unidentified: false,
|
||||
is_identified: true,
|
||||
revision: null,
|
||||
regions: ["USA"],
|
||||
languages: ["en"],
|
||||
tags: [],
|
||||
crc_hash: null,
|
||||
md5_hash: null,
|
||||
sha1_hash: null,
|
||||
ra_hash: null,
|
||||
title_id: null,
|
||||
save_target: null,
|
||||
save_target_layout: null,
|
||||
has_simple_single_file: true,
|
||||
has_nested_single_file: false,
|
||||
has_multiple_files: false,
|
||||
full_path: "/romm/library/snes/Chrono Trigger.sfc",
|
||||
created_at: "2026-01-02T00:00:00Z",
|
||||
updated_at: "2026-01-02T00:00:00Z",
|
||||
missing_from_fs: false,
|
||||
is_physical: false,
|
||||
has_file_on_disk: true,
|
||||
upc: null,
|
||||
has_notes: false,
|
||||
rom_user: ROM_USER,
|
||||
merged_screenshots: [],
|
||||
merged_ra_metadata: null,
|
||||
files: [],
|
||||
sibling_roms: [],
|
||||
};
|
||||
|
||||
function rom(overrides: Partial<SimpleRom> = {}): SimpleRom {
|
||||
return { ...ROM_DEFAULTS, ...overrides };
|
||||
}
|
||||
|
||||
function mountHydratedRow() {
|
||||
return mount(GameListRow, {
|
||||
props: { rom: rom() },
|
||||
@@ -186,6 +74,7 @@ function mountHydratedRow() {
|
||||
describe("list-mode skeleton row", () => {
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia());
|
||||
smAndDown.value = false;
|
||||
});
|
||||
|
||||
it("paints the bootstrap row's per-column shapes", () => {
|
||||
@@ -216,6 +105,17 @@ describe("list-mode skeleton row", () => {
|
||||
expect(tabularFigures(hydrated)).toEqual(expected);
|
||||
});
|
||||
|
||||
it("paints the bootstrap row's compact shapes too", () => {
|
||||
// The compact branch is a second copy of the same placeholder; a tick
|
||||
// column or a bar stack that drifts moves every cover on a phone.
|
||||
smAndDown.value = true;
|
||||
const pending = mount(GameListRow, { props: { position: 0 } }).element;
|
||||
const bootstrap = mount(GameListSkeletonRow).element;
|
||||
|
||||
expect(compactShapes(pending)).toEqual(compactShapes(bootstrap));
|
||||
expect(compactShapes(pending).length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("sizes the cover column off the art cap, not the measured ratios", () => {
|
||||
const grid = (row: HTMLElement) => row.style.gridTemplateColumns;
|
||||
const pending = mount(GameListRow, { props: { position: 0 } }).element;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
// both flavours stay visually identical.
|
||||
import { RSkeletonBlock } from "@v2/lib";
|
||||
import { computed } from "vue";
|
||||
import { useBreakpoint } from "@/v2/composables/useBreakpoint";
|
||||
import {
|
||||
getListColumns,
|
||||
getListGridTemplate,
|
||||
@@ -40,10 +41,34 @@ const gridStyle = computed(() => ({
|
||||
gridTemplateColumns: getListGridTemplate(props.showPlatformColumn),
|
||||
}));
|
||||
const titleGapStyle = { gap: `${LIST_TITLE_SKELETON_GAP_PX}px` };
|
||||
|
||||
// Phones and tablets render the compact two-line row, so the placeholder
|
||||
// follows it instead of the columns.
|
||||
const { smAndDown } = useBreakpoint();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="r-glr-skel" :style="gridStyle">
|
||||
<div v-if="smAndDown" class="r-glr-skel r-glr-skel--compact r-list-compact">
|
||||
<!-- Stands in for the compact row's tick column, or the cover would start
|
||||
further left here than in the row this replaces. -->
|
||||
<div class="r-glr-skel__select" />
|
||||
<div class="r-glr-skel__cell r-glr-skel__cover">
|
||||
<RSkeletonBlock
|
||||
:width="LIST_COVER_WIDTH_PX"
|
||||
:height="LIST_COVER_HEIGHT_PX"
|
||||
/>
|
||||
</div>
|
||||
<div class="r-list-compact__stack" :style="titleGapStyle">
|
||||
<RSkeletonBlock
|
||||
v-for="(bar, i) in LIST_TITLE_SKELETON_BARS"
|
||||
:key="i"
|
||||
:width="bar.width"
|
||||
:height="bar.height"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="r-glr-skel" :style="gridStyle">
|
||||
<template v-for="col in columns" :key="String(col.key)">
|
||||
<div v-if="col.key === 'select'" class="r-glr-skel__cell" />
|
||||
<div
|
||||
@@ -106,6 +131,8 @@ const titleGapStyle = { gap: `${LIST_TITLE_SKELETON_GAP_PX}px` };
|
||||
|
||||
<style scoped>
|
||||
.r-glr-skel {
|
||||
/* Bleeds with the row it stands in for (see GameListRow). */
|
||||
margin-inline: calc(-1 * var(--r-list-bleed, 0px));
|
||||
display: grid;
|
||||
align-items: center;
|
||||
gap: 0 var(--r-space-5);
|
||||
@@ -114,6 +141,11 @@ const titleGapStyle = { gap: `${LIST_TITLE_SKELETON_GAP_PX}px` };
|
||||
border-bottom: 1px solid var(--r-color-border);
|
||||
}
|
||||
|
||||
.r-glr-skel--compact > .r-glr-skel__select {
|
||||
flex: none;
|
||||
width: var(--r-list-select-w);
|
||||
}
|
||||
|
||||
.r-glr-skel__cell {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
@@ -12,21 +12,22 @@
|
||||
//
|
||||
// All admin actions are forwarded as events; permission gating lives
|
||||
// on the parent so the bar stays in sync with `useCan`.
|
||||
import { RBtn, RChip, RPlatformIcon, RTabNav } from "@v2/lib";
|
||||
import { RBtn, RChip, RIcon, RPlatformIcon, RTabNav } from "@v2/lib";
|
||||
import type { RTabNavItem } from "@v2/lib";
|
||||
import { computed } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import type { Platform } from "@/stores/platforms";
|
||||
import InfoPanel from "@/v2/components/Gallery/InfoPanel.vue";
|
||||
import Stat from "@/v2/components/shared/Stat.vue";
|
||||
import { useBreakpoint } from "@/v2/composables/useBreakpoint";
|
||||
import {
|
||||
playTooltip,
|
||||
usePlatformPlayable,
|
||||
} from "@/v2/composables/usePlatformPlayable";
|
||||
import type { StatRow } from "@/v2/types/stats";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
interface StatRow {
|
||||
label: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
interface ProviderChip {
|
||||
key: string;
|
||||
label: string;
|
||||
@@ -35,7 +36,7 @@ interface ProviderChip {
|
||||
title?: string;
|
||||
}
|
||||
|
||||
defineProps<{
|
||||
const props = defineProps<{
|
||||
platform: Platform;
|
||||
tab: string;
|
||||
tabs: RTabNavItem[];
|
||||
@@ -75,6 +76,12 @@ defineEmits<{
|
||||
// the icon to a fixed box height, which — for a tall icon — either overflowed
|
||||
// (overlap) or, once clipped, cut it off.
|
||||
const { xs } = useBreakpoint();
|
||||
const { t } = useI18n();
|
||||
// Same play-mode marker the platforms list carries, so a platform reads the
|
||||
// same in its own header as it does in the index.
|
||||
const { mode, emulator, streamLabel } = usePlatformPlayable(
|
||||
() => props.platform.slug,
|
||||
);
|
||||
const iconSize = computed(() => (xs.value ? 116 : 148));
|
||||
</script>
|
||||
|
||||
@@ -94,7 +101,21 @@ const iconSize = computed(() => (xs.value ? 116 : 148));
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-if="tags.length || description" #tags>
|
||||
<template v-if="tags.length || description || mode" #tags>
|
||||
<RChip
|
||||
v-if="mode"
|
||||
size="small"
|
||||
variant="translucent"
|
||||
:rounded="20"
|
||||
:title="playTooltip(mode, emulator, streamLabel)"
|
||||
>
|
||||
<RIcon
|
||||
icon="mdi-play-circle"
|
||||
size="14"
|
||||
:color="mode === 'stream' ? 'romm-blue' : 'success'"
|
||||
/>
|
||||
{{ t("platform.playable") }}
|
||||
</RChip>
|
||||
<RChip
|
||||
v-for="tag in tags"
|
||||
:key="tag"
|
||||
|
||||
54
frontend/src/v2/components/Gallery/ProviderBadges.vue
Normal file
54
frontend/src/v2/components/Gallery/ProviderBadges.vue
Normal file
@@ -0,0 +1,54 @@
|
||||
<script setup lang="ts">
|
||||
// ProviderBadges: the metadata providers a ROM matched, as tooltipped
|
||||
// logo chips. Rendered twice by GameListRow (the column layout's title cell
|
||||
// and the compact row's detail panel), so it lives here rather than twice
|
||||
// in that template.
|
||||
import { RTooltip } from "@v2/lib";
|
||||
import type { MetadataProvider } from "@/v2/utils/metadataProviders";
|
||||
|
||||
defineProps<{ providers: readonly MetadataProvider[] }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span class="provider-badges">
|
||||
<span
|
||||
v-for="provider in providers"
|
||||
:key="provider.key"
|
||||
class="provider-badges__item"
|
||||
:style="provider.bg ? { background: provider.bg } : undefined"
|
||||
>
|
||||
<img
|
||||
:src="`/assets/scrappers/${provider.logo}`"
|
||||
:alt="provider.title"
|
||||
width="14"
|
||||
height="14"
|
||||
/>
|
||||
<RTooltip activator="parent" :text="provider.title" location="top" />
|
||||
</span>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.provider-badges {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.provider-badges__item {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 4px;
|
||||
background: var(--r-color-surface);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.provider-badges__item img {
|
||||
display: block;
|
||||
object-fit: contain;
|
||||
}
|
||||
</style>
|
||||
@@ -46,7 +46,7 @@ import {
|
||||
RDivider,
|
||||
} from "@v2/lib";
|
||||
import type { Emitter } from "mitt";
|
||||
import { computed, inject, ref } from "vue";
|
||||
import { computed, inject, onBeforeUnmount, onMounted, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import type { RomUserData, RomUserStatus } from "@/__generated__";
|
||||
import { useFavoriteToggle } from "@/composables/useFavoriteToggle";
|
||||
@@ -55,7 +55,7 @@ import romApi from "@/services/api/rom";
|
||||
import storeCollections from "@/stores/collections";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import { romStatusMap } from "@/utils";
|
||||
import { useBreakpoint } from "@/v2/composables/useBreakpoint";
|
||||
import { useAnimatedNumber } from "@/v2/composables/useAnimatedNumber";
|
||||
import { useCan } from "@/v2/composables/useCan";
|
||||
import { useGallerySelectAll } from "@/v2/composables/useGallerySelectAll";
|
||||
import { useRomSync } from "@/v2/composables/useRomSync";
|
||||
@@ -70,6 +70,11 @@ import {
|
||||
type StatusFlagKey,
|
||||
VISIBILITY_FLAG_KEYS,
|
||||
} from "@/v2/utils/romStatus";
|
||||
import {
|
||||
FILLET_PX,
|
||||
NOTCH_RADIUS_PX,
|
||||
selectionBarOutline,
|
||||
} from "./selectionBarOutline";
|
||||
|
||||
interface Props {
|
||||
/** Hides the download action where the selected ROMs have no file on
|
||||
@@ -82,12 +87,12 @@ defineProps<Props>();
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const { t } = useI18n();
|
||||
// On phones the bar drops the "N selected" phrase down to just the
|
||||
// number so the action row fits a 320px width without overflowing.
|
||||
const { xs } = useBreakpoint();
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
const snackbar = useSnackbar();
|
||||
const selection = storeGallerySelection();
|
||||
// The count rolls up to its new value rather than snapping, so a selection
|
||||
// that grew by a tap is a number you see move.
|
||||
const rollingCount = useAnimatedNumber(() => selection.count);
|
||||
const collectionsStore = storeCollections();
|
||||
const galleryRomsStore = storeGalleryRoms();
|
||||
const { ensureFavoriteCollection } = useFavoriteToggle();
|
||||
@@ -301,6 +306,41 @@ function bulkDelete() {
|
||||
emitter?.emit("showDeleteRomDialog", selection.roms);
|
||||
}
|
||||
|
||||
// ── Outline ─────────────────────────────────────────────────────────
|
||||
|
||||
/** The hill's own geometry, which its fill and the outline both read. */
|
||||
const notchStyle = {
|
||||
"--r-notch-fillet": `${FILLET_PX}px`,
|
||||
"--r-notch-radius": `${NOTCH_RADIUS_PX}px`,
|
||||
};
|
||||
|
||||
const barEl = ref<HTMLElement | null>(null);
|
||||
const notchEl = ref<HTMLElement | null>(null);
|
||||
const barSize = ref({ w: 0, h: 0 });
|
||||
const notchSize = ref({ w: 0, h: 0 });
|
||||
|
||||
function measure() {
|
||||
const bar = barEl.value;
|
||||
const notch = notchEl.value;
|
||||
if (bar) barSize.value = { w: bar.offsetWidth, h: bar.offsetHeight };
|
||||
if (notch) notchSize.value = { w: notch.offsetWidth, h: notch.offsetHeight };
|
||||
}
|
||||
|
||||
// The bar's width follows its buttons and the hill's follows the digit count,
|
||||
// so both are watched rather than measured once.
|
||||
let sizeObserver: ResizeObserver | null = null;
|
||||
onMounted(() => {
|
||||
measure();
|
||||
sizeObserver = new ResizeObserver(measure);
|
||||
if (barEl.value) sizeObserver.observe(barEl.value);
|
||||
if (notchEl.value) sizeObserver.observe(notchEl.value);
|
||||
});
|
||||
onBeforeUnmount(() => sizeObserver?.disconnect());
|
||||
|
||||
const outline = computed(() =>
|
||||
selectionBarOutline(barSize.value, notchSize.value),
|
||||
);
|
||||
|
||||
function clear() {
|
||||
selection.clear();
|
||||
}
|
||||
@@ -308,34 +348,46 @@ function clear() {
|
||||
|
||||
<template>
|
||||
<div
|
||||
ref="barEl"
|
||||
class="selection-bar"
|
||||
:class="{ 'selection-bar--visible': selection.enabled }"
|
||||
:aria-hidden="!selection.enabled"
|
||||
>
|
||||
<!-- One stroke around bar, hill and fillets, since three boxes cannot
|
||||
share a border without seams where their edges meet. -->
|
||||
<svg
|
||||
v-if="outline"
|
||||
class="selection-bar__outline"
|
||||
:style="{ top: `${-outline.rise}px`, height: `${outline.height}px` }"
|
||||
:viewBox="`0 0 ${outline.width} ${outline.height}`"
|
||||
:width="outline.width"
|
||||
:height="outline.height"
|
||||
aria-hidden="true"
|
||||
focusable="false"
|
||||
>
|
||||
<path :d="outline.d" />
|
||||
</svg>
|
||||
<!-- Count: a notch rising from the bar's top edge, centred. Its lower
|
||||
half hides behind the bar, so the two read as one surface. -->
|
||||
<!-- Named, not a live region: the digits change once per animation frame
|
||||
while the count rolls, and a status role would read out every one. -->
|
||||
<div
|
||||
ref="notchEl"
|
||||
class="selection-bar__notch"
|
||||
:style="notchStyle"
|
||||
role="img"
|
||||
:aria-label="t('gallery.selection-n-selected', { n: selection.count })"
|
||||
>
|
||||
<span class="selection-bar__notch-count">{{ rollingCount }}</span>
|
||||
</div>
|
||||
|
||||
<RToolbar
|
||||
density="compact"
|
||||
rounded="full"
|
||||
flat
|
||||
class="selection-bar__panel"
|
||||
>
|
||||
<!-- Prepend region: count chip — leftmost item, separated from
|
||||
the action buttons by RToolbar's built-in inter-region
|
||||
spacing. -->
|
||||
<template #prepend>
|
||||
<div class="selection-bar__count">
|
||||
<RIcon
|
||||
icon="mdi-check-circle"
|
||||
size="18"
|
||||
class="selection-bar__count-icon"
|
||||
/>
|
||||
<span>
|
||||
<template v-if="xs">{{ selection.count }}</template>
|
||||
<template v-else>
|
||||
{{ t("gallery.selection-n-selected", { n: selection.count }) }}
|
||||
</template>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- Extends the selection to the whole filtered result; the
|
||||
sole grid-mode affordance (list mode has the header checkbox). -->
|
||||
<RTooltip :text="selectAllLabel">
|
||||
@@ -533,40 +585,50 @@ function clear() {
|
||||
|
||||
<style scoped>
|
||||
.selection-bar {
|
||||
/* Same brand edge a selected card carries, a hair thinner. */
|
||||
--r-color-selection-edge: var(--r-color-brand-primary);
|
||||
position: fixed;
|
||||
left: 50%;
|
||||
bottom: max(24px, env(safe-area-inset-bottom, 0));
|
||||
transform: translate(-50%, calc(100% + 32px));
|
||||
transform: translateX(-50%);
|
||||
/* Above the bottom tab bar (z 100) so the multi-select bar floats over
|
||||
it on mobile instead of being painted behind it; still below dialogs
|
||||
(z 2400) so a confirm opened from a selection covers it. */
|
||||
z-index: 101;
|
||||
pointer-events: none;
|
||||
transition: transform var(--r-motion-mid) var(--r-motion-ease-out);
|
||||
/* Respect the platform's reduced-motion preference: skip the
|
||||
slide-up so the bar appears instantly without animation. */
|
||||
opacity: 0;
|
||||
/* The drop shadow belongs to the whole silhouette, not to the bar: cast
|
||||
from the bar itself it lands on the hill, which sits behind it, and
|
||||
tints it a shade darker than the surface it is meant to continue. */
|
||||
border-radius: var(--r-radius-pill);
|
||||
box-shadow: 0 12px 32px color-mix(in srgb, black 32%, transparent);
|
||||
/* Fades in and out where it stands. */
|
||||
transition: opacity var(--r-motion-med) var(--r-motion-ease-out);
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
|
||||
.selection-bar--visible {
|
||||
transform: translate(-50%, 0);
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.selection-bar__outline {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
z-index: 3;
|
||||
overflow: visible;
|
||||
fill: none;
|
||||
stroke: var(--r-color-selection-edge);
|
||||
stroke-width: 1;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* On sm-and-down sit just above the bottom tab bar (8px gap) so the two
|
||||
read as stacked, not overlapping. Anchoring `bottom` this high means
|
||||
the base hide transform (translateY(100% + 32px)) can't clear the
|
||||
viewport, so the hidden transform is enlarged to push the panel fully
|
||||
past the bar + screen edge; the visible state (declared after, same
|
||||
specificity) pins it back at the 8px gap. */
|
||||
read as stacked, not overlapping. */
|
||||
html[data-bp~="sm-and-down"] .selection-bar {
|
||||
bottom: calc(var(--r-bottom-nav-h) + 8px + env(safe-area-inset-bottom));
|
||||
transform: translate(-50%, calc(100% + var(--r-bottom-nav-h) + 48px));
|
||||
}
|
||||
html[data-bp~="sm-and-down"] .selection-bar--visible {
|
||||
transform: translate(-50%, 0);
|
||||
}
|
||||
|
||||
/* RToolbar's default surface (`--r-color-bg-elevated`) is overridden
|
||||
@@ -575,43 +637,74 @@ html[data-bp~="sm-and-down"] .selection-bar--visible {
|
||||
Border + shadow + backdrop-blur are stacked on top of the
|
||||
primitive's flat pill. `max-width` keeps it inside a 320px viewport. */
|
||||
.selection-bar__panel {
|
||||
/* Over the hill, so the part that laps into the bar is hidden behind it
|
||||
instead of painting across the buttons' own backgrounds. */
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
--r-toolbar-color: var(--r-color-panel);
|
||||
max-width: calc(100vw - 16px);
|
||||
border: 1px solid var(--r-color-panel-border);
|
||||
box-shadow:
|
||||
0 12px 32px color-mix(in srgb, black 32%, transparent),
|
||||
0 0 0 1px color-mix(in srgb, white 4%, transparent) inset;
|
||||
backdrop-filter: blur(18px) saturate(140%);
|
||||
}
|
||||
|
||||
.selection-bar__count {
|
||||
/* A hill rising from the bar's top edge. It shares the bar's fill and laps
|
||||
into it, and the two pseudo-elements curve its foot out into the bar, so
|
||||
bar and hill read as one surface. Nothing here carries a stroke: an edge
|
||||
that stopped at the join is exactly what makes a seam. */
|
||||
.selection-bar__notch {
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
left: 50%;
|
||||
bottom: calc(100% - 6px);
|
||||
transform: translateX(-50%);
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 0 4px;
|
||||
padding: 9px 16px 13px;
|
||||
/* The foot stays square so the sides run straight down into the fillets
|
||||
below. Rounding it would pull the edge inward and open a gap between
|
||||
hill, fillet and bar. The square corners themselves sit inside the bar,
|
||||
out of sight. */
|
||||
border-radius: var(--r-notch-radius) var(--r-notch-radius) 0 0;
|
||||
background: var(--r-color-panel);
|
||||
/* The bar's glass too, or the fill reads a shade off against it. */
|
||||
backdrop-filter: blur(18px) saturate(140%);
|
||||
color: var(--r-color-fg);
|
||||
font-size: var(--r-font-size-md);
|
||||
font-weight: var(--r-font-weight-semibold);
|
||||
color: var(--r-color-fg);
|
||||
white-space: nowrap;
|
||||
font-variant-numeric: tabular-nums;
|
||||
line-height: 1;
|
||||
}
|
||||
.selection-bar__notch-count {
|
||||
display: inline-block;
|
||||
}
|
||||
.selection-bar__notch::before,
|
||||
.selection-bar__notch::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
bottom: 6px;
|
||||
width: var(--r-notch-fillet);
|
||||
height: var(--r-notch-fillet);
|
||||
pointer-events: none;
|
||||
}
|
||||
.selection-bar__notch::before {
|
||||
/* 1px under the hill, so no hairline survives between the two fills. */
|
||||
right: calc(100% - 1px);
|
||||
background: radial-gradient(
|
||||
circle var(--r-notch-fillet) at top left,
|
||||
transparent 0 var(--r-notch-fillet),
|
||||
var(--r-color-panel) var(--r-notch-fillet)
|
||||
);
|
||||
}
|
||||
.selection-bar__notch::after {
|
||||
left: calc(100% - 1px);
|
||||
background: radial-gradient(
|
||||
circle var(--r-notch-fillet) at top right,
|
||||
transparent 0 var(--r-notch-fillet),
|
||||
var(--r-color-panel) var(--r-notch-fillet)
|
||||
);
|
||||
}
|
||||
|
||||
.selection-bar__count-icon {
|
||||
color: var(--r-color-brand-primary);
|
||||
}
|
||||
|
||||
html[data-bp~="xs"] .selection-bar__count {
|
||||
padding: 0 2px;
|
||||
font-size: var(--r-font-size-sm);
|
||||
}
|
||||
|
||||
/* The count icon is decorative; on xs its width budget goes to the
|
||||
select-all button so the bar still fits a 320px viewport. */
|
||||
html[data-bp~="xs"] .selection-bar__count-icon {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Tighten the action row on phones so all buttons + the count + divider
|
||||
fit a 320px width: squeeze the inter-button gaps and side padding. */
|
||||
/* Tighten the action row on phones so all buttons + the divider fit a 320px
|
||||
width: squeeze the inter-button gaps and side padding. */
|
||||
html[data-bp~="xs"] .selection-bar__panel {
|
||||
gap: 2px;
|
||||
padding: 0 6px;
|
||||
|
||||
@@ -143,7 +143,7 @@ export function getListColumns(showPlatform: boolean): readonly ListColumn[] {
|
||||
|
||||
// Fixed track widths (px) — kept as data so the grid template AND the row's
|
||||
// natural min-width (below) derive from the same numbers.
|
||||
const LIST_SELECT_TRACK_PX = 36;
|
||||
const LIST_SELECT_TRACK_PX = parseInt(layout.listSelectWidth, 10);
|
||||
const LIST_PLATFORM_TRACK_PX = 200;
|
||||
const LIST_METRIC_TRACKS_PX = [88, 96, 96, 56, 72, 110, 110, 88];
|
||||
/** Minimum width of the title column so it stays readable when the row is
|
||||
@@ -160,6 +160,20 @@ export const LIST_TITLE_MIN_PX = 200;
|
||||
// skeleton placeholder paints at the same footprint as the real card.
|
||||
export const LIST_ROW_HEIGHT_PX = parseInt(layout.listRowHeight, 10);
|
||||
export const LIST_HEADER_HEIGHT_PX = parseInt(layout.listHeaderHeight, 10);
|
||||
/** Height a row grows by while its detail panel is open (phones and tablets).
|
||||
* The panel is a fixed three-row grid so this stays exact. */
|
||||
export const LIST_ROW_DETAIL_HEIGHT_PX = parseInt(
|
||||
layout.listRowDetailHeight,
|
||||
10,
|
||||
);
|
||||
|
||||
/** The slot a list row needs with `detailHeight` px of its panel showing:
|
||||
* the panel rolls open, so this lands anywhere between the bare row and the
|
||||
* row plus a full panel. Every surface that virtualises `GameListRow`
|
||||
* reserves its rows with this. */
|
||||
export function listRowHeight(detailHeight = 0): number {
|
||||
return LIST_ROW_HEIGHT_PX + Math.round(detailHeight);
|
||||
}
|
||||
export const LIST_COVER_WIDTH_PX = parseInt(layout.cardArtWidthXs, 10);
|
||||
export const LIST_COVER_HEIGHT_PX = parseInt(layout.cardArtHeightXs, 10);
|
||||
|
||||
|
||||
129
frontend/src/v2/components/Gallery/listRowFixture.ts
Normal file
129
frontend/src/v2/components/Gallery/listRowFixture.ts
Normal file
@@ -0,0 +1,129 @@
|
||||
// Shared list-row fixture: a complete `SimpleRom`, so a new required field
|
||||
// breaks the build instead of hiding behind a cast. Tests override only the
|
||||
// fields they read.
|
||||
import type { RomMetadataSchema, RomUserSchema } from "@/__generated__";
|
||||
import type { SimpleRom } from "@/v2/stores/galleryRoms";
|
||||
|
||||
export const ROM_USER: RomUserSchema = {
|
||||
id: 1,
|
||||
user_id: 1,
|
||||
rom_id: 1,
|
||||
created_at: "2026-01-02T00:00:00Z",
|
||||
updated_at: "2026-01-02T00:00:00Z",
|
||||
last_played: null,
|
||||
is_main_sibling: true,
|
||||
backlogged: false,
|
||||
now_playing: false,
|
||||
hidden: false,
|
||||
rating: 0,
|
||||
difficulty: 0,
|
||||
completion: 0,
|
||||
status: null,
|
||||
};
|
||||
|
||||
export const METADATUM: RomMetadataSchema = {
|
||||
rom_id: 1,
|
||||
genres: [],
|
||||
franchises: [],
|
||||
collections: [],
|
||||
companies: [],
|
||||
publishers: [],
|
||||
developers: [],
|
||||
game_modes: [],
|
||||
age_ratings: [],
|
||||
player_count: "1",
|
||||
first_release_date: Date.UTC(1995, 7, 11),
|
||||
average_rating: 9.1,
|
||||
};
|
||||
|
||||
export const ROM_DEFAULTS: SimpleRom = {
|
||||
id: 1,
|
||||
igdb_id: null,
|
||||
sgdb_id: null,
|
||||
moby_id: null,
|
||||
ss_id: null,
|
||||
ra_id: null,
|
||||
launchbox_id: null,
|
||||
hasheous_id: null,
|
||||
tgdb_id: null,
|
||||
flashpoint_id: null,
|
||||
hltb_id: null,
|
||||
demozoo_id: null,
|
||||
pouet_id: null,
|
||||
csdb_id: null,
|
||||
steam_id: null,
|
||||
gamelist_id: null,
|
||||
libretro_id: null,
|
||||
platform_id: 1,
|
||||
platform_slug: "snes",
|
||||
platform_fs_slug: "snes",
|
||||
platform_custom_name: null,
|
||||
platform_display_name: "Super Nintendo",
|
||||
fs_name: "Chrono Trigger.sfc",
|
||||
fs_name_no_tags: "Chrono Trigger",
|
||||
fs_name_no_ext: "Chrono Trigger",
|
||||
fs_extension: "sfc",
|
||||
fs_path: "snes/Chrono Trigger.sfc",
|
||||
fs_size_bytes: 4_194_304,
|
||||
name: "Chrono Trigger",
|
||||
name_sort_key: "chrono trigger",
|
||||
slug: "chrono-trigger",
|
||||
summary: null,
|
||||
alternative_names: [],
|
||||
youtube_video_id: null,
|
||||
metadatum: METADATUM,
|
||||
igdb_metadata: null,
|
||||
moby_metadata: null,
|
||||
ss_metadata: null,
|
||||
launchbox_metadata: null,
|
||||
hasheous_metadata: null,
|
||||
flashpoint_metadata: null,
|
||||
hltb_metadata: { main_story: 23 },
|
||||
demozoo_metadata: null,
|
||||
pouet_metadata: null,
|
||||
csdb_metadata: null,
|
||||
steam_metadata: null,
|
||||
gamelist_metadata: null,
|
||||
manual_metadata: null,
|
||||
path_cover_small: null,
|
||||
path_cover_large: null,
|
||||
url_cover: null,
|
||||
has_manual: false,
|
||||
has_soundtrack: false,
|
||||
path_manual: null,
|
||||
url_manual: null,
|
||||
path_video: null,
|
||||
is_unidentified: false,
|
||||
is_identified: true,
|
||||
revision: null,
|
||||
regions: ["USA"],
|
||||
languages: ["en"],
|
||||
tags: [],
|
||||
crc_hash: null,
|
||||
md5_hash: null,
|
||||
sha1_hash: null,
|
||||
ra_hash: null,
|
||||
title_id: null,
|
||||
save_target: null,
|
||||
save_target_layout: null,
|
||||
has_simple_single_file: true,
|
||||
has_nested_single_file: false,
|
||||
has_multiple_files: false,
|
||||
full_path: "/romm/library/snes/Chrono Trigger.sfc",
|
||||
created_at: "2026-01-02T00:00:00Z",
|
||||
updated_at: "2026-01-02T00:00:00Z",
|
||||
missing_from_fs: false,
|
||||
is_physical: false,
|
||||
has_file_on_disk: true,
|
||||
upc: null,
|
||||
has_notes: false,
|
||||
rom_user: ROM_USER,
|
||||
merged_screenshots: [],
|
||||
merged_ra_metadata: null,
|
||||
files: [],
|
||||
sibling_roms: [],
|
||||
};
|
||||
|
||||
export function rom(overrides: Partial<SimpleRom> = {}): SimpleRom {
|
||||
return { ...ROM_DEFAULTS, ...overrides };
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { NOTCH_RADIUS_PX, selectionBarOutline } from "./selectionBarOutline";
|
||||
|
||||
const BAR = { w: 375, h: 48 };
|
||||
/** The hill as one digit and as four measure on screen. */
|
||||
const ONE_DIGIT = { w: 39, h: 35 };
|
||||
const FOUR_DIGITS = { w: 61, h: 35 };
|
||||
|
||||
/** Every radius the path arcs on, in the order it draws them. */
|
||||
function radii(d: string): number[] {
|
||||
return [...d.matchAll(/A (\d+(?:\.\d+)?) /g)].map((a) => Number(a[1]));
|
||||
}
|
||||
|
||||
describe("selectionBarOutline", () => {
|
||||
// The fill rounds the hill's top corners by a fixed radius, so a count that
|
||||
// widens the hill must not widen the arc the stroke draws over them.
|
||||
it("rounds the hill by the same radius whatever the count", () => {
|
||||
const one = radii(selectionBarOutline(BAR, ONE_DIGIT)!.d);
|
||||
const four = radii(selectionBarOutline(BAR, FOUR_DIGITS)!.d);
|
||||
|
||||
// Fillet, both hill corners, fillet, then the bar's own two ends.
|
||||
expect(one).toEqual([12, NOTCH_RADIUS_PX, NOTCH_RADIUS_PX, 12, 24, 24]);
|
||||
expect(four).toEqual(one);
|
||||
});
|
||||
|
||||
it("runs the hill's sides straight from its corners into the fillets", () => {
|
||||
const { d } = selectionBarOutline(BAR, FOUR_DIGITS)!;
|
||||
|
||||
// Down to the corner's start, and back up from the far one: the fillets
|
||||
// sit against a straight side rather than part-way around a curve.
|
||||
expect(d).toContain(`V ${NOTCH_RADIUS_PX}`);
|
||||
expect(d).toContain("V 17");
|
||||
});
|
||||
|
||||
it("stands the hill on the bar, less the foot it sinks into it", () => {
|
||||
const outline = selectionBarOutline(BAR, FOUR_DIGITS)!;
|
||||
|
||||
expect(outline.rise).toBe(29);
|
||||
expect(outline.height).toBe(29 + BAR.h);
|
||||
expect(outline.width).toBe(BAR.w);
|
||||
});
|
||||
|
||||
it("keeps the hill's corners inside a hill narrower than them", () => {
|
||||
const narrow = { w: 20, h: 35 };
|
||||
|
||||
expect(radii(selectionBarOutline(BAR, narrow)!.d)).toEqual([
|
||||
12, 10, 10, 12, 24, 24,
|
||||
]);
|
||||
});
|
||||
|
||||
it("draws nothing until both boxes are measured", () => {
|
||||
expect(selectionBarOutline({ w: 0, h: 0 }, FOUR_DIGITS)).toBeNull();
|
||||
expect(selectionBarOutline(BAR, { w: 0, h: 0 })).toBeNull();
|
||||
});
|
||||
|
||||
// The fillets need room between the hill and the bar's rounded end.
|
||||
it("draws nothing where the hill fills the bar", () => {
|
||||
expect(selectionBarOutline(BAR, { w: BAR.w - 10, h: 35 })).toBeNull();
|
||||
});
|
||||
});
|
||||
66
frontend/src/v2/components/Gallery/selectionBarOutline.ts
Normal file
66
frontend/src/v2/components/Gallery/selectionBarOutline.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
// The selection bar, the hill carrying the count and the fillets between them
|
||||
// are three separate fills, so no per-box border can trace their union: the
|
||||
// arcs and the hill's sides are measured from different edges and meet at a
|
||||
// kink. One path over the lot is the only line that closes.
|
||||
|
||||
/** Overlap of the hill's foot into the bar; matches `bottom` in the CSS. */
|
||||
export const NOTCH_OVERLAP_PX = 6;
|
||||
/** Radius of the concave corner where the hill meets the bar. */
|
||||
export const FILLET_PX = 12;
|
||||
// A pill radius would grow with the digits until the hill's sides curved all
|
||||
// the way into the bar, leaving the fillets, which meet a straight side,
|
||||
// nothing to sit against. A fixed one keeps the shape whatever the count.
|
||||
/** Radius over the hill's top corners. */
|
||||
export const NOTCH_RADIUS_PX = 14;
|
||||
|
||||
interface Box {
|
||||
w: number;
|
||||
h: number;
|
||||
}
|
||||
|
||||
export interface Outline {
|
||||
width: number;
|
||||
height: number;
|
||||
/** How far the hill stands above the bar's top edge. */
|
||||
rise: number;
|
||||
d: string;
|
||||
}
|
||||
|
||||
/** The stroke around bar, hill and fillets, or null while either is unmeasured
|
||||
* or too small to carry the shape. */
|
||||
export function selectionBarOutline(bar: Box, notch: Box): Outline | null {
|
||||
const rise = Math.max(0, notch.h - NOTCH_OVERLAP_PX);
|
||||
if (bar.w <= 0 || bar.h <= 0 || notch.w <= 0 || rise <= 0) return null;
|
||||
|
||||
const r = bar.h / 2;
|
||||
const hillR = Math.min(NOTCH_RADIUS_PX, notch.w / 2, rise);
|
||||
// The fillet meets the hill's side below its corner, so it cannot be taller
|
||||
// than the straight run between the two.
|
||||
const f = Math.min(FILLET_PX, (bar.w - notch.w) / 2 - r, rise - hillR);
|
||||
const left = (bar.w - notch.w) / 2;
|
||||
const right = left + notch.w;
|
||||
const bottom = rise + bar.h;
|
||||
if (f <= 0 || rise - f <= 0 || left - f <= r) return null;
|
||||
|
||||
return {
|
||||
width: bar.w,
|
||||
height: bottom,
|
||||
rise,
|
||||
d: [
|
||||
`M ${r} ${rise}`,
|
||||
`H ${left - f}`,
|
||||
`A ${f} ${f} 0 0 0 ${left} ${rise - f}`,
|
||||
`V ${hillR}`,
|
||||
`A ${hillR} ${hillR} 0 0 1 ${left + hillR} 0`,
|
||||
`H ${right - hillR}`,
|
||||
`A ${hillR} ${hillR} 0 0 1 ${right} ${hillR}`,
|
||||
`V ${rise - f}`,
|
||||
`A ${f} ${f} 0 0 0 ${right + f} ${rise}`,
|
||||
`H ${bar.w - r}`,
|
||||
`A ${r} ${r} 0 0 1 ${bar.w - r} ${bottom}`,
|
||||
`H ${r}`,
|
||||
`A ${r} ${r} 0 0 1 ${r} ${rise}`,
|
||||
"Z",
|
||||
].join(" "),
|
||||
};
|
||||
}
|
||||
@@ -338,14 +338,6 @@ function onCardPointerDown(e: PointerEvent) {
|
||||
if (!props.selectable || props.position == null) return;
|
||||
selectionInput.handlePointerDown(props.rom, props.position, e);
|
||||
}
|
||||
function onCardPointerMove(e: PointerEvent) {
|
||||
if (!props.selectable) return;
|
||||
selectionInput.handlePointerMove(e);
|
||||
}
|
||||
function onCardPointerEnd() {
|
||||
if (!props.selectable) return;
|
||||
selectionInput.handlePointerEnd();
|
||||
}
|
||||
|
||||
function onStaticKeydown(e: KeyboardEvent) {
|
||||
// Enter / Space activate the card when it's rendered as a plain
|
||||
@@ -393,6 +385,7 @@ function onStaticKeydown(e: KeyboardEvent) {
|
||||
: undefined
|
||||
"
|
||||
:data-rom-id="rom.id"
|
||||
:data-rom-position="selectable ? position : undefined"
|
||||
:data-focus-key="!decorative && !static ? `rom-${rom.id}` : undefined"
|
||||
@click.capture="onCardClickCapture"
|
||||
@click="onCardClick"
|
||||
@@ -402,9 +395,7 @@ function onStaticKeydown(e: KeyboardEvent) {
|
||||
@focus="onCoverFocus"
|
||||
@blur="onCoverBlur"
|
||||
@pointerdown="onCardPointerDown"
|
||||
@pointermove="onCardPointerMove"
|
||||
@pointerup="onCardPointerEnd"
|
||||
@pointercancel="onCardPointerEnd"
|
||||
@contextmenu="selectionInput.handleContextMenu"
|
||||
>
|
||||
<GameCover
|
||||
ref="coverRef"
|
||||
@@ -539,6 +530,8 @@ function onStaticKeydown(e: KeyboardEvent) {
|
||||
|
||||
<style scoped>
|
||||
.r-gc {
|
||||
/* The long press selects the card; iOS would offer its link callout too. */
|
||||
-webkit-touch-callout: none;
|
||||
flex-shrink: 0;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
// view. Mirrors GameListHeader: shared CSS-grid template with every
|
||||
// row underneath, clickable sortable columns that toggle asc → desc.
|
||||
//
|
||||
// The four metadata columns (Family / Category / Generation / Playable)
|
||||
// drop out on narrow viewports (see the `html[data-bp~="xs"]` rules
|
||||
// below) so the row stays legible on mobile without horizontal scroll.
|
||||
// The grid template flips in the same breakpoint so the cells re-align
|
||||
// with the row's compact layout.
|
||||
// Phones and tablets have no columns to head (the rows go compact), so the
|
||||
// sort key they carried moves into a menu, same as the collections list.
|
||||
import { RIcon } from "@v2/lib";
|
||||
import { computed } from "vue";
|
||||
import ListSortMenu from "@/v2/components/shared/ListSortMenu.vue";
|
||||
import { useBreakpoint } from "@/v2/composables/useBreakpoint";
|
||||
import {
|
||||
PLATFORM_COLUMNS,
|
||||
type PlatformColumn,
|
||||
@@ -26,6 +26,14 @@ const emit = defineEmits<{
|
||||
(e: "sort", payload: { key: PlatformSortKey; dir: "asc" | "desc" }): void;
|
||||
}>();
|
||||
|
||||
const { smAndDown } = useBreakpoint();
|
||||
const sortOptions = computed(() =>
|
||||
PLATFORM_COLUMNS.filter((col) => col.sortable).map((col) => ({
|
||||
key: col.key,
|
||||
label: col.label,
|
||||
})),
|
||||
);
|
||||
|
||||
function handleClick(col: PlatformColumn) {
|
||||
if (!col.sortable) return;
|
||||
const nextDir: "asc" | "desc" =
|
||||
@@ -35,7 +43,20 @@ function handleClick(col: PlatformColumn) {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="plat-list-header" role="row">
|
||||
<div
|
||||
v-if="smAndDown"
|
||||
class="plat-list-header plat-list-header--compact"
|
||||
role="row"
|
||||
>
|
||||
<ListSortMenu
|
||||
:options="sortOptions"
|
||||
:sort-key="sortKey"
|
||||
:sort-dir="sortDir"
|
||||
@sort="emit('sort', $event)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-else class="plat-list-header" role="row">
|
||||
<button
|
||||
v-for="col in PLATFORM_COLUMNS"
|
||||
:key="col.key"
|
||||
@@ -78,10 +99,15 @@ function handleClick(col: PlatformColumn) {
|
||||
gap: 0 var(--r-space-3);
|
||||
padding: 0 var(--r-space-3);
|
||||
height: var(--r-list-header-h);
|
||||
background: var(--r-color-bg-elevated);
|
||||
border-bottom: 1px solid var(--r-color-border);
|
||||
/* Glass so rows scrolling under the pinned header read soft behind it. */
|
||||
backdrop-filter: blur(10px);
|
||||
/* Overridable so a pinned header can run it edge to edge (r-pinned-list-header). */
|
||||
border-bottom: var(--r-list-header-border, 1px solid var(--r-color-border));
|
||||
}
|
||||
|
||||
/* Compact (phones / tablets): one sort control instead of the columns. */
|
||||
.plat-list-header--compact {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 var(--r-row-pad);
|
||||
}
|
||||
|
||||
.plat-list-header__cell {
|
||||
@@ -138,11 +164,4 @@ function handleClick(col: PlatformColumn) {
|
||||
flex-shrink: 0;
|
||||
color: var(--r-color-brand-primary);
|
||||
}
|
||||
|
||||
html[data-bp~="xs"] .plat-list-header {
|
||||
grid-template-columns: minmax(0, 1fr) 96px;
|
||||
}
|
||||
html[data-bp~="xs"] .plat-list-header__cell--meta {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -9,7 +9,9 @@ import { RPlatformIcon } from "@v2/lib";
|
||||
import { computed, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useRouter } from "vue-router";
|
||||
import { useBreakpoint } from "@/v2/composables/useBreakpoint";
|
||||
import { usePlatformPlayable } from "@/v2/composables/usePlatformPlayable";
|
||||
import { useStaggeredEntrance } from "@/v2/composables/useStaggeredEntrance";
|
||||
import {
|
||||
pendingMorphName,
|
||||
useViewTransition,
|
||||
@@ -47,6 +49,12 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
|
||||
const router = useRouter();
|
||||
const { t } = useI18n();
|
||||
// Phones and tablets have no room for the columns: the row goes two-line,
|
||||
// the same shape the collections list takes.
|
||||
const { smAndDown } = useBreakpoint();
|
||||
const rowEl = ref<HTMLElement | null>(null);
|
||||
const { entranceClass, entranceStyle, endEntrance } =
|
||||
useStaggeredEntrance(rowEl);
|
||||
const iconEl = ref<HTMLElement | null>(null);
|
||||
const { morphTransition } = useViewTransition();
|
||||
|
||||
@@ -85,10 +93,63 @@ function onRowClick(e: MouseEvent) {
|
||||
|
||||
<template>
|
||||
<a
|
||||
class="plat-list-row"
|
||||
v-if="smAndDown"
|
||||
ref="rowEl"
|
||||
class="plat-list-row plat-list-row--compact r-list-compact"
|
||||
:class="entranceClass"
|
||||
:style="entranceStyle"
|
||||
:href="href"
|
||||
:aria-label="t('common.open-item', { name: displayName })"
|
||||
@click="onRowClick"
|
||||
@animationend.self="endEntrance"
|
||||
>
|
||||
<div ref="iconEl" class="plat-list-row__thumb" :style="morphStyle">
|
||||
<RPlatformIcon
|
||||
:slug="slug"
|
||||
:fs-slug="fsSlug"
|
||||
:alt="displayName"
|
||||
:size="40"
|
||||
:show-tooltip="false"
|
||||
/>
|
||||
</div>
|
||||
<div class="r-list-compact__stack">
|
||||
<div class="plat-list-row__name">{{ displayName }}</div>
|
||||
<div class="r-list-compact__facts">
|
||||
<span>{{
|
||||
t("collection.games-count", romCount ?? 0, {
|
||||
named: { n: romCount ?? 0 },
|
||||
})
|
||||
}}</span>
|
||||
<template v-if="categoryLabel">
|
||||
<span class="r-list-compact__dot">·</span>
|
||||
<span>{{ categoryLabel }}</span>
|
||||
</template>
|
||||
<template v-if="familyName">
|
||||
<span class="r-list-compact__dot">·</span>
|
||||
<span>{{ familyName }}</span>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<PlayModeBadge
|
||||
v-if="mode"
|
||||
class="plat-list-row__playable"
|
||||
:mode="mode"
|
||||
:emulator="emulator"
|
||||
:stream-label="streamLabel"
|
||||
:size="18"
|
||||
/>
|
||||
</a>
|
||||
|
||||
<a
|
||||
v-else
|
||||
ref="rowEl"
|
||||
class="plat-list-row plat-list-row--columns"
|
||||
:class="entranceClass"
|
||||
:style="entranceStyle"
|
||||
:href="href"
|
||||
:aria-label="t('common.open-item', { name: displayName })"
|
||||
@click="onRowClick"
|
||||
@animationend.self="endEntrance"
|
||||
>
|
||||
<div class="plat-list-row__cell plat-list-row__title">
|
||||
<div ref="iconEl" class="plat-list-row__thumb" :style="morphStyle">
|
||||
@@ -145,12 +206,9 @@ function onRowClick(e: MouseEvent) {
|
||||
</div>
|
||||
|
||||
<div class="plat-list-row__cell plat-list-row__cell--end">
|
||||
<span v-if="romCount != null">
|
||||
{{ romCount }}
|
||||
<span class="plat-list-row__count-unit">{{
|
||||
romCount === 1 ? "game" : "games"
|
||||
}}</span>
|
||||
</span>
|
||||
<span v-if="romCount != null">{{
|
||||
t("collection.games-count", romCount, { named: { n: romCount } })
|
||||
}}</span>
|
||||
<span v-else class="plat-list-row__count-unit">—</span>
|
||||
</div>
|
||||
</a>
|
||||
@@ -162,11 +220,9 @@ function onRowClick(e: MouseEvent) {
|
||||
view's narrative; the row applies it via CSS so the breakpoint
|
||||
switch can override without an inline-style override fight). */
|
||||
.plat-list-row {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) 160px 130px 110px 88px 96px;
|
||||
/* Runs to the screen edges wherever the shell asks for it. */
|
||||
margin-inline: calc(-1 * var(--r-list-bleed, 0px));
|
||||
align-items: center;
|
||||
gap: 0 var(--r-space-3);
|
||||
padding: 0 var(--r-space-3);
|
||||
height: var(--r-list-row-h);
|
||||
border-bottom: 1px solid var(--r-color-border);
|
||||
font-size: var(--r-font-size-md);
|
||||
@@ -180,6 +236,19 @@ function onRowClick(e: MouseEvent) {
|
||||
background: var(--r-color-bg-elevated);
|
||||
}
|
||||
|
||||
/* Kept off the compact row, whose shared flex layout this would outrank. */
|
||||
.plat-list-row--columns {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) 160px 130px 110px 88px 96px;
|
||||
gap: 0 var(--r-space-3);
|
||||
padding: 0 var(--r-space-3);
|
||||
}
|
||||
|
||||
/* Clear of the screen edge, which the row itself runs to. */
|
||||
.plat-list-row--compact .plat-list-row__playable {
|
||||
margin-inline-end: var(--r-space-2);
|
||||
}
|
||||
|
||||
.plat-list-row:focus-visible {
|
||||
outline: none;
|
||||
background: var(--r-color-bg-elevated);
|
||||
@@ -263,11 +332,4 @@ function onRowClick(e: MouseEvent) {
|
||||
.plat-list-row__count-unit {
|
||||
color: var(--r-color-fg-muted);
|
||||
}
|
||||
|
||||
html[data-bp~="xs"] .plat-list-row {
|
||||
grid-template-columns: minmax(0, 1fr) 96px;
|
||||
}
|
||||
html[data-bp~="xs"] .plat-list-row__cell--meta {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -4,6 +4,10 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { defineComponent } from "vue";
|
||||
import PlatformTile from "./PlatformTile.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key, locale: { value: "en" } }),
|
||||
}));
|
||||
|
||||
vi.mock("vue-router", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("vue-router")>()),
|
||||
useRouter: () => ({ push: vi.fn() }),
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// around RPlatformIcon and the shared Tile chrome; not a primitive.
|
||||
import { RPlatformIcon } from "@v2/lib";
|
||||
import { computed, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useRouter } from "vue-router";
|
||||
import Tile from "@/v2/components/shared/Tile.vue";
|
||||
import { usePlatformPlayable } from "@/v2/composables/usePlatformPlayable";
|
||||
@@ -40,6 +41,8 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
|
||||
const href = computed(() => props.to ?? `/platform/${props.id ?? ""}`);
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
// Shared-element morph between the platform tile icon and the
|
||||
// RPlatformIcon shown in the Platform view's InfoPanel cover slot.
|
||||
const router = useRouter();
|
||||
@@ -104,7 +107,7 @@ const { emulator, mode, streamLabel } = usePlatformPlayable(() => props.slug);
|
||||
</template>
|
||||
{{ displayName }}
|
||||
<template v-if="romCount != null" #count>
|
||||
{{ romCount }} {{ romCount === 1 ? "game" : "games" }}
|
||||
{{ t("collection.games-count", romCount, { named: { n: romCount } }) }}
|
||||
</template>
|
||||
</Tile>
|
||||
</template>
|
||||
|
||||
@@ -44,6 +44,8 @@ import {
|
||||
} from "@/v2/components/Gallery/listColumns";
|
||||
import CachedPlatformIcon from "@/v2/components/shared/CachedPlatformIcon.vue";
|
||||
import { useConfirm } from "@/v2/composables/useConfirm";
|
||||
import { useGallerySelectionInput } from "@/v2/composables/useGallerySelectionInput";
|
||||
import { useListExpansion } from "@/v2/composables/useListExpansion";
|
||||
import { useLoadingPhase } from "@/v2/composables/useLoadingPhase";
|
||||
import { useSnackbar } from "@/v2/composables/useSnackbar";
|
||||
import { useTaskCompletion } from "@/v2/composables/useTaskCompletion";
|
||||
@@ -142,10 +144,32 @@ const virtualItems = computed<VItem[]>(() => {
|
||||
return items;
|
||||
});
|
||||
|
||||
function vItemHeight(_item: unknown): number {
|
||||
return LIST_ROW_HEIGHT_PX;
|
||||
// The rows are the gallery's, detail panel and all, so their heights come
|
||||
// from the same place.
|
||||
const listExpansion = useListExpansion();
|
||||
|
||||
function vItemHeight(item: unknown): number {
|
||||
const v = item as VItem;
|
||||
return isListRow(v)
|
||||
? listExpansion.rowHeight(v.position)
|
||||
: LIST_ROW_HEIGHT_PX;
|
||||
}
|
||||
|
||||
// The open row's slot is reserved at its settled height; these are the frames
|
||||
// on the way there (see `useListExpansion`).
|
||||
const expandedIndex = computed(() => {
|
||||
const position = listExpansion.expandedPosition.value;
|
||||
if (position == null) return -1;
|
||||
return virtualItems.value.findIndex(
|
||||
(item) => isListRow(item) && item.position === position,
|
||||
);
|
||||
});
|
||||
const offsetShift = computed(() =>
|
||||
expandedIndex.value < 0
|
||||
? undefined
|
||||
: { fromIndex: expandedIndex.value, px: listExpansion.shiftPx.value },
|
||||
);
|
||||
|
||||
interface VListRow {
|
||||
kind: "list-row";
|
||||
position: number;
|
||||
@@ -211,6 +235,7 @@ function onViewportRange(range: { first: number; last: number }) {
|
||||
// (rows 0..N are visible in both), so the scroller may not re-emit. Sync
|
||||
// immediately against the current viewport so the first window loads.
|
||||
watch(virtualItems, () => {
|
||||
listExpansion.collapse();
|
||||
if (fetchDebounceTimer) {
|
||||
clearTimeout(fetchDebounceTimer);
|
||||
fetchDebounceTimer = null;
|
||||
@@ -267,6 +292,8 @@ onMounted(() => {
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
// A press still in flight would otherwise fire into the next surface.
|
||||
useGallerySelectionInput().cancel();
|
||||
if (fetchDebounceTimer) clearTimeout(fetchDebounceTimer);
|
||||
galleryFilter.setFilterMissing(prevFilterMissing);
|
||||
galleryFilter.setSelectedFilterPlatforms(prevSelectedPlatforms);
|
||||
@@ -369,6 +396,7 @@ onBeforeUnmount(() => {
|
||||
<RVirtualScroller
|
||||
:items="virtualItems"
|
||||
:get-item-height="vItemHeight"
|
||||
:offset-shift="offsetShift"
|
||||
:overscan="25"
|
||||
class="r-v2-missing__scroller"
|
||||
@update:viewport-range="onViewportRange"
|
||||
@@ -378,6 +406,10 @@ onBeforeUnmount(() => {
|
||||
v-if="isListRow(item as VItem)"
|
||||
:position="rowPosition(item)"
|
||||
:webp="supportsWebp"
|
||||
expandable
|
||||
:expanded="listExpansion.isExpanded(rowPosition(item))"
|
||||
:detail-height="listExpansion.panelHeight(rowPosition(item))"
|
||||
@toggle-expand="listExpansion.toggle(rowPosition(item))"
|
||||
/>
|
||||
<GameListSkeletonRow v-else />
|
||||
</template>
|
||||
|
||||
@@ -340,46 +340,7 @@ html[data-bp~="md-and-up"]
|
||||
color: var(--r-color-fav);
|
||||
}
|
||||
|
||||
/* Phones: the title takes the full width and the actions share the subtitle's
|
||||
line; the play button subgrids the row so its text shares their tracks. */
|
||||
html[data-bp~="xs"] .r-v2-stp__row {
|
||||
display: grid;
|
||||
grid-template-columns: auto minmax(0, 1fr) auto;
|
||||
grid-template-rows: 1fr auto auto 1fr;
|
||||
row-gap: 0;
|
||||
}
|
||||
|
||||
html[data-bp~="xs"] .r-v2-stp__row-btn {
|
||||
grid-row: 1 / -1;
|
||||
grid-column: 1 / -1;
|
||||
display: grid;
|
||||
grid-template-columns: subgrid;
|
||||
grid-template-rows: subgrid;
|
||||
row-gap: 0;
|
||||
}
|
||||
|
||||
html[data-bp~="xs"] .r-v2-stp__row-lead {
|
||||
grid-row: 1 / -1;
|
||||
grid-column: 1;
|
||||
}
|
||||
|
||||
html[data-bp~="xs"] .r-v2-stp__row-meta {
|
||||
display: contents;
|
||||
}
|
||||
|
||||
html[data-bp~="xs"] .r-v2-stp__row-title {
|
||||
grid-row: 2;
|
||||
grid-column: 2 / -1;
|
||||
}
|
||||
|
||||
html[data-bp~="xs"] .r-v2-stp__row-subtitle {
|
||||
grid-area: 3 / 2;
|
||||
}
|
||||
|
||||
html[data-bp~="xs"] .r-v2-stp__row-right {
|
||||
grid-area: 3 / 3;
|
||||
}
|
||||
|
||||
/* Phones drop the file size so the title keeps what width it can. */
|
||||
html[data-bp~="xs"] .r-v2-stp__row-duration {
|
||||
min-width: 0;
|
||||
}
|
||||
@@ -387,14 +348,4 @@ html[data-bp~="xs"] .r-v2-stp__row-duration {
|
||||
html[data-bp~="xs"] .r-v2-stp__row-size {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Chrome and Edge below 117 ignore subgrid, so the button's text cannot share
|
||||
the row's tracks there; fall back to the flex row the wider layout uses. */
|
||||
@supports not (grid-template-columns: subgrid) {
|
||||
html[data-bp~="xs"] .r-v2-stp__row,
|
||||
html[data-bp~="xs"] .r-v2-stp__row-btn,
|
||||
html[data-bp~="xs"] .r-v2-stp__row-meta {
|
||||
display: flex;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -59,7 +59,11 @@ const { toolbarHeight, pinned, bindToolbar, bindSentinel } = usePinnedToolbar();
|
||||
<slot name="toolbar" />
|
||||
</div>
|
||||
|
||||
<div v-if="listMode" class="r-v2-idx-shell__list-header">
|
||||
<div
|
||||
v-if="listMode"
|
||||
class="r-v2-idx-shell__list-header"
|
||||
:class="{ 'r-pinned-list-header': pinned }"
|
||||
>
|
||||
<slot name="listHeader" />
|
||||
</div>
|
||||
|
||||
@@ -84,4 +88,21 @@ html[data-bp~="xs"] .r-v2-idx-shell {
|
||||
top: calc(var(--r-nav-h) + var(--r-v2-idx-shell-toolbar-h));
|
||||
z-index: 3;
|
||||
}
|
||||
|
||||
/* Compact list mode: the column header and the rows run to the screen
|
||||
edges, out of the shell's gutter. Each keeps that gutter as its own
|
||||
padding, so only the separators and the row fill reach the edge. */
|
||||
html[data-bp~="sm-and-down"] .r-v2-idx-shell {
|
||||
--r-list-bleed: var(--r-row-pad);
|
||||
}
|
||||
html[data-bp~="sm-and-down"] .r-v2-idx-shell__list-header {
|
||||
margin-inline: calc(-1 * var(--r-list-bleed, 0px));
|
||||
}
|
||||
/* The header already reaches both edges by the margin above, so the pinned
|
||||
glass must not add the gutter a second time: the page has no horizontal
|
||||
clip, and the surplus on the right would scroll the document sideways. */
|
||||
html[data-bp~="sm-and-down"]
|
||||
.r-v2-idx-shell__list-header.r-pinned-list-header::before {
|
||||
inset: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
102
frontend/src/v2/components/shared/ListSortMenu.vue
Normal file
102
frontend/src/v2/components/shared/ListSortMenu.vue
Normal file
@@ -0,0 +1,102 @@
|
||||
<script setup lang="ts" generic="K extends string">
|
||||
// ListSortMenu: the sort control a list header shows once its columns are
|
||||
// gone (phones and tablets). Shared by the gallery, platforms and collections
|
||||
// headers, so the three can't answer "what is this sorted by" three ways.
|
||||
import { RIcon, RMenu, RMenuItem } from "@v2/lib";
|
||||
import { computed } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
const props = defineProps<{
|
||||
options: readonly { key: K; label: string }[];
|
||||
/** Null when the list's order is one the columns don't carry. */
|
||||
sortKey: K | null;
|
||||
sortDir: "asc" | "desc";
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: "sort", payload: { key: K; dir: "asc" | "desc" }): void;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const dirIcon = computed(() =>
|
||||
props.sortDir === "asc" ? "mdi-arrow-up-thin" : "mdi-arrow-down-thin",
|
||||
);
|
||||
// Naming a column the list isn't sorted by would claim a sort that isn't in
|
||||
// effect, so an unknown key falls back to the control's own name.
|
||||
const label = computed(
|
||||
() =>
|
||||
props.options.find((option) => option.key === props.sortKey)?.label ??
|
||||
t("gallery.sort-by"),
|
||||
);
|
||||
|
||||
function pick(key: K) {
|
||||
// Toggle direction when re-picking the active key; otherwise start the new
|
||||
// one ascending, like every other sortable table in the app.
|
||||
const dir: "asc" | "desc" =
|
||||
props.sortKey === key && props.sortDir === "asc" ? "desc" : "asc";
|
||||
emit("sort", { key, dir });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<RMenu location="bottom start" :offset="6" sheet-on-mobile>
|
||||
<template #activator="{ props: activatorProps }">
|
||||
<button v-bind="activatorProps" type="button" class="list-sort-menu">
|
||||
<span class="list-sort-menu__label">{{ label }}</span>
|
||||
<RIcon :icon="dirIcon" size="14" class="list-sort-menu__icon" />
|
||||
</button>
|
||||
</template>
|
||||
<RMenuItem
|
||||
v-for="option in options"
|
||||
:key="option.key"
|
||||
:label="option.label"
|
||||
:variant="sortKey === option.key ? 'active' : 'default'"
|
||||
@click="pick(option.key)"
|
||||
>
|
||||
<template #append>
|
||||
<RIcon
|
||||
v-if="sortKey === option.key"
|
||||
:icon="dirIcon"
|
||||
size="14"
|
||||
class="list-sort-menu__icon"
|
||||
/>
|
||||
</template>
|
||||
</RMenuItem>
|
||||
</RMenu>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* Matches the column-header cells it replaces: same uppercase micro-label,
|
||||
same active tone, same brand-tinted direction glyph. */
|
||||
.list-sort-menu {
|
||||
appearance: none;
|
||||
background: transparent;
|
||||
border: 0;
|
||||
padding: 0;
|
||||
font: inherit;
|
||||
color: var(--r-color-fg);
|
||||
font-size: var(--r-font-size-xs);
|
||||
font-weight: var(--r-font-weight-bold);
|
||||
letter-spacing: 0.07em;
|
||||
text-transform: uppercase;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--r-space-1);
|
||||
min-width: 0;
|
||||
height: 100%;
|
||||
cursor: pointer;
|
||||
text-align: start;
|
||||
border-radius: var(--r-radius-sm);
|
||||
}
|
||||
|
||||
.list-sort-menu__label {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.list-sort-menu__icon {
|
||||
flex-shrink: 0;
|
||||
color: var(--r-color-brand-primary);
|
||||
}
|
||||
</style>
|
||||
@@ -11,16 +11,21 @@
|
||||
// gallery views (Platform / Collection / Search) share one separator
|
||||
// regardless of which header sits above it.
|
||||
import { RTag } from "@v2/lib";
|
||||
import { useAnimatedNumber } from "@/v2/composables/useAnimatedNumber";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
withDefaults(
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
title: string;
|
||||
count?: number | string | null;
|
||||
}>(),
|
||||
{ count: null },
|
||||
);
|
||||
|
||||
// A numeric count rolls up to its value; a string one (a range, a label) is
|
||||
// printed as it comes.
|
||||
const countText = useAnimatedNumber(() => props.count);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -31,7 +36,7 @@ withDefaults(
|
||||
{{ title }}
|
||||
</h1>
|
||||
<slot name="count">
|
||||
<RTag v-if="count != null" :text="count" />
|
||||
<RTag v-if="countText != null" :text="countText" />
|
||||
</slot>
|
||||
</div>
|
||||
<slot />
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Stat — KPI column: big value on top, small uppercase label below.
|
||||
// Feature component; InfoPanel and the gallery hero cards reuse it, but
|
||||
// it's not general enough to be a design-system primitive.
|
||||
import { useAnimatedNumber } from "@/v2/composables/useAnimatedNumber";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
@@ -10,16 +11,20 @@ interface Props {
|
||||
label?: string;
|
||||
}
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
value: undefined,
|
||||
label: undefined,
|
||||
});
|
||||
|
||||
// A count rolls up to its value; anything already formatted (a size, a date)
|
||||
// is printed as it comes.
|
||||
const text = useAnimatedNumber(() => props.value);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="stat">
|
||||
<div class="stat__value">
|
||||
<slot>{{ value }}</slot>
|
||||
<slot>{{ text }}</slot>
|
||||
</div>
|
||||
<div class="stat__label">
|
||||
<slot name="label">{{ label }}</slot>
|
||||
|
||||
63
frontend/src/v2/composables/useAnimatedNumber/index.test.ts
Normal file
63
frontend/src/v2/composables/useAnimatedNumber/index.test.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { computed, effectScope, ref } from "vue";
|
||||
import { useAnimatedNumber } from "./index";
|
||||
|
||||
// Reduced motion lands on the value in one step, which is what makes the
|
||||
// state machine readable without chasing frames.
|
||||
const reduced = ref(true);
|
||||
vi.mock("@/v2/composables/useReducedMotion", () => ({
|
||||
useReducedMotion: () => ({ enabled: computed(() => reduced.value) }),
|
||||
}));
|
||||
|
||||
describe("useAnimatedNumber", () => {
|
||||
it("shows the value it is given", () => {
|
||||
const source = ref<number | null>(42);
|
||||
|
||||
const display = useAnimatedNumber(() => source.value);
|
||||
|
||||
expect(display.value).toBe(42);
|
||||
});
|
||||
|
||||
it("lands exactly on each new value", async () => {
|
||||
const source = ref<number | null>(3);
|
||||
const display = useAnimatedNumber(() => source.value);
|
||||
|
||||
source.value = 88;
|
||||
await Promise.resolve();
|
||||
|
||||
expect(display.value).toBe(88);
|
||||
});
|
||||
|
||||
it("paints a missing value as nothing to roll to", async () => {
|
||||
const source = ref<number | null>(7);
|
||||
const display = useAnimatedNumber(() => source.value);
|
||||
|
||||
source.value = null;
|
||||
await Promise.resolve();
|
||||
|
||||
expect(display.value).toBeNull();
|
||||
});
|
||||
|
||||
it("rolls through the numbers on the way when motion is allowed", async () => {
|
||||
reduced.value = false;
|
||||
const source = ref<number | null>(0);
|
||||
const scope = effectScope();
|
||||
const seen: (string | number | null)[] = [];
|
||||
let display!: ReturnType<typeof useAnimatedNumber>;
|
||||
scope.run(() => {
|
||||
display = useAnimatedNumber(() => source.value, { duration: 60 });
|
||||
});
|
||||
|
||||
source.value = 100;
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
seen.push(display.value);
|
||||
await new Promise((resolve) => setTimeout(resolve, 80));
|
||||
|
||||
// Caught mid-roll it sits between the two, and it finishes on the target.
|
||||
expect(seen[0]).toBeGreaterThan(0);
|
||||
expect(seen[0]).toBeLessThan(100);
|
||||
expect(display.value).toBe(100);
|
||||
scope.stop();
|
||||
reduced.value = true;
|
||||
});
|
||||
});
|
||||
74
frontend/src/v2/composables/useAnimatedNumber/index.ts
Normal file
74
frontend/src/v2/composables/useAnimatedNumber/index.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
// useAnimatedNumber: a count that rolls up to its new value instead of
|
||||
// snapping to it, so a number that changed is a number you noticed.
|
||||
//
|
||||
// Reduced motion comes from `useReducedMotion` rather than the global CSS
|
||||
// guard, which cannot reach a ref driven by requestAnimationFrame.
|
||||
import { onScopeDispose, ref, watch, type Ref } from "vue";
|
||||
import { useReducedMotion } from "@/v2/composables/useReducedMotion";
|
||||
import { motion } from "@/v2/tokens";
|
||||
import { tween } from "@/v2/utils/tween";
|
||||
|
||||
type Source = string | number | null | undefined;
|
||||
|
||||
interface Options {
|
||||
/** Roll duration in ms. Defaults to the `slow` motion token. */
|
||||
duration?: number;
|
||||
/** Decimals kept on the in-between frames (the final value lands exact). */
|
||||
decimals?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Follows `source`, rolling through the numbers on the way. Anything already
|
||||
* formatted (a size, a date, a range) passes straight through, so a caller
|
||||
* can hand over a value it doesn't have to classify first.
|
||||
*/
|
||||
export function useAnimatedNumber(
|
||||
source: () => Source,
|
||||
options: Options = {},
|
||||
): Ref<string | number | null> {
|
||||
const { enabled: reducedMotion } = useReducedMotion();
|
||||
const duration = options.duration ?? parseInt(motion.slow, 10);
|
||||
const decimals = options.decimals ?? 0;
|
||||
const display = ref<string | number | null>(null);
|
||||
let cancel: (() => void) | null = null;
|
||||
|
||||
function stop() {
|
||||
cancel?.();
|
||||
cancel = null;
|
||||
}
|
||||
|
||||
watch(
|
||||
source,
|
||||
(target) => {
|
||||
stop();
|
||||
// Nothing to roll through: a missing value is a dash at the call site,
|
||||
// and a formatted one is already what the caller wants painted.
|
||||
if (target == null || typeof target === "string") {
|
||||
display.value = target ?? null;
|
||||
return;
|
||||
}
|
||||
// The first value rolls up from zero, which is the whole point of the
|
||||
// effect: a count that arrives is a count you watch land.
|
||||
const from = typeof display.value === "number" ? display.value : 0;
|
||||
if (from === target) {
|
||||
display.value = target;
|
||||
return;
|
||||
}
|
||||
cancel = tween({
|
||||
from,
|
||||
to: target,
|
||||
durationMs: reducedMotion.value ? 0 : duration,
|
||||
// Rounding is cosmetic, for the frames in between: a raw tween value
|
||||
// like 1567.4972637 would paint in full and widen the layout mid-roll.
|
||||
onUpdate: (value) => (display.value = Number(value.toFixed(decimals))),
|
||||
// The value it lands on is the caller's, decimals and all.
|
||||
onDone: () => (display.value = target),
|
||||
});
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
onScopeDispose(stop);
|
||||
|
||||
return display;
|
||||
}
|
||||
@@ -0,0 +1,292 @@
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { rom } from "@/v2/components/Gallery/listRowFixture";
|
||||
import storeGalleryRoms from "@/v2/stores/galleryRoms";
|
||||
import storeGallerySelection from "@/v2/stores/gallerySelection";
|
||||
import { edgeSpeed, useGallerySelectionInput } from "./index";
|
||||
|
||||
const LONG_PRESS_MS = 500;
|
||||
|
||||
/** A touch press that starts on `target`, as the row or card would see it. */
|
||||
function pressOn(target: Element): PointerEvent {
|
||||
const event = new PointerEvent("pointerdown", {
|
||||
pointerType: "touch",
|
||||
isPrimary: true,
|
||||
bubbles: true,
|
||||
clientX: 10,
|
||||
clientY: 10,
|
||||
});
|
||||
Object.defineProperty(event, "target", { value: target });
|
||||
return event;
|
||||
}
|
||||
|
||||
/** A bare row element for the press to land on. */
|
||||
function rowEl(): HTMLElement {
|
||||
return document.createElement("a");
|
||||
}
|
||||
|
||||
/** What the drag finds under the finger. happy-dom lays nothing out and has
|
||||
* no `elementsFromPoint`, so the stack is supplied directly. */
|
||||
function stackAt(...els: Element[]) {
|
||||
Object.defineProperty(document, "elementsFromPoint", {
|
||||
value: () => els,
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
|
||||
/** A move of the finger already tracked by the press. The press follows it
|
||||
* on the window, so that is where the tests raise it. */
|
||||
function move(clientX: number, clientY: number): PointerEvent {
|
||||
return new PointerEvent("pointermove", {
|
||||
pointerType: "touch",
|
||||
isPrimary: true,
|
||||
clientX,
|
||||
clientY,
|
||||
});
|
||||
}
|
||||
|
||||
function lift(): PointerEvent {
|
||||
return new PointerEvent("pointerup", { pointerType: "touch" });
|
||||
}
|
||||
|
||||
describe("useGallerySelectionInput long press", () => {
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia());
|
||||
vi.useFakeTimers();
|
||||
});
|
||||
|
||||
it("selects the row when the press lands on the row itself", () => {
|
||||
const input = useGallerySelectionInput();
|
||||
const row = document.createElement("a");
|
||||
|
||||
input.handlePointerDown(rom(), 0, pressOn(row));
|
||||
vi.advanceTimersByTime(LONG_PRESS_MS);
|
||||
|
||||
expect(storeGallerySelection().count).toBe(1);
|
||||
});
|
||||
|
||||
// Holding a chevron, a kebab or a tick is a press on that control; the row
|
||||
// underneath would otherwise select itself behind it.
|
||||
it("ignores a press that lands on a nested control", () => {
|
||||
const input = useGallerySelectionInput();
|
||||
const row = document.createElement("a");
|
||||
const button = document.createElement("button");
|
||||
row.appendChild(button);
|
||||
|
||||
input.handlePointerDown(rom(), 0, pressOn(button));
|
||||
vi.advanceTimersByTime(LONG_PRESS_MS);
|
||||
|
||||
expect(storeGallerySelection().count).toBe(0);
|
||||
});
|
||||
|
||||
it("ignores a press that lands on a tick", () => {
|
||||
const input = useGallerySelectionInput();
|
||||
const row = document.createElement("a");
|
||||
const checkbox = document.createElement("input");
|
||||
checkbox.type = "checkbox";
|
||||
row.appendChild(checkbox);
|
||||
|
||||
input.handlePointerDown(rom(), 0, pressOn(checkbox));
|
||||
vi.advanceTimersByTime(LONG_PRESS_MS);
|
||||
|
||||
expect(storeGallerySelection().count).toBe(0);
|
||||
});
|
||||
|
||||
/** The drag reports the row at `position` as the one under the finger. */
|
||||
function overRow(position: number) {
|
||||
const el = document.createElement("a");
|
||||
el.dataset.romPosition = String(position);
|
||||
stackAt(el);
|
||||
}
|
||||
|
||||
it("selects the rows the drag reaches", () => {
|
||||
const input = useGallerySelectionInput();
|
||||
vi.spyOn(storeGalleryRoms(), "getRomAt").mockImplementation((p: number) =>
|
||||
rom({ id: 100 + p }),
|
||||
);
|
||||
|
||||
input.handlePointerDown(rom({ id: 100 }), 0, pressOn(rowEl()));
|
||||
vi.advanceTimersByTime(LONG_PRESS_MS);
|
||||
overRow(1);
|
||||
window.dispatchEvent(move(20, 40));
|
||||
overRow(2);
|
||||
window.dispatchEvent(move(20, 60));
|
||||
|
||||
expect(storeGallerySelection().count).toBe(3);
|
||||
});
|
||||
|
||||
// Coming back up the list hands back what the drag had taken, so a range
|
||||
// can be corrected without lifting the finger.
|
||||
it("gives a row back when the drag leaves it behind", () => {
|
||||
const input = useGallerySelectionInput();
|
||||
vi.spyOn(storeGalleryRoms(), "getRomAt").mockImplementation((p: number) =>
|
||||
rom({ id: 100 + p }),
|
||||
);
|
||||
|
||||
input.handlePointerDown(rom({ id: 100 }), 0, pressOn(rowEl()));
|
||||
vi.advanceTimersByTime(LONG_PRESS_MS);
|
||||
overRow(3);
|
||||
window.dispatchEvent(move(20, 80));
|
||||
overRow(1);
|
||||
window.dispatchEvent(move(20, 40));
|
||||
|
||||
expect(storeGallerySelection().count).toBe(2);
|
||||
});
|
||||
|
||||
it("leaves a row that was already selected where it was", () => {
|
||||
const input = useGallerySelectionInput();
|
||||
vi.spyOn(storeGalleryRoms(), "getRomAt").mockImplementation((p: number) =>
|
||||
rom({ id: 100 + p }),
|
||||
);
|
||||
storeGallerySelection().selectMany([rom({ id: 102 })]);
|
||||
|
||||
input.handlePointerDown(rom({ id: 100 }), 0, pressOn(rowEl()));
|
||||
vi.advanceTimersByTime(LONG_PRESS_MS);
|
||||
overRow(2);
|
||||
window.dispatchEvent(move(20, 60));
|
||||
overRow(0);
|
||||
window.dispatchEvent(move(20, 20));
|
||||
|
||||
// The anchor and the row the user had picked before the drag started.
|
||||
expect(storeGallerySelection().isSelected(102)).toBe(true);
|
||||
expect(storeGallerySelection().count).toBe(2);
|
||||
});
|
||||
|
||||
it("keeps the row the press started on when the drag returns to it", () => {
|
||||
const input = useGallerySelectionInput();
|
||||
vi.spyOn(storeGalleryRoms(), "getRomAt").mockImplementation((p: number) =>
|
||||
rom({ id: 100 + p }),
|
||||
);
|
||||
|
||||
input.handlePointerDown(rom({ id: 100 }), 0, pressOn(rowEl()));
|
||||
vi.advanceTimersByTime(LONG_PRESS_MS);
|
||||
overRow(2);
|
||||
window.dispatchEvent(move(20, 60));
|
||||
overRow(0);
|
||||
window.dispatchEvent(move(20, 20));
|
||||
|
||||
expect(storeGallerySelection().count).toBe(1);
|
||||
});
|
||||
|
||||
// The bottom nav and the selection bar cover the list's lower edge, which
|
||||
// is where an auto-scrolling drag parks: the row under them still paints.
|
||||
it("paints the row under the chrome floating over it", () => {
|
||||
const input = useGallerySelectionInput();
|
||||
const row = document.createElement("a");
|
||||
const next = document.createElement("a");
|
||||
next.dataset.romPosition = "1";
|
||||
stackAt(document.createElement("div"), next);
|
||||
vi.spyOn(storeGalleryRoms(), "getRomAt").mockReturnValue(rom({ id: 2 }));
|
||||
|
||||
input.handlePointerDown(rom({ id: 1 }), 0, pressOn(row));
|
||||
vi.advanceTimersByTime(LONG_PRESS_MS);
|
||||
window.dispatchEvent(move(20, 40));
|
||||
|
||||
expect(storeGallerySelection().count).toBe(2);
|
||||
});
|
||||
|
||||
it("paints nothing until the press has turned into a long one", () => {
|
||||
const input = useGallerySelectionInput();
|
||||
const row = document.createElement("a");
|
||||
const next = document.createElement("a");
|
||||
next.dataset.romPosition = "1";
|
||||
stackAt(next);
|
||||
|
||||
input.handlePointerDown(rom({ id: 1 }), 0, pressOn(row));
|
||||
window.dispatchEvent(move(200, 400));
|
||||
vi.advanceTimersByTime(LONG_PRESS_MS);
|
||||
|
||||
expect(storeGallerySelection().count).toBe(0);
|
||||
});
|
||||
|
||||
// The row that took the press is recycled out from under a long drag, and
|
||||
// a finger parked at the list's edge sits over the chrome, not over a row:
|
||||
// either way the gesture has to keep coming from the window.
|
||||
it("keeps painting once the pressed row is gone", () => {
|
||||
const input = useGallerySelectionInput();
|
||||
vi.spyOn(storeGalleryRoms(), "getRomAt").mockImplementation((p: number) =>
|
||||
rom({ id: 100 + p }),
|
||||
);
|
||||
const row = rowEl();
|
||||
document.body.appendChild(row);
|
||||
|
||||
input.handlePointerDown(rom({ id: 100 }), 0, pressOn(row));
|
||||
vi.advanceTimersByTime(LONG_PRESS_MS);
|
||||
row.remove();
|
||||
overRow(1);
|
||||
window.dispatchEvent(move(20, 40));
|
||||
|
||||
expect(storeGallerySelection().count).toBe(2);
|
||||
});
|
||||
|
||||
it("drops the gesture when the surface goes away under it", () => {
|
||||
const input = useGallerySelectionInput();
|
||||
|
||||
input.handlePointerDown(rom(), 0, pressOn(rowEl()));
|
||||
input.cancel();
|
||||
vi.advanceTimersByTime(LONG_PRESS_MS);
|
||||
|
||||
expect(storeGallerySelection().count).toBe(0);
|
||||
});
|
||||
|
||||
// Nothing is left listening for a finger that has already lifted.
|
||||
it("stops following the finger once it lifts", () => {
|
||||
const input = useGallerySelectionInput();
|
||||
vi.spyOn(storeGalleryRoms(), "getRomAt").mockImplementation((p: number) =>
|
||||
rom({ id: 100 + p }),
|
||||
);
|
||||
|
||||
input.handlePointerDown(rom({ id: 100 }), 0, pressOn(rowEl()));
|
||||
vi.advanceTimersByTime(LONG_PRESS_MS);
|
||||
window.dispatchEvent(lift());
|
||||
overRow(5);
|
||||
window.dispatchEvent(move(20, 200));
|
||||
|
||||
expect(storeGallerySelection().count).toBe(1);
|
||||
});
|
||||
|
||||
it("leaves the mouse alone", () => {
|
||||
const input = useGallerySelectionInput();
|
||||
const row = document.createElement("a");
|
||||
const event = new PointerEvent("pointerdown", {
|
||||
pointerType: "mouse",
|
||||
isPrimary: true,
|
||||
});
|
||||
Object.defineProperty(event, "target", { value: row });
|
||||
|
||||
input.handlePointerDown(rom(), 0, event);
|
||||
vi.advanceTimersByTime(LONG_PRESS_MS);
|
||||
|
||||
expect(storeGallerySelection().count).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("edgeSpeed", () => {
|
||||
const TOP = 100;
|
||||
const BOTTOM = 700;
|
||||
|
||||
it("stays still away from both edges", () => {
|
||||
expect(edgeSpeed(400, TOP, BOTTOM)).toBe(0);
|
||||
});
|
||||
|
||||
it("pulls up near the top and down near the bottom", () => {
|
||||
expect(edgeSpeed(TOP + 10, TOP, BOTTOM)).toBeLessThan(0);
|
||||
expect(edgeSpeed(BOTTOM - 10, TOP, BOTTOM)).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
// Deeper into the band means faster, so a finger parked at the very edge
|
||||
// pulls hardest and one just inside it barely moves.
|
||||
it("speeds up the deeper into the band the finger goes", () => {
|
||||
const shallow = edgeSpeed(BOTTOM - 60, TOP, BOTTOM);
|
||||
const deep = edgeSpeed(BOTTOM - 5, TOP, BOTTOM);
|
||||
|
||||
expect(deep).toBeGreaterThan(shallow);
|
||||
expect(shallow).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("caps the pull past the edge", () => {
|
||||
expect(edgeSpeed(BOTTOM + 500, TOP, BOTTOM)).toBe(
|
||||
edgeSpeed(BOTTOM, TOP, BOTTOM),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -31,6 +31,11 @@ import storeGallerySelection from "@/v2/stores/gallerySelection";
|
||||
|
||||
const LONG_PRESS_MS = 500;
|
||||
const LONG_PRESS_MOVE_TOLERANCE_PX = 8;
|
||||
/** How close to the scroller's edge the finger has to get before a paint
|
||||
* drag starts pulling the list along, and how fast it pulls at the very
|
||||
* edge. Below that band the drag is a plain paint. */
|
||||
const EDGE_BAND_PX = 72;
|
||||
const EDGE_MAX_SPEED_PX = 14;
|
||||
|
||||
interface LongPressState {
|
||||
romId: number;
|
||||
@@ -45,10 +50,106 @@ interface LongPressState {
|
||||
}
|
||||
|
||||
let longPress: LongPressState | null = null;
|
||||
/** The drag's own selections, keyed by position, so dragging back out of the
|
||||
* range gives them back. Null while no drag is painting. */
|
||||
let painted: Map<number, number> | null = null;
|
||||
/** Where the drag started and how far it has reached: the range it owns is
|
||||
* everything between the two. */
|
||||
let paintAnchor: number | null = null;
|
||||
let paintReach: number | null = null;
|
||||
/** True between a tracked touch going down and coming back up. The long-press
|
||||
* state outlives that, waiting for the click it has to swallow. */
|
||||
let pressActive = false;
|
||||
/** Where the finger is, for the auto-scroll to keep painting from. */
|
||||
let paintPoint: { x: number; y: number } | null = null;
|
||||
let paintScroller: HTMLElement | null = null;
|
||||
/** The stretch of the scroller the list is actually reachable in, measured
|
||||
* past the chrome pinned over it. The bands live at its two ends. */
|
||||
let paintBounds: { top: number; bottom: number } | null = null;
|
||||
let edgeFrame: number | null = null;
|
||||
/** Drops the window listeners the live gesture is tracked through. */
|
||||
let untrackPointer: (() => void) | null = null;
|
||||
|
||||
function stopEdgeScroll() {
|
||||
if (edgeFrame !== null) cancelAnimationFrame(edgeFrame);
|
||||
edgeFrame = null;
|
||||
paintPoint = null;
|
||||
paintScroller = null;
|
||||
paintBounds = null;
|
||||
}
|
||||
|
||||
/** First row found straight down the hit stack, past anything over it. */
|
||||
function rowAt(x: number, y: number): HTMLElement | null {
|
||||
for (const el of document.elementsFromPoint(x, y)) {
|
||||
const host = el.closest<HTMLElement>("[data-rom-position]");
|
||||
if (host) return host;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Where the list stops being covered, at each end: the column header and
|
||||
* toolbar pinned over the top, the nav and the selection bar over the
|
||||
* bottom. Probed rather than named, so no chrome's class name is load
|
||||
* bearing in here, and measured once per drag since it barely moves. */
|
||||
function reachableBounds(
|
||||
scroller: HTMLElement,
|
||||
x: number,
|
||||
): { top: number; bottom: number } {
|
||||
const rect = scroller.getBoundingClientRect();
|
||||
const STEP_PX = 8;
|
||||
// Uncovered means the row is what the finger would touch, not chrome.
|
||||
const uncovered = (y: number) =>
|
||||
document.elementFromPoint(x, y)?.closest("[data-rom-position]") != null;
|
||||
|
||||
let top = rect.top;
|
||||
while (top < rect.bottom && !uncovered(top)) top += STEP_PX;
|
||||
if (top >= rect.bottom) return { top: rect.top, bottom: rect.bottom };
|
||||
|
||||
let bottom = rect.bottom;
|
||||
while (bottom > top && !uncovered(bottom)) bottom -= STEP_PX;
|
||||
return { top, bottom };
|
||||
}
|
||||
|
||||
function resetLongPress() {
|
||||
untrackPointer?.();
|
||||
if (longPress?.timer) clearTimeout(longPress.timer);
|
||||
longPress = null;
|
||||
painted = null;
|
||||
paintAnchor = null;
|
||||
paintReach = null;
|
||||
stopEdgeScroll();
|
||||
}
|
||||
|
||||
/** Nearest ancestor that actually scrolls, which is what the drag pulls. */
|
||||
function scrollableAncestor(el: Element | null): HTMLElement | null {
|
||||
for (let node = el; node instanceof HTMLElement; node = node.parentElement) {
|
||||
const overflowY = getComputedStyle(node).overflowY;
|
||||
if (
|
||||
(overflowY === "auto" || overflowY === "scroll") &&
|
||||
node.scrollHeight > node.clientHeight
|
||||
) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Px to scroll this frame: nothing until the finger enters the edge band,
|
||||
* then proportional to how far into it the finger has gone. Exported for
|
||||
* its own test; the drag itself reads it through `runEdgeScroll`. */
|
||||
export function edgeSpeed(y: number, top: number, bottom: number): number {
|
||||
if (y < top + EDGE_BAND_PX) {
|
||||
return (
|
||||
-EDGE_MAX_SPEED_PX * Math.min(1, (top + EDGE_BAND_PX - y) / EDGE_BAND_PX)
|
||||
);
|
||||
}
|
||||
if (y > bottom - EDGE_BAND_PX) {
|
||||
return (
|
||||
EDGE_MAX_SPEED_PX *
|
||||
Math.min(1, (y - (bottom - EDGE_BAND_PX)) / EDGE_BAND_PX)
|
||||
);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function useGallerySelectionInput() {
|
||||
@@ -100,8 +201,19 @@ export function useGallerySelectionInput() {
|
||||
) {
|
||||
if (event.pointerType !== "touch") return;
|
||||
if (event.isPrimary === false) return;
|
||||
// A press that lands on a control belongs to that control. The row and
|
||||
// the card are an `<a>`, so neither matches this and both still track.
|
||||
const target = event.target;
|
||||
if (
|
||||
target instanceof Element &&
|
||||
target.closest("button, input, select, textarea, [role='menuitem']")
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
resetLongPress();
|
||||
trackPointer();
|
||||
pressActive = true;
|
||||
longPress = {
|
||||
romId: rom.id,
|
||||
position,
|
||||
@@ -120,11 +232,132 @@ export function useGallerySelectionInput() {
|
||||
state.consumed = true;
|
||||
state.timer = null;
|
||||
selection.toggle(rom, position);
|
||||
// Whatever the press selected anchors the drag; it owns nothing yet.
|
||||
painted = new Map();
|
||||
paintAnchor = position;
|
||||
paintReach = position;
|
||||
}, LONG_PRESS_MS);
|
||||
}
|
||||
|
||||
/** Select the row under the finger, if it is one we haven't painted. */
|
||||
function paintAt(clientX: number, clientY: number) {
|
||||
if (!painted) return;
|
||||
// Chrome floats over both ends of the list, and a drag parks its finger
|
||||
// at exactly those ends, so take the row under it rather than the thing
|
||||
// on top of it.
|
||||
const host = rowAt(clientX, clientY);
|
||||
if (!host) return;
|
||||
const position = Number(host.dataset.romPosition);
|
||||
paintScroller ??= scrollableAncestor(host);
|
||||
if (!Number.isInteger(position)) return;
|
||||
reachTo(position);
|
||||
}
|
||||
|
||||
/** Move the drag's far end to `position`: everything now between it and the
|
||||
* anchor is selected, and everything the drag has left behind is given
|
||||
* back. Only the rows this drag selected are ever unselected. */
|
||||
function reachTo(position: number) {
|
||||
if (!painted || paintAnchor === null || paintReach === null) return;
|
||||
if (position === paintReach) return;
|
||||
const low = Math.min(paintAnchor, position);
|
||||
const high = Math.max(paintAnchor, position);
|
||||
// Only the stretch between the old and the new far end can have changed.
|
||||
for (
|
||||
let p = Math.min(paintReach, position);
|
||||
p <= Math.max(paintReach, position);
|
||||
p++
|
||||
) {
|
||||
if (p === paintAnchor) continue;
|
||||
if (p >= low && p <= high) {
|
||||
if (painted.has(p)) continue;
|
||||
const rom = galleryRoms.getRomAt(p);
|
||||
// A row that was already selected is the user's, not the drag's: it
|
||||
// stays put, and leaving it behind must not take it away.
|
||||
if (!rom || selection.isSelected(rom.id)) continue;
|
||||
painted.set(p, rom.id);
|
||||
selection.selectMany([rom]);
|
||||
} else {
|
||||
const id = painted.get(p);
|
||||
if (id === undefined) continue;
|
||||
painted.delete(p);
|
||||
selection.removeIds([id]);
|
||||
}
|
||||
}
|
||||
paintReach = position;
|
||||
}
|
||||
|
||||
/** While the finger sits in the edge band, pull the list past it and keep
|
||||
* painting whatever arrives under it, so a drag can run past one screen. */
|
||||
function runEdgeScroll() {
|
||||
edgeFrame = null;
|
||||
const scroller = paintScroller;
|
||||
const point = paintPoint;
|
||||
if (!painted || !scroller || !point) return;
|
||||
paintBounds ??= reachableBounds(scroller, point.x);
|
||||
const { top, bottom } = paintBounds;
|
||||
const speed = edgeSpeed(point.y, top, bottom);
|
||||
if (speed !== 0) {
|
||||
const before = scroller.scrollTop;
|
||||
scroller.scrollTop += speed;
|
||||
if (scroller.scrollTop !== before) paintAt(point.x, point.y);
|
||||
}
|
||||
edgeFrame = requestAnimationFrame(runEdgeScroll);
|
||||
}
|
||||
|
||||
// The row that took the press unmounts mid-drag whenever the virtualiser
|
||||
// recycles it, and the finger ends a drag over the chrome at the list's
|
||||
// edge rather than over a row. Either way its own events stop arriving, so
|
||||
// the gesture is followed on the window until the finger lifts.
|
||||
function trackPointer() {
|
||||
const move = (event: PointerEvent) => handlePointerMove(event);
|
||||
const end = () => handlePointerEnd();
|
||||
// A painting finger owns the gesture; the page must not scroll under it.
|
||||
const scroll = (event: TouchEvent) => {
|
||||
if (isPainting()) event.preventDefault();
|
||||
};
|
||||
window.addEventListener("pointermove", move, { passive: true });
|
||||
window.addEventListener("pointerup", end, { passive: true });
|
||||
window.addEventListener("pointercancel", end, { passive: true });
|
||||
window.addEventListener("touchmove", scroll, { passive: false });
|
||||
untrackPointer = () => {
|
||||
window.removeEventListener("pointermove", move);
|
||||
window.removeEventListener("pointerup", end);
|
||||
window.removeEventListener("pointercancel", end);
|
||||
window.removeEventListener("touchmove", scroll);
|
||||
untrackPointer = null;
|
||||
};
|
||||
}
|
||||
|
||||
/** Drops a gesture still in flight, for a surface going away under it:
|
||||
* its timer would otherwise select into the gallery that replaced it. */
|
||||
function cancel() {
|
||||
resetLongPress();
|
||||
pressActive = false;
|
||||
}
|
||||
|
||||
/** True while a long press has turned into a drag that paints rows. */
|
||||
function isPainting(): boolean {
|
||||
return painted !== null;
|
||||
}
|
||||
|
||||
/** Suppress the native callout the browser offers on a long press, which
|
||||
* would otherwise cover the selection the press just made. Only a live
|
||||
* touch counts, so a right-click still opens the browser's menu. */
|
||||
function handleContextMenu(event: Event) {
|
||||
if (pressActive) event.preventDefault();
|
||||
}
|
||||
|
||||
function handlePointerMove(event: PointerEvent) {
|
||||
if (!longPress || longPress.consumed) return;
|
||||
if (!longPress) return;
|
||||
// Past the long press, the drag selects every row it crosses. Touch
|
||||
// events stay with the element that got the press, so the row under the
|
||||
// finger is looked up by coordinates.
|
||||
if (longPress.consumed) {
|
||||
paintPoint = { x: event.clientX, y: event.clientY };
|
||||
paintAt(event.clientX, event.clientY);
|
||||
if (edgeFrame === null) edgeFrame = requestAnimationFrame(runEdgeScroll);
|
||||
return;
|
||||
}
|
||||
const dx = Math.abs(event.clientX - longPress.startX);
|
||||
const dy = Math.abs(event.clientY - longPress.startY);
|
||||
if (
|
||||
@@ -136,6 +369,9 @@ export function useGallerySelectionInput() {
|
||||
}
|
||||
|
||||
function handlePointerEnd() {
|
||||
untrackPointer?.();
|
||||
pressActive = false;
|
||||
stopEdgeScroll();
|
||||
// If the timer hasn't fired yet, the press was a normal tap —
|
||||
// cancel so the click event passes through unchanged. If it did
|
||||
// fire (`consumed: true`), keep the state so the synthetic click
|
||||
@@ -146,8 +382,9 @@ export function useGallerySelectionInput() {
|
||||
|
||||
return {
|
||||
handleActivate,
|
||||
handleContextMenu,
|
||||
isPainting,
|
||||
handlePointerDown,
|
||||
handlePointerMove,
|
||||
handlePointerEnd,
|
||||
cancel,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { computed, ref } from "vue";
|
||||
import {
|
||||
LIST_ROW_DETAIL_HEIGHT_PX,
|
||||
LIST_ROW_HEIGHT_PX,
|
||||
} from "@/v2/components/Gallery/listColumns";
|
||||
import { useGalleryVirtualItems, type GalleryItem } from "./index";
|
||||
|
||||
/** Row heights for a three-row list, with row 1's panel settling at `open`. */
|
||||
function rowHeights(open: number): number[] {
|
||||
const { virtualItems, getItemHeight } = useGalleryVirtualItems({
|
||||
layout: ref("list"),
|
||||
groupBy: ref("none"),
|
||||
total: ref(3),
|
||||
charIndex: ref({ a: 0 }),
|
||||
columns: ref(1),
|
||||
loadingInitial: computed(() => false),
|
||||
emptyMessage: ref(""),
|
||||
listSettledDetail: (position: number) => (position === 1 ? open : 0),
|
||||
});
|
||||
return virtualItems.value
|
||||
.filter(
|
||||
(i): i is Extract<GalleryItem, { kind: "list-row" }> =>
|
||||
i.kind === "list-row",
|
||||
)
|
||||
.map((row) => getItemHeight(row));
|
||||
}
|
||||
|
||||
describe("useGalleryVirtualItems: list row with a detail panel", () => {
|
||||
it("keeps every row at the base height while none is open", () => {
|
||||
expect(rowHeights(0)).toEqual([
|
||||
LIST_ROW_HEIGHT_PX,
|
||||
LIST_ROW_HEIGHT_PX,
|
||||
LIST_ROW_HEIGHT_PX,
|
||||
]);
|
||||
});
|
||||
|
||||
it("grows the open row with its panel", () => {
|
||||
expect(rowHeights(LIST_ROW_DETAIL_HEIGHT_PX)).toEqual([
|
||||
LIST_ROW_HEIGHT_PX,
|
||||
LIST_ROW_HEIGHT_PX + LIST_ROW_DETAIL_HEIGHT_PX,
|
||||
LIST_ROW_HEIGHT_PX,
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -38,7 +38,10 @@ import {
|
||||
type MaybeRefOrGetter,
|
||||
type Ref,
|
||||
} from "vue";
|
||||
import { LIST_ROW_HEIGHT_PX } from "@/v2/components/Gallery/listColumns";
|
||||
import {
|
||||
LIST_ROW_HEIGHT_PX,
|
||||
listRowHeight,
|
||||
} from "@/v2/components/Gallery/listColumns";
|
||||
import type { GroupByMode, LayoutMode } from "../useGalleryMode";
|
||||
import type { GalleryItem } from "./types";
|
||||
|
||||
@@ -62,7 +65,6 @@ const DEFAULT_COVER_RATIO = 2 / 3;
|
||||
// * list-row / skeleton-list-row: token-derived `LIST_ROW_HEIGHT_PX`.
|
||||
const FIXED_HEIGHT_BY_KIND: Partial<Record<GalleryItem["kind"], number>> = {
|
||||
"letter-header": 56,
|
||||
"list-row": LIST_ROW_HEIGHT_PX,
|
||||
"skeleton-list-row": LIST_ROW_HEIGHT_PX,
|
||||
"load-more": 80,
|
||||
empty: 240,
|
||||
@@ -152,6 +154,10 @@ interface Options {
|
||||
fallbackRatio?: MaybeRefOrGetter<number>;
|
||||
/** Bump to force a re-pack when measured ratios change (Vue tracks it). */
|
||||
ratioVersion?: Ref<number> | ComputedRef<number>;
|
||||
/** Px of detail panel the list row at `position` settles at (0 for the
|
||||
* rest), so the rows below an open one sit clear of it. The frames on the
|
||||
* way there are the scroller's `offsetShift`, not a height change. */
|
||||
listSettledDetail?: (position: number) => number;
|
||||
}
|
||||
|
||||
const ALPHABET = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ@".split("");
|
||||
@@ -250,9 +256,11 @@ export function useGalleryVirtualItems(opts: Options) {
|
||||
// `unknown` matches RVirtualScroller's generic prop. Row / skeleton-row
|
||||
// share the uniform height; every other kind is fixed.
|
||||
function getItemHeight(item: unknown): number {
|
||||
const { kind } = item as GalleryItem;
|
||||
const entry = item as GalleryItem;
|
||||
const { kind } = entry;
|
||||
if (kind === "row" || kind === "skeleton-row") return rowHeightPx.value;
|
||||
return FIXED_HEIGHT_BY_KIND[kind] ?? 0;
|
||||
if (kind !== "list-row") return FIXED_HEIGHT_BY_KIND[kind] ?? 0;
|
||||
return listRowHeight(opts.listSettledDetail?.(entry.position) ?? 0);
|
||||
}
|
||||
|
||||
// ── Structural sharing across re-packs ────────────────────────────────
|
||||
|
||||
84
frontend/src/v2/composables/useListExpansion/index.test.ts
Normal file
84
frontend/src/v2/composables/useListExpansion/index.test.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { computed } from "vue";
|
||||
import {
|
||||
LIST_ROW_DETAIL_HEIGHT_PX,
|
||||
LIST_ROW_HEIGHT_PX,
|
||||
} from "@/v2/components/Gallery/listColumns";
|
||||
import { useListExpansion } from "./index";
|
||||
|
||||
// Reduced motion skips the roll, so the panel lands on its final height in
|
||||
// one step and the state machine can be read without chasing frames.
|
||||
vi.mock("@/v2/composables/useReducedMotion", () => ({
|
||||
useReducedMotion: () => ({ enabled: computed(() => true) }),
|
||||
}));
|
||||
|
||||
const OPEN_HEIGHT = LIST_ROW_HEIGHT_PX + LIST_ROW_DETAIL_HEIGHT_PX;
|
||||
|
||||
describe("useListExpansion", () => {
|
||||
it("opens a row's panel and gives it the room", () => {
|
||||
const list = useListExpansion();
|
||||
|
||||
list.toggle(3);
|
||||
|
||||
expect(list.isExpanded(3)).toBe(true);
|
||||
expect(list.panelHeight(3)).toBe(LIST_ROW_DETAIL_HEIGHT_PX);
|
||||
expect(list.rowHeight(3)).toBe(OPEN_HEIGHT);
|
||||
});
|
||||
|
||||
it("leaves every other row alone", () => {
|
||||
const list = useListExpansion();
|
||||
|
||||
list.toggle(3);
|
||||
|
||||
expect(list.panelHeight(4)).toBe(0);
|
||||
expect(list.rowHeight(4)).toBe(LIST_ROW_HEIGHT_PX);
|
||||
});
|
||||
|
||||
it("opens one row at a time", () => {
|
||||
const list = useListExpansion();
|
||||
|
||||
list.toggle(3);
|
||||
list.toggle(7);
|
||||
|
||||
expect(list.isExpanded(3)).toBe(false);
|
||||
expect(list.rowHeight(3)).toBe(LIST_ROW_HEIGHT_PX);
|
||||
expect(list.rowHeight(7)).toBe(OPEN_HEIGHT);
|
||||
});
|
||||
|
||||
it("gives the row its height back when it closes", () => {
|
||||
const list = useListExpansion();
|
||||
list.toggle(3);
|
||||
|
||||
list.toggle(3);
|
||||
|
||||
expect(list.isExpanded(3)).toBe(false);
|
||||
expect(list.rowHeight(3)).toBe(LIST_ROW_HEIGHT_PX);
|
||||
});
|
||||
|
||||
// Rows below an open one are pulled back by whatever the panel has yet to
|
||||
// paint, so the two move together without a per-frame height.
|
||||
it("reports no shift once the panel has settled", () => {
|
||||
const list = useListExpansion();
|
||||
|
||||
list.toggle(3);
|
||||
|
||||
expect(list.settledPanelHeight(3)).toBe(LIST_ROW_DETAIL_HEIGHT_PX);
|
||||
expect(list.shiftPx.value).toBe(0);
|
||||
});
|
||||
|
||||
it("reports no shift while nothing is open", () => {
|
||||
const list = useListExpansion();
|
||||
|
||||
expect(list.shiftPx.value).toBe(0);
|
||||
});
|
||||
|
||||
it("drops everything when the list underneath changes", () => {
|
||||
const list = useListExpansion();
|
||||
list.toggle(3);
|
||||
|
||||
list.collapse();
|
||||
|
||||
expect(list.isExpanded(3)).toBe(false);
|
||||
expect(list.rowHeight(3)).toBe(LIST_ROW_HEIGHT_PX);
|
||||
});
|
||||
});
|
||||
101
frontend/src/v2/composables/useListExpansion/index.ts
Normal file
101
frontend/src/v2/composables/useListExpansion/index.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
// useListExpansion: one open detail panel at a time in a list-mode table.
|
||||
//
|
||||
// The panel rolls open like a blind, which only reads right if the rows below
|
||||
// it move with it. They do, but not by animating the row's slot: the offset
|
||||
// table an open row belongs to is O(n) to rebuild, so a per-frame height would
|
||||
// rebuild it on every frame of the roll. Instead the table reserves the
|
||||
// settled height from the moment the row opens, and `shiftPx` carries the
|
||||
// difference for the frames in between (see RVirtualScroller's `offsetShift`).
|
||||
import { computed, onScopeDispose, ref } from "vue";
|
||||
import {
|
||||
LIST_ROW_DETAIL_HEIGHT_PX,
|
||||
listRowHeight,
|
||||
} from "@/v2/components/Gallery/listColumns";
|
||||
import { useReducedMotion } from "@/v2/composables/useReducedMotion";
|
||||
import { motion } from "@/v2/tokens";
|
||||
import { tween } from "@/v2/utils/tween";
|
||||
|
||||
const DURATION_MS = parseInt(motion.med, 10);
|
||||
|
||||
export function useListExpansion() {
|
||||
const { enabled: reducedMotion } = useReducedMotion();
|
||||
/** The row painting a panel, set while it rolls shut too. */
|
||||
const expandedPosition = ref<number | null>(null);
|
||||
/** How much of the panel is currently showing, in px. */
|
||||
const openHeight = ref(0);
|
||||
|
||||
let cancelAnimation: (() => void) | null = null;
|
||||
|
||||
function stopAnimation() {
|
||||
cancelAnimation?.();
|
||||
cancelAnimation = null;
|
||||
}
|
||||
|
||||
function animateTo(target: number, onDone?: () => void) {
|
||||
stopAnimation();
|
||||
cancelAnimation = tween({
|
||||
from: openHeight.value,
|
||||
to: target,
|
||||
durationMs: reducedMotion.value ? 0 : DURATION_MS,
|
||||
onUpdate: (value) => (openHeight.value = value),
|
||||
onDone,
|
||||
});
|
||||
}
|
||||
|
||||
function isExpanded(position: number | null | undefined): boolean {
|
||||
return position != null && expandedPosition.value === position;
|
||||
}
|
||||
|
||||
/** Panel px to paint on the row at `position`, mid-roll included. */
|
||||
function panelHeight(position: number | null | undefined): number {
|
||||
return isExpanded(position) ? openHeight.value : 0;
|
||||
}
|
||||
|
||||
/** What the open row's panel settles at, which is what the offset table
|
||||
* reserves from the moment it opens. */
|
||||
function settledPanelHeight(position: number | null | undefined): number {
|
||||
return isExpanded(position) ? LIST_ROW_DETAIL_HEIGHT_PX : 0;
|
||||
}
|
||||
|
||||
/** Settled height of the row at `position`, panel included when open. */
|
||||
function rowHeight(position: number | null | undefined): number {
|
||||
return listRowHeight(settledPanelHeight(position));
|
||||
}
|
||||
|
||||
/** How far the rows below the open one still are from their settled place:
|
||||
* 0 at rest, down to -LIST_ROW_DETAIL_HEIGHT_PX the moment it opens. */
|
||||
const shiftPx = computed(() =>
|
||||
expandedPosition.value == null
|
||||
? 0
|
||||
: openHeight.value - LIST_ROW_DETAIL_HEIGHT_PX,
|
||||
);
|
||||
|
||||
function toggle(position: number) {
|
||||
if (isExpanded(position)) {
|
||||
animateTo(0, () => (expandedPosition.value = null));
|
||||
return;
|
||||
}
|
||||
expandedPosition.value = position;
|
||||
openHeight.value = 0;
|
||||
animateTo(LIST_ROW_DETAIL_HEIGHT_PX);
|
||||
}
|
||||
|
||||
function collapse() {
|
||||
stopAnimation();
|
||||
expandedPosition.value = null;
|
||||
openHeight.value = 0;
|
||||
}
|
||||
|
||||
onScopeDispose(stopAnimation);
|
||||
|
||||
return {
|
||||
expandedPosition,
|
||||
shiftPx,
|
||||
isExpanded,
|
||||
panelHeight,
|
||||
settledPanelHeight,
|
||||
rowHeight,
|
||||
toggle,
|
||||
collapse,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { nextTick, ref } from "vue";
|
||||
import { useStaggeredEntrance } from "./index";
|
||||
|
||||
type Row = ReturnType<typeof useStaggeredEntrance>;
|
||||
|
||||
/** A row whose root sits at `slot` among `container`'s children. */
|
||||
function rowAt(container: HTMLElement, slot: number, ready?: () => boolean) {
|
||||
const el = document.createElement("a");
|
||||
container.insertBefore(el, container.children[slot] ?? null);
|
||||
return useStaggeredEntrance(ref(el), ready);
|
||||
}
|
||||
|
||||
function list(): HTMLElement {
|
||||
const container = document.createElement("div");
|
||||
document.body.appendChild(container);
|
||||
return container;
|
||||
}
|
||||
|
||||
/** The stagger slot a row was given, as its style hands it to the CSS. */
|
||||
function slot(row: Row): number {
|
||||
return row.entranceStyle.value["--asset-fade-i"];
|
||||
}
|
||||
|
||||
function fading(row: Row): boolean {
|
||||
return row.entranceClass.value["r-v2-asset-fade"];
|
||||
}
|
||||
|
||||
/** Lets the tick's arrivals settle into their ranks. */
|
||||
async function settle() {
|
||||
await Promise.resolve();
|
||||
await nextTick();
|
||||
}
|
||||
|
||||
describe("useStaggeredEntrance", () => {
|
||||
it("plays the entrance on a row that mounts with its content", async () => {
|
||||
const row = rowAt(list(), 0);
|
||||
await settle();
|
||||
|
||||
expect(fading(row)).toBe(true);
|
||||
expect(slot(row)).toBe(0);
|
||||
});
|
||||
|
||||
// Vue mounts a keyed batch bottom-up; the cascade still runs top-down.
|
||||
it("cascades a batch in the order it sits on screen", async () => {
|
||||
const container = list();
|
||||
const third = rowAt(container, 0);
|
||||
const second = rowAt(container, 0);
|
||||
const first = rowAt(container, 0);
|
||||
await settle();
|
||||
|
||||
expect([first, second, third].map(slot)).toEqual([0, 1, 2]);
|
||||
});
|
||||
|
||||
it("starts a lone later arrival without a delay", async () => {
|
||||
const container = list();
|
||||
rowAt(container, 0);
|
||||
rowAt(container, 1);
|
||||
await settle();
|
||||
|
||||
const late = rowAt(container, 2);
|
||||
await settle();
|
||||
|
||||
expect(slot(late)).toBe(0);
|
||||
});
|
||||
|
||||
it("stops lengthening the cascade past the rows a screen holds", async () => {
|
||||
const container = list();
|
||||
const rows = Array.from({ length: 20 }, (_, i) => rowAt(container, i));
|
||||
await settle();
|
||||
|
||||
expect(slot(rows[19])).toBe(12);
|
||||
});
|
||||
|
||||
it("waits for the row's content before playing", async () => {
|
||||
const ready = ref(false);
|
||||
const row = rowAt(list(), 0, () => ready.value);
|
||||
|
||||
expect(fading(row)).toBe(false);
|
||||
|
||||
ready.value = true;
|
||||
await settle();
|
||||
|
||||
expect(fading(row)).toBe(true);
|
||||
});
|
||||
|
||||
// A re-sort re-inserts keyed rows, which would restart a class still set.
|
||||
it("drops the class once the entrance has played", async () => {
|
||||
const row = rowAt(list(), 0);
|
||||
await settle();
|
||||
|
||||
row.endEntrance();
|
||||
|
||||
expect(fading(row)).toBe(false);
|
||||
});
|
||||
});
|
||||
69
frontend/src/v2/composables/useStaggeredEntrance/index.ts
Normal file
69
frontend/src/v2/composables/useStaggeredEntrance/index.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
// useStaggeredEntrance: plays `.r-v2-asset-fade` on a row once its content is
|
||||
// ready. Rows turning ready in the same tick cascade top to bottom; a row
|
||||
// scrolled into view on its own fades in without waiting behind the others.
|
||||
import { computed, type Ref, ref, watch } from "vue";
|
||||
|
||||
/** Past this many rows the cascade stops lengthening; they are offscreen. */
|
||||
const MAX_STAGGER = 12;
|
||||
|
||||
interface Arrival {
|
||||
el: Ref<HTMLElement | null>;
|
||||
index: Ref<number>;
|
||||
}
|
||||
|
||||
let batch: Arrival[] = [];
|
||||
|
||||
// Ranked once the tick's render has placed every row: Vue mounts a keyed
|
||||
// batch bottom-up, so arrival order is no guide to the order on screen.
|
||||
function settleBatch() {
|
||||
const arrivals = batch;
|
||||
batch = [];
|
||||
arrivals.sort(byDocumentOrder).forEach((arrival, rank) => {
|
||||
arrival.index.value = Math.min(rank, MAX_STAGGER);
|
||||
});
|
||||
}
|
||||
|
||||
function byDocumentOrder(a: Arrival, b: Arrival): number {
|
||||
const first = a.el.value;
|
||||
const second = b.el.value;
|
||||
if (!first || !second) return 0;
|
||||
return first.compareDocumentPosition(second) &
|
||||
Node.DOCUMENT_POSITION_FOLLOWING
|
||||
? -1
|
||||
: 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Args:
|
||||
* el: the row's root element.
|
||||
* ready: whether the row has its content; the entrance plays each time it
|
||||
* turns true. Omit it for a row that mounts with its content.
|
||||
*/
|
||||
export function useStaggeredEntrance(
|
||||
el: Ref<HTMLElement | null>,
|
||||
ready: () => boolean = () => true,
|
||||
) {
|
||||
const entering = ref(false);
|
||||
const index = ref(0);
|
||||
|
||||
watch(
|
||||
ready,
|
||||
(isReady) => {
|
||||
if (!isReady) return;
|
||||
if (batch.length === 0) queueMicrotask(settleBatch);
|
||||
batch.push({ el, index });
|
||||
entering.value = true;
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
return {
|
||||
entranceClass: computed(() => ({ "r-v2-asset-fade": entering.value })),
|
||||
entranceStyle: computed(() => ({ "--asset-fade-i": index.value })),
|
||||
/** Drops the class once it has played, so a keyed move (a re-sort)
|
||||
* re-inserting the row doesn't replay it. Bind with `.self`. */
|
||||
endEntrance: () => {
|
||||
entering.value = false;
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -430,6 +430,27 @@ const hasLabel = computed(
|
||||
0 0 16px color-mix(in srgb, var(--r-cb-fill) 40%, transparent);
|
||||
}
|
||||
|
||||
/* The inset top highlight reads as a sheen across a flat edge, but on a
|
||||
circle it follows the curve and lands as a white arc over the fill. The
|
||||
round variant keeps the glow and drops the highlight. */
|
||||
.r-checkbox--shape-circle.r-checkbox--checked .r-checkbox__box,
|
||||
.r-checkbox--shape-circle.r-checkbox--indeterminate .r-checkbox__box,
|
||||
.r-checkbox--shape-circle.r-checkbox--multi-active .r-checkbox__box {
|
||||
box-shadow: 0 0 12px color-mix(in srgb, var(--r-cb-fill) 32%, transparent);
|
||||
}
|
||||
.r-checkbox--shape-circle.r-checkbox--checked:not(.r-checkbox--disabled):hover
|
||||
.r-checkbox__box,
|
||||
.r-checkbox--shape-circle.r-checkbox--indeterminate:not(
|
||||
.r-checkbox--disabled
|
||||
):hover
|
||||
.r-checkbox__box,
|
||||
.r-checkbox--shape-circle.r-checkbox--multi-active:not(
|
||||
.r-checkbox--disabled
|
||||
):hover
|
||||
.r-checkbox__box {
|
||||
box-shadow: 0 0 16px color-mix(in srgb, var(--r-cb-fill) 40%, transparent);
|
||||
}
|
||||
|
||||
/* ── Glyph (check / minus) — drawn-in stroke ──────────────────── */
|
||||
/* SVG icon — sized to the per-size --r-cb-icon var, color inherits
|
||||
white from the box. Always mounted (so the path animations have a
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { flushPromises, mount } from "@vue/test-utils";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { ref } from "vue";
|
||||
import RMenu from "./RMenu.vue";
|
||||
|
||||
const modality = ref<"mouse" | "key">("mouse");
|
||||
vi.mock("@/v2/composables/useInputModality", () => ({
|
||||
useInputModality: () => ({ modality }),
|
||||
}));
|
||||
|
||||
function mountMenu() {
|
||||
return mount(RMenu, {
|
||||
attachTo: document.body,
|
||||
@@ -31,4 +37,28 @@ describe("RMenu", () => {
|
||||
expect(wrapper.emitted("close")).toHaveLength(1);
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
// A panel whose content is not RMenuItems (the gallery's letter grid) would
|
||||
// otherwise open with nothing focused and no cell for the arrows to leave.
|
||||
it("opens on the first `initialFocus` selector that matches", async () => {
|
||||
modality.value = "key";
|
||||
const wrapper = mount(RMenu, {
|
||||
attachTo: document.body,
|
||||
props: { initialFocus: [".missing", ".pick-me"] },
|
||||
slots: {
|
||||
activator: `<template #activator="{ props }"><button type="button" class="trigger" v-bind="props">Open</button></template>`,
|
||||
default: `<button type="button" class="skip-me">A</button><button type="button" class="pick-me">B</button>`,
|
||||
},
|
||||
});
|
||||
|
||||
await wrapper.find("button.trigger").trigger("click");
|
||||
await flushPromises();
|
||||
await new Promise<void>((resolve) =>
|
||||
requestAnimationFrame(() => resolve()),
|
||||
);
|
||||
|
||||
expect(document.activeElement).toBe(document.querySelector(".pick-me"));
|
||||
modality.value = "mouse";
|
||||
wrapper.unmount();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -87,6 +87,10 @@ interface Props {
|
||||
width?: string | number;
|
||||
/** Cap the panel height — body scrolls beyond it. */
|
||||
maxHeight?: string | number;
|
||||
/** Selectors for what to focus when the panel opens from a keyboard or a
|
||||
* pad, tried in order. Defaults to the first menu item, which is wrong for
|
||||
* a panel whose content is not `RMenuItem`s. */
|
||||
initialFocus?: string | readonly string[];
|
||||
/** Render a sticky search input at the top. */
|
||||
searchable?: boolean;
|
||||
/** v-model:search — current query string. */
|
||||
@@ -116,6 +120,7 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
offset: 8,
|
||||
width: undefined,
|
||||
maxHeight: undefined,
|
||||
initialFocus: undefined,
|
||||
searchable: false,
|
||||
search: "",
|
||||
searchPlaceholder: "",
|
||||
@@ -399,6 +404,21 @@ const mergedContentClass = computed(() =>
|
||||
// natively focusable, but the panel itself doesn't react to ArrowUp /
|
||||
// ArrowDown. Add a panel-level handler so D-pad / left-stick (mapped to
|
||||
// arrows by `useGamepad`) cycle through the items.
|
||||
/** First match of `initialFocus`, in the order the caller listed them. */
|
||||
function initialFocusTarget(): HTMLElement | null {
|
||||
const panel = panelRef.value;
|
||||
if (!panel || !props.initialFocus) return null;
|
||||
const selectors =
|
||||
typeof props.initialFocus === "string"
|
||||
? [props.initialFocus]
|
||||
: props.initialFocus;
|
||||
for (const selector of selectors) {
|
||||
const match = panel.querySelector<HTMLElement>(selector);
|
||||
if (match) return match;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function focusableMenuItems(): HTMLElement[] {
|
||||
const panel = panelRef.value;
|
||||
if (!panel) return [];
|
||||
@@ -449,8 +469,7 @@ watch(
|
||||
await new Promise<void>((resolve) =>
|
||||
requestAnimationFrame(() => resolve()),
|
||||
);
|
||||
const items = focusableMenuItems();
|
||||
items[0]?.focus();
|
||||
(initialFocusTarget() ?? focusableMenuItems()[0])?.focus();
|
||||
},
|
||||
);
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import { mount } from "@vue/test-utils";
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import { nextTick } from "vue";
|
||||
import RVirtualScroller from "./RVirtualScroller.vue";
|
||||
|
||||
const ROW_H = 100;
|
||||
const VIEWPORT_H = 500;
|
||||
|
||||
// happy-dom lays nothing out, so the scroller would measure a 0-high viewport
|
||||
// and render no rows at all.
|
||||
const clientHeight = Object.getOwnPropertyDescriptor(
|
||||
HTMLElement.prototype,
|
||||
"clientHeight",
|
||||
);
|
||||
beforeAll(() => {
|
||||
Object.defineProperty(HTMLElement.prototype, "clientHeight", {
|
||||
configurable: true,
|
||||
get: () => VIEWPORT_H,
|
||||
});
|
||||
});
|
||||
afterAll(() => {
|
||||
if (clientHeight) {
|
||||
Object.defineProperty(HTMLElement.prototype, "clientHeight", clientHeight);
|
||||
}
|
||||
});
|
||||
const items = Array.from({ length: 5 }, (_, id) => ({ id }));
|
||||
|
||||
async function mountScroller(offsetShift?: { fromIndex: number; px: number }) {
|
||||
const wrapper = mount(RVirtualScroller, {
|
||||
attachTo: document.body,
|
||||
props: {
|
||||
items,
|
||||
getItemHeight: () => ROW_H,
|
||||
height: VIEWPORT_H,
|
||||
offsetShift,
|
||||
},
|
||||
slots: { default: `<div class="row" />` },
|
||||
});
|
||||
// The viewport is measured on mount, so the first render has no rows yet.
|
||||
await nextTick();
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
type Scroller = Awaited<ReturnType<typeof mountScroller>>;
|
||||
|
||||
/** Each rendered row's y, read off the transform the scroller writes. */
|
||||
function tops(wrapper: Scroller): number[] {
|
||||
return wrapper.findAll(".r-virtual-scroller__item").map((el) => {
|
||||
const match = /translateY\((-?[\d.]+)px\)/.exec(
|
||||
el.attributes("style") ?? "",
|
||||
);
|
||||
return Number(match?.[1]);
|
||||
});
|
||||
}
|
||||
|
||||
function innerHeight(wrapper: Scroller): number {
|
||||
const style = wrapper.get(".r-virtual-scroller__inner").attributes("style");
|
||||
return Number(/height:\s*(-?[\d.]+)px/.exec(style ?? "")?.[1]);
|
||||
}
|
||||
|
||||
describe("RVirtualScroller offsetShift", () => {
|
||||
it("stacks the rows on their own heights without one", async () => {
|
||||
const wrapper = await mountScroller();
|
||||
|
||||
expect(tops(wrapper)).toEqual([0, 100, 200, 300, 400]);
|
||||
expect(innerHeight(wrapper)).toBe(500);
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
// A row animating towards a height the table already reserves: everything
|
||||
// after it is pulled back by what it has yet to paint, and the content
|
||||
// shrinks to match, so nothing below the row jumps when it settles.
|
||||
it("pulls back only the rows after `fromIndex`", async () => {
|
||||
const wrapper = await mountScroller({ fromIndex: 1, px: -40 });
|
||||
|
||||
expect(tops(wrapper)).toEqual([0, 100, 160, 260, 360]);
|
||||
expect(innerHeight(wrapper)).toBe(460);
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it("leaves the rows alone once the shift is back to zero", async () => {
|
||||
const wrapper = await mountScroller({ fromIndex: 1, px: 0 });
|
||||
|
||||
expect(tops(wrapper)).toEqual([0, 100, 200, 300, 400]);
|
||||
expect(innerHeight(wrapper)).toBe(500);
|
||||
wrapper.unmount();
|
||||
});
|
||||
});
|
||||
@@ -51,6 +51,11 @@ interface Props {
|
||||
* are cached in an offset table; if a height value depends on dynamic
|
||||
* state, bump items by reference to force a recompute. */
|
||||
getItemHeight: (item: unknown, index: number) => number;
|
||||
/** A pixel shift applied to every item after `fromIndex`, on top of the
|
||||
* offset table. For a row animating towards a height `getItemHeight`
|
||||
* already reports settled: the table stays structural and only this scalar
|
||||
* changes per frame, instead of an O(n) rebuild on each one. */
|
||||
offsetShift?: { fromIndex: number; px: number };
|
||||
/** Returns a stable key for an item. Defaults to the array index, which
|
||||
* re-patches every row in place when items are inserted at the front —
|
||||
* pass a content-stable key (e.g. an id) so insertions only mount the
|
||||
@@ -73,6 +78,7 @@ interface Props {
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
overscan: 25,
|
||||
height: undefined,
|
||||
offsetShift: undefined,
|
||||
getItemKey: undefined,
|
||||
minContentWidth: undefined,
|
||||
});
|
||||
@@ -110,9 +116,17 @@ const offsets = computed<number[]>(() => {
|
||||
return out;
|
||||
});
|
||||
|
||||
/** Top-y of item `i`, with the transient shift folded in. The shift never
|
||||
* reorders the table: it only ever pulls the rows below a growing item back
|
||||
* towards it, by less than that item has already grown. */
|
||||
function offsetAt(offs: number[], i: number): number {
|
||||
const shift = props.offsetShift;
|
||||
return offs[i] + (shift && i > shift.fromIndex ? shift.px : 0);
|
||||
}
|
||||
|
||||
const totalHeight = computed(() => {
|
||||
const offs = offsets.value;
|
||||
return offs[offs.length - 1] ?? 0;
|
||||
return offsetAt(offs, offs.length - 1);
|
||||
});
|
||||
|
||||
// `innerOffsetTop` — distance from the scroller's content top to the
|
||||
@@ -129,7 +143,7 @@ function findFirstVisible(offs: number[], top: number): number {
|
||||
if (hi < 0) return 0;
|
||||
while (lo < hi) {
|
||||
const mid = (lo + hi) >> 1;
|
||||
if (offs[mid + 1] > top) hi = mid;
|
||||
if (offsetAt(offs, mid + 1) > top) hi = mid;
|
||||
else lo = mid + 1;
|
||||
}
|
||||
return lo;
|
||||
@@ -141,7 +155,7 @@ function findLastVisible(offs: number[], bottom: number): number {
|
||||
if (hi < 0) return -1;
|
||||
while (lo < hi) {
|
||||
const mid = (lo + hi + 1) >> 1; // bias up to terminate
|
||||
if (offs[mid] < bottom) lo = mid;
|
||||
if (offsetAt(offs, mid) < bottom) lo = mid;
|
||||
else hi = mid - 1;
|
||||
}
|
||||
return lo;
|
||||
@@ -190,7 +204,7 @@ const renderedItems = computed<RenderedEntry[]>(() => {
|
||||
out.push({
|
||||
item: items[i],
|
||||
index: i,
|
||||
top: offs[i],
|
||||
top: offsetAt(offs, i),
|
||||
key: props.getItemKey ? props.getItemKey(items[i], i) : i,
|
||||
});
|
||||
}
|
||||
@@ -279,7 +293,7 @@ function scrollToIndex(index: number, options: ScrollToIndexOptions = {}) {
|
||||
if (!root) return;
|
||||
const offs = offsets.value;
|
||||
if (index < 0 || index >= offs.length - 1) return;
|
||||
const itemTop = offs[index];
|
||||
const itemTop = offsetAt(offs, index);
|
||||
if (!Number.isFinite(itemTop)) return;
|
||||
const stickyOffset = options.stickyOffset ?? 0;
|
||||
// The item's flow top in the scroller is `innerOffsetTop + itemTop`.
|
||||
@@ -292,7 +306,7 @@ function scrollToIndex(index: number, options: ScrollToIndexOptions = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ scrollToIndex, containerEl, scrollTop });
|
||||
defineExpose({ scrollToIndex, containerEl, scrollTop, innerOffsetTop });
|
||||
|
||||
const minContentWidthCss = computed(() => {
|
||||
const w = props.minContentWidth;
|
||||
|
||||
@@ -5,7 +5,9 @@ import storeGalleryFilter from "@/stores/galleryFilter";
|
||||
import storePlatforms, { type Platform } from "@/stores/platforms";
|
||||
// Import after the mock so the store binds to the mocked rom API.
|
||||
import storeGalleryRoms, {
|
||||
orderSupportsLetters,
|
||||
SELECT_ALL_PAGE_SIZE,
|
||||
type GalleryOrderKey,
|
||||
} from "@/v2/stores/galleryRoms";
|
||||
|
||||
const { getRoms } = vi.hoisted(() => ({ getRoms: vi.fn() }));
|
||||
@@ -474,3 +476,25 @@ describe("galleryRoms length filter", () => {
|
||||
expect(getRoms.mock.calls[0][0].hltbMainStoryMax).toBe(10 * 3600);
|
||||
});
|
||||
});
|
||||
|
||||
describe("orderSupportsLetters", () => {
|
||||
// The backend indexes first letters off a text column only, so every other
|
||||
// order answers with an empty char_index. Spelling out every key means a new
|
||||
// sort key fails here until someone says which kind it is.
|
||||
const EXPECTED: Record<GalleryOrderKey, boolean> = {
|
||||
name: true,
|
||||
fs_name: true,
|
||||
platform_id: false,
|
||||
fs_size_bytes: false,
|
||||
created_at: false,
|
||||
updated_at: false,
|
||||
first_release_date: false,
|
||||
average_rating: false,
|
||||
hltb_main_story: false,
|
||||
last_played: false,
|
||||
};
|
||||
|
||||
it.each(Object.entries(EXPECTED))("answers for %s", (key, expected) => {
|
||||
expect(orderSupportsLetters(key as GalleryOrderKey)).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -69,6 +69,15 @@ export function isGalleryOrderKey(value: string): value is GalleryOrderKey {
|
||||
return (GALLERY_ORDER_KEYS as readonly string[]).includes(value);
|
||||
}
|
||||
|
||||
/** The keys the backend answers with a `char_index`: it indexes first letters
|
||||
* only for a text column. Listed rather than read off an empty `charIndex`,
|
||||
* which is also what an unfetched gallery looks like. */
|
||||
const LEXICAL_ORDER_KEYS: ReadonlySet<string> = new Set(["name", "fs_name"]);
|
||||
|
||||
export function orderSupportsLetters(key: GalleryOrderKey): boolean {
|
||||
return LEXICAL_ORDER_KEYS.has(key);
|
||||
}
|
||||
|
||||
export function isGalleryOrderDir(value: string): value is GalleryOrderDir {
|
||||
return value === "asc" || value === "desc";
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ html[data-bp~="sm-and-down"].r-v2 {
|
||||
}
|
||||
html[data-bp~="xs"].r-v2 {
|
||||
--r-row-pad: 14px;
|
||||
/* List mode: a tighter tick column, so the table spends its width on data. */
|
||||
--r-list-select-w: 24px;
|
||||
}
|
||||
|
||||
/* The nav chrome unmounts while a player stage owns the viewport, so its
|
||||
@@ -313,8 +315,9 @@ html.r-v2-reduced-motion *::after {
|
||||
color: var(--r-color-fg-muted);
|
||||
}
|
||||
|
||||
/* Top-bar glass, shared with the toolbars that pin under it. Reduced motion
|
||||
swaps the blur (costly, murky over its solid background) for a flat bg. */
|
||||
/* Top-bar glass, shared with the toolbars and list column headers that pin
|
||||
under it. Reduced motion swaps the blur (costly, murky over its solid
|
||||
background) for a flat bg. */
|
||||
.r-v2 {
|
||||
--r-glass-bar-bg: color-mix(in srgb, var(--r-color-bg) 78%, transparent);
|
||||
--r-glass-bar-filter: blur(20px);
|
||||
@@ -346,6 +349,57 @@ html.r-v2-reduced-motion {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* List column header once pinned: the same glass, edge to edge, with its
|
||||
border moved onto it. Goes on the sticky element, which anchors the glass. */
|
||||
.r-pinned-list-header {
|
||||
--r-list-header-border: 0;
|
||||
}
|
||||
.r-pinned-list-header::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0 calc(-1 * var(--r-row-pad));
|
||||
z-index: -1;
|
||||
background: var(--r-glass-bar-bg);
|
||||
backdrop-filter: var(--r-glass-bar-filter);
|
||||
border-bottom: 1px solid var(--r-color-border);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Compact list rows (phones and tablets): the anatomy the gallery, the
|
||||
platforms and collections indexes and the loading placeholder all share.
|
||||
Per-surface deltas (a row's height and border, a clamped title) stay in the
|
||||
component. */
|
||||
.r-list-compact {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--r-space-3);
|
||||
padding: 0 var(--r-row-pad);
|
||||
}
|
||||
.r-list-compact__stack {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
gap: 3px;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.r-list-compact__facts {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
font-size: var(--r-font-size-sm);
|
||||
color: var(--r-color-fg-muted);
|
||||
min-width: 0;
|
||||
}
|
||||
.r-list-compact__facts > span {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.r-list-compact__dot {
|
||||
color: var(--r-color-fg-faint);
|
||||
}
|
||||
|
||||
/* Column both gallery Settings tabs (platform, collection) render in, so they
|
||||
share one width. */
|
||||
.r-settings-column {
|
||||
|
||||
@@ -156,9 +156,10 @@
|
||||
--r-coll-cover-w-xs: 150px;
|
||||
--r-coll-cover-h-xs: 202px;
|
||||
--r-alpha-strip-w: 24px;
|
||||
--r-alpha-strip-w-xs: 30px;
|
||||
--r-list-row-h: 80px;
|
||||
--r-list-header-h: 40px;
|
||||
--r-list-select-w: 36px;
|
||||
--r-list-row-detail-h: 226px;
|
||||
--r-z-drawer: 2300;
|
||||
--r-z-dialog: 2400;
|
||||
--r-z-menu: 2500;
|
||||
@@ -214,6 +215,7 @@ html[data-input="pad"] .r-v2 {
|
||||
--r-color-fg-secondary: rgba(17, 17, 23, 0.82);
|
||||
--r-color-fg-muted: rgba(17, 17, 23, 0.74);
|
||||
--r-color-fg-faint: rgba(17, 17, 23, 0.58);
|
||||
--r-color-fg-faint-hard: rgba(17, 17, 23, 0.2);
|
||||
--r-color-border: rgba(0, 0, 0, 0.1);
|
||||
--r-color-border-strong: rgba(0, 0, 0, 0.22);
|
||||
--r-color-focus: rgba(0, 0, 0, 0.45);
|
||||
|
||||
@@ -182,6 +182,7 @@ export const colorLight = {
|
||||
fgSecondary: "rgba(17, 17, 23, 0.82)",
|
||||
fgMuted: "rgba(17, 17, 23, 0.74)",
|
||||
fgFaint: "rgba(17, 17, 23, 0.58)",
|
||||
fgFaintHard: "rgba(17, 17, 23, 0.2)",
|
||||
border: "rgba(0, 0, 0, 0.1)",
|
||||
borderStrong: "rgba(0, 0, 0, 0.22)",
|
||||
focus: "rgba(0, 0, 0, 0.45)",
|
||||
@@ -451,10 +452,8 @@ export const layout = {
|
||||
collectionCoverHeight: "188px",
|
||||
collectionCoverWidthXs: "150px",
|
||||
collectionCoverHeightXs: "202px",
|
||||
// AlphaStrip A-Z jump column (gallery). Wider on phones for bigger, more
|
||||
// tappable letters.
|
||||
// AlphaStrip A-Z jump column (gallery).
|
||||
alphaStripWidth: "24px",
|
||||
alphaStripWidthXs: "30px",
|
||||
// List-mode (table) gallery geometry. `GameListRow`, `GameListHeader`
|
||||
// and `GameListSkeletonRow` all derive their pixel sizing from these,
|
||||
// and `useGalleryVirtualItems` reads `listRowHeight` so the virtualiser's
|
||||
@@ -463,6 +462,12 @@ export const layout = {
|
||||
// `<GameCard size="xs" />` — no dedicated list-cover token.)
|
||||
listRowHeight: "80px",
|
||||
listHeaderHeight: "40px",
|
||||
// The row's leading tick column, narrower on phones (see global.css).
|
||||
listSelectWidth: "36px",
|
||||
// Height of a list row's expanded detail panel on phones and tablets,
|
||||
// where the row collapses to two lines and the columns move in here.
|
||||
// Fixed so the virtualiser can offset the rows below it exactly.
|
||||
listRowDetailHeight: "226px",
|
||||
} as const;
|
||||
|
||||
export const tokens = {
|
||||
|
||||
7
frontend/src/v2/types/stats.ts
Normal file
7
frontend/src/v2/types/stats.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
/** A KPI column in a gallery header: `Stat` renders one per entry. Shared by
|
||||
* the header component and the views that compose the rows. */
|
||||
export interface StatRow {
|
||||
label: string;
|
||||
/** A number rolls up on screen; a string (a size, a date) is printed. */
|
||||
value: string | number;
|
||||
}
|
||||
57
frontend/src/v2/utils/tween.ts
Normal file
57
frontend/src/v2/utils/tween.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
// A minimal ease-out tween over requestAnimationFrame, shared by the two
|
||||
// places that animate a number Vue renders (a rolling count, a panel's
|
||||
// height). The duration arrives already resolved, so reduced motion and the
|
||||
// motion tokens stay the caller's business.
|
||||
|
||||
function easeOut(t: number): number {
|
||||
return 1 - (1 - t) ** 3;
|
||||
}
|
||||
|
||||
interface TweenOptions {
|
||||
from: number;
|
||||
to: number;
|
||||
/** 0 lands on `to` synchronously, which is what reduced motion wants. */
|
||||
durationMs: number;
|
||||
onUpdate: (value: number) => void;
|
||||
onDone?: () => void;
|
||||
}
|
||||
|
||||
/** Starts the tween and returns the function that cancels it. */
|
||||
export function tween({
|
||||
from,
|
||||
to,
|
||||
durationMs,
|
||||
onUpdate,
|
||||
onDone,
|
||||
}: TweenOptions): () => void {
|
||||
if (durationMs <= 0) {
|
||||
onUpdate(to);
|
||||
onDone?.();
|
||||
return () => {};
|
||||
}
|
||||
|
||||
let frame: number | null = null;
|
||||
const cancel = () => {
|
||||
if (frame !== null) cancelAnimationFrame(frame);
|
||||
frame = null;
|
||||
};
|
||||
|
||||
// Paint the starting value now: the first frame is a whole render away,
|
||||
// and in a background tab it never comes at all.
|
||||
onUpdate(from);
|
||||
const start = performance.now();
|
||||
const step = (now: number) => {
|
||||
const t = Math.min(1, (now - start) / durationMs);
|
||||
if (t < 1) {
|
||||
onUpdate(from + (to - from) * easeOut(t));
|
||||
frame = requestAnimationFrame(step);
|
||||
return;
|
||||
}
|
||||
onUpdate(to);
|
||||
frame = null;
|
||||
onDone?.();
|
||||
};
|
||||
frame = requestAnimationFrame(step);
|
||||
|
||||
return cancel;
|
||||
}
|
||||
@@ -41,6 +41,7 @@ import { useIsAlive } from "@/v2/composables/useIsAlive";
|
||||
import { usePageTitle } from "@/v2/composables/usePageTitle";
|
||||
import { useSnackbar } from "@/v2/composables/useSnackbar";
|
||||
import storeGalleryRoms from "@/v2/stores/galleryRoms";
|
||||
import type { StatRow } from "@/v2/types/stats";
|
||||
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
@@ -162,14 +163,13 @@ const tags = computed<string[]>(() => {
|
||||
return out;
|
||||
});
|
||||
|
||||
type StatRow = { label: string; value: string };
|
||||
const platformStats = computed<StatRow[]>(() => {
|
||||
const p = currentPlatform.value;
|
||||
if (!p) return [];
|
||||
const rows: StatRow[] = [
|
||||
{
|
||||
label: t("platform.in-library"),
|
||||
value: String(p.rom_count ?? total.value),
|
||||
value: p.rom_count ?? total.value,
|
||||
},
|
||||
{ label: t("platform.on-disk"), value: formatBytes(p.fs_size_bytes ?? 0) },
|
||||
];
|
||||
@@ -178,7 +178,7 @@ const platformStats = computed<StatRow[]>(() => {
|
||||
if (usableFirmware.length) {
|
||||
rows.push({
|
||||
label: t("common.firmware"),
|
||||
value: String(usableFirmware.length),
|
||||
value: usableFirmware.length,
|
||||
});
|
||||
}
|
||||
return rows;
|
||||
|
||||
@@ -51,6 +51,16 @@ import { useScanTrigger } from "@/v2/composables/useScanTrigger";
|
||||
import { scanNeedsMetadataSource, type ScanType } from "@/v2/types/scan";
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
// The tooltip's paragraph breaks arrive as `<br>` in every locale, and that is
|
||||
// the only markup in it, so split on them rather than render the string as
|
||||
// HTML.
|
||||
const hashesDisabledTooltip = computed(() =>
|
||||
t("scan.hashes-disabled-tooltip")
|
||||
.split(/(?:<br\s*\/?>\s*)+/i)
|
||||
.map((paragraph) => paragraph.trim())
|
||||
.filter(Boolean),
|
||||
);
|
||||
const { startScan } = useScanTrigger();
|
||||
const scanningStore = storeScanning();
|
||||
const { scanning, scanningPlatforms, scanStats } = storeToRefs(scanningStore);
|
||||
@@ -591,10 +601,13 @@ function stopScan() {
|
||||
class="r-v2-scan-card__hash-info"
|
||||
/>
|
||||
</template>
|
||||
<span
|
||||
class="r-v2-scan-card__hash-info-text"
|
||||
v-html="t('scan.hashes-disabled-tooltip')"
|
||||
/>
|
||||
<span class="r-v2-scan-card__hash-info-text">
|
||||
<span
|
||||
v-for="(paragraph, i) in hashesDisabledTooltip"
|
||||
:key="i"
|
||||
>{{ paragraph }}</span
|
||||
>
|
||||
</span>
|
||||
</RTooltip>
|
||||
</span>
|
||||
</RAlert>
|
||||
@@ -829,7 +842,7 @@ function stopScan() {
|
||||
background: var(--r-color-bg-elevated);
|
||||
border: 1px solid var(--r-color-border);
|
||||
border-radius: var(--r-radius-lg);
|
||||
transition: opacity var(--r-motion-mid) var(--r-motion-ease-out);
|
||||
transition: opacity var(--r-motion-med) var(--r-motion-ease-out);
|
||||
}
|
||||
.r-v2-scan-card--locked {
|
||||
/* Slight dim + pointer hold so the running scan reads as "in-flight,
|
||||
@@ -930,6 +943,12 @@ function stopScan() {
|
||||
.r-v2-scan-card__hash-info:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
/* One paragraph per line, the blank line the copy used to carry as `<br><br>`. */
|
||||
.r-v2-scan-card__hash-info-text {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--r-space-2);
|
||||
}
|
||||
|
||||
/* Providers split into General / Specific groups. Each group has a
|
||||
tiny inline caption above its RSelect — same visual rhythm as the
|
||||
@@ -1197,8 +1216,8 @@ function stopScan() {
|
||||
are already on screen stay put; only new arrivals animate. */
|
||||
.r-v2-scan-panel-enter-active {
|
||||
transition:
|
||||
opacity var(--r-motion-mid) var(--r-motion-ease-out),
|
||||
transform var(--r-motion-mid) var(--r-motion-ease-back);
|
||||
opacity var(--r-motion-med) var(--r-motion-ease-out),
|
||||
transform var(--r-motion-med) var(--r-motion-ease-back);
|
||||
}
|
||||
.r-v2-scan-panel-enter-from {
|
||||
opacity: 0;
|
||||
|
||||
Reference in New Issue
Block a user