-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Move the block manager to block editor package #39672
Conversation
Size Change: +84 B (0%) Total Size: 1.23 MB
ℹ️ View Unchanged
|
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 guess the reason for moving the BlockManager and relying on the preferences package is to be able to use the BlockManager in multiple editors.
The more I think about edit-post and edit-site (at least these two), the more I see these as the same editor and that at some point we'll need to merge.
That said maybe we could still have a reusable BlockManager component in block editor but without the dependency to preferences:
<BlockManager value={ allowedBlocks } onChange={ onChange } />
@@ -52,6 +52,7 @@ | |||
"@wordpress/keyboard-shortcuts": "file:../keyboard-shortcuts", | |||
"@wordpress/keycodes": "file:../keycodes", | |||
"@wordpress/notices": "file:../notices", | |||
"@wordpress/preferences": "file:../preferences", |
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'm not really sure that I like that personally, I feel the block-editor package shouldn't be depending on the "preferences" package. The reason is that the "preferences" package is something that is generic now but I see it as more tied to WP especially if we implement later API based preferences (persist in the user profile)
I guess we can implement this WP relationship in a non-intrusive way, using adapters or something but maybe we should cross that bridge at that moment?
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.
Yeah, this is something I was unsure about.
There's also #39632 where I've migrated some of the block-editor's persisted data to the preferences package, that would also add the dependency.
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.
In #39632 it seems it's even harder to remove that dependency. So maybe we can just accept it as a dependency but make sure that any "WP" dependency should be added in an optional "adapter" layer
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.
You can also look at the Block Directory integration:
https://github.com/WordPress/gutenberg/tree/trunk/packages/block-directory
At least outside of the WordPress core, the block manager UI isn't so important as you can have full control over the blocks used.
It's shaped as an optional plugin that integrates with the block editor. Although, I'm not sure how that would work with the preferences store, to be honest.
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.
The block directory renders into slots IIRC, so it seems a bit easier to make optional.
As Riad mentions, #39632 (block insert usage, which is used to power the quick inserter) is a more difficult thing to make optional. That does seem more important to a standalone editor, though perhaps a fallback to in-memory persistence could be an option.
The only way I can see to keep it working would be to extract the whole feature from the block-editor package. There would need to be a way to listen for block insertion events so that insertUsage
could be updated. The block manager could also potentially live in a different package and that would solve the dependency issue for this one.
But there's no hurry to merge this or #39632, so it could be worth exploring how a flexible persistence layer in preferences might be integrated first.
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, the block directory integration was easier to make optional. It's worth also pursuing the same approach because it makes the editor easier to extend assuming you would find a decent way to orchestrate the preferences store. It would benefit also plugin authors. I'm happy to pair with you to discuss the challenges and possible ideas.
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.
There's an experiment here to try making the persistence aspect of preferences optional/configurable - #39795.
ba28c26
to
e60bcd3
Compare
Part of #41004
What?
Moves the block manager component to the block-editor package.
Why?
It will allow the block manager to be more easily implement in other editors (like the site editor).
Now that
hiddenBlockTypes
are stored in the preferences store (since #39132), this change is easier to make.How?
It's worth discussing the changes that require most attention from reviewers first. To make it easier for other editors to implement the block manager, I've made some changes to the block editor settings.
Previously, the block manager worked by modifying the
allowedBlocks
setting (removing any hidden block types). It also set anotherdefaultAllowedBlocks
editor setting, which represented the allowed blocks before any modification.I've changed this. It seems much simpler to use
hiddenBlockTypes
as an editor setting rather thandefaultAllowedBlockTypes
and makecanInsertBlockTypeUnmemoized
check thehiddenBlockTypes
list, so that's the change I've made.I'm open to other option, including changing it back. An alternative could also be for the block editor package to pull in
hiddenBlockTypes
straight from the preferences store instead of using a setting, but it'd have to somehow know whichscope
to use.The rest of the changes are pretty straightforward:
withSelect
touseSelect
scope
prop to indicate which preferences it uses.useHiddenBlockTypes
hook to interact with the preferences store (which could be worth exporting and then the post editor's selectors and actions could be deprecated).Testing Instructions
There shouldn't be any change in functionality in the post editor. To test:
Expected: The blocks that were hidden are not visible in the inserter.