@@ -242,89 +242,77 @@ export function PageLayout({ children, className }: Readonly<PageLayoutProps>) {
242242
243243 // sort the blocks to make sure we have the correct order
244244 const arrangedExtensionBlocks = matchingExtensionBlocks . sort ( ( a , b ) => {
245- const orderPriority = { ' before' : 1 , ' replace' : 2 , ' after' : 3 } ;
245+ const orderPriority = { before : 1 , replace : 2 , after : 3 } ;
246246 return orderPriority [ a . location . position . order ] - orderPriority [ b . location . position . order ] ;
247- } )
248-
249- // get the length of blocks with the "before" position to know when to insert the child block
250- const beforeExtensionBlocksLength = arrangedExtensionBlocks . filter (
251- block => block . location . position . order === 'before' ,
252- ) . length ;
247+ } ) ;
253248
254249 const replacementBlockExists = arrangedExtensionBlocks . some (
255250 block => block . location . position . order === 'replace' ,
256- )
251+ ) ;
257252
258253 let childBlockInserted = false ;
259254 if ( matchingExtensionBlocks . length > 0 ) {
260255 for ( const extensionBlock of arrangedExtensionBlocks ) {
261-
262256 let extensionBlockShouldRender = true ;
263257 if ( typeof extensionBlock ?. shouldRender === 'function' ) {
264258 extensionBlockShouldRender = extensionBlock . shouldRender ( page ) ;
265259 }
266260
267261 // Insert child block before the first non-"before" block
268- if ( ! childBlockInserted && ! replacementBlockExists && extensionBlock . location . position . order !== 'before' ) {
269- finalChildArray . push ( childBlock )
270- childBlockInserted = true
271- }
262+ if (
263+ ! childBlockInserted &&
264+ ! replacementBlockExists &&
265+ extensionBlock . location . position . order !== 'before'
266+ ) {
267+ finalChildArray . push ( childBlock ) ;
268+ childBlockInserted = true ;
269+ }
270+
271+ const isFullWidth = extensionBlock . location . column === 'full' ;
272+ const BlockComponent = isFullWidth ? FullWidthPageBlock : PageBlock ;
272273
273274 const ExtensionBlock =
274275 extensionBlock . component && extensionBlockShouldRender ? (
275- < PageBlock
276+ < BlockComponent
276277 key = { extensionBlock . id }
277278 column = { extensionBlock . location . column }
278279 blockId = { extensionBlock . id }
279280 title = { extensionBlock . title }
280281 >
281282 { < extensionBlock . component context = { page } /> }
282- </ PageBlock >
283+ </ BlockComponent >
283284 ) : undefined ;
284285
285- if ( extensionBlockShouldRender && ExtensionBlock ) {
286- finalChildArray . push ( ExtensionBlock )
286+ if ( extensionBlockShouldRender && ExtensionBlock ) {
287+ finalChildArray . push ( ExtensionBlock ) ;
287288 }
288289 }
289290
290291 // If all blocks were "before", insert child block at the end
291292 if ( ! childBlockInserted && ! replacementBlockExists ) {
292- finalChildArray . push ( childBlock )
293+ finalChildArray . push ( childBlock ) ;
293294 }
294-
295295 } else {
296296 finalChildArray . push ( childBlock ) ;
297297 }
298298 }
299299 }
300300
301+ const fullWidthBlocks = finalChildArray . filter (
302+ child => isPageBlock ( child ) && isOfType ( child , FullWidthPageBlock ) ,
303+ ) ;
304+ const mainBlocks = finalChildArray . filter ( child => isPageBlock ( child ) && child . props . column === 'main' ) ;
305+ const sideBlocks = finalChildArray . filter ( child => isPageBlock ( child ) && child . props . column === 'side' ) ;
306+
301307 return (
302308 < div className = { cn ( 'w-full space-y-4' , className , '@container/layout' ) } >
303309 { isDesktop ? (
304310 < div className = "grid grid-cols-1 gap-4 @3xl/layout:grid-cols-4" >
305- { finalChildArray . map ( ( child , index ) => {
306- const key = child . props ?. blockId ?? `block-${ index } ` ;
307- if ( isPageBlock ( child ) ) {
308- if ( isOfType ( child , FullWidthPageBlock ) ) {
309- return (
310- < div key = { key } className = "@md/layout:col-span-5 space-y-4" > { child } </ div >
311- ) ;
312- }
313-
314- if ( child . props . column === 'main' ) {
315- return (
316- < div key = { key } className = "@3xl/layout:col-span-3 space-y-4" > { child } </ div >
317- )
318- }
319-
320- if ( child . props . column === 'side' ) {
321- return (
322- < div key = { key } className = "@3xl/layout:col-span-1 space-y-4" > { child } </ div >
323- )
324- }
325- }
326- return null
327- } ) }
311+ { fullWidthBlocks . length > 0 && (
312+ < div className = "@md/layout:col-span-5 space-y-4" > { fullWidthBlocks } </ div >
313+ ) }
314+ < div className = "@3xl/layout:col-span-3 space-y-4" > { mainBlocks } </ div >
315+ < div className = "@3xl/layout:col-span-1 space-y-4" > { sideBlocks } </ div >
328316 </ div >
329317 ) : (
330318 < div className = "space-y-4" > { finalChildArray } </ div >
0 commit comments