@@ -753,12 +753,38 @@ export class YCodeCell
753
753
set outputs ( v : Array < nbformat . IOutput > ) {
754
754
this . setOutputs ( v ) ;
755
755
}
756
+ get youtputs ( ) : Y . Array < any > {
757
+ return this . _youtputs ;
758
+ }
756
759
757
760
/**
758
761
* Execution, display, or stream outputs.
759
762
*/
760
763
getOutputs ( ) : Array < nbformat . IOutput > {
761
- return JSONExt . deepCopy ( this . _youtputs . toArray ( ) ) ;
764
+ return JSONExt . deepCopy ( this . _youtputs . toJSON ( ) ) ;
765
+ }
766
+
767
+ createOutputs ( outputs : Array < nbformat . IOutput > ) : Array < any > {
768
+ const newOutputs : Array < any > = [ ] ;
769
+ for ( const output of outputs ) {
770
+ let _newOutput : { [ id : string ] : any } ;
771
+ const newOutput = new Y . Map ( ) ;
772
+ if ( output . output_type === 'stream' ) {
773
+ // Set the text field as a Y.Array
774
+ const { text, ...outputWithoutText } = output ;
775
+ _newOutput = outputWithoutText ;
776
+ const newText = new Y . Array ( ) ;
777
+ newText . push ( text as string [ ] ) ;
778
+ _newOutput [ 'text' ] = newText ;
779
+ } else {
780
+ _newOutput = output ;
781
+ }
782
+ for ( const [ key , value ] of Object . entries ( _newOutput ) ) {
783
+ newOutput . set ( key , value ) ;
784
+ }
785
+ newOutputs . push ( newOutput ) ;
786
+ }
787
+ return newOutputs ;
762
788
}
763
789
764
790
/**
@@ -767,7 +793,8 @@ export class YCodeCell
767
793
setOutputs ( outputs : Array < nbformat . IOutput > ) : void {
768
794
this . transact ( ( ) => {
769
795
this . _youtputs . delete ( 0 , this . _youtputs . length ) ;
770
- this . _youtputs . insert ( 0 , outputs ) ;
796
+ const newOutputs = this . createOutputs ( outputs ) ;
797
+ this . _youtputs . insert ( 0 , newOutputs ) ;
771
798
} , false ) ;
772
799
}
773
800
@@ -789,7 +816,8 @@ export class YCodeCell
789
816
end < this . _youtputs . length ? end - start : this . _youtputs . length - start ;
790
817
this . transact ( ( ) => {
791
818
this . _youtputs . delete ( start , fin ) ;
792
- this . _youtputs . insert ( start , outputs ) ;
819
+ const newOutputs = this . createOutputs ( outputs ) ;
820
+ this . _youtputs . insert ( start , newOutputs ) ;
793
821
} , false ) ;
794
822
}
795
823
0 commit comments