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

Block API comment tweaks #5226

Merged
merged 6 commits into from
Mar 6, 2018
Merged

Block API comment tweaks #5226

merged 6 commits into from
Mar 6, 2018

Conversation

mtias
Copy link
Member

@mtias mtias commented Feb 23, 2018

Trying to clarify a few intentions with comments more about the why and less about the what. Fixes some spelling issues.

@mtias mtias added [Feature] Block API API that allows to express the block paradigm. [Type] Developer Documentation Documentation for developers labels Feb 23, 2018
@@ -140,7 +140,7 @@ export function getPossibleBlockTransformations( blocks ) {
return [];
}

//compute the block that have a from transformation able to transfer blocks passed as argument.
// Compute the block that have a from transformation able to transfer blocks passed as argument.
Copy link
Member Author

Choose a reason for hiding this comment

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

This comment makes little sense :)

// Generated HTML classes for blocks follow the `wp-block-{name}` nomenclature.
// Blocks provided by WordPress drop the prefixes 'core/' or 'core-' (used in 'core-embed/').

// @todo This should be filterable.
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 this seems like a good thing to make filterable.

Copy link
Member

Choose a reason for hiding this comment

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

At the moment you can disable the default class name using supports and className:

// Remove the support for a the generated className .
className: false,

See more https://github.com/WordPress/gutenberg/blob/master/docs/block-api.md#supports-optional.

Yes, it seems like we might make it possible to override this function with a custom implementation. I'll open an issue.

Copy link
Member

Choose a reason for hiding this comment

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

Done: #5299 👍

@@ -177,6 +180,7 @@ export function getBeautifulContent( content ) {
* @return {string} HTML.
*/
export function getBlockContent( block ) {
// @todo why not getBlockInnerHtml?
Copy link
Member Author

Choose a reason for hiding this comment

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

@aduth @youknowriad seems we should go with getBlockInnerHtml for consistency.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I'd like to align more of the terminology here. This is a good example. Also from the parser output, I'd like to normalize attrs -> attributes, blockName -> name.

let {
blockName: name,
attrs: attributes,
innerBlocks = [],
innerHTML,
} = blockNode;

const blockName = startsWith( rawBlockName, 'core/' ) ?
rawBlockName.slice( 5 ) :
rawBlockName;

// @todo make the `wp:` prefix potentially configurable.
Copy link
Member

Choose a reason for hiding this comment

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

Should it be configurable? Or should we just change it per #4636 ? 😄

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 don't think we should change it :)

@@ -131,15 +131,15 @@ export class InserterMenu extends Component {
return recentItems;

case 'blocks':
predicate = ( item ) => item.category !== 'embed' && item.category !== 'reusable-blocks';
Copy link
Member

Choose a reason for hiding this comment

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

innerHTML = innerHTML.trim();

// Use type from block content, otherwise find unknown handler.
name = name || getUnknownTypeHandlerName();

// Convert 'core/text' blocks in existing content to the new
// 'core/paragraph'.
// Convert 'core/text' blocks in existing content to 'core/paragraph'.
if ( 'core/text' === name || 'core/cover-text' === name ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably time to remove this old use-case.

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 was thinking of switching back to text :)

@mtias mtias force-pushed the update/block-api-comments branch from 0908aa9 to d9723b9 Compare March 6, 2018 18:08
title: __( 'Reusable Block' ),
category: 'reusable-blocks',
title: __( 'Shared Block' ),
category: 'shared',
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 bit odd that we assign a category here, since the block never appears on its own in an inserter. But I guess with our block validation, it's not possible to not assign a category. Maybe we should take isPrivate into consideration when determining whether a category is needed.

Edit: Might also impact blocks which are expected to only be used in a nested context.
Edit 2: We could just make category non-required, though it's easy to mistakenly omit and causes a block to not appear in the inserter.

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 think making category non-required might be the best in any case.

Copy link
Member

Choose a reason for hiding this comment

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

I would double check if the shared block won’t show up in the inserter with those changes introduced.

I second making category optional and to be expressed as any alphanumerical string. In the inserter we would put it under others category if it isn’t one of those that core provides.
In general I think we should convert shared block logic into the editor UI instead of introducing isPrivate property.

Copy link
Member

Choose a reason for hiding this comment

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

I think the last time the issue was with the recent blocks in both the regular inserter and in the inline inserter (right hand icons).

@mtias mtias merged commit 7b067e9 into master Mar 6, 2018
@mtias mtias deleted the update/block-api-comments branch March 6, 2018 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants