2023-08-10 18:35:49 +03:00
|
|
|
import { Extension } from '@codemirror/state';
|
|
|
|
import { createTheme } from '@uiw/codemirror-themes';
|
2023-08-11 10:54:53 +03:00
|
|
|
import CodeMirror, { BasicSetupOptions, ReactCodeMirrorRef } from '@uiw/react-codemirror';
|
2023-08-10 18:35:49 +03:00
|
|
|
import { EditorView } from 'codemirror';
|
2023-08-11 10:54:53 +03:00
|
|
|
import { Ref } from 'react';
|
2023-08-10 18:35:49 +03:00
|
|
|
|
|
|
|
import { useConceptTheme } from '../../../context/ThemeContext';
|
|
|
|
|
|
|
|
const lightTheme: Extension = createTheme({
|
|
|
|
theme: 'light',
|
|
|
|
settings: {
|
2023-08-11 10:54:53 +03:00
|
|
|
fontFamily: 'inherit',
|
2023-08-10 18:35:49 +03:00
|
|
|
background: '#ffffff',
|
|
|
|
foreground: '#000000',
|
|
|
|
selection: '#036dd626'
|
|
|
|
},
|
|
|
|
styles: [
|
|
|
|
// { tag: t.comment, color: '#787b8099' },
|
|
|
|
// { tag: t.variableName, color: '#0080ff' },
|
|
|
|
// { tag: [t.string, t.special(t.brace)], color: '#5c6166' },
|
|
|
|
// { tag: t.definition(t.typeName), color: '#5c6166' },
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
const darkTheme: Extension = createTheme({
|
|
|
|
theme: 'dark',
|
|
|
|
settings: {
|
2023-08-11 10:54:53 +03:00
|
|
|
fontFamily: 'inherit',
|
2023-08-10 18:35:49 +03:00
|
|
|
background: '#000000',
|
|
|
|
foreground: '#ffffff',
|
|
|
|
selection: '#036dd626'
|
|
|
|
},
|
|
|
|
styles: [
|
|
|
|
// { tag: t.comment, color: '#787b8099' },
|
|
|
|
// { tag: t.variableName, color: '#0080ff' },
|
|
|
|
// { tag: [t.string, t.special(t.brace)], color: '#5c6166' },
|
|
|
|
// { tag: t.definition(t.typeName), color: '#5c6166' },
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
const editorSetup: BasicSetupOptions = {
|
|
|
|
highlightSpecialChars: true,
|
|
|
|
history: true,
|
|
|
|
drawSelection: true,
|
|
|
|
syntaxHighlighting: true,
|
|
|
|
defaultKeymap: true,
|
|
|
|
historyKeymap: true,
|
|
|
|
|
|
|
|
lineNumbers: false,
|
|
|
|
highlightActiveLineGutter: false,
|
|
|
|
foldGutter: false,
|
|
|
|
dropCursor: false,
|
|
|
|
allowMultipleSelections: false,
|
|
|
|
indentOnInput: false,
|
|
|
|
bracketMatching: true,
|
|
|
|
closeBrackets: false,
|
|
|
|
autocompletion: false,
|
|
|
|
rectangularSelection: false,
|
|
|
|
crosshairCursor: false,
|
|
|
|
highlightActiveLine: false,
|
|
|
|
highlightSelectionMatches: false,
|
|
|
|
closeBracketsKeymap: false,
|
|
|
|
searchKeymap: false,
|
|
|
|
foldKeymap: false,
|
|
|
|
completionKeymap: false,
|
|
|
|
lintKeymap: false
|
|
|
|
};
|
|
|
|
|
2023-08-11 10:54:53 +03:00
|
|
|
const editorExtensions = [
|
|
|
|
EditorView.lineWrapping
|
|
|
|
];
|
|
|
|
|
|
|
|
interface RSInputProps {
|
|
|
|
ref?: Ref<ReactCodeMirrorRef>
|
|
|
|
value?: string
|
|
|
|
disabled?: boolean
|
|
|
|
height?: string
|
|
|
|
placeholder?: string
|
|
|
|
onChange: (newValue: string) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
function RSInput({
|
|
|
|
disabled, onChange,
|
|
|
|
height='10rem',
|
|
|
|
...props
|
|
|
|
}: RSInputProps) {
|
2023-08-10 18:35:49 +03:00
|
|
|
const { darkMode } = useConceptTheme();
|
|
|
|
|
|
|
|
return (
|
2023-08-11 10:54:53 +03:00
|
|
|
<div className={`w-full h-[${height}]`}>
|
2023-08-10 18:35:49 +03:00
|
|
|
<CodeMirror
|
|
|
|
basicSetup={editorSetup}
|
2023-08-11 10:54:53 +03:00
|
|
|
extensions={editorExtensions}
|
2023-08-10 18:35:49 +03:00
|
|
|
editable={!disabled}
|
2023-08-11 10:54:53 +03:00
|
|
|
height={height}
|
2023-08-10 18:35:49 +03:00
|
|
|
indentWithTab={false}
|
|
|
|
theme={darkMode ? darkTheme : lightTheme}
|
2023-08-11 10:54:53 +03:00
|
|
|
onChange={(value) => onChange(value)}
|
|
|
|
{...props}
|
2023-08-10 18:35:49 +03:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default RSInput;
|