Files
aigc-home/calliope-web/src/lib/components/ui/Drawer.svelte
T
总工andmultica-agent 6064bd805d feat(ui): E批——工作流导入与试运行右侧抽屉 + 四步检查 (HEL-655)
- 新增 ui/Drawer.svelte 右侧抽屉基元:380/420px、--d-drawer 280ms
  --ease-drawer 可反向、Esc/Tab 焦点圈、遮罩点击关闭、减动效仅留 ≤120ms 淡变
- 新增 WorkflowImportDrawer.svelte:导入两步向导抽屉化,四步检查
  (解析 JSON→识别节点→核对模型→建立输入槽)逐条出现(80ms 错峰)、
  ✓绿/…青/✕红/待确认琥珀 + 中文原因 + 下一步建议 + 可展开错误 + 重新检查 +
  「查看原始 JSON」折叠;沿用 /api/workflows/analyze 原判定与保存边界
- WorkflowTestDialog.svelte 居中弹窗改右侧抽屉:运行中青芯片 + 进度条 +
  mono 阶段日志滚动区,结果缩略图横排、失败红 + 长错误可展开;
  逻辑(确认弹层、dry_run 拒绝、产物隔离、重复提交复用)不变
- connections 页:导入入口统一为抽屉按钮,次级文字操作(测试/重新检查/更改)
  改 ghost(HEL-649 v2 §1.2),连接卡片改 §3.7 网格;移除内联导入块与死样式
- i18n 七语种各 +16 键(wfd.*)计数一致
- e2e:fake_comfy.py 支持 object_info/no_outputs 场景;新增 import.mjs
  43 项浏览器回归全过;D 批 shoot.mjs 54/54 复跑通过

Co-authored-by: multica-agent <github@multica.ai>
2026-09-30 14:42:56 +08:00

257 lines
6.4 KiB
Svelte

<script lang="ts">
import type { Snippet } from 'svelte';
import Icon from './Icon.svelte';
import { t } from '$lib/i18n.svelte';
/**
* Drawer — the shared right-side floating layer (HEL-649 §四.3):
* slides in over 280ms with --ease-drawer and reverses mid-flight,
* focus is trapped while open, Esc / backdrop click close it, and
* reduced-motion keeps only a ≤120ms opacity fade (no slide).
*/
interface Props {
open?: boolean;
title?: string;
/** Panel width on >760px screens. */
width?: number;
dismissible?: boolean;
onclose?: () => void;
footer?: Snippet;
children: Snippet;
}
let {
open = $bindable(false),
title,
width = 380,
dismissible = true,
onclose,
footer,
children,
}: Props = $props();
const FOCUSABLE =
'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
const titleId = `drawer-title-${Math.random().toString(36).slice(2, 9)}`;
let panel = $state<HTMLDivElement | null>(null);
function requestClose() {
if (!dismissible) return;
open = false;
}
function handleKeydown(event: KeyboardEvent) {
if (event.key === 'Escape') {
event.preventDefault();
requestClose();
return;
}
if (event.key === 'Tab') trapFocus(event);
}
function trapFocus(event: KeyboardEvent) {
if (!panel) return;
const focusables = Array.from(
panel.querySelectorAll<HTMLElement>(FOCUSABLE),
).filter((el) => el.getClientRects().length > 0);
if (focusables.length === 0) {
event.preventDefault();
panel.focus();
return;
}
const first = focusables[0];
const last = focusables[focusables.length - 1];
const active = document.activeElement;
const focusInside = panel.contains(active);
if (event.shiftKey && (!focusInside || active === first)) {
event.preventDefault();
last.focus();
} else if (!focusInside || active === last) {
event.preventDefault();
first.focus();
}
}
function handleBackdropClick(event: MouseEvent) {
if (event.target === event.currentTarget) requestClose();
}
$effect(() => {
if (!open) return;
const invoker = document.activeElement as HTMLElement | null;
const previousOverflow = document.body.style.overflow;
document.body.style.overflow = 'hidden';
document.addEventListener('keydown', handleKeydown, true);
requestAnimationFrame(() => {
if (!panel || panel.contains(document.activeElement)) return;
const first = panel.querySelector<HTMLElement>(FOCUSABLE);
(first ?? panel).focus();
});
return () => {
document.body.style.overflow = previousOverflow;
document.removeEventListener('keydown', handleKeydown, true);
if (invoker?.isConnected) invoker.focus();
onclose?.();
};
});
</script>
{#if open}
<!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
<div class="drawer-backdrop" onclick={handleBackdropClick}>
<div
bind:this={panel}
class="drawer-panel"
style:--drawer-w="{width}px"
role="dialog"
aria-modal="true"
aria-labelledby={title ? titleId : undefined}
aria-label={title ? undefined : t('modal.dialog')}
tabindex="-1"
>
{#if title || dismissible}
<div class="drawer-header">
{#if title}
<h2 class="drawer-title" id={titleId}>{title}</h2>
{/if}
{#if dismissible}
<button
type="button"
class="drawer-close"
aria-label={t('modal.closeDialog')}
onclick={requestClose}
>
<Icon name="close" size={16} />
</button>
{/if}
</div>
{/if}
<div class="drawer-body">
{@render children()}
</div>
{#if footer}
<div class="drawer-footer">
{@render footer()}
</div>
{/if}
</div>
</div>
{/if}
<style>
.drawer-backdrop {
position: fixed;
inset: 0;
z-index: 900;
display: flex;
justify-content: flex-end;
background: var(--overlay);
animation: drawer-fade var(--d-state) ease-out;
}
.drawer-panel {
width: min(var(--drawer-w), 100vw);
height: 100dvh;
display: flex;
flex-direction: column;
background: var(--float-bg);
border-radius: var(--r-lg) 0 0 var(--r-lg);
box-shadow: var(--shadow-float);
outline: none;
animation: drawer-slide var(--d-drawer) var(--ease-drawer) both;
}
.drawer-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 16px 20px 0;
flex-shrink: 0;
}
.drawer-title {
margin: 0;
font-size: var(--fs-title);
font-weight: 600;
color: var(--text);
}
.drawer-close {
display: flex;
align-items: center;
justify-content: center;
width: 28px;
height: 28px;
margin-left: auto;
border: none;
border-radius: var(--r-sm);
background: transparent;
color: var(--text-3);
cursor: pointer;
transition:
background-color var(--d-state) ease,
color var(--d-state) ease;
}
@media (hover: hover) and (pointer: fine) {
.drawer-close:hover {
background: var(--bg-4);
color: var(--text);
}
}
.drawer-close:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.drawer-body {
padding: 14px 20px 20px;
overflow-y: auto;
flex: 1;
min-height: 0;
font-size: 13px;
line-height: 1.55;
color: var(--text);
}
.drawer-footer {
display: flex;
justify-content: flex-end;
gap: 8px;
padding: 12px 20px 16px;
border-top: 1px solid var(--line);
flex-shrink: 0;
}
@keyframes drawer-fade {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes drawer-slide {
from {
transform: translateX(100%);
}
to {
transform: translateX(0);
}
}
/* 减少动态效果 (§五):去位移,只留 ≤120ms 透明度 */
:global(:root[data-reduce='1']) .drawer-panel {
animation: drawer-fade var(--d-drawer) ease-out both;
}
@media (prefers-reduced-motion: reduce) {
.drawer-panel {
animation: drawer-fade var(--d-drawer) ease-out both;
}
}
@media (max-width: 760px) {
.drawer-panel {
width: 100vw;
border-radius: 0;
}
}
</style>