feat: editor

This commit is contained in:
EleanorMao
2024-04-09 23:27:48 +08:00
parent 141f253400
commit 8bd972c992
7 changed files with 48 additions and 42 deletions

1
src/BotAddin.tsx Normal file
View File

@ -0,0 +1 @@
import React from 'react'

View File

@ -3,39 +3,28 @@
* @Date : 2024-04-09 16:24:25
* @LastEditTime : 2024-04-09 16:24:25
*
*
*
*/
import React, { useRef, useEffect } from 'react';
import * as monaco from 'monaco-editor';
// @ts-ignore
// eslint-disable-next-line no-restricted-globals
self.MonacoEnvironment = {
getWorkerUrl: function (_moduleId: any, label: string) {
if (label === 'json') {
return './json.worker.bundle.js';
}
if (label === 'typescript' || label === 'javascript') {
return './ts.worker.bundle.js';
}
return './editor.worker.bundle.js';
}
};
import React, { useState } from 'react';
import MonacoEditor from 'react-monaco-editor';
export const Editor: React.FC = () => {
const divEl = useRef<HTMLDivElement>(null);
let editor: monaco.editor.IStandaloneCodeEditor;
useEffect(() => {
if (divEl.current) {
editor = monaco.editor.create(divEl.current, {
value: ['function x() {', '\tconsole.log("Hello world!");', '}'].join('\n'),
language: 'javascript'
});
}
return () => {
editor.dispose();
};
}, []);
return <div className="Editor" ref={divEl}></div>;
const [code, setCode] = useState(['function x() {', '\tconsole.log("Hello world!");', '}'].join('\n'))
return (
<MonacoEditor
width="100%"
height="300"
language="javascript"
theme="vs-dark"
value={code}
options={{
selectOnLineNumbers: true,
automaticLayout: true,
}}
onChange={setCode}
/>
)
};

1
src/EmailSender.tsx Normal file
View File

@ -0,0 +1 @@
import React from 'react'

1
src/Script.tsx Normal file
View File

@ -0,0 +1 @@
import React from 'react'