import { useCallback, useRef } from 'react'; import { ResizablePanel, ResizablePanelGroup, ResizableHandle } from '../ui/resizable'; import type { LayoutNode, AppRegistry, PanelComponents } from './types'; import { countPanels } from './layout-utils'; import { PanelSlot } from './PanelSlot'; type WorkspaceRendererProps = { layout: LayoutNode; registry: AppRegistry; components?: PanelComponents; interactive?: boolean; onSetApp: (panelId: string, appType: string | null) => void; onSplit: (panelId: string, direction: 'horizontal' | 'vertical') => void; onRemove: (panelId: string) => void; onResized: (groupId: string, sizes: number[]) => void; }; export const WorkspaceRenderer = ({ layout, registry, components, interactive = false, onSetApp, onSplit, onRemove, onResized, }: WorkspaceRendererProps) => { const totalPanels = countPanels(layout); return (
); }; type LayoutNodeRendererProps = { node: LayoutNode; registry: AppRegistry; components?: PanelComponents; interactive: boolean; totalPanels: number; onSetApp: (panelId: string, appType: string | null) => void; onSplit: (panelId: string, direction: 'horizontal' | 'vertical') => void; onRemove: (panelId: string) => void; onResized: (groupId: string, sizes: number[]) => void; }; const getFixedHeight = (node: LayoutNode, registry: AppRegistry): number | undefined => { if (node.type === 'panel' && node.appType) return registry[node.appType]?.fixedHeight; return undefined; }; const LayoutNodeRenderer = ({ node, registry, components, interactive, totalPanels, onSetApp, onSplit, onRemove, onResized, }: LayoutNodeRendererProps) => { const debounceRef = useRef>(null); const mountedRef = useRef(false); const handleLayout = useCallback( (sizes: number[]) => { if (node.type !== 'group') return; if (!mountedRef.current) { mountedRef.current = true; return; } if (debounceRef.current) clearTimeout(debounceRef.current); debounceRef.current = setTimeout(() => { onResized(node.id, sizes); }, 500); }, [node, onResized], ); if (node.type === 'panel') { return ( ); } const hasFixedChild = node.direction === 'vertical' && node.children.some((c) => getFixedHeight(c.node, registry) !== undefined); if (hasFixedChild) { return (
{node.children.map((child) => { const fixed = getFixedHeight(child.node, registry); return (
); })}
); } return ( {node.children.map((child, i) => (
))}
); }; type ChildEntryProps = { index: number; total: number; children: React.ReactNode; }; const ChildEntry = ({ index, total, children }: ChildEntryProps) => { if (index === 0) return <>{children}; return ( <> {children} ); };