51 |
52 |
58 |
59 | {onToggle && (
60 |
74 | )}
75 |
91 |
107 |
108 |
109 | {!isCollapsed && (
110 |
111 |
119 | )}
120 |
121 | );
122 | }
--------------------------------------------------------------------------------
/components/mermaid-definition-card.tsx:
--------------------------------------------------------------------------------
1 | "use client";
2 |
3 | import { useEffect, useState } from "react";
4 | import { Button } from "@/components/ui/button";
5 | import { Textarea } from "@/components/ui/textarea";
6 | import {ClipboardCopy, ClipboardCheck, RefreshCcw, ChevronsDown, ChevronsUp, Copy} from "lucide-react";
7 | import {copyToClipboard} from "@/components/plantuml-definition-card";
8 | import { cn } from "@/lib/utils";
9 |
10 | interface MermaidDefinitionCardProps {
11 | definition: string;
12 | onDefinitionChange?: (definition: string) => void;
13 | onReset?: () => void;
14 | isCollapsed?: boolean;
15 | onToggle?: () => void;
16 | }
17 |
18 | export function MermaidDefinitionCard({
19 | definition,
20 | onDefinitionChange,
21 | onReset,
22 | isCollapsed,
23 | onToggle,
24 | }: MermaidDefinitionCardProps) {
25 | const [copied, setCopied] = useState(false);
26 | const [isResetting, setIsResetting] = useState(false);
27 |
28 | useEffect(() => {
29 | if (!copied) return;
30 | const timer = setTimeout(() => setCopied(false), 1500);
31 | return () => clearTimeout(timer);
32 | }, [copied]);
33 |
34 | const handleCopy = async () => {
35 | if (!definition) return;
36 | await copyToClipboard(definition);
37 | setCopied(true);
38 | };
39 |
40 | const handleReset = () => {
41 | if (onReset) {
42 | setIsResetting(true);
43 | onReset();
44 | // 添加一个短暂的延迟来显示重置动画效果
45 | setTimeout(() => setIsResetting(false), 300);
46 | }
47 | };
48 |
49 | return (
50 |
51 |
52 |
58 |
59 | {onToggle && (
60 |
74 | )}
75 | {onReset && (
76 |
92 | )}
93 |
109 |
110 |
111 | {!isCollapsed && (
112 |
113 |
122 | )}
123 |
124 | );
125 | }
--------------------------------------------------------------------------------
/components/kroki-definition-card.tsx:
--------------------------------------------------------------------------------
1 | "use client";
2 |
3 | import { useEffect, useState } from "react";
4 | import { Button } from "@/components/ui/button";
5 | import { Textarea } from "@/components/ui/textarea";
6 | import {ClipboardCopy, ClipboardCheck, RefreshCcw, ChevronsDown, ChevronsUp, Copy} from "lucide-react";
7 | import { copyToClipboard } from "@/components/plantuml-definition-card";
8 | import { cn } from "@/lib/utils";
9 |
10 | interface KrokiDefinitionCardProps {
11 | definition: string;
12 | onDefinitionChange?: (definition: string) => void;
13 | onReset?: () => void;
14 | isCollapsed?: boolean;
15 | onToggle?: () => void;
16 | }
17 |
18 | export function KrokiDefinitionCard({
19 | definition,
20 | onDefinitionChange,
21 | onReset,
22 | isCollapsed,
23 | onToggle,
24 | }: KrokiDefinitionCardProps) {
25 | const [copied, setCopied] = useState(false);
26 | const [isResetting, setIsResetting] = useState(false);
27 |
28 | useEffect(() => {
29 | if (!copied) return;
30 | const timer = setTimeout(() => setCopied(false), 1500);
31 | return () => clearTimeout(timer);
32 | }, [copied]);
33 |
34 | const handleCopy = async () => {
35 | if (!definition) return;
36 | await copyToClipboard(definition);
37 | setCopied(true);
38 | };
39 |
40 | const handleReset = () => {
41 | if (onReset) {
42 | setIsResetting(true);
43 | onReset();
44 | // 添加一个短暂的延迟来显示重置动画效果
45 | setTimeout(() => setIsResetting(false), 300);
46 | }
47 | };
48 |
49 | return (
50 |
51 |
52 |
58 |
59 | {onToggle && (
60 |
74 | )}
75 | {onReset && (
76 |
92 | )}
93 |
109 |
110 |
111 | {!isCollapsed && (
112 |
113 |
122 | )}
123 |
124 | );
125 | }
--------------------------------------------------------------------------------
/contexts/diagram-context.tsx:
--------------------------------------------------------------------------------
1 | "use client";
2 |
3 | import React, { createContext, useContext, useRef, useState } from "react";
4 | import type { DrawIoEmbedRef } from "react-drawio";
5 | import { extractDiagramXML } from "../lib/utils";
6 |
7 | interface DiagramContextType {
8 | chartXML: string;
9 | latestSvg: string;
10 | diagramHistory: { svg: string; xml: string }[];
11 | loadDiagram: (chart: string) => void;
12 | handleExport: (purpose?: 'chat' | 'file') => void;
13 | resolverRef: React.Ref<((value: string) => void) | null>;
14 | drawioRef: React.Ref