Skip to content

Commit b9ffb59

Browse files
committed
[playground] remove multi-file support and preview (#767)
1 parent 3b3107f commit b9ffb59

15 files changed

+47
-1761
lines changed

compiler/forget/packages/playground/components/Editor/Input.tsx

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import invariant from "invariant";
88
import type { editor } from "monaco-editor";
99
import { useEffect, useState } from "react";
1010
import { renderForgetMarkers } from "../../lib/forgetMonacoDiagnostics";
11-
import { createInputFile, getSelectedFile } from "../../lib/stores";
1211
import { useStore, useStoreDispatch } from "../StoreContext";
13-
import InputTabSelector from "./InputTabSelector";
1412
import { monacoOptions } from "./monacoOptions";
1513
// TODO: Make TS recognize .d.ts files, in addition to loading them with webpack.
1614
// @ts-ignore
@@ -20,45 +18,33 @@ export default function Input({ diagnostics }: { diagnostics: Diagnostic[] }) {
2018
const [monaco, setMonaco] = useState<Monaco | null>(null);
2119
const store = useStore();
2220
const dispatchStore = useStoreDispatch();
23-
const selectedFile = getSelectedFile(store);
2421

2522
useEffect(() => {
2623
if (!monaco) return;
27-
const uri = monaco.Uri.parse(`file:///${selectedFile.id}`);
24+
const uri = monaco.Uri.parse(`file:///index.js`);
2825
const model = monaco.editor.getModel(uri);
2926
invariant(model, "Model must exist for the selected input file.");
3027
renderForgetMarkers({ monaco, model, diagnostics });
31-
}, [diagnostics, monaco, selectedFile.id]);
28+
}, [diagnostics, monaco]);
3229

3330
// Set tab width to 2 spaces for the selected input file.
3431
useEffect(() => {
3532
if (!monaco) return;
36-
const uri = monaco.Uri.parse(`file:///${selectedFile.id}`);
33+
const uri = monaco.Uri.parse(`file:///index.js`);
3734
const model = monaco.editor.getModel(uri);
3835
invariant(model, "Model must exist for the selected input file.");
3936
// N.B. that `tabSize` is a model property, not an editor property.
4037
// So, the tab size has to be set per model.
4138
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]);
5440

5541
const handleChange = (value: string | undefined) => {
5642
if (!value) return;
5743

5844
dispatchStore({
5945
type: "updateFile",
6046
payload: {
61-
file: createInputFile(store.selectedFileId, value),
47+
source: value,
6248
},
6349
});
6450
};
@@ -113,21 +99,16 @@ export default function Input({ diagnostics }: { diagnostics: Diagnostic[] }) {
11399

114100
return (
115101
<div className="relative flex flex-col flex-none border-r border-gray-200">
116-
<InputTabSelector />
117102
{/* Restrict MonacoEditor's height, since the config autoLayout:true
118103
will grow the editor to fit within parent element */}
119104
<div className="w-full h-monaco_small sm:h-monaco">
120105
<MonacoEditor
121-
path={selectedFile.id}
106+
path={"index.js"}
122107
// .js and .jsx files are specified to be TS so that Monaco can actually
123108
// check their syntax using its TS language service. They are still JS files
124109
// 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}
131112
onMount={handleMount}
132113
onChange={handleChange}
133114
options={monacoOptions}

compiler/forget/packages/playground/components/Editor/InputTab.tsx

Lines changed: 0 additions & 108 deletions
This file was deleted.

compiler/forget/packages/playground/components/Editor/InputTabSelector.tsx

Lines changed: 0 additions & 203 deletions
This file was deleted.

0 commit comments

Comments
 (0)