11import { ICollaborativeDrive } from '@jupyter/collaborative-drive' ;
2- import { JupyterGISPanel } from '@jupytergis/base' ;
3- import { JupyterGISModel , IJupyterGISDoc } from '@jupytergis/schema' ;
4-
2+ import {
3+ JupyterGISOutputWidget ,
4+ JupyterGISPanel ,
5+ JupyterGISTracker ,
6+ ToolbarWidget
7+ } from '@jupytergis/base' ;
8+ import {
9+ IJGISExternalCommandRegistry ,
10+ IJGISExternalCommandRegistryToken ,
11+ IJupyterGISDoc ,
12+ IJupyterGISDocTracker ,
13+ IJupyterGISWidgetContext ,
14+ JupyterGISModel
15+ } from '@jupytergis/schema' ;
516import {
617 JupyterFrontEnd ,
718 JupyterFrontEndPlugin
819} from '@jupyterlab/application' ;
920import { Contents } from '@jupyterlab/services' ;
21+ import { CommandRegistry } from '@lumino/commands' ;
1022import { MessageLoop } from '@lumino/messaging' ;
1123import { Panel , Widget } from '@lumino/widgets' ;
1224import * as Y from 'yjs' ;
@@ -31,14 +43,37 @@ export class YJupyterGISModel extends JupyterYModel {
3143}
3244
3345export class YJupyterGISLuminoWidget extends Panel {
34- constructor ( options : { model : JupyterGISModel } ) {
46+ constructor ( options : {
47+ commands : CommandRegistry ;
48+ model : JupyterGISModel ;
49+ externalCommands : IJGISExternalCommandRegistry ;
50+ } ) {
3551 super ( ) ;
36-
52+ const { commands , model , externalCommands } = options ;
3753 this . addClass ( CLASS_NAME ) ;
38- this . _jgisWidget = new JupyterGISPanel ( options ) ;
54+ const content = new JupyterGISPanel ( { model } ) ;
55+ const toolbar = new ToolbarWidget ( {
56+ commands,
57+ model,
58+ externalCommands : externalCommands . getCommands ( )
59+ } ) ;
60+ const context : IJupyterGISWidgetContext = {
61+ model,
62+ path : model . filePath
63+ } ;
64+ this . _jgisWidget = new JupyterGISOutputWidget ( {
65+ context,
66+ content,
67+ toolbar
68+ } ) ;
69+
3970 this . addWidget ( this . _jgisWidget ) ;
4071 }
4172
73+ get jgisWidget ( ) : JupyterGISOutputWidget {
74+ return this . _jgisWidget ;
75+ }
76+
4277 onResize = ( ) : void => {
4378 if ( this . _jgisWidget ) {
4479 MessageLoop . sendMessage (
@@ -48,15 +83,22 @@ export class YJupyterGISLuminoWidget extends Panel {
4883 }
4984 } ;
5085
51- private _jgisWidget : JupyterGISPanel ;
86+ private _jgisWidget : JupyterGISOutputWidget ;
5287}
5388
5489export const notebookRendererPlugin : JupyterFrontEndPlugin < void > = {
5590 id : 'jupytergis:yjswidget-plugin' ,
5691 autoStart : true ,
57- optional : [ IJupyterYWidgetManager , ICollaborativeDrive ] ,
92+ optional : [
93+ IJGISExternalCommandRegistryToken ,
94+ IJupyterGISDocTracker ,
95+ IJupyterYWidgetManager ,
96+ ICollaborativeDrive
97+ ] ,
5898 activate : (
5999 app : JupyterFrontEnd ,
100+ externalCommandRegistry : IJGISExternalCommandRegistry ,
101+ jgisTracker : JupyterGISTracker ,
60102 yWidgetManager ?: IJupyterYWidgetManager ,
61103 drive ?: ICollaborativeDrive
62104 ) : void => {
@@ -75,7 +117,6 @@ export const notebookRendererPlugin: JupyterFrontEndPlugin<void> = {
75117 const { path, format, contentType } = commMetadata ;
76118
77119 const fileFormat = format as Contents . FileFormat ;
78-
79120 const sharedModel = drive ! . sharedModelFactory . createNew ( {
80121 path,
81122 format : fileFormat ,
@@ -85,7 +126,24 @@ export const notebookRendererPlugin: JupyterFrontEndPlugin<void> = {
85126 this . jupyterGISModel = new JupyterGISModel ( {
86127 sharedModel : sharedModel as IJupyterGISDoc
87128 } ) ;
88-
129+ const onchange = ( _ : any , args : any ) => {
130+ if ( args . stateChange ) {
131+ args . stateChange . forEach ( ( change : any ) => {
132+ if ( change . name === 'path' ) {
133+ this . jupyterGISModel . filePath = change . newValue ;
134+ }
135+ } ) ;
136+ }
137+ } ;
138+
139+ this . jupyterGISModel . contentsManager = app . serviceManager . contents ;
140+ sharedModel . changed . connect ( onchange ) ;
141+
142+ if ( sharedModel . getState ( 'path' ) ) {
143+ this . jupyterGISModel . filePath = sharedModel . getState (
144+ 'path'
145+ ) as string ;
146+ }
89147 return this . jupyterGISModel . sharedModel . ydoc ;
90148 }
91149 }
@@ -96,10 +154,12 @@ export const notebookRendererPlugin: JupyterFrontEndPlugin<void> = {
96154 this . node = node ;
97155
98156 const widget = new YJupyterGISLuminoWidget ( {
99- model : yModel . jupyterGISModel
157+ commands : app . commands ,
158+ model : yModel . jupyterGISModel ,
159+ externalCommands : externalCommandRegistry
100160 } ) ;
101161 // Widget.attach(widget, node);
102-
162+ jgisTracker . add ( widget . jgisWidget ) ;
103163 MessageLoop . sendMessage ( widget , Widget . Msg . BeforeAttach ) ;
104164 node . appendChild ( widget . node ) ;
105165 MessageLoop . sendMessage ( widget , Widget . Msg . AfterAttach ) ;
0 commit comments