mirror of
https://github.com/hanzoai/ui.git
synced 2026-11-21 00:18:41 +00:00
build-v2's editor (MIT, from OSW Studio and DeepSite; attribution in NOTICE) as presentation with the data and the transport handed back to the host: Workspace and its bar (Views, ProjectChip, PageSelect), PreviewFrame, FileTree, FileTabs, Console, ModeSelect, Suggestions, Attachments and Feedback, with tree, log and bridge as their pure halves. The preview frames an http(s) address in a sandbox that never allows top navigation and grants its own origin only to a foreign page; the element bridge is opt-in, origin-pinned on both sides. Every file, path, log line and picked element renders as text. CodeEditor gains an accessible label, and the axe helper stops at frames, which are another document. Co-authored-by: Hanzo Dev <[email protected]>
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
import { useState } from 'react'
|
|
import { YStack } from '@hanzo/gui'
|
|
import { FileTabs, type OpenFile } from '@hanzo/ui/agents'
|
|
|
|
/** Editing — open files as tabs over the editor; an edit marks its tab until the host saves it. */
|
|
export function Editing() {
|
|
const [files, setFiles] = useState<OpenFile[]>([
|
|
{ path: 'src/app.tsx', content: 'export function App() {\n return <h1>MEGA Shop</h1>\n}\n' },
|
|
{ path: 'README.md', content: '# MEGA Shop\n' },
|
|
{ path: 'public/hero.png', error: 'A binary file — open it from the preview.' },
|
|
])
|
|
const [shown, setShown] = useState<string | null>('src/app.tsx')
|
|
return (
|
|
<YStack width="100%" maxW={640} height={280} borderWidth={1} borderColor="$borderColor" rounded="$4" overflow="hidden">
|
|
<FileTabs
|
|
files={files}
|
|
value={shown}
|
|
onSelect={setShown}
|
|
onClose={(path) => setFiles((all) => all.filter((f) => f.path !== path))}
|
|
onChange={(path, content) =>
|
|
setFiles((all) => all.map((f) => (f.path === path ? { ...f, content, dirty: true } : f)))
|
|
}
|
|
/>
|
|
</YStack>
|
|
)
|
|
}
|
|
|
|
/** Read-only — no `onChange`, so the field shows the file and takes no edits. */
|
|
export function ReadOnly() {
|
|
return (
|
|
<YStack width="100%" maxW={640} height={200} borderWidth={1} borderColor="$borderColor" rounded="$4" overflow="hidden">
|
|
<FileTabs files={[{ path: 'go.mod', content: 'module widgets\n' }]} value="go.mod" onSelect={() => {}} />
|
|
</YStack>
|
|
)
|
|
}
|