diff --git a/apps/studio/src/shots/AddFiles.tsx b/apps/studio/src/shots/AddFiles.tsx index 212e0ea3..0374d242 100644 --- a/apps/studio/src/shots/AddFiles.tsx +++ b/apps/studio/src/shots/AddFiles.tsx @@ -1,24 +1,36 @@ // Picking files of the project for a content list or a progression (docs/features/shots.md). A collection is never // referenced: it opens, and the photos chosen from it are added one by one. For a progression only pictures are -// offered, and a canvas with frames is added whole or through one of its frames. +// offered, and a canvas with frames is added whole or through one of its frames. A list, or cards (#560) where photos +// are big enough to tell apart: a collection's card opens to its photos, a canvas's frames open from its card. import { useState } from "preact/hooks"; -import { AppIcon, Button, Checkbox, Dialog, EmptyState, Icon, SearchInput, Segmented, cx } from "@openclapper/design"; +import { AppIcon, Button, Checkbox, Dialog, EmptyState, FileCard, FileGrid, Icon, SearchInput, Segmented, cx } from "@openclapper/design"; import type { CanvasBody } from "@openclapper/model"; import type { FileRec } from "../api"; -import { photosOf } from "../collections"; +import { photosOf, tintOf } from "../collections"; import { kindOf } from "../fileKinds"; +import { imageUrl } from "../media"; +import { usePrefs } from "../prefs"; import { Pic } from "./Pic"; import { see, type PicCtx, type PicRef } from "./picture"; const key = (r: PicRef) => `${r.to}|${r.frame ?? ""}`; /** What is never offered: the project's settings, and what only exists for another file. */ const HIDDEN = new Set(["property", "naming", "preferences", "shortcut", "folder", "filter", "preset"]); +type View = "list" | "cards"; +/** The view last used, in this browser. */ +const VIEW_KEY = "shots.addFiles.view"; +const viewOf = (): View => { try { return localStorage.getItem(VIEW_KEY) === "cards" ? "cards" : "list"; } catch { return "list"; } }; export function AddFiles({ title, pictures, files, ctx, self, onAdd, onClose }: { title: string; pictures: boolean; files: readonly FileRec[]; ctx: PicCtx; self: string; onAdd: (refs: PicRef[]) => void; onClose: () => void }) { const [q, setQ] = useState(""); const [kind, setKind] = useState("all"); const [open, setOpen] = useState([]); const [chosen, setChosen] = useState([]); + const [view, setViewState] = useState(viewOf); + const setView = (v: View) => { setViewState(v); setInside(null); try { localStorage.setItem(VIEW_KEY, v); } catch { /* not kept */ } }; + // Cards: the collection or canvas opened to its photos or frames, or null for the top. + const [inside, setInside] = useState(null); + const prefs = usePrefs(); const offered = (t: string) => (pictures ? t === "photo" || t === "canvas" || t === "collection" : !HIDDEN.has(t)); const inColl = (f: FileRec) => !!f.container && ctx.files.get(f.container)?.type === "collection"; const want = (f: FileRec) => !f.deleted_at && !f.internal_of && !f.fixed && f.id !== self && offered(f.type) && !inColl(f) @@ -35,11 +47,46 @@ export function AddFiles({ title, pictures, files, ctx, self, onAdd, onClose }: {frames > 0 && } ); + /** One card that is chosen or not by a click; `more` opens what it holds (a canvas's frames). */ + const pickCard = (r: PicRef, label: string, meta: string, more?: { n: number; what: string }) => ( + } title={`Click to ${has(r) ? "leave out" : "choose"} ${label}`} onClick={() => toggle([r])} + badge={ toggle([r])} aria-label={`Choose ${label}`} />{more && }} /> + ); + const cards = () => { + const at = inside ? ctx.files.get(inside) : undefined; + if (at) { + // Inside a collection (its photos) or a canvas (the whole, then each frame). + const refs: { r: PicRef; label: string; meta: string }[] = at.type === "collection" + ? photosOf(at, files).map((c) => ({ r: { to: c.id }, label: c.name, meta: "Photo" })) + : [{ r: { to: at.id }, label: at.name, meta: "Canvas · as a whole" }, ...((at.body as unknown as CanvasBody | undefined)?.frames ?? []).map((fr) => ({ r: { to: at.id, frame: fr.id }, label: `${at.name} · ${fr.name}`, meta: "One frame of the canvas" }))]; + const all = refs.map((x) => x.r); + return ( +
+
{at.name}{at.type === "collection" && }
+ {refs.length ? {refs.map((x) => pickCard(x.r, x.label, x.meta))} : } +
+ ); + } + return ( +
+ {top.map((f) => { + if (f.type === "collection") { + const kids = photosOf(f, files), n = kids.filter((c) => has({ to: c.id })).length; + return 0} selected={n > 0} + art={} stack={{ srcs: kids.filter((p) => p.photo?.stored.thumbnail).slice(0, 40).map((p) => imageUrl(p.id, "thumbnail")), count: kids.length }} tint={tintOf(f)} mark={prefs.collectionMark} + title="Click to open it and choose its photos" onClick={() => setInside(f.id)} />; + } + const frames = pictures && f.type === "canvas" ? ((f.body as unknown as CanvasBody | undefined)?.frames ?? []) : []; + return pickCard({ to: f.id }, f.name, frames.length ? "Canvas · as a whole" : kindOf(f.type).label, frames.length ? { n: frames.length, what: frames.length === 1 ? "frame" : "frames" } : undefined); + })} +
+ ); + }; return ( {pictures ? "Pictures only: photos, canvases, or one frame of a canvas." : "Any file of the project can be content. Nothing is copied: the list points at the files."}}> -
- {!top.length ? : ( +
{ setQ(v); setInside(null); }} placeholder="Name" style={{ width: 200 }} /> { setKind(v); setInside(null); }} options={[{ value: "all", label: "All" }, { value: "photo", label: "Photos" }, { value: "canvas", label: "Canvases" }]} /> setView(v as View)} options={[{ value: "list", label: "List" }, { value: "cards", label: "Cards" }]} />
+ {!top.length ? : view === "cards" ? cards() : (
    {top.flatMap((f) => { if (f.type === "collection") { diff --git a/apps/studio/src/shots/shots.css b/apps/studio/src/shots/shots.css index df2a890b..7a2db132 100644 --- a/apps/studio/src/shots/shots.css +++ b/apps/studio/src/shots/shots.css @@ -81,9 +81,16 @@ .sh-edit > .cv, .sh-edit > .cv-standalone { flex: 1; min-height: 0; } /* Picking files. */ -.sh-pick { width: min(640px, calc(100vw - 48px)); } +.sh-pick { width: min(720px, calc(100vw - 48px)); } .sh-pick .oc-dialog__body { display: grid; gap: var(--space-4); } .sh-bar { display: flex; align-items: center; gap: var(--space-3); } +/* The cards (#560): bigger pictures to tell photos apart, as tall as the list. */ +.sh-pickcards { height: min(52vh, 440px); overflow: auto; border: var(--border-w) solid var(--border-divider); border-radius: var(--radius-control); } +div.sh-pickcards { display: flex; flex-direction: column; } +div.sh-pickcards > .sh-bar { position: sticky; top: 0; z-index: 1; padding: var(--space-3) var(--space-4); background: var(--surface); border-bottom: var(--border-w) solid var(--border-divider); } +.sh-cardgrid { gap: var(--space-4); padding: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); } +.sh-cardart { position: absolute; inset: 0; border-radius: 3px; } +.sh-cardpick { display: inline-flex; align-items: center; gap: var(--space-2); padding: 2px 4px; border-radius: var(--radius-control); background: var(--surface); box-shadow: 0 0 0 var(--border-w) var(--border-control); } .sh-picklist { list-style: none; margin: 0; padding: 0; height: min(52vh, 440px); overflow: auto; border: var(--border-w) solid var(--border-divider); border-radius: var(--radius-control); } .sh-pickrow { display: flex; align-items: center; gap: var(--space-4); padding: 4px 8px; cursor: pointer; } .sh-pickrow:hover { background: var(--surface-hover); } diff --git a/docs/features/shots.md b/docs/features/shots.md index 5c5b607e..2fa8bfe3 100644 --- a/docs/features/shots.md +++ b/docs/features/shots.md @@ -26,7 +26,7 @@ One window per file, opened from any browser (double-click) or a chip. The defau - **The stage** shows the picture at the progression's playhead (a caption names the progression and the time), or a content entry clicked to look at it ("Back to the playhead" returns); without a progression the first entry of the content. A picture is a photo, or a canvas (its render; one never saved shows its base photo with its frames), through its frame in Outline, Mask, Crop (default) or Full. Beyond the photo is hatched. The caption says which frame and where it came from (its own, the default frame, the canvas's picture). **Open** opens the file's own app; **Edit here** (a canvas, or a double-click) mounts the canvas editor in place of the stage and the side panel, with a bar naming the file and whether it is internal; **Draw or frame** on a photo makes an internal canvas on it, puts it after the photo and edits it here. An empty file offers Add files and Draw a canvas. A missing entry offers to restore the file (from the bin) or to remove the entry. - **The side panel** has two tabs: the file of the window (thumbnail with the rule that chose it, name, the project's properties, for a set the shots that point at it, for a location the sets (with no reference property for that yet, a button adds "Set" or "Locations"), its internal files with what they are used for, Edit here, Make it a project file, Delete when unused, "Used in", System) and the chosen item or entry: one item of the progression (its kind, where it starts, its time, for a zoom block each step's time and its focal lengths, Ease and a slider to look through a smooth move, which frame of a canvas it shows, where its frame comes from, whether its file is listed or counts through the progression; then the file's own facts and properties), several chosen items (how long together, Delete them), or the content entry looked at. -- **Content** (changed by #426 feedback 4): cards or rows, reordered by dragging; a card shows its picture (a progression its first picture, with its number of items and length), its type, and which progressions use it. The first photo, canvas or progression is the shot's **thumbnail**: a "Thumbnail" badge marks it, and "Use as thumbnail" (in a card's menu, or the progression panel's head) moves an entry to the top. "Add files" opens a picker over the project (search, a type filter; a collection opens and its photos are ticked one by one or all; nothing internal); "Progression" makes a new progression and "New canvas" an internal canvas. A card's menu: Use as thumbnail, Edit here, Open, Draw or frame, Insert into the progression at the playhead (or start one), Make it a project file, Remove (an internal file is deleted with its entry once nothing of the shot points at it); a progression's: Use as thumbnail, Open in the progression panel, Rename, Duplicate, Delete. The same menu opens with a right click. A photo or canvas card dragged onto the progression's track becomes an item where it is dropped (onto the empty panel: a new progression). The files the progressions show that the list does not hold are listed below it ("count as content through a progression"); a right click lists one in the content or makes it the thumbnail. +- **Content** (changed by #426 feedback 4): cards or rows, reordered by dragging; a card shows its picture (a progression its first picture, with its number of items and length), its type, and which progressions use it. The first photo, canvas or progression is the shot's **thumbnail**: a "Thumbnail" badge marks it, and "Use as thumbnail" (in a card's menu, or the progression panel's head) moves an entry to the top. "Add files" opens a picker over the project (search, a type filter; a collection opens and its photos are ticked one by one or all; nothing internal), as a **List** or as **Cards** (#560: pictures big enough to tell photos apart; a collection's card opens to its photos with All of them, a canvas's frames open from its card; the view is remembered per browser); "Progression" makes a new progression and "New canvas" an internal canvas. A card's menu: Use as thumbnail, Edit here, Open, Draw or frame, Insert into the progression at the playhead (or start one), Make it a project file, Remove (an internal file is deleted with its entry once nothing of the shot points at it); a progression's: Use as thumbnail, Open in the progression panel, Rename, Duplicate, Delete. The same menu opens with a right click. A photo or canvas card dragged onto the progression's track becomes an item where it is dropped (onto the empty panel: a new progression). The files the progressions show that the list does not hold are listed below it ("count as content through a progression"); a right click lists one in the content or makes it the thumbnail. - **Progression** (shots; changed by #426 feedback 4): one of the shot's progressions as a small timeline (`src/shots/ProgressionEditor.tsx`). The panel's head: a picker of the shot's progressions (switch, New progression, Rename, Duplicate, Delete; deleting takes its zooms and overlay along), its number of items and length, "Thumbnail of the shot" or "Use as thumbnail", Undo and Redo, **Fit** and a zoom slider (or Ctrl + wheel). A bar: **Play/Pause** (Space) runs it on the clock from the playhead and the stage follows, the time, **Timing** (each its own time, one length split evenly, or one length with the first and last picture held twice as long), the **default frame** (none, a preset with a focal length, free-form values, or an aspect ratio with its size), the **overlay** (a switch, Edit overlay; "Add an overlay" makes an internal canvas of the progression on transparent paper, edited here, stretched to each picture's frame), **Generate a zoom…** and **Add pictures…** (photos, canvases, or one frame of a canvas), both inserted at the playhead. The track: a ruler (click or drag to seek; the playhead's knob scrubs; ← → 0.1 s, Shift 1 s, Home, End), one lane of clips, each as wide as it holds with thumbnails (a zoom block one cell per step, a smooth move its two ends with an arrow) and its name, kind and time. Click chooses, Shift adds a range, Ctrl one more, a box drawn on the empty lane chooses what it touches, Ctrl+A all; dragging chosen clips moves them together (a line shows where); pulling a clip's right edge changes its time in tenths of a second (a zoom block in steps per step; in a split timing it switches to each its own time). Delete removes the chosen items (the files stay), Ctrl+X/C/V cut, copy and paste (after the chosen items or at the playhead; across progressions and shots), Ctrl+D duplicates, Ctrl+Z / Ctrl+Shift+Z undo and redo (one history per progression while the window is open). A right click on a clip: Cut, Copy, Paste after, Duplicate, Delete, Edit the canvas here, Use this file as the thumbnail; on the empty lane: Paste here, Choose all, Generate a zoom here…, Add pictures here…. Photos and canvases dropped from a Files window or the desktop become items where they land. The keys are the "shot" scope ([shortcuts](../shortcuts.md)), off while the shot is mounted in a timeline. The ruler and playhead are the design system's `TimeRuler` and `Playhead`, which the Timeline and the master timeline use too. - **The generator** (changed by #426 feedback 4) makes zooms only, from a photo with an angle of view and a preset or free-form values (format, multiplier, squeeze, delivery). The photo is picked from cards with their pictures in two sections, "In this shot" (listed in the content, shown by a progression, or the base of such a canvas) and "Other photos in the project"; a photo without an angle of view (or not uploaded yet) is shown greyed with the reason and cannot be picked. A photo card's menu in the content offers "Generate a zoom from it…". In steps: the ticked primes of a preset, or for a zoom preset and free values common stops, every so many millimetres, or a typed list (whole mm), between From and To (their order is the direction); each picture holds a time. Smooth: from one focal length to another over a time, eased or not. At most 60 frames. The preview shows every frame on the photo and says which see more than it. The result is one internal canvas with a frame per focal length on the photo (named "Framing series" or "Zoom", or as typed) inside the progression, and one **zoom block** that shows it, inserted at the playhead (or where the lane's menu was opened); without a progression it starts one. A double-click on a zoom block, its menu or its panel ("Edit the zoom…") reopens the generator on it (photo, optics, focal lengths as a typed list, time, ease); Apply puts a fresh canvas in its place. "Split into single frames" turns a zoom in steps into one item per frame. A zoom's canvas goes to the bin with the last item that shows it (an undo brings it back), so replaced and deleted zooms leave nothing unused behind. - **Drawing the overlay** (changed by #426 feedback 4): "Edit overlay" mounts the canvas tool in place of the stage with the progression panel left open (the content folds away). Behind the transparent paper it shows the picture at the playhead, through its frame (letterboxed when that frame has another shape than the paper), dimmed unless "Dim the backdrop" is unticked; a line says which picture and time it is. Scrubbing the progression, playing it or choosing its items changes the picture behind and keeps the overlay open; the backdrop is never part of the overlay (the canvas editor's `backdrop`, never saved or rendered). Switching to another progression or "Done" closes it.