forked from TypeFox/monaco-languageclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-react.tsx
61 lines (54 loc) · 2.46 KB
/
main-react.tsx
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2024 TypeFox and others.
* Licensed under the MIT License. See LICENSE in the package root for license information.
* ------------------------------------------------------------------------------------------ */
import React, { StrictMode, useEffect, useState } from 'react';
import ReactDOM from 'react-dom/client';
import { MonacoEditorReactComp } from '@typefox/monaco-editor-react';
import { createLangiumGlobalConfig } from './config/wrapperStatemachineConfig.js';
import { loadStatemachineWorkerRegular } from './main.js';
import text from '../../../resources/langium/statemachine/example.statemachine?raw';
import { disableElement } from '../../common/client/utils.js';
export const runStatemachineReact = async () => {
const wrapperConfig = await createLangiumGlobalConfig({
languageServerId: 'react',
useLanguageClient: true,
text,
worker: loadStatemachineWorkerRegular(),
htmlContainer: document.getElementById('monaco-editor-root')!
});
const root = ReactDOM.createRoot(document.getElementById('react-root')!);
try {
document.querySelector('#button-start')?.addEventListener('click', async () => {
const App = () => {
const [ height, setHeight ] = useState('80vh');
useEffect(() => {
const timer = setTimeout(() => {
console.log('Updating styles');
setHeight('85vh');
}, 2000);
return () => clearTimeout(timer);
}, []);
return (
<div style={{ 'height': height }} >
<MonacoEditorReactComp
style={{ 'height': '100%' }}
wrapperConfig={wrapperConfig} />
</div>
);
};
const strictMode = (document.getElementById('checkbox-strictmode')! as HTMLInputElement).checked;
if (strictMode) {
root.render(<StrictMode><App /></StrictMode>);
} else {
root.render(<App />);
}
disableElement('checkbox-strictmode', true);
});
document.querySelector('#button-dispose')?.addEventListener('click', () => {
root.render([]);
});
} catch (e) {
console.error(e);
}
};