|
| 1 | +/** |
| 2 | + * UI components for the Monaco editor |
| 3 | + */ |
| 4 | +import React from "react"; |
| 5 | +import { useTheme } from "@/lib/theme/ThemeProvider"; |
| 6 | + |
| 7 | +/** |
| 8 | + * Loading placeholder for the Monaco editor |
| 9 | + */ |
| 10 | +export function EditorLoadingPlaceholder() { |
| 11 | + const { getColor } = useTheme(); |
| 12 | + |
| 13 | + return ( |
| 14 | + <div |
| 15 | + style={{ |
| 16 | + backgroundColor: getColor("surface"), |
| 17 | + display: "flex", |
| 18 | + justifyContent: "center", |
| 19 | + alignItems: "center", |
| 20 | + height: "100%", |
| 21 | + width: "100%", |
| 22 | + }} |
| 23 | + > |
| 24 | + <div className="animate-pulse flex flex-col items-center"> |
| 25 | + <svg |
| 26 | + width="40" |
| 27 | + height="40" |
| 28 | + viewBox="0 0 24 24" |
| 29 | + fill="none" |
| 30 | + stroke={getColor("textTertiary")} |
| 31 | + strokeWidth="2" |
| 32 | + strokeLinecap="round" |
| 33 | + strokeLinejoin="round" |
| 34 | + > |
| 35 | + <polyline points="16 18 22 12 16 6"></polyline> |
| 36 | + <polyline points="8 6 2 12 8 18"></polyline> |
| 37 | + </svg> |
| 38 | + <span style={{ color: getColor("textSecondary"), marginTop: "8px" }}> |
| 39 | + Loading editor... |
| 40 | + </span> |
| 41 | + </div> |
| 42 | + </div> |
| 43 | + ); |
| 44 | +} |
| 45 | + |
| 46 | +/** |
| 47 | + * Editor container component with styling |
| 48 | + */ |
| 49 | +export function EditorContainer({ |
| 50 | + children, |
| 51 | + height = "400px", |
| 52 | +}: { |
| 53 | + children: React.ReactNode; |
| 54 | + height?: string; |
| 55 | +}) { |
| 56 | + const { getColor } = useTheme(); |
| 57 | + |
| 58 | + const containerStyle = { |
| 59 | + border: `1px solid ${getColor("border")}`, |
| 60 | + borderRadius: "0.375rem", |
| 61 | + overflow: "hidden", |
| 62 | + height, |
| 63 | + }; |
| 64 | + |
| 65 | + return <div style={containerStyle}>{children}</div>; |
| 66 | +} |
| 67 | + |
| 68 | +/** |
| 69 | + * Error boundary component for the Monaco editor |
| 70 | + */ |
| 71 | +export class EditorErrorBoundary extends React.Component< |
| 72 | + { children: React.ReactNode; fallback?: React.ReactNode }, |
| 73 | + { hasError: boolean } |
| 74 | +> { |
| 75 | + constructor(props: { |
| 76 | + children: React.ReactNode; |
| 77 | + fallback?: React.ReactNode; |
| 78 | + }) { |
| 79 | + super(props); |
| 80 | + this.state = { hasError: false }; |
| 81 | + } |
| 82 | + |
| 83 | + static getDerivedStateFromError() { |
| 84 | + return { hasError: true }; |
| 85 | + } |
| 86 | + |
| 87 | + componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { |
| 88 | + console.error("Error in Monaco Editor:", error, errorInfo); |
| 89 | + } |
| 90 | + |
| 91 | + render() { |
| 92 | + if (this.state.hasError) { |
| 93 | + return ( |
| 94 | + this.props.fallback || ( |
| 95 | + <div className="p-4 text-red-500"> |
| 96 | + An error occurred while loading the editor. Please refresh the page. |
| 97 | + </div> |
| 98 | + ) |
| 99 | + ); |
| 100 | + } |
| 101 | + |
| 102 | + return this.props.children; |
| 103 | + } |
| 104 | +} |
0 commit comments