2026-08-06 21:19:34 +00:00
|
|
|
|
import React, { useMemo } from 'react'
|
2026-02-24 20:44:16 +00:00
|
|
|
|
import DynamicRenderer from './DynamicRenderer'
|
|
|
|
|
|
import { useComponents } from '@/contexts/ComponentContext'
|
2026-08-06 21:19:34 +00:00
|
|
|
|
import { parseComponentDependencies } from '@/contexts/componentRuntime'
|
2026-02-24 20:44:16 +00:00
|
|
|
|
import { Loading } from '../shared'
|
|
|
|
|
|
|
|
|
|
|
|
export interface ComponentPreviewProps {
|
|
|
|
|
|
componentName?: string
|
|
|
|
|
|
className?: string
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const ComponentPreview: React.FC<ComponentPreviewProps> = ({ componentName, className = '' }) => {
|
|
|
|
|
|
const { components, loading } = useComponents()
|
|
|
|
|
|
|
2026-08-06 21:19:34 +00:00
|
|
|
|
// Referans olarak sabit tutulmalı: DynamicRenderer bunu effect bağımlılığı olarak kullanıyor.
|
|
|
|
|
|
const dependencies = useMemo(() => {
|
|
|
|
|
|
const component = components?.find((item) => item.name === componentName && item.isActive)
|
|
|
|
|
|
return parseComponentDependencies(component?.dependencies)
|
|
|
|
|
|
}, [components, componentName])
|
|
|
|
|
|
|
2026-02-24 20:44:16 +00:00
|
|
|
|
if (!componentName) {
|
2026-05-19 20:22:25 +00:00
|
|
|
|
return <div className="text-sm text-gray-500 dark:text-gray-400">Bileşen ismi yok.</div>
|
2026-02-24 20:44:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-06 21:19:34 +00:00
|
|
|
|
if (loading || !Array.isArray(components)) {
|
2026-02-24 20:44:16 +00:00
|
|
|
|
return (
|
2026-05-19 20:22:25 +00:00
|
|
|
|
<div className="flex items-center justify-center min-h-screen bg-gray-50 dark:bg-gray-900">
|
2026-02-24 20:44:16 +00:00
|
|
|
|
<div className="text-center">
|
|
|
|
|
|
<Loading loading={true} />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
2026-05-19 20:22:25 +00:00
|
|
|
|
<div className={`bg-white dark:bg-gray-900 ${className}`}>
|
2026-02-24 20:44:16 +00:00
|
|
|
|
<DynamicRenderer componentName={componentName} dependencies={dependencies} />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default ComponentPreview
|