diff --git a/apps/studio/src/apps/StartScreen.tsx b/apps/studio/src/apps/StartScreen.tsx index 19e94718..20435b3c 100644 --- a/apps/studio/src/apps/StartScreen.tsx +++ b/apps/studio/src/apps/StartScreen.tsx @@ -4,14 +4,16 @@ import { AppIcon, Button, EmptyState, FileCard, FileGrid, SearchInput, Spinner, import type { FileRec } from "../api"; import * as store from "../files"; import { kindOf } from "../fileKinds"; -import { toastError } from "../hosts"; +import { renameFile } from "../fileOps"; +import { contextMenu, toastError } from "../hosts"; import { thumbOf } from "../photoParts"; import * as wm from "../wm/wm"; /** * What a per-file app shows when it is opened without a file (#426), as a desktop program's start * screen: the project's files of its type to open in this window, and New. Opening one turns this - * window into that file's window; one already open elsewhere comes to the front instead. + * window into that file's window; one already open elsewhere comes to the front instead. A file is + * renamed here too (right-click or F2), so it never has to be looked up in Files for that. */ export function StartScreen({ winId, projectId, type, setTitle, setRoute, extra, canCreate = true, action }: { winId: string; projectId: string; type: string; setTitle: (t: string) => void; setRoute: (r: string) => void; @@ -30,6 +32,13 @@ export function StartScreen({ winId, projectId, type, setTitle, setRoute, extra, .filter((f) => f.type === type && !f.internal_of && (!q || f.name.toLowerCase().includes(q.toLowerCase()))) .sort((a, b) => (b.updated_at ?? b.created_at).localeCompare(a.updated_at ?? a.created_at)), [files, type, q]); const open = (f: FileRec) => { wm.setResource(winId, { type: f.type, id: f.id }); }; + const menu = (f: FileRec, e: MouseEvent) => { + e.preventDefault(); + contextMenu(e, [ + { id: "open", label: "Open", icon: "external", run: () => open(f) }, + { id: "rename", label: "Rename…", icon: "edit", kbd: "F2", run: () => void renameFile(f) }, + ]); + }; const create = async () => { setBusy(true); try { const id = crypto.randomUUID(); await store.create({ project: projectId }, type, { id }); wm.setResource(winId, { type, id }); } catch (e) { toastError(e); setBusy(false); } @@ -53,7 +62,8 @@ export function StartScreen({ winId, projectId, type, setTitle, setRoute, extra, {list.map((f) => { const thumb = thumbOf(f, files); return : } picture={!!thumb} - title={`Open ${f.name}`} onClick={() => open(f)} onKeyDown={(e) => { if (e.key === "Enter") open(f); }} />; + title={`Open ${f.name}`} onClick={() => open(f)} onContextMenu={(e) => menu(f, e)} + onKeyDown={(e) => { if (e.key === "Enter") open(f); if (e.key === "F2") { e.preventDefault(); void renameFile(f); } }} />; })} )} diff --git a/apps/studio/src/apps/TimelineApp.tsx b/apps/studio/src/apps/TimelineApp.tsx index 30ab19f7..8903d3af 100644 --- a/apps/studio/src/apps/TimelineApp.tsx +++ b/apps/studio/src/apps/TimelineApp.tsx @@ -9,14 +9,13 @@ import type { ComponentChildren } from "preact"; import { createPortal } from "preact/compat"; import { useEffect, useMemo, useRef, useState } from "preact/hooks"; import { - AppIcon, Badge, Banner, FileCard, Button, Checkbox, ColorChooser, colorCss, Dock, DropdownMenu, EmptyState, Icon, NumberInput, Popover, PropertyList, PropertyRow, PropertySection, SearchInput, Segmented, Slider, Spinner, StatusBar, Switch, TextInput, Toolbar, ToolbarSpacer, + AppIcon, Badge, Banner, FileCard, Button, SplitView, Checkbox, ColorChooser, colorCss, Dock, DropdownMenu, EmptyState, Icon, NumberInput, Popover, PropertyList, PropertyRow, PropertySection, SearchInput, Segmented, Slider, Spinner, StatusBar, Switch, TextInput, Toolbar, ToolbarSpacer, cx, dockCollapse, dockShow, useDockLayout, useSort, type DockPanel, Playhead, TimeRuler, useTimeScrub, } from "@openclapper/design"; -import { emptyCanvas, HOLD_MS, timelineRefs, type CanvasBody, type Clip, type PresetBody, type TimelineBody } from "@openclapper/model"; +import { emptyCanvas, HOLD_MS, MAX_FILE_NAME, timelineRefs, type CanvasBody, type Clip, type PresetBody, type TimelineBody } from "@openclapper/model"; import * as api from "../api"; import type { FileRec, FileUse } from "../api"; -import { photosOf } from "../collections"; import { kindOf } from "../fileKinds"; import { openFile } from "../fileOps"; import * as store from "../files"; @@ -34,6 +33,8 @@ import { Pic } from "../shots/Pic"; import { see, type Mode, type PicCtx } from "../shots/picture"; import { clock } from "../shots/progressionParts"; import { at as atTime, blocksOf, chaptersOf, moveClips, type Block, type Seg } from "../timeline/cut"; +import { FilesPanel, type FilesCols, type FilesView } from "../timeline/FilesPanel"; +import { SourcePane, type ClipRef } from "../timeline/SourcePane"; import { Editing } from "./CanvasApp"; import { launch, type AppProps } from "./registry"; import { StartScreen } from "./StartScreen"; @@ -47,6 +48,10 @@ const STEP_MS = 500; let n = 0; const uid = () => `c${Date.now().toString(36)}${(++n).toString(36)}`; const clampHold = (ms: number) => Math.min(HOLD_MS.max, Math.max(HOLD_MS.min, Math.round(ms / 100) * 100)); +const remembered = (key: string, fallback: T): T => { try { const v = localStorage.getItem(key); return v ? (JSON.parse(v) as T) : fallback; } catch { return fallback; } }; +const remember = (key: string, v: unknown) => { try { localStorage.setItem(key, JSON.stringify(v)); } catch { /* private mode */ } }; +/** Which panes the centre shows: the file looked at (Source), the cut (Master), or both side by side. */ +type StageView = "source" | "both" | "master"; const bodyOf = (f: FileRec): TimelineBody => ({ clips: [], holdMs: null, ...(f.body as Partial | undefined) }); /** `#/timeline/?t=12.5`: the timeline and where the playhead was. */ @@ -70,6 +75,14 @@ export function TimelineApp(p: AppProps) { /** The master timeline as a window's resource: one per project, so one id stands for it. */ export const MASTER = { type: "master", id: "master" } as const; +/** Source and Master side by side, starting at half the width each (the grip moves it). */ +function HalfSplit({ children }: { children: ComponentChildren }) { + const ref = useRef(null); + const [w, setW] = useState(0); + useEffect(() => { setW(ref.current?.clientWidth ?? 0); }, []); + return
{w > 0 && {children}}
; +} + function TimelineView({ win, resource, projectId, setTitle, setRoute, focused }: AppProps) { const id = resource?.id ?? ""; const { files, bin } = store.useRoot({ project: projectId }); @@ -87,7 +100,9 @@ function Cut({ f, files, bin, projectId, active, startAt, setRoute }: { f: FileR const people = usePeople(project?.workspace_id); const nameOf = (u: string) => (u === me?.id ? "You" : people.get(u) ?? "Someone"); const prefs = usePrefs(); - const map = useMemo(() => new Map([...bin, ...files].map((x) => [x.id, x])), [files, bin]); + const [name, setName] = useState(f.name); + useEffect(() => { setName(f.name); }, [f.name]); + const map =useMemo(() => new Map([...bin, ...files].map((x) => [x.id, x])), [files, bin]); const presetList = presetsIn(files); const ctx: PicCtx = { files: map, presets: new Map(presetList.map((p) => [p.id, p.body as PresetBody])) }; @@ -171,10 +186,11 @@ function Cut({ f, files, bin, projectId, active, startAt, setRoute }: { f: FileR }, [playing, total]); // The address says where the playhead is when it stops. useEffect(() => { if (!playing) setRoute(`${f.id}${t > 0 ? `?t=${(t / 1000).toFixed(1)}` : ""}`); }, [playing, t > 0 ? Math.round(t / 100) : 0, f.id]); - const seek = (time: number) => { setPlaying(false); setEditing(null); const x = Math.max(0, Math.min(total, time)); setT(x); const b = atTime(blocks, x)?.block; if (b) setSel([b.clip.id]); }; + // While a file is edited in place the cut is locked (nothing moves the playhead or the clips) until Done. + const seek = (time: number) => { if (editing) return; setPlaying(false); const x = Math.max(0, Math.min(total, time)); setT(x); const b = atTime(blocks, x)?.block; if (b) setSel([b.clip.id]); }; const pick = (b: Block, e?: MouseEvent | KeyboardEvent, time = b.start) => { + if (editing) return; setPlaying(false); setT(time); - if (editing && editing !== b.clip.id) setEditing(null); if (e && (e.ctrlKey || e.metaKey)) { setSel(sel.includes(b.clip.id) ? sel.filter((x) => x !== b.clip.id) : [...sel, b.clip.id]); return; } if (e?.shiftKey && sel.length) { const a = blocks.findIndex((x) => x.clip.id === sel[sel.length - 1]), z = blocks.indexOf(b); @@ -188,13 +204,13 @@ function Cut({ f, files, bin, projectId, active, startAt, setRoute }: { f: FileR // ---------- Changing the cut ---------- const insertAt = () => { const last = clips.map((c) => c.id).filter((x) => sel.includes(x)).pop(); return last ? clips.findIndex((c) => c.id === last) + 1 : clips.length; }; const insert = (refs: { file: string; frame?: string }[], index = insertAt()) => { - if (readonly || !refs.length) return; + if (readonly || editing || !refs.length) return; const made: Clip[] = refs.map((r) => ({ id: uid(), file: r.file, ...(r.frame ? { frame: r.frame } : {}), ms: hold })); setClips([...clips.slice(0, index), ...made, ...clips.slice(index)]); setSel(made.map((c) => c.id)); }; /** A placeholder gets the file and keeps its time and chapter. */ - const fill = (clipId: string, r: { file: string; frame?: string }) => { patch([clipId], (c) => { const { title: _t, ...rest } = c; void _t; return { ...rest, file: r.file, ...(r.frame ? { frame: r.frame } : {}) }; }); setSel([clipId]); }; + const fill = (clipId: string, r: { file: string; frame?: string }) => { if (editing) return; patch([clipId], (c) => { const { title: _t, ...rest } = c; void _t; return { ...rest, file: r.file, ...(r.frame ? { frame: r.frame } : {}) }; }); setSel([clipId]); }; const placeholder = () => { if (readonly) return; const c: Clip = { id: uid(), file: null, ms: hold, title: "Placeholder" }, i = insertAt(); setClips([...clips.slice(0, i), c, ...clips.slice(i)]); setSel([c.id]); setPanels(dockShow(panels, "clip")); }; const remove = (ids: readonly string[]) => { if (readonly || !ids.length) return; setClips(clips.filter((c) => !ids.includes(c.id))); setSel([]); }; const nudge = (d: number) => patch(sel, (c) => ({ ...c, ms: clampHold(c.ms + d) })); @@ -255,7 +271,19 @@ function Cut({ f, files, bin, projectId, active, startAt, setRoute }: { f: FileR const [mode, setMode] = useState("crop"); const [q, setQ] = useState(""); const [kind, setKind] = useState("all"); - const [open, setOpen] = useState([]); + // Per browser, as the Files app keeps its view: how the Files panel lists, which panes the centre shows. + const [filesView, setFilesViewState] = useState(() => remembered("timeline.files.view", "list")); + const setFilesView = (v: FilesView) => { setFilesViewState(v); remember("timeline.files.view", v); }; + // How many cards across the Files panel: as many as fit (auto), or one or two whatever its width. + const [filesCols, setFilesColsState] = useState(() => remembered("timeline.files.cols", "auto")); + const setFilesCols = (v: FilesCols) => { setFilesColsState(v); remember("timeline.files.cols", v); }; + const [stageView, setStageViewState] = useState(() => remembered("timeline.stage", "master")); + const setStageView = (v: StageView) => { setStageViewState(v); remember("timeline.stage", v); }; + // The file looked at in Source (this window only). + const [source, setSource] = useState(null); + /** A click looks at a file in Source (seen when the pane shows); a double-click opens it in its own app. */ + const look = (r: ClipRef) => setSource(r); + const openOwn = (fid: string) => { const x = map.get(fid); if (x) openFile(x, map); }; const [uses, setUses] = useState([]); const useFile = one?.file && !one.file.deleted_at ? one.file : null; useEffect(() => { if (useFile) void api.fetchUses(useFile.id).then(setUses, () => setUses([])); else setUses([]); }, [useFile?.id]); @@ -266,9 +294,11 @@ function Cut({ f, files, bin, projectId, active, startAt, setRoute }: { f: FileR const seenOf = (s: Seg, u = 0) => (s.ref ? see(s.ref, ctx, s.def ?? null, u) : null); // A file dragged from the Files panel: a ghost at the pointer; a line where it would land, or a placeholder lit up. + // A collection drags all its photos, in its order, as clips side by side (it never fills a placeholder). const [drop, setDrop] = useState<{ x: number; y: number; label: string; line: [number, number, number] | null; at: number | null; into: string | null } | null>(null); - const fileDrag = (r: { file: string; frame?: string }, label: string) => (e: PointerEvent) => { - if (e.button !== 0 || readonly) return; + const fileDrag = (r: ClipRef | ClipRef[], label: string) => (e: PointerEvent) => { + const refs = Array.isArray(r) ? r : [r]; + if (e.button !== 0 || readonly || editing || !refs.length) return; const sx = e.clientX, sy = e.clientY; let live: typeof drop = null; const move = (m: PointerEvent) => { @@ -278,13 +308,13 @@ function Cut({ f, files, bin, projectId, active, startAt, setRoute }: { f: FileR if (box && inside) { const els = [...track.current!.querySelectorAll(":scope > [data-sort]")], rs = els.map((c) => c.getBoundingClientRect()); // Over the middle of a placeholder: it is filled. Elsewhere: a new clip goes between two. - const hit = els.findIndex((el, i) => el.dataset.placeholder === "1" && m.clientX > rs[i].left + rs[i].width * 0.25 && m.clientX < rs[i].right - rs[i].width * 0.25); + const hit = refs.length > 1 ? -1 : els.findIndex((el, i) => el.dataset.placeholder === "1" && m.clientX > rs[i].left + rs[i].width * 0.25 && m.clientX < rs[i].right - rs[i].width * 0.25); if (hit >= 0) into = els[hit].dataset.clip ?? null; else { index = rs.filter((x) => x.left + x.width / 2 < m.clientX).length; line = [index < rs.length ? rs[index].left - 2 : (rs[rs.length - 1]?.right ?? box.left) + 1, box.top, box.height]; } } live = { x: m.clientX, y: m.clientY, label, line, at: index, into }; setDrop(live); }; - const up = () => { removeEventListener("pointermove", move); removeEventListener("pointerup", up); setDrop(null); if (live?.into) fill(live.into, r); else if (live?.at != null) insert([r], live.at); }; + const up = () => { removeEventListener("pointermove", move); removeEventListener("pointerup", up); setDrop(null); if (live?.into) fill(live.into, refs[0]); else if (live?.at != null) insert(refs, live.at); }; addEventListener("pointermove", move); addEventListener("pointerup", up); }; const stretch = (b: Block) => (e: PointerEvent) => { @@ -329,25 +359,25 @@ function Cut({ f, files, bin, projectId, active, startAt, setRoute }: { f: FileR :
} {seg && here && {chapterAt && {chapterAt.title}}{labelOf(here.block)}{here.block.segs.length > 1 && · picture {here.block.segs.indexOf(seg) + 1} of {here.block.segs.length}}} -
-
); + // ---------- Source and Master ---------- + const sourceFile = source ? map.get(source.file) : undefined; + const sourcePane = insert([r])} drag={(r, label) => fileDrag(r, label)} />; + const masterPane =
{stageView !== "master" &&
Master{f.name}
}{stage}
; + // While a file is edited in place its editor takes the whole centre; the panes come back after Done. + const centre = editFile || stageView === "master" ? stage : stageView === "source" ? sourcePane + : {sourcePane}{masterPane}; + // ---------- The strip ---------- const scrub = useTimeScrub(scale, seek); const fit = () => { const w = view.current?.clientWidth; if (w && total) setScale(Math.max(2, (w - 34) / (total / 1000))); }; const px = (ms: number) => (ms / 1000) * scale; - const strip = !blocks.length ?

Nothing in this cut yet. Drag files here from the Files panel, double-click one, or add a placeholder.

: ( -
{ if (e.ctrlKey) { e.preventDefault(); setScale((s) => Math.min(240, Math.max(2, s * (e.deltaY < 0 ? 1.15 : 1 / 1.15)))); } }}> + const strip = !blocks.length ?

Nothing in this cut yet. Drag files here from the Files panel or press a file's plus, or add a placeholder.

: ( +
{ if (e.ctrlKey) { e.preventDefault(); setScale((s) => Math.min(240, Math.max(2, s * (e.deltaY < 0 ? 1.15 : 1 / 1.15)))); } }}>
{chapters.map((c) => )}
@@ -379,9 +409,27 @@ function Cut({ f, files, bin, projectId, active, startAt, setRoute }: { f: FileR
); - const stripActions = ( + // The transport moves the playhead, so it sits with the cut (#549 feedback); how pictures are drawn is the window's. + const transport = ( + + +
+ ) : ( +
+ {transport} + {clips.length} clips @@ -404,31 +452,9 @@ function Cut({ f, files, bin, projectId, active, startAt, setRoute }: { f: FileR // ---------- The side panels ---------- const offered = files.filter((x) => !x.internal_of && ["photo", "canvas", "shot", "collection"].includes(x.type) && (kind === "all" || x.type === kind || (kind === "photo" && x.type === "collection")) && (!q || x.name.toLowerCase().includes(q.toLowerCase()))); - const inColl = (x: FileRec) => !!x.container && map.get(x.container)?.type === "collection"; const thumbSeen = (fid: string, frame?: string) => { const x = map.get(fid); if (x?.type !== "shot") return see({ to: fid, frame }, ctx); const s = blocksOf([{ id: "x", file: fid, ms: 1 }], map)[0].segs[0]; return seenOf(s) ?? see({ to: fid }, ctx); }; - const fileRow = (x: FileRec, r: { file: string; frame?: string }, label: string, depth = 0, extra?: ComponentChildren) => ( -
  • insert([r])} title="Drag into the cut (onto a placeholder fills it), or double-click to add after the chosen clip"> - - {label}{r.frame ? "One frame of the canvas" : kindOf(x.type).label} - {extra && e.stopPropagation()}>{extra}} -
  • - ); - const twist = (fid: string, count: number, what: string) => { const on = open.includes(fid); return ; }; - const filesBody = ( -
      - {offered.filter((x) => !inColl(x)).sort((a, b) => kindOf(a.type).label.localeCompare(kindOf(b.type).label) || a.name.localeCompare(b.name, undefined, { numeric: true })).flatMap((x) => { - const on = open.includes(x.id); - if (x.type === "collection") { - const kids = photosOf(x, files); - return [
    • {x.name}Collection: its photos are added one by one{twist(x.id, kids.length, "photos")}
    • , ...(on ? kids.map((c) => fileRow(c, { file: c.id }, c.name, 1)) : [])]; - } - const frames = x.type === "canvas" ? ((x.body as unknown as CanvasBody | undefined)?.frames ?? []) : []; - return [fileRow(x, { file: x.id }, x.name, 0, frames.length ? twist(x.id, frames.length, "frames") : undefined), ...(on ? frames.map((fr) => fileRow(x, { file: x.id, frame: fr.id }, `${x.name} · ${fr.name}`, 1)) : [])]; - })} - {!offered.length &&
    • Nothing matches.
    • } -
    - ); + const filesBody = insert(Array.isArray(r) ? r : [r])} drag={(r, label) => fileDrag(r, label)} />; const used = [...new Set(clips.filter((c) => c.file).map((c) => c.file!))].map((fid) => ({ fid, x: map.get(fid), count: clips.filter((c) => c.file === fid).length })); const placeholders = clips.filter((c) => !c.file); /** A click on a file in use goes to its next clip after the chosen one. */ @@ -518,26 +544,35 @@ function Cut({ f, files, bin, projectId, active, startAt, setRoute }: { f: FileR ); const dockPanels: DockPanel[] = [ - { id: "files", title: "Files", icon: "folder", actions:
    , body: filesBody }, + { id: "files", title: "Files", icon: "folder", actions:
    setFilesView(v as FilesView)} options={[{ value: "list", icon: "list", title: "List" }, { value: "cards", icon: "grid", title: "Cards: bigger pictures, a collection as one card to scrub through" }]} /> + ({ id: `cols:${c}`, label: c === "auto" ? "As many as fit" : c === "1" ? "One column" : "Two columns", checked: filesCols === c, disabled: filesView !== "cards" }))]} + onSelect={(id) => { if (id.startsWith("cols:")) setFilesCols(id.slice(5) as FilesCols); }} />
    , body: filesBody }, { id: "used", title: "In use", icon: "files", body: usedBody }, { id: "chapters", title: "Chapters", icon: "bookmark", body: chaptersBody }, - { id: "clip", title: chosen.length > 1 ? "Clips" : "Clip", icon: "info", body:
    {clipBody}
    }, + { id: "clip", title: chosen.length > 1 ? "Clips" : "Clip", icon: "info", body:
    {clipBody}
    }, { id: "strip", title: "Cut", icon: "film", actions: stripActions, body: strip }, ]; const master = project?.master ?? []; + /** The name is typed in place, under the timeline's lock (read-only watchers see it plain). */ + const commitName = () => { const to = name.trim(); if (!to || to === f.name || readonly) { setName(f.name); return; } void store.rename(f, to, lock.holder).catch((e) => { toastError(e); setName(f.name); }); }; return (
    - {f.name} + + {readonly ? {f.name} + : setName(e.currentTarget.value)} onBlur={commitName} onKeyDown={(e) => { if (e.key === "Enter") e.currentTarget.blur(); if (e.key === "Escape") { setName(f.name); e.currentTarget.blur(); } }} />} {lock.editing ? : {lock.by === "You" ? "Editing in another window of yours" : lock.by ? `${lock.by} is editing` : "Nobody is editing"}} + setMode(v as Mode)} options={[{ value: "outline", label: "Outline" }, { value: "mask", label: "Mask" }, { value: "crop", label: "Crop" }, { value: "full", label: "Full" }]} /> + setStageView(v as StageView)} options={[{ value: "source", label: "Source", title: "Only the file you look at" }, { value: "both", label: "Both", title: "The file you look at beside the cut" }, { value: "master", label: "Master", title: "Only the cut" }]} /> resetPanels()} /> - {stage} - {clips.length} clips · {clock(total)} · {chapters.length} chapters{placeholders.length > 0 && <> · {placeholders.length} placeholders}{sel.length > 1 && <> · {sel.length} chosen}{playing && <> · playing}{editFile && <> · editing {editFile.name} in place: playback is paused and the playhead stays on the clip} · {readonly ? (lock.live ? "Read-only, live" : "Read-only, read again every 5 s") : status === "saving" ? "Saving…" : status === "waiting" ? "Changed" : status === "failed" ? Not saved : "Saved"} + {centre} + {clips.length} clips · {clock(total)} · {chapters.length} chapters{placeholders.length > 0 && <> · {placeholders.length} placeholders}{sel.length > 1 && <> · {sel.length} chosen}{playing && <> · playing}{editFile && <> · editing {editFile.name} in place: the cut is locked until Done} · {readonly ? (lock.live ? "Read-only, live" : "Read-only, read again every 5 s") : status === "saving" ? "Saving…" : status === "waiting" ? "Changed" : status === "failed" ? Not saved : "Saved"} {drop && createPortal(<>{drop.line && }
    {drop.into ? `Fill the placeholder with ${drop.label}` : drop.label}
    , document.body)}
    ); diff --git a/apps/studio/src/shortcuts.ts b/apps/studio/src/shortcuts.ts index 682fc108..d17f62f7 100644 --- a/apps/studio/src/shortcuts.ts +++ b/apps/studio/src/shortcuts.ts @@ -9,7 +9,7 @@ * then, so a page's own letter never swallows a section jump. */ -export type ScopeId = "global" | "wm" | "files" | "desktop" | "bin" | "photo" | "timeline" | "shot" | "flows"; +export type ScopeId = "global" | "wm" | "files" | "desktop" | "bin" | "photo" | "start" | "timeline" | "shot" | "flows"; export interface Scope { label: string; @@ -28,6 +28,7 @@ export const SCOPES: Record = { desktop: { label: "Desktop icons", with: [] }, bin: { label: "Recycle bin", with: [] }, photo: { label: "Photo", with: [] }, + start: { label: "Start screens (an app opened without a file)", with: [] }, timeline: { label: "Timeline", with: [] }, shot: { label: "Shot · progression", with: [] }, flows: { label: "Flows (extension)", with: [] }, @@ -114,6 +115,10 @@ export const SHORTCUTS = [ { scope: "photo", action: "prev", keys: ["ArrowLeft"], label: "Previous photo" }, { scope: "photo", action: "next", keys: ["ArrowRight"], label: "Next photo" }, + // ---- Start screens (docs/features/files.md) + { scope: "start", action: "rename", keys: ["F2"], info: true, label: "Rename the focused file" }, + { scope: "start", action: "menu", keys: ["Right-click"], info: true, label: "On a file: open, rename" }, + // ---- Timeline (docs/features/timeline.md) { scope: "timeline", action: "play", keys: [" "], display: "Space", label: "Play or pause" }, { scope: "timeline", action: "prev", keys: ["ArrowLeft"], label: "Previous clip" }, diff --git a/apps/studio/src/timeline/FilesPanel.tsx b/apps/studio/src/timeline/FilesPanel.tsx new file mode 100644 index 00000000..9b40c2ab --- /dev/null +++ b/apps/studio/src/timeline/FilesPanel.tsx @@ -0,0 +1,103 @@ +// The Files panel of a timeline window (docs/features/timeline.md): the project's photos, canvases, shots and +// collections, as a list (a collection or a canvas opens in place to its photos or frames) or as cards (a collection +// is one card to scrub through, as in Files). A click looks at a file in the Source pane; a drag or the plus puts it +// into the cut (a collection: its photos, in its order, one clip each); a double-click opens it in its own app. +import { AppIcon, Button, FileCard, FileGrid, cx, type CollectionMark } from "@openclapper/design"; +import type { CanvasBody } from "@openclapper/model"; +import type { ComponentChildren } from "preact"; +import { useState } from "preact/hooks"; +import type { FileRec } from "../api"; +import { photosOf, tintOf } from "../collections"; +import { kindOf } from "../fileKinds"; +import { imageUrl } from "../media"; +import { thumbOf } from "../photoParts"; +import { Pic } from "../shots/Pic"; +import type { Seen } from "../shots/picture"; +import type { ClipRef } from "./SourcePane"; + +export type FilesView = "list" | "cards"; +/** Cards across the panel: as many as fit, or a fixed one or two (one makes each picture as wide as the panel). */ +export type FilesCols = "auto" | "1" | "2"; + +export function FilesPanel({ view, cols = "auto", offered, files, map, mark, shown, canAdd, thumbSeen, look, open: openOwn, add, drag }: { + view: FilesView; + cols?: FilesCols; + /** The files that pass the panel's search and type filter. */ + offered: FileRec[]; + files: FileRec[]; map: ReadonlyMap; mark: CollectionMark; + /** What the Source pane shows (marked as chosen). */ + shown: ClipRef | null; + canAdd: boolean; + thumbSeen: (fid: string, frame?: string) => Seen | null; + /** A click looks at it in Source. */ + look: (r: ClipRef) => void; + /** A double-click opens it in its own app. */ + open: (fid: string) => void; + add: (r: ClipRef | ClipRef[]) => void; + drag: (r: ClipRef | ClipRef[], label: string) => (e: PointerEvent) => void; +}) { + const [open, setOpen] = useState([]); + const inColl = (x: FileRec) => !!x.container && map.get(x.container)?.type === "collection"; + const top = offered.filter((x) => !inColl(x)).sort((a, b) => kindOf(a.type).label.localeCompare(kindOf(b.type).label) || a.name.localeCompare(b.name, undefined, { numeric: true })); + const framesOf = (x: FileRec) => (x.type === "canvas" ? ((x.body as unknown as CanvasBody | undefined)?.frames ?? []) : []); + const isShown = (r: ClipRef) => shown?.file === r.file && (shown.frame ?? "") === (r.frame ?? ""); + const plus = (r: ClipRef | ClipRef[], label: string) => ; }; + return ( +
      + {top.flatMap((x) => { + const on = open.includes(x.id); + if (x.type === "collection") { + const kids = photosOf(x, files); + return [ +
    • look({ file: x.id })} onDblClick={() => openOwn(x.id)} title={collHint}> + {x.name}Collection: drag it in for all its photos + e.stopPropagation()} onClick={(e) => e.stopPropagation()}>{twist(x.id, kids.length, "photos")} + {kids.length > 0 && plus(photoRefs(kids), many(kids.length, x.name))} +
    • , + ...(on ? kids.map((c) => row(c, { file: c.id }, c.name, 1)) : []), + ]; + } + const frames = framesOf(x); + return [row(x, { file: x.id }, x.name, 0, frames.length ? twist(x.id, frames.length, "frames") : undefined), ...(on ? frames.map((fr) => row(x, { file: x.id, frame: fr.id }, `${x.name} · ${fr.name}`, 1)) : [])]; + })} +
    + ); +} + diff --git a/apps/studio/src/timeline/SourcePane.tsx b/apps/studio/src/timeline/SourcePane.tsx new file mode 100644 index 00000000..6562dccc --- /dev/null +++ b/apps/studio/src/timeline/SourcePane.tsx @@ -0,0 +1,76 @@ +// The Source pane of a timeline window (docs/features/timeline.md): a file from the Files panel looked at large, +// beside the cut (Master), before it goes in. A collection, a canvas with frames and a shot with a progression +// show a filmstrip of what they hold; the picture shown is what Add and a drag put into the cut. +import { AppIcon, Button, EmptyState, cx } from "@openclapper/design"; +import type { CanvasBody } from "@openclapper/model"; +import { useState } from "preact/hooks"; +import type { FileRec } from "../api"; +import { photosOf } from "../collections"; +import { kindOf } from "../fileKinds"; +import { Pic } from "../shots/Pic"; +import { see, type Mode, type PicCtx, type Seen } from "../shots/picture"; +import { blocksOf } from "./cut"; + +/** What goes into the cut: a file, or one frame of a canvas. */ +export type ClipRef = { file: string; frame?: string }; + +interface Member { key: string; label: string; seen: Seen | null; overlay?: string | null; add: ClipRef | null } + +/** The pictures a file holds, in order: a collection's photos, a canvas and its frames, a shot's progression. */ +function membersOf(x: FileRec, files: FileRec[], map: ReadonlyMap, ctx: PicCtx, overlaySrc: (id: string | null | undefined) => string | null): Member[] { + if (x.type === "collection") return photosOf(x, files).map((p) => ({ key: p.id, label: p.name, seen: see({ to: p.id }, ctx), add: { file: p.id } })); + if (x.type === "shot") { + // As the cut plays it: one segment per picture of its progression (or its first picture); the shot goes in whole. + const segs = blocksOf([{ id: "source", file: x.id, ms: 1 }], map)[0]?.segs ?? []; + return segs.map((s, i) => ({ key: String(i), label: segs.length > 1 ? `Picture ${i + 1}` : x.name, seen: s.ref ? see(s.ref, ctx, s.def ?? null) : null, overlay: overlaySrc(s.overlay), add: { file: x.id } })); + } + const whole: Member = { key: "", label: x.name, seen: see({ to: x.id }, ctx), add: { file: x.id } }; + if (x.type !== "canvas") return [whole]; + const frames = (x.body as unknown as CanvasBody | undefined)?.frames ?? []; + return [whole, ...frames.map((fr) => ({ key: fr.id, label: `${x.name} · ${fr.name}`, seen: see({ to: x.id, frame: fr.id }, ctx), add: { file: x.id, frame: fr.id } }))]; +} + +export function SourcePane({ x, frame, files, map, ctx, mode, overlaySrc, canAdd, onAdd, drag }: { + x: FileRec | undefined; frame?: string; files: FileRec[]; map: ReadonlyMap; ctx: PicCtx; mode: Mode; + overlaySrc: (id: string | null | undefined) => string | null; + /** False while the timeline is read-only or the cut is locked. */ + canAdd: boolean; + onAdd: (r: ClipRef) => void; + /** Starts the same drag as a row of the Files panel. */ + drag: (r: ClipRef, label: string) => (e: PointerEvent) => void; +}) { + const members = x && !x.deleted_at ? membersOf(x, files, map, ctx, overlaySrc) : []; + const [at, setAt] = useState(() => Math.max(0, members.findIndex((m) => m.key === (frame ?? "")))); + const i = Math.min(at, Math.max(0, members.length - 1)); + const m = members[i]; + const step = (d: number) => setAt(Math.min(members.length - 1, Math.max(0, i + d))); + const head = ( +
    + Source + {x && <>{m?.label ?? x.name}} + {members.length > 1 && {i + 1} / {members.length}} + + {m?.add && } +
    + ); + if (!x) return
    {head}
    Click a file in the Files panel to look at it here.
    ; + return ( +
    { if (e.key === "ArrowLeft" || e.key === "ArrowRight") { e.preventDefault(); step(e.key === "ArrowLeft" ? -1 : 1); } }}> + {head} +
    + {!m ? + : m.seen ?
    + : } +
    + {members.length > 1 && ( +
    + {members.map((y, k) => ( + + ))} +
    + )} +
    + ); +} diff --git a/apps/studio/src/timeline/timeline.css b/apps/studio/src/timeline/timeline.css index 9584fd07..2bc47450 100644 --- a/apps/studio/src/timeline/timeline.css +++ b/apps/studio/src/timeline/timeline.css @@ -1,8 +1,9 @@ /* The Timeline window (docs/features/timeline.md): stage with its transport, the strip, the side panels. Builds on shots.css. */ .tl-stage { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; } .tl-stage > .sh-stage.is-empty { background: var(--photo-bg); } -.tl-transport { flex: none; display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-5); border-top: var(--border-w) solid var(--border-divider); background: var(--surface); } -.tl-time { margin-left: var(--space-4); color: var(--text-secondary); } +/* The transport, at the start of the Cut's row: it moves the playhead. */ +.tl-transport { flex: none; display: inline-flex; align-items: center; gap: var(--space-2); padding-right: var(--space-4); margin-right: var(--space-2); border-right: var(--border-w) solid var(--border-divider); } +.tl-time { margin-left: var(--space-3); color: var(--text-secondary); white-space: nowrap; } .tl-time strong { color: var(--text); } .tl-card { display: grid; justify-items: center; gap: var(--space-3); max-width: 420px; padding: var(--space-8); border: 2px dashed color-mix(in srgb, var(--over-paper) 45%, transparent); border-radius: var(--radius-card, 8px); text-align: center; color: var(--over-paper); } .tl-card strong { font-size: var(--font-size-lg, 18px); } @@ -47,5 +48,31 @@ .tl-file.is-missing { color: var(--danger); } .tl-file > b { flex: none; min-width: 14px; text-align: center; color: var(--text-secondary); } .tl-file > .oc-icon:first-child { flex: none; color: var(--text-disabled); } -.tl-file--coll { cursor: default; } +.tl-file--coll { cursor: pointer; } .tl-dot { flex: none; width: 10px; height: 10px; margin: 0 4px; border-radius: 50%; } + +/* Editing a file in place locks the cut until Done (the strip is inert meanwhile). */ +.tl-scroll.is-locked { opacity: .55; } +.tl-locked { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--text-secondary); font-size: var(--font-size-2xs); } + +/* The Files panel as cards: two or more across the panel; a card drags into the cut, its plus adds it. */ +.tl-cards { gap: var(--space-4); padding: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); } +.tl-cards .oc-filecard { touch-action: none; user-select: none; } +.tl-cardadd { display: grid; border-radius: var(--radius-control); background: var(--surface); box-shadow: 0 0 0 var(--border-w) var(--border-control); } + +/* Source and Master: the file looked at beside the cut, each with a small head naming it. */ +.tl-source, .tl-master { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; } +.tl-source:focus-visible { outline: 0; box-shadow: inset 0 0 0 2px var(--focus-ring); } +.tl-source > .sh-stage { touch-action: none; } +.tl-split { flex: 1; display: flex; min-width: 0; min-height: 0; } +.tl-panehead { flex: none; display: flex; align-items: center; gap: var(--space-3); min-height: 32px; padding: 0 var(--space-3) 0 var(--space-5); border-bottom: var(--border-w) solid var(--border-divider); background: var(--surface); color: var(--text-secondary); font-size: var(--font-size-2xs); } +.tl-panehead > b { color: var(--text); text-transform: uppercase; letter-spacing: .06em; } +.tl-panehead__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); } +.tl-panehead__count { flex: none; } +.tl-source__strip { flex: none; display: flex; gap: var(--space-2); padding: var(--space-3); overflow-x: auto; border-top: var(--border-w) solid var(--border-divider); background: var(--surface); } +.tl-source__cell { flex: none; width: 72px; height: 48px; padding: 0; border: 2px solid transparent; border-radius: 3px; background: none; cursor: pointer; } +.tl-source__cell > .sh-box { width: 100%; height: 100%; border-radius: 2px; } +.tl-source__cell.is-on { border-color: var(--accent); } +.tl-source__cell:focus-visible { outline: 0; box-shadow: 0 0 0 1px var(--focus), 0 0 0 3px var(--focus-ring); } +.tl-cards--1 { grid-template-columns: minmax(0, 1fr); } +.tl-cards--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } diff --git a/docs/features/desktop.md b/docs/features/desktop.md index b3578832..6873690d 100644 --- a/docs/features/desktop.md +++ b/docs/features/desktop.md @@ -21,7 +21,7 @@ The Studio is a desktop scoped to one project: apps in windows, a taskbar, virtu - **Motion** comes from the design system's window frame: opening, closing (a closed window fades, then leaves the store), minimising toward its taskbar button, and maximise, snap and restore as one move. - Click anywhere in a window to bring it to the front. Right-click the title bar for minimise, maximise, snap, **Move to** another desktop, and close. - **One window per file:** opening something that is open focuses its window, on whichever desktop it is. An app marked `singleton` has one window in all. -- **Start screens** (`apps/StartScreen.tsx`, #426): an app for one file opened without one (from the launcher) shows the project's files of its type, newest first, with search and New, as a desktop program does; a click opens that file in the same window (or brings up its window if it is open). Photo has no New (photos are imported); Timeline lists the master timeline first. +- **Start screens** (`apps/StartScreen.tsx`, #426): an app for one file opened without one (from the launcher) shows the project's files of its type, newest first, with search and New, as a desktop program does; a click opens that file in the same window (or brings up its window if it is open). Photo has no New (photos are imported); Timeline lists the master timeline first. Right-click a file (Open, Rename…) or press F2 on it to rename it there. - **Closing** asks first when the app registered a guard (`wm/closeGuards.ts`). - **Layout per project and browser** (`wm/desktopState.ts`): windows, z-order, each window's route and the desktops in `localStorage["desktop."]` (`v: 3`; anything else starts fresh), saved 600 ms after a change, on a project switch and on `pagehide`. diff --git a/docs/features/timeline.md b/docs/features/timeline.md index acf13940..e76e8b38 100644 --- a/docs/features/timeline.md +++ b/docs/features/timeline.md @@ -29,12 +29,14 @@ Every project has one: an ordered list of the project's timelines (`PUT /api/pro ## The Timeline window (`apps/studio/src/apps/TimelineApp.tsx`, `src/timeline/`) -One window per timeline (Files: New, Timeline; a double-click on one). The U4 layout: the **stage** with the transport under it; the **Cut** below (the strip); at the left **Files**, **In use** and **Chapters**; at the right the chosen **Clip**. Panels move, size, collapse and stack as everywhere (`Dock`). +One window per timeline (Files: New, Timeline; a double-click on one). The U4 layout: the **stage**; the **Cut** below (the strip, with the transport at the start of its row); at the left **Files**, **In use** and **Chapters**; at the right the chosen **Clip**. Panels move, size, collapse and stack as everywhere (`Dock`). -- **The stage** plays what is under the playhead: a picture through its frame in Outline, Mask, Crop or Full (the window's choice); a progression's pictures at its timing with its default frame and overlay, a smooth zoom moving; a placeholder or a missing file as a card. The caption names the chapter and the clip (and the picture of a progression). Transport: to the start, previous and next clip, play and pause (on the clock; at the end it stops and goes back to the start), the time. +- **The stage** plays what is under the playhead: a picture through its frame in Outline, Mask, Crop or Full (the window's choice, in its toolbar, for Source and Master alike); a progression's pictures at its timing with its default frame and overlay, a smooth zoom moving; a placeholder or a missing file as a card. The caption names the chapter and the clip (and the picture of a progression). +- **Source and Master** (the toolbar's Source · Both · Master, remembered per browser): Master is the stage above; Source shows the file chosen in the Files panel, large, through the same view mode. A collection, a canvas with frames and a shot with a progression get a filmstrip of what they hold (a click or ← → steps through it). **Add to the cut** (after the chosen clips) or a drag from the picture into the strip puts in what is shown: the photo, the canvas or its frame, the whole shot. Both puts Source at the left and Master at the right, with a grip between them. Looking at a file changes nothing in the cut. +- **The transport** opens the Cut's row, since it moves the playhead: to the start, previous and next clip, play and pause (on the clock; at the end it stops and goes back to the start), the time. It goes where the Cut panel goes; the keys work either way. - **The strip**: a ruler (click or drag to move the playhead; the knob scrubs), a lane of chapters (each from its marker to the next), the clips, each as wide as it lasts. Zoom with the slider or Ctrl + wheel; **Fit** shows the whole cut. A shot with a progression is **Spread** (a cell per picture; a click on a cell goes to that picture) or **Collapsed** (its first picture); its length is the progression's in both, and it has no edge to pull. Others: pull the right edge to change the time, drag to reorder. - **Choosing**: a click chooses a clip and puts the playhead at its start; Shift adds a range, Ctrl one more. With several chosen, the Clip panel sets one hold time for all, ± 0.5 s, moves them together (Alt + arrows) or removes them. -- **Files**: the project's shots, photos, canvases and collections, with a search and a type filter; a collection opens to its photos (never a clip itself), a canvas with frames opens to its frames. Drag a row into the strip (a line shows where it lands; over a **placeholder** it fills it, keeping its time and chapter), double-click it, or press its plus to add it after the chosen clips. A new clip holds the timeline's value, else the account's ("New clips … s": "This timeline has its own value"; the account's value is the `clipHoldMs` preference, 2 s to start with). +- **Files**: the project's shots, photos, canvases and collections, with a search and a type filter, as a **List** or as **Cards** (bigger pictures; remembered per browser). The panel's ⋯ menu sets how many cards go across: as many as fit (the default), one (each picture as wide as the panel) or two; also remembered per browser. In the list a collection opens to its photos and a canvas with frames to its frames; as cards a collection is one card to scrub through (as in Files), and a canvas's frames are looked through in Source. **A click looks at a file in Source** (when the pane shows; nothing else happens otherwise); **a double-click opens it in its own app** (a canvas in Canvas, a photo in Photo, a shot in Shot, a collection as its folder). Drag a row or a card into the strip (a line shows where it lands; over a **placeholder** it fills it, keeping its time and chapter), or press its plus to add it after the chosen clips. **A collection is never a clip itself: dragged in (or its plus), it puts its photos in, one clip each, in the collection's order**; it does not fill a placeholder. A new clip holds the timeline's value, else the account's ("New clips … s": "This timeline has its own value"; the account's value is the `clipHoldMs` preference, 2 s to start with). - **In use**: the files this cut uses, with how often, and the placeholders; a click goes to the next clip that uses it. - **Chapters**: each with its start and length; a click goes there. "Chapter" (C) starts one at the chosen clip, or ends it; its title and colour are set in the Clip panel. - **The Clip panel**: the picture, the file's name (a placeholder's title is typed here), the hold time with ± 0.5 s (D focuses it), where it starts; a shot whose thumbnail is a progression says it plays it. **Open in …** (or a double-click on the clip) opens the file's app in a window of its own; **Make a canvas from it** (a photo) makes a canvas on the photo next to it and points the clip at it; **Fill it** (a placeholder); **Remove**. Then where else the file is used, and its properties. @@ -42,11 +44,12 @@ One window per timeline (Files: New, Timeline; a double-click on one). The U4 la - **Undo and redo** (Ctrl+Z, Ctrl+Shift+Z or Ctrl+Y; the buttons in the Cut's row): up to 100 steps, changes close together are one. - **Keys**: Space, ← →, Home, End, Alt+← →, - and +, D, P (a placeholder after the chosen clip), C, Delete, Ctrl+A ([shortcuts](../shortcuts.md)). - **The edit lock**: the window takes it when it opens; others see the timeline read-only with who edits it, and Edit when it is free; **Stop editing** saves and lets it go. A watching window follows every change at once in a project set to realtime (the file's live room), else reads the timeline again every 5 s. Changes save 0.6 s after the last one (status bar: Saved, Changed, Saving…, Not saved). +- **The name** sits in the toolbar and is typed in place while you hold the lock (Enter or leaving the field saves, Escape undoes); watching, it is plain text. The start screen renames too (right-click or F2). - **The address** keeps the playhead: `#/timeline/?t=12.5`. ## Editing a canvas or a shot from the cut -A double-click on a canvas or shot clip, or **Edit here** in the Clip panel, mounts the file's own window in place of the stage: the canvas editor, or the Shot window (progression and content as tabs below, its own arrangement). A bar names the file, says where else it is used, offers **Edit a copy instead** when it is used elsewhere (the clip then points at a copy, which is edited here; the original stays), **Open in …** (its app in a window of its own) and **Done**. Playback stops and the playhead stays on the clip; choosing another clip, moving the playhead or playing ends the edit. The file panels fold away meanwhile and come back after. The mounted editor owns the keys. **The lock is the file's**: editing in place takes the same lock as its own window, so a file someone edits elsewhere is read-only here too (with who has it), and the other way round. A photo clip is not edited: Make a canvas from it. +A double-click on a canvas or shot clip, or **Edit here** in the Clip panel, mounts the file's own window in place of the stage: the canvas editor, or the Shot window (progression and content as tabs below, its own arrangement). A bar names the file, says where else it is used, offers **Edit a copy instead** when it is used elsewhere (the clip then points at a copy, which is edited here; the original stays), **Open in …** (its app in a window of its own) and **Done**. Playback stops, the playhead stays on the clip and **the cut is locked** until Done (or Back to the cut): the strip and the Clip panel take no clicks, scrubbing, choosing another clip and playing do nothing, and the strip says so with its own Done. The file panels fold away meanwhile and come back after. The mounted editor owns the keys. **The lock is the file's**: editing in place takes the same lock as its own window, so a file someone edits elsewhere is read-only here too (with who has it), and the other way round. A photo clip is not edited: Make a canvas from it. ## The master timeline (`apps/studio/src/apps/MasterApp.tsx`, in the Timeline app, route `#/timeline/master`) diff --git a/docs/shortcuts.md b/docs/shortcuts.md index c6cc02d7..941d4f57 100644 --- a/docs/shortcuts.md +++ b/docs/shortcuts.md @@ -84,6 +84,13 @@ The same list is in the app: `?`, and Settings › Shortcuts. Single keys never | ← | Previous photo | | → | Next photo | +## Start screens (an app opened without a file) + +| Keys | What | +| --- | --- | +| F2 | Rename the focused file | +| Right-click | On a file: open, rename | + ## Timeline | Keys | What |