covid19-dashboard
Version:
Dashboard App displaying COVID-19 numbers by country
161 lines (144 loc) • 3.88 kB
JavaScript
import Component from '../../../../node_modules/neo.mjs/src/component/Base.mjs';
/**
* @class Docs.view.classdetails.SourceViewComponent
* @extends Neo.component.Base
*/
class SourceViewComponent extends Component {
static getConfig() {return {
/**
* @member {String} className='Docs.view.classdetails.SourceViewComponent'
* @protected
*/
className: 'Docs.view.classdetails.SourceViewComponent',
/**
* @member {String} ntype='classdetails-sourceviewcomponent'
* @protected
*/
ntype: 'classdetails-sourceviewcomponent',
/**
* @member {Boolean} isHighlighted_=false
* @protected
*/
isHighlighted_: false,
/**
* @member {Number|null} line_=null
* @protected
*/
line_: null,
/**
* @member {Number|null} previousLine=null
* @protected
*/
previousLine: null,
/**
* @member {Object|null} structureData=null
* @protected
*/
structureData: null,
/**
* @member {Object} style= {overflow: 'auto'}
*/
style: {
overflow: 'auto'
},
/**
* @member {Object} _vdom={cn: [//...]}
*/
_vdom: {
cn: [{
tag: 'pre',
cn : [{
tag : 'code',
class: 'javascript'
}]
}]
}
}}
/**
*
* @param {Object} config
*/
construct(config) {
super.construct(config);
let me = this,
url = '../../' + me.structureData.srcPath;
Neo.Xhr.promiseRequest({
url: url
}).then(data => {
setTimeout(() => { // ensure we are not mounting
me.applySourceCode(data.response);
}, 100);
});
}
/**
* Triggered after the isHighlighted config got changed
* @param {Boolean} value
* @param {Boolean} oldValue
* @protected
*/
afterSetIsHighlighted(value, oldValue) {
if (value) {
let me = this;
setTimeout(() => {
Neo.main.addon.HighlightJS.syntaxHighlightLine({
addLine : me.line,
removeLine: me.previousLine,
vnodeId : me.vdom.cn[0].id
});
}, 50);
}
}
/**
* Triggered after the line config got changed
* @param {Number} value
* @param {Number} oldValue
* @protected
*/
afterSetLine(value, oldValue) {
let me = this;
if (oldValue) {
me.previousLine = oldValue;
}
if (me.isHighlighted) {
me.afterSetIsHighlighted(true, false);
}
}
/**
*
* @param {Object} data
*/
applySourceCode(data) {
let me = this,
vdom = me.vdom,
node = vdom.cn[0]; // pre tag
node.cn[0].innerHTML = data; // code tag
me.vdom = vdom;
setTimeout(() => {
me.syntaxHighlight(node.id);
}, 50);
}
/**
*
* @param {String} vnodeId
*/
syntaxHighlight(vnodeId) {
let me = this,
id;
if (me.vnode) {
Neo.main.addon.HighlightJS.syntaxHighlight({
vnodeId: me.vdom.cn[0].id
}).then(() => {
me.isHighlighted = true;
});
} else {
id = me.on('mounted', () => {
setTimeout(() => {
me.un('mounted', id);
me.syntaxHighlight(vnodeId);
}, 50);
});
}
}
}
Neo.applyClassConfig(SourceViewComponent);
export {SourceViewComponent as default};