The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import { Platform } from "react-native"; |
| 2 | import { useState } from "react"; |
| 3 | import { useGT } from "gt-react-native"; |
| 4 | import type { AssistantCitation } from "@t3tools/contracts"; |
| 5 | import { parseAssistantCitationHref } from "@t3tools/shared/assistantCitations"; |
| 6 | import { AssistantCitationSheet } from "../components/AssistantCitationSheet"; |
| 7 | import { copyTextWithHaptic } from "../lib/copyTextWithHaptic"; |
| 8 | import type { SelectableMarkdownTextProps } from "./SelectableMarkdownText.types"; |
| 9 | |
| 10 | import { MobileEnrichedMarkdownText } from "./EnrichedMarkdownText"; |
| 11 | import { themeColorWithAlpha } from "../lib/mobileTheme"; |
| 12 | import { useUniwindTheme } from "../lib/useUniwindTheme"; |
| 13 | |
| 14 | export type { |
| 15 | MarkdownFileContextMenu, |
| 16 | MarkdownFileContextMenuAction, |
| 17 | MarkdownImageRenderer, |
| 18 | MarkdownImageRequest, |
| 19 | MarkdownImageSourceResolver, |
| 20 | MarkdownLinkCustomization, |
| 21 | NativeMarkdownTextStyle, |
| 22 | SelectableMarkdownSkill, |
| 23 | } from "./SelectableMarkdownText.types"; |
| 24 | |
| 25 | export function SelectableMarkdownText(props: SelectableMarkdownTextProps) { |
| 26 | const [citation, setCitation] = useState<AssistantCitation | null>(null); |
| 27 | const gt = useGT(); |
| 28 | const hasCitations = props.markdown.includes("t3-citation:"); |
| 29 | const theme = useUniwindTheme(); |
| 30 | const selectionColor = themeColorWithAlpha(theme["--color-focus"], 0.32); |
| 31 | const selectionHandleColor = theme["--color-focus"]; |
| 32 | const textStyle = |
| 33 | Platform.OS === "android" |
| 34 | ? { selectionColor, selectionHandleColor, ...props.textStyle } |
| 35 | : props.textStyle; |
| 36 | return ( |
| 37 | <> |
| 38 | <MobileEnrichedMarkdownText |
| 39 | {...props} |
| 40 | textStyle={textStyle} |
| 41 | onLinkPress={ |
| 42 | hasCitations |
| 43 | ? (href) => { |
| 44 | const quote = parseAssistantCitationHref(href); |
| 45 | if (quote) setCitation(quote); |
| 46 | else props.onLinkPress?.(href); |
| 47 | } |
| 48 | : props.onLinkPress |
| 49 | } |
| 50 | fileContextMenu={ |
| 51 | hasCitations |
| 52 | ? (href) => |
| 53 | parseAssistantCitationHref(href) |
| 54 | ? { |
| 55 | title: gt("Assistant quote"), |
| 56 | actions: [ |
| 57 | { id: "open-quote", title: gt("Open quote") }, |
| 58 | { id: "copy-quote", title: gt("Copy quote") }, |
| 59 | ], |
| 60 | } |
| 61 | : props.fileContextMenu?.(href) |
| 62 | : props.fileContextMenu |
| 63 | } |
| 64 | onFileContextMenuAction={ |
| 65 | hasCitations |
| 66 | ? (href, actionId) => { |
| 67 | const quote = parseAssistantCitationHref(href); |
| 68 | if (quote) { |
| 69 | if (actionId === "open-quote") setCitation(quote); |
| 70 | else if (actionId === "copy-quote") copyTextWithHaptic(quote.text); |
| 71 | } else props.onFileContextMenuAction?.(href, actionId); |
| 72 | } |
| 73 | : props.onFileContextMenuAction |
| 74 | } |
| 75 | /> |
| 76 | {citation ? ( |
| 77 | <AssistantCitationSheet citation={citation} onClose={() => setCitation(null)} /> |
| 78 | ) : null} |
| 79 | </> |
| 80 | ); |
| 81 | } |