@@ -139,9 +139,19 @@ class WidgetManager extends ManagerBase<Widget> implements IDisposable {
139
139
*/
140
140
private _saveState ( ) {
141
141
const state = this . get_state_sync ( { drop_defaults : true } ) ;
142
- this . _context . model . metadata . set ( 'widgets' , {
143
- 'application/vnd.jupyter.widget-state+json' : state
144
- } ) ;
142
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
143
+ // @ts -ignore JupyterLab 4 support
144
+ if ( this . _context . model . setMetadata ) {
145
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
146
+ // @ts -ignore JupyterLab 4 support
147
+ this . _context . model . setMetadata ( 'widgets' , {
148
+ 'application/vnd.jupyter.widget-state+json' : state ,
149
+ } ) ;
150
+ } else {
151
+ this . _context . model . metadata . set ( 'widgets' , {
152
+ 'application/vnd.jupyter.widget-state+json' : state
153
+ } ) ;
154
+ }
145
155
}
146
156
147
157
/**
@@ -228,7 +238,13 @@ class WidgetManager extends ManagerBase<Widget> implements IDisposable {
228
238
* Load widget state from notebook metadata
229
239
*/
230
240
async _loadFromNotebook ( notebook : INotebookModel ) : Promise < void > {
231
- const widget_md = notebook . metadata . get ( 'widgets' ) as any ;
241
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
242
+ // @ts -ignore JupyterLab 4 support
243
+ const widget_md = notebook . getMetadata
244
+ ? // eslint-disable-next-line @typescript-eslint/ban-ts-comment
245
+ // @ts -ignore JupyterLab 4 support
246
+ ( notebook . getMetadata ( 'widgets' ) as any )
247
+ : notebook . metadata . get ( 'widgets' ) ;
232
248
// Restore any widgets from saved state that are not live
233
249
if ( widget_md && widget_md [ WIDGET_STATE_MIMETYPE ] ) {
234
250
let state = widget_md [ WIDGET_STATE_MIMETYPE ] ;
0 commit comments