import { useRef, useState, type ReactNode } from 'react'; import { Columns2, Maximize2 } from 'lucide-react'; import { Button } from '@/components/ui/button'; import './desktop-workspace.css'; const preferenceKey = 'makelore.cloud-agent-editor-ratio'; export function DesktopSplit({ configuration, preview }: { configuration: ReactNode; preview: (action: ReactNode) => ReactNode }) { const root = useRef(null); const [ratio, setRatio] = useState(() => { try { const saved = Number(localStorage.getItem(preferenceKey)); return saved >= 25 && saved <= 75 ? saved : 46; } catch { return 46; } }); const [focus, setFocus] = useState<'configuration' | 'preview' | null>(null); const [compactPanel, setCompactPanel] = useState<'configuration' | 'preview'>('configuration'); const resize = (next: number) => { const width = (root.current?.clientWidth ?? 0) - 8; if (width < 720) return; const clamped = Math.max(25, 340 / width * 100, Math.min(75, 100 - 380 / width * 100, next)); setRatio(clamped); try { localStorage.setItem(preferenceKey, String(clamped)); } catch { /* Layout remains usable without persistence. */ } }; const panelToggle = (panel: 'configuration' | 'preview') => ; return
{ if (e.key === 'Escape') setFocus(null); if (e.key === 'F6' && root.current) { const panels = [...root.current.querySelectorAll('.agent-config-pane, .agent-preview-pane')].filter(panel => panel.offsetParent !== null); const current = panels.findIndex(panel => panel.contains(document.activeElement)); const next = panels[(current + 1) % panels.length]; const target = [...(next?.querySelectorAll('textarea:not(:disabled), input:not(:disabled), button:not(:disabled)') ?? [])].find(el => el.offsetParent !== null); if (target) { e.preventDefault(); target.focus(); } } }}>
配置智能体{panelToggle('configuration')}
{configuration}
resize(46)} onPointerDown={e => { e.preventDefault(); e.currentTarget.focus(); e.currentTarget.setPointerCapture(e.pointerId); }} onPointerMove={e => { if (e.currentTarget.hasPointerCapture(e.pointerId) && root.current) resize((e.clientX - root.current.getBoundingClientRect().left) / (root.current.clientWidth - 8) * 100); }} onPointerUp={e => e.currentTarget.releasePointerCapture(e.pointerId)} onKeyDown={e => { if (['ArrowLeft', 'ArrowRight', 'Home'].includes(e.key)) { e.preventDefault(); resize(e.key === 'Home' ? 46 : ratio + (e.key === 'ArrowLeft' ? -2 : 2)); } }} />
{preview(panelToggle('preview'))}
; }