diff --git a/apps/studio/src/apps/FilesApp.tsx b/apps/studio/src/apps/FilesApp.tsx index 51156ab..d905363 100644 --- a/apps/studio/src/apps/FilesApp.tsx +++ b/apps/studio/src/apps/FilesApp.tsx @@ -21,7 +21,7 @@ import { CollectionSections, PhotoFactsSections, thumbOf } from "../photoParts"; import { CoverArt, coverOf } from "../shots/Cover"; import { MapView, positionOf } from "../places/map"; import { presetsIn } from "../optics"; -import { usePrefs, type Pin } from "../prefs"; +import { setPrefs, usePrefs, type Pin } from "../prefs"; import { useProjects } from "../projects"; import { useUser } from "../user"; import { pinsOf, togglePin as togglePinIn } from "../wm/Taskbar"; @@ -381,6 +381,30 @@ function Browser({ win, projectId, setTitle, setRoute, entry, start, onEntry }: const crumbs = media ? [{ id: "all", label: "Photos" }, ...(openColl ? [{ id: openColl.id, label: openColl.name }] : mnav === "collections" ? [{ id: "collections", label: "Collections" }] : mnav === "loose" ? [{ id: "loose", label: "Not in a collection" }] : [])] : [{ id: "root", label: rootLabel }, ...path.map((f) => ({ id: f.id, label: f.name }))]; + // ---- Columns (#426): every column this kind of list can show, the ones shown and their widths, kept with the account + // per kind (folders, Photos, Shots, Sets, Locations). Properties are columns too; the Shots list starts with its own. + const listKind = home ? "home" : entry; + const typeDefs = (type: string) => defs.filter((d) => d.def.attached.some((a) => a.type === type)); + const propCols = (media ? typeDefs("photo") : only ? typeDefs(only) : defs).map((d) => ({ key: `p:${d.id}`, label: d.name, def: d })); + const baseCols: { key: string; label: string; sortable?: boolean; mono?: boolean; numeric?: boolean; width?: number }[] = media + ? [{ key: "name", label: "Name", sortable: true }, { key: "coll", label: "Collection" }, { key: "taken", label: "Taken", sortable: true, mono: true, width: 130 }, { key: "size", label: "Size", numeric: true, width: 110 }, { key: "created", label: "Created", sortable: true, mono: true, width: 130 }] + : only ? [{ key: "name", label: "Name", sortable: true }, { key: "created", label: "Created", sortable: true, mono: true, width: 130 }] + : [{ key: "name", label: "Name", sortable: true }, { key: "type", label: "Type", sortable: true, width: 140 }, ...(flat ? [{ key: "where", label: "In" }] : []), { key: "created", label: "Created", sortable: true, mono: true, width: 130 }]; + const allCols = [...baseCols.slice(0, 1), ...(only ? propCols.map((c) => ({ key: c.key, label: c.label })) : []), ...baseCols.slice(1), ...(only ? [] : propCols.map((c) => ({ key: c.key, label: c.label })))]; + const defaultVisible = media ? ["name", "coll", "taken", "size"] : only ? ["name", ...propCols.filter((c) => c.def.def.attached.some((a) => a.type === only && !a.hidden)).map((c) => c.key), "created"] : ["name", "type", "where", "created"]; + const setup = prefs.columns[listKind] ?? {}; + const visible = new Set(["name", ...(setup.visible ?? defaultVisible)]); + const shownCols = allCols.filter((c) => visible.has(c.key)).map((c) => ({ ...c, width: setup.widths?.[c.key] ?? (c as { width?: number }).width })); + const columnDefs = propCols.filter((c) => visible.has(c.key)).map((c) => c.def); + const setColumns = (patch: { visible?: string[]; widths?: Record }) => setPrefs({ columns: { ...prefs.columns, [listKind]: { ...setup, ...patch } } }); + const toggleColumn = (key: string) => setColumns({ visible: allCols.map((c) => c.key).filter((k) => k !== "name" && (k === key ? !visible.has(k) : visible.has(k))) }); + // A search that matched in a property whose column is hidden says so on the row (search covers every property). + const hiddenMatch = (f: FileRec) => { + if (!q) return null; + const needle = q.toLowerCase(); + const d = defs.find((x) => !visible.has(`p:${x.id}`) && f.values?.[x.id] !== undefined && valueText(x.def, f.values![x.id], (id) => map.get(id)?.name).toLowerCase().includes(needle)); + return d ? `${d.name}: ${valueText(d.def, f.values![d.id], (id) => map.get(id)?.name)}` : null; + }; const toolbar = nav === "bin" ? null : ( (media ? (id === "all" ? setMnav("all") : undefined) : go({ folder: id === "root" ? null : id }))} @@ -395,6 +419,8 @@ function Browser({ win, projectId, setTitle, setRoute, entry, start, onEntry }: setView(v as View)} options={[{ value: "list", icon: "list", title: "List" }, { value: "grid", icon: "grid", title: "Grid" }, ...(!home ? [{ value: "board", icon: "columns" as const, title: "Board: lanes by a property" }] : []), ...(mapped ? [{ value: "map", icon: "pin" as const, title: "Map: the files with a position" }] : [])]} /> {!home && !shotsOnly && } {!media && !shotsOnly && void (id === "shot" || id === "set" || id === "location" || id === "timeline" ? newOf(id) : id === "canvas" ? ops.newCanvas(root, here) : ops.newFolder(root, here))} />} + {shownView === "list" && c.key !== "name").map((c) => ({ id: c.key, label: c.label, checked: visible.has(c.key) })), { separator: true }, { id: "reset", label: "As they were", icon: "refresh" }]} + onSelect={(id: string) => (id === "reset" ? setColumns({ visible: undefined, widths: undefined }) : toggleColumn(id))} />} { const t = e.currentTarget; if (t.files?.length) importAll(t.files); t.value = ""; }} /> @@ -429,10 +455,9 @@ function Browser({ win, projectId, setTitle, setRoute, entry, start, onEntry }: const nameCell = (f: FileRec) => { const thumb = thumbOf(f, all); const up = uploadOf(f); - return {thumb ? : icon(f, 20)}{f.name}{lookOf(f, map).shortcut && }{up && }; + const hit = hiddenMatch(f); + return {thumb ? : icon(f, 20)}{f.name}{lookOf(f, map).shortcut && }{up && }{hit && · {hit}}; }; - // The Shots list shows the shot properties as columns: the shot list as a table. - const columnDefs = shotsOnly ? defs.filter((d) => d.def.attached.some((a) => a.type === only && !a.hidden)) : []; const valueCell = (d: Definition, f: FileRec) => { const v = f.values?.[d.id]; if (v === undefined) return –; @@ -450,10 +475,7 @@ function Browser({ win, projectId, setTitle, setRoute, entry, start, onEntry }: : shownView === "board" && !home ? : shownView === "list" ? ( open(map.get(id)!)} sort={openColl ? undefined : sort} onSort={(s) => setSort(s as Sort)} rowProps={(id) => ({ ...rowDrag(map.get(id)!), "data-file-id": id })} - columns={media - ? [{ key: "name", label: "Name", sortable: true }, { key: "coll", label: "Collection" }, { key: "taken", label: "Taken", sortable: true, mono: true, width: 130 }, { key: "size", label: "Size", numeric: true, width: 110 }] - : shotsOnly ? [{ key: "name", label: "Name", sortable: true }, ...columnDefs.map((d) => ({ key: `p:${d.id}`, label: d.name })), { key: "created", label: "Created", sortable: true, mono: true, width: 130 }] - : [{ key: "name", label: "Name", sortable: true }, { key: "type", label: "Type", sortable: true, width: 140 }, ...(flat ? [{ key: "where", label: "In" }] : []), { key: "created", label: "Created", sortable: true, mono: true, width: 130 }]} + columns={shownCols} onResize={(key, w) => setColumns({ widths: { ...setup.widths, [key]: w } })} rows={items.map((f) => ({ ...Object.fromEntries(columnDefs.map((d) => [`p:${d.id}`, valueCell(d, f)])), id: f.id, name: nameCell(f), type: kindOf(f.type).label, where: where(f), created: day(f.created_at), coll: collCell(f), diff --git a/apps/studio/src/prefs.ts b/apps/studio/src/prefs.ts index 832fae4..8c63c61 100644 --- a/apps/studio/src/prefs.ts +++ b/apps/studio/src/prefs.ts @@ -30,9 +30,12 @@ export interface Prefs { clipHoldMs: number; /** A canvas made from a photo starts with the frame the photo was taken with. */ canvasTakesFrame: boolean; + /** The file browser's table per kind of list (folders, Photos, Shots, …): which columns show and how wide (#426). */ + columns: Record; } +export interface ColumnSetup { visible?: string[]; widths?: Record } -export const DEFAULT_PREFS: Prefs = { theme: "auto", taskbarEdge: "bottom", taskbarAlign: "start", pins: {}, icons: {}, binOnDesktop: true, collectionMark: "bar", clipHoldMs: 2000, canvasTakesFrame: true }; +export const DEFAULT_PREFS: Prefs = { columns: {}, theme: "auto", taskbarEdge: "bottom", taskbarAlign: "start", pins: {}, icons: {}, binOnDesktop: true, collectionMark: "bar", clipHoldMs: 2000, canvasTakesFrame: true }; export type PrefsState = "local" | "loading" | "saved" | "saving" | "unsaved"; let prefs: Prefs = { ...DEFAULT_PREFS, theme: getTheme() }; diff --git a/apps/studio/src/shell.css b/apps/studio/src/shell.css index c602ecc..fbf876e 100644 --- a/apps/studio/src/shell.css +++ b/apps/studio/src/shell.css @@ -173,3 +173,4 @@ body.wm-gesture { user-select: none; } /* A workspace in Settings › Workspaces: a row that opens its page. */ .st-wsrow { width: 100%; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; border-radius: var(--radius-control); } .st-wsrow:hover { background: var(--surface-hover); } +.st-hit { margin-left: var(--space-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } diff --git a/docs/features/files.md b/docs/features/files.md index 72263d0..f6da7d8 100644 --- a/docs/features/files.md +++ b/docs/features/files.md @@ -26,6 +26,7 @@ Everything a user makes is a file ([07 · organisation](../rewrite/07-organisati - **Toolbar:** the path (each part a link and a drop target), search over names in the whole root (marked "whole project"), the Types filter once there is more than one type, List · Grid, New (folder). - **Selecting is an OS file manager's** (#426): a click selects a file (the panel shows it), Ctrl-click adds or removes one, Shift-click selects the range from the file last clicked; a drag on the empty part of the list or grid draws a rectangle and selects what it touches (Ctrl keeps the selection), and a click there clears it. No checkboxes or tick circles; hover is a light background, selected a stronger one (`useMarquee` and `clickSelect` in the design system). The status bar counts the selection, with Clear. New files are made from the New menu and the context menu of the empty space, never from a button per type. - **List:** name with its icon (a fixed folder's own glyph, arrow for a shortcut), type, "In" while searching, created; sortable by name, type and created, containers first. **Grid:** cards with the type icon and a line of facts. Sort and view are remembered per browser. +- **Columns** (#426): every column a kind of list can show, the properties included; **Columns** in the toolbar (list view) shows or hides them (hidden, not deleted; *As they were* resets), and a header's right edge is dragged to size it. Kept with the account per kind of list (folders, home, Photos, Shots, Sets, Locations), the same in every window and browser. Search keeps covering every property: a row that matched in a hidden column says which property and value. - **Open** (double-click, `Enter`): a folder opens in place, or in a window of its own with "Open in a new window"; every folder shows in at most one window (opening one that is open brings that window up), each with its own taskbar button, as in an OS file manager (#426). Folders opened from elsewhere (the desktop, a pin, a shortcut) open in their own window; any other file in the app registered for its type; a shortcut opens what it points at. - **Context menu:** Open · Show what it points at (shortcut) · Rename… · Duplicate · New folder inside · Move to… (a folder picker) · Move to the top level · Move to the desktop · Create shortcut on the desktop · Pin to taskbar · Move to the recycle bin. With several ticked: the move entries and the bin. On the empty area: New folder, Select everything listed. - **Drag and drop:** rows and cards onto a folder (in the list, the grid, the tree or the path) move there; onto the desktop they move into the Desktop folder; onto the recycle bin they are deleted; onto the taskbar they are pinned. What cannot be (a folder into itself, more than 8 levels, a fixed folder) is said in a toast, by the same rules the server applies. diff --git a/packages/design/src/data/Table.tsx b/packages/design/src/data/Table.tsx index 0f0e78a..207b469 100644 --- a/packages/design/src/data/Table.tsx +++ b/packages/design/src/data/Table.tsx @@ -1,4 +1,5 @@ import type { ComponentChildren, JSX } from "preact"; +import { useRef } from "preact/hooks"; import { Icon } from "../core/Icon"; import { cx } from "../util"; import { clickSelect } from "./useMarquee"; @@ -16,7 +17,7 @@ export interface TableColumn { } /** A dense data table: sticky header, sortable columns, row selection, numeric columns right-aligned with tabular figures. */ -export interface TableProps extends Omit, "onSelect"> { +export interface TableProps extends Omit, "onSelect" | "onResize"> { columns: TableColumn[]; rows: ({ id: string } & Record)[]; sort?: { key: string; dir: "asc" | "desc" }; @@ -33,20 +34,42 @@ export interface TableProps extends Omit, " onOpen?: (id: string) => void; /** More for one row's element: dragging it, dropping onto it, its context menu, a class. */ rowProps?: (id: string) => JSX.HTMLAttributes | undefined; + /** Columns can be resized by dragging a header's right edge (#426); called with the new width when the drag ends. */ + onResize?: (key: string, width: number) => void; } -export function Table({ columns = [], rows = [], sort, onSort, selected = [], onSelect, cursor, selectable, onCursor, onOpen, rowProps, className, ...rest }: TableProps) { +/** A header's right edge: dragging it sizes the column, live; the width is reported once at the end. */ +function Grip({ th, onDone }: { th: () => HTMLTableCellElement | null; onDone: (w: number) => void }) { + const down = (e: JSX.TargetedPointerEvent) => { + const el = th(); + if (!el || e.button !== 0) return; + e.preventDefault(); e.stopPropagation(); + const grip = e.currentTarget, x0 = e.clientX, w0 = el.getBoundingClientRect().width; + let w = w0; + grip.setPointerCapture(e.pointerId); + const move = (ev: PointerEvent) => { w = Math.max(48, Math.min(1200, Math.round(w0 + ev.clientX - x0))); el.style.width = `${w}px`; }; + const up = () => { grip.removeEventListener("pointermove", move); grip.removeEventListener("pointerup", up); grip.removeEventListener("pointercancel", up); if (w !== w0) onDone(w); }; + grip.addEventListener("pointermove", move); + grip.addEventListener("pointerup", up); + grip.addEventListener("pointercancel", up); + }; + return e.stopPropagation()} />; +} + +export function Table({ columns = [], rows = [], sort, onSort, selected = [], onSelect, cursor, selectable, onCursor, onOpen, rowProps, onResize, className, ...rest }: TableProps) { const emit = (ids: string[]) => onSelect && onSelect(ids); + const ths = useRef(new Map()); return (
{columns.map(c => { const dir = sort && sort.key === c.key ? sort.dir : null; return ( - ); })} diff --git a/packages/design/src/data/data.css b/packages/design/src/data/data.css index 2e25b44..2e6778d 100644 --- a/packages/design/src/data/data.css +++ b/packages/design/src/data/data.css @@ -13,6 +13,9 @@ .oc-row>.oc-icon:last-child{color:var(--text-secondary)} .oc-table{width:100%;border-collapse:collapse;color:var(--text);font:var(--weight-regular) var(--font-size-md)/1 var(--font-sans)} .oc-table th{position:sticky;top:0;z-index:1;height:var(--row-h-lg);padding:0 var(--space-4);border-bottom:var(--border-w) solid var(--border-control);background:var(--surface);color:var(--text-secondary);font-weight:var(--weight-medium);text-align:left;white-space:nowrap} +.oc-table th.is-resizable{position:sticky} +.oc-table__grip{position:absolute;top:6px;bottom:6px;right:-3px;z-index:2;width:7px;cursor:col-resize;border-right:var(--border-w) solid var(--border-divider)} +.oc-table__grip:hover{border-right:2px solid var(--accent)} .oc-table th[aria-sort]{color:var(--text);font-weight:var(--weight-bold)} .oc-table__sort{display:inline-flex;align-items:center;gap:var(--space-2);height:100%;padding:0;border:0;background:transparent;color:inherit;font:inherit;cursor:default} .oc-table__sort:hover{color:var(--text)} diff --git a/packages/model/src/types.ts b/packages/model/src/types.ts index a5651fc..9ec26d0 100644 --- a/packages/model/src/types.ts +++ b/packages/model/src/types.ts @@ -66,6 +66,10 @@ const PREFERENCE_RULES: Record boolean> = { // A canvas made from a photo starts with the frame the photo was taken with (docs/features/camera-layouts.md). canvasTakesFrame: (v) => typeof v === "boolean", clipHoldMs: (v) => typeof v === "number" && Number.isInteger(v) && v >= 100 && v <= 3_600_000, + // The file browser's table per kind of list (#426): which columns show, in order, and their widths. + columns: (v) => isRecord(v) && Object.keys(v).length <= 20 && Object.entries(v).every(([kind, c]) => /^[a-z]{1,20}$/.test(kind) && isRecord(c) + && (c.visible === undefined || (Array.isArray(c.visible) && c.visible.length <= 100 && c.visible.every((k) => typeof k === "string" && k.length <= 80))) + && (c.widths === undefined || (isRecord(c.widths) && Object.keys(c.widths).length <= 100 && Object.entries(c.widths).every(([k, w]) => k.length <= 80 && Number.isInteger(w) && (w as number) >= 40 && (w as number) <= 1200)))), // The taskbar's pins per project: apps by id, files by id. pins: (v) => isRecord(v) && Object.entries(v).every(([project, list]) => UUID.test(project) && Array.isArray(list) && list.length <= 60 && list.every((p) => isRecord(p) && Object.keys(p).length === 1 && (typeof p.app === "string" ? APP_ID.test(p.app) : typeof p.file === "string" && UUID.test(p.file)))),
+ { if (el) ths.current.set(c.key, el); else ths.current.delete(c.key); }} style={{ width: c.width }} className={cx(c.numeric && "is-num", c.mono && "is-mono", onResize && "is-resizable")} aria-sort={dir ? (dir === "asc" ? "ascending" : "descending") : undefined}> {c.sortable ? : c.label} + {onResize && ths.current.get(c.key) ?? null} onDone={(w) => onResize(c.key, w)} />}