Skip to content

Commit 53cb332

Browse files
chore: Migrate playground example from ace to monaco editor (#9617)
1 parent da2e93e commit 53cb332

File tree

3 files changed

+23
-31
lines changed

3 files changed

+23
-31
lines changed

examples/playground/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<div id="app"></div>
2020
</body>
2121
<script type="module">
22-
import {renderToDOM} from './src/app.jsx';
22+
import {renderToDOM} from './src/app.tsx';
2323
renderToDOM(document.getElementById('app'));
2424
</script>
2525
</html>

examples/playground/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"@loaders.gl/draco": "^4.2.0",
1616
"@loaders.gl/gltf": "^4.2.0",
1717
"@luma.gl/constants": "^9.1.9",
18-
"brace": "^0.11.1",
1918
"deck.gl": "^9.0.0",
2019
"maplibre-gl": "^5.0.0",
20+
"monaco-editor": "^0.39.0",
21+
"@monaco-editor/react": "^4.4.6",
2122
"react": "^18.0.0",
22-
"react-ace": "^6.1.4",
2323
"react-dom": "^18.0.0",
2424
"react-map-gl": "^8.0.0",
2525
"react-virtualized-auto-sizer": "^1.0.2"

examples/playground/src/app.jsx renamed to examples/playground/src/app.tsx

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import {FlyToInterpolator} from '@deck.gl/core';
1313
import {JSONConverter, JSONConfiguration, _shallowEqualObjects} from '@deck.gl/json';
1414
import JSON_CONVERTER_CONFIGURATION from './configuration';
1515

16-
import AceEditor from 'react-ace';
17-
import 'brace/mode/json';
18-
import 'brace/theme/github';
16+
import Editor from '@monaco-editor/react';
1917

2018
import JSON_TEMPLATES from '../json-examples';
2119

@@ -47,21 +45,18 @@ function addUpdateTriggersForAccessors(json) {
4745
}
4846

4947
export default class App extends Component {
50-
constructor(props) {
51-
super(props);
48+
jsonConverter: JSONConverter;
5249

53-
this.state = {
54-
// react-ace
55-
text: '',
56-
// deck.gl JSON Props
57-
jsonProps: {},
58-
initialViewState: null
59-
};
50+
state = {
51+
// editor
52+
text: '',
53+
// deck.gl JSON Props
54+
jsonProps: {} as Record<string, unknown>,
55+
initialViewState: null as Record<string, any> | null
56+
};
6057

61-
// TODO/ib - could use arrow functions
62-
// keeping like this for now to allow this code to be copied back to deck.gl
63-
this._onTemplateChange = this._onTemplateChange.bind(this);
64-
this._onEditorChange = this._onEditorChange.bind(this);
58+
constructor(props) {
59+
super(props);
6560

6661
// Configure and create the JSON converter instance
6762
const configuration = new JSONConfiguration(JSON_CONVERTER_CONFIGURATION);
@@ -130,7 +125,8 @@ export default class App extends Component {
130125
this._setTemplate(value);
131126
}
132127

133-
_onEditorChange(text, event) {
128+
_onEditorChange(value) {
129+
const text = value;
134130
let json = null;
135131
// Parse JSON, while capturing and ignoring exceptions
136132
try {
@@ -144,7 +140,7 @@ export default class App extends Component {
144140

145141
_renderJsonSelector() {
146142
return (
147-
<select name="JSON templates" onChange={this._onTemplateChange}>
143+
<select name="JSON templates" onChange={event => this._onTemplateChange(event)}>
148144
{Object.entries(JSON_TEMPLATES).map(([key]) => (
149145
<option key={key} value={key}>
150146
{key}
@@ -180,25 +176,21 @@ export default class App extends Component {
180176

181177
return (
182178
<Fragment>
183-
{/* Left Pane: Ace Editor and Template Selector */}
179+
{/* Left Pane: Monaco Editor and Template Selector */}
184180
<div id="left-pane">
185181
{this._renderJsonSelector()}
186182

187183
<div id="editor">
188184
<AutoSizer>
189185
{({width, height}) => (
190-
<AceEditor
186+
<Editor
191187
width={`${width}px`}
192188
height={`${height}px`}
193-
mode="json"
194-
theme="github"
195-
onChange={this._onEditorChange}
196-
name="AceEditorDiv"
197-
editorProps={{$blockScrolling: true}}
198-
ref={instance => {
199-
this.ace = instance;
200-
}}
189+
defaultLanguage="json"
190+
theme="light"
201191
value={this.state.text}
192+
onChange={value => this._onEditorChange(value)}
193+
options={{scrollBeyondLastLine: false}}
202194
/>
203195
)}
204196
</AutoSizer>

0 commit comments

Comments
 (0)