@@ -23,7 +23,7 @@ import { IInteractiveWindowMapping, IPyWidgetMessages, InteractiveWindowMessages
23
23
import { WIDGET_MIMETYPE , WIDGET_STATE_MIMETYPE } from '../../../../platform/common/constants' ;
24
24
import { NotebookMetadata } from '../../../../platform/common/utils' ;
25
25
import { noop } from '../../../../platform/common/utils/misc' ;
26
- import type { RendererContext } from 'vscode-notebook-renderer' ;
26
+ import type { OutputItem , RendererContext } from 'vscode-notebook-renderer' ;
27
27
import { renderersAndMimetypes } from './mimeTypes' ;
28
28
import { base64ToUint8Array } from '../../../../platform/common/utils/string' ;
29
29
@@ -246,35 +246,47 @@ export class WidgetManager implements IIPyWidgetManager, IMessageHandler {
246
246
const context = ( globalThis as any ) . jupyter_vscode_rendererContext as RendererContext < any > ;
247
247
const renderer = await context . getRenderer ( rendererId ) ;
248
248
const isImage = mime . toLowerCase ( ) . startsWith ( 'image/' ) && ! mime . toLowerCase ( ) . includes ( 'svg' ) ;
249
- renderer ?. renderOutputItem (
250
- {
251
- id : new Date ( ) . getTime ( ) . toString ( ) , // Not used except when saving plots, but with nested outputs, thats not possible.
252
- metadata,
253
- text : ( ) => {
254
- return JSON . stringify ( data [ mime ] ) ;
249
+ const renderOutputItem = renderer ?. renderOutputItem as
250
+ | undefined
251
+ | ( ( outputItem : OutputItem , element : HTMLElement , signal : AbortSignal ) => void ) ;
252
+ if ( renderOutputItem ) {
253
+ renderOutputItem (
254
+ {
255
+ id : new Date ( ) . getTime ( ) . toString ( ) , // Not used except when saving plots, but with nested outputs, thats not possible.
256
+ metadata,
257
+ text : ( ) => {
258
+ if (
259
+ ( mime . startsWith ( 'text/' ) || mime . startsWith ( 'image/svg+xml' ) ) &&
260
+ typeof data [ mime ] === 'string'
261
+ ) {
262
+ return data [ mime ] as string ;
263
+ }
264
+ return JSON . stringify ( data [ mime ] ) ;
265
+ } ,
266
+ json : ( ) => {
267
+ return data [ mime ] ;
268
+ } ,
269
+ blob ( ) {
270
+ if ( isImage ) {
271
+ const bytes = base64ToUint8Array ( data [ mime ] as string ) ;
272
+ return new Blob ( [ bytes ] , { type : mime } ) ;
273
+ } else {
274
+ throw new Error ( `Not able to get blob for ${ mime } .` ) ;
275
+ }
276
+ } ,
277
+ data ( ) {
278
+ if ( isImage ) {
279
+ return base64ToUint8Array ( data [ mime ] as string ) ;
280
+ } else {
281
+ throw new Error ( `Not able to get blob for ${ mime } .` ) ;
282
+ }
283
+ } ,
284
+ mime
255
285
} ,
256
- json : ( ) => {
257
- return data [ mime ] ;
258
- } ,
259
- blob ( ) {
260
- if ( isImage ) {
261
- const bytes = base64ToUint8Array ( data [ mime ] as string ) ;
262
- return new Blob ( [ bytes ] , { type : mime } ) ;
263
- } else {
264
- throw new Error ( `Not able to get blob for ${ mime } .` ) ;
265
- }
266
- } ,
267
- data ( ) {
268
- if ( isImage ) {
269
- return base64ToUint8Array ( data [ mime ] as string ) ;
270
- } else {
271
- throw new Error ( `Not able to get blob for ${ mime } .` ) ;
272
- }
273
- } ,
274
- mime
275
- } ,
276
- node
277
- ) ;
286
+ node ,
287
+ new AbortController ( ) . signal
288
+ ) ;
289
+ }
278
290
} ) ;
279
291
} ) ;
280
292
} ) ;
0 commit comments