-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathShotCard.tsx
More file actions
436 lines (408 loc) · 14 KB
/
Copy pathShotCard.tsx
File metadata and controls
436 lines (408 loc) · 14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
/** @jsxImportSource @emotion/react */
/**
* ShotCard
*
* One shot in the storyboard, laid out as a full-width row: the keyframe
* still or rendered clip on the left, and the shot's text, camera line,
* cast, takes browser, and actions in the wide column beside it. There is
* no approval step: the selected still (see {@link ShotTakesGallery}) is
* what the clip render uses, so a shot is ready for video as soon as it
* has a still.
*/
import React, { memo, useCallback, useMemo, useState } from "react";
import { css } from "@emotion/react";
import { useMediaQuery } from "@mui/material";
import { useTheme } from "@mui/material/styles";
import type { Theme } from "@mui/material/styles";
import type { Shot, ShotStatus } from "@nodetool-ai/protocol";
import ArrowUpwardIcon from "@mui/icons-material/ArrowUpward";
import ArrowDownwardIcon from "@mui/icons-material/ArrowDownward";
import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
import {
Card,
FlexRow,
FlexColumn,
EditorButton,
StatusIndicator,
Chip,
Text,
Caption,
VideoPlayer,
Dialog,
TextInput,
ToolbarIconButton,
HoverActionGroup,
SPACING,
getSpacingPx,
BORDER_RADIUS,
MOTION,
type StatusType
} from "../ui_primitives";
import ImageRefPreview from "../node/ImageRefPreview";
import ShotTakesGallery from "./ShotTakesGallery";
import { useStoryboardStore } from "../../stores/storyboard/StoryboardStore";
import { entitiesForShot } from "../../stores/storyboard/shotEntities";
import { useGenerateShot } from "../../hooks/storyboard/useGenerateShot";
import { useEntities } from "../../serverState/useEntities";
import { ENTITY_KIND_COLOR } from "../entities/entityKind";
interface ShotCardProps {
boardId: string;
shot: Shot;
readOnly?: boolean;
/** True when this is the first shot on the board (disables "move up"). */
isFirst?: boolean;
/** True when this is the last shot on the board (disables "move down"). */
isLast?: boolean;
}
const STATUS_META: Record<ShotStatus, { status: StatusType; label: string; pulse?: boolean }> = {
planned: { status: "default", label: "Planned" },
keyframe_generating: { status: "pending", label: "Generating still…", pulse: true },
keyframe_ready: { status: "info", label: "Still ready" },
// Legacy status from the removed approval step; same meaning as a ready still.
approved: { status: "info", label: "Still ready" },
clip_generating: { status: "pending", label: "Rendering…", pulse: true },
rendered: { status: "success", label: "Rendered" },
failed: { status: "error", label: "Failed" }
};
const styles = (theme: Theme) =>
css({
display: "grid",
gridTemplateColumns: "minmax(220px, 300px) minmax(0, 1fr)",
gap: getSpacingPx(SPACING.md),
alignItems: "start",
"@media (max-width: 720px)": {
gridTemplateColumns: "minmax(0, 1fr)"
},
".preview": {
position: "relative",
width: "100%",
aspectRatio: "16 / 9",
borderRadius: BORDER_RADIUS.sm,
overflow: "hidden",
backgroundColor: theme.vars.palette.c_overlay_subtle,
display: "flex",
alignItems: "center",
justifyContent: "center",
"& img": {
width: "100%",
height: "100%",
objectFit: "cover"
}
},
".placeholder": {
color: theme.vars.palette.text.disabled,
textAlign: "center",
padding: getSpacingPx(SPACING.md)
},
".details": {
minWidth: 0,
display: "flex",
flexDirection: "column",
gap: getSpacingPx(SPACING.sm)
},
".camera": {
color: theme.vars.palette.text.secondary
},
// ── Generating: shimmer sweep + spark over the preview, glow on the card ──
"@keyframes shot-shimmer": {
from: { backgroundPosition: "200% 0" },
to: { backgroundPosition: "-200% 0" }
},
"@keyframes shot-spark": {
"0%, 100%": { opacity: 0.4, transform: "scale(0.9) rotate(0deg)" },
"50%": { opacity: 1, transform: "scale(1.2) rotate(90deg)" }
},
"@keyframes shot-breathe": {
"0%, 100%": { boxShadow: `0 0 0 1px ${theme.vars.palette.primary.main}33` },
"50%": { boxShadow: `0 0 14px 1px ${theme.vars.palette.primary.main}55` }
},
"&.generating": {
animation: `shot-breathe ${MOTION.pulse} infinite`
},
".conjure": {
position: "absolute",
inset: 0,
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
gap: getSpacingPx(SPACING.sm),
backgroundImage: `linear-gradient(100deg, transparent 40%, ${theme.vars.palette.action.selected} 50%, transparent 60%)`,
backgroundSize: "200% 100%",
animation: `shot-shimmer ${MOTION.spin} infinite`,
".spark": {
fontSize: "1.5em",
color: theme.vars.palette.primary.main,
animation: `shot-spark ${MOTION.pulse} infinite`
},
".conjure-label": {
color: theme.vars.palette.text.secondary
}
},
"@media (prefers-reduced-motion: reduce)": {
"&.generating, .conjure, .conjure .spark": { animation: "none" }
}
});
const cameraLine = (shot: Shot): string =>
[
shot.camera?.framing,
shot.camera?.lens,
shot.camera?.angle,
shot.camera?.movement
]
.filter((p): p is string => !!p && p.trim().length > 0)
.join(" · ");
const EMPTY_IDS: string[] = [];
const ShotCardInner: React.FC<ShotCardProps> = ({
boardId,
shot,
readOnly,
isFirst,
isLast
}) => {
const theme = useTheme();
// Touch devices can't hover, so the row actions (reorder, delete) must stay
// visible instead of hiding behind a hover reveal.
const coarsePointer = useMediaQuery("(pointer: coarse)");
const toggleShotEntity = useStoryboardStore((state) => state.toggleShotEntity);
const moveShot = useStoryboardStore((state) => state.moveShot);
const removeShot = useStoryboardStore((state) => state.removeShot);
const boardEntityIds = useStoryboardStore(
(state) => state.boards[boardId]?.entityIds ?? EMPTY_IDS
);
const { data: allEntities } = useEntities();
const { generateKeyframe, generateClip, generateRevisedClip } =
useGenerateShot();
const { boardEntities, appliedEntities, appliedIds } = useMemo(() => {
const idSet = new Set(boardEntityIds);
const board = (allEntities ?? []).filter((e) => idSet.has(e.id));
const applied = entitiesForShot(shot, board);
return {
boardEntities: board,
appliedEntities: applied,
appliedIds: applied.map((e) => e.id)
};
}, [allEntities, boardEntityIds, shot]);
const [reviseOpen, setReviseOpen] = useState(false);
const [reviseText, setReviseText] = useState("");
const [confirmDelete, setConfirmDelete] = useState(false);
const meta = STATUS_META[shot.status];
const isGenerating =
shot.status === "keyframe_generating" || shot.status === "clip_generating";
const camera = cameraLine(shot);
const clipUri = shot.clip?.uri;
const shotName = `${shot.index + 1}. ${shot.slug ?? "Untitled shot"}`;
const handleGenerateStill = useCallback(() => {
void generateKeyframe(boardId, shot);
}, [generateKeyframe, boardId, shot]);
const handleGenerateClip = useCallback(() => {
void generateClip(boardId, shot);
}, [generateClip, boardId, shot]);
const handleReviseConfirm = useCallback(() => {
const instruction = reviseText.trim();
if (instruction.length > 0) {
void generateRevisedClip(boardId, shot, instruction);
}
setReviseOpen(false);
setReviseText("");
}, [reviseText, generateRevisedClip, boardId, shot]);
const handleMoveUp = useCallback(() => {
moveShot(boardId, shot.id, "up");
}, [moveShot, boardId, shot.id]);
const handleMoveDown = useCallback(() => {
moveShot(boardId, shot.id, "down");
}, [moveShot, boardId, shot.id]);
const handleDelete = useCallback(() => {
removeShot(boardId, shot.id);
setConfirmDelete(false);
}, [removeShot, boardId, shot.id]);
return (
<Card
variant="outlined"
padding="compact"
css={styles(theme)}
className={`shot-card${isGenerating ? " generating" : ""}`}
>
<div className="preview">
{clipUri ? (
<VideoPlayer src={clipUri} />
) : (
<ImageRefPreview
value={shot.keyframe}
placeholder={
<Caption className="placeholder">No still yet</Caption>
}
/>
)}
{isGenerating && (
<div className="conjure">
<span className="spark">✦</span>
<Caption className="conjure-label">
{shot.status === "clip_generating"
? "Rendering clip…"
: "Conjuring still…"}
</Caption>
</div>
)}
</div>
<FlexColumn className="details">
<FlexRow align="center" justify="space-between" gap={1} wrap>
<Text size="small" weight={600} truncate>
{shotName}
</Text>
<FlexRow align="center" gap={1}>
{typeof shot.cost_estimate === "number" && (
<Chip
compact
color="info"
label={`~$${shot.cost_estimate.toFixed(2)}`}
/>
)}
<StatusIndicator
status={meta.status}
label={meta.label}
pulse={meta.pulse}
/>
{!readOnly && (
<HoverActionGroup
triggerSelector=".shot-card:hover"
gap={0}
alwaysVisible={coarsePointer}
>
<ToolbarIconButton
icon={<ArrowUpwardIcon sx={{ fontSize: 16 }} />}
tooltip="Move up"
ariaLabel="Move shot up"
onClick={handleMoveUp}
disabled={isFirst}
/>
<ToolbarIconButton
icon={<ArrowDownwardIcon sx={{ fontSize: 16 }} />}
tooltip="Move down"
ariaLabel="Move shot down"
onClick={handleMoveDown}
disabled={isLast}
/>
<ToolbarIconButton
icon={<DeleteOutlineIcon sx={{ fontSize: 16 }} />}
tooltip="Delete shot"
ariaLabel="Delete shot"
variant="error"
onClick={() => setConfirmDelete(true)}
disabled={isGenerating}
/>
</HoverActionGroup>
)}
</FlexRow>
</FlexRow>
<Text size="small" lineClamp={3}>
{shot.action}
</Text>
{camera.length > 0 && (
<Caption className="camera" noWrap>
{camera}
</Caption>
)}
{boardEntities.length > 0 && (
<FlexRow gap={0.5} wrap>
{boardEntities.map((entity) => {
const applied = appliedIds.includes(entity.id);
return (
<Chip
key={entity.id}
compact
label={entity.name || "Untitled"}
color={applied ? ENTITY_KIND_COLOR[entity.kind] : "default"}
variant={applied ? "filled" : "outlined"}
sx={{
borderRadius: BORDER_RADIUS.sm,
...(applied ? undefined : { opacity: 0.55 })
}}
title={
applied
? `${entity.descriptor || entity.name} — click to exclude from this shot`
: `Click to include ${entity.name} in this shot`
}
onClick={
readOnly
? undefined
: () =>
toggleShotEntity(boardId, shot.id, entity.id, appliedIds)
}
/>
);
})}
</FlexRow>
)}
<ShotTakesGallery boardId={boardId} shot={shot} readOnly={readOnly} />
{!readOnly && (
<FlexRow gap={0.5} wrap>
<EditorButton
onClick={handleGenerateStill}
disabled={isGenerating}
>
{shot.keyframe ? "New still" : "Generate still"}
</EditorButton>
<EditorButton
onClick={handleGenerateClip}
disabled={isGenerating || !shot.keyframe}
title={
shot.keyframe
? "Animate the selected still into a clip"
: "Generate a still first"
}
>
{shot.clip ? "New clip" : "Generate clip"}
</EditorButton>
{shot.clip && (
<EditorButton
onClick={() => setReviseOpen(true)}
disabled={isGenerating}
>
Revise clip
</EditorButton>
)}
</FlexRow>
)}
</FlexColumn>
<Dialog
open={reviseOpen}
onClose={() => setReviseOpen(false)}
title="Revise clip"
onConfirm={handleReviseConfirm}
confirmText="Revise"
confirmDisabled={reviseText.trim().length === 0}
>
<FlexColumn gap={1}>
<Caption color="secondary">
Describe the change to make. The current clip is re-rendered with
your note applied.
</Caption>
<TextInput
value={reviseText}
placeholder="e.g. make it darker, add rain"
onChange={(e) => setReviseText(e.target.value)}
multiline
rows={3}
autoFocus
/>
</FlexColumn>
</Dialog>
<Dialog
open={confirmDelete}
onClose={() => setConfirmDelete(false)}
title="Delete shot?"
onConfirm={handleDelete}
confirmText="Delete"
destructive
>
<Text size="small">
{`Remove “${shotName}” from the board. Generated stills and clips stay in your asset library.`}
</Text>
</Dialog>
</Card>
);
};
export const ShotCard = memo(ShotCardInner);
ShotCard.displayName = "ShotCard";
export default ShotCard;