"use client" import * as React from "react" import Editor, { DiffEditor, type DiffEditorProps as MonacoDiffEditorProps, type EditorProps as MonacoEditorProps, } from "@monaco-editor/react" import { BracesIcon, LoaderCircleIcon } from "lucide-react" import { cn } from "@/lib/utils" const defaultEditorOptions: MonacoEditorProps["options"] = { automaticLayout: true, fontSize: 13, minimap: { enabled: false }, padding: { top: 12, bottom: 12 }, scrollBeyondLastLine: false, smoothScrolling: true, tabSize: 2, } export type CodeEditorProps = Omit & { onValueChange?: (value: string) => void loading?: React.ReactNode containerClassName?: string editorClassName?: string bordered?: boolean } function DefaultEditorLoading() { return (
) } function CodeEditor({ onValueChange, loading = , containerClassName, editorClassName, bordered = true, height = "360px", defaultLanguage = "typescript", theme = "vs-dark", options, onChange, ...props }: CodeEditorProps) { return (
{ onChange?.(value, event) onValueChange?.(value ?? "") }} />
) } export type JsonEditorProps = Omit & { formatOnMount?: boolean } function JsonEditor({ formatOnMount = false, beforeMount, onMount, options, ...props }: JsonEditorProps) { return ( { monaco.languages.json.jsonDefaults.setDiagnosticsOptions({ validate: true, allowComments: false, trailingCommas: "error", }) beforeMount?.(monaco) }} onMount={(editor, monaco) => { if (formatOnMount) { void editor.getAction("editor.action.formatDocument")?.run() } onMount?.(editor, monaco) }} options={{ ...options, formatOnPaste: true, formatOnType: true, }} /> ) } export type CodeDiffEditorProps = Omit & { loading?: React.ReactNode containerClassName?: string editorClassName?: string bordered?: boolean } function CodeDiffEditor({ loading = , containerClassName, editorClassName, bordered = true, height = "420px", language = "typescript", theme = "vs-dark", options, ...props }: CodeDiffEditorProps) { return (
) } export type CodePreviewProps = { value: string language?: string label?: string className?: string } function CodePreview({ value, language = "text", label = "Code preview", className }: CodePreviewProps) { return (
        {value}
      
) } export { CodeDiffEditor, CodeEditor, CodePreview, JsonEditor }