Files
aigc-home/calliope-web/src/lib/components/generate/ParamChip.svelte
T
6f4d50f4f0 HEL-653: C 批生成台——拆分输入台/工作流选择/输入槽/记录流/检视区
- 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>
2026-09-30 10:59:46 +08:00

180 lines
5.0 KiB
Svelte
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script lang="ts">
import ShellPop from '$lib/components/shell/ShellPop.svelte';
import type { ComfyDynamicInput } from '$lib/comfy/types';
import { t } from '$lib/i18n.svelte';
import { inputRole, isChanged, type FormValue, type FormValues } from './schema';
/**
* One common parameter as a composer chip (spec-v2 §3.3 参数芯片): the
* pop edits it in place — options list for selects, a number field for
* the rest (seed adds 随机) — and 恢复原值 returns to the workflow value.
* `inputs` holds two entries for the width × height pair.
*/
interface Props {
inputs: ComfyDynamicInput[];
values: FormValues;
text: string;
title?: string;
invalid?: boolean;
onSet: (nodeId: string, value: FormValue) => void;
}
let { inputs, values, text, title, invalid = false, onSet }: Props = $props();
let open = $state(false);
const changed = $derived(inputs.some((i) => isChanged(i, values)));
const single = $derived(inputs.length === 1 ? inputs[0] : null);
const uid = Math.random().toString(36).slice(2, 8);
function current(inp: ComfyDynamicInput): string {
const v = values[inp.nodeId] ?? inp.defaultValue ?? '';
return Array.isArray(v) ? v.join(',') : String(v);
}
function setNumber(inp: ComfyDynamicInput, raw: string) {
if (raw === '') return onSet(inp.nodeId, '');
const n = Number(raw);
onSet(inp.nodeId, Number.isNaN(n) ? raw : n);
}
function restore() {
for (const inp of inputs) onSet(inp.nodeId, inp.defaultValue ?? '');
}
function randomSeed(inp: ComfyDynamicInput) {
const max = Math.min(inp.max ?? 2 ** 32 - 1, Number.MAX_SAFE_INTEGER);
const min = Math.max(inp.min ?? 0, 0);
onSet(inp.nodeId, min + Math.floor(Math.random() * (max - min + 1)));
}
function pickOption(inp: ComfyDynamicInput, opt: string) {
onSet(inp.nodeId, opt);
open = false;
}
</script>
<div class="param-chip">
<button
type="button"
class="a-chip"
class:changed={changed && !invalid}
class:err={invalid}
aria-haspopup="dialog"
aria-expanded={open}
title={title ?? inputs.map((i) => i.label).join(' × ')}
onclick={() => (open = !open)}
>
<span class="lbl">{text}</span>
</button>
<ShellPop bind:open label={inputs.map((i) => i.label).join(' × ')} placement="top" width="260px">
{#if single?.kind === 'select' && single.options?.length}
<div class="a-menu-group">{single.label}</div>
{#each single.options as opt (opt)}
<button
type="button"
class="a-menu-item"
aria-current={current(single) === opt ? 'true' : undefined}
onclick={() => pickOption(single, opt)}
>
<span class="a-menu-label">{opt}</span>
{#if String(single.defaultValue ?? '') === opt}
<span class="a-menu-meta">{t('desk.origValue')}</span>
{/if}
</button>
{/each}
{:else}
<div class="fields">
{#each inputs as inp (inp.nodeId)}
{@const id = `pc-${uid}-${inp.nodeId.replace(/[^a-zA-Z0-9_-]/g, '')}`}
<div class="field-row">
<label class="field-label" for={id}>
{inp.label}
{#if inp.defaultValue !== undefined && inp.defaultValue !== ''}
<span class="orig mono">{t('cdf.orig', { v: String(inp.defaultValue) })}</span>
{/if}
</label>
<div class="inline">
{#if inp.kind === 'number'}
<input
{id}
class="a-input mono"
class:invalid
type="number"
inputmode="numeric"
value={current(inp)}
oninput={(e) => setNumber(inp, e.currentTarget.value)}
onkeydown={(e) => e.key === 'Enter' && (open = false)}
/>
{:else}
<input
{id}
class="a-input"
class:invalid
type="text"
value={current(inp)}
oninput={(e) => onSet(inp.nodeId, e.currentTarget.value)}
onkeydown={(e) => e.key === 'Enter' && (open = false)}
/>
{/if}
{#if inputRole(inp) === 'seed'}
<button type="button" class="a-btn secondary sm" onclick={() => randomSeed(inp)}>
{t('desk.seedRandom')}
</button>
{/if}
</div>
{#if inp.min != null || inp.max != null}
<span class="field-hint mono">{inp.min ?? '−∞'} – {inp.max ?? '∞'}</span>
{/if}
</div>
{/each}
</div>
{/if}
{#if changed}
<div class="foot">
<button type="button" class="a-btn ghost sm" onclick={restore}>{t('desk.restoreOrig')}</button>
</div>
{/if}
</ShellPop>
</div>
<style>
.param-chip {
position: relative;
min-width: 0;
}
.fields {
display: grid;
gap: var(--sp-5);
padding: var(--sp-3);
}
.field-row {
display: grid;
gap: var(--sp-2);
}
.field-row .field-label {
display: flex;
justify-content: space-between;
gap: var(--sp-3);
margin: 0;
}
.orig {
font-size: var(--fs-mini);
color: var(--text-3);
font-weight: 400;
}
.inline {
display: flex;
gap: var(--sp-2);
}
.field-row .field-hint {
margin: 0;
}
.foot {
display: flex;
justify-content: flex-end;
padding: var(--sp-2) var(--sp-1) 0;
border-top: 1px solid var(--line);
margin-top: var(--sp-2);
}
</style>