import * as monaco from 'monaco-editor';
import * as React from 'react';
export class MonacoEditor extends React.PureComponent {
    constructor() {
        super(...arguments);
        this.setRef = (e) => {
            if (!e) {
                return;
            }
            this.props.editorWillMount(monaco);
            this.editor = monaco.editor.create(e, Object.assign({ value: this.props.value, language: this.props.language, theme: this.props.theme }, this.props.options));
        };
    }
    componentWillReceiveProps(nextProps) {
        if (this.props.value !== nextProps.value) {
            if (this.editor && this.editor.getValue() !== nextProps.value) {
                this.editor.setValue(nextProps.value || '');
            }
        }
    }
    componentWillUnmount() {
        if (this.editor) {
            this.editor.dispose();
            // HACK: Clean up ARIA container that Monaco apparently forgets to remove.
            // tslint:disable-next-line:ban
            document.querySelectorAll('.monaco-aria-container').forEach(e => e.remove());
        }
    }
    render() {
        return (React.createElement("div", { 
            // tslint:disable-next-line:jsx-ban-props
            style: { height: `${this.props.height}px`, position: 'relative' }, ref: this.setRef, id: this.props.id, className: "monaco-editor-container" }));
    }
}
window.MonacoEnvironment = {
    getWorkerUrl(moduleId, label) {
        if (label === 'json') {
            return window.context.assetsRoot + '/scripts/json.worker.bundle.js';
        }
        return window.context.assetsRoot + '/scripts/editor.worker.bundle.js';
    },
};
//# sourceMappingURL=MonacoEditor.js.map