@@ -12,6 +12,7 @@ import { compile as convertVegaLiteSpecToVega } from 'vega-lite';
1212import { produce } from 'immer' ;
1313import { SqlBlockConverter } from './converters/sqlBlockConverter' ;
1414import { TextBlockConverter } from './converters/textBlockConverter' ;
15+ // @ts -ignore - types_unstable path doesn't resolve correctly in some TypeScript configurations
1516import type { Field , LayerSpec , TopLevel } from 'vega-lite/types_unstable' ;
1617import { ChartBigNumberBlockConverter } from './converters/chartBigNumberBlockConverter' ;
1718import {
@@ -362,22 +363,30 @@ export class DeepnoteDataConverter {
362363 }
363364
364365 if ( data [ 'application/vnd.vegalite.v5+json' ] ) {
365- const patchedVegaLiteSpec = produce (
366- data [ 'application/vnd.vegalite.v5+json' ] as TopLevel < LayerSpec < Field > > ,
367- ( draft ) => {
368- draft . height = 'container' ;
369- draft . width = 'container' ;
370-
371- draft . autosize = {
372- type : 'fit'
373- } ;
374- if ( ! draft . config ) {
375- draft . config = { } ;
376- }
377- draft . config . customFormatTypes = true ;
366+ type VegaLiteSpec = TopLevel < LayerSpec < Field > > ;
367+ type VegaLiteConfig = { customFormatTypes ?: boolean } ;
368+ type VegaLiteSpecWithExtensions = VegaLiteSpec & {
369+ height ?: string | number ;
370+ width ?: string | number ;
371+ autosize ?: { type : string } ;
372+ config ?: VegaLiteConfig ;
373+ } ;
374+
375+ const originalSpec = data [ 'application/vnd.vegalite.v5+json' ] as VegaLiteSpecWithExtensions ;
376+
377+ const patchedVegaLiteSpec = produce ( originalSpec , ( draft : VegaLiteSpecWithExtensions ) => {
378+ draft . height = 'container' ;
379+ draft . width = 'container' ;
380+ draft . autosize = {
381+ type : 'fit'
382+ } ;
383+ if ( ! draft . config ) {
384+ draft . config = { } ;
378385 }
379- ) ;
380- const vegaSpec = convertVegaLiteSpecToVega ( patchedVegaLiteSpec ) . spec ;
386+ draft . config . customFormatTypes = true ;
387+ } ) ;
388+
389+ const vegaSpec = convertVegaLiteSpecToVega ( patchedVegaLiteSpec as VegaLiteSpec ) . spec ;
381390 items . push ( NotebookCellOutputItem . json ( vegaSpec , 'application/vnd.vega.v5+json' ) ) ;
382391 }
383392
0 commit comments