2026-06-17 22:07:18 -06:00
|
|
|
<script lang="ts" module>
|
2026-07-07 23:08:10 +02:00
|
|
|
import type { FileItem, FolderItem } from '$lib/api/types';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Per-item envelope info that isn't on `FileItem` / `FolderItem` itself
|
|
|
|
|
* — supplied by the page in a `contextMap` keyed by item id.
|
|
|
|
|
*
|
|
|
|
|
* Example use-cases:
|
|
|
|
|
* - `/trash`: `date = deletion_date`, `extras = { driveId, trashedAt }`.
|
|
|
|
|
* - `/recent`: `date = accessed_at`, `ownerId = updated_by`.
|
|
|
|
|
* - `/favorites`: `ownerId = created_by`.
|
|
|
|
|
*
|
|
|
|
|
* All fields are optional; ResourceList falls back to the equivalent
|
|
|
|
|
* intrinsic on the item (`modified_at`, `created_by`) when absent.
|
|
|
|
|
*/
|
|
|
|
|
export interface ItemContext {
|
|
|
|
|
/**
|
|
|
|
|
* Overrides `item.modified_at` for the date column + `modifiedAt`
|
|
|
|
|
* group-by dimension. Accepts epoch (ms or s), an ISO string, or
|
|
|
|
|
* `null` — same shape `formatDate` and the date-bucket helpers
|
|
|
|
|
* already tolerate. `/trash` uses ISO strings; `/recent` uses
|
|
|
|
|
* epoch ms.
|
|
|
|
|
*/
|
2026-06-17 22:07:18 -06:00
|
|
|
date?: number | string | null;
|
2026-07-07 23:08:10 +02:00
|
|
|
/** Overrides `item.created_by` for the owner column + vignette. */
|
2026-06-17 22:07:18 -06:00
|
|
|
ownerId?: string | null;
|
2026-07-07 23:08:10 +02:00
|
|
|
/** Free-form extras that page-provided `bucketOf` / `contextActions` read. */
|
|
|
|
|
extras?: Record<string, string | number | null>;
|
2026-06-17 22:07:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A group-by ("swimlane") dimension a page can offer. `orderBy` is sent to the
|
2026-07-07 23:08:10 +02:00
|
|
|
* API; the optional `bucketOf` maps an item + its context to a section key,
|
|
|
|
|
* and `labelOf` maps that key to a header label. Omitting `bucketOf` means a
|
|
|
|
|
* flat list.
|
2026-06-17 22:07:18 -06:00
|
|
|
*/
|
|
|
|
|
export interface GroupByDef {
|
|
|
|
|
key: string;
|
|
|
|
|
label: string;
|
|
|
|
|
orderBy: string;
|
|
|
|
|
/** Optional icon for the dropdown option (defaults to the group glyph). */
|
|
|
|
|
icon?: string;
|
2026-07-07 23:08:10 +02:00
|
|
|
bucketOf?: (item: FileItem | FolderItem, ctx?: ItemContext) => string | null;
|
2026-06-17 22:07:18 -06:00
|
|
|
labelOf?: (bucketKey: string) => string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** A right-click / overflow context-menu action. */
|
|
|
|
|
export interface ContextAction {
|
|
|
|
|
key: string;
|
|
|
|
|
label: string;
|
|
|
|
|
icon: string;
|
|
|
|
|
danger?: boolean;
|
2026-07-07 23:08:10 +02:00
|
|
|
run: (item: FileItem | FolderItem, ctx?: ItemContext) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* True when the item is a file. Uses structural narrowing on
|
|
|
|
|
* `mime_type` (only present on `FileItem`) so callers can pattern
|
|
|
|
|
* match without importing the discriminator manually.
|
|
|
|
|
*/
|
|
|
|
|
export function isFile(item: FileItem | FolderItem): item is FileItem {
|
|
|
|
|
return 'mime_type' in item;
|
2026-06-17 22:07:18 -06:00
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
|
import type { Snippet } from 'svelte';
|
2026-06-21 19:03:07 +02:00
|
|
|
import { SvelteSet } from 'svelte/reactivity';
|
2026-06-17 22:07:18 -06:00
|
|
|
import Icon from '$lib/icons/Icon.svelte';
|
2026-06-17 22:30:56 -06:00
|
|
|
import EmptyState from '$lib/components/EmptyState.svelte';
|
|
|
|
|
import SkeletonList from '$lib/components/SkeletonList.svelte';
|
2026-06-17 22:07:18 -06:00
|
|
|
import ListToolbar from '$lib/components/ListToolbar.svelte';
|
2026-06-20 02:13:23 +02:00
|
|
|
import UserVignette from '$lib/components/UserVignette.svelte';
|
2026-06-19 14:00:56 +00:00
|
|
|
import VirtualList from '$lib/components/VirtualList.svelte';
|
2026-06-17 22:07:18 -06:00
|
|
|
import { t } from '$lib/i18n/index.svelte';
|
2026-07-13 23:16:04 +02:00
|
|
|
import { files as filesStore } from '$lib/stores/files.svelte';
|
2026-07-07 23:08:10 +02:00
|
|
|
import { preferences } from '$lib/stores/preferences.svelte';
|
2026-06-17 22:07:18 -06:00
|
|
|
import { formatBytes } from '$lib/utils/format';
|
2026-06-20 16:33:08 +02:00
|
|
|
import { formatDate, iconNameFromClass, fileIconKindClass } from '$lib/utils/display';
|
2026-06-19 14:48:37 +00:00
|
|
|
import { gridColumns } from '$lib/utils/grid';
|
2026-07-19 11:36:47 +00:00
|
|
|
import { ResourceSectionsBuilder } from '$lib/utils/resourceSections';
|
2026-07-19 20:53:30 +00:00
|
|
|
import { ItemIndexBuilder } from '$lib/utils/itemIndex';
|
2026-07-19 01:32:00 +00:00
|
|
|
import { fileThumbnailUrl, thumbSizeForView } from '$lib/api/endpoints/files';
|
2026-07-07 23:08:10 +02:00
|
|
|
import {
|
|
|
|
|
canThumbnailClientSide,
|
|
|
|
|
preloadPdf,
|
|
|
|
|
queueGenerate as queueThumbnailGenerate
|
|
|
|
|
} from '$lib/utils/thumbnail';
|
2026-06-17 22:07:18 -06:00
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
title: string;
|
2026-07-07 23:08:10 +02:00
|
|
|
items: Array<FileItem | FolderItem>;
|
|
|
|
|
/**
|
|
|
|
|
* Per-item envelope info keyed by `item.id`. See `ItemContext`
|
|
|
|
|
* above. When absent, ResourceList uses the intrinsic item
|
|
|
|
|
* fields (`modified_at`, `created_by`).
|
|
|
|
|
*/
|
|
|
|
|
contextMap?: Map<string, ItemContext>;
|
|
|
|
|
/**
|
|
|
|
|
* Set of item ids the caller considers "favorite". When
|
|
|
|
|
* provided, the star widget renders next to each row and
|
|
|
|
|
* `onfavorite` is invoked on click. Kept as an external Set so
|
|
|
|
|
* the page owns the source of truth (e.g. the favorites store).
|
|
|
|
|
*/
|
|
|
|
|
favoriteIds?: Set<string>;
|
|
|
|
|
/**
|
|
|
|
|
* Resolve `userId → display name`. Optional; when absent
|
|
|
|
|
* `UserVignette` falls back to its own internal resolution.
|
|
|
|
|
* Accepts `null` for consistency with the useOwnerCache API
|
|
|
|
|
* (returns `null` for a not-yet-resolved id).
|
|
|
|
|
*/
|
|
|
|
|
resolveOwnerName?: (userId: string) => string | null | undefined;
|
2026-06-17 22:07:18 -06:00
|
|
|
loading?: boolean;
|
|
|
|
|
error?: string | null;
|
|
|
|
|
/** Empty-state primary line. */
|
|
|
|
|
emptyText?: string;
|
|
|
|
|
/** Empty-state secondary hint line. */
|
|
|
|
|
emptyHint?: string;
|
|
|
|
|
/** Empty-state icon-registry name (e.g. "star", "clock", "trash"). */
|
|
|
|
|
emptyIcon?: string;
|
|
|
|
|
hasMore?: boolean;
|
|
|
|
|
onloadmore?: () => void;
|
|
|
|
|
/** Show the path/location column (list view only). */
|
|
|
|
|
showPath?: boolean;
|
|
|
|
|
/** Override the path column header label (e.g. trash → "Original location"). */
|
|
|
|
|
pathLabel?: string;
|
|
|
|
|
showSize?: boolean;
|
|
|
|
|
showType?: boolean;
|
|
|
|
|
showDate?: boolean;
|
|
|
|
|
/** Override the date column header label (e.g. trash → "Remaining"). */
|
|
|
|
|
dateLabel?: string;
|
|
|
|
|
/** Custom renderer for the date cell (e.g. trash expiry chip). */
|
2026-07-07 23:08:10 +02:00
|
|
|
dateCell?: Snippet<[FileItem | FolderItem, ItemContext | undefined]>;
|
2026-06-24 21:31:59 +02:00
|
|
|
/**
|
|
|
|
|
* Optional per-bucket action button rendered alongside the swimlane
|
|
|
|
|
* header label. Receives the bucket key (the value `bucketOf`
|
|
|
|
|
* returned for the active group-by). Used by the trash page to expose
|
|
|
|
|
* a per-drive "Empty" affordance — the page decides which group-bys
|
|
|
|
|
* the action is meaningful for and returns nothing otherwise.
|
|
|
|
|
*/
|
|
|
|
|
bucketAction?: Snippet<[string]>;
|
2026-06-17 22:07:18 -06:00
|
|
|
/** Show the owner column + vignette (list view) and hover tooltip. */
|
|
|
|
|
showOwner?: boolean;
|
|
|
|
|
/** Allow grid/list toggle (shares the app-wide view mode). */
|
|
|
|
|
showViewToggle?: boolean;
|
2026-07-07 23:08:10 +02:00
|
|
|
/** Show the dotfile-visibility eye toggle in the toolbar AND
|
|
|
|
|
* apply the corresponding filter to `items` when
|
|
|
|
|
* `preferences.hideDotfiles` is true. Opt-in per host page —
|
|
|
|
|
* surfaces that never filter dotfiles (favorites, trash) leave
|
|
|
|
|
* this false so the button doesn't appear AND the filter never
|
|
|
|
|
* kicks in. Single flag governs both concerns so a page can't
|
|
|
|
|
* accidentally expose the button without wiring the filter or
|
|
|
|
|
* vice-versa.
|
|
|
|
|
*
|
|
|
|
|
* A host page that needs to surface "N items hidden" in its
|
|
|
|
|
* empty state derives that count independently via the shared
|
|
|
|
|
* `isDotfile` predicate in `$lib/utils/dotfileFilter` — no
|
|
|
|
|
* count-out prop here (avoids a bindable whose $bindable
|
|
|
|
|
* default is always shadowed by the effect that would sync it,
|
|
|
|
|
* and keeps the component's API one-way-inbound). */
|
2026-07-13 19:26:19 +02:00
|
|
|
showDotfileToggle?: boolean;
|
2026-06-17 22:07:18 -06:00
|
|
|
/** Multi-select checkboxes + selection model. */
|
|
|
|
|
selectable?: boolean;
|
|
|
|
|
/** Right-click / overflow context-menu actions. */
|
|
|
|
|
contextActions?: ContextAction[];
|
|
|
|
|
/** Group-by dimensions; when provided, a swimlane selector is shown. */
|
|
|
|
|
groupBys?: GroupByDef[];
|
|
|
|
|
/** Active group-by key (bind:groupBy from the page). */
|
|
|
|
|
groupBy?: string;
|
|
|
|
|
/** Reverse sort toggle state (bind:reversed from the page). */
|
|
|
|
|
reversed?: boolean;
|
|
|
|
|
/** Called when group-by or direction changes; page should reload page 1. */
|
|
|
|
|
onreload?: (orderBy: string, reversed: boolean) => void;
|
2026-07-07 23:08:10 +02:00
|
|
|
onopen?: (item: FileItem | FolderItem) => void;
|
|
|
|
|
/** Per-item favorite star toggle. */
|
|
|
|
|
onfavorite?: (item: FileItem | FolderItem) => void;
|
|
|
|
|
/** Selection changed (set of selected item ids). */
|
2026-06-17 22:07:18 -06:00
|
|
|
onselectionchange?: (ids: Set<string>) => void;
|
2026-07-07 23:08:10 +02:00
|
|
|
actions?: Snippet<[FileItem | FolderItem]>;
|
2026-06-17 22:07:18 -06:00
|
|
|
toolbar?: Snippet;
|
2026-07-07 23:08:10 +02:00
|
|
|
/** Batch toolbar shown when items are selected; receives selected items. */
|
|
|
|
|
batchToolbar?: Snippet<[Array<FileItem | FolderItem>]>;
|
|
|
|
|
/**
|
|
|
|
|
* Render `<img>` thumbnails on file rows and fall back to
|
|
|
|
|
* client-side generation when the server doesn't have one
|
|
|
|
|
* (image / PDF / video via `$lib/utils/thumbnail`). Default on
|
|
|
|
|
* — every view that lists real files gets the same behaviour.
|
|
|
|
|
* Set false for views that never benefit (empty states,
|
|
|
|
|
* synthetic rows).
|
|
|
|
|
*/
|
|
|
|
|
enableThumbnails?: boolean;
|
|
|
|
|
/**
|
|
|
|
|
* Enable per-row drag/drop hooks. Used by the files browser so
|
|
|
|
|
* a folder row is a drop target and any row is draggable to
|
|
|
|
|
* another folder or the breadcrumb. Pages that don't wire these
|
|
|
|
|
* (trash, favorites, recent, shared-with-me) opt out of the
|
|
|
|
|
* drag-drop UX entirely by leaving the callbacks unset.
|
|
|
|
|
*/
|
|
|
|
|
isDraggable?: (item: FileItem | FolderItem) => boolean;
|
|
|
|
|
isDropTarget?: (item: FileItem | FolderItem) => boolean;
|
|
|
|
|
/**
|
|
|
|
|
* Which item id currently shows the drop-target highlight (page
|
|
|
|
|
* owns the state so it can share it with breadcrumb / other drop
|
|
|
|
|
* zones). Only meaningful when `isDropTarget` is provided.
|
|
|
|
|
*/
|
|
|
|
|
dropTargetId?: string | null;
|
|
|
|
|
onitemdragstart?: (e: DragEvent, item: FileItem | FolderItem) => void;
|
|
|
|
|
onitemdragover?: (e: DragEvent, item: FileItem | FolderItem) => void;
|
|
|
|
|
onitemdragleave?: (e: DragEvent, item: FileItem | FolderItem) => void;
|
|
|
|
|
onitemdrop?: (e: DragEvent, item: FileItem | FolderItem) => void;
|
|
|
|
|
/**
|
|
|
|
|
* Override the list-view column header. When provided,
|
|
|
|
|
* ResourceList renders this instead of its default header —
|
|
|
|
|
* used by the files browser to expose clickable column-sort
|
|
|
|
|
* buttons (name / size / type / modified). Pages that override
|
|
|
|
|
* this typically also handle sorting on their side (pass
|
|
|
|
|
* pre-sorted `items`) rather than relying on `onreload`.
|
|
|
|
|
*/
|
|
|
|
|
listHeader?: Snippet;
|
|
|
|
|
/**
|
|
|
|
|
* Open the row on single click (default) vs. double click.
|
|
|
|
|
* Files browser prefers double-click so single-click can drive
|
|
|
|
|
* the shift-range selection model without accidentally
|
|
|
|
|
* navigating.
|
|
|
|
|
*/
|
|
|
|
|
openOnDoubleClick?: boolean;
|
|
|
|
|
/**
|
|
|
|
|
* Enable shift-click range selection. The row that was clicked
|
|
|
|
|
* without shift becomes the anchor; the next shift-click
|
|
|
|
|
* selects the range between anchor and target in visible order.
|
|
|
|
|
* Requires `selectable`.
|
|
|
|
|
*/
|
|
|
|
|
shiftRangeSelect?: boolean;
|
2026-06-17 22:07:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let {
|
|
|
|
|
title,
|
|
|
|
|
items,
|
2026-07-07 23:08:10 +02:00
|
|
|
contextMap,
|
|
|
|
|
favoriteIds,
|
|
|
|
|
resolveOwnerName,
|
2026-06-17 22:07:18 -06:00
|
|
|
loading = false,
|
|
|
|
|
error = null,
|
|
|
|
|
emptyText,
|
|
|
|
|
emptyHint,
|
|
|
|
|
emptyIcon,
|
|
|
|
|
hasMore = false,
|
|
|
|
|
onloadmore,
|
|
|
|
|
showPath = true,
|
|
|
|
|
pathLabel,
|
|
|
|
|
showSize = true,
|
|
|
|
|
showType = false,
|
|
|
|
|
showDate = true,
|
|
|
|
|
dateLabel,
|
|
|
|
|
dateCell,
|
2026-06-24 21:31:59 +02:00
|
|
|
bucketAction,
|
2026-06-17 22:07:18 -06:00
|
|
|
showOwner = false,
|
|
|
|
|
showViewToggle = true,
|
2026-07-13 19:26:19 +02:00
|
|
|
showDotfileToggle = false,
|
2026-06-17 22:07:18 -06:00
|
|
|
selectable = false,
|
|
|
|
|
contextActions,
|
|
|
|
|
groupBys,
|
|
|
|
|
groupBy = $bindable(''),
|
|
|
|
|
reversed = $bindable(false),
|
|
|
|
|
onreload,
|
|
|
|
|
onopen,
|
|
|
|
|
onfavorite,
|
|
|
|
|
onselectionchange,
|
|
|
|
|
actions,
|
|
|
|
|
toolbar,
|
2026-07-07 23:08:10 +02:00
|
|
|
batchToolbar,
|
|
|
|
|
enableThumbnails = true,
|
|
|
|
|
isDraggable,
|
|
|
|
|
isDropTarget,
|
|
|
|
|
dropTargetId = null,
|
|
|
|
|
onitemdragstart,
|
|
|
|
|
onitemdragover,
|
|
|
|
|
onitemdragleave,
|
|
|
|
|
onitemdrop,
|
|
|
|
|
listHeader: listHeaderOverride,
|
|
|
|
|
openOnDoubleClick = false,
|
|
|
|
|
shiftRangeSelect = false
|
2026-06-17 22:07:18 -06:00
|
|
|
}: Props = $props();
|
|
|
|
|
|
2026-07-07 23:08:10 +02:00
|
|
|
// ── Per-item accessors ────────────────────────────────────────────────────
|
|
|
|
|
// Every read of an item field goes through these helpers so the
|
|
|
|
|
// contextMap override for date + owner is centralised. Kept as
|
|
|
|
|
// module-level fns (not $derived) — they run on each row render;
|
|
|
|
|
// caching a Map on every items/contextMap change would be wasteful.
|
|
|
|
|
function ctxOf(id: string): ItemContext | undefined {
|
|
|
|
|
return contextMap?.get(id);
|
|
|
|
|
}
|
|
|
|
|
function dateOf(item: FileItem | FolderItem): number | string | null {
|
|
|
|
|
return ctxOf(item.id)?.date ?? item.modified_at;
|
|
|
|
|
}
|
|
|
|
|
function ownerIdOf(item: FileItem | FolderItem): string | null {
|
|
|
|
|
const ctx = ctxOf(item.id);
|
|
|
|
|
return ctx && 'ownerId' in ctx ? (ctx.ownerId ?? null) : (item.created_by ?? null);
|
|
|
|
|
}
|
|
|
|
|
function sizeOf(item: FileItem | FolderItem): number | null {
|
|
|
|
|
return isFile(item) ? item.size : null;
|
|
|
|
|
}
|
|
|
|
|
function mimeOf(item: FileItem | FolderItem): string | null {
|
|
|
|
|
return isFile(item) ? item.mime_type : null;
|
|
|
|
|
}
|
|
|
|
|
function iconClassOf(item: FileItem | FolderItem): string {
|
|
|
|
|
return item.icon_class;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Dotfile filter ────────────────────────────────────────────────────────
|
|
|
|
|
// Two conditions gate the filter (both must be true):
|
|
|
|
|
// 1. Host page opted in via `showDotfileToggle` — so pages where
|
|
|
|
|
// dotfiles are always visible (favorites, trash) never hide them
|
|
|
|
|
// even if the user's global preference is on.
|
|
|
|
|
// 2. User preference is set to hide — read from the reactive
|
|
|
|
|
// `preferences.hideDotfiles` getter, so a toolbar click flips
|
|
|
|
|
// this list in real time without a reload.
|
|
|
|
|
// The `visibleItems` derived is what every downstream reader
|
|
|
|
|
// (bucketing, rendering, "all-selected", range-select) uses, so
|
|
|
|
|
// hidden rows disappear consistently across grid, list, and every
|
|
|
|
|
// group-by dimension. `selectedItems` and the reap-stale-selection
|
|
|
|
|
// effect stay on the raw `items` — selection persists across a
|
|
|
|
|
// display filter toggle, matching how file managers treat a
|
|
|
|
|
// filter-hide as "hidden, not gone".
|
|
|
|
|
const filterDotfiles = $derived(showDotfileToggle && preferences.hideDotfiles);
|
|
|
|
|
const visibleItems = $derived(
|
|
|
|
|
filterDotfiles ? items.filter((i) => !i.name.startsWith('.')) : items
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// isEmpty tracks the VISIBLE list — an all-dotfile page with the
|
|
|
|
|
// filter on shows the empty state (the host page's `emptyHint` can
|
|
|
|
|
// reference `hiddenCount` to say "3 items hidden by the filter").
|
|
|
|
|
const isEmpty = $derived(visibleItems.length === 0);
|
2026-06-19 14:48:37 +00:00
|
|
|
/** Content width, for computing the grid's column count to match auto-fill. */
|
|
|
|
|
let gridWidth = $state(0);
|
|
|
|
|
const gridCols = $derived(gridColumns(gridWidth));
|
2026-06-17 22:07:18 -06:00
|
|
|
|
|
|
|
|
// Build the list-view column track from the enabled cells.
|
|
|
|
|
const columns = $derived(
|
|
|
|
|
[
|
|
|
|
|
selectable ? '36px' : '',
|
|
|
|
|
'minmax(200px, 2fr)',
|
|
|
|
|
showOwner ? 'minmax(120px, 1fr)' : '',
|
|
|
|
|
showPath ? 'minmax(140px, 1.5fr)' : '',
|
|
|
|
|
showType ? '120px' : '',
|
|
|
|
|
showSize ? '110px' : '',
|
|
|
|
|
showDate ? '160px' : '',
|
|
|
|
|
actions ? '120px' : ''
|
|
|
|
|
]
|
|
|
|
|
.filter(Boolean)
|
|
|
|
|
.join(' ')
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const SKELETON = [0, 1, 2, 3, 4, 5];
|
|
|
|
|
|
|
|
|
|
// ── Group-by / direction ──────────────────────────────────────────────────
|
|
|
|
|
const activeGroup = $derived(groupBys?.find((g) => g.key === groupBy));
|
|
|
|
|
|
|
|
|
|
function selectGroup(key: string) {
|
|
|
|
|
if (groupBy === key) return;
|
|
|
|
|
groupBy = key;
|
|
|
|
|
const def = groupBys?.find((g) => g.key === key);
|
|
|
|
|
onreload?.(def?.orderBy ?? 'name', reversed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toggleDirection() {
|
|
|
|
|
reversed = !reversed;
|
|
|
|
|
onreload?.(activeGroup?.orderBy ?? 'name', reversed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Partition the visible items into grouped sections when a `bucketOf` is
|
|
|
|
|
* active. Server order is preserved within and across buckets (first-seen).
|
2026-07-19 11:36:47 +00:00
|
|
|
*
|
|
|
|
|
* `ResourceSectionsBuilder` re-buckets only the freshly-appended page rather
|
|
|
|
|
* than the whole accumulated list, and hands `VirtualList` the same rows
|
|
|
|
|
* array reference for every untouched bucket so it skips re-rendering it. An
|
|
|
|
|
* infinite-scroll drain of a grouped listing (trash / recent / favorites /
|
|
|
|
|
* shared-with-me) collapses from Σ O(N²/page) to O(N) bucketing work
|
|
|
|
|
* (benches/ROUND15.md §F1). Held off the reactive graph — a plain
|
|
|
|
|
* accumulator keyed by the append cursor, not $state; `sync` is idempotent,
|
|
|
|
|
* so if the derive re-fires without an actual append it safely full-rebuilds
|
|
|
|
|
* to the same output the pure `buildResourceSections` reference produces.
|
2026-06-17 22:07:18 -06:00
|
|
|
*/
|
2026-07-19 11:36:47 +00:00
|
|
|
const sectionsBuilder = new ResourceSectionsBuilder<FileItem | FolderItem, ItemContext>();
|
|
|
|
|
const sections = $derived.by(() =>
|
|
|
|
|
sectionsBuilder.sync(visibleItems, {
|
|
|
|
|
bucketOf: activeGroup?.bucketOf,
|
|
|
|
|
labelOf: activeGroup?.labelOf,
|
|
|
|
|
ctxOf: (item) => ctxOf(item.id)
|
|
|
|
|
})
|
2026-07-07 23:08:10 +02:00
|
|
|
);
|
2026-06-17 22:07:18 -06:00
|
|
|
const grouped = $derived(!!activeGroup?.bucketOf);
|
|
|
|
|
|
|
|
|
|
// ── Selection ─────────────────────────────────────────────────────────────
|
2026-06-21 19:03:07 +02:00
|
|
|
// SvelteSet is reactive on its own; mutate in place rather than reassigning.
|
|
|
|
|
const selected = new SvelteSet<string>();
|
2026-06-17 22:07:18 -06:00
|
|
|
|
|
|
|
|
function toggleSelected(id: string) {
|
2026-06-21 19:03:07 +02:00
|
|
|
if (selected.has(id)) selected.delete(id);
|
|
|
|
|
else selected.add(id);
|
|
|
|
|
onselectionchange?.(selected);
|
2026-06-17 22:07:18 -06:00
|
|
|
}
|
2026-07-07 23:08:10 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Anchor id for shift-range selection. The row clicked without
|
|
|
|
|
* shift becomes the anchor; the next shift-click selects every
|
|
|
|
|
* row between anchor and target in visible order. Kept in module
|
|
|
|
|
* state so it survives re-renders that don't drop the component.
|
|
|
|
|
*/
|
|
|
|
|
let selectionAnchor = $state<string | null>(null);
|
|
|
|
|
function selectRange(anchorId: string, targetId: string) {
|
|
|
|
|
// Range-select over the VISIBLE order — a shift-click can't reach
|
|
|
|
|
// a row the user can't see.
|
|
|
|
|
const order = visibleItems.map((i) => i.id);
|
|
|
|
|
const a = order.indexOf(anchorId);
|
|
|
|
|
const b = order.indexOf(targetId);
|
|
|
|
|
if (a < 0 || b < 0) return;
|
|
|
|
|
const [lo, hi] = a < b ? [a, b] : [b, a];
|
|
|
|
|
for (let i = lo; i <= hi; i++) selected.add(order[i]);
|
|
|
|
|
onselectionchange?.(selected);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Left-click handler that either navigates (`onopen`) or manages
|
|
|
|
|
* selection depending on modifiers + config. Returns `true` when
|
|
|
|
|
* the click was consumed by selection, so callers can suppress the
|
|
|
|
|
* open. Enabled only for `selectable + shiftRangeSelect` callers.
|
|
|
|
|
*/
|
|
|
|
|
function handleRowClick(e: MouseEvent, id: string): boolean {
|
|
|
|
|
if (!selectable || !shiftRangeSelect) return false;
|
|
|
|
|
if (e.shiftKey && selectionAnchor) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
selectRange(selectionAnchor, id);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (e.metaKey || e.ctrlKey) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
toggleSelected(id);
|
|
|
|
|
selectionAnchor = id;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// Plain click: only sets the anchor; open (if any) still fires.
|
|
|
|
|
selectionAnchor = id;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2026-06-17 22:07:18 -06:00
|
|
|
function clearSelection() {
|
2026-06-21 19:03:07 +02:00
|
|
|
selected.clear();
|
2026-06-17 22:07:18 -06:00
|
|
|
onselectionchange?.(selected);
|
|
|
|
|
}
|
2026-07-07 23:08:10 +02:00
|
|
|
// "All-selected" means every VISIBLE row is selected — hiding
|
|
|
|
|
// dotfiles by preference shouldn't be confused with "not selected".
|
|
|
|
|
const allSelected = $derived(
|
|
|
|
|
visibleItems.length > 0 && visibleItems.every((i) => selected.has(i.id))
|
|
|
|
|
);
|
2026-06-17 22:07:18 -06:00
|
|
|
function toggleSelectAll() {
|
|
|
|
|
if (allSelected) clearSelection();
|
|
|
|
|
else {
|
2026-06-21 19:03:07 +02:00
|
|
|
selected.clear();
|
2026-07-07 23:08:10 +02:00
|
|
|
// Select all VISIBLE rows only. A user hiding dotfiles then
|
|
|
|
|
// pressing select-all shouldn't sweep in the hidden files
|
|
|
|
|
// they can't see — that would be a footgun for destructive
|
|
|
|
|
// batch actions.
|
|
|
|
|
for (const i of visibleItems) selected.add(i.id);
|
2026-06-17 22:07:18 -06:00
|
|
|
onselectionchange?.(selected);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-07 23:08:10 +02:00
|
|
|
// `selectedItems` and the reap-stale effect below stay on the RAW
|
|
|
|
|
// items — selection persists across a display-filter toggle, and
|
|
|
|
|
// stale-selection cleanup only fires when items truly leave the
|
|
|
|
|
// dataset (reload, delete, etc.), not when the filter hides them.
|
2026-07-18 23:15:10 +00:00
|
|
|
//
|
2026-07-19 20:53:30 +00:00
|
|
|
// Index extended over the freshly-appended page only (never re-scanned in
|
|
|
|
|
// full) via `ItemIndexBuilder`: an infinite-scroll drain with a selection
|
|
|
|
|
// active collapses from Σ O(N²) Map rebuilds to O(N) total, and the Map
|
|
|
|
|
// reference is reused across appends so the reap-stale effect below no
|
|
|
|
|
// longer re-fires (nor re-allocates an O(N) id Set) on a page that removed
|
|
|
|
|
// nothing — its reference only changes on a rebuild (reload / deletion),
|
|
|
|
|
// exactly when a reap is warranted. The projection is then O(k · log k) in
|
|
|
|
|
// the selection size k, not a full O(N) re-scan on every toggle
|
|
|
|
|
// (benches/ROUND11.md §S1, benches/ROUND18.md §F1). The index sort preserves
|
|
|
|
|
// item order, so the toolbar sees the same array the old filter produced.
|
|
|
|
|
const itemIndex = new ItemIndexBuilder<FileItem | FolderItem>();
|
|
|
|
|
const itemIndexById = $derived(itemIndex.sync(items));
|
2026-07-18 23:15:10 +00:00
|
|
|
const selectedItems = $derived.by(() => {
|
|
|
|
|
const picked: { idx: number; item: FileItem | FolderItem }[] = [];
|
2026-07-18 22:02:00 +00:00
|
|
|
for (const id of selected) {
|
|
|
|
|
const idx = itemIndexById.get(id);
|
|
|
|
|
if (idx !== undefined) picked.push({ idx, item: items[idx] });
|
|
|
|
|
}
|
|
|
|
|
picked.sort((a, b) => a.idx - b.idx);
|
|
|
|
|
return picked.map((p) => p.item);
|
|
|
|
|
});
|
2026-06-17 22:07:18 -06:00
|
|
|
|
|
|
|
|
// Drop selection ids that are no longer present after a reload.
|
|
|
|
|
$effect(() => {
|
2026-07-19 20:53:30 +00:00
|
|
|
// With nothing selected (the common case) the loop never runs — skip
|
|
|
|
|
// straight out. `selected.size` is reactive, so the effect re-fires
|
|
|
|
|
// when a selection appears.
|
2026-07-18 16:12:04 +00:00
|
|
|
if (selected.size === 0) return;
|
2026-07-19 20:53:30 +00:00
|
|
|
// Test membership against the incremental `itemIndexById` rather than a
|
|
|
|
|
// throwaway O(N) id Set rebuilt per page. Its reference is stable across
|
|
|
|
|
// infinite-scroll appends (which never remove an id — nothing to reap)
|
|
|
|
|
// so this effect no longer re-fires on every page; the reference changes
|
|
|
|
|
// only on a rebuild (reload / deletion), which is exactly when a stale
|
|
|
|
|
// selection must be dropped (benches/ROUND18.md §F1).
|
|
|
|
|
const index = itemIndexById;
|
2026-06-17 22:07:18 -06:00
|
|
|
let changed = false;
|
|
|
|
|
for (const id of selected) {
|
2026-07-19 20:53:30 +00:00
|
|
|
if (!index.has(id)) {
|
2026-06-21 19:03:07 +02:00
|
|
|
selected.delete(id);
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
2026-06-17 22:07:18 -06:00
|
|
|
}
|
2026-06-21 19:03:07 +02:00
|
|
|
if (changed) onselectionchange?.(selected);
|
2026-06-17 22:07:18 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// ── Right-click context menu ──────────────────────────────────────────────
|
|
|
|
|
let ctxOpen = $state(false);
|
|
|
|
|
let ctxX = $state(0);
|
|
|
|
|
let ctxY = $state(0);
|
2026-07-07 23:08:10 +02:00
|
|
|
let ctxItem = $state<FileItem | FolderItem | null>(null);
|
2026-06-17 22:07:18 -06:00
|
|
|
|
2026-07-07 23:08:10 +02:00
|
|
|
function openContext(e: MouseEvent, item: FileItem | FolderItem) {
|
2026-06-17 22:07:18 -06:00
|
|
|
if (!contextActions?.length) return;
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
2026-07-07 23:08:10 +02:00
|
|
|
ctxItem = item;
|
2026-06-17 22:07:18 -06:00
|
|
|
ctxX = Math.min(e.clientX, window.innerWidth - 220);
|
|
|
|
|
ctxY = Math.min(e.clientY, window.innerHeight - (contextActions.length * 44 + 24));
|
|
|
|
|
ctxOpen = true;
|
|
|
|
|
}
|
|
|
|
|
function closeContext() {
|
|
|
|
|
ctxOpen = false;
|
2026-07-07 23:08:10 +02:00
|
|
|
ctxItem = null;
|
2026-06-17 22:07:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Infinite scroll (IntersectionObserver) ────────────────────────────────
|
|
|
|
|
let sentinel = $state<HTMLElement | null>(null);
|
|
|
|
|
$effect(() => {
|
|
|
|
|
const el = sentinel;
|
|
|
|
|
if (!el || typeof IntersectionObserver === 'undefined') return;
|
|
|
|
|
const obs = new IntersectionObserver(
|
|
|
|
|
(entries) => {
|
|
|
|
|
for (const en of entries) {
|
|
|
|
|
if (en.isIntersecting && hasMore && !loading) onloadmore?.();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{ rootMargin: '200px' }
|
|
|
|
|
);
|
|
|
|
|
obs.observe(el);
|
|
|
|
|
return () => obs.disconnect();
|
|
|
|
|
});
|
|
|
|
|
|
2026-07-07 23:08:10 +02:00
|
|
|
function ownerTitle(item: FileItem | FolderItem): string {
|
|
|
|
|
const ownerId = ownerIdOf(item);
|
|
|
|
|
const owner = ownerId ? (resolveOwnerName?.(ownerId) ?? ownerId) : '';
|
|
|
|
|
const path = item.path ?? '';
|
2026-06-17 22:07:18 -06:00
|
|
|
return [
|
|
|
|
|
owner && `${t('files.col_owner', 'Owner')}: ${owner}`,
|
|
|
|
|
path && `${t('files.col_path', 'Location')}: ${path}`
|
|
|
|
|
]
|
|
|
|
|
.filter(Boolean)
|
|
|
|
|
.join('\n');
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2026-07-07 23:08:10 +02:00
|
|
|
{#snippet row(item: FileItem | FolderItem)}
|
|
|
|
|
{@const kind = isFile(item) ? 'file' : 'folder'}
|
|
|
|
|
{@const iconName = kind === 'folder' ? 'folder' : iconNameFromClass(iconClassOf(item))}
|
|
|
|
|
{@const isFav = favoriteIds?.has(item.id) ?? false}
|
|
|
|
|
{@const ctx = ctxOf(item.id)}
|
|
|
|
|
{@const ownerId = ownerIdOf(item)}
|
|
|
|
|
{@const dateVal = dateOf(item)}
|
|
|
|
|
{@const sizeVal = sizeOf(item)}
|
|
|
|
|
{@const mimeVal = mimeOf(item)}
|
|
|
|
|
{@const draggable = isDraggable?.(item) ?? false}
|
|
|
|
|
{@const dropTarget = isDropTarget?.(item) ?? false}
|
2026-06-17 22:07:18 -06:00
|
|
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
|
|
|
<div
|
|
|
|
|
class="file-item"
|
2026-07-07 23:08:10 +02:00
|
|
|
class:file-item--selected={selectable && selected.has(item.id)}
|
|
|
|
|
class:file-item--drop-target={dropTarget && dropTargetId === item.id}
|
2026-06-17 22:07:18 -06:00
|
|
|
role={onopen ? 'button' : undefined}
|
|
|
|
|
tabindex={onopen ? 0 : undefined}
|
2026-07-07 23:08:10 +02:00
|
|
|
aria-label={onopen ? item.name : undefined}
|
|
|
|
|
data-testid={item.name}
|
|
|
|
|
title={showOwner ? ownerTitle(item) : undefined}
|
|
|
|
|
{draggable}
|
|
|
|
|
ondragstart={draggable && onitemdragstart ? (e) => onitemdragstart(e, item) : undefined}
|
|
|
|
|
ondragover={dropTarget && onitemdragover ? (e) => onitemdragover(e, item) : undefined}
|
|
|
|
|
ondragleave={dropTarget && onitemdragleave ? (e) => onitemdragleave(e, item) : undefined}
|
|
|
|
|
ondrop={dropTarget && onitemdrop ? (e) => onitemdrop(e, item) : undefined}
|
|
|
|
|
onclick={onopen
|
|
|
|
|
? (e) => {
|
|
|
|
|
// Selection-first for shift/meta clicks; only "open" fires on a
|
|
|
|
|
// plain click when the click wasn't consumed by selection.
|
|
|
|
|
if (handleRowClick(e, item.id)) return;
|
|
|
|
|
if (!openOnDoubleClick) onopen(item);
|
|
|
|
|
}
|
|
|
|
|
: undefined}
|
|
|
|
|
ondblclick={onopen && openOnDoubleClick ? () => onopen(item) : undefined}
|
|
|
|
|
onkeydown={onopen ? (e) => e.key === 'Enter' && onopen(item) : undefined}
|
|
|
|
|
oncontextmenu={contextActions?.length ? (e) => openContext(e, item) : undefined}
|
2026-06-17 22:07:18 -06:00
|
|
|
>
|
|
|
|
|
{#if selectable}
|
|
|
|
|
<div class="select-cell" role="presentation" onclick={(e) => e.stopPropagation()}>
|
|
|
|
|
<input
|
|
|
|
|
type="checkbox"
|
|
|
|
|
aria-label={t('common.select', 'Select')}
|
2026-07-07 23:08:10 +02:00
|
|
|
data-testid={`resource-list-select-${item.id}-checkbox`}
|
|
|
|
|
checked={selected.has(item.id)}
|
|
|
|
|
onchange={() => toggleSelected(item.id)}
|
2026-06-17 22:07:18 -06:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
<div class="name-cell">
|
2026-06-20 16:33:08 +02:00
|
|
|
<span class="file-icon {fileIconKindClass(iconName)}">
|
2026-07-07 23:08:10 +02:00
|
|
|
<!-- Type icon always renders. When `enableThumbnails` is on
|
|
|
|
|
and the item is a file with a supported mime, an
|
|
|
|
|
`<img>` overlays the icon on success; onerror hides it
|
|
|
|
|
(revealing the icon) and kicks off client-side
|
|
|
|
|
generation for image / PDF / video so the next viewer
|
|
|
|
|
hits the server-side thumbnail. -->
|
2026-06-20 16:33:08 +02:00
|
|
|
<Icon name={iconName} />
|
2026-07-07 23:08:10 +02:00
|
|
|
{#if enableThumbnails && kind === 'file' && mimeVal && canThumbnailClientSide( { id: item.id, name: item.name, mime_type: mimeVal } )}
|
|
|
|
|
<img
|
|
|
|
|
class="file-thumb"
|
2026-07-19 01:32:00 +00:00
|
|
|
src={fileThumbnailUrl(item.id, thumbSizeForView(filesStore.viewMode))}
|
2026-07-07 23:08:10 +02:00
|
|
|
alt=""
|
|
|
|
|
loading="lazy"
|
|
|
|
|
onerror={(e) => {
|
|
|
|
|
const img = e.currentTarget as HTMLImageElement;
|
|
|
|
|
img.style.display = 'none';
|
|
|
|
|
if (mimeVal === 'application/pdf') preloadPdf();
|
|
|
|
|
void queueThumbnailGenerate(
|
|
|
|
|
{ id: item.id, name: item.name, mime_type: mimeVal },
|
|
|
|
|
(dataUrl) => {
|
|
|
|
|
img.src = dataUrl;
|
|
|
|
|
img.style.display = '';
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
{/if}
|
2026-06-17 22:07:18 -06:00
|
|
|
</span>
|
2026-07-07 23:08:10 +02:00
|
|
|
<span class="name-cell__text">{item.name}</span>
|
2026-06-17 22:07:18 -06:00
|
|
|
</div>
|
|
|
|
|
{#if showOwner}
|
|
|
|
|
<div class="owner-cell">
|
2026-07-07 23:08:10 +02:00
|
|
|
{#if ownerId}
|
|
|
|
|
<UserVignette userId={ownerId} fallbackLabel={resolveOwnerName?.(ownerId) ?? undefined} />
|
2026-06-20 02:13:23 +02:00
|
|
|
{:else}
|
2026-07-07 23:08:10 +02:00
|
|
|
<span class="owner-cell__placeholder">—</span>
|
2026-06-20 02:13:23 +02:00
|
|
|
{/if}
|
2026-06-17 22:07:18 -06:00
|
|
|
</div>
|
|
|
|
|
{/if}
|
2026-07-07 23:08:10 +02:00
|
|
|
{#if showPath}<div class="path-cell">{item.path ?? ''}</div>{/if}
|
|
|
|
|
{#if showType}<div class="type-cell">{item.category ?? ''}</div>{/if}
|
2026-06-17 22:07:18 -06:00
|
|
|
{#if showSize}
|
2026-07-07 23:08:10 +02:00
|
|
|
<div class="size-cell">{sizeVal != null ? formatBytes(sizeVal) : '—'}</div>
|
2026-06-17 22:07:18 -06:00
|
|
|
{/if}
|
|
|
|
|
{#if showDate}
|
|
|
|
|
<div class="date-cell">
|
2026-07-07 23:08:10 +02:00
|
|
|
{#if dateCell}{@render dateCell(item, ctx)}{:else}{formatDate(dateVal)}{/if}
|
2026-06-17 22:07:18 -06:00
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
<div class="grid-meta">
|
2026-07-07 23:08:10 +02:00
|
|
|
{#if showDate && dateCell}<span class="grid-meta__chip">{@render dateCell(item, ctx)}</span
|
|
|
|
|
>{/if}
|
2026-06-17 22:07:18 -06:00
|
|
|
<span class="grid-meta__line">
|
2026-07-07 23:08:10 +02:00
|
|
|
{#if sizeVal != null}<span class="grid-meta__size">{formatBytes(sizeVal)}</span>{/if}
|
|
|
|
|
{#if dateVal != null}<span class="grid-meta__date">{formatDate(dateVal)}</span>{/if}
|
2026-06-17 22:07:18 -06:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
{#if onfavorite}
|
|
|
|
|
<button
|
|
|
|
|
class="rl-star"
|
2026-07-07 23:08:10 +02:00
|
|
|
class:rl-star--on={isFav}
|
|
|
|
|
data-testid={`resource-list-favorite-${item.id}-btn`}
|
|
|
|
|
title={isFav
|
2026-06-17 22:07:18 -06:00
|
|
|
? t('files.unfavorite', 'Remove favorite')
|
|
|
|
|
: t('files.favorite', 'Add favorite')}
|
2026-07-07 23:08:10 +02:00
|
|
|
aria-pressed={isFav}
|
2026-06-17 22:07:18 -06:00
|
|
|
onclick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
2026-07-07 23:08:10 +02:00
|
|
|
onfavorite(item);
|
|
|
|
|
}}><Icon name={isFav ? 'star' : 'star-outline'} /></button
|
2026-06-17 22:07:18 -06:00
|
|
|
>
|
|
|
|
|
{/if}
|
|
|
|
|
{#if actions}
|
2026-07-07 23:08:10 +02:00
|
|
|
<div class="action-cell">{@render actions(item)}</div>
|
2026-06-17 22:07:18 -06:00
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
{/snippet}
|
|
|
|
|
|
|
|
|
|
<div class="page-sticky-header">
|
|
|
|
|
<h1 class="page-title">{title}</h1>
|
|
|
|
|
<ListToolbar
|
|
|
|
|
groups={groupBys}
|
|
|
|
|
{groupBy}
|
|
|
|
|
{reversed}
|
|
|
|
|
ongroup={selectGroup}
|
|
|
|
|
ondirection={toggleDirection}
|
|
|
|
|
{showViewToggle}
|
2026-07-13 19:26:19 +02:00
|
|
|
{showDotfileToggle}
|
2026-06-17 22:07:18 -06:00
|
|
|
>
|
|
|
|
|
{#snippet start()}
|
|
|
|
|
<div class="action-buttons">{@render toolbar?.()}</div>
|
|
|
|
|
{/snippet}
|
|
|
|
|
</ListToolbar>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{#if selectable && selected.size > 0 && batchToolbar}
|
2026-06-21 20:03:32 -06:00
|
|
|
<div
|
|
|
|
|
class="rl-batch"
|
|
|
|
|
role="region"
|
|
|
|
|
aria-label={t('files.selection', 'Selection')}
|
|
|
|
|
data-testid="resource-list-batch-toolbar"
|
|
|
|
|
>
|
|
|
|
|
<button
|
|
|
|
|
class="rl-batch__close"
|
|
|
|
|
title={t('common.clear', 'Clear')}
|
|
|
|
|
data-testid="resource-list-batch-close-btn"
|
|
|
|
|
onclick={clearSelection}
|
|
|
|
|
>
|
2026-06-17 22:07:18 -06:00
|
|
|
<Icon name="times" />
|
|
|
|
|
</button>
|
|
|
|
|
<span class="rl-batch__count"
|
|
|
|
|
>{t('files.selected_count', { count: selected.size }, '{{count}} selected')}</span
|
|
|
|
|
>
|
2026-07-07 23:08:10 +02:00
|
|
|
<div class="rl-batch__actions">{@render batchToolbar(selectedItems)}</div>
|
2026-06-17 22:07:18 -06:00
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
{#if error}
|
2026-06-17 22:30:56 -06:00
|
|
|
<EmptyState icon="exclamation-circle" title={error} error />
|
2026-06-17 22:07:18 -06:00
|
|
|
{:else if loading && isEmpty}
|
2026-06-17 22:30:56 -06:00
|
|
|
<SkeletonList count={SKELETON.length} />
|
2026-06-17 22:07:18 -06:00
|
|
|
{:else if isEmpty}
|
2026-06-17 22:30:56 -06:00
|
|
|
<EmptyState
|
|
|
|
|
icon={emptyIcon}
|
|
|
|
|
title={emptyText ?? t('common.empty', 'Nothing here yet.')}
|
|
|
|
|
hint={emptyHint}
|
|
|
|
|
/>
|
2026-06-17 22:07:18 -06:00
|
|
|
{:else}
|
2026-06-19 14:48:37 +00:00
|
|
|
<div class="files-container" bind:clientWidth={gridWidth}>
|
2026-07-19 08:17:48 +00:00
|
|
|
{#if grouped && filesStore.viewMode === 'list'}
|
|
|
|
|
<div class="files-list-view" style="--files-list-columns: {columns}">
|
2026-07-07 23:08:10 +02:00
|
|
|
{#if listHeaderOverride}{@render listHeaderOverride()}{:else}{@render listHeader()}{/if}
|
2026-06-17 22:07:18 -06:00
|
|
|
{#each sections as section (section.key)}
|
2026-06-24 21:31:59 +02:00
|
|
|
<div class="rl-swimlane-header" role="rowheader">
|
|
|
|
|
<span class="rl-swimlane-header__label">{section.label}</span>
|
|
|
|
|
{#if bucketAction}
|
|
|
|
|
<span class="rl-swimlane-header__action">
|
|
|
|
|
{@render bucketAction(section.key)}
|
|
|
|
|
</span>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
2026-07-19 08:17:48 +00:00
|
|
|
<!-- Window each section's rows so a large grouped list (e.g. a big
|
|
|
|
|
trash, grouped by remaining days) doesn't mount every row. -->
|
|
|
|
|
<VirtualList items={section.rows} rowHeight={56} key={(e) => e.id} {row} />
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
{:else if grouped}
|
|
|
|
|
<!-- Grouped GRID: a vertical stack of (header + its own windowed card
|
|
|
|
|
grid) per section. The outer is a flex column, NOT `.files-grid-view`
|
|
|
|
|
(which is itself a grid and would place each header/VirtualList into a
|
|
|
|
|
cell) — the grid lives on each VirtualList's inner window via
|
|
|
|
|
`windowClass`, exactly like the flat-grid arm. This was the last
|
|
|
|
|
unwindowed path: a grouped-by-default grid (trash) mounted every card
|
|
|
|
|
(benches/ROUND13.md §V1). -->
|
|
|
|
|
<div class="rl-grouped-grid">
|
|
|
|
|
{#each sections as section (section.key)}
|
|
|
|
|
<div class="rl-swimlane-header rl-swimlane-header--grid" role="rowheader">
|
|
|
|
|
<span class="rl-swimlane-header__label">{section.label}</span>
|
|
|
|
|
{#if bucketAction}
|
|
|
|
|
<span class="rl-swimlane-header__action">
|
|
|
|
|
{@render bucketAction(section.key)}
|
|
|
|
|
</span>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
<VirtualList
|
|
|
|
|
items={section.rows}
|
|
|
|
|
columns={gridCols}
|
|
|
|
|
rowHeight={240}
|
|
|
|
|
windowClass="files-grid-view"
|
|
|
|
|
key={(e) => e.id}
|
|
|
|
|
{row}
|
|
|
|
|
/>
|
2026-06-17 22:07:18 -06:00
|
|
|
{/each}
|
2026-06-19 14:48:37 +00:00
|
|
|
</div>
|
2026-07-13 23:16:04 +02:00
|
|
|
{:else if filesStore.viewMode === 'list'}
|
2026-06-19 14:48:37 +00:00
|
|
|
<!-- Flat list view: only the visible rows are mounted. The spacer keeps the
|
|
|
|
|
full scroll height so the end-of-list sentinel still fires. -->
|
|
|
|
|
<div class="files-list-view" style="--files-list-columns: {columns}">
|
2026-07-07 23:08:10 +02:00
|
|
|
{#if listHeaderOverride}{@render listHeaderOverride()}{:else}{@render listHeader()}{/if}
|
|
|
|
|
<VirtualList items={visibleItems} rowHeight={56} key={(e) => e.id} {row} />
|
2026-06-19 14:48:37 +00:00
|
|
|
</div>
|
|
|
|
|
{:else}
|
|
|
|
|
<!-- Grid view: the windowed list's inner element IS the card grid. -->
|
|
|
|
|
<VirtualList
|
2026-07-07 23:08:10 +02:00
|
|
|
items={visibleItems}
|
2026-06-19 14:48:37 +00:00
|
|
|
columns={gridCols}
|
|
|
|
|
rowHeight={240}
|
|
|
|
|
windowClass="files-grid-view"
|
|
|
|
|
key={(e) => e.id}
|
|
|
|
|
{row}
|
|
|
|
|
/>
|
|
|
|
|
{/if}
|
2026-06-17 22:07:18 -06:00
|
|
|
|
|
|
|
|
{#if hasMore}
|
2026-06-21 20:03:32 -06:00
|
|
|
<button
|
|
|
|
|
class="btn btn-secondary rl-more"
|
|
|
|
|
data-testid="resource-list-load-more-btn"
|
|
|
|
|
onclick={onloadmore}
|
|
|
|
|
disabled={loading}
|
|
|
|
|
>
|
2026-06-17 22:07:18 -06:00
|
|
|
{loading ? t('common.loading', 'Loading…') : t('common.load_more', 'Load more')}
|
|
|
|
|
</button>
|
|
|
|
|
{/if}
|
|
|
|
|
<!-- Infinite-scroll sentinel: auto-loads the next page as it nears the viewport. -->
|
|
|
|
|
<div bind:this={sentinel} class="rl-sentinel" aria-hidden="true"></div>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
|
2026-06-19 14:48:37 +00:00
|
|
|
{#snippet listHeader()}
|
|
|
|
|
<div class="list-header">
|
|
|
|
|
{#if selectable}
|
|
|
|
|
<div class="select-cell">
|
|
|
|
|
<input
|
|
|
|
|
type="checkbox"
|
|
|
|
|
aria-label={t('common.select_all', 'Select all')}
|
2026-06-21 20:03:32 -06:00
|
|
|
data-testid="resource-list-select-all-checkbox"
|
2026-06-19 14:48:37 +00:00
|
|
|
checked={allSelected}
|
|
|
|
|
onchange={toggleSelectAll}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
<div>{t('files.col_name', 'Name')}</div>
|
|
|
|
|
{#if showOwner}<div>{t('files.col_owner', 'Owner')}</div>{/if}
|
|
|
|
|
{#if showPath}<div>{pathLabel ?? t('files.col_path', 'Location')}</div>{/if}
|
|
|
|
|
{#if showType}<div>{t('files.col_type', 'Type')}</div>{/if}
|
|
|
|
|
{#if showSize}<div>{t('files.col_size', 'Size')}</div>{/if}
|
|
|
|
|
{#if showDate}<div>{dateLabel ?? t('files.col_modified', 'Date')}</div>{/if}
|
|
|
|
|
{#if onfavorite || actions}<div></div>{/if}
|
|
|
|
|
</div>
|
|
|
|
|
{/snippet}
|
|
|
|
|
|
2026-07-07 23:08:10 +02:00
|
|
|
{#if ctxOpen && ctxItem && contextActions}
|
2026-06-17 22:07:18 -06:00
|
|
|
<div
|
|
|
|
|
class="rl-ctx-scrim"
|
|
|
|
|
role="presentation"
|
|
|
|
|
onclick={closeContext}
|
|
|
|
|
oncontextmenu={(e) => e.preventDefault()}
|
|
|
|
|
></div>
|
2026-06-21 20:03:32 -06:00
|
|
|
<div
|
|
|
|
|
class="rl-ctx-menu"
|
|
|
|
|
style:left="{ctxX}px"
|
|
|
|
|
style:top="{ctxY}px"
|
|
|
|
|
role="menu"
|
|
|
|
|
data-testid="resource-list-context-menu"
|
|
|
|
|
>
|
2026-06-17 22:07:18 -06:00
|
|
|
{#each contextActions as action (action.key)}
|
|
|
|
|
<button
|
|
|
|
|
class="rl-ctx-item"
|
|
|
|
|
class:rl-ctx-item--danger={action.danger}
|
|
|
|
|
role="menuitem"
|
2026-06-21 20:03:32 -06:00
|
|
|
data-testid={`resource-list-context-${action.key}-item`}
|
2026-06-17 22:07:18 -06:00
|
|
|
onclick={() => {
|
2026-07-07 23:08:10 +02:00
|
|
|
const target = ctxItem!;
|
2026-06-17 22:07:18 -06:00
|
|
|
closeContext();
|
2026-07-07 23:08:10 +02:00
|
|
|
action.run(target, ctxOf(target.id));
|
2026-06-17 22:07:18 -06:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Icon name={action.icon} />
|
|
|
|
|
{action.label}
|
|
|
|
|
</button>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.rl-more {
|
|
|
|
|
margin: var(--space-4) auto 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.rl-sentinel {
|
|
|
|
|
height: 1px;
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ── Batch toolbar ── */
|
|
|
|
|
.rl-batch {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: var(--space-3);
|
|
|
|
|
padding: var(--space-2) var(--space-4);
|
|
|
|
|
margin-bottom: var(--space-3);
|
|
|
|
|
background: var(--color-accent-bg);
|
|
|
|
|
border: 1px solid var(--color-border);
|
|
|
|
|
border-radius: var(--radius-md);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.rl-batch__close {
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
width: 28px;
|
|
|
|
|
height: 28px;
|
|
|
|
|
border: none;
|
|
|
|
|
border-radius: var(--radius-sm);
|
|
|
|
|
background: transparent;
|
|
|
|
|
color: var(--color-text-secondary);
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.rl-batch__close:hover {
|
|
|
|
|
background: var(--color-bg-hover);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.rl-batch__count {
|
|
|
|
|
font-weight: var(--weight-semibold);
|
|
|
|
|
color: var(--color-text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.rl-batch__actions {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: var(--space-2);
|
|
|
|
|
margin-left: auto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ── Selection column ── */
|
|
|
|
|
.select-cell {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.file-item--selected {
|
|
|
|
|
background: var(--color-accent-bg);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-07 23:08:10 +02:00
|
|
|
/* Drop-target highlight — mirrors the legacy files browser's cue when
|
|
|
|
|
dragging a row over a folder row. */
|
|
|
|
|
.file-item--drop-target {
|
|
|
|
|
outline: 2px dashed var(--color-accent);
|
|
|
|
|
outline-offset: -2px;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-17 22:07:18 -06:00
|
|
|
/* ── Owner vignette ── */
|
|
|
|
|
.owner-cell {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
min-width: 0;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-20 02:13:23 +02:00
|
|
|
.owner-cell__placeholder {
|
2026-06-17 22:07:18 -06:00
|
|
|
overflow: hidden;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
color: var(--color-text-secondary);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.name-cell__text {
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ── Favorite star ── */
|
|
|
|
|
.rl-star {
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
width: 32px;
|
|
|
|
|
height: 32px;
|
|
|
|
|
border: none;
|
|
|
|
|
border-radius: var(--radius-sm);
|
|
|
|
|
background: transparent;
|
|
|
|
|
color: var(--color-text-faint);
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.rl-star:hover {
|
|
|
|
|
background: var(--color-bg-hover);
|
|
|
|
|
color: var(--color-text-secondary);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.rl-star--on {
|
|
|
|
|
color: var(--color-warning-text-amber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ── Swimlane section header ── */
|
|
|
|
|
.rl-swimlane-header {
|
|
|
|
|
grid-column: 1 / -1;
|
|
|
|
|
padding: var(--space-3) var(--space-1) var(--space-1);
|
|
|
|
|
font-size: var(--text-sm);
|
|
|
|
|
font-weight: var(--weight-semibold);
|
|
|
|
|
color: var(--color-text-secondary);
|
|
|
|
|
border-bottom: 1px solid var(--color-border-faint);
|
2026-06-24 21:31:59 +02:00
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
gap: var(--space-2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Optional per-bucket action (e.g. trash page's per-drive Empty). */
|
|
|
|
|
.rl-swimlane-header__action {
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
align-items: center;
|
2026-06-17 22:07:18 -06:00
|
|
|
}
|
|
|
|
|
|
2026-07-19 08:17:48 +00:00
|
|
|
/* Grouped-grid container: a vertical stack of (header + its own windowed
|
|
|
|
|
card grid) per section. Not `.files-grid-view` — the grid is on each
|
|
|
|
|
VirtualList's inner window, so this outer element just stacks. */
|
|
|
|
|
.rl-grouped-grid {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
gap: var(--space-2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* In the flex stack the `grid-column: 1 / -1` span (meant for the grid
|
|
|
|
|
context) is inert; the header spans naturally as a block-level flex
|
|
|
|
|
child. */
|
|
|
|
|
.rl-swimlane-header--grid {
|
|
|
|
|
grid-column: auto;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-17 22:07:18 -06:00
|
|
|
/* Grid view date meta line. */
|
|
|
|
|
.grid-meta__line {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: var(--space-2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Grid view: overlay a custom date chip (e.g. trash expiry) on the card corner. */
|
|
|
|
|
:global(.files-grid-view) .grid-meta__chip {
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: var(--space-2);
|
|
|
|
|
right: var(--space-2);
|
|
|
|
|
z-index: 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ── Context menu ── */
|
|
|
|
|
.rl-ctx-scrim {
|
|
|
|
|
position: fixed;
|
|
|
|
|
inset: 0;
|
|
|
|
|
z-index: 1000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.rl-ctx-menu {
|
|
|
|
|
position: fixed;
|
|
|
|
|
z-index: 1001;
|
|
|
|
|
min-width: 200px;
|
|
|
|
|
padding: var(--space-1);
|
|
|
|
|
background: var(--color-bg-surface);
|
|
|
|
|
border: 1px solid var(--color-border);
|
|
|
|
|
border-radius: var(--radius-md);
|
|
|
|
|
box-shadow: var(--shadow-lg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.rl-ctx-item {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: var(--space-2);
|
|
|
|
|
width: 100%;
|
|
|
|
|
padding: var(--space-2) var(--space-3);
|
|
|
|
|
border: none;
|
|
|
|
|
border-radius: var(--radius-sm);
|
|
|
|
|
background: transparent;
|
|
|
|
|
color: var(--color-text);
|
|
|
|
|
text-align: left;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.rl-ctx-item:hover {
|
|
|
|
|
background: var(--color-bg-hover);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.rl-ctx-item--danger {
|
2026-06-20 18:15:30 +02:00
|
|
|
/* Danger *foreground* on the light menu surface — the red accent, not
|
|
|
|
|
--color-danger-text (white, for text ON a red fill, invisible here). */
|
|
|
|
|
color: var(--color-danger-alt);
|
2026-06-17 22:07:18 -06:00
|
|
|
}
|
|
|
|
|
</style>
|