mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 08:13:43 +08:00 
			
		
		
		
	feat: improve svg viewer
This commit is contained in:
		@@ -2,7 +2,15 @@
 | 
				
			|||||||
import { ChatMessage, useAppConfig, useChatStore } from "../store";
 | 
					import { ChatMessage, useAppConfig, useChatStore } from "../store";
 | 
				
			||||||
import Locale from "../locales";
 | 
					import Locale from "../locales";
 | 
				
			||||||
import styles from "./exporter.module.scss";
 | 
					import styles from "./exporter.module.scss";
 | 
				
			||||||
import { List, ListItem, Modal, Select, showModal, showToast } from "./ui-lib";
 | 
					import {
 | 
				
			||||||
 | 
					  List,
 | 
				
			||||||
 | 
					  ListItem,
 | 
				
			||||||
 | 
					  Modal,
 | 
				
			||||||
 | 
					  Select,
 | 
				
			||||||
 | 
					  showImageModal,
 | 
				
			||||||
 | 
					  showModal,
 | 
				
			||||||
 | 
					  showToast,
 | 
				
			||||||
 | 
					} from "./ui-lib";
 | 
				
			||||||
import { IconButton } from "./button";
 | 
					import { IconButton } from "./button";
 | 
				
			||||||
import { copyToClipboard, downloadAs, useMobileScreen } from "../utils";
 | 
					import { copyToClipboard, downloadAs, useMobileScreen } from "../utils";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -359,24 +367,6 @@ function ExportAvatar(props: { avatar: string }) {
 | 
				
			|||||||
  return <Avatar avatar={props.avatar}></Avatar>;
 | 
					  return <Avatar avatar={props.avatar}></Avatar>;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function showImageModal(img: string) {
 | 
					 | 
				
			||||||
  showModal({
 | 
					 | 
				
			||||||
    title: Locale.Export.Image.Modal,
 | 
					 | 
				
			||||||
    children: (
 | 
					 | 
				
			||||||
      <div>
 | 
					 | 
				
			||||||
        <img
 | 
					 | 
				
			||||||
          src={img}
 | 
					 | 
				
			||||||
          alt="preview"
 | 
					 | 
				
			||||||
          style={{
 | 
					 | 
				
			||||||
            maxWidth: "100%",
 | 
					 | 
				
			||||||
          }}
 | 
					 | 
				
			||||||
        ></img>
 | 
					 | 
				
			||||||
      </div>
 | 
					 | 
				
			||||||
    ),
 | 
					 | 
				
			||||||
    defaultMax: true,
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export function ImagePreviewer(props: {
 | 
					export function ImagePreviewer(props: {
 | 
				
			||||||
  messages: ChatMessage[];
 | 
					  messages: ChatMessage[];
 | 
				
			||||||
  topic: string;
 | 
					  topic: string;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,6 +12,7 @@ import mermaid from "mermaid";
 | 
				
			|||||||
import LoadingIcon from "../icons/three-dots.svg";
 | 
					import LoadingIcon from "../icons/three-dots.svg";
 | 
				
			||||||
import React from "react";
 | 
					import React from "react";
 | 
				
			||||||
import { useDebouncedCallback, useThrottledCallback } from "use-debounce";
 | 
					import { useDebouncedCallback, useThrottledCallback } from "use-debounce";
 | 
				
			||||||
 | 
					import { showImageModal } from "./ui-lib";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function Mermaid(props: { code: string }) {
 | 
					export function Mermaid(props: { code: string }) {
 | 
				
			||||||
  const ref = useRef<HTMLDivElement>(null);
 | 
					  const ref = useRef<HTMLDivElement>(null);
 | 
				
			||||||
@@ -37,11 +38,13 @@ export function Mermaid(props: { code: string }) {
 | 
				
			|||||||
    if (!svg) return;
 | 
					    if (!svg) return;
 | 
				
			||||||
    const text = new XMLSerializer().serializeToString(svg);
 | 
					    const text = new XMLSerializer().serializeToString(svg);
 | 
				
			||||||
    const blob = new Blob([text], { type: "image/svg+xml" });
 | 
					    const blob = new Blob([text], { type: "image/svg+xml" });
 | 
				
			||||||
    const url = URL.createObjectURL(blob);
 | 
					    console.log(blob);
 | 
				
			||||||
    const win = window.open(url);
 | 
					    // const url = URL.createObjectURL(blob);
 | 
				
			||||||
    if (win) {
 | 
					    // const win = window.open(url);
 | 
				
			||||||
      win.onload = () => URL.revokeObjectURL(url);
 | 
					    // if (win) {
 | 
				
			||||||
    }
 | 
					    //   win.onload = () => URL.revokeObjectURL(url);
 | 
				
			||||||
 | 
					    // }
 | 
				
			||||||
 | 
					    showImageModal(URL.createObjectURL(blob));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (hasError) {
 | 
					  if (hasError) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					/* eslint-disable @next/next/no-img-element */
 | 
				
			||||||
import styles from "./ui-lib.module.scss";
 | 
					import styles from "./ui-lib.module.scss";
 | 
				
			||||||
import LoadingIcon from "../icons/three-dots.svg";
 | 
					import LoadingIcon from "../icons/three-dots.svg";
 | 
				
			||||||
import CloseIcon from "../icons/close.svg";
 | 
					import CloseIcon from "../icons/close.svg";
 | 
				
			||||||
@@ -414,3 +415,20 @@ export function showPrompt(content: any, value = "", rows = 3) {
 | 
				
			|||||||
    );
 | 
					    );
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function showImageModal(img: string) {
 | 
				
			||||||
 | 
					  showModal({
 | 
				
			||||||
 | 
					    title: Locale.Export.Image.Modal,
 | 
				
			||||||
 | 
					    children: (
 | 
				
			||||||
 | 
					      <div>
 | 
				
			||||||
 | 
					        <img
 | 
				
			||||||
 | 
					          src={img}
 | 
				
			||||||
 | 
					          alt="preview"
 | 
				
			||||||
 | 
					          style={{
 | 
				
			||||||
 | 
					            maxWidth: "100%",
 | 
				
			||||||
 | 
					          }}
 | 
				
			||||||
 | 
					        ></img>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    ),
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user