2022-09-04 11:31:48 +00:00
|
|
|
import { action } from '@ember/object';
|
|
|
|
|
import Component from '@glimmer/component';
|
2022-09-05 15:08:46 +00:00
|
|
|
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api.js';
|
2022-09-04 11:31:48 +00:00
|
|
|
|
|
|
|
|
export default class MonacoEditorComponent extends Component {
|
|
|
|
|
@action
|
|
|
|
|
initEditor(el) {
|
|
|
|
|
this.editor = monaco.editor.create(el, {
|
|
|
|
|
value: this.args.value,
|
|
|
|
|
language: this.args.language,
|
2022-09-05 15:58:34 +00:00
|
|
|
lineNumbers: 'off',
|
|
|
|
|
roundedSelection: false,
|
|
|
|
|
scrollBeyondLastLine: false,
|
2022-09-04 11:31:48 +00:00
|
|
|
minimap: {
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
|
|
|
|
});
|
2022-09-05 15:58:34 +00:00
|
|
|
|
|
|
|
|
// Add onChange event
|
|
|
|
|
if (this.args.onChange) {
|
|
|
|
|
this.editor.onDidChangeModelContent(() => {
|
|
|
|
|
this.args.onChange(this.editor.getValue());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// autoresize height of element
|
|
|
|
|
const disposable = this.editor.onDidContentSizeChange(() => {
|
|
|
|
|
const contentHeight = Math.min(320, this.editor.getContentHeight());
|
|
|
|
|
el.style.height = `${contentHeight}px`;
|
|
|
|
|
this.editor.layout();
|
|
|
|
|
disposable.dispose();
|
|
|
|
|
});
|
2022-09-04 11:31:48 +00:00
|
|
|
}
|
2022-09-05 15:08:46 +00:00
|
|
|
|
|
|
|
|
willDestroy() {
|
|
|
|
|
this.editor?.dispose();
|
|
|
|
|
|
|
|
|
|
super.willDestroy(...arguments);
|
|
|
|
|
}
|
2022-09-04 11:31:48 +00:00
|
|
|
}
|