2017-12-15 21:39:18 +00:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import { computed } from '@ember/object';
|
|
|
|
import { run } from '@ember/runloop';
|
2018-02-20 23:27:03 +00:00
|
|
|
import { copy } from '@ember/object/internals';
|
2018-07-06 20:38:57 +00:00
|
|
|
import JSONFormatter from 'json-formatter-js';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
export default Component.extend({
|
|
|
|
classNames: ['json-viewer'],
|
|
|
|
|
|
|
|
json: null,
|
2017-12-07 22:06:51 +00:00
|
|
|
expandDepth: Infinity,
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
formatter: computed('json', 'expandDepth', function() {
|
2018-02-20 23:27:03 +00:00
|
|
|
return new JSONFormatter(copy(this.get('json'), true), this.get('expandDepth'), {
|
2017-09-19 14:47:10 +00:00
|
|
|
theme: 'nomad',
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
didReceiveAttrs() {
|
|
|
|
const json = this.get('json');
|
|
|
|
if (!json) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
run.scheduleOnce('afterRender', this, embedViewer);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
function embedViewer() {
|
2017-12-07 22:06:51 +00:00
|
|
|
this.$()
|
|
|
|
.empty()
|
|
|
|
.append(this.get('formatter').render());
|
2017-09-19 14:47:10 +00:00
|
|
|
}
|