Skip to content

Commit 921dd8a

Browse files
committed
Quickfix supernova block controlling innerBlocks count and attributes
1 parent 493dbc4 commit 921dd8a

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

packages/block-library/src/blocks/supernova/edit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ const SupernovaEdit = props => {
155155
}, [ attributes ] );
156156

157157
// Make sure that we keep the number of inner Supernova Items in sync with the number of items.
158-
// useInnerBlocksCount( clientId, postsToShow, 'novablocks/supernova-item', innerBlocksAttributes );
158+
useInnerBlocksCount( clientId, postsToShow, 'novablocks/supernova-item', innerBlocksAttributes );
159159

160160
// Either lock or unlock nb-supernova-items depending on whether we are in a query or not.
161161
if ( isDescendentOfQueryLoop ) {

packages/block-library/src/blocks/supernova/filters/with-set-children-attributes.js

+23-19
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { useCallback } from "@wordpress/element";
22
import { useDispatch, useSelect } from "@wordpress/data";
33

4-
import { getChildAttributes } from "../utils";
54
import { getAlignFromMatrix } from "@novablocks/utils";
5+
import { useInnerBlocks } from "@novablocks/block-editor";
6+
7+
import { getChildAttributes } from "../utils";
68

79
const withSetChildrenAttributes = OriginalComponent => {
810

@@ -15,6 +17,7 @@ const withSetChildrenAttributes = OriginalComponent => {
1517
const { clientId } = props;
1618
const { updateBlockAttributes } = useDispatch( 'core/block-editor' );
1719
const { getBlock } = useSelect( select => select( 'core/block-editor' ) );
20+
const innerBlocks = useInnerBlocks( clientId );
1821

1922
const normalizeAttributes = useCallback( attributes => {
2023
const { cardLayout } = attributes;
@@ -32,37 +35,38 @@ const withSetChildrenAttributes = OriginalComponent => {
3235
}, [] );
3336

3437
const setChildrenAttributes = useCallback( attributes => {
35-
const { innerBlocks } = getBlock( clientId );
3638
const newAttributes = getChildAttributes( attributes );
3739

38-
if ( attributes.contentPosition && Array.isArray( innerBlocks ) ) {
40+
if ( Array.isArray( innerBlocks ) ) {
3941
innerBlocks.filter( block => block.name === 'novablocks/supernova-item' ).forEach( block => {
4042
updateBlockAttributes( block.clientId, newAttributes );
4143

42-
const contentBlocks = getBlock( block.clientId ).innerBlocks;
43-
const contentAlign = getAlignFromMatrix( attributes?.contentPosition );
44+
if ( attributes.contentPosition ) {
45+
const contentBlocks = getBlock( block.clientId ).innerBlocks;
46+
const contentAlign = getAlignFromMatrix( attributes?.contentPosition );
4447

45-
if ( Array.isArray( contentBlocks ) ) {
48+
if ( Array.isArray( contentBlocks ) ) {
4649

47-
contentBlocks.filter( block => block.name === 'novablocks/headline' ).forEach( block => {
48-
updateBlockAttributes( block.clientId, { textAlign: contentAlign[1] } );
49-
} )
50+
contentBlocks.filter( block => block.name === 'novablocks/headline' ).forEach( block => {
51+
updateBlockAttributes( block.clientId, { textAlign: contentAlign[1] } );
52+
} )
5053

51-
contentBlocks.filter( block => block.name === 'core/heading' ).forEach( block => {
52-
updateBlockAttributes( block.clientId, { textAlign: contentAlign[1] } );
53-
} )
54+
contentBlocks.filter( block => block.name === 'core/heading' ).forEach( block => {
55+
updateBlockAttributes( block.clientId, { textAlign: contentAlign[1] } );
56+
} )
5457

55-
contentBlocks.filter( block => block.name === 'core/paragraph' ).forEach( block => {
56-
updateBlockAttributes( block.clientId, { align: contentAlign[1] } );
57-
} )
58+
contentBlocks.filter( block => block.name === 'core/paragraph' ).forEach( block => {
59+
updateBlockAttributes( block.clientId, { align: contentAlign[1] } );
60+
} )
5861

59-
contentBlocks.filter( block => block.name === 'core/buttons' ).forEach( block => {
60-
updateBlockAttributes( block.clientId, { layout: { ...block.attributes.layout, type: 'flex', justifyContent: contentAlign[1] } } );
61-
} )
62+
contentBlocks.filter( block => block.name === 'core/buttons' ).forEach( block => {
63+
updateBlockAttributes( block.clientId, { layout: { ...block.attributes.layout, type: 'flex', justifyContent: contentAlign[1] } } );
64+
} )
65+
}
6266
}
6367
} );
6468
}
65-
}, [ clientId ] );
69+
}, [ innerBlocks ] );
6670

6771
return (
6872
<OriginalComponent { ...props } setAttributes={ attributes => {

0 commit comments

Comments
 (0)