@@ -2,23 +2,14 @@ import { default as MonacoEditor } from "@monaco-editor/react";
22import type * as monaco from "monaco-editor" ;
33import { Component } from "react" ;
44
5- import { saveLastSource } from "../config.js" ;
6- import * as ls from "../dot-monaco/index.js" ;
7-
8- type Monaco = typeof monaco ;
9-
105type EditorPaneProps = {
116 defaultValue ?: string ;
127 onChangeValue ( value : string ) : void ;
138 onValueError ( err : monaco . editor . IMarkerData [ ] ) : void ;
149} ;
1510
16- const SOURCE_SAVE_TIMEOUT = 5 * 1000 ; // 5 seconds
17-
1811export default class EditorPane extends Component < EditorPaneProps , object > {
19- #processor: ls . LanguageProcessor | undefined ;
2012 #editor: monaco . editor . IStandaloneCodeEditor | undefined ;
21- #autoSaveTimeout: ReturnType < typeof setTimeout > | undefined = undefined ;
2213
2314 state : object = { } ;
2415
@@ -29,36 +20,8 @@ export default class EditorPane extends Component<EditorPaneProps, object> {
2920 }
3021 }
3122
32- #editorWillMount = ( monaco : Monaco ) : void => {
33- ls . registerService ( monaco , ls . service ) ;
34- this . #processor = ls . service . processor ;
35- } ;
36-
37- #onChange = (
38- value : string | undefined ,
39- _event : monaco . editor . IModelContentChangedEvent ,
40- ) : void => {
41- const p = this . #processor;
42- const e = this . #editor;
43- if ( ! p || ! e ) return ;
44-
45- if ( typeof this . #autoSaveTimeout !== "undefined" ) {
46- clearTimeout ( this . #autoSaveTimeout) ;
47- }
48- this . #autoSaveTimeout = setTimeout (
49- ( ) => saveLastSource ( value ) ,
50- SOURCE_SAVE_TIMEOUT ,
51- ) ;
52- } ;
53-
5423 render ( ) {
5524 const defaultValue = this . props . defaultValue || "" ;
56- return (
57- < MonacoEditor
58- defaultValue = { defaultValue }
59- onChange = { this . #onChange}
60- beforeMount = { this . #editorWillMount}
61- />
62- ) ;
25+ return < MonacoEditor defaultValue = { defaultValue } /> ;
6326 }
6427}
0 commit comments