MCPcopy
hub / github.com/intentui/intentui / EditorText

Function EditorText

src/components/code/editor-text.tsx:23–140  ·  view source on GitHub ↗
({ source }: Props)

Source from the content-addressed store, hash-verified

21const registry = generated as Record<string, RegistryItem>
22
23export function EditorText({ source }: Props) {
24 const [copiedStates, setCopiedStates] = useState<Record<string, boolean>>({})
25 const { copy } = useClipboard()
26
27 const [rawSourceCode, setRawSourceCode] = useState<Record<string, string | null>>({})
28
29 const handleCopy = async (key: string, value: string | null) => {
30 if (value) {
31 const didCopy = await copy(value)
32 if (!didCopy) return
33 setCopiedStates((prev) => ({ ...prev, [key]: true }))
34 setTimeout(() => {
35 setCopiedStates((prev) => ({ ...prev, [key]: false }))
36 }, 2000)
37 }
38 }
39
40 useEffect(() => {
41 const fetchRegistryData = async () => {
42 const fetchedSourceCode: Record<string, string | null> = {}
43 await Promise.all(
44 Object.entries(source)
45 .filter(([key]) => key !== 'preview')
46
47 .map(async ([key, path]) => {
48 const registryKey = `${path}`
49 const registryItem = registry[registryKey]
50
51 if (registryItem) {
52 try {
53 const response = await fetch(`/registry/${registryKey}.json`)
54 if (response.ok) {
55 const registryEntry = await response.json()
56 fetchedSourceCode[key] =
57 registryEntry.files?.[0]?.content || 'No content available'
58 } else {
59 console.error(`Failed to fetch source code for ${path}:`, response.status)
60 fetchedSourceCode[key] = 'Error loading source code.'
61 }
62 } catch (error) {
63 console.error(`Error fetching source code for ${path}:`, error)
64 fetchedSourceCode[key] = 'Error loading source code.'
65 }
66 } else {
67 console.error(`Registry item for ${registryKey} not found.`)
68 fetchedSourceCode[key] = 'Registry item not found.'
69 }
70 })
71 )
72 setRawSourceCode(fetchedSourceCode)
73 }
74
75 fetchRegistryData()
76 }, [source])
77
78 return (
79 <>
80 {rawSourceCode && Object.keys(rawSourceCode).length > 0 ? (

Callers

nothing calls this directly

Calls 3

useClipboardFunction · 0.90
fetchRegistryDataFunction · 0.85
handleCopyFunction · 0.70

Tested by

no test coverage detected