2018-04-03 14:16:57 +00:00
|
|
|
import IvyCodemirrorComponent from './ivy-codemirror';
|
|
|
|
import Ember from 'ember';
|
|
|
|
|
|
|
|
const { assign } = Ember;
|
|
|
|
const JSON_EDITOR_DEFAULTS = {
|
|
|
|
// IMPORTANT: `gutters` must come before `lint` since the presence of
|
|
|
|
// `gutters` is cached internally when `lint` is toggled
|
|
|
|
gutters: ['CodeMirror-lint-markers'],
|
|
|
|
tabSize: 2,
|
|
|
|
mode: 'application/json',
|
|
|
|
lineNumbers: true,
|
|
|
|
lint: { lintOnChange: false },
|
|
|
|
theme: 'hashi',
|
|
|
|
readOnly: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default IvyCodemirrorComponent.extend({
|
|
|
|
'data-test-component': 'json-editor',
|
|
|
|
updateCodeMirrorOptions() {
|
|
|
|
const options = assign({}, JSON_EDITOR_DEFAULTS, this.get('options'));
|
2018-05-25 20:33:22 +00:00
|
|
|
if (options.autoHeight) {
|
|
|
|
options.viewportMargin = Infinity;
|
|
|
|
delete options.autoHeight;
|
|
|
|
}
|
2018-04-03 14:16:57 +00:00
|
|
|
|
|
|
|
if (options) {
|
|
|
|
Object.keys(options).forEach(function(option) {
|
|
|
|
this.updateCodeMirrorOption(option, options[option]);
|
|
|
|
}, this);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|