Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Add trust button:
let btnTrust = document.createElement('button');
btnTrust.innerText = 'Trust';
btnTrust.onclick = (ev: MouseEvent) => {
// Triggers change event:
this.model.trusted = !this.model.trusted;
};
w = new Widget({node: btnTrust});
w.addClass(TRUST_BUTTON_CLASS);
this.menu.addWidget(w);
// Add mimetype select:
let mimetypes: string[] = [];
for (let output of this.model.contents) {
let bundle = OutputModel.getData(output);
mimetypes = mimetypes.concat(Object.keys(bundle));
}
mimetypes = mimetypes.filter(unique);
if (mimetypes.length > 1) {
let cboMimetype = buildSelect(mimetypes);
let selectedMimetype = this.selectedMimetype;
if (selectedMimetype) {
cboMimetype.selectedIndex = mimetypes.indexOf(selectedMimetype);
}
cboMimetype.onchange = (ev: Event) => {
this.selectedMimetype = mimetypes[cboMimetype.selectedIndex];
};
w = new Widget({node: cboMimetype});
w.addClass(MIMETYPE_SELECT_CLASS);
this.menu.addWidget(w);
} else if (mimetypes.length === 1) {
it('should handle all bundle types', () => {
for (let i = 0; i < NBTestUtils.DEFAULT_OUTPUTS.length; i++) {
const output = NBTestUtils.DEFAULT_OUTPUTS[i];
const bundle = OutputModel.getData(output);
expect(Object.keys(bundle).length).to.not.equal(0);
}
});
});
protected get selectedMimetype(): string | null {
if (this._mimetype !== null) {
return this._mimetype;
}
let data = OutputModel.getData(this.model.base || this.model.remote!);
let mt = this.rendermime.preferredMimeType(
data,
this.model.trusted ? 'any' : 'ensure'
);
return mt === undefined ? null : mt;
}
protected createRenderer(output: nbformat.IOutput, trusted: boolean, mimetype: string): IRenderMime.IRenderer {
let model = new OutputModel({value: output, trusted});
let widget = this.rendermime.createRenderer(mimetype);
widget.renderModel(model);
widget.addClass(RENDERED_OUTPUT_CLASS);
let bundle = OutputModel.getData(output);
if (isBase64(bundle[mimetype] as string)) {
widget.addClass(DATA_IS_BASE64_CLASS);
}
return widget;
}
static canRender(model: OutputDiffModel, rendermime: IRenderMimeRegistry): boolean {
let toTest = model.contents;
for (let o of toTest) {
let bundle = OutputModel.getData(o);
let mimetype = rendermime.preferredMimeType(
bundle,
model.trusted ? 'any' : 'ensure'
);
if (!mimetype) {
return false;
}
}
return true;
}
}