Skip to content

Commit 119a5bf

Browse files
author
Alan Fleming
committed
Output widget - modified so layout applies to the OutputArea directly and prompt width is 0.
1 parent fb8adbe commit 119a5bf

File tree

2 files changed

+62
-24
lines changed

2 files changed

+62
-24
lines changed

packages/controls/css/widgets-base.css

+12
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@
125125
flex-direction: column;
126126
}
127127

128+
.jupyter-widget-output {
129+
box-sizing: border-box;
130+
display: flex;
131+
margin: 0;
132+
overflow: auto;
133+
flex-direction: column;
134+
}
135+
.jupyter-widget-output .jp-OutputArea-prompt{
136+
width: 0;
137+
flex : 0;
138+
}
139+
128140
/* General Tags Styling */
129141

130142
.jupyter-widget-tagsinput {

python/jupyterlab_widgets/src/output.ts

+50-24
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,20 @@
33

44
import * as outputBase from '@jupyter-widgets/output';
55

6-
import { JupyterLuminoPanelWidget } from '@jupyter-widgets/base';
7-
8-
import { Panel } from '@lumino/widgets';
9-
106
import { 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

1612
import * as nbformat from '@jupyterlab/nbformat';
1713

18-
import { KernelMessage } from '@jupyterlab/services';
14+
import type { KernelMessage } from '@jupyterlab/services';
1915

2016
import $ from 'jquery';
2117

18+
import type { Message } from '@lumino/messaging';
19+
2220
export const OUTPUT_WIDGET_VERSION = outputBase.OUTPUT_WIDGET_VERSION;
2321

2422
export 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+
106139
export 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

Comments
 (0)