Debian Codegraph @

jupyter-widgets-html-manager/lib/output.js

raw
1 // Copyright (c) Jupyter Development Team.
2 // Distributed under the terms of the Modified BSD License.
3 import * as outputBase from '@jupyter-widgets/output';
4 import { JupyterLuminoPanelWidget } from '@jupyter-widgets/base';
5 import { OutputAreaModel, OutputArea } from '@jupyterlab/outputarea';
6 import $ from 'jquery';
7 import '../css/output.css';
8 export class OutputModel extends outputBase.OutputModel {
9 defaults() {
10 return Object.assign(Object.assign({}, super.defaults()), { msg_id: '', outputs: [] });
11 }
12 initialize(attributes, options) {
13 super.initialize(attributes, options);
14 this._outputs = new OutputAreaModel({ trusted: true });
15 this.listenTo(this, 'change:outputs', this.setOutputs);
16 this.setOutputs();
17 }
18 get outputs() {
19 return this._outputs;
20 }
21 clear_output(wait = false) {
22 this._outputs.clear(wait);
23 }
24 setOutputs(model, value, options) {
25 if (!(options && options.newMessage)) {
26 // fromJSON does not clear the existing output
27 this.clear_output();
28 // fromJSON does not copy the message, so we make a deep copy
29 this._outputs.fromJSON(JSON.parse(JSON.stringify(this.get('outputs'))));
30 }
31 }
32 }
33 export class OutputView extends outputBase.OutputView {
34 _createElement(tagName) {
35 this.luminoWidget = new JupyterLuminoPanelWidget({ view: this });
36 return this.luminoWidget.node;
37 }
38 _setElement(el) {
39 if (this.el || el !== this.luminoWidget.node) {
40 // Boxes don't allow setting the element beyond the initial creation.
41 throw new Error('Cannot reset the DOM element.');
42 }
43 this.el = this.luminoWidget.node;
44 this.$el = $(this.luminoWidget.node);
45 }
46 render() {
47 super.render();
48 this._outputView = new OutputArea({
49 rendermime: this.model.widget_manager.renderMime,
50 model: this.model.outputs,
51 });
52 this.luminoWidget.insertWidget(0, this._outputView);
53 this.luminoWidget.addClass('jupyter-widgets');
54 this.luminoWidget.addClass('widget-output');
55 this.update();
56 }
57 remove() {
58 this._outputView.dispose();
59 return super.remove();
60 }
61 }
62 //# sourceMappingURL=output.js.map