Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions apps/studio/src/apps/FilesApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<string, number> }) => 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 : (
<Toolbar>
<Breadcrumb items={crumbs} onNavigate={(id) => (media ? (id === "all" ? setMnav("all") : undefined) : go({ folder: id === "root" ? null : id }))}
Expand All @@ -395,6 +419,8 @@ function Browser({ win, projectId, setTitle, setRoute, entry, start, onEntry }:
<Segmented label="View" value={shownView} onChange={(v) => 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 && <Button size="sm" variant={media ? "primary" : "secondary"} icon="upload" onClick={() => picker.current?.click()}>Import</Button>}
{!media && !shotsOnly && <DropdownMenu size="sm" variant="primary" icon="plus" label="New" align="end" items={[{ id: "folder", label: "Folder", icon: "folder-plus", kbd: "⇧N" }, ...(!home ? [{ id: "shot", label: "Shot", icon: "slate" as const }, { id: "set", label: "Set", icon: "home" as const }, { id: "location", label: "Location", icon: "location" as const }, { id: "canvas", label: "Canvas", icon: "brush" as const }, { id: "timeline", label: "Timeline", icon: "timeline" as const }] : [])]} onSelect={(id) => void (id === "shot" || id === "set" || id === "location" || id === "timeline" ? newOf(id) : id === "canvas" ? ops.newCanvas(root, here) : ops.newFolder(root, here))} />}
{shownView === "list" && <DropdownMenu size="sm" variant="quiet" icon="columns" label="Columns" align="end" items={[{ heading: "Columns" }, ...allCols.filter((c) => 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))} />}
<DropdownMenu size="sm" variant="quiet" icon="more" align="end" items={[{ id: "panels", label: "Panels back to their places", icon: "refresh" }]} onSelect={resetPanels} />
<input ref={picker} type="file" accept={IMAGE_TYPES} multiple hidden onChange={(e) => { const t = e.currentTarget; if (t.files?.length) importAll(t.files); t.value = ""; }} />
</Toolbar>
Expand Down Expand Up @@ -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 <span className="st-name">{thumb ? <img className="st-mini" src={thumb} alt="" loading="lazy" /> : icon(f, 20)}{f.name}{lookOf(f, map).shortcut && <Icon name="shortcut" size={12} label="Shortcut" />}{up && <UploadBadge state={up} />}</span>;
const hit = hiddenMatch(f);
return <span className="st-name">{thumb ? <img className="st-mini" src={thumb} alt="" loading="lazy" /> : icon(f, 20)}{f.name}{lookOf(f, map).shortcut && <Icon name="shortcut" size={12} label="Shortcut" />}{up && <UploadBadge state={up} />}{hit && <span className="st-note st-hit">· {hit}</span>}</span>;
};
// 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 <span className="st-note">–</span>;
Expand All @@ -450,10 +475,7 @@ function Browser({ win, projectId, setTitle, setRoute, entry, start, onEntry }:
: shownView === "board" && !home ? <Board projectId={projectId} items={items} defs={defs} layout={board} onLayout={setBoard} selected={sel} card={card} />
: shownView === "list" ? (
<Table selectable selected={sel} onSelect={setSel} cursor={cur ?? undefined} onCursor={setCur} onOpen={(id) => 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),
Expand Down
5 changes: 4 additions & 1 deletion apps/studio/src/prefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ColumnSetup>;
}
export interface ColumnSetup { visible?: string[]; widths?: Record<string, number> }

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() };
Expand Down
1 change: 1 addition & 0 deletions apps/studio/src/shell.css
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
1 change: 1 addition & 0 deletions docs/features/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 26 additions & 3 deletions packages/design/src/data/Table.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<JSX.HTMLAttributes<HTMLTableElement>, "onSelect"> {
export interface TableProps extends Omit<JSX.HTMLAttributes<HTMLTableElement>, "onSelect" | "onResize"> {
columns: TableColumn[];
rows: ({ id: string } & Record<string, ComponentChildren>)[];
sort?: { key: string; dir: "asc" | "desc" };
Expand All @@ -33,20 +34,42 @@ export interface TableProps extends Omit<JSX.HTMLAttributes<HTMLTableElement>, "
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<HTMLTableRowElement> | 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<HTMLSpanElement>) => {
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 <span className="oc-table__grip" role="separator" aria-orientation="vertical" onPointerDown={down} onClick={(e) => 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<string, HTMLTableCellElement>());
return (
<table role="grid" className={cx("oc-table", className)} {...rest}>
<thead><tr>
{columns.map(c => {
const dir = sort && sort.key === c.key ? sort.dir : null;
return (
<th key={c.key} style={{ width: c.width }} className={cx(c.numeric && "is-num", c.mono && "is-mono")} aria-sort={dir ? (dir === "asc" ? "ascending" : "descending") : undefined}>
<th key={c.key} ref={(el) => { 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
? <button type="button" className="oc-table__sort" onClick={() => onSort && onSort({ key: c.key, dir: dir === "asc" ? "desc" : "asc" })}>{c.label}<Icon name={dir === "desc" ? "arrow-down" : dir === "asc" ? "arrow-up" : "sort"} size={12} /></button>
: c.label}
{onResize && <Grip th={() => ths.current.get(c.key) ?? null} onDone={(w) => onResize(c.key, w)} />}
</th>
);
})}
Expand Down
3 changes: 3 additions & 0 deletions packages/design/src/data/data.css
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
4 changes: 4 additions & 0 deletions packages/model/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ const PREFERENCE_RULES: Record<string, (v: unknown) => 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)))),
Expand Down
Loading