import React, { ErrorInfo } from 'react'; import { Button, Heading, Paragraph, Image, Container, Section, Row, Column, Divider, Spacer, } from '../components/base'; interface ComponentConfig { id?: string; type: string; properties?: Record; children?: ComponentConfig[]; } interface ComponentRendererProps { config: ComponentConfig; } interface ErrorBoundaryState { hasError: boolean; error?: Error; } class ComponentErrorBoundary extends React.Component< { children: React.ReactNode }, ErrorBoundaryState > { constructor(props: { children: React.ReactNode }) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error('Component render error:', error, errorInfo); } render() { if (this.state.hasError) { return (

Error rendering component

{process.env.NODE_ENV === 'development' && this.state.error && (
{this.state.error.message}
)}
); } return this.props.children; } } const componentMap: Record> = { Button, Heading, Paragraph, Image, Container, Section, Row, Column, Divider, Spacer, }; export const ComponentRenderer: React.FC = ({ config, }) => { if (!config || !config.type) { return (
Invalid component config
); } const Component = componentMap[config.type]; if (!Component) { return (
Unknown component: {config.type}
); } const props = config.properties || {}; const children = config.children?.map((child, index) => ( )); return ( {children} ); };