mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-05-21 21:20:19 +09:00
fix: typescript error
This commit is contained in:
parent
b0e9a542ba
commit
4b9697e336
@ -23,17 +23,19 @@ import { Path, ApiPath, REPO_URL } from "@/app/constant";
|
|||||||
import { Loading } from "./home";
|
import { Loading } from "./home";
|
||||||
import styles from "./artifacts.module.scss";
|
import styles from "./artifacts.module.scss";
|
||||||
|
|
||||||
export const HTMLPreview = forwardRef<
|
type HTMLPreviewProps = {
|
||||||
{
|
|
||||||
reload: () => void;
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: string;
|
code: string;
|
||||||
autoHeight?: boolean;
|
autoHeight?: boolean;
|
||||||
height?: number | string;
|
height?: number | string;
|
||||||
onLoad?: (title?: string) => void;
|
onLoad?: (title?: string) => void;
|
||||||
}
|
};
|
||||||
>(function HTMLPreview(props, ref) {
|
|
||||||
|
export type HTMLPreviewHander = {
|
||||||
|
reload: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const HTMLPreview = forwardRef<HTMLPreviewHander, HTMLPreviewProps>(
|
||||||
|
function HTMLPreview(props, ref) {
|
||||||
const iframeRef = useRef<HTMLIFrameElement>(null);
|
const iframeRef = useRef<HTMLIFrameElement>(null);
|
||||||
const [frameId, setFrameId] = useState<string>(nanoid());
|
const [frameId, setFrameId] = useState<string>(nanoid());
|
||||||
const [iframeHeight, setIframeHeight] = useState(600);
|
const [iframeHeight, setIframeHeight] = useState(600);
|
||||||
@ -72,7 +74,9 @@ export const HTMLPreview = forwardRef<
|
|||||||
return props.height;
|
return props.height;
|
||||||
}
|
}
|
||||||
const parentHeight = props.height || 600;
|
const parentHeight = props.height || 600;
|
||||||
return iframeHeight + 40 > parentHeight ? parentHeight : iframeHeight + 40;
|
return iframeHeight + 40 > parentHeight
|
||||||
|
? parentHeight
|
||||||
|
: iframeHeight + 40;
|
||||||
}, [props.autoHeight, props.height, iframeHeight]);
|
}, [props.autoHeight, props.height, iframeHeight]);
|
||||||
|
|
||||||
const srcDoc = useMemo(() => {
|
const srcDoc = useMemo(() => {
|
||||||
@ -100,7 +104,8 @@ export const HTMLPreview = forwardRef<
|
|||||||
onLoad={handleOnLoad}
|
onLoad={handleOnLoad}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
export function ArtifactsShareButton({
|
export function ArtifactsShareButton({
|
||||||
getCode,
|
getCode,
|
||||||
@ -203,7 +208,7 @@ export function Artifacts() {
|
|||||||
const [code, setCode] = useState("");
|
const [code, setCode] = useState("");
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [fileName, setFileName] = useState("");
|
const [fileName, setFileName] = useState("");
|
||||||
const previewRef = useRef<typeof HTMLPreview>(null);
|
const previewRef = useRef<HTMLPreviewHander>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (id) {
|
if (id) {
|
||||||
|
@ -14,7 +14,11 @@ import ReloadButtonIcon from "../icons/reload.svg";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { useDebouncedCallback } from "use-debounce";
|
import { useDebouncedCallback } from "use-debounce";
|
||||||
import { showImageModal, FullScreen } from "./ui-lib";
|
import { showImageModal, FullScreen } from "./ui-lib";
|
||||||
import { ArtifactsShareButton, HTMLPreview } from "./artifacts";
|
import {
|
||||||
|
ArtifactsShareButton,
|
||||||
|
HTMLPreview,
|
||||||
|
HTMLPreviewHander,
|
||||||
|
} from "./artifacts";
|
||||||
import { Plugin } from "../constant";
|
import { Plugin } from "../constant";
|
||||||
import { useChatStore } from "../store";
|
import { useChatStore } from "../store";
|
||||||
import { IconButton } from "./button";
|
import { IconButton } from "./button";
|
||||||
@ -67,7 +71,7 @@ export function Mermaid(props: { code: string }) {
|
|||||||
|
|
||||||
export function PreCode(props: { children: any }) {
|
export function PreCode(props: { children: any }) {
|
||||||
const ref = useRef<HTMLPreElement>(null);
|
const ref = useRef<HTMLPreElement>(null);
|
||||||
const previewRef = useRef<typeof HTMLPreview>(null);
|
const previewRef = useRef<HTMLPreviewHander>(null);
|
||||||
const [mermaidCode, setMermaidCode] = useState("");
|
const [mermaidCode, setMermaidCode] = useState("");
|
||||||
const [htmlCode, setHtmlCode] = useState("");
|
const [htmlCode, setHtmlCode] = useState("");
|
||||||
const { height } = useWindowSize();
|
const { height } = useWindowSize();
|
||||||
|
Loading…
Reference in New Issue
Block a user