补齐会话重命名/删除与会话菜单能力,新增聊天参数透传与本地开关持久化,并统一输入区、消息区、代码块和弹框等关键交互样式。 Made-with: Cursor
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import { useState } from "react";
|
||||
import { CheckOutlined, CopyOutlined } from "@ant-design/icons";
|
||||
import { Button, message } from "antd";
|
||||
import ReactMarkdown from "react-markdown";
|
||||
import remarkGfm from "remark-gfm";
|
||||
import remarkMath from "remark-math";
|
||||
@@ -5,19 +8,68 @@ import rehypeKatex from "rehype-katex";
|
||||
import rehypeHighlight from "rehype-highlight";
|
||||
import "katex/dist/katex.min.css";
|
||||
import "highlight.js/styles/github.css";
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
type StreamMessageProps = {
|
||||
content: string;
|
||||
};
|
||||
|
||||
function extractText(node: ReactNode): string {
|
||||
if (typeof node === "string") return node;
|
||||
if (typeof node === "number") return String(node);
|
||||
if (!node) return "";
|
||||
if (Array.isArray(node)) return node.map((item) => extractText(item)).join("");
|
||||
if (typeof node === "object" && "props" in node) {
|
||||
const child = (node as { props?: { children?: ReactNode } }).props?.children;
|
||||
return extractText(child);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function MarkdownPreBlock(props: { children: ReactNode }) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
const codeText = extractText(props.children).replace(/\n$/, "");
|
||||
|
||||
const onCopy = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(codeText);
|
||||
setCopied(true);
|
||||
message.success("代码已复制");
|
||||
window.setTimeout(() => setCopied(false), 1200);
|
||||
} catch {
|
||||
message.error("复制失败");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="my-2 overflow-hidden rounded-xl bg-neutral-50">
|
||||
<div className="flex items-center justify-end px-2 py-1">
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
icon={copied ? <CheckOutlined /> : <CopyOutlined />}
|
||||
className="text-neutral-600 hover:bg-black/5! hover:text-neutral-800!"
|
||||
onClick={() => {
|
||||
void onCopy();
|
||||
}}
|
||||
>
|
||||
{copied ? "已复制" : "复制"}
|
||||
</Button>
|
||||
</div>
|
||||
<pre className="m-0 overflow-x-auto p-3 text-[13px] text-neutral-800">{props.children}</pre>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function StreamMessage(props: StreamMessageProps) {
|
||||
return (
|
||||
<div className="rounded-2xl border border-[var(--ds-border)] bg-neutral-50/80 px-4 py-2.5 text-[15px] leading-relaxed text-neutral-800">
|
||||
<div className="prose prose-sm max-w-none break-words prose-neutral prose-pre:my-2 prose-pre:rounded-lg prose-pre:border prose-pre:border-[var(--ds-border)] prose-pre:bg-neutral-950 prose-pre:p-3 prose-code:before:content-none prose-code:after:content-none">
|
||||
<div className="rounded-2xl px-4 py-2.5 text-[15px] leading-relaxed text-neutral-800">
|
||||
<div className="prose prose-sm max-w-none break-words prose-neutral prose-code:before:content-none prose-code:after:content-none">
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm, remarkMath]}
|
||||
rehypePlugins={[rehypeKatex, rehypeHighlight]}
|
||||
components={{
|
||||
pre: ({ children }) => <MarkdownPreBlock>{children}</MarkdownPreBlock>,
|
||||
table: ({ children }) => (
|
||||
<div className="my-2 overflow-x-auto rounded-lg border border-[var(--ds-border)]">
|
||||
<table className="w-full border-collapse text-sm">{children}</table>
|
||||
|
||||
Reference in New Issue
Block a user