Skip to content
Merged
16 changes: 13 additions & 3 deletions apps/studio/src/apps/StartScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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); }
Expand All @@ -53,7 +62,8 @@ export function StartScreen({ winId, projectId, type, setTitle, setRoute, extra,
{list.map((f) => {
const thumb = thumbOf(f, files);
return <FileCard key={f.id} name={f.name} meta={new Date(f.updated_at ?? f.created_at).toLocaleDateString()} art={thumb ? <img src={thumb} alt="" loading="lazy" draggable={false} /> : <AppIcon glyph={kind.glyph} color={kind.color} size={48} />} 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); } }} />;
})}
</FileGrid>
)}
Expand Down
143 changes: 89 additions & 54 deletions apps/studio/src/apps/TimelineApp.tsx

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion apps/studio/src/shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +28,7 @@ export const SCOPES: Record<ScopeId, Scope> = {
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: [] },
Expand Down Expand Up @@ -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" },
Expand Down
103 changes: 103 additions & 0 deletions apps/studio/src/timeline/FilesPanel.tsx
Original file line number Diff line number Diff line change
@@ -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<string, FileRec>; 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<string[]>([]);
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) => <Button size="sm" variant="quiet" icon="plus" label={`Add ${label} to the cut`} disabled={!canAdd} onPointerDown={(e) => e.stopPropagation()} onClick={(e) => { e.stopPropagation(); add(r); }} />;
const hint = "Click to look at it in Source, double-click to open it; drag it into the cut (onto a placeholder fills it), or press its plus to add it after the chosen clip";
const collHint = "Click to look through it in Source, double-click to open it; drag it into the cut or press its plus: its photos go in one clip each, in its order";
const photoRefs = (kids: FileRec[]) => kids.map((c) => ({ file: c.id }));
const many = (n: number, name: string) => `${n} photo${n === 1 ? "" : "s"} of ${name}`;
if (!offered.length) return <p className="sh-note">Nothing matches.</p>;

if (view === "cards") return (
<FileGrid className={cx("tl-cards", cols !== "auto" && `tl-cards--${cols}`)}>
{top.map((x) => {
const r = { file: x.id }, thumb = thumbOf(x, files), frames = framesOf(x);
// A collection goes in as all its photos; a single one is chosen in Source (or in the list).
const coll = x.type === "collection";
const kids = coll ? photosOf(x, files) : [];
const what: ClipRef | ClipRef[] = coll ? photoRefs(kids) : r, label = coll ? many(kids.length, x.name) : x.name;
return (
<FileCard key={x.id} name={x.name} picture={!!thumb} selected={shown?.file === x.id}
art={thumb ? <img src={thumb} alt="" draggable={false} loading="lazy" /> : <AppIcon glyph={kindOf(x.type).glyph} color={kindOf(x.type).color} size={40} />}
meta={x.type === "collection" ? `${kids.length} photos` : frames.length ? `Canvas · ${frames.length} frame${frames.length === 1 ? "" : "s"}` : kindOf(x.type).label}
badge={coll && !kids.length ? undefined : <span className="tl-cardadd" data-nodrag>{plus(what, label)}</span>}
stack={x.type === "collection" ? { srcs: kids.filter((p) => p.photo?.stored.thumbnail).slice(0, 40).map((p) => imageUrl(p.id, "thumbnail")), count: kids.length } : undefined}
tint={x.type === "collection" ? tintOf(x) : undefined} mark={mark}
title={coll ? collHint : hint}
onPointerDown={drag(what, label)} onClick={() => look(r)} onDblClick={() => openOwn(x.id)} />
);
})}
</FileGrid>
);

const row = (x: FileRec, r: ClipRef, label: string, depth = 0, extra?: ComponentChildren) => (
<li key={`${r.file}${r.frame ?? ""}`} className={cx("tl-file", isShown(r) && "is-on")} style={{ paddingLeft: 6 + depth * 18 }} onPointerDown={drag(r, label)} onClick={() => look(r)} onDblClick={() => openOwn(r.file)} title={hint}>
<span className="sh-pickrow__art sh-box">{(() => { const s = thumbSeen(r.file, r.frame); return s ? <Pic seen={s} /> : null; })()}</span>
<span className="sh-pickrow__name">{label}<small>{r.frame ? "One frame of the canvas" : kindOf(x.type).label}</small></span>
{extra && <span data-nodrag onPointerDown={(e) => e.stopPropagation()} onClick={(e) => e.stopPropagation()}>{extra}</span>}
{plus(r, label)}
</li>
);
const twist = (fid: string, count: number, what: string) => { const on = open.includes(fid); return <Button size="sm" variant="quiet" iconAfter={on ? "chevron-up" : "chevron-down"} onClick={() => setOpen(on ? open.filter((y) => y !== fid) : [...open, fid])}>{count} {count === 1 ? what.replace(/s$/, "") : what}</Button>; };
return (
<ul className="tl-files">
{top.flatMap((x) => {
const on = open.includes(x.id);
if (x.type === "collection") {
const kids = photosOf(x, files);
return [
<li key={x.id} className={cx("tl-file tl-file--coll", shown?.file === x.id && "is-on")} onPointerDown={drag(photoRefs(kids), many(kids.length, x.name))} onClick={() => look({ file: x.id })} onDblClick={() => openOwn(x.id)} title={collHint}>
<AppIcon glyph="layers" color={4} size={24} /><span className="sh-pickrow__name">{x.name}<small>Collection: drag it in for all its photos</small></span>
<span data-nodrag onPointerDown={(e) => e.stopPropagation()} onClick={(e) => e.stopPropagation()}>{twist(x.id, kids.length, "photos")}</span>
{kids.length > 0 && plus(photoRefs(kids), many(kids.length, x.name))}
</li>,
...(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)) : [])];
})}
</ul>
);
}

76 changes: 76 additions & 0 deletions apps/studio/src/timeline/SourcePane.tsx
Original file line number Diff line number Diff line change
@@ -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<string, FileRec>, 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<string, FileRec>; 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 = (
<div className="tl-panehead">
<b>Source</b>
{x && <><AppIcon glyph={kindOf(x.type).glyph} color={kindOf(x.type).color} size={16} /><span className="tl-panehead__name">{m?.label ?? x.name}</span></>}
{members.length > 1 && <span className="oc-num tl-panehead__count">{i + 1} / {members.length}</span>}
<span style={{ flex: 1 }} />
{m?.add && <Button size="sm" variant="quiet" icon="plus" disabled={!canAdd} title="After the chosen clip; or drag the picture into the cut" onClick={() => onAdd(m.add!)}>Add to the cut</Button>}
</div>
);
if (!x) return <div className="tl-source">{head}<div className="sh-stage is-empty"><EmptyState icon="image" title="Nothing to look at yet">Click a file in the Files panel to look at it here.</EmptyState></div></div>;
return (
<div className="tl-source" tabIndex={0} onKeyDown={(e) => { if (e.key === "ArrowLeft" || e.key === "ArrowRight") { e.preventDefault(); step(e.key === "ArrowLeft" ? -1 : 1); } }}>
{head}
<div className={cx("sh-stage", !m?.seen && "is-empty")} onPointerDown={m?.add && canAdd ? drag(m.add, m.label) : undefined}>
{!m ? <EmptyState icon={kindOf(x.type).glyph} title={x.deleted_at ? "In the recycle bin" : "Nothing in it yet"} />
: m.seen ? <div className="sh-box"><Pic seen={m.seen} mode={mode} overlay={m.overlay} label /></div>
: <EmptyState icon="slate" title="No picture yet" />}
</div>
{members.length > 1 && (
<div className="tl-source__strip" role="listbox" aria-label={`What ${x.name} holds`}>
{members.map((y, k) => (
<button type="button" key={y.key} role="option" aria-selected={k === i} className={cx("tl-source__cell", k === i && "is-on")} title={y.label} onClick={() => setAt(k)}>
<span className="sh-box">{y.seen ? <Pic seen={y.seen} overlay={y.overlay} /> : null}</span>
</button>
))}
</div>
)}
</div>
);
}
Loading
Loading