@@ -257,25 +257,30 @@ function getTransformedBBox(node) {
257
257
* in case of lr-tb or changing content area...).
258
258
*/
259
259
function checkDimensions ( node , space ) {
260
+ if ( node [ $getTemplateRoot ] ( ) [ $extra ] . firstUnsplittable === null ) {
261
+ return true ;
262
+ }
263
+
260
264
if ( node . w === 0 || node . h === 0 ) {
261
265
return true ;
262
266
}
263
267
264
268
if ( space . width <= 0 || space . height <= 0 ) {
265
- return false ;
269
+ return node [ $getTemplateRoot ] ( ) [ $extra ] . noLayoutFailure ;
266
270
}
267
271
268
272
const parent = node [ $getParent ] ( ) ;
269
- const attempt = ( node [ $extra ] && node [ $extra ] . attempt ) || 0 ;
273
+ const attempt = ( parent [ $extra ] && parent [ $extra ] . attempt ) || 0 ;
270
274
switch ( parent . layout ) {
271
275
case "lr-tb" :
272
276
case "rl-tb" :
273
- switch ( attempt ) {
274
- case 0 : {
275
- let w , h ;
276
- if ( node . w !== "" || node . h !== "" ) {
277
- [ , , w , h ] = getTransformedBBox ( node ) ;
278
- }
277
+ if ( attempt === 0 ) {
278
+ let w , h ;
279
+ if ( node . w !== "" || node . h !== "" ) {
280
+ [ , , w , h ] = getTransformedBBox ( node ) ;
281
+ }
282
+
283
+ if ( ! node [ $getTemplateRoot ] ( ) [ $extra ] . noLayoutFailure ) {
279
284
if ( node . h !== "" && Math . round ( h - space . height ) > 1 ) {
280
285
return false ;
281
286
}
@@ -285,42 +290,51 @@ function checkDimensions(node, space) {
285
290
286
291
return node . minW <= space . width ;
287
292
}
288
- case 1 : {
289
- if ( node . h !== "" && ! node [ $isSplittable ] ( ) ) {
290
- const [ , , , h ] = getTransformedBBox ( node ) ;
291
- if ( Math . round ( h - space . height ) > 1 ) {
292
- return false ;
293
- }
294
- }
295
- return true ;
293
+ if ( node . w !== "" ) {
294
+ return Math . round ( w - space . width ) <= 1 ;
296
295
}
297
- default :
298
- return true ;
296
+ return true ;
299
297
}
300
- case "table" :
301
- case "tb" :
302
- if ( attempt !== 1 && node . h !== "" && ! node [ $isSplittable ] ( ) ) {
298
+ if ( node [ $getTemplateRoot ] ( ) [ $extra ] . noLayoutFailure ) {
299
+ return true ;
300
+ }
301
+
302
+ if ( node . h !== "" && ! node [ $isSplittable ] ( ) ) {
303
303
const [ , , , h ] = getTransformedBBox ( node ) ;
304
304
if ( Math . round ( h - space . height ) > 1 ) {
305
305
return false ;
306
306
}
307
307
}
308
308
return true ;
309
- case "position" :
310
- const [ x , y , w , h ] = getTransformedBBox ( node ) ;
311
- const isWidthOk = node . w === "" || Math . round ( w + x - space . width ) <= 1 ;
312
- const isHeightOk = node . h === "" || Math . round ( h + y - space . height ) <= 1 ;
313
309
314
- if ( isWidthOk && isHeightOk ) {
310
+ case "table" :
311
+ case "tb" :
312
+ if ( node [ $getTemplateRoot ] ( ) [ $extra ] . noLayoutFailure ) {
315
313
return true ;
316
314
}
317
315
318
- const area = node [ $getTemplateRoot ] ( ) [ $extra ] . currentContentArea ;
319
- if ( isWidthOk ) {
320
- return h + y > area . h ;
316
+ // If the node has a height then check
317
+ // if it's fine with available height. If the node
318
+ // is breakable then we can return true.
319
+ if ( node . h !== "" && ! node [ $isSplittable ] ( ) ) {
320
+ const [ , , , h ] = getTransformedBBox ( node ) ;
321
+ return Math . round ( h - space . height ) <= 1 ;
322
+ }
323
+ // Else wait and see: this node will be layed out itself
324
+ // in the provided space and maybe a children won't fit.
325
+ return true ;
326
+ case "position" :
327
+ if ( node [ $getTemplateRoot ] ( ) [ $extra ] . noLayoutFailure ) {
328
+ return true ;
329
+ }
330
+
331
+ const [ , y , , h ] = getTransformedBBox ( node ) ;
332
+ if ( node . h === "" || Math . round ( h + y - space . height ) <= 1 ) {
333
+ return true ;
321
334
}
322
335
323
- return w + x > area . w ;
336
+ const area = node [ $getTemplateRoot ] ( ) [ $extra ] . currentContentArea ;
337
+ return h + y > area . h ;
324
338
case "rl-row" :
325
339
case "row" :
326
340
default :
0 commit comments