Skip to content

Commit

Permalink
Remove data-align divs for themes that support layout
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Feb 8, 2022
1 parent 9423769 commit 67b1282
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
27 changes: 24 additions & 3 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import {
isUnmodifiedDefaultBlock,
} from '@wordpress/blocks';
import { withFilters } from '@wordpress/components';
import { withDispatch, withSelect, useDispatch } from '@wordpress/data';
import {
withDispatch,
withSelect,
useDispatch,
useSelect,
} from '@wordpress/data';
import { compose, pure, ifCondition } from '@wordpress/compose';
import { safeHTML } from '@wordpress/dom';

Expand Down Expand Up @@ -86,6 +91,10 @@ function BlockListBlock( {
onMerge,
toggleSelection,
} ) {
const themeSupportsLayout = useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
return getSettings().supportsLayout;
}, [] );
const { removeBlock } = useDispatch( blockEditorStore );
const onRemove = useCallback( () => removeBlock( clientId ), [ clientId ] );

Expand Down Expand Up @@ -123,7 +132,13 @@ function BlockListBlock( {

// For aligned blocks, provide a wrapper element so the block can be
// positioned relative to the block column.
if ( isAligned ) {
// This is only kept for classic themes that don't support layout
// Historically we used to rely on extra divs and data-align to
// provide the alignments styles in the editor.
// Due to the differences between frontend and backend, we migrated
// to the layout feature, and we're now aligning the markup of frontend
// and backend.
if ( isAligned && ! themeSupportsLayout ) {
blockEdit = (
<div
className="wp-block"
Expand Down Expand Up @@ -164,7 +179,13 @@ function BlockListBlock( {

const value = {
clientId,
className,
className:
isAligned && themeSupportsLayout
? classnames(
className,
`align${ wrapperProps[ 'data-align' ] }`
)
: className,
wrapperProps: omit( wrapperProps, [ 'data-align' ] ),
isAligned,
};
Expand Down
8 changes: 4 additions & 4 deletions packages/block-editor/src/layouts/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,23 @@ export default {
margin-right: auto !important;
}
${ appendSelectors( selector, '> [data-align="wide"]' ) } {
${ appendSelectors( selector, '> .alignwide' ) } {
max-width: ${ wideSize ?? contentSize };
}
${ appendSelectors( selector, '> [data-align="full"]' ) } {
${ appendSelectors( selector, '> .alignfull' ) } {
max-width: none;
}
`
: '';

output += `
${ appendSelectors( selector, '> [data-align="left"]' ) } {
${ appendSelectors( selector, '> .alignleft' ) } {
float: left;
margin-right: 2em;
}
${ appendSelectors( selector, '> [data-align="right"]' ) } {
${ appendSelectors( selector, '> .alignright' ) } {
float: right;
margin-left: 2em;
}
Expand Down

0 comments on commit 67b1282

Please sign in to comment.