import { JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application';
import { ICommandPalette, IFrame } from '@jupyterlab/apputils';
import { PageConfig } from '@jupyterlab/coreutils';
import { ILauncher } from '@jupyterlab/launcher';
import { LabIcon } from '@jupyterlab/ui-components';
const nniIconSvg = `
`;
const nniIcon = new LabIcon({ name: 'nni', svgstr: nniIconSvg });
class NniWidget extends IFrame {
constructor() {
super({
sandbox: [
'allow-same-origin',
'allow-scripts',
]
});
this.url = PageConfig.getBaseUrl() + 'nni/index';
this.id = 'nni';
this.title.label = 'NNI';
this.title.icon = nniIcon;
this.title.closable = true;
}
}
async function activate(app: JupyterFrontEnd, palette: ICommandPalette, launcher: ILauncher | null) {
console.log('nni extension is activated');
const { commands, shell } = app;
const command = 'nni';
const category = 'Other';
commands.addCommand(command, {
label: 'NNI',
caption: 'NNI',
icon: (args) => (args.isPalette ? null : nniIcon),
execute: () => {
shell.add(new NniWidget(), 'main');
}
});
palette.addItem({ command, category });
if (launcher) {
launcher.add({ command, category });
}
}
const extension: JupyterFrontEndPlugin = {
id: 'nni',
autoStart: true,
optional: [ILauncher],
requires: [ICommandPalette],
activate,
};
export default extension;