35 lines
1001 B
TypeScript
35 lines
1001 B
TypeScript
import type { ScopedThreadRef } from "@t3tools/contracts";
|
|
|
|
import ChatMarkdown from "~/components/ChatMarkdown";
|
|
import { resolvePathLinkTarget } from "~/terminal-links";
|
|
|
|
export function FileMarkdownPreview(props: {
|
|
readonly cwd: string;
|
|
readonly relativePath: string;
|
|
readonly text: string;
|
|
readonly threadRef: ScopedThreadRef;
|
|
readonly onTaskListChange?:
|
|
| ((input: { readonly markerOffset: number; readonly checked: boolean }) => void)
|
|
| undefined;
|
|
}) {
|
|
const lastSeparator = Math.max(
|
|
props.relativePath.lastIndexOf("/"),
|
|
props.relativePath.lastIndexOf("\\"),
|
|
);
|
|
const imageBaseDir =
|
|
lastSeparator >= 0
|
|
? resolvePathLinkTarget(props.relativePath.slice(0, lastSeparator), props.cwd)
|
|
: props.cwd;
|
|
|
|
return (
|
|
<ChatMarkdown
|
|
text={props.text}
|
|
cwd={props.cwd}
|
|
imageBaseDir={imageBaseDir}
|
|
threadRef={props.threadRef}
|
|
className="mx-auto max-w-4xl px-6 py-5"
|
|
onTaskListChange={props.onTaskListChange}
|
|
/>
|
|
);
|
|
}
|