Files
aigc-home/calliope-web/src/lib/components/generate/TakeFeed.svelte
T
总工andmultica-agent 949cd2ecad HEL-654: D 批——记录流状态语义、金框结果切换、撤销删除与任务页重皮
- 点选金框滑动 + 检视区 150ms 交叉淡变;↑↓/J/K 即时切换、空格播放、
  Delete 删除、] 检视区、浮层让位;新记录入场/完成金光/失败抖动,减动效只余短淡变
- 单条删除 5 秒撤销(Toast 金色动作钮),窗口过后才提交 DELETE,离页 flush;
  任务页同队列同步;工作流删除保留旧记录并标识「工作流已删除」
- 红/琥珀界线:失败红 + 中文结论展开;done 但文件取不到 → 琥珀「文件缺失」
  + 用相同参数重做/移除记录
- 参数页提交自动切结果页;工作流选择器 ↑↓ 真高亮 + Enter 使用(ShellPop arrowRoving 开关)
- 记录流 80 条分页(220 条专项:50 次轮询 490ms);任务页 §3.5 芯片+搜索+
  行内进度条+ghost 重试;i18n 七语种 +17 键

Co-authored-by: multica-agent <github@multica.ai>
2026-09-30 13:02:51 +08:00

345 lines
10 KiB
Svelte

<script lang="ts">
import type { Snippet } from 'svelte';
import { cubicOut } from 'svelte/easing';
import { SvelteSet } from 'svelte/reactivity';
import Icon from '$lib/components/ui/Icon.svelte';
import type { Job, Workflow } from '$lib/comfy/types';
import { parseDbTs } from '$lib/dbtime';
import { t } from '$lib/i18n.svelte';
import TakeCard from './TakeCard.svelte';
import { dayLabel, matchesFilter, type FeedFilter } from './takes';
/**
* 记录流 (spec-v2 §3.3): every desk take, newest last above the composer,
* filtered 全部 / 图片 / 视频 / 失败 and grouped by day.
* D 批 (HEL-654): rows pending their 5-second undo collapse out
* (200ms) instead of vanishing, new/restored takes rise in (220ms),
* the gold selection frame slides between cards on pointer picks
* (键盘 ↑↓/J/K 即时切换无动画 — driven by the desk through the
* exported helpers), and long histories page in from the top
* (spec §五: 记录流超 200 条分页).
*/
interface Props {
jobs: Job[];
workflowOf: (job: Job) => Workflow | undefined;
filter: FeedFilter;
selectedId: number | null;
nowMs: number;
busyId: number | null;
loading: boolean;
/** Takes whose delete is inside the 5s undo window — hidden. */
pendingIds: SvelteSet<number>;
/** One-shot completion flashes / failure shakes (driven by SSE). */
flashIds: SvelteSet<number>;
shakeIds: SvelteSet<number>;
/** Ordered visible ids (oldest first) for ↑↓/J/K. */
orderedIds?: number[];
/** Shown under the filters (e.g. the workbench context bar). */
banner?: Snippet;
/** Inspector toggle when it is hidden (desktop) or an overlay (mid). */
inspectorToggle?: Snippet;
onSelect: (job: Job) => void;
onReuse: (job: Job) => void;
onRetry: (job: Job) => void;
onCancel: (job: Job) => void;
onDelete: (job: Job) => void;
}
let {
jobs,
workflowOf,
filter = $bindable(),
selectedId,
nowMs,
busyId,
loading,
pendingIds,
flashIds,
shakeIds,
orderedIds = $bindable(),
banner,
inspectorToggle,
onSelect,
onReuse,
onRetry,
onCancel,
onDelete,
}: Props = $props();
const FILTERS: Array<{ id: FeedFilter; key: string }> = [
{ id: 'all', key: 'desk.filterAll' },
{ id: 'image', key: 'desk.filterImage' },
{ id: 'video', key: 'desk.filterVideo' },
{ id: 'failed', key: 'desk.filterFailed' },
];
/** §五 分页: render the newest PAGE_SIZE takes; older ones load on demand. */
const PAGE_SIZE = 80;
let limit = $state(PAGE_SIZE);
let scroller = $state<HTMLElement | null>(null);
/** Oldest first so the newest take sits right above the composer. */
const shown = $derived(
jobs
.filter((j) => matchesFilter(j, filter) && !pendingIds.has(j.id))
.sort((a, b) => parseDbTs(a.created_at) - parseDbTs(b.created_at)),
);
const hiddenEarlier = $derived(Math.max(0, shown.length - limit));
const visible = $derived(hiddenEarlier > 0 ? shown.slice(-limit) : shown);
$effect(() => {
orderedIds = visible.map((j) => j.id);
});
const activeCount = $derived(jobs.filter((j) => j.status === 'pending' || j.status === 'running').length);
const days = $derived.by(() => {
const out: Array<{ label: string; items: Job[] }> = [];
for (const job of visible) {
const label = dayLabel(parseDbTs(job.created_at), nowMs);
const last = out[out.length - 1];
if (last?.label === label) last.items.push(job);
else out.push({ label, items: [job] });
}
return out;
});
// Stick to the bottom as takes arrive, unless the user scrolled up to read.
let pinned = true;
function onScroll() {
if (!scroller) return;
pinned = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < 80;
}
$effect(() => {
void visible.length;
void filter;
if (!scroller || !pinned) return;
const el = scroller;
requestAnimationFrame(() => (el.scrollTop = el.scrollHeight));
});
// ------------------------------------------------------------------
// Entrance bookkeeping: only takes that appear AFTER the first fill
// (or come back from an undo) play the 220ms rise.
// ------------------------------------------------------------------
const seenIds = new Set<number>();
const animateIds = new SvelteSet<number>();
let hydrated = false;
$effect(() => {
if (!hydrated) {
if (jobs.length) {
for (const j of jobs) seenIds.add(j.id);
hydrated = true;
}
return;
}
for (const j of jobs) {
if (seenIds.has(j.id)) continue;
seenIds.add(j.id);
animateIds.add(j.id);
}
});
export function markEnter(jobId: number) {
seenIds.add(jobId);
animateIds.add(jobId);
}
function reduced(): boolean {
return (
document.documentElement.dataset.reduce === '1' ||
window.matchMedia('(prefers-reduced-motion: reduce)').matches
);
}
// ------------------------------------------------------------------
// Gold selection frame (HEL-648 slideMark): pointer picks only.
// ------------------------------------------------------------------
export function markRect(): DOMRect | null {
const el = scroller?.querySelector(`.take[data-job="${selectedId}"]`);
return el instanceof HTMLElement ? el.getBoundingClientRect() : null;
}
export function slideFrom(fromRect: DOMRect | null) {
if (!fromRect || reduced()) return;
const el = scroller?.querySelector(`.take[data-job="${selectedId}"]`);
const mark = el?.querySelector('.sel-mark');
if (!(el instanceof HTMLElement) || !(mark instanceof HTMLElement)) return;
const to = el.getBoundingClientRect();
if (Math.abs(fromRect.top - to.top) < 1 && Math.abs(fromRect.height - to.height) < 1) return;
mark.animate(
[
{ top: `${fromRect.top - to.top - 1}px`, bottom: `${to.bottom - fromRect.bottom - 1}px` },
{ top: '-1px', bottom: '-1px' },
],
{ duration: 220, easing: 'cubic-bezier(0.23, 1, 0.32, 1)' },
);
}
/** Bring a keyboard-selected take into view without animation. */
export function scrollToJob(jobId: number) {
const el = scroller?.querySelector(`.take[data-job="${jobId}"]`);
el?.scrollIntoView({ block: 'nearest', behavior: 'auto' });
}
// ------------------------------------------------------------------
// Row transitions: undo-pending rows collapse out (200ms 收起 + 补位),
// new/restored takes rise in (220ms). Everything else is instant.
// ------------------------------------------------------------------
function takeEnter(_node: HTMLElement, should: () => boolean) {
if (!should()) return { duration: 0 };
if (reduced()) return { duration: 120, css: (t: number) => `opacity: ${t}` };
return {
duration: 220,
easing: cubicOut,
css: (t: number) => `opacity: ${t}; transform: translateY(${8 * (1 - t)}px)`,
};
}
function takeLeave(node: HTMLElement, isPending: () => boolean) {
if (!isPending()) return { duration: 0 };
if (reduced()) return { duration: 120, css: (t: number) => `opacity: ${t}` };
const h = node.offsetHeight;
const cs = getComputedStyle(node);
const num = (v: string) => parseFloat(v) || 0;
const padT = num(cs.paddingTop);
const padB = num(cs.paddingBottom);
const mb = num(cs.marginBottom);
return {
duration: 200,
easing: cubicOut,
css: (t: number, u: number) =>
`height:${h * t}px;padding-top:${padT * t}px;padding-bottom:${padB * t}px;` +
`margin-bottom:${mb * t}px;opacity:${t};transform:translateX(${-10 * u}px);overflow:hidden;`,
};
}
</script>
<div class="filters">
<div class="a-seg" role="group" aria-label={t('desk.filterAria')}>
{#each FILTERS as f (f.id)}
<button type="button" aria-pressed={filter === f.id} onclick={() => (filter = f.id)}>{t(f.key)}</button>
{/each}
</div>
<span class="count">
{t('desk.countTakes', { n: shown.length })}{#if activeCount}&nbsp;· {t('desk.countActive', { n: activeCount })}{/if}
</span>
{@render inspectorToggle?.()}
</div>
{@render banner?.()}
<div class="feed" bind:this={scroller} onscroll={onScroll}>
{#if loading && !jobs.length}
<p class="empty">{t('common.loading')}</p>
{:else if !shown.length}
<div class="empty">
<Icon name={filter === 'video' ? 'film' : filter === 'failed' ? 'check' : 'image'} size={20} />
<p>{filter === 'failed' ? t('desk.emptyFailed') : t('desk.emptyFeed')}</p>
</div>
{:else}
{#if hiddenEarlier > 0}
<button type="button" class="a-btn ghost sm earlier" onclick={() => (limit += PAGE_SIZE)}>
<Icon name="chevron-up" size={13} />
{t('desk.loadEarlier', { n: hiddenEarlier })}
</button>
{/if}
{#each days as day (day.label)}
<div class="day">{day.label}</div>
{#each day.items as job (job.id)}
<div
class="take-slot"
in:takeEnter={() => animateIds.has(job.id)}
out:takeLeave={() => pendingIds.has(job.id)}
>
<TakeCard
{job}
wf={workflowOf(job)}
selected={job.id === selectedId}
{nowMs}
busy={busyId === job.id}
enter={animateIds.has(job.id)}
flash={flashIds.has(job.id)}
shake={shakeIds.has(job.id)}
onSelect={() => onSelect(job)}
onReuse={() => onReuse(job)}
onRetry={() => onRetry(job)}
onCancel={() => onCancel(job)}
onDelete={() => onDelete(job)}
/>
</div>
{/each}
{/each}
{/if}
</div>
<style>
.filters {
display: flex;
align-items: center;
gap: var(--sp-2);
padding: var(--sp-4) var(--sp-7);
border-bottom: 1px solid var(--line);
}
.count {
margin-left: auto;
color: var(--text-3);
font-size: var(--fs-aux);
white-space: nowrap;
}
.feed {
flex: 1;
min-height: 0;
overflow-y: auto;
padding: var(--sp-6) var(--sp-7) var(--sp-3);
}
.earlier {
display: flex;
margin: 0 auto var(--sp-4);
}
.day {
display: flex;
align-items: center;
gap: var(--sp-3);
margin: var(--sp-4) 0 var(--sp-3);
color: var(--text-3);
font-size: var(--fs-aux);
}
.day::after {
content: '';
flex: 1;
height: 1px;
background: var(--line);
}
.empty {
display: grid;
place-items: center;
gap: var(--sp-3);
margin: 0;
padding: var(--sp-8) var(--sp-6);
color: var(--text-3);
text-align: center;
font-size: var(--fs-aux);
}
.empty p {
margin: 0;
}
@media (max-width: 1179px) {
.filters {
padding: var(--sp-4) var(--sp-6);
}
.feed {
padding: var(--sp-5) var(--sp-6) var(--sp-3);
}
}
@media (max-width: 760px) {
.filters {
padding: var(--sp-3) var(--sp-5);
overflow-x: auto;
}
.count {
display: none;
}
.feed {
padding: var(--sp-5) var(--sp-5) var(--sp-2);
}
}
</style>