import React from 'react'; import { EditingModes, HtmlClassName } from './AppendEditor'; import { MonacoEditor } from './Monaco'; import DynamicEditor from './DynamicEditor'; import { HtmlElementId } from './AppendEditor'; interface EditProps { debugMode: boolean; editingMode?: string; fontSize: string; keyMap: any; monacoEditorLanguage: string; onKeyDown: Function; onKeyUp: Function; onKeyDownEditTextArea: Function; onKeyDownTextArea: Function; saveText: Function; text: string; viewMode: boolean | undefined; } interface EditState { text: string; } export default class EditNote extends React.Component { static defaultProps = { // none }; constructor(props: EditProps) { super(props); this.state = { text: this.props.text, }; } handleInputChange = (event: React.ChangeEvent) => { const target = event.target; const value = target.value; this.setState( { text: value, }, () => { this.props.saveText(this.state.text); } ); }; saveText = (text: string) => { this.setState( { text, }, () => { this.props.saveText(this.state.text); } ); }; onBlur = (e: React.FocusEvent) => { const content = document.getElementById(HtmlElementId.content); if (content) { content.classList.remove(HtmlClassName.focused); } }; onFocus = (e: React.FocusEvent) => { const content = document.getElementById(HtmlElementId.content); if (content) { content.classList.add(HtmlClassName.focused); } }; onKeyDown = (e: React.KeyboardEvent) => { this.props.onKeyDown(e); this.props.onKeyDownEditTextArea(e); this.props.onKeyDownTextArea(e); }; onKeyUp = (event: React.KeyboardEvent) => { this.props.keyMap.delete(event.key); this.props.onKeyUp(event); }; render() { const { text } = this.state; return (
{this.props.editingMode === EditingModes.useMonacoEditor ? ( ) : this.props.editingMode === EditingModes.useDynamicEditor ? (
) : (