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

FileMarkdownPreview.tsx

37 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 onTaskListChange?:
14 | ((input: { readonly markerOffset: number; readonly checked: boolean }) => void)
15 | undefined;
16}) {
17 const lastSeparator = Math.max(
18 props.relativePath.lastIndexOf("/"),
19 props.relativePath.lastIndexOf("\\"),
20 );
21 const imageBaseDir =
22 lastSeparator >= 0
23 ? resolvePathLinkTarget(props.relativePath.slice(0, lastSeparator), props.cwd)
24 : props.cwd;
25​
26 return (
27 <ChatMarkdown
28 text={maskMarkdownFrontmatter(props.text)}
29 cwd={props.cwd}
30 imageBaseDir={imageBaseDir}
31 threadRef={props.threadRef}
32 workspaceMutationId={props.workspaceMutationId}
33 className="mx-auto max-w-4xl px-6 py-5"
34 onTaskListChange={props.onTaskListChange}
35 />
36 );