Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

FileMarkdownPreview.tsx

34 lines1010 Bytes

1import type { ScopedThreadRef } from "@t3tools/contracts";
2​
3import ChatMarkdown from "~/components/ChatMarkdown";
4import { resolvePathLinkTarget } from "@t3tools/shared/fileLinks";
5​
6export function FileMarkdownPreview(props: {
7 readonly cwd: string;
8 readonly relativePath: string;
9 readonly text: string;
10 readonly threadRef: ScopedThreadRef;
11 readonly onTaskListChange?:
12 | ((input: { readonly markerOffset: number; readonly checked: boolean }) => void)
13 | undefined;
14}) {
15 const lastSeparator = Math.max(
16 props.relativePath.lastIndexOf("/"),
17 props.relativePath.lastIndexOf("\\"),
18 );
19 const imageBaseDir =
20 lastSeparator >= 0
21 ? resolvePathLinkTarget(props.relativePath.slice(0, lastSeparator), props.cwd)
22 : props.cwd;
23​
24 return (
25 <ChatMarkdown
26 text={props.text}
27 cwd={props.cwd}
28 imageBaseDir={imageBaseDir}
29 threadRef={props.threadRef}
30 className="mx-auto max-w-4xl px-6 py-5"
31 onTaskListChange={props.onTaskListChange}
32 />
33 );