Skip to content

Commit 5932009

Browse files
committed
Adds a split panel and improve the cell
1 parent ac271b4 commit 5932009

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

packages/blockly-extension/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ const plugin: JupyterFrontEndPlugin<IBlocklyRegistry> = {
210210
tracker,
211211
interruptKernel: current => {
212212
const kernel = current.context.sessionContext.session?.kernel;
213-
console.debug('Interrupt:', kernel);
214213
if (kernel) {
215214
return kernel.interrupt();
216215
}

packages/blockly/src/layout.ts

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { CodeCell, CodeCellModel } from '@jupyterlab/cells';
44

55
import { Message } from '@lumino/messaging';
66
import { PartialJSONValue } from '@lumino/coreutils';
7-
import { PanelLayout, Widget } from '@lumino/widgets';
7+
import { SplitLayout, SplitPanel, Widget } from '@lumino/widgets';
88
import { IIterator, ArrayIterator } from '@lumino/algorithm';
99
import { Signal } from '@lumino/signaling';
1010

@@ -16,8 +16,8 @@ import { THEME } from './utils';
1616
/**
1717
* A blockly layout to host the Blockly editor.
1818
*/
19-
export class BlocklyLayout extends PanelLayout {
20-
private _host: HTMLElement;
19+
export class BlocklyLayout extends SplitLayout {
20+
private _host: Widget;
2121
private _manager: BlocklyManager;
2222
private _workspace: Blockly.WorkspaceSvg;
2323
private _sessionContext: ISessionContext;
@@ -32,13 +32,13 @@ export class BlocklyLayout extends PanelLayout {
3232
sessionContext: ISessionContext,
3333
rendermime: IRenderMimeRegistry
3434
) {
35-
super();
35+
super({ renderer: SplitPanel.defaultRenderer, orientation: 'vertical' });
3636
this._manager = manager;
3737
this._sessionContext = sessionContext;
3838

3939
// Creating the container for the Blockly editor
4040
// and the output area to render the execution replies.
41-
this._host = document.createElement('div');
41+
this._host = new Widget();
4242

4343
// Creating a CodeCell widget to render the code and
4444
// outputs from the execution reply.
@@ -83,7 +83,8 @@ export class BlocklyLayout extends PanelLayout {
8383
init(): void {
8484
super.init();
8585
// Add the blockly container into the DOM
86-
this.addWidget(new Widget({ node: this._host }));
86+
this.addWidget(this._host);
87+
this.addWidget(this._cell);
8788
}
8889

8990
/**
@@ -141,8 +142,6 @@ export class BlocklyLayout extends PanelLayout {
141142
const code =
142143
extra_init + this._manager.generator.workspaceToCode(this._workspace);
143144
this._cell.model.sharedModel.setSource(code);
144-
this.addWidget(this._cell);
145-
this._resizeWorkspace();
146145

147146
// Execute the code using the kernel, by using a static method from the
148147
// same class to make an execution request.
@@ -165,49 +164,49 @@ export class BlocklyLayout extends PanelLayout {
165164
* Handle `update-request` messages sent to the widget.
166165
*/
167166
protected onUpdateRequest(msg: Message): void {
167+
super.onUpdateRequest(msg);
168168
this._resizeWorkspace();
169169
}
170170

171171
/**
172172
* Handle `resize-request` messages sent to the widget.
173173
*/
174-
protected onResize(msg: Message): void {
174+
protected onResize(msg: Widget.ResizeMessage): void {
175+
super.onResize(msg);
175176
this._resizeWorkspace();
176177
}
177178

178179
/**
179180
* Handle `fit-request` messages sent to the widget.
180181
*/
181182
protected onFitRequest(msg: Message): void {
183+
super.onFitRequest(msg);
182184
this._resizeWorkspace();
183185
}
184186

185187
/**
186188
* Handle `after-attach` messages sent to the widget.
187189
*/
188190
protected onAfterAttach(msg: Message): void {
191+
super.onAfterAttach(msg);
189192
//inject Blockly with appropiate JupyterLab theme.
190-
this._workspace = Blockly.inject(this._host, {
193+
this._workspace = Blockly.inject(this._host.node, {
191194
toolbox: this._manager.toolbox,
192195
theme: THEME
193196
});
197+
198+
this._workspace.addChangeListener(() => {
199+
// Get extra code from the blocks in the workspace.
200+
const extra_init = this.getBlocksToplevelInit();
201+
// Serializing our workspace into the chosen language generator.
202+
const code =
203+
extra_init + this._manager.generator.workspaceToCode(this._workspace);
204+
this._cell.model.sharedModel.setSource(code);
205+
});
194206
}
195207

196208
private _resizeWorkspace(): void {
197209
//Resize logic.
198-
const rect = this.parent.node.getBoundingClientRect();
199-
const { height } = this._cell.node.getBoundingClientRect();
200-
const margin = rect.height / 3;
201-
202-
if (height > margin) {
203-
this._host.style.height = rect.height - margin + 'px';
204-
this._cell.node.style.height = margin + 'px';
205-
this._cell.node.style.overflowY = 'scroll';
206-
} else {
207-
this._host.style.height = rect.height - height + 'px';
208-
this._cell.node.style.overflowY = 'scroll';
209-
}
210-
211210
Blockly.svgResize(this._workspace);
212211
}
213212

packages/blockly/src/widget.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
77
import { runIcon } from '@jupyterlab/ui-components';
88

9-
import { Panel } from '@lumino/widgets';
9+
import { SplitPanel } from '@lumino/widgets';
1010
import { Signal } from '@lumino/signaling';
1111

1212
import { BlocklyLayout } from './layout';
@@ -76,7 +76,7 @@ export namespace BlocklyEditor {
7676
/**
7777
* Widget that contains the main view of the DocumentWidget.
7878
*/
79-
export class BlocklyPanel extends Panel {
79+
export class BlocklyPanel extends SplitPanel {
8080
private _context: DocumentRegistry.IContext<DocumentModel>;
8181

8282
/**

0 commit comments

Comments
 (0)