1
+ import { SimplifiedOutputArea , OutputAreaModel } from '@jupyterlab/outputarea' ;
1
2
import { IRenderMimeRegistry } from '@jupyterlab/rendermime' ;
2
3
import { ISessionContext } from '@jupyterlab/apputils' ;
3
4
@@ -18,8 +19,8 @@ export class BlocklyLayout extends PanelLayout {
18
19
private _host : HTMLElement ;
19
20
private _manager : BlocklyManager ;
20
21
private _workspace : Blockly . WorkspaceSvg ;
21
- // private _sessionContext: ISessionContext;
22
- private _outputArea : Widget ;
22
+ private _sessionContext : ISessionContext ;
23
+ private _outputArea : SimplifiedOutputArea ;
23
24
24
25
/**
25
26
* Construct a `BlocklyLayout`.
@@ -32,12 +33,18 @@ export class BlocklyLayout extends PanelLayout {
32
33
) {
33
34
super ( ) ;
34
35
this . _manager = manager ;
35
- // this._sessionContext = sessionContext;
36
+ this . _sessionContext = sessionContext ;
36
37
37
38
// Creating the container for the Blockly editor
38
39
// and the output area to render the execution replies.
39
40
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
+ } ) ;
41
48
}
42
49
43
50
get workspace ( ) : PartialJSONValue {
@@ -86,8 +93,17 @@ export class BlocklyLayout extends PanelLayout {
86
93
}
87
94
88
95
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 ) ) ;
91
107
}
92
108
93
109
/**
0 commit comments