33
44import * as outputBase from '@jupyter-widgets/output' ;
55
6- import { JupyterLuminoPanelWidget } from '@jupyter-widgets/base' ;
7-
8- import { Panel } from '@lumino/widgets' ;
9-
106import { IRenderMimeRegistry } from '@jupyterlab/rendermime' ;
117
12- import { KernelWidgetManager } from './manager' ;
8+ import type { KernelWidgetManager } from './manager' ;
139
14- import { OutputAreaModel , OutputArea } from '@jupyterlab/outputarea' ;
10+ import { OutputArea , OutputAreaModel } from '@jupyterlab/outputarea' ;
1511
1612import * as nbformat from '@jupyterlab/nbformat' ;
1713
18- import { KernelMessage } from '@jupyterlab/services' ;
14+ import type { KernelMessage } from '@jupyterlab/services' ;
1915
2016import $ from 'jquery' ;
2117
18+ import type { Message } from '@lumino/messaging' ;
19+
2220export const OUTPUT_WIDGET_VERSION = outputBase . OUTPUT_WIDGET_VERSION ;
2321
2422export class OutputModel extends outputBase . OutputModel {
@@ -103,9 +101,50 @@ export class OutputModel extends outputBase.OutputModel {
103101 static rendermime : IRenderMimeRegistry ;
104102}
105103
104+ class JupyterOutputArea extends OutputArea {
105+ constructor ( options : JupyterOutputArea . IOptions & OutputArea . IOptions ) {
106+ const view = options . view ;
107+ delete ( options as any ) . view ;
108+ super ( options ) ;
109+ this . _view = view ;
110+ }
111+
112+ processMessage ( msg : Message ) : void {
113+ super . processMessage ( msg ) ;
114+ this . _view ?. processLuminoMessage ( msg ) ;
115+ }
116+ /**
117+ * Dispose the widget.
118+ *
119+ * This causes the view to be destroyed as well with 'remove'
120+ */
121+ dispose ( ) : void {
122+ if ( this . isDisposed ) {
123+ return ;
124+ }
125+ super . dispose ( ) ;
126+ this . _view ?. remove ( ) ;
127+ this . _view = null ! ;
128+ }
129+
130+ private _view : OutputView ;
131+ }
132+
133+ export namespace JupyterOutputArea {
134+ export interface IOptions {
135+ view : OutputView ;
136+ }
137+ }
138+
106139export class OutputView extends outputBase . OutputView {
107140 _createElement ( tagName : string ) : HTMLElement {
108- this . luminoWidget = new JupyterLuminoPanelWidget ( { view : this } ) ;
141+ this . luminoWidget = new JupyterOutputArea ( {
142+ view : this ,
143+ rendermime : OutputModel . rendermime ,
144+ contentFactory : OutputArea . defaultContentFactory ,
145+ model : this . model . outputs ,
146+ promptOverlay : false ,
147+ } ) ;
109148 return this . luminoWidget . node ;
110149 }
111150
@@ -124,29 +163,16 @@ export class OutputView extends outputBase.OutputView {
124163 */
125164 render ( ) : void {
126165 super . render ( ) ;
127- this . _outputView = new OutputArea ( {
128- rendermime : OutputModel . rendermime ,
129- contentFactory : OutputArea . defaultContentFactory ,
130- model : this . model . outputs ,
131- } ) ;
132-
133- // TODO: why is this a readonly property now?
134- // this._outputView.model = this.model.outputs;
135- // TODO: why is this on the model now?
136- // this._outputView.trusted = true;
137- this . luminoWidget . insertWidget ( 0 , this . _outputView ) ;
138-
139166 this . luminoWidget . addClass ( 'jupyter-widgets' ) ;
140- this . luminoWidget . addClass ( 'widget-output' ) ;
167+ this . luminoWidget . addClass ( 'jupyter- widget-output' ) ;
141168 this . update ( ) ; // Set defaults.
142169 }
143170
144171 remove ( ) : any {
145- this . _outputView . dispose ( ) ;
172+ this . luminoWidget . dispose ( ) ;
146173 return super . remove ( ) ;
147174 }
148175
149176 model : OutputModel ;
150- _outputView : OutputArea ;
151- luminoWidget : Panel ;
177+ luminoWidget : OutputArea ;
152178}
0 commit comments