feat(canvas): 画布工作区 - 整合侧栏与风格预设并修复提示词回填
选择性整合 #547,保留主分支节点与工具条设计。新增默认折叠的节点、资产、任务和历史面板,风格与预设保留在节点内,移除重复入口。 补齐工具权限、提示词解析、资源引用保护及数据库迁移,修复提示词清空和连续编辑后的生成配置同步。 验证:前端全量 1925 项测试、构建、类型检查及 lint 通过;后端 go test ./... 通过。真实模型、PostgreSQL 实库与登录态页面验收仍待进行。 Refs #547 Co-authored-by: bensharp <bensharp@qq.com>
This commit is contained in:
1 parent
be5f2733b6
commit
e93bf3ca39
66 files changed
+6127
-97
No files matched your search
@@ -48,7 +48,7 @@ export function CanvasSelectionToolbar({ anchorRef, containerRef, count, childre
|
||||
toolbarRef.current.classList.toggle("-translate-y-full", placement === "above");
|
||||
return;
|
||||
}
|
||||
setAnchor((current) => current?.left === left && current.top === top && current.placement === placement ? current : { left, top, placement });
|
||||
setAnchor((current) => (current?.left === left && current.top === top && current.placement === placement ? current : { left, top, placement }));
|
||||
};
|
||||
|
||||
update();
|
||||
@@ -79,15 +79,45 @@ export function CanvasSelectionToolbar({ anchorRef, containerRef, count, childre
|
||||
onMouseDown={(event) => event.stopPropagation()}
|
||||
onPointerDown={(event) => event.stopPropagation()}
|
||||
>
|
||||
<motion.div initial={reducedMotion ? { opacity: 0 } : { opacity: 0, scale: 0.9, y: anchor.placement === "above" ? 8 : -8 }} animate={{ opacity: 1, scale: 1, y: 0 }} transition={aceternityMotion.spring.panel} className="flex items-center gap-2">
|
||||
<span className="aceternity-floating-panel shrink-0 rounded-full border px-2.5 py-1.5 text-[var(--fs-tiny)] font-semibold tabular-nums backdrop-blur-2xl" style={{ background: theme.spatial.elevated, borderColor: theme.toolbar.border, color: theme.accent.primary }}>已选 {count}</span>
|
||||
<motion.div
|
||||
initial={reducedMotion ? { opacity: 0 } : { opacity: 0, scale: 0.9, y: anchor.placement === "above" ? 8 : -8 }}
|
||||
animate={{ opacity: 1, scale: 1, y: 0 }}
|
||||
transition={aceternityMotion.spring.panel}
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
<span
|
||||
className="aceternity-floating-panel shrink-0 rounded-full border px-2.5 py-1.5 text-[var(--fs-tiny)] font-semibold tabular-nums backdrop-blur-2xl"
|
||||
style={{ background: theme.spatial.elevated, borderColor: theme.toolbar.border, color: theme.accent.primary }}
|
||||
>
|
||||
已选 {count}
|
||||
</span>
|
||||
<div className="max-w-[min(560px,calc(100vw-90px))]">{children}</div>
|
||||
</motion.div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function CanvasNodePanelOverlay({ node, viewport, containerRef, panelWidth, panelHeight = 190, dragOffset, isDragging = false, allowOverflow = false, children }: { node: CanvasNodeData; viewport: ViewportTransform; containerRef: RefObject<HTMLDivElement | null>; panelWidth?: number; panelHeight?: number; dragOffset?: Position | null; isDragging?: boolean; allowOverflow?: boolean; children: ReactNode }) {
|
||||
export function CanvasNodePanelOverlay({
|
||||
node,
|
||||
viewport,
|
||||
containerRef,
|
||||
panelWidth,
|
||||
panelHeight = 190,
|
||||
dragOffset,
|
||||
isDragging = false,
|
||||
allowOverflow = false,
|
||||
children,
|
||||
}: {
|
||||
node: CanvasNodeData;
|
||||
viewport: ViewportTransform;
|
||||
containerRef: RefObject<HTMLDivElement | null>;
|
||||
panelWidth?: number;
|
||||
panelHeight?: number;
|
||||
dragOffset?: Position | null;
|
||||
isDragging?: boolean;
|
||||
allowOverflow?: boolean;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const panelRef = useRef<HTMLDivElement>(null);
|
||||
const { bringToFront, zIndex } = useCanvasOverlayLayer(`node-panel:${node.id}`, "var(--z-modal-overlay)");
|
||||
const initialWidth = resolveNodePanelWidth(node, viewport, panelWidth);
|
||||
@@ -109,9 +139,7 @@ export function CanvasNodePanelOverlay({ node, viewport, containerRef, panelWidt
|
||||
const nextWidth = resolveNodePanelWidth(node, nextViewport, panelWidth);
|
||||
panel.style.width = `${nextWidth}px`;
|
||||
const nodeElement = container.querySelector<HTMLElement>(`[data-node-id="${CSS.escape(node.id)}"]`);
|
||||
const position = nodeElement
|
||||
? getAttachedNodePanelPosition(nodeElement, container, nextWidth)
|
||||
: getNodePanelPosition(node, nextViewport, viewportSize, nextWidth, panelHeight, liveDragOffset);
|
||||
const position = nodeElement ? getAttachedNodePanelPosition(nodeElement, container, nextWidth) : getNodePanelPosition(node, nextViewport, viewportSize, nextWidth, panelHeight, liveDragOffset);
|
||||
panel.style.transform = `translate3d(${position.left}px, ${position.top}px, 0)`;
|
||||
};
|
||||
update(viewport);
|
||||
@@ -154,7 +182,31 @@ function resolveNodePanelWidth(node: CanvasNodeData, viewport: ViewportTransform
|
||||
return clamp(Math.round(node.width * viewport.k * 1.5), 680, 920);
|
||||
}
|
||||
|
||||
export function CanvasConnectionCreateMenu({ pending, viewport, viewportSize, containerRef, canCreateDrawing, getDisabledReason, onCreate, onClose }: { pending: PendingConnectionCreate; viewport: ViewportTransform; viewportSize: { width: number; height: number }; containerRef: RefObject<HTMLDivElement | null>; canCreateDrawing: boolean; getDisabledReason: (type: CanvasNodeType.Image | CanvasNodeType.Text | CanvasNodeType.Script | CanvasNodeType.BatchTable | CanvasNodeType.Video | CanvasNodeType.Audio | CanvasNodeType.Drawing | CanvasNodeType.Config | CanvasNodeType.MediaConversion, provider?: "runninghub") => string; onCreate: (type: CanvasNodeType.Image | CanvasNodeType.Text | CanvasNodeType.Script | CanvasNodeType.BatchTable | CanvasNodeType.Video | CanvasNodeType.Audio | CanvasNodeType.Drawing | CanvasNodeType.Config | CanvasNodeType.MediaConversion, provider?: "runninghub") => void; onClose: () => void }) {
|
||||
export function CanvasConnectionCreateMenu({
|
||||
pending,
|
||||
viewport,
|
||||
viewportSize,
|
||||
containerRef,
|
||||
canCreateDrawing,
|
||||
getDisabledReason,
|
||||
onCreate,
|
||||
onClose,
|
||||
}: {
|
||||
pending: PendingConnectionCreate;
|
||||
viewport: ViewportTransform;
|
||||
viewportSize: { width: number; height: number };
|
||||
containerRef: RefObject<HTMLDivElement | null>;
|
||||
canCreateDrawing: boolean;
|
||||
getDisabledReason: (
|
||||
type: CanvasNodeType.Image | CanvasNodeType.Text | CanvasNodeType.Script | CanvasNodeType.BatchTable | CanvasNodeType.Video | CanvasNodeType.Audio | CanvasNodeType.Drawing | CanvasNodeType.Config | CanvasNodeType.MediaConversion,
|
||||
provider?: "runninghub",
|
||||
) => string;
|
||||
onCreate: (
|
||||
type: CanvasNodeType.Image | CanvasNodeType.Text | CanvasNodeType.Script | CanvasNodeType.BatchTable | CanvasNodeType.Video | CanvasNodeType.Audio | CanvasNodeType.Drawing | CanvasNodeType.Config | CanvasNodeType.MediaConversion,
|
||||
provider?: "runninghub",
|
||||
) => void;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const theme = canvasThemes[useActiveTheme()];
|
||||
const reducedMotion = useReducedMotion();
|
||||
const menuRef = useRef<HTMLDivElement>(null);
|
||||
@@ -226,28 +278,137 @@ export function CanvasConnectionCreateMenu({ pending, viewport, viewportSize, co
|
||||
onPointerDown={(event) => event.stopPropagation()}
|
||||
>
|
||||
<div className="grid min-w-0 grid-cols-1 gap-1">
|
||||
<ConnectionCreateOption expanded={activeOption === "文本生成"} motionEnabled={!reducedMotion} icon={<List className="size-4" />} title="文本生成" description="引用当前内容,生成或改写文本" disabledReason={getDisabledReason(CanvasNodeType.Text)} onClick={() => onCreate(CanvasNodeType.Text)} />
|
||||
<ConnectionCreateOption expanded={activeOption === "分镜脚本"} motionEnabled={!reducedMotion} icon={<Clapperboard className="size-4" />} title="分镜脚本" description="根据剧情拆解镜头,编排分镜脚本" disabledReason={getDisabledReason(CanvasNodeType.Script)} onClick={() => onCreate(CanvasNodeType.Script)} />
|
||||
<ConnectionCreateOption expanded={activeOption === "批量创作表"} motionEnabled={!reducedMotion} icon={<Table2 className="size-4" />} title="批量创作表" description="汇总多张图片,批量执行换装或创意生图" disabledReason={getDisabledReason(CanvasNodeType.BatchTable)} onClick={() => onCreate(CanvasNodeType.BatchTable)} />
|
||||
<ConnectionCreateOption expanded={activeOption === "图片生成"} motionEnabled={!reducedMotion} icon={<ImageIcon className="size-4" />} title="图片生成" description="结合提示词和参考图,生成新的画面" disabledReason={getDisabledReason(CanvasNodeType.Image)} onClick={() => onCreate(CanvasNodeType.Image)} />
|
||||
<ConnectionCreateOption expanded={activeOption === "生成配置"} motionEnabled={!reducedMotion} icon={<WorkflowIcon className="size-4" />} title="生成配置" description="选择模型,或使用已启用的工作流插件" disabledReason={getDisabledReason(CanvasNodeType.Config)} onClick={() => onCreate(CanvasNodeType.Config)} />
|
||||
{canCreateDrawing ? <ConnectionCreateOption expanded={activeOption === "绘图"} motionEnabled={!reducedMotion} icon={<Pencil className="size-4" />} title="绘图" description="以参考图片为底图,自由绘制和标注" disabledReason={getDisabledReason(CanvasNodeType.Drawing)} onClick={() => onCreate(CanvasNodeType.Drawing)} /> : null}
|
||||
<ConnectionCreateOption expanded={activeOption === "视频生成"} motionEnabled={!reducedMotion} icon={<Video className="size-4" />} title="视频生成" description="结合提示词与参考素材,生成动态视频" disabledReason={getDisabledReason(CanvasNodeType.Video)} onClick={() => onCreate(CanvasNodeType.Video)} />
|
||||
<ConnectionCreateOption expanded={activeOption === "音频参考"} motionEnabled={!reducedMotion} icon={<Music2 className="size-4" />} title="音频参考" description="连接文本或角色卡,创建音频生成节点" disabledReason={getDisabledReason(CanvasNodeType.Audio)} onClick={() => onCreate(CanvasNodeType.Audio)} />
|
||||
<ConnectionCreateOption expanded={activeOption === "转换"} motionEnabled={!reducedMotion} icon={<WandSparkles className="size-4" />} title="转换" description="本地处理图片或视频" disabledReason={getDisabledReason(CanvasNodeType.MediaConversion)} onClick={() => onCreate(CanvasNodeType.MediaConversion)} />
|
||||
<ConnectionCreateOption
|
||||
expanded={activeOption === "文本生成"}
|
||||
motionEnabled={!reducedMotion}
|
||||
icon={<List className="size-4" />}
|
||||
title="文本生成"
|
||||
description="引用当前内容,生成或改写文本"
|
||||
disabledReason={getDisabledReason(CanvasNodeType.Text)}
|
||||
onClick={() => onCreate(CanvasNodeType.Text)}
|
||||
/>
|
||||
<ConnectionCreateOption
|
||||
expanded={activeOption === "分镜脚本"}
|
||||
motionEnabled={!reducedMotion}
|
||||
icon={<Clapperboard className="size-4" />}
|
||||
title="分镜脚本"
|
||||
description="根据剧情拆解镜头,编排分镜脚本"
|
||||
disabledReason={getDisabledReason(CanvasNodeType.Script)}
|
||||
onClick={() => onCreate(CanvasNodeType.Script)}
|
||||
/>
|
||||
<ConnectionCreateOption
|
||||
expanded={activeOption === "批量创作表"}
|
||||
motionEnabled={!reducedMotion}
|
||||
icon={<Table2 className="size-4" />}
|
||||
title="批量创作表"
|
||||
description="汇总多张图片,批量执行换装或创意生图"
|
||||
disabledReason={getDisabledReason(CanvasNodeType.BatchTable)}
|
||||
onClick={() => onCreate(CanvasNodeType.BatchTable)}
|
||||
/>
|
||||
<ConnectionCreateOption
|
||||
expanded={activeOption === "图片生成"}
|
||||
motionEnabled={!reducedMotion}
|
||||
icon={<ImageIcon className="size-4" />}
|
||||
title="图片生成"
|
||||
description="结合提示词和参考图,生成新的画面"
|
||||
disabledReason={getDisabledReason(CanvasNodeType.Image)}
|
||||
onClick={() => onCreate(CanvasNodeType.Image)}
|
||||
/>
|
||||
<ConnectionCreateOption
|
||||
expanded={activeOption === "生成配置"}
|
||||
motionEnabled={!reducedMotion}
|
||||
icon={<WorkflowIcon className="size-4" />}
|
||||
title="生成配置"
|
||||
description="选择模型,或使用已启用的工作流插件"
|
||||
disabledReason={getDisabledReason(CanvasNodeType.Config)}
|
||||
onClick={() => onCreate(CanvasNodeType.Config)}
|
||||
/>
|
||||
{canCreateDrawing ? (
|
||||
<ConnectionCreateOption
|
||||
expanded={activeOption === "绘图"}
|
||||
motionEnabled={!reducedMotion}
|
||||
icon={<Pencil className="size-4" />}
|
||||
title="绘图"
|
||||
description="以参考图片为底图,自由绘制和标注"
|
||||
disabledReason={getDisabledReason(CanvasNodeType.Drawing)}
|
||||
onClick={() => onCreate(CanvasNodeType.Drawing)}
|
||||
/>
|
||||
) : null}
|
||||
<ConnectionCreateOption
|
||||
expanded={activeOption === "视频生成"}
|
||||
motionEnabled={!reducedMotion}
|
||||
icon={<Video className="size-4" />}
|
||||
title="视频生成"
|
||||
description="结合提示词与参考素材,生成动态视频"
|
||||
disabledReason={getDisabledReason(CanvasNodeType.Video)}
|
||||
onClick={() => onCreate(CanvasNodeType.Video)}
|
||||
/>
|
||||
<ConnectionCreateOption
|
||||
expanded={activeOption === "音频参考"}
|
||||
motionEnabled={!reducedMotion}
|
||||
icon={<Music2 className="size-4" />}
|
||||
title="音频参考"
|
||||
description="连接文本或角色卡,创建音频生成节点"
|
||||
disabledReason={getDisabledReason(CanvasNodeType.Audio)}
|
||||
onClick={() => onCreate(CanvasNodeType.Audio)}
|
||||
/>
|
||||
<ConnectionCreateOption
|
||||
expanded={activeOption === "转换"}
|
||||
motionEnabled={!reducedMotion}
|
||||
icon={<WandSparkles className="size-4" />}
|
||||
title="转换"
|
||||
description="本地处理图片或视频"
|
||||
disabledReason={getDisabledReason(CanvasNodeType.MediaConversion)}
|
||||
onClick={() => onCreate(CanvasNodeType.MediaConversion)}
|
||||
/>
|
||||
</div>
|
||||
</motion.div>
|
||||
);
|
||||
}
|
||||
|
||||
function ConnectionCreateOption({ expanded, motionEnabled, icon, title, description, disabledReason, onClick }: { expanded: boolean; motionEnabled: boolean; icon: ReactNode; title: string; description: string; disabledReason?: string; onClick: () => void }) {
|
||||
function ConnectionCreateOption({
|
||||
expanded,
|
||||
motionEnabled,
|
||||
icon,
|
||||
title,
|
||||
description,
|
||||
disabledReason,
|
||||
onClick,
|
||||
}: {
|
||||
expanded: boolean;
|
||||
motionEnabled: boolean;
|
||||
icon: ReactNode;
|
||||
title: string;
|
||||
description: string;
|
||||
disabledReason?: string;
|
||||
onClick: () => void;
|
||||
}) {
|
||||
const theme = canvasThemes[useActiveTheme()];
|
||||
return (
|
||||
<button type="button" aria-disabled={Boolean(disabledReason)} aria-label={title} aria-description={disabledReason || description} data-create-option={title} data-expanded={expanded} data-motion={motionEnabled ? "enabled" : "reduced"} className="canvas-connection-create-option group flex min-h-10 w-full cursor-pointer items-start gap-2 rounded-[var(--dock-item-radius)] px-2 py-1.5 text-left outline-none focus-visible:ring-2 aria-disabled:cursor-not-allowed aria-disabled:opacity-40" style={{ color: theme.node.text, "--tw-ring-color": theme.node.muted, background: expanded ? theme.toolbar.itemHover : undefined } as CSSProperties} onClick={() => { if (!disabledReason) onClick(); }}>
|
||||
<span className="grid size-7 shrink-0 place-items-center rounded-[var(--r-md)] opacity-65 transition-opacity group-hover:opacity-100 [&_svg]:size-3.5" style={{ background: theme.toolbar.itemHover }}>{icon}</span>
|
||||
<button
|
||||
type="button"
|
||||
aria-disabled={Boolean(disabledReason)}
|
||||
aria-label={title}
|
||||
aria-description={disabledReason || description}
|
||||
data-create-option={title}
|
||||
data-expanded={expanded}
|
||||
data-motion={motionEnabled ? "enabled" : "reduced"}
|
||||
className="canvas-connection-create-option group flex min-h-10 w-full cursor-pointer items-start gap-2 rounded-[var(--dock-item-radius)] px-2 py-1.5 text-left outline-none focus-visible:ring-2 aria-disabled:cursor-not-allowed aria-disabled:opacity-40"
|
||||
style={{ color: theme.node.text, "--tw-ring-color": theme.node.muted, background: expanded ? theme.toolbar.itemHover : undefined } as CSSProperties}
|
||||
onClick={() => {
|
||||
if (!disabledReason) onClick();
|
||||
}}
|
||||
>
|
||||
<span className="grid size-7 shrink-0 place-items-center rounded-[var(--r-md)] opacity-65 transition-opacity group-hover:opacity-100 [&_svg]:size-3.5" style={{ background: theme.toolbar.itemHover }}>
|
||||
{icon}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1 pt-1.5">
|
||||
<span className="flex items-center gap-2 text-[var(--fs-tiny)] font-semibold leading-4">{title}</span>
|
||||
<span aria-hidden="true" className="canvas-connection-create-description" style={{ color: theme.node.muted }}><span className="min-h-0 overflow-hidden"><span className="block pt-1 whitespace-normal break-words text-[var(--fs-micro)] leading-relaxed">{disabledReason || description}</span></span></span>
|
||||
<span aria-hidden="true" className="canvas-connection-create-description" style={{ color: theme.node.muted }}>
|
||||
<span className="min-h-0 overflow-hidden">
|
||||
<span className="block pt-1 whitespace-normal break-words text-[var(--fs-micro)] leading-relaxed">{disabledReason || description}</span>
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user