- 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>
411 lines
11 KiB
Svelte
411 lines
11 KiB
Svelte
<script lang="ts">
|
||
import Icon from '$lib/components/ui/Icon.svelte';
|
||
import ShellPop from '$lib/components/shell/ShellPop.svelte';
|
||
import type { ComfyDynamicInput, Workflow } from '$lib/comfy/types';
|
||
import { t } from '$lib/i18n.svelte';
|
||
import ParamChip from './ParamChip.svelte';
|
||
import SlotTray from './SlotTray.svelte';
|
||
import WorkflowPicker from './WorkflowPicker.svelte';
|
||
import { chipValue, type BlockReason, type DeskSchema, type FormValue, type FormValues } from './schema';
|
||
|
||
/**
|
||
* 输入台 (spec-v2 §3.3): slots from the workflow JSON, the prompt, and one
|
||
* row of chips — workflow, connection, common params, 参数 — ending in
|
||
* 生成 with its reason line. The whole composer takes dropped files.
|
||
* ≤760px it collapses to one line and rises as a bottom sheet on focus.
|
||
*/
|
||
interface Props {
|
||
ds: DeskSchema;
|
||
values: FormValues;
|
||
workflows: Workflow[];
|
||
current: Workflow | null;
|
||
endpoints: Array<{ id: string; name: string }>;
|
||
endpointId: string;
|
||
conn: { state: 'ok' | 'fail' | 'untested' | 'dry'; ms?: number | null };
|
||
errors: Record<string, string>;
|
||
showErrors: boolean;
|
||
block: BlockReason | null;
|
||
changedCount: number;
|
||
submitting: boolean;
|
||
/** Shows 已提交 on the button for --d-flash. */
|
||
sent: boolean;
|
||
slotBusy?: boolean;
|
||
promptEl?: HTMLTextAreaElement | null;
|
||
onSet: (nodeId: string, value: FormValue) => void;
|
||
onPickWorkflow: (wf: Workflow) => void;
|
||
onPickEndpoint: (id: string) => void;
|
||
onSubmit: () => void;
|
||
onReveal: () => void;
|
||
onOpenParams: () => void;
|
||
onFromResults: (nodeId: string) => void;
|
||
}
|
||
|
||
let {
|
||
ds,
|
||
values,
|
||
workflows,
|
||
current,
|
||
endpoints,
|
||
endpointId,
|
||
conn,
|
||
errors,
|
||
showErrors,
|
||
block,
|
||
changedCount,
|
||
submitting,
|
||
sent,
|
||
slotBusy = $bindable(false),
|
||
promptEl = $bindable(null),
|
||
onSet,
|
||
onPickWorkflow,
|
||
onPickEndpoint,
|
||
onSubmit,
|
||
onReveal,
|
||
onOpenParams,
|
||
onFromResults,
|
||
}: Props = $props();
|
||
|
||
let tray = $state<ReturnType<typeof SlotTray> | null>(null);
|
||
let root = $state<HTMLElement | null>(null);
|
||
let dragDepth = $state(0);
|
||
let expanded = $state(false);
|
||
let connOpen = $state(false);
|
||
|
||
const hasSlots = $derived(ds.slots.length + ds.lists.length > 0);
|
||
const promptVal = $derived(ds.prompt ? String(values[ds.prompt.nodeId] ?? '') : '');
|
||
const promptErr = $derived(showErrors && ds.prompt ? errors[ds.prompt.nodeId] : undefined);
|
||
const endpointName = $derived(endpoints.find((e) => e.id === endpointId)?.name ?? t('desk.noConn'));
|
||
|
||
/** Composer chips: ratio, the width × height pair, resolution, duration, seed. */
|
||
const chips = $derived.by(() => {
|
||
const out: Array<{ key: string; inputs: ComfyDynamicInput[]; text: string }> = [];
|
||
if (ds.ratio) out.push({ key: ds.ratio.nodeId, inputs: [ds.ratio], text: chipValue(ds.ratio, values, ds) });
|
||
if (ds.width && ds.height) {
|
||
const w = values[ds.width.nodeId] ?? ds.width.defaultValue ?? '?';
|
||
const h = values[ds.height.nodeId] ?? ds.height.defaultValue ?? '?';
|
||
out.push({ key: ds.width.nodeId, inputs: [ds.width, ds.height], text: `${w}×${h}` });
|
||
} else {
|
||
for (const inp of [ds.width, ds.height]) {
|
||
if (inp) out.push({ key: inp.nodeId, inputs: [inp], text: `${inp.label} ${chipValue(inp, values, ds)}` });
|
||
}
|
||
}
|
||
for (const inp of [ds.resolution, ds.duration, ds.seed]) {
|
||
if (inp) out.push({ key: inp.nodeId, inputs: [inp], text: chipValue(inp, values, ds) });
|
||
}
|
||
return out;
|
||
});
|
||
|
||
function onDrop(e: DragEvent) {
|
||
e.preventDefault();
|
||
dragDepth = 0;
|
||
const files = Array.from(e.dataTransfer?.files ?? []);
|
||
if (files.length) tray?.dropFiles(files);
|
||
}
|
||
|
||
function hasFiles(e: DragEvent): boolean {
|
||
return Array.from(e.dataTransfer?.types ?? []).includes('Files');
|
||
}
|
||
|
||
function onFocusOut(e: FocusEvent) {
|
||
const next = e.relatedTarget as Node | null;
|
||
if (!next || !root?.contains(next)) expanded = false;
|
||
}
|
||
|
||
function onKeydown(e: KeyboardEvent) {
|
||
if (e.key === 'Escape' && expanded && !e.defaultPrevented) {
|
||
expanded = false;
|
||
(document.activeElement as HTMLElement | null)?.blur();
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<div class="composer-wrap">
|
||
<div class="a-sprocket" aria-hidden="true"></div>
|
||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||
<div
|
||
bind:this={root}
|
||
class="composer"
|
||
class:drag={dragDepth > 0}
|
||
class:expanded
|
||
onfocusin={() => (expanded = true)}
|
||
onfocusout={onFocusOut}
|
||
onkeydown={onKeydown}
|
||
ondragenter={(e) => {
|
||
if (!hasFiles(e)) return;
|
||
e.preventDefault();
|
||
dragDepth += 1;
|
||
}}
|
||
ondragleave={() => (dragDepth = Math.max(0, dragDepth - 1))}
|
||
ondragover={(e) => hasFiles(e) && e.preventDefault()}
|
||
ondrop={onDrop}
|
||
>
|
||
{#if hasSlots}
|
||
<div class="slots">
|
||
<SlotTray bind:this={tray} bind:busy={slotBusy} {ds} {values} {showErrors} {errors} {onSet} {onFromResults} />
|
||
</div>
|
||
{/if}
|
||
|
||
{#if ds.prompt}
|
||
<textarea
|
||
bind:this={promptEl}
|
||
id="desk-prompt"
|
||
class="prompt"
|
||
class:invalid={!!promptErr}
|
||
rows="2"
|
||
value={promptVal}
|
||
placeholder={t('desk.promptPh')}
|
||
aria-label={t('studio.promptLabel')}
|
||
aria-invalid={!!promptErr || undefined}
|
||
aria-keyshortcuts="Control+Enter Meta+Enter /"
|
||
oninput={(e) => onSet(ds.prompt!.nodeId, e.currentTarget.value)}
|
||
></textarea>
|
||
{#if promptErr}<p class="a-slot-hint err prompt-err" role="alert">{promptErr}</p>{/if}
|
||
{:else if current}
|
||
<p class="no-prompt">{t('desk.noPromptInput')}</p>
|
||
{/if}
|
||
|
||
<div class="foot">
|
||
<WorkflowPicker {workflows} {current} {endpoints} onPick={onPickWorkflow} />
|
||
<div class="conn opt">
|
||
<button
|
||
type="button"
|
||
id="desk-conn"
|
||
class="a-chip"
|
||
class:err={conn.state === 'fail'}
|
||
aria-haspopup="dialog"
|
||
aria-expanded={connOpen}
|
||
title={t('studio.connLabel')}
|
||
onclick={() => (connOpen = !connOpen)}
|
||
>
|
||
<span class="status-chip-dot {conn.state === 'ok' ? 'run' : conn.state === 'fail' ? 'fail' : 'idle'}"></span>
|
||
<span class="lbl">{endpointName}</span>
|
||
{#if conn.state === 'ok' && conn.ms != null}<span class="mono">· {Math.round(conn.ms)} ms</span>{/if}
|
||
{#if conn.state === 'dry'}<span>· {t('desk.dryRun')}</span>{/if}
|
||
</button>
|
||
<ShellPop bind:open={connOpen} label={t('studio.connLabel')} placement="top" width="280px">
|
||
<div class="a-menu-group">{t('studio.connLabel')}</div>
|
||
{#each endpoints as ep (ep.id)}
|
||
<button
|
||
type="button"
|
||
class="a-menu-item"
|
||
aria-current={ep.id === endpointId ? 'true' : undefined}
|
||
onclick={() => {
|
||
onPickEndpoint(ep.id);
|
||
connOpen = false;
|
||
}}
|
||
>
|
||
<span class="a-menu-label">{ep.name}</span>
|
||
</button>
|
||
{/each}
|
||
<a class="a-menu-item" href="/connections">
|
||
<Icon name="link" size={15} />
|
||
<span class="a-menu-label">{t('studio.connManage')}</span>
|
||
</a>
|
||
</ShellPop>
|
||
</div>
|
||
{#each chips as c (c.key)}
|
||
<div class="opt">
|
||
<ParamChip
|
||
inputs={c.inputs}
|
||
{values}
|
||
text={c.text}
|
||
invalid={showErrors && c.inputs.some((i) => !!errors[i.nodeId]?.trim())}
|
||
{onSet}
|
||
/>
|
||
</div>
|
||
{/each}
|
||
{#if ds.common.length + ds.advanced.length > 0}
|
||
<button type="button" class="a-chip opt" class:changed={changedCount > 0} onclick={onOpenParams}>
|
||
<Icon name="settings" size={14} />
|
||
<span class="lbl">
|
||
{changedCount > 0 ? t('desk.paramsChanged', { n: changedCount }) : t('desk.paramsAll')}
|
||
</span>
|
||
</button>
|
||
{/if}
|
||
|
||
<div class="submit">
|
||
{#if block}
|
||
<button type="button" class="why" class:err={block.tone === 'err'} onclick={onReveal}>
|
||
{block.text}
|
||
</button>
|
||
{/if}
|
||
<button
|
||
type="button"
|
||
class="a-btn primary gen"
|
||
class:sent
|
||
disabled={!!block || submitting || slotBusy}
|
||
aria-keyshortcuts="Control+Enter Meta+Enter"
|
||
title={t('desk.genHint')}
|
||
onclick={onSubmit}
|
||
>
|
||
<span class="l-idle"><Icon name="sparkle" size={13} />{t('desk.generate')}</span>
|
||
<span class="l-sent" aria-hidden={!sent}><Icon name="check" size={13} />{t('desk.sent')}</span>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<style>
|
||
.composer-wrap {
|
||
padding: var(--sp-2) var(--sp-7) var(--sp-6);
|
||
}
|
||
.a-sprocket {
|
||
margin: 0 var(--sp-2) var(--sp-3);
|
||
}
|
||
.composer {
|
||
border: 1px solid var(--line-2);
|
||
border-radius: var(--r-lg);
|
||
background: var(--composer-bg);
|
||
transition:
|
||
border-color var(--d-state) ease,
|
||
box-shadow var(--d-state) ease;
|
||
}
|
||
.composer:focus-within {
|
||
border-color: var(--accent-line);
|
||
box-shadow: var(--composer-focus);
|
||
}
|
||
.composer.drag {
|
||
border-color: var(--accent-line);
|
||
box-shadow: 0 0 0 3px var(--accent-soft);
|
||
}
|
||
.slots {
|
||
max-height: 40vh;
|
||
overflow-y: auto;
|
||
}
|
||
.prompt {
|
||
display: block;
|
||
box-sizing: border-box;
|
||
width: 100%;
|
||
min-height: 52px;
|
||
max-height: 180px;
|
||
padding: var(--sp-5) var(--sp-6) var(--sp-2);
|
||
border: 0;
|
||
outline: 0;
|
||
background: transparent;
|
||
color: var(--text);
|
||
font: inherit;
|
||
line-height: 1.6;
|
||
resize: none;
|
||
field-sizing: content;
|
||
}
|
||
.prompt:focus-visible {
|
||
outline: 0;
|
||
}
|
||
.prompt::placeholder {
|
||
color: var(--text-3);
|
||
}
|
||
.prompt-err,
|
||
.no-prompt {
|
||
margin: 0;
|
||
padding: 0 var(--sp-6);
|
||
}
|
||
.no-prompt {
|
||
padding-top: var(--sp-5);
|
||
font-size: var(--fs-aux);
|
||
color: var(--text-3);
|
||
}
|
||
.foot {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
align-items: center;
|
||
gap: var(--sp-2);
|
||
padding: var(--sp-2) var(--sp-3) var(--sp-3);
|
||
}
|
||
.conn {
|
||
position: relative;
|
||
}
|
||
.submit {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: var(--sp-4);
|
||
margin-left: auto;
|
||
}
|
||
.why {
|
||
padding: 0;
|
||
border: 0;
|
||
background: none;
|
||
font: inherit;
|
||
font-size: var(--fs-aux);
|
||
color: var(--warn);
|
||
white-space: nowrap;
|
||
text-decoration: underline dotted;
|
||
text-underline-offset: 3px;
|
||
cursor: pointer;
|
||
}
|
||
.why.err {
|
||
color: var(--err);
|
||
}
|
||
/* 生成:按下即缩,提交后文字换成「已提交」约 --d-flash,期间仍可再次提交 */
|
||
.gen {
|
||
display: inline-grid;
|
||
min-width: 84px;
|
||
border-radius: var(--r-pill);
|
||
}
|
||
.gen > span {
|
||
grid-area: 1 / 1;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: var(--sp-1);
|
||
transition:
|
||
opacity var(--d-state) ease,
|
||
transform var(--d-pop) var(--ease-out);
|
||
}
|
||
.gen .l-sent {
|
||
opacity: 0;
|
||
transform: translateY(8px);
|
||
}
|
||
.gen.sent .l-idle {
|
||
opacity: 0;
|
||
transform: translateY(-8px);
|
||
}
|
||
.gen.sent .l-sent {
|
||
opacity: 1;
|
||
transform: none;
|
||
}
|
||
:global(:root[data-reduce='1']) .gen > span {
|
||
transform: none;
|
||
}
|
||
|
||
@media (max-width: 1179px) {
|
||
.composer-wrap {
|
||
padding: var(--sp-2) var(--sp-6) var(--sp-5);
|
||
}
|
||
}
|
||
@media (max-width: 760px) {
|
||
.composer-wrap {
|
||
padding: var(--sp-1) var(--sp-4) var(--sp-4);
|
||
}
|
||
.composer:not(.expanded) .slots,
|
||
.composer:not(.expanded) .opt {
|
||
display: none;
|
||
}
|
||
.composer:not(.expanded) .prompt {
|
||
min-height: 40px;
|
||
max-height: 40px;
|
||
padding: var(--sp-4) var(--sp-5) var(--sp-1);
|
||
white-space: nowrap;
|
||
overflow: hidden;
|
||
}
|
||
.composer.expanded {
|
||
position: fixed;
|
||
left: 0;
|
||
right: 0;
|
||
bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
|
||
z-index: 45;
|
||
border-bottom: 0;
|
||
border-radius: var(--r-lg) var(--r-lg) 0 0;
|
||
box-shadow: var(--shadow-float);
|
||
max-height: calc(100dvh - var(--topbar-h) - var(--tabbar-h));
|
||
overflow-y: auto;
|
||
}
|
||
.composer.expanded .slots {
|
||
max-height: none;
|
||
}
|
||
.submit {
|
||
gap: var(--sp-3);
|
||
}
|
||
}
|
||
</style>
|