Files
deerflow-code/frontend-web/src/report-collaboration/components/ReportCollaborationLayout.tsx
T
董宏凯andCursor f109a95535 feat: 新增报告协作页,并强化 Deep Research 运行诊断与报告兜底
支持浏览器侧素材快照撰写、拒绝报告读时修复、Mermaid PNG 导出与 Word 导出加固。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-03 11:16:50 +08:00

167 lines
5.1 KiB
TypeScript
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.
"use client";
import { useCallback, useRef } from "react";
import { MessageSquare, Workflow } from "lucide-react";
import {
CANVAS_MIN_WIDTH,
PANEL_MIN_WIDTH,
RESIZE_KEYBOARD_STEP,
type FocusMode,
type NarrowView,
type UseReportPanelLayoutResult,
} from "@/report-collaboration/hooks/useReportPanelLayout";
interface ReportCollaborationLayoutProps {
layout: UseReportPanelLayoutResult;
header: React.ReactNode;
conversation: React.ReactNode;
canvas: React.ReactNode;
statusBar: React.ReactNode;
}
/**
* 固定两栏骨架:左对话 / 右画布 + 可拖拽分隔条(pointer + 方向键 + Home/End)
* + 窄屏单面板切换 + 「专注」模式。节点抽屉与预览 Dialog 由画布侧覆盖渲染。
*/
export function ReportCollaborationLayout({
layout,
header,
conversation,
canvas,
statusBar,
}: ReportCollaborationLayoutProps) {
const { conversationWidth, setConversationWidth, nudgeConversationWidth, isNarrow, narrowView, setNarrowView, focusMode, bodyRef } =
layout;
const dragStart = useRef<{ x: number; width: number } | null>(null);
const onPointerDown = useCallback(
(event: React.PointerEvent<HTMLDivElement>) => {
event.currentTarget.setPointerCapture(event.pointerId);
dragStart.current = { x: event.clientX, width: conversationWidth };
},
[conversationWidth],
);
const onPointerMove = useCallback(
(event: React.PointerEvent<HTMLDivElement>) => {
if (!dragStart.current || event.buttons !== 1) return;
setConversationWidth(dragStart.current.width + (event.clientX - dragStart.current.x));
},
[setConversationWidth],
);
const onPointerUp = useCallback((event: React.PointerEvent<HTMLDivElement>) => {
if (event.currentTarget.hasPointerCapture(event.pointerId)) {
event.currentTarget.releasePointerCapture(event.pointerId);
}
dragStart.current = null;
}, []);
const onKeyDown = useCallback(
(event: React.KeyboardEvent<HTMLDivElement>) => {
const max = Math.max(
PANEL_MIN_WIDTH,
Math.min(720, (bodyRef.current?.clientWidth ?? 720) - CANVAS_MIN_WIDTH),
);
if (event.key === "ArrowLeft") {
event.preventDefault();
nudgeConversationWidth(-RESIZE_KEYBOARD_STEP);
} else if (event.key === "ArrowRight") {
event.preventDefault();
nudgeConversationWidth(RESIZE_KEYBOARD_STEP);
} else if (event.key === "Home") {
event.preventDefault();
setConversationWidth(PANEL_MIN_WIDTH);
} else if (event.key === "End") {
event.preventDefault();
setConversationWidth(max);
}
},
[bodyRef, nudgeConversationWidth, setConversationWidth],
);
const showConversation = isNarrow ? narrowView === "conversation" : focusMode !== "canvas";
const showCanvas = isNarrow ? narrowView === "canvas" : focusMode !== "conversation";
return (
<div className="rc-root">
{header}
<div className="rc-body" ref={bodyRef}>
{showConversation ? (
<section
className="rc-conversation-panel"
style={{ width: isNarrow ? "100%" : conversationWidth, flexShrink: isNarrow ? 1 : 0 }}
aria-label="对话面板"
>
{conversation}
</section>
) : null}
{!isNarrow && showConversation && showCanvas ? (
<div
role="separator"
aria-orientation="vertical"
aria-label="调整对话与画布宽度"
aria-valuenow={conversationWidth}
aria-valuemin={PANEL_MIN_WIDTH}
aria-valuemax={720}
tabIndex={0}
className="rc-resizer"
onPointerDown={onPointerDown}
onPointerMove={onPointerMove}
onPointerUp={onPointerUp}
onKeyDown={onKeyDown}
/>
) : null}
{showCanvas ? (
<section className="rc-canvas-panel" aria-label="协作流程画布">
{isNarrow ? (
<div className="absolute left-2 top-2 z-10">
<NarrowSwitch narrowView={narrowView} setNarrowView={setNarrowView} />
</div>
) : null}
{canvas}
</section>
) : null}
</div>
{statusBar}
</div>
);
}
export function NarrowSwitch({
narrowView,
setNarrowView,
}: {
narrowView: NarrowView;
setNarrowView: (view: NarrowView) => void;
}) {
return (
<div className="rc-narrow-switch" role="tablist" aria-label="视图切换">
<button
type="button"
role="tab"
aria-selected={narrowView === "conversation"}
data-active={narrowView === "conversation"}
onClick={() => setNarrowView("conversation")}
>
<MessageSquare className="mr-1 inline size-3" aria-hidden />
对话
</button>
<button
type="button"
role="tab"
aria-selected={narrowView === "canvas"}
data-active={narrowView === "canvas"}
onClick={() => setNarrowView("canvas")}
>
<Workflow className="mr-1 inline size-3" aria-hidden />
流程
</button>
</div>
);
}
export type { FocusMode };