@@ -30,13 +30,6 @@ interface BoundingBox {
3030 y : number ;
3131}
3232
33- function asArrayOrNull < T > ( value : T ) : T [ ] | null {
34- if ( ! value ) {
35- return null ;
36- }
37- return [ value ] ;
38- }
39-
4033/**
4134 * Performs most of the work of converting a slide into API requests.
4235 *
@@ -72,10 +65,9 @@ export default class GenericLayout {
7265 }
7366
7467 public appendContentRequests ( requests : SlidesV1 . Schema$Request [ ] ) : SlidesV1 . Schema$Request [ ] {
75- this . appendFillPlaceholderTextRequest ( asArrayOrNull ( this . slide . title ) , 'TITLE' , requests ) ;
76- this . appendFillPlaceholderTextRequest ( asArrayOrNull ( this . slide . title ) , 'CENTERED_TITLE' , requests ) ;
77- this . appendFillPlaceholderTextRequest ( asArrayOrNull ( this . slide . subtitle ) , 'SUBTITLE' , requests ) ;
78- this . appendFillPlaceholderTextRequest ( this . slide . bodies , 'BODY' , requests ) ;
68+ this . appendFillPlaceholderTextRequest ( this . slide . title , 'TITLE' , requests ) ;
69+ this . appendFillPlaceholderTextRequest ( this . slide . title , 'CENTERED_TITLE' , requests ) ;
70+ this . appendFillPlaceholderTextRequest ( this . slide . subtitle , 'SUBTITLE' , requests ) ;
7971
8072 if ( this . slide . backgroundImage ) {
8173 this . appendSetBackgroundImageRequest ( this . slide . backgroundImage , requests ) ;
@@ -85,12 +77,18 @@ export default class GenericLayout {
8577 this . appendCreateTableRequests ( this . slide . tables , requests ) ;
8678 }
8779
88- if ( this . slide . images . length ) {
89- this . appendCreateImageRequests ( this . slide . images , requests ) ;
90- }
91-
92- if ( this . slide . videos . length ) {
93- this . appendCreateVideoRequests ( this . slide . videos , requests ) ;
80+ if ( this . slide . bodies ) {
81+ const bodyElements = findPlaceholder ( this . presentation , this . slide . objectId , 'BODY' ) ;
82+ this . slide . bodies . forEach ( ( body , index ) => {
83+ let placeholder = bodyElements [ index ] ;
84+ this . appendFillPlaceholderTextRequest ( body . text , placeholder , requests ) ;
85+ if ( body . images && body . images . length ) {
86+ this . appendCreateImageRequests ( body . images , placeholder , requests ) ;
87+ }
88+ if ( body . videos && body . videos . length ) {
89+ this . appendCreateVideoRequests ( body . videos , placeholder , requests ) ;
90+ }
91+ } ) ;
9492 }
9593
9694 if ( this . slide . notes ) {
@@ -102,28 +100,25 @@ export default class GenericLayout {
102100 }
103101
104102 protected appendFillPlaceholderTextRequest (
105- values : TextDefinition [ ] ,
106- placeholderName : string ,
103+ value : TextDefinition ,
104+ placeholder : string | SlidesV1 . Schema$PageElement ,
107105 requests : SlidesV1 . Schema$Request [ ] ,
108106 ) : SlidesV1 . Schema$Request [ ] {
109- if ( ! ( values && values . length ) ) {
110- debug ( 'No text for placeholder %s' , placeholderName ) ;
107+ if ( ! value ) {
108+ debug ( 'No text for placeholder %s' ) ;
111109 return ;
112110 }
113111
114- const pageElements = findPlaceholder ( this . presentation , this . slide . objectId , placeholderName ) ;
115- if ( ! pageElements ) {
116- debug ( 'Skipping undefined placeholder %s' , placeholderName ) ;
117- return ;
118- }
119-
120- for ( let i in pageElements ) {
121- if ( values [ i ] != undefined ) {
122- debug ( 'Slide #%d: setting %s[%d] to %s' , this . slide . index , placeholderName , i , values [ i ] . rawText ) ;
123- let id = pageElements [ i ] . objectId ;
124- this . appendInsertTextRequests ( values [ i ] , { objectId : id } , requests ) ;
112+ if ( typeof placeholder === 'string' ) {
113+ const pageElements = findPlaceholder ( this . presentation , this . slide . objectId , placeholder ) ;
114+ if ( ! pageElements ) {
115+ debug ( 'Skipping undefined placeholder %s' , placeholder ) ;
116+ return ;
125117 }
118+ placeholder = pageElements [ 0 ] ;
126119 }
120+
121+ this . appendInsertTextRequests ( value , { objectId : placeholder . objectId } , requests ) ;
127122 }
128123
129124 protected appendInsertTextRequests ( text : TextDefinition , locationProps , requests : SlidesV1 . Schema$Request [ ] ) : void {
@@ -215,7 +210,7 @@ export default class GenericLayout {
215210 } ) ;
216211 }
217212
218- protected appendCreateImageRequests ( images , requests : SlidesV1 . Schema$Request [ ] ) : void {
213+ protected appendCreateImageRequests ( images , placeholder , requests : SlidesV1 . Schema$Request [ ] ) : void {
219214 // TODO - Fix weird cast
220215 const layer = ( Layout as ( s : string ) => Layout . PackingSmith ) ( 'left-right' ) ; // TODO - Configurable?
221216 for ( let image of images ) {
@@ -227,7 +222,7 @@ export default class GenericLayout {
227222 } ) ;
228223 }
229224
230- const box = this . getBodyBoundingBox ( false ) ;
225+ const box = this . getBodyBoundingBox ( placeholder ) ;
231226 const computedLayout = layer . export ( ) ;
232227
233228 let scaleRatio = Math . min ( box . width / computedLayout . width , box . height / computedLayout . height ) ;
@@ -277,15 +272,19 @@ export default class GenericLayout {
277272 }
278273 }
279274
280- protected appendCreateVideoRequests ( videos : VideoDefinition [ ] , requests : SlidesV1 . Schema$Request [ ] ) : void {
275+ protected appendCreateVideoRequests (
276+ videos : VideoDefinition [ ] ,
277+ placeholder ,
278+ requests : SlidesV1 . Schema$Request [ ] ,
279+ ) : void {
281280 if ( videos . length > 1 ) {
282281 throw new Error ( 'Multiple videos per slide are not supported.' ) ;
283282 }
284283 const video = videos [ 0 ] ;
285284
286285 debug ( 'Slide #%d: adding video %s' , this . slide . index , video . id ) ;
287286
288- const box = this . getBodyBoundingBox ( false ) ;
287+ const box = this . getBodyBoundingBox ( placeholder ) ;
289288
290289 const scaleRatio = Math . min ( box . width / video . width , box . height / video . height ) ;
291290
@@ -389,10 +388,9 @@ export default class GenericLayout {
389388 } ;
390389 }
391390
392- protected getBodyBoundingBox ( fullScreen : boolean ) : BoundingBox {
393- const body = findPlaceholder ( this . presentation , this . slide . objectId , 'BODY' ) ;
394- if ( body && ! fullScreen ) {
395- return this . calculateBoundingBox ( body [ 0 ] ) ;
391+ protected getBodyBoundingBox ( placeholder ) : BoundingBox {
392+ if ( placeholder ) {
393+ return this . calculateBoundingBox ( placeholder ) ;
396394 }
397395 return {
398396 width : this . presentation . pageSize . width . magnitude ,
0 commit comments