-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreactPython.tsx
More file actions
47 lines (42 loc) · 1.77 KB
/
reactPython.tsx
File metadata and controls
47 lines (42 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2024 TypeFox and others.
* Licensed under the MIT License. See LICENSE in the package root for license information.
* ------------------------------------------------------------------------------------------ */
import React, { StrictMode } from 'react';
import ReactDOM from 'react-dom/client';
import { MonacoEditorReactComp } from '@typefox/monaco-editor-react';
import { createUserConfig } from './config.js';
import { useWorkerFactory } from 'monaco-editor-wrapper/workerFactory';
import { MonacoEditorLanguageClientWrapper } from 'monaco-editor-wrapper';
export const configureMonacoWorkers = () => {
useWorkerFactory({
basePath: '../../../node_modules'
});
};
export const runPythonReact = () => {
/**
* Code is intentionally incorrect - language server will pick this up on connection and highlight the error
*/
const code = `def main():
return pass`;
const onTextChanged = (text: string, isDirty: boolean) => {
console.log(`Dirty? ${isDirty} Content: ${text}`);
};
ReactDOM.createRoot(document.getElementById('root')!).render(
<StrictMode>
<MonacoEditorReactComp
userConfig={createUserConfig(code)}
style={{
'paddingTop': '5px',
'height': '80vh'
}}
onTextChanged={onTextChanged}
onLoad={(wrapper: MonacoEditorLanguageClientWrapper) => {
console.log(`Loaded ${wrapper.reportStatus().join('\n').toString()}`);
}}
onError={(e) => {
console.error(e);
}}
/>
</StrictMode>);
};