-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add block variations to the slash inserter #23364
Conversation
Size Change: -48 B (0%) Total Size: 1.13 MB
ℹ️ View Unchanged
|
* @param {Array} items Denormalized inserter items | ||
* @return {Array} Normalized inserter items. | ||
*/ | ||
export function includeVariationsInInserterItems( items ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think should probably be bundled in the getInserterItems
selector. But I'd leave that for a separate PR as this is already how it works today in the global inserter, it's just extracted as a function. cc @gziolo @noisysocks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to double-check the initial implementation for block variation tomorrow. I think there was a reason to keep it as is initially. It might be no longer valid concern :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found related PR: #19243. I can't think of any blocker for further refactoring. It seems like producing multiple items for blocks with variations followed-up with array flattening would do the trick. We just need to give it a try :)
function defaultGetSelectedBlockName() { | ||
const { getSelectedBlockClientId, getBlockName } = select( | ||
'core/block-editor' | ||
const createBlocksFromInnerBlocksTemplate = ( innerBlocksTemplate ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's copied in a few places, we should extract it and put in @wordpress/blocks
as public API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know if the "variations" are the only place where we could have this shape of innerBlocks.
It seems to me there's an inconsistency here. The variationIItem has a shape of a block object { name, innerBlocks, attributes }
but its innerBlocks have a shape of a template [ name, attributes, innerBlocks ]
which make me thing we should consolidate or rename innerBlocks
to innerBlocksTemplate
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just figured that it's because in the variations API we have innerBlocks property with the template shape too. I think that's not great as it's inconsistent with "example" API and it's inconsistent with it's self since a variation is an object with attributes and innerBlocks so you'd assume its innerBlocks keep the same shape.
I'll address this in a separate PR and I'll drop the template format from the variations while retaining backward compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree that it is confusing. If you have some ideas on how to improve that, go for it :)
I thought about using so innerBlocksTemplate
(I called the variable like that in the mapping helper) inside the variation item object but I left what was there before.
This fixes #20583 |
We had this issue on master too, I think a rebase should fix it. |
266b4f7
to
ae66586
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested after rebase and everything works perfectly fine. Great work 💯
I quickly drafted #23585 to see if that would fit as an e2e test covering this integration. |
Thanks! This really helps tie the inserter APIs together and I like it's more red code than green :) |
closes #20583
Uses the API introduced in #22853 to introduce support for block variations in the slash inserter.
More importantly, this PR makes the slash inserter behaves exactly like the global inserter by sharing logic.
We could for example easily consider adding patterns in a separate PR.