open-vault/ui/app/components/json-editor.js

54 lines
1.2 KiB
JavaScript
Raw Normal View History

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,
showCursorWhenSelecting: true,
2018-04-03 14:16:57 +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
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
}
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
},
});