| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- import {
- forwardRef, useMemo, useRef,
- } from 'react';
- import type { ReactCodeMirrorProps } from '@uiw/react-codemirror';
- import { GlobalCodeMirrorEditorKey } from '../consts';
- import { useCodeMirrorEditorIsolated } from '../stores';
- import style from './CodeMirrorEditor.module.scss';
- const CodeMirrorEditorContainer = forwardRef<HTMLDivElement>((props, ref) => {
- return (
- <div {...props} className={`${style['codemirror-editor-container']}`} ref={ref} />
- );
- });
- type Props = {
- editorKey: string | GlobalCodeMirrorEditorKey,
- onChange?: (value: string) => void,
- }
- export const CodeMirrorEditor = (props: Props): JSX.Element => {
- const {
- editorKey,
- onChange,
- } = props;
- const containerRef = useRef(null);
- const cmProps = useMemo<ReactCodeMirrorProps>(() => {
- return {
- onChange,
- };
- }, [onChange]);
- useCodeMirrorEditorIsolated(editorKey, containerRef.current, cmProps);
- return <CodeMirrorEditorContainer ref={containerRef} />;
- };
|