docs/en/references/components/image-preview.md
Image Preview Components are a set of specialized components in Cherry Studio for rendering and displaying various diagram and image formats. They provide a consistent user experience across different preview types with shared functionality for loading states, error handling, and interactive controls.
graph TD
A[MermaidPreview] --> D[ImagePreviewLayout]
B[PlantUmlPreview] --> D
C[SvgPreview] --> D
E[GraphvizPreview] --> D
D --> F[ImageToolbar]
D --> G[useDebouncedRender]
F --> H[Pan Controls]
F --> I[Zoom Controls]
F --> J[Reset Function]
F --> K[Dialog Control]
G --> L[Debounced Rendering]
G --> M[Error Handling]
G --> N[Loading State]
G --> O[Dependency Management]
A common layout wrapper that provides the foundation for all image preview components.
Features:
Props:
children: The preview content to be displayedloading: Boolean indicating if content is being renderederror: Error message to display if rendering failsenableToolbar: Whether to show the interactive toolbarimageRef: Reference to the container element for image manipulationInteractive toolbar component providing image manipulation controls.
Features:
Layout:
A specialized React hook for managing preview rendering with performance optimizations.
Features:
API:
const { containerRef, error, isLoading, triggerRender, cancelRender, clearError, setLoading } = useDebouncedRender(
value,
renderFunction,
options
)
Options:
debounceDelay: Customize debounce timingshouldRender: Function for conditional rendering logicRenders Mermaid diagrams with special handling for visibility detection.
Special Features:
Renders PlantUML diagrams using the online PlantUML server.
Special Features:
Renders SVG content using Shadow DOM for isolation.
Special Features:
Renders Graphviz/DOT diagrams using the viz.js library.
Special Features:
All preview components provide consistent error handling:
Standardized loading indicators across all components:
Common interaction patterns:
Image Preview Components integrate seamlessly with CodeBlockView:
For more information about the overall CodeBlockView architecture, see CodeBlockView Documentation.