@@ -8,9 +8,7 @@ import invariant from "invariant";
8
8
import type { editor } from "monaco-editor" ;
9
9
import { useEffect , useState } from "react" ;
10
10
import { renderForgetMarkers } from "../../lib/forgetMonacoDiagnostics" ;
11
- import { createInputFile , getSelectedFile } from "../../lib/stores" ;
12
11
import { useStore , useStoreDispatch } from "../StoreContext" ;
13
- import InputTabSelector from "./InputTabSelector" ;
14
12
import { monacoOptions } from "./monacoOptions" ;
15
13
// TODO: Make TS recognize .d.ts files, in addition to loading them with webpack.
16
14
// @ts -ignore
@@ -20,45 +18,33 @@ export default function Input({ diagnostics }: { diagnostics: Diagnostic[] }) {
20
18
const [ monaco , setMonaco ] = useState < Monaco | null > ( null ) ;
21
19
const store = useStore ( ) ;
22
20
const dispatchStore = useStoreDispatch ( ) ;
23
- const selectedFile = getSelectedFile ( store ) ;
24
21
25
22
useEffect ( ( ) => {
26
23
if ( ! monaco ) return ;
27
- const uri = monaco . Uri . parse ( `file:///${ selectedFile . id } ` ) ;
24
+ const uri = monaco . Uri . parse ( `file:///index.js ` ) ;
28
25
const model = monaco . editor . getModel ( uri ) ;
29
26
invariant ( model , "Model must exist for the selected input file." ) ;
30
27
renderForgetMarkers ( { monaco, model, diagnostics } ) ;
31
- } , [ diagnostics , monaco , selectedFile . id ] ) ;
28
+ } , [ diagnostics , monaco ] ) ;
32
29
33
30
// Set tab width to 2 spaces for the selected input file.
34
31
useEffect ( ( ) => {
35
32
if ( ! monaco ) return ;
36
- const uri = monaco . Uri . parse ( `file:///${ selectedFile . id } ` ) ;
33
+ const uri = monaco . Uri . parse ( `file:///index.js ` ) ;
37
34
const model = monaco . editor . getModel ( uri ) ;
38
35
invariant ( model , "Model must exist for the selected input file." ) ;
39
36
// N.B. that `tabSize` is a model property, not an editor property.
40
37
// So, the tab size has to be set per model.
41
38
model . updateOptions ( { tabSize : 2 } ) ;
42
- } , [ monaco , selectedFile . id ] ) ;
43
-
44
- useEffect ( ( ) => {
45
- if ( ! monaco ) return ;
46
- // Let Monaco Editor know of the input files so that its language
47
- // service can correctly resolve import statements.
48
- store . files . forEach ( ( file ) => {
49
- const lib = [ file . content , `file:///${ file . id } ` ] as const ;
50
- monaco . languages . typescript . javascriptDefaults . addExtraLib ( ...lib ) ;
51
- monaco . languages . typescript . typescriptDefaults . addExtraLib ( ...lib ) ;
52
- } ) ;
53
- } , [ monaco , store . files ] ) ;
39
+ } , [ monaco ] ) ;
54
40
55
41
const handleChange = ( value : string | undefined ) => {
56
42
if ( ! value ) return ;
57
43
58
44
dispatchStore ( {
59
45
type : "updateFile" ,
60
46
payload : {
61
- file : createInputFile ( store . selectedFileId , value ) ,
47
+ source : value ,
62
48
} ,
63
49
} ) ;
64
50
} ;
@@ -113,21 +99,16 @@ export default function Input({ diagnostics }: { diagnostics: Diagnostic[] }) {
113
99
114
100
return (
115
101
< div className = "relative flex flex-col flex-none border-r border-gray-200" >
116
- < InputTabSelector />
117
102
{ /* Restrict MonacoEditor's height, since the config autoLayout:true
118
103
will grow the editor to fit within parent element */ }
119
104
< div className = "w-full h-monaco_small sm:h-monaco" >
120
105
< MonacoEditor
121
- path = { selectedFile . id }
106
+ path = { "index.js" }
122
107
// .js and .jsx files are specified to be TS so that Monaco can actually
123
108
// check their syntax using its TS language service. They are still JS files
124
109
// due to their extensions, so TS language features don't work.
125
- language = {
126
- selectedFile . language === "javascript"
127
- ? "typescript"
128
- : selectedFile . language
129
- }
130
- value = { selectedFile . content }
110
+ language = { "javascript" }
111
+ value = { store . source }
131
112
onMount = { handleMount }
132
113
onChange = { handleChange }
133
114
options = { monacoOptions }
0 commit comments