@@ -7,12 +7,20 @@ import { jsonIcon } from '@jupyterlab/ui-components';
77import { WidgetTracker , ICommandPalette } from '@jupyterlab/apputils' ;
88import { IRenderMimeRegistry } from '@jupyterlab/rendermime' ;
99import { IEditorServices } from '@jupyterlab/codeeditor' ;
10+ import { CodeCell } from '@jupyterlab/cells' ;
1011import { IFileBrowserFactory } from '@jupyterlab/filebrowser' ;
1112import { ILauncher } from '@jupyterlab/launcher' ;
1213import { ITranslator } from '@jupyterlab/translation' ;
1314import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
1415import { IKernelMenu , IMainMenu } from '@jupyterlab/mainmenu' ;
1516
17+ import { IJupyterWidgetRegistry } from '@jupyter-widgets/base' ;
18+
19+ import {
20+ WidgetRenderer ,
21+ registerWidgetManager
22+ } from '@jupyter-widgets/jupyterlab-manager' ;
23+
1624import { BlocklyEditorFactory } from 'jupyterlab-blockly' ;
1725import { IBlocklyRegistry } from 'jupyterlab-blockly' ;
1826import { BlocklyEditor } from 'jupyterlab-blockly' ;
@@ -49,7 +57,7 @@ const plugin: JupyterFrontEndPlugin<IBlocklyRegistry> = {
4957 ISettingRegistry ,
5058 ITranslator
5159 ] ,
52- optional : [ ILauncher , ICommandPalette , IMainMenu ] ,
60+ optional : [ ILauncher , ICommandPalette , IMainMenu , IJupyterWidgetRegistry ] ,
5361 provides : IBlocklyRegistry ,
5462 activate : (
5563 app : JupyterFrontEnd ,
@@ -61,7 +69,8 @@ const plugin: JupyterFrontEndPlugin<IBlocklyRegistry> = {
6169 translator : ITranslator ,
6270 launcher : ILauncher | null ,
6371 palette : ICommandPalette | null ,
64- mainMenu : IMainMenu | null
72+ mainMenu : IMainMenu | null ,
73+ widgetRegistry : IJupyterWidgetRegistry | null
6574 ) : IBlocklyRegistry => {
6675 console . log ( 'JupyterLab extension jupyterlab-blocky is activated!' ) ;
6776
@@ -233,8 +242,34 @@ const plugin: JupyterFrontEndPlugin<IBlocklyRegistry> = {
233242 } as IKernelMenu . IKernelUser < BlocklyEditor > ) ;
234243 }
235244
245+ if ( widgetRegistry ) {
246+ tracker . forEach ( panel => {
247+ registerWidgetManager (
248+ panel . context as any ,
249+ panel . content . rendermime ,
250+ widgetRenderers ( [ panel . content . cell ] )
251+ ) ;
252+ } ) ;
253+
254+ tracker . widgetAdded . connect ( ( sender , panel ) => {
255+ registerWidgetManager (
256+ panel . context as any ,
257+ panel . content . rendermime ,
258+ widgetRenderers ( [ panel . content . cell ] )
259+ ) ;
260+ } ) ;
261+ }
262+
236263 return widgetFactory . registry ;
237264 }
238265} ;
239266
267+ function * widgetRenderers ( cells : CodeCell [ ] ) : IterableIterator < WidgetRenderer > {
268+ for ( const w of cells ) {
269+ if ( w instanceof WidgetRenderer ) {
270+ yield w ;
271+ }
272+ }
273+ }
274+
240275export default plugin ;
0 commit comments