2021-05-06 16:59:15 +00:00
|
|
|
import Component from '@ember/component';
|
|
|
|
|
2018-04-03 14:16:57 +00:00
|
|
|
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,
|
2018-08-16 16:07:19 +00:00
|
|
|
showCursorWhenSelecting: true,
|
2018-04-03 14:16:57 +00:00
|
|
|
};
|
|
|
|
|
2021-05-06 16:59:15 +00:00
|
|
|
export default Component.extend({
|
|
|
|
showToolbar: true,
|
|
|
|
title: null,
|
|
|
|
subTitle: null,
|
|
|
|
helpText: null,
|
|
|
|
value: null,
|
|
|
|
options: null,
|
|
|
|
valueUpdated: null,
|
|
|
|
onFocusOut: null,
|
|
|
|
readOnly: false,
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2021-05-06 16:59:15 +00:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.options = { ...JSON_EDITOR_DEFAULTS, ...this.options };
|
|
|
|
if (this.options.autoHeight) {
|
|
|
|
this.options.viewportMargin = Infinity;
|
|
|
|
delete this.options.autoHeight;
|
2018-04-03 14:16:57 +00:00
|
|
|
}
|
2021-05-06 16:59:15 +00:00
|
|
|
if (this.options.readOnly) {
|
|
|
|
this.options.readOnly = 'nocursor';
|
|
|
|
this.options.lineNumbers = false;
|
|
|
|
delete this.options.gutters;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
updateValue(...args) {
|
|
|
|
if (this.valueUpdated) {
|
|
|
|
this.valueUpdated(...args);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onFocus(...args) {
|
|
|
|
if (this.onFocusOut) {
|
|
|
|
this.onFocusOut(...args);
|
|
|
|
}
|
|
|
|
},
|
2018-04-03 14:16:57 +00:00
|
|
|
},
|
|
|
|
});
|