- StudioGenerate 拆为 generate/ 下的 Composer、WorkflowPicker、SlotTray、ParamChip、 TakeFeed/TakeCard、Inspector、ParamsPanel、ContextBar,逻辑收进 schema/takes/context - 输入槽只按工作流 JSON 实际接线渲染;常用参数芯片 + 高级参数折叠,显示原值与已改标记 - 工作台素材/镜头卡新增「在生成台调参」,带项目上下文进入;结果不回填(后端无目标) - 共享样式(a-chip/a-seg/a-slot/a-tile 等)进 app.css;ShellPop 支持向上弹出 - /image、/video 仍是同一生成台,按用途预选默认工作流与筛选 Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: multica-agent <github@multica.ai>
196 lines
5.0 KiB
Svelte
196 lines
5.0 KiB
Svelte
<script lang="ts">
|
||
import Icon from '$lib/components/ui/Icon.svelte';
|
||
import { assetUrl } from '$lib/api';
|
||
import { IMAGE_SLOT_ACCEPT, formatBytes, uploadBaseName } from '$lib/comfy/imageFile';
|
||
import { t } from '$lib/i18n.svelte';
|
||
|
||
/**
|
||
* Single media input slot as a composer tile (spec-v2 §3.3 输入槽):
|
||
* empty = dashed + "+", drag-hover = gold, uploading = ring, filled = thumb
|
||
* (click to replace) with a ✕ on hover/focus. `need` = required but empty
|
||
* after a blocked 生成 (amber); `error` = rejected file / invalid (red).
|
||
*/
|
||
interface Props {
|
||
label: string;
|
||
/** Hint after the label, e.g. 必填 · 1 张. */
|
||
hint?: string;
|
||
required?: boolean;
|
||
/** Current value: a server-side path ('' = empty). */
|
||
value: string;
|
||
kind: 'image' | 'video' | 'audio';
|
||
/** Byte size of the current file when known. */
|
||
size?: number;
|
||
uploading?: boolean;
|
||
uploadName?: string;
|
||
need?: boolean;
|
||
error?: string;
|
||
/** Show the 从结果选 action (image slots fed from finished takes). */
|
||
allowFromResults?: boolean;
|
||
/** Anchor id so 「还缺:…」 can jump focus here. */
|
||
anchorId?: string;
|
||
onFile: (file: File) => void;
|
||
onFromResults?: () => void;
|
||
onClear: () => void;
|
||
}
|
||
|
||
let {
|
||
label,
|
||
hint,
|
||
required = false,
|
||
value,
|
||
kind,
|
||
size,
|
||
uploading = false,
|
||
uploadName,
|
||
need = false,
|
||
error,
|
||
allowFromResults = false,
|
||
anchorId,
|
||
onFile,
|
||
onFromResults,
|
||
onClear,
|
||
}: Props = $props();
|
||
|
||
let fileInput = $state<HTMLInputElement | null>(null);
|
||
let dragDepth = $state(0);
|
||
let broken = $state(false);
|
||
let dims = $state('');
|
||
$effect(() => {
|
||
void value;
|
||
broken = false;
|
||
dims = '';
|
||
});
|
||
|
||
const filled = $derived(!!value && !broken);
|
||
const meta = $derived(
|
||
[uploadBaseName(value), dims, size != null ? formatBytes(size) : ''].filter(Boolean).join(' · '),
|
||
);
|
||
|
||
function accept(): string {
|
||
if (kind === 'video') return 'video/*,.mp4,.webm,.mov,.mkv';
|
||
if (kind === 'audio') return 'audio/*';
|
||
return IMAGE_SLOT_ACCEPT;
|
||
}
|
||
|
||
function noteDims(e: Event) {
|
||
const img = e.currentTarget as HTMLImageElement;
|
||
if (img.naturalWidth) dims = `${img.naturalWidth}×${img.naturalHeight}`;
|
||
}
|
||
|
||
function pick() {
|
||
if (uploading || !fileInput) return;
|
||
fileInput.value = '';
|
||
fileInput.click();
|
||
}
|
||
|
||
function onDrop(e: DragEvent) {
|
||
e.preventDefault();
|
||
e.stopPropagation();
|
||
dragDepth = 0;
|
||
if (uploading) return;
|
||
const file = e.dataTransfer?.files?.[0];
|
||
if (file) onFile(file);
|
||
}
|
||
|
||
const dragHandlers = {
|
||
ondragenter: (e: DragEvent) => {
|
||
e.preventDefault();
|
||
dragDepth += 1;
|
||
},
|
||
ondragleave: () => (dragDepth = Math.max(0, dragDepth - 1)),
|
||
ondragover: (e: DragEvent) => e.preventDefault(),
|
||
ondrop: onDrop,
|
||
};
|
||
</script>
|
||
|
||
<div class="a-slot">
|
||
<div class="a-slot-label">
|
||
<span>{label}</span>
|
||
{#if required}<span class="req" aria-hidden="true">*</span>{/if}
|
||
{#if hint}<span>{hint}</span>{/if}
|
||
{#if allowFromResults && onFromResults}
|
||
<button type="button" class="a-btn ghost xs" onclick={onFromResults}>
|
||
{t('studio.slotFromResultsShort')}
|
||
</button>
|
||
{/if}
|
||
</div>
|
||
|
||
<input
|
||
bind:this={fileInput}
|
||
type="file"
|
||
class="sr-file"
|
||
tabindex="-1"
|
||
aria-hidden="true"
|
||
accept={accept()}
|
||
onchange={(e) => {
|
||
const f = e.currentTarget.files?.[0];
|
||
if (f) onFile(f);
|
||
}}
|
||
/>
|
||
|
||
<div class="a-slot-row">
|
||
{#if filled}
|
||
<div class="a-tile" class:drag={dragDepth > 0} class:bad={!!error} {...dragHandlers}>
|
||
<button
|
||
type="button"
|
||
id={anchorId}
|
||
class="a-tile-hit"
|
||
title={`${t('studio.refReplace')} · ${meta}`}
|
||
aria-label={`${t('studio.refReplace')} ${label}`}
|
||
disabled={uploading}
|
||
onclick={pick}
|
||
>
|
||
{#if kind === 'image'}
|
||
<img src={assetUrl(value)} alt="" onload={noteDims} onerror={() => (broken = true)} />
|
||
{:else if kind === 'video'}
|
||
<video src={assetUrl(value)} preload="metadata" muted playsinline></video>
|
||
{:else}
|
||
<Icon name="music" size={18} />
|
||
{/if}
|
||
</button>
|
||
{#if uploading}
|
||
<span class="a-tile-ring" title={uploadName}><i></i></span>
|
||
{:else}
|
||
<button type="button" class="a-tile-x" aria-label={`${t('studio.deleteBtn')} ${label}`} onclick={onClear}>
|
||
<Icon name="close" size={10} />
|
||
</button>
|
||
{/if}
|
||
</div>
|
||
{:else}
|
||
<button
|
||
type="button"
|
||
id={anchorId}
|
||
class="a-tile add"
|
||
class:drag={dragDepth > 0}
|
||
class:need={need && !error}
|
||
class:bad={!!error}
|
||
title={t('studio.slotPick')}
|
||
aria-label={`${label} · ${t('studio.slotPick')}`}
|
||
aria-busy={uploading || undefined}
|
||
disabled={uploading}
|
||
onclick={pick}
|
||
{...dragHandlers}
|
||
>
|
||
{#if uploading}
|
||
<span class="a-tile-ring" title={uploadName}><i></i></span>
|
||
{:else}
|
||
<Icon name={kind === 'video' ? 'film' : kind === 'audio' ? 'music' : 'plus'} size={18} />
|
||
{/if}
|
||
</button>
|
||
{/if}
|
||
</div>
|
||
{#if error?.trim()}<span class="a-slot-hint err" role="alert">{error}</span>{/if}
|
||
</div>
|
||
|
||
<style>
|
||
.sr-file {
|
||
position: absolute;
|
||
width: 1px;
|
||
height: 1px;
|
||
overflow: hidden;
|
||
clip: rect(0 0 0 0);
|
||
white-space: nowrap;
|
||
border: 0;
|
||
}
|
||
</style>
|