Skip to content
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

Merged
merged 10 commits into from
Jul 10, 2018
Merged

Conversation

oandregal
Copy link
Member

@oandregal oandregal commented Jul 2, 2018

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.

@oandregal oandregal self-assigned this Jul 2, 2018
@oandregal oandregal force-pushed the add/html-to-blocks branch from 3aca796 to 6de5a3b Compare July 2, 2018 15:16
aduth
aduth previously requested changes Jul 2, 2018
Copy link
Member

@aduth aduth left a 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.

@aduth
Copy link
Member

aduth commented Jul 2, 2018

Related: #7199

@aduth aduth added [Feature] Blocks Overall functionality of blocks [Feature] Extensibility The ability to extend blocks or the editing experience [Feature] Paste labels Jul 2, 2018
@oandregal
Copy link
Member Author

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 } ) => ( {
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also related #6361

Copy link
Member Author

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.

Copy link
Member Author

@oandregal oandregal Jul 5, 2018

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.

@gziolo
Copy link
Member

gziolo commented Jul 3, 2018

This newly introduced component is very similar to UnknownConverter (https://github.com/WordPress/gutenberg/blob/6de5a3bc7f0e940b5e00a26609b7e286bfd60fb7/editor/components/block-settings-menu/unknown-converter.js) - would be there a way to consolidate them?

@oandregal
Copy link
Member Author

re: UnknownConverter and HTMLConverter. I've considered other approaches:

  • using a single Converter that would use conditionals to differentiate different block logic.
  • extract a common Converter that HTMLConverter and UnknownConverter would inherit from using the Template pattern.
  • create a mechanism for blocks to register their own converter, allowing extensibility.

After doing an audit of blocks #7684 I operate with this assumption: Convert to blocks is a transitional feature that it's supposed to be used by the classic and HTML blocks and not plugins. Given that assumption, we don't expect to create more converters (for core or plugins). So, at this point, building any indirection to allow extensibility could do more harm than good (perhaps less code, but also less obvious).

@oandregal oandregal force-pushed the add/html-to-blocks branch from 6de5a3b to d0e747e Compare July 5, 2018 14:56
Copy link
Member

@gziolo gziolo left a 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 = () => {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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).

@@ -1891,3 +1891,14 @@ export function getTokenSettings( state, name ) {

return state.tokens[ name ];
}

/*
* Returns whether or not the user has the unfiltered_html capability
Copy link
Member

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 . :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gziolo gziolo dismissed aduth’s stale review July 10, 2018 10:06

Let's merge this one and iterate.

@oandregal
Copy link
Member Author

Thanks for the review, Grzegorz!

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?

I'm already working on this and will ping you soon with a proposal.

@oandregal oandregal merged commit ccbb54b into master Jul 10, 2018
@gziolo
Copy link
Member

gziolo commented Jul 10, 2018

@nosolosw, congrats. You made your first Gutenberg contribution! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks [Feature] Extensibility The ability to extend blocks or the editing experience [Feature] Paste
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants