* feat(canvas): 面板层级管理优化 - 五层Elevation+渐进式三区+进度增强 #98 #94 基于 Wayfinder 地图 #98 决议执行面板层级管理优化: 1. 五层 Elevation 体系(决策1) - 画布组件 z-index 硬编码值全部迁移到 token - L0 画布层 → L1 工具层 → L2 面板层 → L3 对话框层 → L4 通知层 - 涉及 14 个 .tsx 文件,0 处 z-[N] 硬编码残留 2. prompt 面板渐进式三区(决策2) - B区参数区改为手风琴折叠模式(默认折叠) - 新增 SlidersHorizontal + ChevronDown 图标切换 - 点击展开 video 工具参数,收起后释放视觉空间 - A区核心区(prompt+生成)始终展开 3. 任务进度条增强(决策3) - 进度条高度 1px→1.5px,视觉更醒目 - 新增 shimmer 扫描动画(running 态,1.4s/cycle) - 新增百分比数字显示(tabular-nums 等宽数字) - 新增 indeterminate 模式(无百分比时循环扫描) - 尊重 prefers-reduced-motion(reducedMotion 时禁用动画) 4. CSS 动画 - 新增 @keyframes canvas-task-progress-shimmer - .canvas-task-progress-shimmer 类 Closes #98 * refactor(canvas): z-index 全量迁移到五层Elevation token #98 #94 补全 #98 五层 Elevation 体系的剩余硬编码 z-index 清理: - 三个设置弹层(图/音/视频)zIndex:1200 → var(--z-popover) - model-setup-guide z-[900] → var(--z-toast) - 项目侧栏 z-30 → var(--z-panel),章节预览 z-50 → var(--z-panel-floating) - shared 页头/缩放控件/访客提示 z-[80]/z-[70] → var(--z-panel-floating),右键菜单 z-[90] → var(--z-modal) - project 缩放控件容器 z-50 → var(--z-panel),绘图加载遮罩 z-[500] → var(--z-toast) - 反馈面板 z-[90] → var(--z-panel-floating) 共 16 处全局浮层 z-index 迁移到 token,消除层级冲突隐患。 --------- Co-authored-by: sikongyue <3155157671@qq.com>
129 lines
6.1 KiB
TypeScript
129 lines
6.1 KiB
TypeScript
import { useEffect, useRef, useState, type RefObject } from "react";
|
|
import { createPortal } from "react-dom";
|
|
import { Settings2 } from "lucide-react";
|
|
import { Button } from "antd";
|
|
|
|
import { ImageSettingsPanel, imageQualityLabel, imageSizeLabel } from "@/components/image-settings-panel";
|
|
import { canvasThemes } from "@/lib/canvas-theme";
|
|
import { useThemeStore } from "@/stores/use-theme-store";
|
|
import type { AiConfig } from "@/stores/use-config-store";
|
|
|
|
type CanvasImageSettingsPopoverProps = {
|
|
config: AiConfig;
|
|
onConfigChange: (key: keyof AiConfig, value: string) => void;
|
|
onMissingConfig?: () => void;
|
|
onOpenChange?: (open: boolean) => void;
|
|
buttonClassName?: string;
|
|
getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
|
|
placement?: "topLeft" | "top" | "topRight" | "bottomLeft" | "bottom" | "bottomRight";
|
|
autoAdjustOverflow?: boolean;
|
|
showCount?: boolean;
|
|
};
|
|
|
|
export function CanvasImageSettingsPopover({ config, onConfigChange, onOpenChange, buttonClassName, placement = "topLeft", showCount = true }: CanvasImageSettingsPopoverProps) {
|
|
const theme = canvasThemes[useThemeStore((state) => state.theme)];
|
|
const buttonRef = useRef<HTMLSpanElement>(null);
|
|
const panelRef = useRef<HTMLDivElement>(null);
|
|
const [open, setOpen] = useState(false);
|
|
const [buttonRect, setButtonRect] = useState<DOMRect | null>(null);
|
|
const quality = config.quality || "auto";
|
|
const count = Math.max(1, Math.min(15, Math.floor(Math.abs(Number(config.count)) || 1)));
|
|
const activeSize = config.size || "auto";
|
|
const transparentLabel = config.transparentBackground === "true" ? " · 透明" : "";
|
|
const summary = showCount ? `${imageQualityLabel(quality)} · ${imageSizeLabel(activeSize)} · ${count} 张${transparentLabel}` : `${imageQualityLabel(quality)} · ${imageSizeLabel(activeSize)}${transparentLabel}`;
|
|
const updateOpen = (nextOpen: boolean) => {
|
|
setOpen(nextOpen);
|
|
onOpenChange?.(nextOpen);
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (!open) return;
|
|
const syncPosition = () => setButtonRect(buttonRef.current?.getBoundingClientRect() || null);
|
|
const closeOnOutsidePointer = (event: PointerEvent) => {
|
|
const target = event.target;
|
|
if (!(target instanceof Node)) return;
|
|
if (buttonRef.current?.contains(target) || panelRef.current?.contains(target)) return;
|
|
if (document.activeElement instanceof HTMLElement && panelRef.current?.contains(document.activeElement)) document.activeElement.blur();
|
|
setOpen(false);
|
|
onOpenChange?.(false);
|
|
};
|
|
|
|
syncPosition();
|
|
window.addEventListener("resize", syncPosition);
|
|
window.addEventListener("scroll", syncPosition, true);
|
|
window.addEventListener("pointerdown", closeOnOutsidePointer, true);
|
|
return () => {
|
|
window.removeEventListener("resize", syncPosition);
|
|
window.removeEventListener("scroll", syncPosition, true);
|
|
window.removeEventListener("pointerdown", closeOnOutsidePointer, true);
|
|
};
|
|
}, [onOpenChange, open]);
|
|
|
|
const panel = open && buttonRect ? <ImageSettingsPortal buttonRect={buttonRect} panelRef={panelRef} placement={placement} theme={theme} config={config} showCount={showCount} onConfigChange={onConfigChange} /> : null;
|
|
|
|
return (
|
|
<>
|
|
<span ref={buttonRef} className="inline-flex min-w-0">
|
|
<Button size="small" type="text" className={`canvas-generation-settings-trigger ${buttonClassName || "!h-8 !max-w-[180px] !justify-start !rounded-full !px-2.5"}`} style={{ background: theme.node.fill, color: theme.node.text }} icon={<Settings2 className="size-3.5" />} aria-expanded={open} aria-label={`图像设置:${summary}`} title={`图像设置 · ${summary}`} onClick={() => updateOpen(!open)}>
|
|
<span className="truncate">{summary}</span>
|
|
</Button>
|
|
</span>
|
|
{panel}
|
|
</>
|
|
);
|
|
}
|
|
|
|
function ImageSettingsPortal({
|
|
buttonRect,
|
|
panelRef,
|
|
placement,
|
|
theme,
|
|
config,
|
|
showCount,
|
|
onConfigChange,
|
|
}: {
|
|
buttonRect: DOMRect;
|
|
panelRef: RefObject<HTMLDivElement | null>;
|
|
placement: CanvasImageSettingsPopoverProps["placement"];
|
|
theme: (typeof canvasThemes)[keyof typeof canvasThemes];
|
|
config: AiConfig;
|
|
showCount: boolean;
|
|
onConfigChange: (key: keyof AiConfig, value: string) => void;
|
|
}) {
|
|
const gap = 8;
|
|
const margin = 12;
|
|
const width = Math.min(420, window.innerWidth - margin * 2);
|
|
const alignRight = placement?.endsWith("Right");
|
|
const alignCenter = placement === "top" || placement === "bottom";
|
|
const left = alignCenter ? buttonRect.left + buttonRect.width / 2 - width / 2 : alignRight ? buttonRect.right - width : buttonRect.left;
|
|
const topPlacement = placement?.startsWith("top");
|
|
const style = {
|
|
position: "fixed",
|
|
zIndex: "var(--z-popover)",
|
|
width,
|
|
left: Math.max(margin, Math.min(window.innerWidth - width - margin, left)),
|
|
...(topPlacement ? { bottom: window.innerHeight - buttonRect.top + gap, maxHeight: Math.max(260, buttonRect.top - margin * 2) } : { top: buttonRect.bottom + gap, maxHeight: Math.max(260, window.innerHeight - buttonRect.bottom - margin * 2) }),
|
|
background: theme.canvas.background,
|
|
border: `1px solid ${theme.toolbar.border}`,
|
|
borderRadius: 10,
|
|
boxShadow: `0 24px 72px ${theme.spatial.shadow}`,
|
|
padding: 12,
|
|
overflowY: "auto",
|
|
color: theme.node.text,
|
|
} as const;
|
|
|
|
return createPortal(
|
|
<div
|
|
ref={panelRef}
|
|
className="canvas-image-settings-popover aceternity-floating-panel backdrop-blur-2xl"
|
|
style={style}
|
|
onPointerDown={(event) => event.stopPropagation()}
|
|
onMouseDown={(event) => event.stopPropagation()}
|
|
onClick={(event) => event.stopPropagation()}
|
|
>
|
|
<ImageSettingsPanel config={config} onConfigChange={(key, value) => onConfigChange(key, value)} theme={theme} showCount={showCount} quickCount={3} className="space-y-3" />
|
|
</div>,
|
|
document.body,
|
|
);
|
|
}
|