Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Create tab
this.codeEditor.codeLayout.layout.addPanelToStack('edit-panel', {
type: 'component',
title: code.name,
componentName: code.id,
html: `<div style="width: 100%; height: 100%;" id="${code.id}-editor"></div>`,
onClose: () => {
this.code.dispose();
if (this.onClose)
this.onClose();
}
});
// Create editor
this.code = new CodeEditor('typescript', code.code);
await this.code.build(code.id + '-editor');
// On the user changes the code
let compileTimeoutId = -1;
this.code.onChange = value => {
// Set a timeout before transpilation until the user
// finished typings his code
clearTimeout(compileTimeoutId);
compileTimeoutId = setTimeout(() => {
const config = {
module: 'cjs',
target: 'es5',
experimentalDecorators: true,
};
public async create(): Promise {
// Layout
this.layout = new Layout(this.divElement.id);
this.layout.panels = [
{ type: 'top', size: 30, resizable: false, content: '<div style="width: 100%; height: 100%;" id="METADATA-EDITOR-TOOLBAR"></div>' },
{ type: 'main', content: '<div style="width: 100%; height: 100%;" id="METADATA-EDITOR-EDITOR"></div>' }
]
this.layout.build(this.divElement.id);
// Toolbar
this.toolbar = new Toolbar('METADATA-EDITOR-TOOLBAR');
this.toolbar.build('METADATA-EDITOR-TOOLBAR');
// Create json editor
this.code = new CodeEditor('json', '{\n\n}');
this.code.onChange = (value) => {
if (!this.selectedNode)
return;
// Clear JSON checker timeout
if (this._checkTimeout !== -1) {
clearTimeout(this._checkTimeout);
this._checkTimeout = -1;
}
try {
// Parse JSON text value
const data = JSON.parse(value);
this.selectedNode['metadata'].customMetadatas = data;
this.toolbar.notifyMessage('');
} catch (e) {
protected async createEditor (): Promise {
this.code = new CodeEditor('javascript');
await this.code.build('CODE-BEHAVIOR-EDITOR');
this.code.onChange = value => {
if (this.data)
this.data.code = this.code.getValue();
};
}
}