mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
chore: update Docker config, dev-proxy, and HTML preview components
This commit is contained in:
1 parent
9afd5f04d5
commit
088b1d7b18
9 files changed
+53
-87
No files matched your search
@@ -154,27 +154,27 @@ export const FileBrowser = forwardRef<FileBrowserHandle, FileBrowserProps>(funct
|
||||
const uploadCancelledRef = useRef(false)
|
||||
const isMobile = useMobile()
|
||||
|
||||
const openMobilePreview = useCallback((file: FileInfo) => {
|
||||
if (isHtmlFileInfo(file)) {
|
||||
setHtmlArtifact(createHtmlArtifact({ source: 'file', path: file.path, title: file.name }))
|
||||
setIsPreviewModalOpen(false)
|
||||
} else {
|
||||
setHtmlArtifact(null)
|
||||
setIsPreviewModalOpen(true)
|
||||
}
|
||||
onPreviewStateChange?.(true)
|
||||
}, [onPreviewStateChange])
|
||||
|
||||
const { data: initialFileData, error: initialFileError } = useFile(initialSelectedFile)
|
||||
|
||||
useEffect(() => {
|
||||
if (initialFileData) {
|
||||
setSelectedFile(initialFileData)
|
||||
if (isMobile) {
|
||||
if (isHtmlFileInfo(initialFileData)) {
|
||||
setHtmlArtifact(createHtmlArtifact({
|
||||
source: 'file',
|
||||
path: initialFileData.path,
|
||||
title: initialFileData.name,
|
||||
}))
|
||||
setIsPreviewModalOpen(false)
|
||||
} else {
|
||||
setHtmlArtifact(null)
|
||||
setIsPreviewModalOpen(true)
|
||||
}
|
||||
onPreviewStateChange?.(true)
|
||||
openMobilePreview(initialFileData)
|
||||
}
|
||||
}
|
||||
}, [initialFileData, isMobile, onPreviewStateChange])
|
||||
}, [initialFileData, isMobile, openMobilePreview])
|
||||
|
||||
useEffect(() => {
|
||||
if (initialFileError) {
|
||||
@@ -280,18 +280,7 @@ useEffect(() => {
|
||||
|
||||
// On mobile, open preview in modal
|
||||
if (isMobile) {
|
||||
if (isHtmlFileInfo(fullFileData)) {
|
||||
setHtmlArtifact(createHtmlArtifact({
|
||||
source: 'file',
|
||||
path: fullFileData.path,
|
||||
title: fullFileData.name,
|
||||
}))
|
||||
setIsPreviewModalOpen(false)
|
||||
} else {
|
||||
setHtmlArtifact(null)
|
||||
setIsPreviewModalOpen(true)
|
||||
}
|
||||
onPreviewStateChange?.(true)
|
||||
openMobilePreview(fullFileData)
|
||||
}
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to load file')
|
||||
@@ -299,23 +288,15 @@ useEffect(() => {
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [onFileSelect, isMobile, onPreviewStateChange])
|
||||
}, [onFileSelect, isMobile, openMobilePreview])
|
||||
|
||||
const handleCloseModal = useCallback(() => {
|
||||
const handleClosePreview = useCallback(() => {
|
||||
setIsPreviewModalOpen(false)
|
||||
setHtmlArtifact(null)
|
||||
setSelectedFile(null)
|
||||
onPreviewStateChange?.(false)
|
||||
}, [onPreviewStateChange])
|
||||
|
||||
const handleCloseHtmlArtifact = useCallback(() => {
|
||||
setHtmlArtifact(null)
|
||||
setSelectedFile(null)
|
||||
onPreviewStateChange?.(false)
|
||||
}, [onPreviewStateChange])
|
||||
|
||||
const handleToggleHtmlArtifactFullscreen = useCallback(() => {}, [])
|
||||
|
||||
const handleDirectoryClick = (path: string) => {
|
||||
loadFiles(path)
|
||||
}
|
||||
@@ -513,13 +494,13 @@ useEffect(() => {
|
||||
|
||||
const handleEscape = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') {
|
||||
handleCloseModal()
|
||||
handleClosePreview()
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', handleEscape)
|
||||
return () => document.removeEventListener('keydown', handleEscape)
|
||||
}, [isPreviewModalOpen, handleCloseModal])
|
||||
}, [isPreviewModalOpen, handleClosePreview])
|
||||
|
||||
const showNavigateUp = allowNavigateAboveBase && normalizePath(currentPath) !== '..'
|
||||
? true
|
||||
@@ -592,6 +573,15 @@ useEffect(() => {
|
||||
</Dialog>
|
||||
)
|
||||
|
||||
const htmlArtifactPanel = isMobile && htmlArtifact && (
|
||||
<HtmlArtifactPanel
|
||||
artifact={htmlArtifact}
|
||||
isFullscreen={true}
|
||||
isMobile={true}
|
||||
onClose={handleClosePreview}
|
||||
/>
|
||||
)
|
||||
|
||||
if (embedded) {
|
||||
return (
|
||||
<div
|
||||
@@ -678,20 +668,12 @@ useEffect(() => {
|
||||
{/* Mobile: File Preview Modal */}
|
||||
<MobileFilePreviewModal
|
||||
isOpen={isMobile && isPreviewModalOpen}
|
||||
onClose={handleCloseModal}
|
||||
onClose={handleClosePreview}
|
||||
file={selectedFile}
|
||||
showFilePreviewHeader={true}
|
||||
/>
|
||||
|
||||
{isMobile && htmlArtifact && (
|
||||
<HtmlArtifactPanel
|
||||
artifact={htmlArtifact}
|
||||
isFullscreen={true}
|
||||
isMobile={true}
|
||||
onClose={handleCloseHtmlArtifact}
|
||||
onToggleFullscreen={handleToggleHtmlArtifactFullscreen}
|
||||
/>
|
||||
)}
|
||||
{htmlArtifactPanel}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -790,19 +772,11 @@ useEffect(() => {
|
||||
{/* Mobile: File Preview Modal */}
|
||||
<MobileFilePreviewModal
|
||||
isOpen={isMobile && isPreviewModalOpen}
|
||||
onClose={handleCloseModal}
|
||||
onClose={handleClosePreview}
|
||||
file={selectedFile}
|
||||
/>
|
||||
|
||||
{isMobile && htmlArtifact && (
|
||||
<HtmlArtifactPanel
|
||||
artifact={htmlArtifact}
|
||||
isFullscreen={true}
|
||||
isMobile={true}
|
||||
onClose={handleCloseHtmlArtifact}
|
||||
onToggleFullscreen={handleToggleHtmlArtifactFullscreen}
|
||||
/>
|
||||
)}
|
||||
{htmlArtifactPanel}
|
||||
|
||||
{uploadDialog}
|
||||
</div>
|
||||
|
||||
@@ -14,7 +14,7 @@ interface HtmlArtifactPanelProps {
|
||||
isFullscreen: boolean
|
||||
isMobile: boolean
|
||||
onClose: () => void
|
||||
onToggleFullscreen: () => void
|
||||
onToggleFullscreen?: () => void
|
||||
}
|
||||
|
||||
export function HtmlArtifactPanel({
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useMemo } from 'react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { normalizeHtmlPreviewDocument } from '@/lib/htmlArtifacts'
|
||||
|
||||
@@ -11,7 +12,7 @@ interface HtmlPreviewFrameProps {
|
||||
|
||||
export function HtmlPreviewFrame({ title, src, srcDoc, className, sandbox }: HtmlPreviewFrameProps) {
|
||||
const resolvedSandbox = sandbox ?? (src ? 'allow-scripts allow-same-origin' : 'allow-scripts')
|
||||
const normalizedSrcDoc = srcDoc ? normalizeHtmlPreviewDocument(srcDoc) : undefined
|
||||
const normalizedSrcDoc = useMemo(() => (srcDoc ? normalizeHtmlPreviewDocument(srcDoc) : undefined), [srcDoc])
|
||||
return (
|
||||
<iframe
|
||||
title={title}
|
||||
|
||||
@@ -171,7 +171,9 @@ function CodeBlock({ children, className, onHtmlArtifactOpen, ...props }: CodeBl
|
||||
const codeContent = rawCodeContent.trim()
|
||||
|
||||
const childArray = React.Children.toArray(children)
|
||||
const codeElement = childArray.find((child): child is React.ReactElement => React.isValidElement(child))
|
||||
const codeElement = childArray.find(
|
||||
(child): child is React.ReactElement<{ className?: string }> => React.isValidElement(child)
|
||||
)
|
||||
const codeClassName = codeElement?.props?.className
|
||||
const isHtmlCode = typeof codeClassName === 'string' && (codeClassName.includes('language-html') || codeClassName.includes('language-htm'))
|
||||
|
||||
|
||||
Reference in new issue
Block a user