1+ import { SimplifiedOutputArea , OutputAreaModel } from '@jupyterlab/outputarea' ;
12import { IRenderMimeRegistry } from '@jupyterlab/rendermime' ;
23import { ISessionContext } from '@jupyterlab/apputils' ;
34
@@ -18,8 +19,8 @@ export class BlocklyLayout extends PanelLayout {
1819 private _host : HTMLElement ;
1920 private _manager : BlocklyManager ;
2021 private _workspace : Blockly . WorkspaceSvg ;
21- // private _sessionContext: ISessionContext;
22- private _outputArea : Widget ;
22+ private _sessionContext : ISessionContext ;
23+ private _outputArea : SimplifiedOutputArea ;
2324
2425 /**
2526 * Construct a `BlocklyLayout`.
@@ -32,12 +33,18 @@ export class BlocklyLayout extends PanelLayout {
3233 ) {
3334 super ( ) ;
3435 this . _manager = manager ;
35- // this._sessionContext = sessionContext;
36+ this . _sessionContext = sessionContext ;
3637
3738 // Creating the container for the Blockly editor
3839 // and the output area to render the execution replies.
3940 this . _host = document . createElement ( 'div' ) ;
40- this . _outputArea = new Widget ( ) ;
41+
42+ // Creating a SimplifiedOutputArea widget to render the
43+ // outputs from the execution reply.
44+ this . _outputArea = new SimplifiedOutputArea ( {
45+ model : new OutputAreaModel ( { trusted : true } ) ,
46+ rendermime
47+ } ) ;
4148 }
4249
4350 get workspace ( ) : PartialJSONValue {
@@ -86,8 +93,17 @@ export class BlocklyLayout extends PanelLayout {
8693 }
8794
8895 run ( ) : void {
89- //const code = this._manager.generator.workspaceToCode(this._workspace);
90- // Execute the code using the kernel
96+ // Serializing our workspace into the chosen language generator.
97+ const code = this . _manager . generator . workspaceToCode ( this . _workspace ) ;
98+
99+ // Execute the code using the kernel, by using a static method from the
100+ // same class to make an execution request.
101+ SimplifiedOutputArea . execute ( code , this . _outputArea , this . _sessionContext )
102+ . then ( resp => {
103+ this . addWidget ( this . _outputArea ) ;
104+ this . _resizeWorkspace ( ) ;
105+ } )
106+ . catch ( e => console . error ( e ) ) ;
91107 }
92108
93109 /**
0 commit comments