feat: modal-based video source picker with project clip grid
The native select was too cramped for a project with many clips. Replace it with a wide modal (Auto / Upload file / clip grid with thumbnails). Clip options now cover any scene in the timeline, not just earlier ones, and uploads wire through a hidden input. Also fix the Choose-Video modal rendering blank under Clips/Uploads tabs: duplicate asset paths crashed Svelte's keyed each mid-render — dedupe by path and clamp the active tab when a tile's kind changes.
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
type Workflow,
|
||||
} from '$lib/api';
|
||||
import { compactInputValues } from '$lib/comfy/promptInput';
|
||||
import { createUploadManager } from '$lib/comfy/useUpload.svelte';
|
||||
import { normalizeInputRole } from '$lib/comfy/parser';
|
||||
import type { ComfyDynamicInput } from '$lib/comfy/types';
|
||||
import type { AssetOption } from '$lib/assetPicker';
|
||||
@@ -40,6 +41,21 @@
|
||||
let lastFormScene = $state<number | null>(null);
|
||||
// Clip source for continue scenes, keyed per scene: 'auto' | 'upload' | scene id.
|
||||
let clipSource = $state<Record<number, string>>({});
|
||||
// Hidden file input backing "Upload file" in the video source modal.
|
||||
let videoFileInput = $state<HTMLInputElement | null>(null);
|
||||
const videoUploadMgr = createUploadManager();
|
||||
|
||||
async function onVideoFileChosen(e: Event) {
|
||||
const el = e.currentTarget as HTMLInputElement;
|
||||
const file = el.files?.[0];
|
||||
el.value = '';
|
||||
const node = videoInputNodeFor(selected ? workflowFor(selected) : undefined);
|
||||
if (!file || !selected || !node) return;
|
||||
const path = await videoUploadMgr.uploadSafe(node.nodeId, file);
|
||||
if (path) {
|
||||
formValues = { ...formValues, [node.nodeId]: path };
|
||||
}
|
||||
}
|
||||
|
||||
// Per-scene input cache — switching scenes no longer wipes the form.
|
||||
const formCache = new Map<number, Record<string, string | number>>();
|
||||
@@ -183,12 +199,12 @@
|
||||
return wf?.input_schema?.find((inp) => normalizeInputRole(inp.role ?? null) === 'video');
|
||||
}
|
||||
|
||||
// Timeline source options for a continue scene: earlier scenes that already
|
||||
// Timeline source options for a continue scene: any other scene that has
|
||||
// rendered a clip, ordered by timeline position.
|
||||
function timelineClipOptions(current: Scene | null): Scene[] {
|
||||
if (!current) return [];
|
||||
return scenes
|
||||
.filter((s) => s.id !== current.id && s.order_index < current.order_index && s.video_path)
|
||||
.filter((s) => s.id !== current.id && s.video_path)
|
||||
.sort((a, b) => a.order_index - b.order_index);
|
||||
}
|
||||
|
||||
@@ -546,6 +562,13 @@
|
||||
{@const selSource = clipSource[selected.id] ?? 'auto'}
|
||||
{@const selSourceValid = selSource === 'auto' || selSource === 'upload' || selClips.some((s) => String(s.id) === selSource)}
|
||||
{@const selBlocked = selChain && !selHasVideoInput}
|
||||
<input
|
||||
bind:this={videoFileInput}
|
||||
type="file"
|
||||
class="sr-only-video-file"
|
||||
accept="video/*,.mp4,.webm,.mov,.mkv"
|
||||
onchange={onVideoFileChosen}
|
||||
/>
|
||||
<VideoEditWorkspace
|
||||
{scenes}
|
||||
{selected}
|
||||
@@ -572,7 +595,11 @@
|
||||
clipSource={{
|
||||
enabled: selChain && selHasVideoInput && Boolean(selVideoNode),
|
||||
value: selSourceValid ? selSource : 'auto',
|
||||
options: selClips.map((s) => ({ id: String(s.id), label: `#${s.order_index} ${s.heading || 'Scene'}` })),
|
||||
options: selClips.map((s) => ({
|
||||
id: String(s.id),
|
||||
label: `#${s.order_index} ${s.heading || 'Scene'}`,
|
||||
path: s.video_path ?? undefined,
|
||||
})),
|
||||
}}
|
||||
onClipSourceChange={(val) => {
|
||||
if (val === 'auto') {
|
||||
@@ -591,6 +618,7 @@
|
||||
}
|
||||
}
|
||||
}}
|
||||
onClipSourceUpload={() => videoFileInput?.click()}
|
||||
onSelect={selectScene}
|
||||
onStep={step}
|
||||
onWorkflowChange={(id) => {
|
||||
@@ -739,6 +767,18 @@
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.sr-only-video-file {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0 0 0 0);
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.queue-root {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -65,6 +65,16 @@
|
||||
wasOpen = now;
|
||||
});
|
||||
|
||||
// The modal instance can be reused across tiles whose kind differs (e.g. a
|
||||
// workflow swap turns an image node into video). If the stored tab is not in
|
||||
// the visible list, the body would render one tab while the header shows
|
||||
// another — clamp it instead.
|
||||
$effect(() => {
|
||||
if (tabs.length > 0 && !tabs.some((t) => t.id === tab)) {
|
||||
tab = tabs[0].id;
|
||||
}
|
||||
});
|
||||
|
||||
const q = $derived(query.trim().toLowerCase());
|
||||
|
||||
const visible = $derived.by(() => {
|
||||
|
||||
@@ -73,11 +73,19 @@
|
||||
|
||||
const isImageKind = $derived(input.kind === 'image' || input.kind === 'image_url');
|
||||
const isVideoKind = $derived(input.kind === 'video');
|
||||
const matchingAssets = $derived(
|
||||
assetOptions.filter(
|
||||
(o) => !o.kind || o.kind === input.kind || (isImageKind && o.kind === 'image'),
|
||||
),
|
||||
);
|
||||
const matchingAssets = $derived.by(() => {
|
||||
// The same path can arrive twice (e.g. a scene clip that was also
|
||||
// uploaded to the playground). Duplicate keys crash the keyed each
|
||||
// in the picker grid, so dedupe by path first.
|
||||
const seen = new Set<string>();
|
||||
return assetOptions.filter((o) => {
|
||||
const match =
|
||||
!o.kind || o.kind === input.kind || (isImageKind && o.kind === 'image');
|
||||
if (!match || seen.has(o.path)) return false;
|
||||
seen.add(o.path);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
|
||||
const displayLabel = $derived(
|
||||
input.role === 'character'
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
interface Props {
|
||||
open?: boolean;
|
||||
title?: string;
|
||||
size?: 'md' | 'lg';
|
||||
size?: 'md' | 'lg' | 'xl';
|
||||
dismissible?: boolean;
|
||||
onclose?: () => void;
|
||||
footer?: Snippet;
|
||||
@@ -163,6 +163,9 @@
|
||||
.modal-panel.size-lg {
|
||||
width: min(920px, 100%);
|
||||
}
|
||||
.modal-panel.size-xl {
|
||||
width: min(1180px, 100%);
|
||||
}
|
||||
.modal-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -0,0 +1,302 @@
|
||||
<script lang="ts">
|
||||
/**
|
||||
* Video source picker for continue scenes — Auto (previous clip),
|
||||
* Upload file, or any other scene's clip in the project timeline.
|
||||
* Replaces the cramped native select.
|
||||
*/
|
||||
import { assetUrl } from '$lib/api';
|
||||
import Button from '$lib/components/ui/Button.svelte';
|
||||
import Icon from '$lib/components/ui/Icon.svelte';
|
||||
import Modal from '$lib/components/ui/Modal.svelte';
|
||||
|
||||
interface ClipSourceOption {
|
||||
/** Scene id as string, or the 'auto' / 'upload' sentinels. */
|
||||
id: string;
|
||||
label: string;
|
||||
/** Clip path — renders a video thumbnail when present. */
|
||||
path?: string;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
open?: boolean;
|
||||
/** Current source: 'auto' | 'upload' | a scene id from options. */
|
||||
value?: string;
|
||||
options?: ClipSourceOption[];
|
||||
/** Picking Auto or a project clip. */
|
||||
onselect: (source: string) => void;
|
||||
/** Picking Upload file — caller opens the file dialog and applies the result. */
|
||||
onupload: () => void;
|
||||
}
|
||||
|
||||
let { open = $bindable(false), value = 'auto', options = [], onselect, onupload }: Props =
|
||||
$props();
|
||||
|
||||
function hideBroken(e: Event) {
|
||||
const el = e.currentTarget as HTMLElement | null;
|
||||
if (el) el.style.display = 'none';
|
||||
}
|
||||
|
||||
function pick(source: string) {
|
||||
onselect(source);
|
||||
open = false;
|
||||
}
|
||||
|
||||
function pickUpload() {
|
||||
onupload();
|
||||
open = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal bind:open title="Video source" size="xl">
|
||||
<div class="sources">
|
||||
<button
|
||||
type="button"
|
||||
class="source-card"
|
||||
class:selected={value === 'auto'}
|
||||
onclick={() => pick('auto')}
|
||||
>
|
||||
<span class="source-icon"><Icon name="sparkle" size={18} /></span>
|
||||
<span class="source-text">
|
||||
<span class="source-name">Auto (previous clip)</span>
|
||||
<span class="source-desc">Continue from the previous scene's clip</span>
|
||||
</span>
|
||||
{#if value === 'auto'}
|
||||
<span class="check"><Icon name="check" size={12} /></span>
|
||||
{/if}
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="source-card"
|
||||
class:selected={value === 'upload'}
|
||||
onclick={pickUpload}
|
||||
>
|
||||
<span class="source-icon"><Icon name="upload" size={18} /></span>
|
||||
<span class="source-text">
|
||||
<span class="source-name">Upload file</span>
|
||||
<span class="source-desc">Pick a video from your computer</span>
|
||||
</span>
|
||||
{#if value === 'upload'}
|
||||
<span class="check"><Icon name="check" size={12} /></span>
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{#if options.length > 0}
|
||||
<p class="section-label">Project clips <span class="count">{options.length}</span></p>
|
||||
<div class="grid-wrap">
|
||||
<div class="grid">
|
||||
{#each options as opt (opt.id)}
|
||||
{@const isSelected = value === opt.id}
|
||||
<button
|
||||
type="button"
|
||||
class="clip-card"
|
||||
class:selected={isSelected}
|
||||
onclick={() => pick(opt.id)}
|
||||
title={opt.label}
|
||||
>
|
||||
<div class="thumb">
|
||||
{#if opt.path}
|
||||
<!-- svelte-ignore a11y_media_has_caption -->
|
||||
<video
|
||||
src={assetUrl(opt.path)}
|
||||
muted
|
||||
playsinline
|
||||
preload="metadata"
|
||||
onerror={hideBroken}
|
||||
></video>
|
||||
{:else}
|
||||
<Icon name="film" size={22} />
|
||||
{/if}
|
||||
{#if isSelected}
|
||||
<span class="check"><Icon name="check" size={12} /></span>
|
||||
{/if}
|
||||
</div>
|
||||
<span class="name">{opt.label}</span>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<p class="empty">No clips in the project yet. Generate a clip first, or upload a video file.</p>
|
||||
{/if}
|
||||
|
||||
{#snippet footer()}
|
||||
<Button variant="ghost" onclick={() => (open = false)}>Cancel</Button>
|
||||
{/snippet}
|
||||
</Modal>
|
||||
|
||||
<style>
|
||||
.sources {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.source-card {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 14px 16px;
|
||||
text-align: left;
|
||||
font: inherit;
|
||||
font-size: 14px;
|
||||
color: var(--text-secondary);
|
||||
background: var(--bg-elevated);
|
||||
border: 1.5px solid var(--border);
|
||||
border-radius: var(--radius-md);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.source-card:hover {
|
||||
border-color: var(--text-muted);
|
||||
}
|
||||
|
||||
.source-card:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.source-card.selected {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 3px var(--accent-glow);
|
||||
}
|
||||
|
||||
.source-icon {
|
||||
flex-shrink: 0;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.source-card.selected .source-icon {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.source-text {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.source-name {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.source-desc {
|
||||
font-size: 12.5px;
|
||||
line-height: 1.4;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.section-label {
|
||||
margin: 16px 0 8px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.count {
|
||||
margin-left: 4px;
|
||||
font-weight: 500;
|
||||
color: var(--text-muted);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.grid-wrap {
|
||||
overflow-y: auto;
|
||||
overscroll-behavior: contain;
|
||||
max-height: min(52vh, 560px);
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.clip-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
padding: 0;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.thumb {
|
||||
position: relative;
|
||||
aspect-ratio: 16 / 9;
|
||||
border-radius: var(--radius-md);
|
||||
border: 1.5px solid var(--border);
|
||||
background: var(--bg-elevated);
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.clip-card:hover .thumb {
|
||||
border-color: var(--text-muted);
|
||||
}
|
||||
|
||||
.clip-card.selected .thumb {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 3px var(--accent-glow);
|
||||
}
|
||||
|
||||
.clip-card:focus-visible .thumb {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.thumb video {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.check {
|
||||
position: absolute;
|
||||
top: 6px;
|
||||
right: 6px;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 9999px;
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.name {
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
line-height: 1.35;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
padding: 0 2px;
|
||||
}
|
||||
|
||||
.clip-card.selected .name {
|
||||
color: var(--text-primary);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.empty {
|
||||
margin: 32px 8px;
|
||||
text-align: center;
|
||||
color: var(--text-muted);
|
||||
font-size: 13px;
|
||||
line-height: 1.45;
|
||||
}
|
||||
</style>
|
||||
@@ -9,6 +9,7 @@
|
||||
import type { AssetOption } from '$lib/assetPicker';
|
||||
import Icon from '$lib/components/ui/Icon.svelte';
|
||||
import ClipMonitor from './ClipMonitor.svelte';
|
||||
import ClipSourceModal from './ClipSourceModal.svelte';
|
||||
import SceneFilmstrip from './SceneFilmstrip.svelte';
|
||||
import SceneScriptDrawer from './SceneScriptDrawer.svelte';
|
||||
|
||||
@@ -20,9 +21,11 @@
|
||||
}
|
||||
|
||||
interface ClipSourceOption {
|
||||
/** Scene id as string, for a native select. */
|
||||
/** Scene id as string, or the 'auto' / 'upload' sentinels. */
|
||||
id: string;
|
||||
label: string;
|
||||
/** Clip path — the source modal renders video thumbnails when present. */
|
||||
path?: string;
|
||||
}
|
||||
|
||||
interface ClipSourceConfig {
|
||||
@@ -52,6 +55,8 @@
|
||||
/** Where this continue scene's video input comes from (auto / upload / a timeline clip). */
|
||||
clipSource?: ClipSourceConfig;
|
||||
onClipSourceChange?: (value: string) => void;
|
||||
/** Upload file picked in the source modal — caller opens the file dialog. */
|
||||
onClipSourceUpload?: () => void;
|
||||
chained?: (scene: Scene) => boolean;
|
||||
submitting?: boolean;
|
||||
statusOf: (scene: Scene) => string;
|
||||
@@ -82,6 +87,7 @@
|
||||
generateDisabledReason = '',
|
||||
clipSource,
|
||||
onClipSourceChange,
|
||||
onClipSourceUpload,
|
||||
chained = () => false,
|
||||
submitting = false,
|
||||
statusOf,
|
||||
@@ -93,6 +99,17 @@
|
||||
onFormChange,
|
||||
onGenerate,
|
||||
}: Props = $props();
|
||||
|
||||
let clipSourceOpen = $state(false);
|
||||
|
||||
/** The label shown on the Video source trigger. */
|
||||
const clipSourceLabel = $derived.by(() => {
|
||||
if (!clipSource?.enabled) return '';
|
||||
const val = clipSource.value;
|
||||
if (val === 'auto') return 'Auto (previous clip)';
|
||||
if (val === 'upload') return 'Upload file';
|
||||
return clipSource.options.find((o) => o.id === val)?.label ?? 'Auto (previous clip)';
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="workspace">
|
||||
@@ -136,26 +153,29 @@
|
||||
</div>
|
||||
</div>
|
||||
{:else if clipSource?.enabled}
|
||||
<div class="clip-source-row">
|
||||
<label class="clip-source-label" for="clip-source-select">Video source</label>
|
||||
<select
|
||||
id="clip-source-select"
|
||||
class="clip-source-select"
|
||||
value={clipSource.value}
|
||||
onchange={(e) => onClipSourceChange?.(e.currentTarget.value)}
|
||||
>
|
||||
<option value="auto">Auto (previous clip)</option>
|
||||
<option value="upload">Upload file</option>
|
||||
{#if clipSource.options.length > 0}
|
||||
<optgroup label="From timeline">
|
||||
{#each clipSource.options as opt (opt.id)}
|
||||
<option value={opt.id}>{opt.label}</option>
|
||||
{/each}
|
||||
</optgroup>
|
||||
{/if}
|
||||
</select>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="clip-source-row">
|
||||
<span class="clip-source-label" id="clip-source-label">Video source</span>
|
||||
<button
|
||||
type="button"
|
||||
class="clip-source-trigger"
|
||||
aria-haspopup="dialog"
|
||||
aria-expanded={clipSourceOpen}
|
||||
aria-labelledby="clip-source-label clip-source-value"
|
||||
onclick={() => (clipSourceOpen = true)}
|
||||
>
|
||||
<Icon name="film" size={14} />
|
||||
<span id="clip-source-value" class="clip-source-value">{clipSourceLabel}</span>
|
||||
<Icon name="chevron-down" size={12} />
|
||||
</button>
|
||||
</div>
|
||||
<ClipSourceModal
|
||||
bind:open={clipSourceOpen}
|
||||
value={clipSource.value}
|
||||
options={clipSource.options}
|
||||
onselect={(source) => onClipSourceChange?.(source)}
|
||||
onupload={() => onClipSourceUpload?.()}
|
||||
/>
|
||||
{/if}
|
||||
{#if assetOptions.length === 0}
|
||||
<p class="asset-hint">
|
||||
No refs yet. Generate character sheets or environments in Assets, or upload a video/audio
|
||||
@@ -260,15 +280,38 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.clip-source-select {
|
||||
max-width: 320px;
|
||||
padding: 6px 10px;
|
||||
.clip-source-trigger {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
max-width: 360px;
|
||||
padding: 6px 12px;
|
||||
font: inherit;
|
||||
font-size: 13px;
|
||||
color: var(--text-primary);
|
||||
background: var(--bg-elevated);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-sm);
|
||||
font-family: var(--font-body);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.clip-source-trigger:hover {
|
||||
border-color: var(--text-muted);
|
||||
}
|
||||
|
||||
.clip-source-trigger:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.clip-source-trigger :global(svg:last-child) {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.clip-source-value {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.asset-hint {
|
||||
|
||||
Reference in New Issue
Block a user