import Editor, { DiffEditor, Monaco } from '@monaco-editor/react' import { useEffect, useState } from 'react' import { ClientOnly } from 'remix-utils/client-only' import Fallback from '~/routes/_data.acls._index/fallback' import { cn } from '~/utils/cn' interface MonacoProps { variant: 'editor' | 'diff' language: 'json' | 'yaml' value: string onChange: (value: string) => void original?: string } function monacoCallback(monaco: Monaco) { monaco.languages.json.jsonDefaults.setDiagnosticsOptions({ validate: true, allowComments: true, schemas: [], enableSchemaRequest: true, trailingCommas: 'ignore', }) monaco.languages.register({ id: 'json' }) monaco.languages.register({ id: 'yaml' }) } export default function MonacoEditor({ value, onChange, variant, original, language }: MonacoProps) { const [light, setLight] = useState(false) useEffect(() => { const theme = window.matchMedia('(prefers-color-scheme: light)') setLight(theme.matches) theme.addEventListener('change', (theme) => { setLight(theme.matches) }) }, []) return ( <>
}> {() => variant === 'editor' ? ( { if (!updated) { return } if (updated !== value) { onChange(updated) } }} loading={} beforeMount={monacoCallback} options={{ wordWrap: 'on', minimap: { enabled: false }, fontSize: 14, }} /> ) : ( } beforeMount={monacoCallback} options={{ wordWrap: 'on', minimap: { enabled: false }, fontSize: 13, }} /> )}
) }