import { json } from '@codemirror/lang-json' import { yaml } from '@codemirror/lang-yaml' import { useFetcher } from '@remix-run/react' import { githubDark, githubLight } from '@uiw/codemirror-theme-github' import CodeMirror from '@uiw/react-codemirror' import clsx from 'clsx' import { useEffect, useMemo, useState } from 'react' import CodeMirrorMerge from 'react-codemirror-merge' import { toast } from 'react-hot-toast/headless' import Button from '~/components/Button' import Spinner from '~/components/Spinner' import Fallback from './fallback' type EditorProperties = { readonly acl: string; readonly setAcl: (acl: string) => void; readonly mode: 'edit' | 'diff'; readonly data: { hasAclWrite: boolean; currentAcl: string; aclType: string; }; } export default function Editor({ data, acl, setAcl, mode }: EditorProperties) { const [light, setLight] = useState(false) const [loading, setLoading] = useState(true) const fetcher = useFetcher() const aclType = useMemo(() => data.aclType === 'json' ? json() : yaml(), [data.aclType]) useEffect(() => { const theme = window.matchMedia('(prefers-color-scheme: light)') setLight(theme.matches) theme.addEventListener('change', theme => { setLight(theme.matches) }) // Prevents the FOUC setLoading(false) }, []) return ( <>