Run prettier
parent
256e10bb54
commit
cff50c2a31
@ -1,43 +1,40 @@
|
|||||||
import React, { useRef, useEffect } from 'react'
|
import React, { useRef, useEffect } from 'react';
|
||||||
import * as monaco from "monaco-editor";
|
import * as monaco from 'monaco-editor';
|
||||||
|
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
self.MonacoEnvironment = {
|
self.MonacoEnvironment = {
|
||||||
getWorkerUrl: function (_moduleId: any, label: string) {
|
getWorkerUrl: function (_moduleId: any, label: string) {
|
||||||
if (label === "json") {
|
if (label === 'json') {
|
||||||
return "./json.worker.bundle.js";
|
return './json.worker.bundle.js';
|
||||||
}
|
}
|
||||||
if (label === "css") {
|
if (label === 'css') {
|
||||||
return "./css.worker.bundle.js";
|
return './css.worker.bundle.js';
|
||||||
}
|
}
|
||||||
if (label === "html") {
|
if (label === 'html') {
|
||||||
return "./html.worker.bundle.js";
|
return './html.worker.bundle.js';
|
||||||
}
|
}
|
||||||
if (label === "typescript" || label === "javascript") {
|
if (label === 'typescript' || label === 'javascript') {
|
||||||
return "./ts.worker.bundle.js";
|
return './ts.worker.bundle.js';
|
||||||
}
|
}
|
||||||
return "./editor.worker.bundle.js";
|
return './editor.worker.bundle.js';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const Editor: React.FC = () => {
|
export const Editor: React.FC = () => {
|
||||||
const divEl = useRef<HTMLDivElement>(null)
|
const divEl = useRef<HTMLDivElement>(null);
|
||||||
let editor: monaco.editor.IStandaloneCodeEditor
|
let editor: monaco.editor.IStandaloneCodeEditor;
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (divEl.current) {
|
if (divEl.current) {
|
||||||
editor = monaco.editor.create(divEl.current, {
|
editor = monaco.editor.create(divEl.current, {
|
||||||
value: ["function x() {", '\tconsole.log("Hello world!");', "}"].join("\n"),
|
value: ['function x() {', '\tconsole.log("Hello world!");', '}'].join(
|
||||||
language: "typescript"
|
'\n'
|
||||||
|
),
|
||||||
|
language: 'typescript'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return () => {
|
return () => {
|
||||||
editor.dispose()
|
editor.dispose();
|
||||||
}
|
};
|
||||||
}, [])
|
}, []);
|
||||||
return (
|
return <div className="Editor" ref={divEl}></div>;
|
||||||
<div className="Editor" ref={divEl}>
|
};
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
@ -1,16 +1,12 @@
|
|||||||
import "./index.css";
|
import './index.css';
|
||||||
|
|
||||||
import React from 'react'
|
|
||||||
import ReactDOM from 'react-dom'
|
|
||||||
import { Editor } from "./components/Editor";
|
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
|
import { Editor } from './components/Editor';
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<Editor />
|
<Editor />
|
||||||
</React.StrictMode>,
|
</React.StrictMode>,
|
||||||
document.getElementById('root')
|
document.getElementById('root')
|
||||||
)
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue