-
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 "Convert to blocks" option in HTML block #7667
Conversation
3aca796
to
6de5a3b
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 could see a pattern emerging here where a block wants to add options to its own "More" menu, so instead of adding awareness of this to the editor in the BlockSettingsMenu
component, I wonder if this should be a Slot/Fill pairing similar to what we're doing with InspectorControls
.
Related: #7199 |
Thanks for pointing me to that debate, Andrew. After reading the thread, my current thinking is: let's merge this and iterate on the more general menu extensibility in a separate PR. The concerns are different, and from the convo with @youknowriad @gziolo I got the feeling that the menu extensibility still needs some discussion. I will prepare a separate PR for that and will also look at the code of the general menu that already includes some space for plugins. |
withDispatch( ( dispatch ) => ( { | ||
onReplace: dispatch( 'core/editor' ).replaceBlocks, | ||
} ) ), | ||
withAPIData( ( { postType } ) => ( { |
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.
We are trying to get rid of withAPIData
usage and deprecate it as explained in #7390 and #7397. An alternative approach would be to use _links
object returned from the REST API as implemented in other places by @danielbachhuber, examples: #7495 or even better #6724.
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 can be done in a separate PR given that there are a few occurrences of get( user, [ 'data', 'capabilities', 'unfiltered_html' ], false )
, but this should be started in parallel.
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.
Also related #6361
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.
Fixed in 138c7f1.
Also added the canUserUseUnfilteredHTML
selector in d0e747e to substitute the rest of occurrences in a separate PR once this lands.
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.
#7729 substitutes the remaining cases of unfiltered_html
and withAPIData
. It depends on this being merged.
This newly introduced component is very similar to |
re:
After doing an audit of blocks #7684 I operate with this assumption: |
6de5a3b
to
d0e747e
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.
It works great. I left some minor comments to address before merging this PR.
Thanks for pointing me to that debate, Andrew. After reading the thread, my current thinking is: let's merge this and iterate on the more general menu extensibility in a separate PR.
Should we open a follow-up issue where we could discuss how to make this part of the extensibility layer, to allow plugin developers add their own option in a similar fashion?
|
||
const label = __( 'Convert to blocks' ); | ||
|
||
const convertToBlocks = () => { |
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.
Is it possible to move it to withDispatch
or is there any blocker?
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 it could be refactored, indeed. I don't mind one-way or the other and did that to mimic what existed in UnknownConverter. I'll leave it as it is, we can always refactor both later if necessary.
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 a leaf component inside the dropdown which is not rendered by default, so this shouldn't impact performance. In general, having a local function inside render
method isn't expected because it causes unnecessary re-renders.
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.
Grzegorz, #7885 follows up the work on this PR and addresses some ideas you mentioned in this thread (share common code, move to withDispatch
).
editor/store/selectors.js
Outdated
@@ -1891,3 +1891,14 @@ export function getTokenSettings( state, name ) { | |||
|
|||
return state.tokens[ name ]; | |||
} | |||
|
|||
/* | |||
* Returns whether or not the user has the unfiltered_html capability |
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.
Nit: Comment should start with /**
. All sentences should end with .
:)
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.
Thanks for the review, Grzegorz!
I'm already working on this and will ping you soon with a proposal. |
@nosolosw, congrats. You made your first Gutenberg contribution! 🎉 |
Addresses #7466
I've tested this by trying some HTML with a direct map to blocks (ie: lists, paragraphs), and also HTML that has no direct counterpart as a WordPress block. As far as this relies on
rawHandler
for block conversion, they're in line with what Gutenberg can manage.