| 1 |
// Copyright (c) Jupyter Development Team. |
| 2 |
// Distributed under the terms of the Modified BSD License. |
| 3 |
import { Widget } from '@lumino/widgets'; |
| 4 |
export const WIDGET_MIMETYPE = 'application/vnd.jupyter.widget-view+json'; |
| 5 |
// Renderer to allow the output widget to render sub-widgets |
| 6 |
export class WidgetRenderer extends Widget { |
| 7 |
constructor(options, manager) { |
| 8 |
super(); |
| 9 |
this.mimeType = options.mimeType; |
| 10 |
this._manager = manager; |
| 11 |
} |
| 12 |
async renderModel(model) { |
| 13 |
const source = model.data[this.mimeType]; |
| 14 |
if (!this._manager.has_model(source.model_id)) { |
| 15 |
this.node.textContent = 'Error creating widget: could not find model'; |
| 16 |
this.addClass('jupyter-widgets'); |
| 17 |
return; |
| 18 |
} |
| 19 |
try { |
| 20 |
const wModel = await this._manager.get_model(source.model_id); |
| 21 |
const wView = await this._manager.create_view(wModel); |
| 22 |
Widget.attach(wView.luminoWidget || wView.pWidget, this.node); |
| 23 |
} |
| 24 |
catch (err) { |
| 25 |
console.log('Error displaying widget'); |
| 26 |
console.log(err); |
| 27 |
this.node.textContent = 'Error displaying widget'; |
| 28 |
this.addClass('jupyter-widgets'); |
| 29 |
} |
| 30 |
} |
| 31 |
} |
| 32 |
//# sourceMappingURL=output_renderers.js.map |