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

FileMarkdownPreview.tsx

38 lines1.2 KB

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