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

Edit Site: Allow wide alignment #23488

Merged
merged 6 commits into from
Jun 30, 2020
Merged

Edit Site: Allow wide alignment #23488

merged 6 commits into from
Jun 30, 2020

Conversation

ockham
Copy link
Contributor

@ockham ockham commented Jun 25, 2020

Description

For the Site Editor, we want to allow post content to be inserted at full width (e.g. Cover Blocks). This is currently impossible (see Automattic/wp-calypso#43640) due to 3 2 independent problems. This PR fixes all of them.

To provide some context for those issues -- the alignment handling is somewhat complex, and happens mostly at BlockListBlock level, using the withDataAlign HOC.

  1. Unlike the Post Editor, we're currently not setting alignWide in the Site Editor's settings, which becomes a problem here:
    const hasWideEnabled = useSelect(
    ( select ) =>
    !! select( 'core/block-editor' ).getSettings().alignWide,
    []
    );
    // If an alignment is not assigned, there's no need to go through the
    // effort to validate or assign its value.
    if ( align === undefined ) {
    return <BlockListBlock { ...props } />;
    }
    const validAlignments = getValidAlignments(
    getBlockSupport( name, 'align' ),
    hasBlockSupport( name, 'alignWide', true ),
    hasWideEnabled
    );
    let wrapperProps = props.wrapperProps;
    if ( includes( validAlignments, align ) ) {
    wrapperProps = { ...wrapperProps, 'data-align': align };
    }
    return <BlockListBlock { ...props } wrapperProps={ wrapperProps } />;
    .
    2. In block-list/block-wrapper.js, we're omitting the data-align prop from wrapper props, before passing them on to the actual element. I believe that this is an oversight from a refactor PR (Block: move align wrapper out of Block element #23089) that moved some logic from the block wrapper into BlockListBlock. cc/ @ellatrix Reverted, see this discussion.
  2. In order to specifically make the Post Content block full-width, we need to add align to its supports attribute. (It's still conceivable to use this block at other widths, e.g. in a setting with a sidebar.)

Fixes Automattic/wp-calypso#43640.

How has this been tested?

  • There shouldn't be any wp_template CPTs (neither published nor auto-drafts) from previous Site Editor runs. (It's best to start with a fresh install, i.e. npx wp-env clean all && npx wp-env start. Careful, this will wipe your WordPress install's data!)
  • Furthermore, the "Full Site Editing Demo Templates" checkbox in /wp-admin/admin.php?page=gutenberg-experiments must not be ticked. (Make sure the "Full Site Editing" checkbox is ticked -- since it also gets reset after a wipe.)
  • Make sure you have linked your wp-env install to themes from the theme-experiments repo (see the wp-env README).
  • Activate the "Twenty Twenty Blocks" theme.
  • Create a Home page (under Pages), and insert a full-width Cover block into it. (Verify that it takes up the entire (editor) screen width.)
  • In 'Settings > Reading', set the front page to that Home page.
  • Open the Site Editor. Make sure the template used for the front page contains a Post Content block (insert one if it doesn't).
  • Set that Post Content block to Full Width.
  • Verify that it takes up the entire (editor) screen width, as it should. (There's currently still a 10px padding which I'll address separately.) Fixed, see 6ae4c63.

Screenshots

Before

image

After

image

Types of changes

Bugfix

Follow-up PRs

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@github-actions
Copy link

github-actions bot commented Jun 25, 2020

Size Change: -372 B (0%)

Total Size: 1.13 MB

Filename Size Change
build/a11y/index.js 1.14 kB +1 B
build/api-fetch/index.js 3.4 kB -1 B
build/autop/index.js 2.82 kB +1 B
build/block-directory/index.js 7.39 kB +3 B (0%)
build/block-editor/index.js 109 kB +46 B (0%)
build/block-editor/style-rtl.css 10.7 kB -2 B (0%)
build/block-editor/style.css 10.7 kB -3 B (0%)
build/block-library/editor-rtl.css 7.41 kB -186 B (2%)
build/block-library/editor.css 7.41 kB -187 B (2%)
build/block-library/index.js 129 kB -139 B (0%)
build/block-library/style-rtl.css 8.04 kB +5 B (0%)
build/block-library/style.css 8.05 kB +5 B (0%)
build/block-serialization-default-parser/index.js 1.88 kB +1 B
build/blocks/index.js 48.2 kB +3 B (0%)
build/components/index.js 198 kB -23 B (0%)
build/components/style-rtl.css 15.9 kB +6 B (0%)
build/components/style.css 15.9 kB +5 B (0%)
build/compose/index.js 9.65 kB -1 B
build/core-data/index.js 11.4 kB -1 B
build/data-controls/index.js 1.29 kB +1 B
build/data/index.js 8.44 kB +6 B (0%)
build/date/index.js 5.47 kB +3 B (0%)
build/edit-navigation/index.js 9.88 kB +16 B (0%)
build/edit-post/index.js 303 kB -13 B (0%)
build/edit-post/style-rtl.css 5.51 kB +5 B (0%)
build/edit-post/style.css 5.51 kB +5 B (0%)
build/edit-site/index.js 16.6 kB +25 B (0%)
build/edit-site/style-rtl.css 3 kB -34 B (1%)
build/edit-site/style.css 3 kB -36 B (1%)
build/edit-widgets/index.js 9.32 kB -4 B (0%)
build/editor/index.js 44.8 kB +88 B (0%)
build/editor/style-rtl.css 3.85 kB +9 B (0%)
build/editor/style.css 3.86 kB +10 B (0%)
build/element/index.js 4.65 kB -1 B
build/i18n/index.js 3.56 kB -1 B
build/is-shallow-equal/index.js 710 B -1 B
build/keyboard-shortcuts/index.js 2.52 kB +5 B (0%)
build/keycodes/index.js 1.94 kB +1 B
build/list-reusable-blocks/index.js 3.12 kB -1 B
build/notices/index.js 1.79 kB -2 B (0%)
build/nux/index.js 3.4 kB -1 B
build/nux/style-rtl.css 671 B +8 B (1%)
build/nux/style.css 668 B +8 B (1%)
build/plugins/index.js 2.56 kB -1 B
build/rich-text/index.js 14 kB +1 B
build/server-side-render/index.js 2.67 kB -2 B (0%)
build/shortcode/index.js 1.69 kB -1 B
build/token-list/index.js 1.28 kB +1 B
build/wordcount/index.js 1.17 kB +1 B
ℹ️ View Unchanged
Filename Size Change
build/annotations/index.js 3.62 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/style-rtl.css 941 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-library/theme-rtl.css 730 B 0 B
build/block-library/theme.css 732 B 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 569 B 0 B
build/dom/index.js 3.19 kB 0 B
build/edit-navigation/style-rtl.css 1.02 kB 0 B
build/edit-navigation/style.css 1.02 kB 0 B
build/edit-widgets/style-rtl.css 2.42 kB 0 B
build/edit-widgets/style.css 2.42 kB 0 B
build/editor/editor-styles-rtl.css 537 B 0 B
build/editor/editor-styles.css 539 B 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.72 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 622 B 0 B
build/list-reusable-blocks/style-rtl.css 450 B 0 B
build/list-reusable-blocks/style.css 451 B 0 B
build/media-utils/index.js 5.29 kB 0 B
build/primitives/index.js 1.5 kB 0 B
build/priority-queue/index.js 788 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.85 kB 0 B
build/warning/index.js 1.14 kB 0 B

compressed-size-action

@ockham ockham marked this pull request as ready for review June 25, 2020 22:19
@ockham
Copy link
Contributor Author

ockham commented Jun 25, 2020

cc/ @jeyip (who I can't seem to set as a reviewer 😕 )

Copy link
Contributor

@Addison-Stavlo Addison-Stavlo left a comment

Choose a reason for hiding this comment

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

I followed the testing instructions. I cleaned the environment, activated 2020-blocks, and went through these steps. I am getting the post content block at full-width (minus the 10px padding). While the cover block is also set to full-width, it is still restricted to the thin width as before:

(crud, github isn't letting me upload right now 😭 )

Also, If I activate 2019-blocks and visit the site editor.. everything is super wide and flowing off the visible page.

@@ -241,7 +241,7 @@ const BlockComponent = forwardRef(
// Overrideable props.
aria-label={ blockLabel }
role="group"
{ ...omit( wrapperProps, [ 'data-align' ] ) }
Copy link
Contributor

Choose a reason for hiding this comment

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

This is like this because the attribute is now applied to a wrapper. This change might be causing the breakage @Addison-Stavlo noticed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean the <div className="wp-block" data-align="..." /> wrapper? But as of #23089, that's added by block-list/block.js rather than block-wrapper.js. And AFAICS, block-wrapper omitting that prop when instantiating the block component is why that wrapper wasn't added. Or am I missing something?

Copy link
Contributor

Choose a reason for hiding this comment

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

if ( isAligned ) {
const alignmentWrapperProps = {
'data-align': wrapperProps[ 'data-align' ],
};
blockEdit = (
<div className="wp-block" { ...alignmentWrapperProps }>
{ blockEdit }
</div>
);
}

I see it on a different div there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But that's the one I'm talking about:

You mean the <div className="wp-block" data-align="..." /> wrapper?

Try this, on master, and then on this branch:

diff --git a/packages/block-editor/src/components/block-list/block.js b/packages/block-editor/src/components/block-list/block.js
index 93ae691015..aca5b8bb8f 100644
--- a/packages/block-editor/src/components/block-list/block.js
+++ b/packages/block-editor/src/components/block-list/block.js
@@ -95,6 +95,10 @@ function BlockListBlock( {
        );
        const isUnregisteredBlock = name === getUnregisteredTypeHandlerName();
 
+       if ( name === 'core/cover' ) {
+               console.log( { wrapperProps } );
+       }
+
        // Determine whether the block has props to apply to the wrapper.
        if ( blockType.getEditWrapperProps ) {
                wrapperProps = {

master:

wrapper-props-master

This branch:

wrapper-props-branch

Copy link
Contributor

Choose a reason for hiding this comment

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

The block wrapper is a child in this file. How would omitting the prop there make it not show here?

<Block.div { ...wrapperProps }>
{ blockEdit }
{ mode === 'html' && (
<BlockHtml clientId={ clientId } />
) }
</Block.div>

blockEdit is already wrapped at that point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. I was getting my wires crossed here with regard to which component uses which (and I could've sworn I re-built Gutenberg with and without the change to verify, but apparently not 🤷‍♂️ )

Anyway, I've reverted the relevant commit, and Twenty Twenty Blocks still looks as before reverting 👍 However, Twenty Nineteen Blocks also still looks garbled 😕

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like a different issue then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ellatrix
Copy link
Member

There's a lot of thoughts to rewrite alignment (#20650). It would be great if this could wait after Beta 1 or everything added is experimental.

@ockham ockham force-pushed the fix/edit-site-full-width branch from cba1766 to 186aa2e Compare June 28, 2020 10:04
@ockham
Copy link
Contributor Author

ockham commented Jun 28, 2020

There's a lot of thoughts to rewrite alignment (#20650). It would be great if this could wait after Beta 1 or everything added is experimental.

Thanks for the pointer! Wow, that's a long discussion 😅

This PR currently consists of 3 changes, 2 of which I think are quite limited in scope to the Site Editor (which is experimental anyway). The lack of wide alignment of post content is quite the blocker for site editing, so TBH I'd rather not wait on the outcome of #20650. I think the risk in these changes is fairly low -- curious to hear your thoughts?

@ockham
Copy link
Contributor Author

ockham commented Jun 29, 2020

There's currently still a 10px padding which I'll address separately.

This is coming from here:

In the Post Editor, it's compensated by this selector:

// For full-wide blocks, we compensate for these 10px.
.block-editor-block-list__layout.is-root-container > .wp-block[data-align="full"] {
margin-left: -10px;
margin-right: -10px;
}

@ockham
Copy link
Contributor Author

ockham commented Jun 29, 2020

There's currently still a 10px padding which I'll address separately.

This is coming from here:

In the Post Editor, it's compensated by this selector:

// For full-wide blocks, we compensate for these 10px.
.block-editor-block-list__layout.is-root-container > .wp-block[data-align="full"] {
margin-left: -10px;
margin-right: -10px;
}

In the Site Editor, it's set here:

.edit-site-block-editor__block-list {
padding-bottom: $grid-unit-30;
padding-top: $grid-unit-30 + 5;
padding-left: $block-padding;
padding-right: $block-padding;
// Full-wide. (to account for the padddings added above)
.wp-block[data-align="full"] {
margin-left: -$block-padding;
margin-right: -$block-padding;
}
}

I've noticed that the Post Editor padding/margin was changed very recently: #22213. We might need to do something similar to the Site Editor.

This carries over a change that was applied to the Post Editor in #22213.
See there for more context.
@ockham
Copy link
Contributor Author

ockham commented Jun 29, 2020

Simple removal of the relevant lines seems to fix the 10px padding problem: 6ae4c63 🎉

Copy link
Contributor

@jeyip jeyip left a comment

Choose a reason for hiding this comment

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

Tested expanding post content with a cover block on:
✅ Chrome
✅ Firefox
✅ Edge
✅ IE11

The functionality looks good to me!

@ockham ockham requested a review from epiqueras June 30, 2020 20:52
@ockham
Copy link
Contributor Author

ockham commented Jun 30, 2020

Thanks a lot @jeyip! ❤️

@epiqueras It seems like I need your approval in order to merge the PR 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Site Editor: block list width looks off
6 participants