Skip to content

Commit

Permalink
Use block props hook in all blocks of inner-blocks-templates plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
stokesman committed Jul 5, 2023
1 parent 390a321 commit 3bb740f
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions packages/e2e-tests/plugins/inner-blocks-templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
icon: 'cart',
category: 'text',

edit() {
return el( InnerBlocks, {
edit: function InnerBlocksNoLockingEdit() {
return el( 'div', useBlockProps(), el( InnerBlocks, {
template: TEMPLATE,
} );
} ) );
},

save,
Expand All @@ -67,11 +67,11 @@
icon: 'cart',
category: 'text',

edit() {
return el( InnerBlocks, {
edit: function InnerBlocksBlocksLockingAllEdit() {
return el( 'div', useBlockProps(), el( InnerBlocks, {
template: TEMPLATE,
templateLock: 'all',
} );
} ) );
},

save,
Expand All @@ -90,7 +90,7 @@
},
},

edit( props ) {
edit: function InnerBlocksUpdateLockedTemplateEdit( props ) {
const hasUpdatedTemplated = props.attributes.hasUpdatedTemplate;
return el( 'div', null, [
el(
Expand All @@ -102,12 +102,12 @@
},
'Update template'
),
el( InnerBlocks, {
el( 'div', useBlockProps(), el( InnerBlocks, {
template: hasUpdatedTemplated
? TEMPLATE_TWO_PARAGRAPHS
: TEMPLATE,
templateLock: 'all',
} ),
} ) ),
] );
},

Expand All @@ -120,11 +120,11 @@
icon: 'cart',
category: 'text',

edit() {
return el( InnerBlocks, {
edit: function InnerBlocksParagraphPlaceholderEdit() {
return el( 'div', useBlockProps(), el( InnerBlocks, {
template: TEMPLATE_PARAGRAPH_PLACEHOLDER,
templateInsertUpdatesSelection: true,
} );
} ) );
},

save,
Expand Down Expand Up @@ -170,28 +170,15 @@
],
},

edit() {
return el( InnerBlocks, {
edit: function InnerBlocksTransformerTargetEdit() {
return el( 'div', useBlockProps(), el( InnerBlocks, {
template: TEMPLATE,
} );
} ) );
},

save,
} );


function InnerBlocksAsyncTemplateEdit() {
const [ template, setTemplate ] = useState( [] );

setInterval( () => {
setTemplate( TEMPLATE_TWO_PARAGRAPHS );
}, 1000 );

return el('div', useBlockProps(), el( InnerBlocks, {
template,
} ) );
}

registerBlockType(
'test/test-inner-blocks-async-template',
{
Expand All @@ -200,7 +187,17 @@
icon: 'cart',
category: 'text',

edit: InnerBlocksAsyncTemplateEdit,
edit: function InnerBlocksAsyncTemplateEdit() {
const [ template, setTemplate ] = useState( [] );

setInterval( () => {
setTemplate( TEMPLATE_TWO_PARAGRAPHS );
}, 1000 );

return el('div', useBlockProps(), el( InnerBlocks, {
template,
} ) );
},

// Purposely do not save inner blocks so that it's possible to test template resolution.
save() {},
Expand Down

0 comments on commit 3bb740f

Please sign in to comment.